支持耳钉货盘克重与对数同步库存及历史盘点基准

This commit is contained in:
summer committed 2026-11-08 15:47:07 +08:00
1 parent ba15795f0a
commit b6a0213a0c
28 files changed
+906 -161

No files matched your search

+4 -2
View File
@@ -61,6 +61,8 @@ function quote(ledger,input,actor,env,{creating=false,orderId=null,existingRecov
const e=input.exchange;if(!e||typeof e!=='object'||Array.isArray(e))env.fail('请填写换出的新货');
const newMg=env.weight(e.quantity,'新货克重');if(newMg<=0)env.fail('新货克重须大于0');
const newProduct={name:env.text(e.name??'足金','新货名称',60),quantity:newMg,pocket:ledger.validatePocket(e.pocket,{original:existingRecovery?.newProduct?.pocket,name:'新货货盘'})};
const samePocket=!!existingRecovery&&newProduct.pocket===existingRecovery.newProduct?.pocket,stockCount=ledger.validateStockCount(newProduct.pocket,e.stockCount,{original:samePocket?existingRecovery.newProduct?.stockCount??null:null,allowLegacy:samePocket});
if(stockCount!==null)newProduct.stockCount=stockCount;
if(Calc.isSilver(newProduct.name))env.fail('黄金置换暂只支持按克黄金商品');
const matchedMg=Math.min(newMg,oldMg),differenceMg=Math.max(newMg-oldMg,0),surplusMg=Math.max(oldMg-newMg,0);
const goldRate=env.money(e.gold_price??'0','销售金价'),laborRate=env.money(e.labor_rate??'0','销售工费'),laborMode=env.pick(e.labor_mode??'gram',['gram','total'],'销售工费方式');
@@ -123,7 +125,7 @@ function nextNumber(ledger,date,env){
ledger.setMeta(key,seq);return 'HS'+date.replaceAll('-','')+String(seq).padStart(4,'0');
}
function orderInput(q){return {date:q.date,member:q.member,customer:q.customer,salesperson:q.salesperson,note:q.note,
lines:[{name:q.newProduct.name,unit:'g',quantity:weightInput(q.newMg),pocket:q.newProduct.pocket,payer:q.exchange.costPayer,costPayers:q.exchange.costPayers,
lines:[{name:q.newProduct.name,unit:'g',quantity:weightInput(q.newMg),pocket:q.newProduct.pocket,...(q.newProduct.stockCount==null?{}:{stockCount:q.newProduct.stockCount}),payer:q.exchange.costPayer,costPayers:q.exchange.costPayers,
pricingMode:'manual',sale:amountInput(q.goldAmount+q.laborAmount+q.depreciationAmount),charges:q.charges.map(charge=>({...charge,amount:amountInput(charge.amount)})),
costParts:{material:amountInput(q.materialCost??0),labor:amountInput(q.laborCost),accessories:'0',other:'0'},
priceNote:`补金 ${weightInput(q.differenceMg)}克 × ${amountInput(q.goldRate)}元;新货工费 ${amountInput(q.laborAmount)}元;折旧 ${amountInput(q.depreciationAmount)}元`}],
@@ -134,7 +136,7 @@ function inputFor(q){
buy_rate:amountInput(q.buyRate),buy_total:amountInput(q.purchaseAmount),payer:q.payer,payment_account:q.payment_account,verified:true};
if(q.mode==='exchange'){
const e=q.exchange;
input.exchange={name:q.newProduct.name,quantity:weightInput(q.newMg),pocket:q.newProduct.pocket,gold_price:amountInput(q.goldRate),labor_rate:amountInput(q.laborRate),labor_mode:q.laborMode,
input.exchange={name:q.newProduct.name,quantity:weightInput(q.newMg),pocket:q.newProduct.pocket,...(q.newProduct.stockCount==null?{}:{stockCount:q.newProduct.stockCount}),gold_price:amountInput(q.goldRate),labor_rate:amountInput(q.laborRate),labor_mode:q.laborMode,
depreciation_weight:weightInput(q.depreciationMg),depreciation_rate:amountInput(q.depreciationRate),charges:q.charges.map(charge=>({...charge,amount:amountInput(charge.amount)})),
discount:amountInput(q.discount),rounding_mode:q.rounding_mode,cost_material:e.costMaterial.mode==='pool'?{mode:'pool',poolId:e.costMaterial.poolId}:{mode:'gram',rate:amountInput(e.costMaterial.rate??0)},
cost_labor:e.costLabor.mode==='gram'?{mode:'gram',rate:amountInput(e.costLabor.rate)}:{mode:'total',amount:amountInput(e.costLabor.amount??q.laborCost)},