سامانه صدور فاکتور و حسابداری
feat: route source draft deletion through lifecycle RPC
davoodmehraban89 committed
Nov 18, 2026 at 08:59 UTC
8c94330ab8c78c72f992ee3a1c88b573055baf88
1 file changed
+17
-3
js/journal-rpc.js
+17
-3
@@ -118,7 +118,7 @@ async function jeRpcPost(voucherId){
118
async function jeRpcDeleteDraft(voucherId){
119
if(!requireWrite())throw new Error('مجوز حذف پیشنویس ندارید.');
120
const org=await jeRpcAssertContext(),v=getMyJournalVouchers().find(x=>x.id===voucherId);
121
- if(!v||v.status!=='draft'||(v.sourceType||'manual')!=='manual')throw new Error('فقط پیشنویس دستی قابل حذف است.');
121
+ if(!v||v.status!=='draft'||(v.sourceType||'manual')!=='manual')throw new Error('فقط پیشنویس دستیِ مستقل قابل حذف است؛ سند منبع را از خود منبع حذف کنید.');
122
if(!Number.isInteger(Number(v._serverVersion)))throw new Error('نسخه معتبر سند در سرور پیدا نشد.');
123
const data=await jeRpcCall('finora_journal_delete_draft',{
124
p_organization_id:org,p_voucher_id:voucherId,p_expected_version:Number(v._serverVersion)
@@ -126,6 +126,20 @@ async function jeRpcDeleteDraft(voucherId){
126
await jeRpcRefresh(org);
127
return data;
128
}
129
+async function jeRpcDeleteSourceDraft(collection,documentId){
130
+ if(!requireWrite())throw new Error('مجوز حذف سند را ندارید.');
131
+ if(!['invoices','purchases'].includes(collection))throw new Error('حذف اتمیک این نوع سند هنوز فعال نشده است.');
132
+ const org=await jeRpcAssertContext();
133
+ const source=jeRpcSourceRecord(collection,documentId);
134
+ if(!source||source.ownerUserId!==currentUser.id||source.companyId!==afCompanyId())throw new Error('سند در شرکت فعال پیدا نشد.');
135
+ if(source.accountingPostingPending)throw new Error('نتیجه ثبت حسابداری این سند هنوز مشخص نیست؛ ابتدا وضعیت را تطبیق دهید.');
136
+ const data=await jeRpcCall('finora_document_delete_draft',{
137
+ p_organization_id:org,p_collection:collection,p_document_id:documentId,
138
+ p_expected_version:Number(source._serverVersion||0)
139
+ });
140
+ await jeRpcRefresh(org);
141
+ return data;
142
+}
143
async function jeRpcReverse(voucherId,date,reason){
144
if(!requireWrite())throw new Error('مجوز برگشت سند ندارید.');
145
const org=await jeRpcAssertContext(),reversalReason=String(reason||'').trim();
@@ -165,7 +179,7 @@ async function jeRpcReverse(voucherId,date,reason){
179
}
180
async function jeRpcCopyVoucher(voucherId,date){
181
const {voucher:v,lines}=jeVoucherDraftInput(voucherId);
168
- return jeRpcCreateDraft({date:date||getJalaliNumeric(),description:'کپی سند '+(v.number||v.id)+(v.description?' — '+v.description:''),
182
+ return jeRpcCreateDraft({date:date||getJalaliNumeric(),description:'کپی سند '+(v.number||v.temporaryNumber||v.atfNumber||v.id)+(v.description?' — '+v.description:''),
183
reference:v.reference||('سند '+(v.number||v.id)),voucherType:'manual',lines});
184
}
185
async function jeRpcReadGraph(voucherId){
@@ -287,4 +301,4 @@ async function jeRpcAutoPost(kind,sourceId){
301
}
302
return voucher;
303
}finally{jeRpcAutoPostBusy=false;}
290
-}
304
+}
\ No newline at end of file