Skip to content

Calculate invoice amounts

The "Calculate invoice amounts" service task automatically computes all relevant totals from invoice line items. Based on quantity, unit price (net), and VAT rate, the service calculates line item totals, VAT breakdowns, and grand totals. This allows invoices to be generated fully automatically without any manual calculation.


How it works

The task processes all invoice line items and calculates:

  • Per line item: Net total, gross total, VAT amount
  • Aggregated: Grand total net, grand total gross, VAT grouped by rate (0 %, 7 %, 19 %)

The calculated values are written directly into the invoice object and are available for subsequent steps (e.g. PDF generation or e-invoicing).


Input parameters

The invoice object with its line items is provided as input:

{
  "vat_rounding": "per_rate",
  "app_invoice_items_custom": [
    {
      "app_item_description": "Consulting",
      "app_amount": 10,
      "app_item_price_net": 150.00,
      "app_vat_percentage": 19,
      "app_unit": "Hours"
    },
    {
      "app_item_description": "Materials",
      "app_amount": 5,
      "app_item_price_net": 25.00,
      "app_vat_percentage": 7,
      "app_unit": "Pieces"
    }
  ]
}

Explanation:

  • vat_rounding: VAT rounding method, see VAT rounding.
  • app_invoice_items_custom: List of invoice line items.
  • app_amount: Quantity for the line item.
  • app_item_price_net: Unit price (net).
  • app_vat_percentage: VAT rate (0, 7, or 19).
  • app_unit: Unit of measure (e.g. "Hours", "Pieces", "Flat rate").

Output

The invoice object is enriched with calculated fields:

Per line item:

Field Description
app_invoice_item_no Sequential item number (1, 2, 3, …)
app_items_total_sum_net Net total for the line item (quantity × unit price)
app_items_total_sum_gross Gross total for the line item
app_item_price_gross Unit price (gross)

Aggregated fields:

Field Description
app_net_total Grand total (net)
app_gross_total Grand total (gross)
app_vat_total Total VAT amount
app_vat_nineteen VAT at 19 % (amount)
app_vat_seven VAT at 7 % (amount)
app_vat_zero VAT at 0 % (amount)
app_has_vat_nineteen true if any line item has 19 % VAT
app_has_vat_seven true if any line item has 7 % VAT
app_has_vat_zero true if any line item has 0 % VAT
app_has_reverse_charge true if the invoice is issued without VAT under Section 13b UStG
app_net_reverse_charge Net amount for reverse charge (otherwise 0)

Example

An invoice contains two line items: 10 hours of consulting at €150.00 net (19 %) and 5 pieces of material at €25.00 net (7 %). The service automatically calculates: net total €1,625.00, VAT 19 %: €285.00, VAT 7 %: €8.75, gross total €1,918.75.


JSONata example

{
  "vat_rounding": "per_rate",
  "app_invoice_items_custom": $.app_invoice_items_custom
}

All other invoice fields (invoice number, date, recipient, etc.) can be included — they are passed through unchanged.


VAT rounding

The field app_vat_rounding (or vat_rounding) defines how VAT is rounded:

Value Calculation
per_rate For each line item, the net total (quantity × unit price) is rounded to the cent. VAT is then calculated and rounded once per rate from the sum of these net totals. This is how the EN 16931 standard, on which ZUGFeRD and XRechnung are based, calculates.
(empty) Previous method: VAT is rounded per unit and multiplied by the quantity. Deprecated and will be removed on January 1, 2027. After that, the service always calculates as with per_rate.

Any other value results in an error.

Switch from the previous method by January 1, 2027

With the previous method, the rounding error of a single unit is multiplied by the quantity. Example: 1,000 pieces at €0.99 net with 19 % result in €190.00 VAT instead of €188.10. If the VAT of a rate deviates by €1.00 or more, the e-invoice is invalid (validation rules BR-S-09 and BR-CO-17) and may be rejected by the recipient.

What changes when switching:

  • Most invoices stay the same to the cent.
  • With several line items at the same rate or quantities above 1, the gross amount may change by one cent, e.g. €89.51 instead of €89.50. This mainly affects net prices that were calculated back from a desired gross price.
  • VAT and gross total per line item are still calculated for the PDF template. Their sum may differ from the grand total by one cent; the grand total is authoritative.
  • Invoices already issued remain unchanged.

How to switch: Set the field vat_rounding (or app_vat_rounding) to per_rate in the invoice data – for the single service in the JSONata input as in the example, for Complete e-invoice alternatively via the service task's inbound mapping.


Notes

  • Supports VAT rates of 0 %, 7 %, and 19 %. Other rates will result in an error.
  • If the tax mode app_tax_mode (or tax_mode) is set to reverse_charge_13b, all line items are calculated at 0 %, regardless of the stored VAT rate. Details in Reverse charge (Section 13b UStG) in e-invoices.
  • All amounts are rounded to two decimal places using commercial rounding. How VAT is rounded is described under VAT rounding.
  • In addition to custom line items (app_invoice_items_custom), article-based line items (app_invoice_items_articles) are also supported — both types can be combined within a single invoice.
  • Item numbers are assigned sequentially: custom items first, then article items.

Tip

This service is typically used as the first step in an invoicing pipeline — followed by Generate PDF from Handlebars template and optionally Create e-invoice (ZUGFeRD). Alternatively, the entire chain can be executed in a single step using the Complete e-invoice service.