合并跨日余料并支持历史料价复核更正
增加订单货盘筛选,统一当天加权料价,保留历史订单成本;退货按原金料成本回池,历史购料更正经复核后同步结转。708 项测试通过。
This commit is contained in:
1 parent
505110ab0e
commit
ab9d3009ea
18 files changed
+1163
-77
No files matched your search
+6
-2
@@ -59,10 +59,11 @@ function actualPurchasePayer(ledger,purchase){
|
||||
return historical?.payer??purchase.payer;
|
||||
}
|
||||
function materialUsageObligations(ledger,snapshot,order,liable,env){
|
||||
if(order.status!=='delivered')return;
|
||||
const rollingReturns=ledger.rows('SELECT * FROM material_rolling_returns WHERE order_id=?',order.id);
|
||||
if(order.status!=='delivered'&&!(order.status==='returned'&&rollingReturns.length))return;
|
||||
for(const [index,line] of order.lines.entries()){
|
||||
if(line.costMaterial?.mode!=='pool')continue;
|
||||
const usage=ledger.one('SELECT * FROM material_pool_usages WHERE order_id=? AND line_index=? AND active=1',order.id,index);
|
||||
const usage=ledger.one('SELECT * FROM material_pool_usages WHERE order_id=? AND line_index=?'+(order.status==='returned'?'':' AND active=1'),order.id,index);
|
||||
if(!usage||usage.amount===null){snapshot.pending.push({member:liable,project:'日购料实际耗用成本待补'});continue;}
|
||||
const third=ledger.one('SELECT assistant2_amount FROM material_usage_parties WHERE usage_id=?',usage.id);
|
||||
const amounts={owner:usage.owner_amount,assistant:usage.assistant_amount,assistant2:third?.assistant2_amount??0};
|
||||
@@ -97,6 +98,9 @@ function orderSnapshot(ledger,id,env){
|
||||
}
|
||||
}
|
||||
}
|
||||
// 回料沿用原资金归属,只在退回当日撤销该笔金料往来;采购现金与历史耗用记录保留。
|
||||
for(const returned of ledger.rows('SELECT * FROM material_rolling_returns WHERE order_id=?',id))for(const part of JSON.parse(returned.allocations))
|
||||
obligation(snapshot,'material-return:'+returned.id+':'+part.payer,returned.date,'material_return','退货金料回池',part.payer,liable,part.amount);
|
||||
return snapshot;
|
||||
}
|
||||
function priceLockSnapshot(ledger,id){
|
||||
|
||||
Reference in new issue
Block a user