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

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

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

Synced Dec 3, 23:15 UTC

fix(inventory): align Kardex status and company scope with inventory movement (#216)

davoodmehraban89 committed Nov 22, 2026 at 01:27 UTC 91221fa4ca4abc98bedb6d9c074dfae4494c8cb3
1 file changed +7 -2
js/products.js
+7 -2
@@ -110,8 +110,13 @@ function editProduct(id){
110 function cancelProductEdit(clear=true){editingProductId='';const b=document.getElementById('product-save-btn'),c=document.getElementById('product-edit-cancel-btn');if(b)b.textContent='➕ ثبت کالا';if(c)c.style.display='none';if(clear){['prod-code-input','prod-name-input','prod-spec-input','prod-category-input','prod-subcategory-input','prod-barcode-input','prod-official-id-input'].forEach(id=>{const e=document.getElementById(id);if(e)e.value=''});}}
111 function productKardexRows(id){
112 const out=[];const add=(kind,doc,qty,date,number)=>out.push({kind,doc,qty:Number(qty)||0,date:date||'',number:number||''});
113 - getMyPurchases().filter(x=>typeof purchaseAffectsBalance==='function'&&purchaseAffectsBalance(x)).forEach(x=>(x.items||[]).filter(i=>(i.prodId||i.productId)===id).forEach(i=>add('خرید',x.id,i.qty??i.quantity,x.date,x.number)));
114 - getMyInvoices().filter(x=>typeof invoiceDocumentStatus==='function'&&invoiceDocumentStatus(x)==='posted').forEach(x=>(x.items||[]).filter(i=>(i.prodId||i.productId)===id).forEach(i=>add('فروش',x.id,-Number((i.qty??i.quantity)||0),x.date,x.number)));
113 + // Keep Kardex consistent with productMovement: purchaseAffectsBalance is
114 + // private to accounting.js, so it cannot be called from this module.
115 + const companies=getMyCompanies(),active=getMySettings().default_company_id||companies[0]?.id||'';
116 + const legacyOk=companies.length===1;
117 + const companyOk=x=>!active||x.companyId===active||(!x.companyId&&legacyOk);
118 + getMyPurchases().filter(x=>companyOk(x)&&['posted','legacy_review'].includes(typeof purchaseDocumentStatus==='function'?purchaseDocumentStatus(x):'legacy_review')).forEach(x=>(x.items||[]).filter(i=>(i.prodId||i.productId)===id).forEach(i=>add('خرید',x.id,i.qty??i.quantity,x.date,x.number)));
119 + getMyInvoices().filter(x=>companyOk(x)&&typeof invoiceDocumentStatus==='function'&&invoiceDocumentStatus(x)==='posted').forEach(x=>(x.items||[]).filter(i=>(i.prodId||i.productId)===id).forEach(i=>add('فروش',x.id,-Number((i.qty??i.quantity)||0),x.date,x.number)));
120 (datastore.stockMovements||[]).filter(x=>x.ownerUserId===currentUser?.id&&(x.productId===id||x.prodId===id)).forEach(x=>add(x.type||x.kind||'گردش انبار',x.id,x.quantity??x.qty,x.date,x.number));
121 return out.sort((a,b)=>String(a.date).localeCompare(String(b.date)));
122 }