سامانه صدور فاکتور و حسابداری
test(finora): reconcile actual journal and reporting read projections
davoodmehraban89 committed
Nov 25, 2026 at 06:31 UTC
65acbb13118fa7133125cb3d9b22cccb0b7aab24
1 file changed
+51
-1
scripts/phase6-behavior-check.mjs
+51
-1
@@ -10,4 +10,54 @@ const cut=P.legacyCutoverPreview();if(cut.length!==1||cut[0].readiness!=='ready'
10
const dr=P.rollup().reduce((s,x)=>s+x.debit,0),cr=P.rollup().reduce((s,x)=>s+x.credit,0);if(dr!==cr)throw new Error('trial balance mismatch');
11
console.log('Phase 6 reporting/reconciliation scenarios passed.');
12
const perfVoucher={id:'VP',number:'P',date:'1405/01/15',status:'posted',sourceType:'performance'};const baseLen=rows.length;for(let i=0;i<10000;i++){rows.push({id:'PD'+i,voucherId:'VP',accountId:'A3',debit:1,credit:0,voucher:perfVoucher,account:accounts[2]},{id:'PC'+i,voucherId:'VP',accountId:'A2',debit:0,credit:1,voucher:perfVoucher,account:accounts[1]})}
13
-const perfStart=Date.now(),perfRoll=P.rollup('1405/01/01','1405/01/31'),perfFin=P.financials('1405/01/01','1405/01/31'),perfLedger=P.ledger({from:'1405/01/01',to:'1405/01/31'}),perfMs=Date.now()-perfStart;if(perfRoll.reduce((s,x)=>s+x.debit,0)!==perfRoll.reduce((s,x)=>s+x.credit,0))throw new Error('large-dataset trial balance mismatch');if(perfFin.revenue!==10100||perfFin.expense!==10030||perfFin.profit!==70)throw new Error('large-dataset financial report mismatch');if(perfLedger.length!==20006)throw new Error('large-dataset ledger row loss: expected 20006, got '+perfLedger.length);if(perfMs>5000)throw new Error('large-dataset reporting performance regression: '+perfMs+'ms for '+perfLedger.length+' rows');console.log('Phase 6 20k-line reporting performance passed in '+perfMs+'ms.');
\ No newline at end of file
13
+const perfStart=Date.now(),perfRoll=P.rollup('1405/01/01','1405/01/31'),perfFin=P.financials('1405/01/01','1405/01/31'),perfLedger=P.ledger({from:'1405/01/01',to:'1405/01/31'}),perfMs=Date.now()-perfStart;if(perfRoll.reduce((s,x)=>s+x.debit,0)!==perfRoll.reduce((s,x)=>s+x.credit,0))throw new Error('large-dataset trial balance mismatch');if(perfFin.revenue!==10100||perfFin.expense!==10030||perfFin.profit!==70)throw new Error('large-dataset financial report mismatch');if(perfLedger.length!==20006)throw new Error('large-dataset ledger row loss: expected 20006, got '+perfLedger.length);if(perfMs>5000)throw new Error('large-dataset reporting performance regression: '+perfMs+'ms for '+perfLedger.length+' rows');console.log('Phase 6 20k-line reporting performance passed in '+perfMs+'ms.');
14
+
15
+ // G01: exercise the actual journal read projection rather than a pre-filtered
16
+ // jeLedgerRows stub. Synthetic historical rows only: no save/post operations.
17
+ {
18
+ const ownerUserId='G01_QA',companyId='G01_COMPANY';
19
+ const book={journalVouchers:[],journalLines:[],journalLineDimensions:[]};
20
+ const a=[
21
+ {id:'AR',code:'1102',title:'Receivable',accountType:'asset',postingAllowed:true},
22
+ {id:'REV',code:'4101',title:'Revenue',accountType:'revenue',postingAllowed:true},
23
+ {id:'EXP',code:'5101',title:'Expense',accountType:'expense',postingAllowed:true},
24
+ {id:'AP',code:'2101',title:'Payable',accountType:'liability',postingAllowed:true}
25
+ ];
26
+ const add=(id,date,status,amount,debitAccount,creditAccount)=>{
27
+ book.journalVouchers.push({id,number:id,date,status,ownerUserId,companyId,totalDebit:amount,totalCredit:amount});
28
+ book.journalLines.push({id:id+'D',voucherId:id,accountId:debitAccount,debit:amount,credit:0,ownerUserId,companyId},
29
+ {id:id+'C',voucherId:id,accountId:creditAccount,debit:0,credit:amount,ownerUserId,companyId});
30
+ };
31
+ add('SALE','1405/01/01','reversed',100,'AR','REV');
32
+ add('PURCHASE','1405/01/02','posted',170,'EXP','AP');
33
+ add('REVERSAL','1405/01/03','posted',100,'REV','AR');
34
+ add('REPLACEMENT','1405/01/03','posted',120,'AR','REV');
35
+ add('DRAFT','1405/01/04','draft',999,'AR','REV');
36
+ const before=JSON.stringify(book);
37
+ const actual={window:{},console,datastore:book,currentUser:{id:ownerUserId},afCompanyId:()=>companyId,getMyAccounts:()=>a};
38
+ vm.createContext(actual);
39
+ vm.runInContext(fs.readFileSync('js/journal-engine.js','utf8'),actual);
40
+ vm.runInContext(fs.readFileSync('js/phase6-reporting.js','utf8'),actual);
41
+ const reports=actual.window.P6Reports;
42
+ const check=(label,got,want)=>{
43
+ if(JSON.stringify(got)!==JSON.stringify(want))throw new Error('G01 '+label+': '+JSON.stringify({got,want}));
44
+ };
45
+ const result=(from,to)=>{
46
+ const f=reports.financials(from,to);
47
+ return {revenue:f.revenue,expense:f.expense,profit:f.profit,assets:f.assets,liabilities:f.liabilities,
48
+ debit:f.trial.reduce((s,x)=>s+x.debit,0),credit:f.trial.reduce((s,x)=>s+x.credit,0)};
49
+ };
50
+ check('before correction',result('1405/01/01','1405/01/02'),
51
+ {revenue:100,expense:170,profit:-70,assets:100,liabilities:170,debit:270,credit:270});
52
+ check('after reversal and replacement',result('1405/01/01','1405/01/04'),
53
+ {revenue:120,expense:170,profit:-50,assets:120,liabilities:170,debit:490,credit:490});
54
+ const ledger=reports.ledger({});
55
+ check('effective voucher IDs',[...new Set(ledger.map(x=>x.voucherId))].sort(),['PURCHASE','REPLACEMENT','REVERSAL','SALE']);
56
+ check('effective line count',ledger.length,8);
57
+ check('account balances',reports.rollup().map(x=>[x.accountId,x.balance]),
58
+ [['AR',120],['AP',-170],['REV',-120],['EXP',170]]);
59
+ check('draft only date',result('1405/01/04','1405/01/04'),
60
+ {revenue:0,expense:0,profit:0,assets:0,liabilities:0,debit:0,credit:0});
61
+ check('read projection preserves journal input',JSON.stringify(book),before);
62
+ console.log('G01 actual journal/report reconciliation passed: draft exclusion, reversal, replacement, date range and read-only input.');
63
+ }