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

Reconcile balances only with cleared cheques

davoodmehraban89 committed Sep 28, 2026 at 14:29 UTC 3f9b930c07c9c434dfd97d4cd0d6a9fc50fcb93f
1 file changed +3 -3
js/drilldown.js
+3 -3
@@ -18,8 +18,8 @@ window.openContactLedger=function(contactId){
18 const receivable=getMyInvoices().filter(i=>i.contactId===contactId&&i.paymentMethod==='credit').reduce((a,i)=>a+Number(i.grandTotal||0),0);
19 const payable=(datastore.purchases||[]).filter(p=>p.ownerUserId===currentUser.id&&p.supplierId===contactId&&p.paymentMethod==='credit').reduce((a,p)=>a+Number(p.grandTotal||0),0);
20 const contactCheques=getMyCheques().filter(q=>q.contactId===contactId||(!q.contactId&&q.contactName===c.name));
21 - const received=contactCheques.filter(q=>q.direction==='inbound').reduce((a,q)=>a+Number(q.amount||0),0);
22 - const paid=contactCheques.filter(q=>q.direction==='outbound').reduce((a,q)=>a+Number(q.amount||0),0);
21 + const received=contactCheques.filter(q=>q.direction==='inbound'&&q.status==='cleared').reduce((a,q)=>a+Number(q.amount||0),0);
22 + const paid=contactCheques.filter(q=>q.direction==='outbound'&&q.status==='cleared').reduce((a,q)=>a+Number(q.amount||0),0);
23 const net=(receivable-received)-(payable-paid);
24 show('مرور حساب — '+c.name,`<div class="grid-kpi" style="margin-bottom:12px"><div class="kpi-unit"><div><div class="kpi-lbl">فروش</div><div class="kpi-val">${fmt(sales)}</div></div></div><div class="kpi-unit"><div><div class="kpi-lbl">خرید</div><div class="kpi-val">${fmt(purchases)}</div></div></div><div class="kpi-unit"><div><div class="kpi-lbl">مطالبات</div><div class="kpi-val">${fmt(receivable)}</div></div></div><div class="kpi-unit"><div><div class="kpi-lbl">بدهی</div><div class="kpi-val">${fmt(payable)}</div></div></div></div><div style="padding:10px 12px;margin-bottom:12px;border:1px solid var(--border);border-radius:10px"><b>مانده خالص:</b> ${fmt(Math.abs(net))} — ${net>0?'مطالبات از طرف حساب':net<0?'بدهی به طرف حساب':'تسویه'}</div>${rowsTable(rows)}`);
25 }
@@ -44,6 +44,6 @@ function wire(){
44 }
45 const rd=window.renderDashboard;window.renderDashboard=function(){rd();wire();const tb=$('dashboard-recent-table');if(tb)tb.querySelectorAll('tr').forEach(tr=>{const num=(tr.cells?.[0]?.textContent||'').replace(/^#/,'');const i=getMyInvoices().find(x=>String(x.number)===num);if(i&&tr.lastElementChild&&!tr.lastElementChild.querySelector('.dash-open')){const b=document.createElement('button');b.className='btn btn-secondary btn-inline dash-open';b.style.cssText='padding:4px 8px;font-size:11px;margin-left:4px';b.textContent='جزئیات';b.onclick=()=>editInvoice(i.id);tr.lastElementChild.prepend(b);}});};
46 const rr=window.renderFinancialReports;if(typeof rr==='function')window.renderFinancialReports=function(){rr();wire();};
47 -const rc=window.renderContacts;window.renderContacts=function(){rc();const cs=getMyContacts(),trs=document.querySelectorAll('#contacts-ledger-table-body tr');trs.forEach((tr,i)=>{const c=cs[i];if(!c||!tr.cells||tr.cells.length<7)return;tr.cells[0].style.cursor='pointer';tr.cells[0].title='مرور حساب';tr.cells[0].onclick=()=>openContactLedger(c.id);const rec=getMyInvoices().filter(i=>i.contactId===c.id&&i.paymentMethod==='credit').reduce((a,i)=>a+Number(i.grandTotal||0),0);const pay=(datastore.purchases||[]).filter(p=>p.ownerUserId===currentUser.id&&p.supplierId===c.id&&p.paymentMethod==='credit').reduce((a,p)=>a+Number(p.grandTotal||0),0);const cq=getMyCheques().filter(q=>q.contactId===c.id||(!q.contactId&&q.contactName===c.name));const received=cq.filter(q=>q.direction==='inbound').reduce((a,q)=>a+Number(q.amount||0),0);const paid=cq.filter(q=>q.direction==='outbound').reduce((a,q)=>a+Number(q.amount||0),0);const net=(rec-received)-(pay-paid);tr.cells[6].innerHTML=`<div style="font-weight:bold">${fmt(Math.abs(net))}</div><button class="btn btn-secondary btn-inline" style="padding:2px 7px;font-size:11px;margin-top:3px" onclick="openContactLedger('${c.id}')">${net>0?'مطالبات':net<0?'بدهی':'مرور حساب'} ↗</button>`;});};
47 +const rc=window.renderContacts;window.renderContacts=function(){rc();const cs=getMyContacts(),trs=document.querySelectorAll('#contacts-ledger-table-body tr');trs.forEach((tr,i)=>{const c=cs[i];if(!c||!tr.cells||tr.cells.length<7)return;tr.cells[0].style.cursor='pointer';tr.cells[0].title='مرور حساب';tr.cells[0].onclick=()=>openContactLedger(c.id);const rec=getMyInvoices().filter(i=>i.contactId===c.id&&i.paymentMethod==='credit').reduce((a,i)=>a+Number(i.grandTotal||0),0);const pay=(datastore.purchases||[]).filter(p=>p.ownerUserId===currentUser.id&&p.supplierId===c.id&&p.paymentMethod==='credit').reduce((a,p)=>a+Number(p.grandTotal||0),0);const cq=getMyCheques().filter(q=>q.contactId===c.id||(!q.contactId&&q.contactName===c.name));const received=cq.filter(q=>q.direction==='inbound'&&q.status==='cleared').reduce((a,q)=>a+Number(q.amount||0),0);const paid=cq.filter(q=>q.direction==='outbound'&&q.status==='cleared').reduce((a,q)=>a+Number(q.amount||0),0);const net=(rec-received)-(pay-paid);tr.cells[6].innerHTML=`<div style="font-weight:bold">${fmt(Math.abs(net))}</div><button class="btn btn-secondary btn-inline" style="padding:2px 7px;font-size:11px;margin-top:3px" onclick="openContactLedger('${c.id}')">${net>0?'مطالبات':net<0?'بدهی':'مرور حساب'} ↗</button>`;});};
48 try{if(currentUser)refreshAllSurfaces();}catch(e){console.error('drilldown init',e);}
49 })();
\ No newline at end of file