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

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

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

Synced Dec 4, 01:45 UTC

Scope derived inventory to active company

davoodmehraban89 committed Sep 28, 2026 at 15:18 UTC b82f6eb5272b4dec71bf0416ca81e8708ecdaa31
1 file changed +4 -2
js/accounting.js
+4 -2
@@ -3,8 +3,10 @@
3 const n=v=>Number(v)||0;
4 function productMovement(productId){
5 const opening=n(getMyProducts().find(p=>p.id===productId)?.stock);
6 - const purchased=getMyPurchases().reduce((sum,p)=>sum+(p.items||[]).filter(i=>(i.prodId||i.productId)===productId).reduce((s,i)=>s+n(i.qty??i.quantity),0),0);
7 - const sold=getMyInvoices().reduce((sum,p)=>sum+(p.items||[]).filter(i=>(i.prodId||i.productId)===productId).reduce((s,i)=>s+n(i.qty??i.quantity),0),0);
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);
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)}));}