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

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

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

Synced Dec 3, 17:00 UTC

fix(finance): exclude unposted sales drafts from inventory, receivables and revenue reporting

davoodmehraban89 committed Oct 11, 2026 at 20:59 UTC 4402b900da814f95688277d0bc7229df68eeab56
1 file changed +2 -2
js/accounting.js
+2 -2
@@ -6,13 +6,13 @@ function productMovement(productId){
6 const companies=getMyCompanies(),active=getMySettings().default_company_id||companies[0]?.id||'';
7 const legacyOk=companies.length===1;
8 const purchased=getMyPurchases().filter(p=>!active||p.companyId===active||(!p.companyId&&legacyOk)).reduce((sum,p)=>sum+(p.items||[]).filter(i=>(i.prodId||i.productId)===productId).reduce((s,i)=>s+n(i.qty??i.quantity),0),0);
9 - const sold=getMyInvoices().filter(p=>!active||p.companyId===active||(!p.companyId&&legacyOk)).reduce((sum,p)=>sum+(p.items||[]).filter(i=>(i.prodId||i.productId)===productId).reduce((s,i)=>s+n(i.qty??i.quantity),0),0);
9 + const sold=getMyInvoices().filter(p=>(!active||p.companyId===active||(!p.companyId&&legacyOk))&&typeof invoiceDocumentStatus==='function'&&invoiceDocumentStatus(p)==='posted').reduce((sum,p)=>sum+(p.items||[]).filter(i=>(i.prodId||i.productId)===productId).reduce((s,i)=>s+n(i.qty??i.quantity),0),0);
10 return {opening,purchased,sold,available:opening+purchased-sold};
11 }
12 function getInventorySnapshot(){return getMyProducts().map(p=>({productId:p.id,code:p.code,name:p.name,unit:p.unit||'عدد',...productMovement(p.id)}));}
13 function getProjectFinancials(projectId){
14 const companies=getMyCompanies(),active=getMySettings().default_company_id||companies[0]?.id||'',legacyOk=companies.length===1,companyOk=i=>!active||i.companyId===active||(!i.companyId&&legacyOk);
15 - const sales=getMyInvoices().filter(i=>companyOk(i)&&i.projectId===projectId).reduce((s,i)=>s+n(i.grandTotal),0);
15 + const sales=getMyInvoices().filter(i=>companyOk(i)&&i.projectId===projectId&&typeof invoiceDocumentStatus==='function'&&invoiceDocumentStatus(i)==='posted').reduce((s,i)=>s+n(i.grandTotal),0);
16 const purchases=getMyPurchases().filter(i=>companyOk(i)&&i.costCenterId===projectId).reduce((s,i)=>s+n(i.grandTotal),0);
17 const expenses=getMyExpenses().filter(e=>companyOk(e)&&e.projectId===projectId&&e.kind==='expense').reduce((s,e)=>s+n(e.amount),0);
18 const income=getMyExpenses().filter(e=>companyOk(e)&&e.projectId===projectId&&e.kind==='income').reduce((s,e)=>s+n(e.amount),0);