锁价支持手动料价和当日加权料池预留

This commit is contained in:
summer committed 2026-11-02 19:30:28 +08:00
1 parent 4e5a04a34e
commit 9893ecf037
22 files changed
+622 -94

No files matched your search

+5 -4
View File
@@ -132,7 +132,7 @@
indices.add(entry.lineIndex);
}
const originals=orderId?allUsages.filter(usage=>usage.order_id===orderId):[];
const usages=pool.usages.filter(usage=>usage.active&&usage.order_id!==orderId).map(usage=>({...usage}));
const usages=pool.usages.filter(usage=>usage.active&&(!orderId||usage.order_id!==orderId)).map(usage=>({...usage}));
const usedMg=usages.reduce((total,usage)=>total+usage.mg,0),wantedMg=entries.reduce((total,entry)=>total+entry.mg,0);
const covered=pool.totalMg>0&&usedMg+wantedMg<=pool.totalMg,amounts=Object.fromEntries(entries.map(entry=>[entry.lineIndex,null]));
for(const entry of entries){
@@ -184,7 +184,8 @@
const payers=costPayers(line.costPayers);
const parts=line.costParts?Object.entries(costLabels).map(([key,name])=>({key,name,amount:line.costParts[key]??null})):[{key:'total',name:'货品成本(原单未分项)',amount:line.cost??null}];
for(const part of parts){
if(part.key==='material'&&line.costMaterial?.mode==='pool'){
if(part.key==='material'&&line.priceLockPool&&part.amount===null){add({kind:'goods',component:'material',name:part.name,source:'锁价料池成本待补',amount:null,payer:payers?.material??line.payer,excluded:goodsExcluded,materialPoolId:line.priceLockPool.poolId,poolPending:true,calculation:null});
}else if(part.key==='material'&&line.costMaterial?.mode==='pool'){
const pool=line.materialPool,allocations=pool?.allocations;
if(part.amount===null||!allocations?.length){
add({kind:'goods',component:'material',name:part.name,source:`商品 ${i+1} · ${line.name} · ${line.costMaterial.poolId}日购料待补`,amount:null,payer:payers?.material??line.payer,excluded:goodsExcluded,materialPoolId:line.costMaterial.poolId,materialPoolRevision:pool?.revision,poolPending:true,calculation:null});
@@ -195,8 +196,8 @@
}else if(part.key==='material'&&line.materialAllocations){
const allocations=line.materialAllocations;
if(!Array.isArray(allocations)||!allocations.length||allocations.some(item=>!['original','extra'].includes(item.source)||!['owner','assistant','assistant2'].includes(item.payer)||!Number.isSafeInteger(item.amount)||item.amount<0||!Number.isSafeInteger(item.quantity)||item.quantity<=0||!Number.isSafeInteger(item.rate)||item.rate<=0)||allocations.reduce((total,item)=>total+item.amount,0)!==part.amount)throw new Error('锁价分项料费记录无效');
for(const item of allocations)add({kind:'goods',component:'material',name:part.name,source:`商品 ${i+1} · ${line.name} · ${item.source==='original'?'原锁价采购':'补重采购'}`,amount:item.amount,payer:item.payer,excluded:goodsExcluded,
priceLockSource:item.source,calculation:{rate:item.rate,quantity:item.quantity}});
for(const item of allocations)add({kind:'goods',component:'material',name:part.name,source:`商品 ${i+1} · ${line.name} · ${item.source==='original'?(item.weighted?'原锁日料池':'原锁价采购'):'补重采购'}`,amount:item.amount,payer:item.payer,excluded:goodsExcluded,
priceLockSource:item.source,...(item.poolId?{materialPoolId:item.poolId}:{}),calculation:{rate:item.rate,quantity:item.quantity,...(item.weighted?{weighted:true}:{} )}});
}else add({kind:'goods',name:part.name,source:`商品 ${i+1} · ${line.name}`,amount:part.amount,payer:payers?.[part.key]??line.payer,excluded:goodsExcluded,
calculation:part.key==='material'&&line.recovery_id&&line.costMaterial?.rate!==undefined?{rate:line.costMaterial.rate,quantity:line.recoveryMaterialMg}:part.key==='material'&&line.costMaterial?.mode==='gram'?{rate:line.costMaterial.rate,quantity:line.quantity}:part.key==='labor'&&line.costLabor?.mode==='gram'?{rate:line.costLabor.rate,quantity:line.quantity}:null});
}