53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import { inputText } from './input-text.ts';
|
|
import type { Acquisition } from './iva-acquisitions.ts';
|
|
export function beverageParcel(row: Acquisition): string {
|
|
return JSON.stringify([
|
|
row.field === '11'
|
|
? 'customs'
|
|
: row.supplier.trim().toLocaleLowerCase(),
|
|
row.documentRef.trim().toLocaleLowerCase(),
|
|
row.documentDate,
|
|
row.documentLine.trim(),
|
|
]);
|
|
}
|
|
type Claim = {
|
|
source: { parcel: string; origin: string } | null;
|
|
stage: string;
|
|
decision: string;
|
|
receipts: unknown[];
|
|
};
|
|
export function beverageParcelReserved(
|
|
d: Record<string, unknown>,
|
|
row: Acquisition,
|
|
): boolean {
|
|
const store = JSON.parse(inputText(d.modelo_a_snapshot || '{}')),
|
|
map = store.ivaBeverageRestitutions as
|
|
| Record<
|
|
string,
|
|
{
|
|
rows: Claim[];
|
|
result?: { inputs: Claim[] };
|
|
history?: Array<{ inputs: Claim[] }>;
|
|
}
|
|
>
|
|
| undefined;
|
|
return Object.entries(map ?? {}).some(([scope, b]) =>
|
|
[
|
|
...b.rows,
|
|
...[...(b.history ?? []), ...(b.result ? [b.result] : [])].flatMap(
|
|
(c) => c.inputs,
|
|
),
|
|
].some(
|
|
(r) =>
|
|
r.source &&
|
|
(scope === inputText(d.context_opportunity || 'general') ||
|
|
r.source.origin === 'effective') &&
|
|
r.source.origin === row.origin &&
|
|
r.source.parcel === beverageParcel(row) &&
|
|
(r.stage === 'submitted' ||
|
|
r.decision !== 'pending' ||
|
|
r.receipts.length > 0),
|
|
),
|
|
);
|
|
}
|