سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 01:45 UTC
Bind settlements to source document company
davoodmehraban89 committed
Sep 28, 2026 at 15:17 UTC
d6f6bd0c263eb43efee76cb3a69c387fe6a47ac2
1 file changed
+4
-2
js/payments.js
+4
-2
@@ -61,8 +61,10 @@ function commitSavePayment(){
61
if(old&&old.invoiceId===invoiceId)outstanding+=num(old.amount);
62
if(invoiceId&&amount>outstanding){alert('مبلغ از مانده فاکتور بیشتر است.');return;}
63
const contact=getMyContacts().find(c=>c.id===contactId);
64
- const companies=getMyCompanies(),active=getMySettings().default_company_id||companies[0]?.id||'';
65
- 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:(invoiceType==='sale'?getMyInvoices().find(i=>i.id===invoiceId)?.projectId:getMyPurchases().find(i=>i.id===invoiceId)?.costCenterId)||'',date:old?.date||new Date().toISOString()};
64
+ const linkedSale=invoiceType==='sale'?getMyInvoices().find(i=>i.id===invoiceId):null;
65
+ const linkedPurchase=invoiceType==='purchase'?getMyPurchases().find(i=>i.id===invoiceId):null;
66
+ const companies=getMyCompanies(),active=linkedSale?.companyId||linkedPurchase?.companyId||getMySettings().default_company_id||companies[0]?.id||'';
67
+ 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()};
68
if(old)Object.assign(old,payload);else datastore.payments.push(payload);
69
saveDatastore();resetPaymentForm();refreshAllSurfaces();renderPayments();
70
}