开单成本改为勾选并支持按账号配置默认开单人

This commit is contained in:
summer committed 2026-11-19 02:23:28 +08:00
1 parent 8cac61deb3
commit 6047cc360b
17 files changed
+278 -40

No files matched your search

+4 -4
View File
@@ -43,7 +43,7 @@ function feeInputs(order){
}
for(const row of active)if(!used.has(row.id))items.push({key:'manual:'+row.id,note:row.note,amount:yuan(row.amount),payer:row.payer,status:'estimated',edited:true,expense_id:row.id,date:row.date});
for(const line of order.lines)for(const charge of line.charges||[]){
if(!charge.id)continue;
if(!charge.id||order.fee_cost_mode==='checkboxes'&&FeeEstimates.checkboxCategory(charge.name))continue;
const key=FeeEstimates.normalize(charge.name)==='快递'?'shipping':'charge:'+charge.id;
if(!items.some(item=>item.key===key))items.push({key,note:key==='shipping'?'快递费':charge.name,amount:'0.00',payer:'assistant',status:'estimated',edited:true,date:order.fees_date||order.date});
}
@@ -54,7 +54,7 @@ function inputFor(order){
const allowed=['name','code','unit','quantity','pocket','stockCount','payer','costPayers','costFundings','cost','costParts','costMaterial','costLabor','sale','baseSale','charges','pricingMode','goldPrice','laborRate','laborMode','pieces','priceNote'];
const accounts=new Set(order.payments.filter(row=>row.amount>0&&row.kind==='receipt'&&!order.corrections.some(correction=>correction.type==='payment'&&correction.target===row.id)).map(row=>row.account));
return {id:order.id,date:order.date,customer:order.customer,salesperson:order.salesperson,note:order.note,internal_note:order.internal_note??'',
discount:converted.discount,rounding_mode:order.rounding_mode,fees_date:order.fees_date||order.date,
discount:converted.discount,rounding_mode:order.rounding_mode,fee_cost_mode:order.fee_cost_mode||'legacy',fees_date:order.fees_date||order.date,
payment_account:accounts.size===1?[...accounts][0]:order.payment_account,
lines:converted.lines.map((line,index)=>({...Object.fromEntries(allowed.filter(key=>Object.hasOwn(line,key)).map(key=>[key,line[key]])),...(order.lines[index]?.returnedStockId?{returnedStockId:order.lines[index].returnedStockId}:{}),...(Number.isSafeInteger(order.lines[index]?.stockCount)?{stockCount:order.lines[index].stockCount}:{})})),fee_items:feeInputs(order)};
}
@@ -250,7 +250,7 @@ function editDeliveredLock(ledger,info,input,metadata,actor,env){
const lines=states.map(row=>row.line);
if(!Array.isArray(data.fee_items))env.fail('请完整带入本单所有实际费用后再修改,不能遗漏额外费用');
const cardFees=ledger.cardFeeInputs(order,data.fee_items),fees=ledger.validateFees(data.fee_items.filter(fee=>!isCardFee(fee)).map(fee=>({...fee,status:'estimated'})));
ledger.validateCompletedCosts(lines,fees);
ledger.validateCompletedCosts(lines,fees,{checkboxCosts:order.fee_cost_mode==='checkboxes'});
const feesDate=env.day(data.fees_date||date),feeState=(items,defaultDate)=>items.map(item=>({key:item.key,amount:env.money(item.amount,'实际费用'),payer:item.payer,note:item.note,date:env.day(item.date||defaultDate),expense_id:item.expense_id??null,funding:item.funding??null})).sort((a,b)=>a.key.localeCompare(b.key));
const costState=value=>Object.fromEntries(COST_FIELDS.map(key=>[key,value[key]])),financialChanged=date!==order.date||date!==order.delivered_date||states.some(row=>row.materialChanged||row.extraChanged||!same(costState(row.line),costState(order.lines[row.index])))||feesDate!==(order.fees_date||order.date)||!same(feeState(data.fee_items,feesDate),feeState(info.inputs.fee_items,info.inputs.fees_date));
if(!financialChanged)return editMetadata(ledger,order,metadata,actor);
@@ -338,7 +338,7 @@ function edit(ledger,id,input,actor,env){return atomic(ledger,()=>{
}
const rounding=input.rounding_mode??order.rounding_mode,total=Calc.orderTotal(lines.map(line=>line.sale),discount,rounding).total;
const fees=ledger.validateFees(input.fee_items.filter(fee=>!isCardFee(fee)).map(fee=>({...fee,status:'estimated'})));
ledger.validateCompletedCosts(lines,fees);
ledger.validateCompletedCosts(lines,fees,{checkboxCosts:order.fee_cost_mode==='checkboxes'});
const feesDate=env.day(input.fees_date||date),account=env.pick(CreditCardFees.normalizeAccount(input.payment_account),env.accounts,'收款账户');
const preservePayment=order.netReceived===total&&CreditCardFees.normalizeAccount(account)===CreditCardFees.normalizeAccount(info.inputs.payment_account);
const storedAccount=preservePayment?order.payment_account:CreditCardFees.normalizeAccount(account);