Treasury & Bank Transfer Management System — سامانه مدیریت خزانهداری و حوالههای بانکی
ci/windows-dual-app-lab-20261016
ci/public-windows-bridge-probe-20261017
ci/windows-dispatch-bootstrap-20261016
ci/windows-dual-app-lab-20261016
dev/v7-production-failclosed-20261021
feature/reconciliation-guard-20261013
main
phase-1-foundation
phase-1-implementation
phase-2-treasury-core
phase-3-banking-reconciliation
phase-4-operations-enterprise-ux
phase-5-hardening-release
phase-6-production-platform
phase-7-production-infrastructure-bank-golive
phase-7-sql-readonly-ux-20261015
transfer-exe-to-drive-20261006
| 1 | // Safely compare sanitized runtime captures. Synthetic fixtures are not proof of application parity. |
| 2 | export function meaningOfMayan(row) { |
| 3 | if (row.status === 4 && row.isError === false && |
| 4 | row.insertResult?.error === false && Number(row.insertResult?.errorCode) === 200 && |
| 5 | typeof row.insertResult?.issueId === 'string' && row.insertResult.issueId.length > 0) |
| 6 | return 'API_ACCEPTED_NOT_SETTLED'; |
| 7 | if (row.status === 1 && row.isError !== true) return 'NO_BANK_ACCEPTANCE_PROOF'; |
| 8 | if (row.status === 3 && row.isError === true) return 'ERROR_REQUIRES_REVIEW'; |
| 9 | return 'CONFLICT_REQUIRES_REVIEW'; |
| 10 | } |
| 11 | export function compareMayanTreasuryRuntime(mayan, treasury) { |
| 12 | if (mayan?.source !== 'MAYAN_RUNTIME_CAPTURE' || |
| 13 | treasury?.source !== 'TREASURY_RUNTIME_CAPTURE' || |
| 14 | mayan.currency !== 'IRR' || treasury.currency !== 'IRR' || |
| 15 | !Array.isArray(mayan.rows) || !Array.isArray(treasury.rows)) throw Error('VERIFIED_SANITIZED_RUNTIME_CAPTURES_REQUIRED'); |
| 16 | const diff = [], m = new Map(), t = new Map(); |
| 17 | for (const row of mayan.rows) { |
| 18 | if (typeof row.caseId !== 'string' || !/^[A-Z0-9_-]{1,64}$/.test(row.caseId) || m.has(row.caseId)) |
| 19 | throw Error('MAYAN_CASE_ID_NOT_UNIQUE'); |
| 20 | m.set(row.caseId, row); |
| 21 | } |
| 22 | for (const row of treasury.rows) { |
| 23 | if (typeof row.caseId !== 'string' || !/^[A-Z0-9_-]{1,64}$/.test(row.caseId) || t.has(row.caseId)) |
| 24 | throw Error('TREASURY_CASE_ID_NOT_UNIQUE'); |
| 25 | t.set(row.caseId, row); |
| 26 | } |
| 27 | for (const [caseId,row] of m) { |
| 28 | const out = t.get(caseId); |
| 29 | if (!out) {diff.push({caseId,code:'MISSING_TREASURY_ROW'});continue;} |
| 30 | const monetary = value => typeof value === 'string' && /^[1-9][0-9]*$/.test(value); |
| 31 | if (!monetary(row.amountIrr) || !monetary(out.amountIrr)) throw Error('IRR_UNIT_OR_INTEGER_UNVERIFIED'); |
| 32 | if (row.amountIrr !== out.amountIrr) diff.push({caseId,code:'AMOUNT_IRR_MISMATCH'}); |
| 33 | for (const f of ['paymentIdentifier','depositIdentifier']) |
| 34 | if (String(row[f]??'') !== String(out[f]??'')) diff.push({caseId,code:'IDENTIFIER_MISMATCH',field:f}); |
| 35 | const meaning = meaningOfMayan(row); |
| 36 | if (meaning === 'API_ACCEPTED_NOT_SETTLED' && out.state !== 'SUBMITTED') |
| 37 | diff.push({caseId,code:'ACCEPTANCE_WRONGLY_PROMOTED_TO_SETTLEMENT_OR_OTHER'}); |
| 38 | if (meaning !== 'API_ACCEPTED_NOT_SETTLED' && ['SUBMITTED','SETTLED'].includes(out.state)) |
| 39 | diff.push({caseId,code:'UNPROVEN_BANK_DISPATCH_OR_SETTLEMENT'}); |
| 40 | } |
| 41 | for (const id of t.keys()) if (!m.has(id)) diff.push({caseId:id,code:'EXTRA_TREASURY_ROW'}); |
| 42 | return {passed:diff.length===0,total:m.size,differences:diff}; |
| 43 | } |