Class: QuickbooksInvoiceDetailResolver
- Inherits:
-
Object
- Object
- QuickbooksInvoiceDetailResolver
- Defined in:
- app/resolver/quickbooks_invoice_detail_resolver.rb
Overview
QuickbooksInvoiceDetailResolver handles the processing and integration of invoice line items from QuickBooks with the application’s internal invoice detail data model. This resolver processes individual invoice detail lines from the QuickBooks API and performs the necessary operations to maintain data consistency between systems.
The resolver manages three primary scenarios:
-
Finding and updating existing integrated invoice details
-
Finding matching non-integrated invoice details and integrating them
-
Creating new invoice details when no match is found
It also handles special cases such as skipping subtotal lines and lines with missing IDs.
Constant Summary collapse
- USER_NAME =
'SYSTEM'
Instance Attribute Summary collapse
-
#company_id ⇒ Object
readonly
Returns the value of attribute company_id.
-
#customer_id ⇒ Object
readonly
Returns the value of attribute customer_id.
-
#invoice_detail ⇒ Object
readonly
Returns the value of attribute invoice_detail.
-
#quickbooks_invoice_header_id ⇒ Object
readonly
Returns the value of attribute quickbooks_invoice_header_id.
Instance Method Summary collapse
-
#initialize(company_id:, customer_id:, quickbooks_invoice_header_id:, invoice_detail:) ⇒ QuickbooksInvoiceDetailResolver
constructor
Initializes a new QuickbooksInvoiceDetailResolver.
-
#resolve ⇒ Hash?
Processes the QuickBooks invoice line item data and performs the necessary actions to integrate it with the application’s data model.
Constructor Details
#initialize(company_id:, customer_id:, quickbooks_invoice_header_id:, invoice_detail:) ⇒ QuickbooksInvoiceDetailResolver
Initializes a new QuickbooksInvoiceDetailResolver
37 38 39 40 41 42 |
# File 'app/resolver/quickbooks_invoice_detail_resolver.rb', line 37 def initialize(company_id:, customer_id:, quickbooks_invoice_header_id:, invoice_detail:) @company_id = company_id @customer_id = customer_id @quickbooks_invoice_header_id = quickbooks_invoice_header_id @invoice = invoice_detail.with_indifferent_access end |
Instance Attribute Details
#company_id ⇒ Object (readonly)
Returns the value of attribute company_id.
28 29 30 |
# File 'app/resolver/quickbooks_invoice_detail_resolver.rb', line 28 def company_id @company_id end |
#customer_id ⇒ Object (readonly)
Returns the value of attribute customer_id.
28 29 30 |
# File 'app/resolver/quickbooks_invoice_detail_resolver.rb', line 28 def customer_id @customer_id end |
#invoice_detail ⇒ Object (readonly)
Returns the value of attribute invoice_detail.
28 29 30 |
# File 'app/resolver/quickbooks_invoice_detail_resolver.rb', line 28 def invoice_detail @invoice_detail end |
#quickbooks_invoice_header_id ⇒ Object (readonly)
Returns the value of attribute quickbooks_invoice_header_id.
28 29 30 |
# File 'app/resolver/quickbooks_invoice_detail_resolver.rb', line 28 def quickbooks_invoice_header_id @quickbooks_invoice_header_id end |
Instance Method Details
#resolve ⇒ Hash?
Processes the QuickBooks invoice line item data and performs the necessary actions to integrate it with the application’s data model
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/resolver/quickbooks_invoice_detail_resolver.rb', line 50 def resolve # Skip processing subtotal line types if @invoice['DetailType'] == 'SubTotalLineDetail' return { action: 'skip', invoice_detail: nil } end # Skip if the line ID is missing if @invoice['Id'].blank? Rails.logger.warn("Skipping invoice detail with missing line ID for header #{quickbooks_invoice_header_id}") return { action: 'skip', invoice_detail: nil } end begin ActiveRecord::Base.transaction do if find_integrated_invoice_detail update_invoice_detail { action: 'update', invoice_detail: @invoice_detail } elsif find_invoice_detail_to_integrate integrate_invoice_detail update_invoice_detail { action: 'integrate', invoice_detail: @invoice_detail } elsif create_invoice_detail integrate_invoice_detail { action: 'create', invoice_detail: @invoice_detail } end end rescue StandardError => e Rails.logger.error "QuickBooks Invoice Detail resolve failed: #{e.}" Rails.logger.error e.backtrace.join("\n") raise e end end |