سامانه صدور فاکتور و حسابداری
Phase 5: post valued inventory adjustments [skip ci]
davoodmehraban89 committed
Sep 29, 2026 at 20:50 UTC
a3ba1f0c2a9e5f29b06c9ba71f5b59027a7941d3
1 file changed
+1
-1
js/phase5-enterprise.js
+1
-1
@@ -48,7 +48,7 @@ function p5SaveWarehouse(){
48
function p5PostMovement(){
49
const cid=p5Need();if(!cid)return;const m={id:p5Id('SM'),ownerUserId:currentUser.id,companyId:cid,kind:document.getElementById('p5-mv-kind').value,productId:document.getElementById('p5-mv-product').value,warehouseId:document.getElementById('p5-mv-from').value,toWarehouseId:document.getElementById('p5-mv-to').value,qty:Number(toEnDigits(document.getElementById('p5-mv-qty').value))||0,unitCost:Number(toEnDigits(document.getElementById('p5-mv-cost').value))||0,date:document.getElementById('p5-mv-date').value||getJalaliNumeric(),reference:document.getElementById('p5-mv-ref').value.trim(),status:'posted',postedAt:new Date().toISOString()};
50
try{P5Domain.validateMovement(m);if(['adjustment_out','transfer'].includes(m.kind)&&p5Stock(m.productId,m.warehouseId)<m.qty)throw new Error('موجودی انبار برای خروج کافی نیست.');}catch(e){return alert(e.message)}
51
- datastore.stockMovements.push(m);p5Audit('post','stockMovement',m.id,null,m);saveDatastore();p5RenderInventory();
51
+ datastore.stockMovements.push(m);try{if(['adjustment_in','adjustment_out'].includes(m.kind)&&m.unitCost>0){const inv=jeAccountByCode('1103'),other=jeAccountByCode(m.kind==='adjustment_in'?'4201':'5101'),value=m.qty*m.unitCost;if(!inv||!other)throw new Error('حساب موجودی/تعدیل در کدینگ تکمیل نیست.');const lines=m.kind==='adjustment_in'?[{accountId:inv.id,debit:value,credit:0,description:'تعدیل موجودی',dimensions:[]},{accountId:other.id,debit:0,credit:value,description:'تعدیل افزایشی موجودی',dimensions:[]}]:[{accountId:other.id,debit:value,credit:0,description:'تعدیل کاهشی موجودی',dimensions:[]},{accountId:inv.id,debit:0,credit:value,description:'خروج تعدیلی موجودی',dimensions:[]}];const v=jeCreateDraft({date:m.date,description:'تعدیل موجودی — '+(m.reference||m.id),sourceType:'inventory_adjustment',sourceId:m.id,lines});jePost(v.id);m.journalVoucherId=v.id;m.accountingStatus='posted';}p5Audit('post','stockMovement',m.id,null,m);saveDatastore();p5RenderInventory();}catch(e){datastore.stockMovements=datastore.stockMovements.filter(x=>x.id!==m.id);saveDatastore();alert(e.message)}
52
}
53
function p5SaveCount(){
54
const cid=p5Need();if(!cid)return;const productId=document.getElementById('p5-count-product').value,warehouseId=document.getElementById('p5-count-wh').value,physicalQty=Number(toEnDigits(document.getElementById('p5-count-qty').value));if(!productId||!warehouseId||!Number.isFinite(physicalQty)||physicalQty<0)return alert('اطلاعات شمارش معتبر نیست.');