@davoodmehraban89 / Factor-easy / commits / 357b42d
Fork 0

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

feat: make purchase deletion cascade-aware

davoodmehraban89 committed Nov 18, 2026 at 09:00 UTC 357b42d1461de770255884c3599c5b45eb944c69
1 file changed +4 -2
js/purchases.js
+4 -2
@@ -205,7 +205,9 @@
205 window.deletePurchasePilotDraft=function(id){
206 if(!requireWrite())throw new Error('مجوز حذف ندارید.');
207 const p=myPurchases().find(x=>x.id===id&&x.companyId===afCompanyId());
208 - if(!p||purchaseDocumentStatus(p)!=='draft'||p.journalVoucherId||p.accountingPostingPending)throw new Error('تنها پیش‌نویس بدون ثبت حسابداری یا درخواست معلق قابل حذف است.');
208 + if(!p||purchaseDocumentStatus(p)!=='draft'||p.accountingPostingPending)throw new Error('تنها سند موقت بدون درخواست معلق قابل حذف است.');
209 + const linkedVoucher=p.journalVoucherId&&typeof jeSourceVoucher==='function'?jeSourceVoucher(p):null;
210 + if(linkedVoucher?.status&&linkedVoucher.status!=='draft')throw new Error('سند حسابداری این خرید قطعی شده و حذف مستقیم مجاز نیست.');
211 if(getMyPayments().some(x=>x.invoiceType==='purchase'&&x.invoiceId===id))throw new Error('خرید دارای تسویه است.');
212 datastore.purchases=datastore.purchases.filter(x=>x.id!==id);saveDatastore();refreshAllSurfaces();return true;
213 };
@@ -233,7 +235,7 @@
235 catch(e){alert('قطعی‌سازی تأیید نشد: '+e.message);}
236 };
237 window.purDeleteDraftUi=function(id){
236 - if(!confirm('پیش‌نویس خرید بدون سند حسابداری حذف شود؟'))return;
238 + if(!confirm('فاکتور خرید موقت حذف شود؟'+(myPurchases().find(x=>x.id===id)?.journalVoucherId?'\nسند حسابداری موقت وابسته نیز همزمان حذف خواهد شد.':'') ))return;
239 try{deletePurchasePilotDraft(id);}catch(e){alert(e.message);}
240 };
241