Files
sam-react-prod/src/components/organisms/LineItemsTable/calculations.ts

34 lines
866 B
TypeScript
Raw Normal View History

/**
*
*/
const DEFAULT_TAX_RATE = 0.1;
/**
*
*/
export function calcSupplyAmount(quantity: number, unitPrice: number): number {
return quantity * unitPrice;
}
/**
* ( 10%, )
*/
export function calcVat(supplyAmount: number, taxRate: number = DEFAULT_TAX_RATE): number {
return Math.floor(supplyAmount * taxRate);
}
/**
* +
* @returns { supplyAmount, vat }
*/
export function recalculate(
quantity: number,
unitPrice: number,
taxRate: number = DEFAULT_TAX_RATE,
): { supplyAmount: number; vat: number } {
const supplyAmount = calcSupplyAmount(quantity, unitPrice);
const vat = calcVat(supplyAmount, taxRate);
return { supplyAmount, vat };
}