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

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

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

Synced Dec 3, 22:00 UTC

feat: delete linked draft voucher through source document

davoodmehraban89 committed Nov 18, 2026 at 09:00 UTC 609e76416e45830b6fb0642c56e79bf76aa2ce5c
1 file changed +5 -2
js/invoices.js
+5 -2
@@ -500,9 +500,12 @@ async function cancelPostedInvoicePilot(invoiceId,reason){
500 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 + const linkedVoucher=inv.journalVoucherId&&typeof jeSourceVoucher==='function'?jeSourceVoucher(inv):null;
507 + if(linkedVoucher?.status&&linkedVoucher.status!=='draft')throw new Error('سند حسابداری این فاکتور قطعی شده و حذف مستقیم مجاز نیست.');
508 + if(linkedVoucher&&!confirm('این فاکتور خرید/فروش به یک سند حسابداری موقت متصل است. با حذف فاکتور، سند حسابداری وابسته نیز همزمان حذف می‌شود. ادامه می‌دهید؟'))return;
509 if(typeof getMyPayments==='function'&&getMyPayments().some(p=>p.invoiceId===inv.id||p.sourceInvoiceId===inv.id||p.relatedInvoiceId===inv.id))
510 throw new Error('این فاکتور ارجاع دریافت/پرداخت دارد و قابل حذف نیست.');
511 datastore.invoices=datastore.invoices.filter(x=>x.id!==inv.id);