UNPKG

invoice-craft

Version:

Customizable, browser-first invoice PDF generator library with modern TypeScript API

13 lines (12 loc) 440 B
export function calculateTotals(invoice) { let subtotal = 0, totalTax = 0; invoice.items.forEach(item => { subtotal += item.quantity * item.unitPrice; if (item.taxRate) { totalTax += (item.quantity * item.unitPrice * item.taxRate) / 100; } }); const discount = invoice.discount || 0; const total = subtotal + totalTax - discount; return { subtotal, totalTax, discount, total }; }