增加客户寄存料登记与置换使用,支持余额恢复
This commit is contained in:
1 parent
d0809d61a7
commit
1f1e6dd402
11 files changed
+170
-23
No files matched your search
@@ -7,9 +7,9 @@ function quote(l,input,actor,env,options,R){
|
||||
const items=input.exchange.items;
|
||||
if(!Array.isArray(items)||!items.length||items.length>60)env.fail('请填写1~60件独立置换商品');
|
||||
const parts=items.map((item,i)=>{
|
||||
if(!item||typeof item!=='object'||!item.exchange||item.exchange.items||item.exchange.products||!Array.isArray(item.old_lines)||item.old_lines.length!==1)env.fail('第'+(i+1)+'件置换资料无效');
|
||||
if(!item||typeof item!=='object'||!item.exchange||item.exchange.items||item.exchange.products||(item.old_source!=='deposit'&&(!Array.isArray(item.old_lines)||item.old_lines.length!==1)))env.fail('第'+(i+1)+'件置换资料无效');
|
||||
// 内部单件预览不产生收付款,信用卡手续费只按整单实收计算。
|
||||
return R.quote(l,{...input,...item,old_lines:item.old_lines,old_pocket:item.old_pocket??'回收旧料',old_stock_count:item.old_stock_count,buy_rate:item.buy_rate,buy_total:item.buy_total,mode:'exchange',date:input.date,customer:input.customer,salesperson:input.salesperson,member:input.member,note:input.note,payer:input.payer,payment_account:input.payment_account?.endsWith('信用卡')?'麦麦微信':input.payment_account,exchange:{...item.exchange,charges:[],fee_items:[],discount:'0',rounding_mode:'cent'}},actor,env,{...options,creating:false,existingRecovery:options.existingRecovery?.exchangeItems?.[i]??null});
|
||||
return R.quote(l,{...input,...item,old_source:item.old_source,deposit_id:item.deposit_id,deposit_weight:item.deposit_weight,old_lines:item.old_lines,old_pocket:item.old_pocket??'回收旧料',old_stock_count:item.old_stock_count,buy_rate:item.buy_rate,buy_total:item.buy_total,mode:'exchange',date:input.date,customer:input.customer,salesperson:input.salesperson,member:input.member,note:input.note,payer:input.payer,payment_account:input.payment_account?.endsWith('信用卡')?'麦麦微信':input.payment_account,exchange:{...item.exchange,charges:[],fee_items:[],discount:'0',rounding_mode:'cent'}},actor,env,{...options,creating:false,existingRecovery:options.existingRecovery?.exchangeItems?.[i]??null});
|
||||
});
|
||||
if(options.creating&&parts.some(p=>p.laborCost===null||p.differenceMg&&!p.exchange.costMaterial.rate&&p.exchange.costMaterial.mode!=='pool'))env.fail('请逐件补齐进货工费和差重料费');
|
||||
// 必须一次试算所有用料,避免多件分别试算时重复使用同一笔剩料。
|
||||
@@ -20,6 +20,7 @@ function quote(l,input,actor,env,options,R){
|
||||
if(probes[i].materialPool?.materialSources)p.exchange.costMaterial.materialSources=probes[i].materialPool.materialSources;
|
||||
}
|
||||
const first=parts[0],q={...first,exchangeItems:parts,newProducts:parts.map(p=>({...p.newProduct,laborMode:p.laborMode,laborRate:p.laborRate,laborAmount:p.laborAmount,costLabor:p.exchange.costLabor,laborCost:p.laborCost,laborPayer:p.exchange.costPayers.labor})),old_lines:parts.flatMap(p=>p.old_lines),payment_account:input.payment_account??first.payment_account};
|
||||
delete q.customerDeposit;
|
||||
for(const key of ['oldMg','newMg','matchedMg','differenceMg','surplusMg','depreciationMg','goldAmount','laborAmount','depreciationAmount','purchaseMg','purchaseAmount','calculatedPurchaseAmount'])q[key]=sum(parts,key);
|
||||
for(const key of ['materialCost','laborCost','goodsCost'])q[key]=parts.some(p=>p[key]===null)?null:sum(parts,key);
|
||||
q.charges=Calc.charges(input.exchange.charges??[]).items;if(q.charges.some(p=>p.amount===null))env.fail('请补齐其他收费');q.chargesAmount=sum(q.charges,'amount');
|
||||
@@ -34,6 +35,7 @@ function quote(l,input,actor,env,options,R){
|
||||
q.actualBuyRate=q.purchaseMg?Number((BigInt(q.purchaseAmount)*1000n+BigInt(q.purchaseMg)/2n)/BigInt(q.purchaseMg)):null;
|
||||
q.paymentMethods=q.cashReceipt||q.cashPayment?[q.payment_account.replace(/^(助理2|助理1|助理|麦麦)/,'')]:[];
|
||||
for(const key of ['oldMg','newMg','differenceMg','purchaseAmount','receivable','directCost','goodsCost','netSettlement'])if(q[key]!==null&&(!Number.isSafeInteger(q[key])||Math.abs(q[key])>100000000000))env.fail('置换汇总超出范围');
|
||||
require('./customer-materials').validate(l,q,env,{orderId:options.orderId});
|
||||
return q;
|
||||
}
|
||||
function publicItems(q){const fields=['old_lines','oldMg','newMg','matchedMg','differenceMg','surplusMg','goldRate','laborRate','laborMode','depreciationMg','depreciationRate','buyRate','goldAmount','laborAmount','depreciationAmount','calculatedPurchaseAmount','purchaseAmount'];return q.exchangeItems.map(p=>({...Object.fromEntries(fields.map(k=>[k,p[k]])),newProduct:{name:p.newProduct.name,quantity:p.newMg}}));}
|
||||
|
||||
Reference in new issue
Block a user