Build an invoice template
Build an invoice with DocStudio: seller and customer blocks, a line item table, calculated subtotal, tax and total, currency formatting and page numbers.
The invoice example is a complete template. This guide explains how it is built.
Layout
- A
rowwithjustify: "between"holds the seller block on one side and the invoice number and dates on the other. - A
dividerseparates the header from the bill-to block. - A
stackshows the customer. - A
tablebound tolineslists the items. - A
stackat the end holds the payment terms. - The page footer has a
pageNumberwithPage {n} of {total}.
Line totals and the footer
Each row's amount is an expression, and the footer sums it:
{
"id": "amount",
"header": "Amount",
"align": "end",
"cell": {
"fn": "format",
"args": [
"currency",
{ "fn": "mul", "args": [{ "path": "quantity" }, { "path": "unitPrice" }] },
"USD"
]
}
}{
"cells": [
{ "text": "Total due", "span": 3, "align": "end" },
{
"expr": {
"fn": "format",
"args": [
"currency",
{
"fn": "mul",
"args": [
{
"fn": "sum",
"args": [{ "path": "$rows" }],
"of": { "fn": "mul", "args": [{ "path": "quantity" }, { "path": "unitPrice" }] }
},
{ "fn": "add", "args": [1, { "path": "invoice.taxRate" }] }
]
},
"USD"
]
},
"align": "end"
}
]
}Tips
- Keep prices as numbers in your data and let the
currencyformatter present them. - Rounding:
roundrounds half away from zero. Round each line before summing if your accounting requires it. - Use
repeatHeader: trueandrowBreak: "avoid"so long invoices continue cleanly. - Set
missingDatatowarnso a missing customer name is reported.
Output
Print it with printHtml, or produce a PDF with the server guide.