// Filename: docs/concepts/tax-settlement-to-ap-invoice.concept.md
Concept: Tax Settlement to Accounts Payable Invoice Flow
1. Overview
This document outlines the cross-module process that transforms a calculated tax liability from the General Ledger (GL) module into a payable vendor invoice in the Accounts Payable (AP) module. This allows the organization to pay its tax liabilities using the standard vendor payment process.
The core principle is to treat the Tax Authority as a Vendor. The net tax liability for a period becomes a service-based invoice that the AP department pays.
2. Process Flow
The flow is initiated after a tax settlement journal is posted in the General Ledger.
- GL: Journal Posted: The
TaxSettlementJournalPostedEventHandlerin the GL module listens forLedgerJournalPostedDomainEvent. - GL: Event Published: If the posted journal is a
TaxSettlementtype, the handler calculates the net liability and publishes aTaxSettlementPayableCreatedIntegrationEventto the message bus. This event contains the Tax Authority's Vendor Account ID, the payable amount, and the GL settlement voucher number. - AP: Event Consumed: The
TaxSettlementPayableCreatedIntegrationEventHandlerin the AP module consumes this event. - AP: Invoice Creation: The handler performs the following actions:
a. Requests a new Purchase Invoice number from the Number Sequence service.
b. Calls the
PurchaseInvoiceHeader.CreateForTaxSettlement()factory method. c. This factory method creates a newPurchaseInvoiceHeaderwith a single, non-stock line representing the total tax liability. d. Crucially, it populates theTaxSettlementVoucherproperty on the invoice header with the voucher from the GL event. This serves as an audit trail and a flag to bypass inventory logic. e. The new invoice is saved to the database in anOpen(draft) state. - AP: Invoice Posting (User Action): An AP user reviews and posts the newly created tax invoice via the standard UI/API.
- AP: Inventory Posting Bypass: When the invoice's
Postmethod is called, it eventually triggers theVendorInvoiceInventoryPostingInitiatedDomainEvent. - AP: Logic Check: The handler for this event,
PurchaseInvoiceInventoryPostingInitiatedDomainEventHandler, checks if theTaxSettlementVoucherproperty is populated. - AP: Workflow Continuation: Because the property is not null, the handler immediately calls
invoice.CompleteInventoryPosting()and exits without publishing an event to the Inventory module. This allows the posting workflow to proceed directly to the final GL posting step. - Final GL Posting: The standard process for posting the vendor invoice to the GL continues, debiting the tax settlement clearing account and crediting the Accounts Payable control account.