panels-origin/web-panel/composables/expenseAmounts.ts
Cursor Agent 1e5bc22936
fix: catálogo de proveedores y unidades en la captura de gastos
Proveedor y unidad pasan a Select de catálogo (no texto libre). Subtotal, IVA y total se calculan al vuelo. El comprobante usa FileUpload de PrimeVue.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-08 20:06:45 +00:00

21 lines
636 B
TypeScript

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) };
}