fbr_invoice library
FBR Digital Invoicing: a builder that works out the sales tax and an offline validator for the invoice JSON posted to FBR's Digital Invoicing API. No HTTP client and no token handling.
Same as the pakdatakit/fbr-invoice entry point of the npm package.
Classes
- FbrInvoiceBuild
- Result of buildFbrInvoice.
- FbrInvoiceError
- One problem found by validateFbrInvoice.
- FbrInvoiceReference
-
Reference lists from FBR's own APIs (PRAL's
/pdi/v1/provinces,/pdi/v1/uom,/pdi/v2/HS_UOM, sale types from/pdi/v2/SaleTypeToRate...), which an app syncs with its token, forvalidateFbrInvoice(invoice, reference: ...). FBR's APIs are authoritative; this library ships no copy of these lists. - FbrInvoiceTotals
- Column totals of an invoice, in rupees. Not sent to FBR.
- FbrInvoiceValidation
- Result of validateFbrInvoice.
- FbrSaleType
- A sale type as PRAL's specification names it, with its sandbox scenarios. Result of getSaleTypes.
Enums
- FbrInvoiceType
-
invoiceTypevalues in the specification. - FbrRegistrationType
-
buyerRegistrationTypevalues in the specification.
Constants
- fbrDiSpecVersion → const String
-
Version of PRAL's technical specification this module follows
(
FBR_DI_SPEC_VERSIONin the npm package).
Functions
-
buildFbrInvoice(
Object? input) → FbrInvoiceBuild? -
Builds an FBR digital invoice from your own fields, working out
salesTaxApplicableon each line where you leave it out (see expectedSalesTax; uses calculateSalesTax). Lines with a rate that is neitherN%norRs.N(Exempt, combined rates) get 0 unless you give the tax. -
expectedSalesTax(
Object? item) → double? -
The sales tax FBR expects on a line, in rupees, or
nullwhen the rate is not a plain percentage or per-unit amount (spec §7, errors 0102, 0104, 0105): -
getSaleTypes(
) → List< FbrSaleType> - The sale types named in PRAL's DI specification (v1.12, section 9, "Scenarios for Sandbox Testing"), with the scenarios that use each.
-
validateFbrInvoice(
Object? invoice, {String? today, FbrInvoiceReference? reference}) → FbrInvoiceValidation - Checks an FBR digital invoice against the rules of PRAL's specification (v1.12) and Error Message Guide that need no call to FBR, and returns every problem with FBR's error code.
Typedefs
-
FbrInvoice
= Map<
String, Object?> -
The invoice body for
postinvoicedataandvalidateinvoicedata(spec §4.1, §4.2), as JSON:invoiceType,invoiceDate(YYYY-MM-DD),sellerNTNCNIC,sellerBusinessName,sellerProvince,sellerAddress,buyerNTNCNIC,buyerBusinessName,buyerProvince,buyerAddress,buyerRegistrationType,invoiceRefNo,scenarioId(sandbox only) anditems, a list of FbrInvoiceItems. -
FbrInvoiceInput
= Map<
String, Object?> -
Input for buildFbrInvoice: an FbrInvoice whose
invoiceRefNoandbuyerNTNCNICmay be left out. -
FbrInvoiceItem
= Map<
String, Object?> -
One line of an invoice (spec §4.1,
items), as JSON. Amounts are in rupees:hsCode,productDescription,rate(18%,Rs.3,Exempt…),uoM,quantity(up to 4 decimals),totalValues,valueSalesExcludingST,fixedNotifiedValueOrRetailPrice,salesTaxApplicable,salesTaxWithheldAtSource,extraTax,furtherTax,sroScheduleNo,fedPayable,discount,saleTypeandsroItemSerialNo. -
FbrInvoiceItemInput
= Map<
String, Object?> -
An item for buildFbrInvoice: an FbrInvoiceItem whose
salesTaxApplicable,salesTaxWithheldAtSource,totalValuesandfixedNotifiedValueOrRetailPricemay be left out.