سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 03:00 UTC
fix(accounting): block reversal-of-reversal in manual journal UI
davoodmehraban89 committed
Nov 16, 2026 at 07:12 UTC
36a0f727ab29a2e4f00d557c0b4b90bc733456c9
3 files changed
+9
-1
js/journal-rpc.js
+1
@@ -107,6 +107,7 @@ async function jeRpcReverse(voucherId,date,reason){
107
if(!requireWrite())throw new Error('مجوز برگشت سند ندارید.');
108
const org=await jeRpcAssertContext(),v=getMyJournalVouchers().find(x=>x.id===voucherId);
109
if(!v||v.status!=='posted')throw new Error('سند قطعی در سازمان فعال پیدا نشد.');
110
+ if(v.sourceType==='reversal'||v.voucherType==='reversal')throw new Error('سند معکوس را نمیتوان دوباره معکوس کرد؛ برای اصلاح، سند تعدیلی مستقل ثبت کنید.');
111
await jeRpcRefreshEffectiveStatuses();
112
const effective=jeRpcEffectiveStatus(v);
113
if(effective!=='posted')throw new Error(effective==='reversed'?'این سند قبلاً بهطور کامل برگشت شده است.':'این سند قبلاً برگشت جزئی داشته؛ برای برگشت مانده، تخصیص جزئی لازم است.');
js/journal-ui.js
+2
-1
@@ -54,7 +54,7 @@ async function jePostUi(id){try{await jeRpcPost(id);renderJournal()}catch(e){ale
54
async function jeReverseUi(id){const why=prompt('علت برگشت سند:','اصلاح ثبت');if(why===null)return;try{await jeRpcReverse(id,getJalaliNumeric(),why);renderJournal()}catch(e){alert(e.message)}}
55
async function jeCopyVoucherUi(id){try{const v=await jeRpcCopyVoucher(id,getJalaliNumeric());alert('کپی سند در سرور بهصورت پیشنویس ایجاد شد.');renderJournal()}catch(e){alert(e.message)}}
56
async function jeDeleteUi(id){if(!confirm('پیشنویس حذف شود؟'))return;try{await jeRpcDeleteDraft(id);renderJournal()}catch(e){alert(e.message)}}
57
-function jeStatusLabel(v){return v==='draft'?'پیشنویس':v==='posted'?'قطعی':v==='reversed'?'برگشتشده':v}
57
+function jeStatusLabel(v){return v==='draft'?'پیشنویس':v==='posted'?'قطعی':v==='reversed'?'برگشتشده':v==='partially_reversed'?'برگشت جزئی':v}
58
function jeTypeLabel(v){return({manual:'عادی',adjustment:'اصلاحی',opening:'افتتاحیه',closing:'اختتامیه',copy:'کپی',reversal:'برگشت'})[v]||v||'عادی'}
59
function jeJournalActions(v,status){
60
const sourceType=v.sourceType||'manual';
@@ -63,6 +63,7 @@ function jeJournalActions(v,status){
63
return '<button class="btn btn-success btn-inline" onclick="jePostUi(\''+v.id+'\')">قطعی</button> <button class="btn btn-secondary btn-inline" onclick="jeLoadDraftUi(\''+v.id+'\')">ویرایش موقت</button> <button class="btn btn-danger btn-inline" onclick="jeDeleteUi(\''+v.id+'\')">حذف موقت</button> ';
64
}
65
if(status==='posted'){
66
+ if(sourceType==='reversal'||v.voucherType==='reversal')return '<span class="af-hint">سند معکوس؛ اصلاح فقط با سند تعدیلی مستقل</span> ';
67
if(sourceType==='manual'&&!v.sourceId)return '<button class="btn btn-secondary btn-inline" onclick="jeCancelPostedUi(\''+v.id+'\')">ابطال / سند معکوس</button> ';
68
return '<button class="btn btn-secondary btn-inline" onclick="jeReverseUi(\''+v.id+'\')">سند معکوس</button> ';
69
}
scripts/journal-rpc-adapter.test.mjs
+6
@@ -75,6 +75,12 @@ test('reverse is rejected after full/partial reversal and only sends null alloca
75
assert.equal(partial.calls.length,0);
76
});
77
78
+test('a reversal voucher cannot itself be reversed from the manual journal UI adapter',async()=>{
79
+ const h=harness({vouchers:[{id:'JV_REV',status:'posted',sourceType:'reversal',voucherType:'reversal',_serverVersion:5}]});
80
+ await assert.rejects(()=>h.context.jeRpcReverse('JV_REV','1405/07/19','reason'),/نمیتوان دوباره معکوس کرد/);
81
+ assert.equal(h.calls.length,0);
82
+});
83
+
84
test('fresh membership and pending generic sync are hard preconditions before mutation',async()=>{
85
const revoked=harness({failMembership:true});
86
await assert.rejects(()=>revoked.context.jeRpcCreateDraft({date:'1405/07/19',lines:[{accountId:'A1',debit:1,credit:0},{accountId:'A2',debit:0,credit:1}]}),/عضویت فعال/);