@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 2c5cf0b
Fork 0

سامانه صدور فاکتور و حسابداری

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 23:15 UTC

feat(accounting): refresh source-linked draft through server RPC

davoodmehraban89 committed Nov 18, 2026 at 09:08 UTC 2c5cf0b6c5566a7f2163ca8bdaf2bc35d7c20101
1 file changed +18
js/journal-rpc.js
+18
@@ -220,6 +220,24 @@ async function jeRpcPersistSourceRecord(collection,id){
220 }
221 throw new Error('تأیید ذخیره رکورد منبع از سرور دریافت نشد؛ ثبت حسابداری انجام نشد یا وضعیت باید پس از بارگذاری مجدد بررسی شود.');
222 }
223 +async function jeRpcRefreshSourceDraft(kind,sourceId){
224 + if(!requireWrite())throw new Error('مجوز ویرایش پیش‌نویس حسابداری ندارید.');
225 + const collection=kind==='sale'?'invoices':kind==='purchase'?'purchases':'';
226 + if(!collection)throw new Error('نوع سند منبع برای به‌روزرسانی پشتیبانی نمی‌شود.');
227 + const org=await jeRpcAssertContext(),source=jeRpcSourceRecord(collection,sourceId);
228 + if(!source?.journalVoucherId)throw new Error('پیش‌نویس حسابداری مرتبط پیدا نشد.');
229 + const voucher=getMyJournalVouchers().find(v=>v.id===source.journalVoucherId);
230 + if(!voucher||voucher.status!=='draft'||!Number.isInteger(Number(voucher._serverVersion)))
231 + throw new Error('پیش‌نویس حسابداری معتبر یا نسخه سرور آن پیدا نشد.');
232 + await jeRpcPersistSourceRecord(collection,sourceId);
233 + const data=await jeRpcCall('finora_journal_refresh_source_draft',{
234 + p_organization_id:org,p_source_collection:collection,p_source_id:String(sourceId),
235 + p_expected_voucher_version:Number(voucher._serverVersion)
236 + });
237 + await jeRpcRefresh(org);
238 + return data?.voucher||getMyJournalVouchers().find(v=>v.id===source.journalVoucherId)||data;
239 +}
240 +
241 async function jeRpcDeleteSourceDraft(kind,sourceId,reason){
242 if(!requireWrite())throw new Error('مجوز حذف پیش‌نویس ندارید.');
243 const collection=kind==='sale'?'invoices':kind==='purchase'?'purchases':'';