Added Private Note Scanning

Also removed redundant checks
This commit is contained in:
2016-09-19 10:59:20 -04:00
committed by GitHub
parent b4d6fc55ea
commit da7ba40e61

View File

@@ -46,32 +46,46 @@ class QboInvoice < ActiveRecord::Base
process_invoice invoice process_invoice invoice
end end
# processes the invoice into the system private
def self.process_invoice(invoice)
is_changed = false
# Scan the line items for hashtags and attach to the applicable issues
invoice.line_items.each { |line|
if line.description
line.description.scan(/#(\w+)/).flatten.each { |issue|
i = Issue.find_by_id(issue.to_i)
# Attach the invoice to the issue
def self.attach_to_issue(issue, invoice)
# Load the invoice into the database # Load the invoice into the database
qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id) qbo_invoice = QboInvoice.find_or_create_by(id: invoice.id)
qbo_invoice.doc_number = invoice.doc_number qbo_invoice.doc_number = invoice.doc_number
qbo_invoice.id = invoice.id qbo_invoice.id = invoice.id
qbo_invoice.save! qbo_invoice.save!
# Attach the invoice to the issue unless issue.qbo_invoices.include?(qbo_invoice)
unless i.qbo_invoices.include?(qbo_invoice) issue.qbo_invoices << qbo_invoice
i.qbo_invoices << qbo_invoice issue.save!
i.save!
end end
end
# processes the invoice into the system
def self.process_invoice(invoice)
is_changed = false
# Check the private notes
invoice.private_note.scan(/#(\w+)/).flatten.each { |issue|
attach_to_issue(Issue.find_by_id(issue.to_i), invoice)
}
# Scan the line items for hashtags and attach to the applicable issues
invoice.line_items.each { |line|
if line.description
line.description.scan(/#(\w+)/).flatten.each { |issue|
attach_to_issue(Issue.find_by_id(issue.to_i), invoice)
}
end
}
# update the invoive custom fields with infomation from the work ticket if available # update the invoive custom fields with infomation from the work ticket if available
invoice.custom_fields.each { |cf| invoice.custom_fields.each { |cf|
# TODO Add some hooks here
# VIN from the attached vehicle # VIN from the attached vehicle
begin begin
if cf.name.eql? "VIN" if cf.name.eql? "VIN"
@@ -123,9 +137,8 @@ class QboInvoice < ActiveRecord::Base
# Nothing to do here, there is no match # Nothing to do here, there is no match
end end
} }
}
end # TODO Add some hooks here
}
# Push updates # Push updates
get_base.update(invoice) if is_changed get_base.update(invoice) if is_changed