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:
{
"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:
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 |
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
{
"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.
Notes
- Supports VAT rates of 0 %, 7 %, and 19 %. Other rates will result in an error.
- All amounts are rounded to two decimal places using commercial 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.