فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

A08: replace per-cheque linear treasury lookup with single O(n) account index

davoodmehraban89 committed Oct 23, 2026 at 10:57 UTC 306ed2f9d01a5be6001ecab7d524a7129f08a76c
1 file changed +7 -2
src/core/ReconciliationCore.mjs
+7 -2
@@ -113,6 +113,12 @@ export function reconcileFinancialData({
113 // Only posted integrated cheques can be reconciled against double-entry GL.
114 if (integrated) {
115 const chequeById = new Map(cheques.map(row => [row.id, row]));
116 + // One account index for the entire report. A linear treasury.find for
117 + // every cleared cheque was O(cheques × treasury rows) and scaled poorly
118 + // when real stores have thousands of cheques and bank/cash records.
119 + const cashAccountById = new Map(transactions
120 + .filter(row => row.recordType === 'account')
121 + .map(row => [row.id, row]));
122 const moneyByCheque = new Map();
123 for (const transaction of transactions.filter(row =>
124 row.recordType === 'transaction' && row.refChequeId)) {
@@ -156,8 +162,7 @@ export function reconcileFinancialData({
162 // Older cleared cheques may lack this field; do not invent historical
163 // evidence or silently fabricate a clearing account for those rows.
164 if (cheque.clearingAccountId) {
159 - const selected = transactions.find(t => t.recordType === 'account' &&
160 - t.id === cheque.clearingAccountId);
165 + const selected = cashAccountById.get(cheque.clearingAccountId);
166 if (!selected) {
167 report('CHEQUE_CLEARING_ACCOUNT_MISSING',
168 'حساب انتخاب‌شده وصول چک در خزانه یافت نشد', cheque.id);