diff options
| author | mihailo.vojinovic <mihailonvojinovic@gmail.com> | 2026-02-13 13:01:34 +0100 |
|---|---|---|
| committer | mihailo.vojinovic <mihailonvojinovic@gmail.com> | 2026-02-13 13:01:34 +0100 |
| commit | fc3fccc32edc47a4ae8b1d52da238883ec972831 (patch) | |
| tree | 1ddabdf7cb4672e97e8ccc10e8132ff59a9c3a05 /src/lib | |
| parent | a2025bba133905a1265feef685675d8f1e3590d1 (diff) | |
| download | invoice-fc3fccc32edc47a4ae8b1d52da238883ec972831.tar.gz invoice-fc3fccc32edc47a4ae8b1d52da238883ec972831.zip | |
Add subtotal to generated pdf
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/generate.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/generate.ts b/src/lib/generate.ts index 7789f3e..e78b61e 100644 --- a/src/lib/generate.ts +++ b/src/lib/generate.ts @@ -137,6 +137,24 @@ export async function generateInvoice(invoice: Invoice): Promise<Blob> { doc.text("", MARGIN + T_PADDING, doc.y + T_ROW_HEIGHT / 2); }); + const total = invoice.line_items.reduce( + (acc, cur) => acc + (cur.quantity ?? 0) * (cur.rate ?? 0), + 0, + ); + const totalText = + "Subtotal: " + + total.toLocaleString(undefined, { + style: "currency", + currency: invoice.currency, + }); + + doc.moveDown(2); + doc.fontSize(12); + doc.text( + totalText, + doc.page.width - MARGIN - T_PADDING - doc.widthOfString(totalText), + ); + doc.end(); return new Promise((resolve, reject) => { stream.on("finish", () => { |
