Files
compras/resources/js/lib/order-parts.ts
T
nala dc73540558
tests / ci (push) Waiting to run
commit melhorias compras6
2026-11-23 06:37:16 +02:00

37 lines
1.3 KiB
TypeScript

/** Exact transport of explicit monetary input; no price, VAT or exchange calculation. */
export function orderPartMinor(value: string): number | null {
if (!/^\d{1,13}(?:\.\d{1,2})?$/.test(value)) return null;
const [whole, fraction = ''] = value.split('.');
const result = BigInt(whole) * 100n + BigInt(fraction.padEnd(2, '0'));
return result <= 100000000000000n ? Number(result) : null;
}
/** Display-only metadata must not change the identity of a remembered quantity preparation. */
export function orderPartDraftKey(
sources: {
requisition_id: number;
award_id: number;
items: {
quotation_item_id: number;
quantity_milli: number;
quantity_offset_milli: number;
}[];
}[],
): string {
return JSON.stringify(
sources
.map((source): [number, number, [number, number, number][]] => [
source.requisition_id,
source.award_id,
source.items
.map((line): [number, number, number] => [
line.quotation_item_id,
line.quantity_milli,
line.quantity_offset_milli,
])
.sort((a, b) => a[0] - b[0]),
])
.sort((a, b) => a[0] - b[0]),
);
}