Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
import { vatRate } from "./finance_tax_vat_rate.ts"; ← from finance.tax.vat-rate ^1.0.0 · built alongside by fune
import { addMoney } from "./money_add.ts"; ← from money.add ^1.0.0 · built alongside by fune
import { type Money } from "./money_amount.ts"; ← from money.amount ^1.0.0 · built alongside by fune
import { applyRate } from "./money_apply_rate.ts"; ← from money.apply-rate ^1.0.0 · built alongside by fune
import { type VatBreakdown } from "./finance_tax_add_vat_types.ts";
/**
* Add VAT to a net amount at the rate in force on the date of supply.
*
* Returns the whole breakdown rather than just the tax: an invoice needs net,
* tax and gross together, and deriving the third from the other two in caller
* code is where rounding bugs are born.
*/
export function addVat(net: Money, jurisdiction: string, category: string, onDate: string): VatBreakdown {
const rate = vatRate(jurisdiction, category, onDate);
const tax = applyRate(net, rate.basisPoints, "half-up");
return {
net,
tax,
gross: addMoney(net, tax),
basisPoints: rate.basisPoints,
};
}