Files
Investidor-V2/resources/js/lib/iva-beverage-parcels.ts
T

5 lines
1.0 KiB
TypeScript

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(String(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===String(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)));}