سامانه صدور فاکتور و حسابداری
merge(finance): carry reviewed document draft workflow onto current main
davoodmehraban89 committed
Oct 11, 2026 at 21:08 UTC
2a2fd29515f1b5c9fd9841f7f218f479782d9bab
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);