Reconcile IVA projection with Tempo Modelo A in QA
This commit is contained in:
@@ -793,6 +793,20 @@ export function monthlyProjectedSales(input: BusinessFinancialPlanInput): Array<
|
||||
});
|
||||
}
|
||||
|
||||
/** Existing purchase orders are planning references, never a proxy for deductible VAT or invoice dates. */
|
||||
export function monthlyProjectedPurchaseOrders(input: BusinessFinancialPlanInput): Array<string | null> {
|
||||
const periods = input.periods ?? 12;
|
||||
if (!Number.isInteger(periods) || periods < 1 || periods > 60) throw new Error('Horizonte de compras inválido.');
|
||||
return Array.from({length: periods}, (_, month) => {
|
||||
const amounts = input.useProductInventorySchedule
|
||||
? input.products.map((product) => product.productInventoryPurchasesByPeriod?.[month]?.amount)
|
||||
: [input.useInventoryPurchaseSchedule
|
||||
? input.inventoryPurchaseSchedule?.[month]?.amount : input.monthlyInventoryPurchases];
|
||||
if (!amounts.length || amounts.some((amount) => typeof amount !== 'string' || amount.trim() === '')) return null;
|
||||
return format(amounts.reduce((total, amount) => total + cents(amount!, 'Compras projectadas'), 0n));
|
||||
});
|
||||
}
|
||||
|
||||
function format(centsValue: bigint): string {
|
||||
const absolute = centsValue < 0n ? -centsValue : centsValue;
|
||||
return `${centsValue < 0n ? '-' : ''}${absolute / 100n}.${String(absolute % 100n).padStart(2, '0')}`;
|
||||
|
||||
Reference in New Issue
Block a user