سامانه صدور فاکتور و حسابداری
Scope project profitability to active company
davoodmehraban89 committed
Sep 28, 2026 at 15:24 UTC
353089099a7131425e48de995eb5a571e989fd4a
1 file changed
+7
-6
js/accounting.js
+7
-6
@@ -11,12 +11,13 @@ function productMovement(productId){
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 sales=getMyInvoices().filter(i=>i.projectId===projectId).reduce((s,i)=>s+n(i.grandTotal),0);
15
- const purchases=getMyPurchases().filter(i=>i.costCenterId===projectId).reduce((s,i)=>s+n(i.grandTotal),0);
16
- const expenses=getMyExpenses().filter(e=>e.projectId===projectId&&e.kind==='expense').reduce((s,e)=>s+n(e.amount),0);
17
- const income=getMyExpenses().filter(e=>e.projectId===projectId&&e.kind==='income').reduce((s,e)=>s+n(e.amount),0);
18
- const receipts=getMyPayments().filter(p=>p.projectId===projectId&&p.direction==='inbound').reduce((s,p)=>s+n(p.amount),0);
19
- const payments=getMyPayments().filter(p=>p.projectId===projectId&&p.direction==='outbound').reduce((s,p)=>s+n(p.amount),0);
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);
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);
19
+ const receipts=getMyPayments().filter(p=>companyOk(p)&&p.projectId===projectId&&p.direction==='inbound').reduce((s,p)=>s+n(p.amount),0);
20
+ const payments=getMyPayments().filter(p=>companyOk(p)&&p.projectId===projectId&&p.direction==='outbound').reduce((s,p)=>s+n(p.amount),0);
21
return {sales,purchases,expenses,income,receipts,payments,accrualProfit:sales+income-purchases-expenses,cashNet:receipts+income-payments-expenses};
22
}
23
window.productMovement=productMovement;window.getInventorySnapshot=getInventorySnapshot;window.getProjectFinancials=getProjectFinancials;