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

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

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

Synced Dec 3, 22:00 UTC

feat: delete purchase drafts through atomic lifecycle RPC

davoodmehraban89 committed Nov 18, 2026 at 09:00 UTC eeafe20158cb0d995fd6dd14bfbefea3ca85522c
1 file changed +9 -6
js/purchases.js
+9 -6
@@ -202,12 +202,15 @@
202 if(typeof syncProductDefaultPrices==='function'&&syncProductDefaultPrices(savedPurchase.items,'purchase'))saveDatastore();
203 refreshAllSurfaces();return voucher.id;
204 };
205 - window.deletePurchasePilotDraft=function(id){
205 + window.deletePurchasePilotDraft=async 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')throw new Error('فقط پیش‌نویس همین شرکت قابل حذف است.');
209 + if(p.accountingPostingPending)throw new Error('نتیجه ثبت حسابداری این خرید هنوز مشخص نیست؛ ابتدا وضعیت را تطبیق دهید.');
210 if(getMyPayments().some(x=>x.invoiceType==='purchase'&&x.invoiceId===id))throw new Error('خرید دارای تسویه است.');
210 - datastore.purchases=datastore.purchases.filter(x=>x.id!==id);saveDatastore();refreshAllSurfaces();return true;
211 + const result=await jeRpcDeleteSourceDraft('purchases',id);
212 + refreshAllSurfaces();
213 + return result;
214 };
215 window.purReturnToDraftUi=async function(id){
216 const why=prompt('علت برگشت خرید قطعی به موقت:','اصلاح خرید دوره پایلوت');
@@ -233,8 +236,8 @@
236 catch(e){alert('قطعی‌سازی تأیید نشد: '+e.message);}
237 };
238 window.purDeleteDraftUi=function(id){
236 - if(!confirm('پیش‌نویس خرید بدون سند حسابداری حذف شود؟'))return;
237 - try{deletePurchasePilotDraft(id);}catch(e){alert(e.message);}
239 + if(!confirm('این فاکتور خرید موقت حذف شود؟\n\nاگر سند حسابداری موقت متصل داشته باشد، آن سند نیز هم‌زمان حذف می‌شود و سابقه حذف در لاگ باقی می‌ماند. شماره عطف هرگز دوباره استفاده نخواهد شد.'))return;
240 + try{await deletePurchasePilotDraft(id);}catch(e){alert(e.message);}
241 };
242
243 window.purAddRow=function(prodId,qty,price,unit){
@@ -456,4 +459,4 @@
459 window.refreshAllSurfaces=function(){oldRefresh.apply(this,arguments);try{render();}catch(e){console.error('purchases render',e);}};
460 document.addEventListener('DOMContentLoaded',injectUI);
461 injectUI();
459 -})();
462 +})();
\ No newline at end of file