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

fix(A05): reject disabled treasury accounts in transfers, expenses and cheque clearance

Integrated retail ledger now honors isActive:false on both internal transfer endpoints, cash expense posting, and cheque clearing (including explicit destination account). Real installed NSIS/Tauri/WebView2 tested blocked transfer and cheque settlement without partial writes, followed by valid single cheque clearance through native UI; required 12 financial cases, crash restore, offline RTL PDF and 60k IndexedDB baseline remained green. Verified PR Quality #38963640313 (193/193 Node tests, Vite, audit, Windows NSIS) and Native Windows #38963640187, artifact #12074411460. A05 and INDEPENDENT_QA remain unaccepted; no user data or release.

davoodmehraban89 committed Oct 17, 2026 at 00:15 UTC ede489ccdc892d58817e7cde88269d0559bd87e5
4 files changed +138 -3
scripts/windows-vm-native-lab.ps1
+1
@@ -170,6 +170,7 @@ try {
170 'positive-opening-ledger-and-idempotency',
171 'purchase-and-post-ledger',
172 'partial-sale-and-inventory',
173 + 'inactive-treasury-cheque-settlement',
174 'sale-return-immutable-stock-and-ledger',
175 'purchase-return-and-stock-guardrails',
176 'append-only-history-bulk-clear-protection',
src/core/RetailPostingService.js
+7 -3
@@ -422,6 +422,8 @@ class RetailPostingServiceImpl {
422 ctx.companyId,'حساب مبدا');
423 const to=sameCompany(all.find(a=>a.id===info.toAccountId&&a.recordType==='account'),
424 ctx.companyId,'حساب مقصد');
425 + if(from.isActive===false||to.isActive===false)
426 + throw Error('انتقال بین حساب‌های بانکی/صندوق غیرفعال مجاز نیست');
427 if(from.id===to.id)throw Error('حساب مبدا و مقصد باید متفاوت باشند');
428 const mapping=account=>cashLedger(ctx,account);
429 const id=info.transactionId||uid('tx_');
@@ -453,7 +455,8 @@ class RetailPostingServiceImpl {
455 if(await tx.get('expenses',row.id))throw Error('سند هزینه/درآمد تکراری است');
456 const sum=positiveAmount(row.amount);
457 if(row.method==='cheque')throw Error('هزینه یا درآمد چکی را در بخش چک‌ها ثبت کنید');
456 - const cash=(await tx.getAll('treasury')).filter(a=>a.companyId===company&&a.recordType==='account');
458 + const cash=(await tx.getAll('treasury')).filter(a=>a.companyId===company&&
459 + a.recordType==='account'&&a.isActive!==false);
460 const selected=cash.find(a=>a.isDefault)||cash[0];
461 if(!selected)throw Error('صندوق یا بانک برای ثبت هزینه/درآمد موجود نیست');
462 const cashLedgerId=cashLedger(ctx,selected);
@@ -508,9 +511,10 @@ class RetailPostingServiceImpl {
511 const ctx=await this.context(tx,company,options.date||cheque.dueDate);
512 const sum=amount(cheque.amount),inbound=cheque.direction==='inbound';
513 const ref={contactId:cheque.contactId};
511 - const accounts=(await tx.getAll('treasury')).filter(a=>a.companyId===company&&a.recordType==='account');
514 + const accounts=(await tx.getAll('treasury')).filter(a=>a.companyId===company&&
515 + a.recordType==='account'&&a.isActive!==false);
516 if(options.accountId&&!accounts.some(a=>a.id===options.accountId))
513 - throw Error('حساب بانکی انتخاب‌شده در شرکت فعال وجود ندارد');
517 + throw Error('حساب بانکی انتخاب‌شده فعال نیست یا در شرکت فعال وجود ندارد');
518 const bank=accounts.find(a=>a.id===options.accountId)||accounts.find(a=>a.isDefault)||accounts[0];
519 if(status==='cleared'&&!bank)throw Error('حساب بانک یا صندوق برای وصول چک مشخص نیست');
520 const bankLedger=status==='cleared'?cashLedger(ctx,bank):null;
tests/retail-phase2.test.mjs
+52
@@ -484,3 +484,55 @@ test('A01: successive returns cannot exceed original gross even if total quantit
484 await assert.rejects(retail.issueInvoice(excessive), /مجموع مبلغ مرجوعی/);
485 assert.equal((await db.getAll('document_corrections')).length, 1);
486 });
487 +
488 +test('A05: inactive treasury accounts reject transfers, expenses and cheque clearance atomically',async()=>{
489 + await setup();await purchase10();await sale3();
490 + const active=await db.get('treasury','cash-1');
491 + const second=await retail.createTreasuryAccount({
492 + id:'disabled-a05',companyId:company,recordType:'account',
493 + type:'bank',name:'بانک مسدود',ownerUserId:'phase2-admin',
494 + initialBalance:0,isActive:true,isDefault:false
495 + });
496 + await db.put('treasury',{...second,isActive:false});
497 + const count=(name)=>db.getAll(name).then(rows=>rows.length);
498 + const before={journals:await count('journal_entries'),money:await count('treasury')};
499 + for(const [id,fromAccountId,toAccountId] of [
500 + ['disabled-transfer-to',active.id,second.id],
501 + ['disabled-transfer-from',second.id,active.id]
502 + ]){
503 + await assert.rejects(retail.postTransaction({
504 + id,type:'transfer',date,amount:45,fromAccountId,toAccountId
505 + }),/غیرفعال/);
506 + assert.equal(await db.get('treasury',id),undefined);
507 + }
508 + assert.equal(await count('journal_entries'),before.journals);
509 + assert.equal(await count('treasury'),before.money);
510 + await db.put('treasury',{...active,isActive:false});
511 + await assert.rejects(retail.postExpense({
512 + id:'disabled-expense',kind:'expense',date,amount:60,method:'cash',category:'تست'
513 + }),/صندوق یا بانک/);
514 + assert.equal(await db.get('expenses','disabled-expense'),undefined);
515 + await db.put('treasury',active);
516 + const cheque=await retail.postCheque({
517 + id:'disabled-cheque',direction:'inbound',status:'pending',
518 + issueDate:date,dueDate:date,contactId:'contact-1',amount:120,
519 + chequeNumber:'A05'
520 + });
521 + const preClear=await count('journal_entries');
522 + await assert.rejects(retail.changeChequeStatus(cheque.id,'cleared',{
523 + date,accountId:second.id
524 + }),/فعال نیست/);
525 + assert.equal((await db.get('cheques',cheque.id)).status,'pending');
526 + assert.equal(await count('journal_entries'),preClear);
527 + assert.equal((await db.getAll('treasury')).filter(x=>x.refChequeId===cheque.id).length,0);
528 + const cleared=await retail.changeChequeStatus(cheque.id,'cleared',{
529 + date,accountId:active.id
530 + });
531 + assert.equal(cleared.status,'cleared');
532 + await assert.rejects(retail.changeChequeStatus(cheque.id,'cleared',{
533 + date,accountId:active.id
534 + }),/در جریان/);
535 + assert.equal((await db.getAll('treasury')).filter(x=>x.refChequeId===cheque.id).length,1);
536 + const balance=await accounts.trialBalance();
537 + assert.equal(balance.totals.debit,balance.totals.credit);
538 +});
tests/windows-vm-native-functional-matrix.cjs
+78
@@ -482,6 +482,83 @@ async function nativeHistoryClearFailClosed() {
482 historyUnchanged: true };
483 }
484
485 +async function nativeInactiveBankSettlementGuard() {
486 + const wait=ms=>new Promise(r=>setTimeout(r,ms));
487 + const check=(ok,msg)=>{if(!ok)throw Error(msg);};
488 + const db=FINORA.Storage,company=await FINORA.Company.current();
489 + check(company?.id&&FINORA.Auth.isAdmin(),'A05 native admin required');
490 + const contact=(await db.getAll('contacts')).find(c=>c.companyId===company.id&&c.name==='مشتری آزمایشی ویندوز');
491 + const active=(await db.getAll('treasury')).find(x=>x.companyId===company.id&&x.recordType==='account'&&x.ledgerAccountId&&x.isActive!==false);
492 + check(contact&&active,'Treasury fixtures absent');
493 + await FINORA.Router.go('treasury');await wait(180);
494 + const tv=window.TreasuryView;
495 + await tv.openAccountModal();
496 + document.getElementById('accName').value='VM-only inactive bank A05';
497 + document.getElementById('accInitialBalance').value='0';
498 + await tv.saveAccount(null);
499 + const secondary=(await db.getAll('treasury')).find(x=>
500 + x.companyId===company.id&&x.recordType==='account'&&x.name==='VM-only inactive bank A05');
501 + check(secondary?.ledgerAccountId,'Actual treasury account creation failed');
502 + await db.put('treasury',{...secondary,isActive:false});
503 + const counts=async()=>({
504 + journals:(await db.getAll('journal_entries')).length,
505 + payments:(await db.getAll('treasury')).filter(x=>x.recordType==='transaction').length
506 + });
507 + const before=await counts();
508 + tv.openTransferModal();
509 + check(document.getElementById('txToAccount'),'Native transfer form not open');
510 + document.getElementById('txDate').value='1405/07/18';
511 + document.getElementById('txAmount').value='40';
512 + document.getElementById('txFromAccount').value=active.id;
513 + document.getElementById('txToAccount').value=secondary.id;
514 + await tv._saveTransaction('transfer');
515 + let toast=[...document.querySelectorAll('.toast-error')].find(x=>x.textContent.includes('غیرفعال'));
516 + check(toast,'Inactive bank transfer did not display rejection');
517 + check(JSON.stringify(await counts())===JSON.stringify(before),'Rejected transfer wrote journals or cash');
518 + toast.querySelector('.toast-close')?.click();
519 + FINORA.Modal.close();
520 + check(!document.querySelector('.toast-error'),'Expected transfer toast not dismissed');
521 +
522 + // With no active bank, the real cheque status UI must reject settlement
523 + // without changing posted status or writing a cash receipt.
524 + await db.put('treasury',{...active,isActive:false});
525 + await FINORA.Router.go('cheques');await wait(200);
526 + const cv=window.ChequesView;
527 + await cv.openChequeModal();
528 + check(document.getElementById('chqSayad'),'Native cheque form absent');
529 + document.getElementById('chqDirection').value='inbound';
530 + document.getElementById('chqContact').value=contact.id;
531 + document.getElementById('chqSayad').value='1234567890123489';
532 + document.getElementById('chqAmount').value='90';
533 + document.getElementById('chqIssueDate').value='1405/07/18';
534 + document.getElementById('chqDueDate').value='1405/07/18';
535 + await cv.saveCheque(null);
536 + const cheque=(await db.getAll('cheques')).find(x=>x.companyId===company.id&&x.sayadNumber==='1234567890123489');
537 + check(cheque?.financePosted&&cheque.status==='pending','Native cheque posting failed');
538 + const journalCount=(await db.getAll('journal_entries')).length;
539 + await cv.changeStatus(cheque.id);
540 + check(document.getElementById('newStatus'),'Cheque status form missing');
541 + document.getElementById('newStatus').value='cleared';
542 + await cv._applyStatusChange(cheque.id);
543 + toast=[...document.querySelectorAll('.toast-error')].find(x=>
544 + x.textContent.includes('حساب بانک یا صندوق برای وصول چک مشخص نیست'));
545 + check(toast,'Cheque clearing with all banks inactive did not reject');
546 + check((await db.get('cheques',cheque.id)).status==='pending'&&
547 + (await db.getAll('journal_entries')).length===journalCount&&
548 + !(await db.getAll('treasury')).some(t=>t.refChequeId===cheque.id),
549 + 'Rejected cheque clearance modified ledger or treasury');
550 + toast.querySelector('.toast-close')?.click();
551 + await db.put('treasury',active);
552 + await cv._applyStatusChange(cheque.id);
553 + check((await db.get('cheques',cheque.id)).status==='cleared'&&
554 + (await db.getAll('treasury')).filter(t=>t.refChequeId===cheque.id).length===1,
555 + 'Restoring active bank did not clear cheque exactly once');
556 + check(!document.querySelector('.toast-error')&&!document.querySelector('.modal-backdrop'),
557 + 'A05 native treasury scenario left error toast/modal');
558 + return { inactiveTransferRejected:true, invalidTransferRolledBack:true,
559 + disabledChequeClearingRejected:true, validChequeClearedExactlyOnce:true };
560 +}
561 +
562 async function nativeBackupRestore() {
563 const check = (value, message) => { if (!value) throw Error(message); };
564 const S = FINORA.Storage;
@@ -743,6 +820,7 @@ module.exports = async function nativeFunctionalMatrix(cdp) {
820 ['positive-opening-ledger-and-idempotency', nativePositiveOpeningLedger],
821 ['purchase-and-post-ledger', purchaseInvoice],
822 ['partial-sale-and-inventory', saleInvoice],
823 + ['inactive-treasury-cheque-settlement', nativeInactiveBankSettlementGuard],
824 ['sale-return-immutable-stock-and-ledger', nativeSaleReturnGuardrails],
825 ['purchase-return-and-stock-guardrails', nativePurchaseReturnGuardrails],
826 ['append-only-history-bulk-clear-protection', nativeHistoryClearFailClosed],