完善逐件置换的旧料、折旧、补金与独立成本结算

This commit is contained in:
summer committed 2026-11-24 21:56:05 +08:00
1 parent 2e4e7dad55
commit d0809d61a7
9 files changed
+248 -23

No files matched your search

+7 -6
View File
@@ -102,7 +102,7 @@ function movements(l,row,after){
if(matching)Object.assign(matching,{stockCount:-count.stockCount,countEffectiveDate:count.date});
else deltas.push({...count,mg:0,stockCount:-count.stockCount,countEffectiveDate:count.date,kind:'recovery_change_reverse'});
}
if(after){deltas.push({date:after.date,pocket:after.oldPocket??'回收旧料',mg:after.oldMg,stockCount:after.oldStockCount??null,kind:'recovery_change_old'});if(after.mode==='exchange')for(const product of Recoveries.products(after))if(product.pocket)deltas.push({date:after.date,pocket:product.pocket,mg:-product.quantity,stockCount:product.stockCount==null?null:-product.stockCount,kind:'recovery_change_sale'});}
if(after){for(const old of Recoveries.oldInventory(after))deltas.push({date:after.date,...old,kind:'recovery_change_old'});if(after.mode==='exchange')for(const product of Recoveries.products(after))if(product.pocket)deltas.push({date:after.date,pocket:product.pocket,mg:-product.quantity,stockCount:product.stockCount==null?null:-product.stockCount,kind:'recovery_change_sale'});}
return deltas;
}
function validateInventory(l,deltas,env){
@@ -161,11 +161,11 @@ function replaceJournal(l,row,after){
l.touch(id);
}
function financialInput(value){const {customer,salesperson,note,...rest}=value;return rest;}
function inventoryOnlyInput(value){const {old_pocket,old_stock_count,...rest}=financialInput(value);return rest;}
function inventoryOnlyInput(value){const {old_pocket,old_stock_count,...rest}=financialInput(value);if(rest.exchange?.items)rest.exchange={...rest.exchange,items:rest.exchange.items.map(({old_pocket,old_stock_count,...item})=>item)};return rest;}
function metadataChangeOnly(row,after){return !!after&&hash(financialInput(Recoveries.inputFor(JSON.parse(row.data))))===hash(financialInput(Recoveries.inputFor(after)));}
function legacyCountInfo(l,row){
const q=JSON.parse(row.data);
return Counts.legacyInfo(l,[...Recoveries.products(q).filter(product=>product.stockCount==null).map(product=>({id:'',pocket:product.pocket,mg:product.quantity})),...(q.oldStockCount==null?[{id:'',pocket:q.oldPocket??'回收旧料',mg:q.oldMg}]:[])]);
return Counts.legacyInfo(l,[...Recoveries.products(q).filter(product=>product.stockCount==null).map(product=>({id:'',pocket:product.pocket,mg:product.quantity})),...Recoveries.oldInventory(q).filter(p=>p.stockCount==null).map(p=>({id:'',pocket:p.pocket,mg:p.mg}))]);
}
function verifyLegacyCount(l,row,after,input,env){const info=legacyCountInfo(l,row);if(info.requiresLegacyCountVerified&&!metadataChangeOnly(row,after)&&input?.legacyCountVerified!==true)env.fail('请核对并确认:'+info.legacyCountNotice);}
function execute(l,row,after,actor,reason,env,input={}){return Rolling.withHistorical(l,()=>l.scope(null,()=>{
@@ -205,10 +205,11 @@ function normalized(l,row,input,actor,env){
const physical=product=>JSON.stringify([product.name,product.quantity,product.pocket,product.stockCount??null]);
if(physical(product)!==physical(Recoveries.products(after)[index]??{}))env.fail('启用前已交付的置换新货没有原始对数,只能更正资料和财务;成品变化请先核对实物,再登记今天的数量调整,不能补旧单对数重扣盘点基准');
}
if(previous.oldStockCount==null&&l.pocket(previous.oldPocket??'回收旧料')?.countUnit==='pair'){
const physical=value=>JSON.stringify([value.oldPocket??'回收旧料',value.oldMg,value.oldStockCount??null]);
if(physical(previous)!==physical(after))env.fail('启用前的回收旧料没有原始对数,只能更正资料和财务;实物变化请先核对后登记今天的库存数量调整,不能补旧单对数重扣盘点基准');
for(const [i,old] of Recoveries.oldInventory(previous).entries())if(old.stockCount==null&&l.pocket(old.pocket)?.countUnit==='pair'){
const physical=value=>JSON.stringify([value?.pocket,value?.mg,value?.stockCount??null]);
if(physical(old)!==physical(Recoveries.oldInventory(after)[i]))env.fail('启用前的回收旧料没有原始对数,只能更正资料和财务;请先核对实物');
}
return after;
}
function quote(l,id,input,actor,env){object(input,env);const row=rowFor(l,id,actor,env);if(row.status==='cancelled')env.fail('本单已经取消',409);if(input.revision!==row.revision||!Number.isSafeInteger(input.revision))env.fail('回收记录版本已有变动,请刷新核对',409);return normalized(l,row,input,actor,env);}