Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

1 export type StatementInput={sourceId:string;amountIrr:number;date:string;reference:string};export type BankTransaction=Readonly<StatementInput&{tenantId:string;accountId:string;reference:string}>;export function ingestStatement(tenantId:string,accountId:string,rows:StatementInput[]){const errors:string[]=[];const seen=new Set<string>();const txns:BankTransaction[]=[];for(const [i,r] of rows.entries()){if(!r.sourceId||seen.has(r.sourceId))errors.push(`row ${i+1}: duplicate/missing source id`);seen.add(r.sourceId);if(!Number.isSafeInteger(r.amountIrr))errors.push(`row ${i+1}: invalid amount`);if(!/^\d{4}-\d{2}-\d{2}$/.test(r.date)||Number.isNaN(Date.parse(r.date+'T00:00:00Z')))errors.push(`row ${i+1}: invalid date`);txns.push(Object.freeze({...r,tenantId,accountId,reference:r.reference.trim().toUpperCase()}))}return errors.length?{ok:false as const,errors}:{ok:true as const,transactions:Object.freeze(txns)}}