unified-invoicing
The inception of the Unified Invoicing initiative emerged as a strategic endeavor to standardize the procedures associated with invoice generation and processing. Prior to the integration of UALA with Treatwell, disparate methods were employed for managing invoices, exemplified by the use of Fatture in Cloud for Italy and Elorus for Greece.
The consolidation of Treatwell and UALA prompted the necessity for a centralized framework to streamline the entire invoice workflow. Consequently, the Unified Invoicing project was initiated to harmonize and optimize the invoicing processes across the amalgamated entities.
Unified invoicing Flow
A Country is integrated into the unified invoicing system through the establishment of a designated CountryProvider known as "Treatwell Ledger." Once this provider is linked to a specific country, all billing entities operating within that jurisdiction will automatically adhere to the standardized invoicing procedures.
example of a Treatwell Ledger provider: https://admin.uala.com/backend/country_providers/99=share_link
During the execution of the billing process within the SYNC INVOICES phase for every generated BillingCompanyInvoice, the method Payments::InvoicePaymentService#add_invoice is invoked. Specifically, in instances involving Treatwell Ledger countries, this operation is delegated to Payments::InvoicePayment::TreatwellLedgerProvider#add_invoice.
Payments::InvoicePayment::TreatwellLedgerProvider#add_invoice will trigger a background job called Single::SupplierFeeJob.perform_now(id) located within the TW-INTEGRATION application. To accomplish this, the process involves navigating through our intrapp system, specifically through Uala::Intrapps::TwIntegration::Utility#synch_supplier_fee. The queued job is identified as Single::SupplierFeeJob.perform_later(billing_company_invoice_id)
This job execute an HTTP request to the Treatwell ledger to sync the invoice and is divided into two distinct logics. In the case of synchronizing an invoice for monthly or annual fees (such as IT PREMIUM, IT ADVANCED), we transmit a payload named subscriptionFees through the SupplierFeePresenter. Conversely, for all other fees, including addons and new business charges, a payload called supplierCharges is dispatched through the SupplierChargePresenter.
Forcing a invoice sync into the ledger
If an invoice is generated but fails to synchronize with the ledger for any reason, you can manually trigger the synch process from a Rails console in the cluster — see Infrastructure for getting kubectl pointed at it:
kubectl -n be-main-env-prod exec -ti deploy/toolbox -- bin/rails c
Then execute Single::SupplierFeeJob.perform_now(id).
To investigate a failing HTTP request, read the logs of the jobs worker that runs the queue, for example kubectl -n be-main-env-prod logs deploy/jobs-worker-invoices --tail 200.