@davoodmehraban89 / Factor-easy / commits / d65a4f7
Fork 0

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

feat(sales): atomically delete draft invoice and linked voucher

davoodmehraban89 committed Nov 18, 2026 at 09:06 UTC d65a4f72af45cfee9dc2835e02a5d92594223f23
1 file changed +13 -5
js/invoices.js
+13 -5
@@ -497,16 +497,24 @@ async function cancelPostedInvoicePilot(invoiceId,reason){
497 await invoicePilotAwaitSync(['journalVouchers|'+v.id,'journalVouchers|'+reversal.id]);
498 refreshAllSurfaces();return reversal.id;
499 }
500 -function deleteInvoicePilotDraft(invoiceId){
500 +async function deleteInvoicePilotDraft(invoiceId){
501 if(!requireWrite())throw new Error('مجوز حذف ندارید.');
502 const inv=getMyInvoices().find(x=>x.id===invoiceId);
503 - if(!inv||inv.ownerUserId!==currentUser?.id||inv.companyId!==afCompanyId()||invoiceDocumentStatus(inv)!=='draft'||inv.journalVoucherId||inv.accountingPostingPending)
504 - throw new Error('فقط پیش‌نویس ثبت‌نشده همین شرکت قابل حذف است.');
503 + if(!inv||inv.ownerUserId!==currentUser?.id||inv.companyId!==afCompanyId()||invoiceDocumentStatus(inv)!=='draft'||inv.accountingPostingPending)
504 + throw new Error('فقط فاکتور موقت و بدون عملیات حسابداری معلق قابل حذف است.');
505 if(inv.electronicDoc)throw new Error('سند الکترونیکی مرتبط ابتدا باید بررسی شود.');
506 if(typeof getMyPayments==='function'&&getMyPayments().some(p=>p.invoiceId===inv.id||p.sourceInvoiceId===inv.id||p.relatedInvoiceId===inv.id))
507 throw new Error('این فاکتور ارجاع دریافت/پرداخت دارد و قابل حذف نیست.');
508 - datastore.invoices=datastore.invoices.filter(x=>x.id!==inv.id);
509 - saveDatastore();refreshAllSurfaces();return true;
508 + if(!confirm('این فاکتور در وضعیت موقت است و سند حسابداری موقت آن نیز وجود دارد. هر دو مورد با هم حذف و شماره عطف برای همیشه در سابقه حذف ثبت می‌شود. ادامه می‌دهید؟'))return false;
509 + const reason=prompt('علت حذف فاکتور و سند حسابداری را وارد کنید:','حذف سند موقت');
510 + if(reason===null)return false;
511 + if(inv.journalVoucherId&&typeof jeRpcDeleteSourceDraft==='function'){
512 + await jeRpcDeleteSourceDraft('sale',inv.id,reason);
513 + }else{
514 + datastore.invoices=datastore.invoices.filter(x=>x.id!==inv.id);
515 + saveDatastore();refreshAllSurfaces();
516 + }
517 + return true;
518 }
519 function commitSaveInvoice(){
520 if(!requireWrite())return;