锁价交付补重支持当日料池,内部备注移至客户名旁

This commit is contained in:
summer committed 2026-11-30 16:40:30 +08:00
1 parent ac9073471d
commit c5883351c1
20 files changed
+196 -66

No files matched your search

+15 -9
View File
@@ -15,7 +15,7 @@ const same=(a,b)=>JSON.stringify(a)===JSON.stringify(b);
const CreditCardFees=require('./public/credit-card-fees');
const CreditCardRates=require('./credit-card-rates');
const isCardFee=item=>item?.system==='credit_card'||String(item?.key||'').startsWith('card_fee:');
const COST_FIELDS=['payer','costPayers','costFundings','cost','costParts','costMaterial','costLabor','materialAllocations','priceLockPool','returnedStockId','returnedStock'];
const COST_FIELDS=['payer','costPayers','costFundings','cost','costParts','costMaterial','costLabor','materialAllocations','priceLockPool','priceLockExtraPool','returnedStockId','returnedStock'];
const SALE_FIELDS=['name','code','unit','quantity','pocket','stockCount','sale','baseSale','charges','pricingMode','goldPrice','laborRate','laborMode','pieces','priceNote'];
function editFeeCostMode(order,input,env){
const mode=env.pick(input.fee_cost_mode===undefined?order.fee_cost_mode??'legacy':input.fee_cost_mode,['legacy','checkboxes'],'费用录入方式');
@@ -90,7 +90,7 @@ function detail(ledger,id,actor,env){
const line=inputs.lines[row.line_index],extra=lock.material_events.find(event=>event.source==='extra'&&(event.line_index??0)===row.line_index),delivery=row.delivery??LockLines.deliveryAt(lock,row.line_index);
line.lineId=row.id;
line.price_lock_material={source:row.material_source,rate:yuan(row.buy_rate),payer:row.buy_payer,verified:true};
if(delivery?.extra_mg)line.price_lock_extra_material={rate:yuan(extra?.rate),payer:extra?.payer,verified:true};
if(delivery?.extra_mg){const pool=order.lines[row.line_index].priceLockExtraPool;line.price_lock_extra_material={...(pool?{source:'pool',amount:pool.amount}:{}),rate:yuan(pool?.averageRate??extra?.rate),payer:pool?.allocations?.[0]?.payer??extra?.payer,verified:true};}
}
if(inputs.lines.length===1){
inputs.price_lock_material=inputs.lines[0].price_lock_material;
@@ -219,7 +219,7 @@ function editDeliveredLock(ledger,info,input,metadata,actor,env){
const rawLine=data.lines[index],originalLine=order.lines[index],delivery=locked.delivery??LockLines.deliveryAt(lock,index);
if(!rawLine||typeof rawLine!=='object'||Array.isArray(rawLine)||!delivery)env.fail(unchanged);
if((lockedRows.length>1||rawLine.lineId!==undefined)&&rawLine.lineId!==locked.id)env.fail('锁价商品来源或顺序已变化,请重新打开订单',409);
if(rawLine.materialAllocations!==undefined||rawLine.materialPool!==undefined||rawLine.priceLockPool!==undefined)env.fail(unchanged);
if(rawLine.materialAllocations!==undefined||rawLine.materialPool!==undefined||rawLine.priceLockPool!==undefined||rawLine.priceLockExtraPool!==undefined)env.fail(unchanged);
const material=materialInput(rawLine,index,'price_lock_material');
if(!material||typeof material!=='object'||Array.isArray(material))env.fail('请完整带入每件商品的原锁价料费后再修改');
const source=env.pick(material.source,['pool','manual'],'原锁料费来源'),originalSource=locked.material_source;
@@ -230,15 +230,19 @@ function editDeliveredLock(ledger,info,input,metadata,actor,env){
const materialChanged=source!==originalSource||rate!==locked.buy_rate||payer!==locked.buy_payer;
if(materialChanged&&material.verified!==true)env.fail('请确认更正后的原料款和付款人已经核实');
const previousExtra=lock.material_events.find(row=>row.source==='extra'&&(row.line_index??0)===index),extra=materialInput(rawLine,index,'price_lock_extra_material');
const extraReservation=LockPools.find(ledger,lock.id,LockPools.extraIndex(index)),extraSource=extra?.source??(extraReservation?'pool':'manual');
env.pick(extraSource,['pool','manual'],'补重料费来源');if(extraSource==='pool'&&!extraReservation)env.fail('手填补重不能直接改为料池来源');
let extraRate=null,extraPayer=null;
if(delivery.extra_mg){
if(!extra||typeof extra!=='object'||Array.isArray(extra))env.fail('请完整带入补重料费和付款人后再修改');
extraRate=env.money(extra.rate,'补重进货料价');extraPayer=env.pick(extra.payer,['owner','assistant','assistant2'],'补重料费付款人');
if(extraRate<=0)env.fail('补重进货料价必须大于0');
if((extraRate!==previousExtra?.rate||extraPayer!==previousExtra?.payer)&&extra.verified!==true)env.fail('请确认更正后的补重料款和付款人已经核实');
if(extraSource==='pool'&&(extraRate!==extraReservation.snapshot.averageRate||extraPayer!==extraReservation.allocations[0]?.payer))env.fail('补重料池成本由料池维护,手填前请选择独立采购');
if(extraSource==='manual'&&(extraRate!==previousExtra?.rate||extraPayer!==previousExtra?.payer)&&extra.verified!==true)env.fail('请确认更正后的补重料款和付款人已经核实');
}else if(extra!==undefined)env.fail('本商品没有补重采购,不能新增补重料费');
const extraChanged=delivery.extra_mg&&(extraRate!==previousExtra?.rate||extraPayer!==previousExtra?.payer);
const extraChanged=delivery.extra_mg&&(extraReservation?extraSource!=='pool':extraRate!==previousExtra?.rate||extraPayer!==previousExtra?.payer);
const costs=Calc.priceLockCost({lockedQuantity:(locked.locked_mg/1000).toFixed(3),quantity:(originalLine.quantity/1000).toFixed(3),buyRate:yuan(rate),extraBuyRate:extraRate===null?undefined:yuan(extraRate)});
if(extraSource==='pool'){if(extraReservation.amount==null)env.fail('补重料池成本待补,请核实后修改',409);costs.extraCost=extraReservation.amount;costs.materialCost=costs.originalUsedCost+costs.extraCost;}
const reservation=source==='pool'?LockPools.find(ledger,lock.id,index):null,part=reservation?LockPools.split(reservation.snapshot,delivery.original_used_mg):null;
if(source==='pool'&&(!part||part.amount===null))env.fail('原锁料池成本待补,请先核实料池后再更正交付成本',409);
if(part)Object.assign(costs,{originalPurchase:reservation.amount,originalUsedCost:part.amount,leftoverCost:part.leftoverCost,materialCost:part.amount+costs.extraCost});
@@ -250,9 +254,10 @@ function editDeliveredLock(ledger,info,input,metadata,actor,env){
if(SALE_FIELDS.some(field=>!same(saleValue(line,field),saleValue(originalLine,field))))env.fail(unchanged);
if(originalLine.lineId!==undefined||lockedRows.length>1)line.lineId=locked.id;
line.materialAllocations=reservation?LockPools.materialAllocations(reservation.snapshot,delivery.original_used_mg):[{source:'original',quantity:delivery.original_used_mg,rate,amount:costs.originalUsedCost,payer}];
if(delivery.extra_mg)line.materialAllocations.push({source:'extra',quantity:delivery.extra_mg,rate:extraRate,amount:costs.extraCost,payer:extraPayer});
if(extraSource==='pool'){line.priceLockExtraPool={...originalLine.priceLockExtraPool};line.materialAllocations.push(...LockPools.materialAllocations(extraReservation.snapshot,delivery.extra_mg).map(a=>({...a,source:'extra'})));}
else if(delivery.extra_mg)line.materialAllocations.push({source:'extra',quantity:delivery.extra_mg,rate:extraRate,amount:costs.extraCost,payer:extraPayer});
if(reservation)line.priceLockPool={...originalLine.priceLockPool};
return {locked,index,line,delivery,source,originalSource,rate,payer,extraRate,extraPayer,materialChanged,extraChanged,costs,reservation};
return {locked,index,line,delivery,source,originalSource,rate,payer,extraRate,extraPayer,materialChanged,extraChanged,costs,reservation,extraSource,extraReservation};
});
const lines=states.map(row=>row.line);
if(!Array.isArray(data.fee_items))env.fail('请完整带入本单所有实际费用后再修改,不能遗漏额外费用');
@@ -275,7 +280,7 @@ function editDeliveredLock(ledger,info,input,metadata,actor,env){
storedRows[index]={...storedRows[index],material_source:'manual',buy_rate:rate,buy_payer:payer,material_amount:costs.originalPurchase,line:lockedLine};
PriceLocks.reviseMaterial(ledger,lock,'original',{line_index:index,rate,payer,quantity:locked.locked_mg,amount:costs.originalPurchase},actor,env);
}
if(delivery.extra_mg)PriceLocks.reviseMaterial(ledger,lock,'extra',{line_index:index,rate:extraRate,payer:extraPayer,quantity:delivery.extra_mg,amount:costs.extraCost},actor,env);
if(delivery.extra_mg&&state.extraSource!=='pool')PriceLocks.reviseMaterial(ledger,lock,'extra',{line_index:index,rate:extraRate,payer:extraPayer,quantity:delivery.extra_mg,amount:costs.extraCost},actor,env);
}
if(states.some(row=>row.source==='manual'))LockLines.save(ledger,storedLock,storedRows);
const recorded=replaceExpenses(ledger,order,fees,data.fee_items,feesDate,actor,reason,env);
@@ -296,7 +301,8 @@ function editDeliveredLock(ledger,info,input,metadata,actor,env){
ledger.run('UPDATE price_locks SET delivery=? WHERE id=?',JSON.stringify(originalDateDelivery),lock.id);
for(const row of releases)poolChanges.push(LockPools.releaseForOrderEdit(ledger,lock.id,actor,env,{lineIndex:row.index,skipJournalOrder:id,preservePriceLockIds:[lock.id]}));
}
if(states.some(row=>row.reservation)&&date!==lock.delivery.date)poolChanges.push(LockPools.moveDeliveryDate(ledger,lock.id,date,actor,env,{skipJournalOrder:id}));
for(const row of states.filter(row=>row.extraReservation&&row.extraSource==='manual'))poolChanges.push(LockPools.releaseForOrderEdit(ledger,lock.id,actor,env,{lineIndex:LockPools.extraIndex(row.index),skipJournalOrder:id,preservePriceLockIds:[lock.id]}));
if(states.some(row=>row.reservation||row.extraSource==='pool')&&date!==lock.delivery.date)poolChanges.push(LockPools.moveDeliveryDate(ledger,lock.id,date,actor,env,{skipJournalOrder:id}));
ledger.run('UPDATE price_locks SET delivery=?,revision=revision+1,updated=? WHERE id=?',JSON.stringify(nextDelivery),env.now(),lock.id);
const next=ledger.rawOrder(id);replaceInventory(ledger,order,next,date,actor,reason);
const expensesChanged=before.expenses.length!==ledger.one('SELECT COUNT(*) AS count FROM expenses WHERE order_id=?',id).count;