This document explains the runtime document flow for sales invoices, purchase
invoices, and POS fiscal flows.
Document Events
The app hooks into:
Sales Invoice.before_submitPurchase Invoice.before_submitItem.before_saveCompany.before_save
Company Before Save
The app prevents duplicate sale types in the company configuration.
Item Before Save
If an item has an HS Code but no HS UOM, the app auto-fetches the linked UOM.
Sales Invoice Flow
The sales invoice flow has two branches.
Standard DI Sales Invoice
This path is used when the invoice is not POS.
- Check whether DI is enabled for the company
- Check whether the customer has digital invoicing enabled
- Validate per-item DI fields
- Validate SRO requirements for sale types that need them
- Build the FBR DI payload
- Post automatically if
Auto Post on Submitis enabled - Save the FBR invoice number, posting time, QR code, and DI log
If the DI API rejects the invoice, the app raises a validation error and stores
the failure details in DI Log.
POS Fiscal Sales Invoice
This path is used when the invoice is POS and the POS Profile has FBR
integration enabled.
- Validate that each item has a customs tariff number
- Load POS Profile FBR credentials and endpoint settings
- Resolve payment mode into the FBR payment mode code
- Build the POS fiscal payload
- Submit the payload to the FBR POS endpoint
- Save the fiscal invoice number and posting timestamp
- Generate a QR code
Purchase Invoice Flow
For purchase invoices:
- Check whether DI is enabled for the company
- Validate item-level HS code presence
- Build the DI payload
- Post automatically if
Auto Post on Submitis enabled - Save the response details in
DI Log
Manual Actions Available in the UI
On submitted sales invoices, the app can expose:
DI PreviewPost to FBRValidate with FBRVerify Buyer
On submitted purchase invoices, the app can expose:
DI PreviewPost to FBR
QR Code Flow
When an invoice is posted successfully and an FBR invoice number is available,
the app generates a QR code and stores it as a base64 PNG data URI for UI and
print use.
Print Output
The app ships a Sales Tax Invoice print format that can render FBR-specific
invoice data and the generated QR code.