export function roundMoney(value: number) { return Math.round((Number(value) || 0) * 100) / 100; } export function expenseAmounts( quantity: number, unitPrice: number, taxIncluded: boolean, ivaRate = 0.16, ) { const line = roundMoney(quantity * unitPrice); const rate = Number(ivaRate) || 0.16; if (taxIncluded) { const total = line; const subtotal = roundMoney(total / (1 + rate)); return { subtotal, ivaAmount: roundMoney(total - subtotal), total }; } const subtotal = line; const ivaAmount = roundMoney(subtotal * rate); return { subtotal, ivaAmount, total: roundMoney(subtotal + ivaAmount) }; }