سامانه صدور فاکتور و حسابداری
Integrate settlements with Phase 3 automatic posting
davoodmehraban89 committed
Sep 28, 2026 at 18:33 UTC
365cfa11a0fe77a28ac45e3944ccb2d6762fb357
1 file changed
+3
-3
js/payments.js
+3
-3
@@ -58,7 +58,7 @@ function commitSavePayment(){
58
let outstanding=Infinity;
59
if(invoiceId&&invoiceType==='sale'){const inv=getMyInvoices().find(i=>i.id===invoiceId);if(!inv||direction!=='inbound'||inv.contactId!==contactId){alert('فاکتور فروش با طرف حساب یا نوع دریافت مطابقت ندارد.');return;}if(inv.paymentMethod!=='credit'){alert('فاکتور نقدی مانده قابل تخصیص ندارد.');return;}outstanding=invoiceOutstanding(inv);}
60
if(invoiceId&&invoiceType==='purchase'){const inv=getMyPurchases().find(i=>i.id===invoiceId);if(!inv||direction!=='outbound'||inv.supplierId!==contactId){alert('فاکتور خرید با طرف حساب یا نوع پرداخت مطابقت ندارد.');return;}if(inv.paymentMethod!=='credit'){alert('فاکتور خرید نقدی مانده قابل تخصیص ندارد.');return;}outstanding=purchaseOutstanding(inv);}
61
- const old=editingPaymentId?getMyPayments().find(p=>p.id===editingPaymentId):null;
61
+ const old=editingPaymentId?getMyPayments().find(p=>p.id===editingPaymentId):null;if(old&&typeof jeGuardSourceMutation==='function'){try{jeGuardSourceMutation(old,'دریافت/پرداخت');}catch(e){alert(e.message);return;}}
62
if(old&&old.invoiceId===invoiceId&&old.invoiceType===invoiceType&&old.direction===direction)outstanding+=num(old.amount);
63
if(invoiceId&&amount>outstanding){alert('مبلغ از مانده فاکتور بیشتر است.');return;}
64
const contact=getMyContacts().find(c=>c.id===contactId);
@@ -66,7 +66,7 @@ function commitSavePayment(){
66
const linkedPurchase=invoiceType==='purchase'?getMyPurchases().find(i=>i.id===invoiceId):null;
67
const companies=getMyCompanies(),active=linkedSale?.companyId||linkedPurchase?.companyId||getMySettings().default_company_id||companies[0]?.id||'';
68
const payload={id:old?.id||('PAY-'+Date.now()),ownerUserId:currentUser.id,companyId:active,contactId,contactName:contact?.name||'',direction,amount,method:document.getElementById('pay-method')?.value||'bank',reference:(document.getElementById('pay-reference')?.value||'').trim(),note:(document.getElementById('pay-note')?.value||'').trim(),invoiceType,invoiceId,projectId:linkedSale?.projectId||linkedPurchase?.costCenterId||'',date:old?.date||new Date().toISOString()};
69
- if(old)Object.assign(old,payload);else datastore.payments.push(payload);
69
+ if(old)Object.assign(old,payload);else{datastore.payments.push(payload);if(typeof jePostSourceRecord==='function'){try{jePostSourceRecord(direction==='outbound'?'payment':'receipt',payload);}catch(e){datastore.payments=datastore.payments.filter(x=>x.id!==payload.id);alert('دریافت/پرداخت ثبت نشد: '+e.message);return;}}}
70
saveDatastore();resetPaymentForm();refreshAllSurfaces();renderPayments();
71
}
72
function editPayment(id){
@@ -85,7 +85,7 @@ function editPayment(id){
85
}
86
function deletePayment(id){
87
if(typeof requireWrite==='function'&&!requireWrite())return;
88
- if(!confirm('این دریافت/پرداخت حذف شود؟ مانده فاکتور دوباره محاسبه میشود.'))return;
88
+ const source=getMyPayments().find(p=>p.id===id);if(typeof jeGuardSourceMutation==='function'){try{jeGuardSourceMutation(source,'دریافت/پرداخت');}catch(e){alert(e.message);return;}}if(!confirm('این دریافت/پرداخت حذف شود؟ مانده فاکتور دوباره محاسبه میشود.'))return;
89
datastore.payments=datastore.payments.filter(p=>!(p.id===id&&p.ownerUserId===currentUser.id));
90
if(editingPaymentId===id)resetPaymentForm();
91
saveDatastore();refreshAllSurfaces();renderPayments();