Class: QuickbooksInvoiceHeaderResolver
- Inherits:
-
Object
- Object
- QuickbooksInvoiceHeaderResolver
- Includes:
- AddressHelper, QuickbooksCustomerHelper
- Defined in:
- app/resolver/quickbooks_invoice_header_resolver.rb
Overview
QuickbooksInvoiceHeaderResolver is responsible for processing QuickBooks invoice data and integrating it with the application’s internal invoice data model. This resolver handles the creation, updating, and integration of QuickBooks invoices with corresponding invoice header records in the application.
The resolver handles three primary scenarios:
-
Finding and updating existing integrated invoice headers
-
Finding matching non-integrated invoice headers and integrating them
-
Creating new invoice headers when no match is found
It also manages the creation of distribution center customers when necessary based on shipping address information in the invoice.
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 ⇒ Object
readonly
Returns the value of attribute invoice.
Instance Method Summary collapse
-
#initialize(company_id:, customer_id:, invoice:) ⇒ QuickbooksInvoiceHeaderResolver
constructor
Initializes a new QuickbooksInvoiceHeaderResolver.
-
#resolve ⇒ Hash
Processes the QuickBooks invoice data and performs the necessary actions to integrate it with the application’s data model.
Methods included from QuickbooksCustomerHelper
#check_and_create_member_customer, #check_and_set_customer_hierarchy, #extract_shipping_address_from_quickbooks_customer, #find_currency_id, #find_payment_term_id, #find_type, #format_known_as, #formatted_code
Methods included from CustomerHierarchyManagement
#assign_customer_hierarchy, #billing_shipping_addresses_match?, #create_dc_customer_for_shipping_address, #create_member_customer_for_shipping_address, #determine_hierarchy_attributes, #find_customer_with_same_address, #shipping_address_valid?
Methods included from AddressHelper
#canadian_postal_code?, #clean_city, #normalize_postal_code, #parse_address_line, #parse_address_parts, #us_zip_code?, #valid_city?, #valid_state?
Constructor Details
#initialize(company_id:, customer_id:, invoice:) ⇒ QuickbooksInvoiceHeaderResolver
Initializes a new QuickbooksInvoiceHeaderResolver
39 40 41 42 43 44 |
# File 'app/resolver/quickbooks_invoice_header_resolver.rb', line 39 def initialize(company_id:, customer_id:, invoice:) @company_id = company_id @customer_id = customer_id @invoice = invoice.with_indifferent_access @customer_service = CustomerService.new(USER_NAME) end |
Instance Attribute Details
#company_id ⇒ Object (readonly)
Returns the value of attribute company_id.
31 32 33 |
# File 'app/resolver/quickbooks_invoice_header_resolver.rb', line 31 def company_id @company_id end |
#customer_id ⇒ Object (readonly)
Returns the value of attribute customer_id.
31 32 33 |
# File 'app/resolver/quickbooks_invoice_header_resolver.rb', line 31 def customer_id @customer_id end |
#invoice ⇒ Object (readonly)
Returns the value of attribute invoice.
31 32 33 |
# File 'app/resolver/quickbooks_invoice_header_resolver.rb', line 31 def invoice @invoice end |
Instance Method Details
#resolve ⇒ Hash
Processes the QuickBooks invoice data and performs the necessary actions to integrate it with the application’s data model
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/resolver/quickbooks_invoice_header_resolver.rb', line 51 def resolve ActiveRecord::Base.transaction do if find_integrated_invoice_header update_invoice_header check_and_create_dc_customer { action: 'update', quickbooks_invoice_header: @invoice_header } elsif find_invoice_header_to_integrate integrate_invoice_header update_invoice_header check_and_create_dc_customer { action: 'integrate', quickbooks_invoice_header: @invoice_header } elsif create_invoice_header integrate_invoice_header check_and_create_dc_customer { action: 'create', quickbooks_invoice_header: @invoice_header } end end rescue StandardError => e Rails.logger.error "QuickBooks Invoice Header resolve failed: #{e.}" Rails.logger.error e.backtrace.join("\n") raise e end |