Overview of Total Fields
Our API uses the following fields to represent invoice amounts:| Field | Description | Can be negative? |
|---|---|---|
subtotal | The taxable base (amount subject to VAT) after document-level allowances/charges | No |
total_discount | Total document-level allowances (discounts) | No |
total_tax | The total VAT/tax amount | No |
invoice_total | The final invoice amount including tax | No (usually) |
amount_due | The amount the customer needs to pay after prepayments | No |
previous_unpaid_balance | Any outstanding balance from previous invoices | No |
The Basic Formula
subtotal is calculated after applying document-level allowances and charges, so total_discount is already factored into the subtotal.
Understanding Each Field
1. Subtotal (Taxable Base)
The subtotal represents the taxable base - the amount on which VAT is calculated. Calculation:- This is always positive
- Only includes allowances and charges that have VAT applied to them
- This is the base amount used for tax calculation
2. Total Tax
The total_tax is the total amount of VAT calculated on the subtotal. Calculation:- VAT is calculated on the subtotal for each applicable tax rate
- Multiple tax rates are grouped and calculated separately
- The results are summed to get the total tax
3. Total Discount
The total_discount field represents the total amount of document-level allowances (discounts) applied to the invoice. Calculation:- This field is always positive (or zero)
- Represents the total value of discounts given at the document level
- These allowances are already factored into the
subtotal - Examples: Early payment discounts, volume discounts, promotional discounts
4. Invoice Total
The invoice_total is the final amount of the invoice including VAT. Calculation:5. Amount Due
The amount_due is what the customer actually needs to pay. Calculation:6. Previous Unpaid Balance
The previous_unpaid_balance represents any outstanding amounts from previous invoices. This is a custom field not part of standard UBL.Document-Level vs Line-Level Allowances and Charges
Understanding where to apply adjustments is crucial:Document-Level Allowances/Charges
- Affect the subtotal (taxable base)
- Applied to the entire invoice after line items are totaled
- VAT is calculated on the adjusted amount
- Contribute to the
total_discountfield (for allowances) - Examples: Early payment discounts, shipping charges for the entire order, handling fees
Line-Level Allowances/Charges
- Affect individual line item amounts
- Applied to specific products or services
- Do NOT appear in the document-level
total_discountfield - Examples: Bulk discount on a specific product, special handling for fragile items
Complete Example
Here’s a complete invoice calculation:- Line items total: €1,000.00
- Apply document-level allowances:
- Commercial discount: -€200.00
- Early payment discount: -€50.00
- Apply document-level charges:
- Shipping: +€50.00
- Subtotal (taxable base): €800.00
- Calculate tax: €800.00 × 21% = €168.00
- Total discount: €250.00 (sum of allowances only)
- Invoice total: €800.00 + €168.00 = €968.00
- Amount due: €968.00 (no prepayment)
UBL Mapping
For reference, here’s how our fields map to UBL (Universal Business Language) elements:| Our Field | UBL Element |
|---|---|
subtotal | cac:LegalMonetaryTotal/cbc:TaxExclusiveAmount |
total_tax | cac:TaxTotal/cbc:TaxAmount |
total_discount | cac:LegalMonetaryTotal/cbc:AllowanceTotalAmount |
invoice_total | cac:LegalMonetaryTotal/cbc:TaxInclusiveAmount |
amount_due | cac:LegalMonetaryTotal/cbc:PayableAmount |
Key points about UBL mapping:
TaxExclusiveAmount(subtotal) is the taxable base after applying document-level allowances and chargesAllowanceTotalAmount(total_discount) represents the sum of all document-level allowancesTaxInclusiveAmount(invoice_total) is the total including VATPayableAmount(amount_due) is the final amount to be paid after prepayments
Validation Rules
When creating or updating invoices, the following validations are applied:- Subtotal must match the calculated taxable base after document-level adjustments (within €0.01 tolerance)
- Total tax must match the calculated VAT amount (within €0.01 tolerance)
- Total discount must match the sum of document-level allowances (within €0.01 tolerance)
- Invoice total must equal
subtotal + total_tax(within €0.01 tolerance) - Amount due must be between 0 and invoice_total (inclusive)
Common Questions
What’s the difference between document-level and line-level allowances?
- Document-level allowances apply to the entire invoice and are reflected in the
total_discountfield - Line-level allowances apply to specific line items and are included in the line item calculations, not in
total_discount
Can invoice_total be negative?
In theory yes, if you have large allowances, but this is unusual. Most invoices should have a positive invoice total. Credit notes are the proper way to issue refunds.What if I don’t provide these fields?
If you don’t providesubtotal, total_tax, total_discount, or invoice_total, the system will automatically calculate them based on your line items, allowances, and charges. The calculated values will be validated if you do provide them.
How are document-level charges handled?
Document-level charges (like shipping fees) increase the subtotal before VAT is calculated. They are not reflected in thetotal_discount field, which only includes allowances (discounts).