完善订单成本编辑与多商品置换,修正锁价跨天作废回池

This commit is contained in:
summer committed 2026-11-24 21:11:32 +08:00
1 parent a3262a455d
commit 2e4e7dad55
25 files changed
+430 -109

No files matched your search

+5 -4
View File
@@ -25,7 +25,7 @@ function recoveryEditPanelHTML(data){
}
function recoveryEditDraft(input){
const first=input.old_lines[0],x=input.exchange||{},charge=x.charges?.[0],fee=x.fee_items?.[0],account=input.payment_account||'',recipient=account.startsWith('麦麦')?'麦麦':account.startsWith('助理2')?'助理2':'助理',method=account.replace(/^(麦麦|助理2|助理1|助理)/,'');
return {...recoveryDefaults(input.mode),mode:input.mode,date:input.date,customer:input.customer,salesperson:input.salesperson,member:input.member,note:input.note||'',old_name:first.name,incoming_weight:first.incoming_weight,melted_weight:first.melted_weight,purity:first.purity,old_lines:JSON.parse(JSON.stringify(input.old_lines)),buy_rate:input.buy_rate,buy_total:input.buy_total??'',buy_total_manual:Object.hasOwn(input,'buy_total'),melted_manual:true,depreciation_manual:Object.hasOwn(x,'depreciation_weight'),payer:input.payer,payment_method:method,payment_recipient:recipient,payout_method:method==='信用卡'?'微信':method,new_name:x.name||'足金999',new_quantity:x.quantity||'',pocket:x.pocket||state.pockets[0]||'',stockCount:x.stockCount??'',gold_price:x.gold_price||'0',labor_mode:x.labor_mode||'gram',labor_rate:x.labor_rate||'0',depreciation_weight:x.depreciation_weight??'',depreciation_rate:x.depreciation_rate||'0',charge_name:charge?.name||'其他收费',charge_amount:charge?.amount||'0',charges:JSON.parse(JSON.stringify(x.charges||[])),discount:x.discount||'0',rounding_mode:x.rounding_mode||'cent',material_source:x.cost_material?.mode==='pool'?'pool':'manual',material_pool_id:x.cost_material?.poolId||input.date,material_rate:x.cost_material?.rate||'',material_payer:x.cost_material_payer||input.member,cost_labor_mode:x.cost_labor?.mode||'total',cost_labor_value:x.cost_labor?.mode==='gram'?x.cost_labor.rate:x.cost_labor?.amount??'',cost_payer:x.cost_payer||input.member,labor_payer:x.cost_labor_payer||x.cost_payer||input.member,fee_note:fee?.note||'其他费用',fee_amount:fee?.amount||'0',fee_payer:fee?.payer||input.member,fee_items:JSON.parse(JSON.stringify(x.fee_items||[])),verified:false};
return {...recoveryDefaults(input.mode),mode:input.mode,date:input.date,customer:input.customer,salesperson:input.salesperson,member:input.member,note:input.note||'',old_pocket:input.old_pocket??'回收旧料',old_stock_count:input.old_stock_count??'',old_name:first.name,incoming_weight:first.incoming_weight,melted_weight:first.melted_weight,purity:first.purity,old_lines:JSON.parse(JSON.stringify(input.old_lines)),buy_rate:input.buy_rate,buy_total:input.buy_total??'',buy_total_manual:Object.hasOwn(input,'buy_total'),melted_manual:true,depreciation_manual:Object.hasOwn(x,'depreciation_weight'),payer:input.payer,payment_method:method,payment_recipient:recipient,payout_method:method==='信用卡'?'微信':method,new_name:x.name||'足金999',new_quantity:x.quantity||'',pocket:x.pocket??state.pockets[0]??'',stockCount:x.stockCount??'',gold_price:x.gold_price||'0',labor_mode:x.labor_mode||'gram',labor_rate:x.labor_rate||'0',depreciation_weight:x.depreciation_weight??'',depreciation_rate:x.depreciation_rate||'0',charge_name:charge?.name||'其他收费',charge_amount:charge?.amount||'0',charges:JSON.parse(JSON.stringify(x.charges||[])),discount:x.discount||'0',rounding_mode:x.rounding_mode||'cent',material_source:x.cost_material?.mode==='pool'?'pool':'manual',material_pool_id:x.cost_material?.poolId||input.date,material_rate:x.cost_material?.rate||'',material_payer:x.cost_material_payer||input.member,cost_labor_mode:x.cost_labor?.mode||'total',cost_labor_value:x.cost_labor?.mode==='gram'?x.cost_labor.rate:x.cost_labor?.amount??'',cost_payer:x.cost_payer||input.member,labor_payer:x.cost_labor_payer||x.cost_payer||input.member,fee_note:fee?.note||'其他费用',fee_amount:fee?.amount||'0',fee_payer:fee?.payer||input.member,fee_items:JSON.parse(JSON.stringify(x.fee_items||[])),...(x.products?{...recoveryProductDraft(x.products[0]),extra_products:x.products.slice(1).map(recoveryProductDraft)}:{}),verified:false};
}
function recoveryEditFormDraft(form,flat){
const entry=recoveryEditEntry;if(!entry)return flat;const source=entry.draft,read=(row,name)=>recoveryText(row.querySelector('[name="'+name+'"]')?.value);
@@ -42,7 +42,7 @@ function recoveryEditRowsHTML(kind,rows){return rows.slice(1).map((row,offset)=>
function recoveryEditingFormHTML(entry){
const draft=entry.draft,locked=`<label>归属成员<input value="${e(teamMemberName(entry.data.inputs.member))}" readonly><input name="member" type="hidden" value="${e(entry.data.inputs.member)}"></label>`;
let html=recoveryFormHTML(draft).replace('<form id="recovery-form"','<form id="recovery-form" data-recovery-edit="true"').replace(/<div class="recovery-mode-switch"[\s\S]*?<\/div>/,`<p class="note">${e(recoveryModeNames[draft.mode])} · 沿用原单号 ${e(entry.data.record.number)},本单业务类型保持不变。</p>`).replace(recoveryMemberField(draft),locked).replace('保存后自动编号','沿用原单号').replace('<p class="small muted recovery-formula" id="recovery-folded-formula"',`${recoveryEditRowsHTML('old',draft.old_lines)}${button('+ 添加旧料','recovery-edit-add-row','quiet','data-kind="old"')}<p class="small muted recovery-formula" id="recovery-folded-formula"`);
if(draft.pocket&&!activePocketKeys().includes(draft.pocket))html=html.replace(pocketChoice('出货货盘','pocket',draft.pocket,{blank:null}),pocketChoice('出货货盘','pocket',draft.pocket,{blank:null,historical:true}));
if(draft.pocket&&!activePocketKeys().includes(draft.pocket))html=html.replace(pocketChoice('出货货盘','pocket',draft.pocket,{blank:'外配(不扣店内库存)'}),pocketChoice('出货货盘','pocket',draft.pocket,{blank:'外配(不扣店内库存)',historical:true}));
html=html.replace('</div></details></section><section class="panel recovery-buy-panel">',`</div>${recoveryEditRowsHTML('charge',draft.charges)}${button('+ 添加收费','recovery-edit-add-row','quiet','data-kind="charge"')}</details></section><section class="panel recovery-buy-panel">`);
html=html.replace('</div></details><p class="small recovery-formula" id="recovery-internal-preview"',`</div>${recoveryEditRowsHTML('fee',draft.fee_items)}${button('+ 添加实际费用','recovery-edit-add-row','quiet','data-kind="fee"')}</details><p class="small recovery-formula" id="recovery-internal-preview"`);
html=html.replace('<section class="panel recovery-save-panel">',`<section class="panel recovery-save-panel"><div class="note" id="recovery-edit-mode" aria-live="polite"></div>${legacyCountConfirmationHTML(entry.data.permissions)}${field('修改原因','change_reason',entry.reason||'','text','required maxlength="200"')}<div id="recovery-edit-conflict" aria-live="polite">${entry.invalid?`<p class="error">记录已有变动,填写已保留,请核对最新记录。</p>${button('重新读取并核对','recovery-edit-reload','',`data-id="${e(entry.id)}"`)}${entry.latest?button('已核对最新记录,保留填写继续','recovery-edit-keep','','data-id="'+e(entry.id)+'"'):''}`:''}</div>`).replace('<button type="submit" class="primary" id="recovery-save">',`${button('取消修改','recovery-edit-close','quiet')}<button type="submit" class="primary" id="recovery-save">`);return html;
@@ -72,8 +72,9 @@ function recoveryCompareCell(value){return e(value==null||value===''?'未提供'
function recoveryChangeComparisonHTML(raw){
const request=validateRecoveryChangeRequest(raw),before=request.before,after=request.after,pair=(title,a,b)=>`<tr${String(a??'')!==String(b??'')?' class="order-change-modified"':''}><th scope="row">${e(title)}</th><td>${recoveryCompareCell(a)}</td><td>${recoveryCompareCell(b)}</td></tr>`,old=input=>input?.old_lines.map(row=>`${row.name}:来料 ${row.incoming_weight}g,熔后 ${row.melted_weight}g,成色 ${row.purity}%`).join('\n'),fees=input=>input?.exchange?.fee_items.map(row=>`${row.note}:${row.amount}元 · ${teamMemberName(row.payer)}付款`).join('\n')||'无',charges=input=>input?.exchange?.charges.map(row=>`${row.name}:${row.amount}元`).join('\n')||'无';
const x=before.exchange||{},y=after?.exchange||{},material=value=>value?.mode==='pool'?'料池 '+value.poolId:value?'手填 '+value.rate+'元/克':'无补金差重',labor=value=>value?value.mode==='gram'?value.rate+'元/克':value.amount+'元总工费':'未提供';
let rows=pair('业务日期',before.date,after?.date||'取消原记录')+pair('客户',before.customer,after?.customer)+pair('开单人',before.salesperson,after?.salesperson)+pair('归属',teamMemberName(before.member),after?teamMemberName(after.member):'沿用原身份留档')+pair('旧料逐项称重',old(before),after?old(after):'冲正原库存及关联购料')+pair('回收单价(元/克)',before.buy_rate,after?.buy_rate)+pair('回收结算额(元)',before.buy_total,after?.buy_total)+pair('实际收付款账户',accountDisplayName(before.payment_account),after?accountDisplayName(after.payment_account):'冲正原收付记录')+pair('付款人',teamMemberName(before.payer),after?teamMemberName(after.payer):'原付款流水保留')+pair('备注',before.note,after?.note);
if(before.mode==='exchange')rows+=pair('置换新货',x.name,y.name)+pair('新货克重(g)',x.quantity,y.quantity)+pair('实际货盘',pocketLabel(x.pocket),pocketLabel(y.pocket))+pair('出库数量(对)',stockCountText(x.stockCount==null?null:Number(x.stockCount)),stockCountText(y.stockCount==null?null:Number(y.stockCount)))+pair('销售金价(元/克)',x.gold_price,y.gold_price)+pair('销售工费',x.labor_rate+'元/'+(x.labor_mode==='gram'?'克':'总额'),after?y.labor_rate+'元/'+(y.labor_mode==='gram'?'克':'总额'):'取消')+pair('折旧计费克重/单价',x.depreciation_weight+'g × '+x.depreciation_rate+'元/克',after?y.depreciation_weight+'g × '+y.depreciation_rate+'元/克':'取消')+pair('附加收费',charges(before),after?charges(after):'取消')+pair('优惠(元)',x.discount,y.discount)+pair('取整方式',x.rounding_mode==='yuan'?'四舍五入到元':'保留到分',after?(y.rounding_mode==='yuan'?'四舍五入到元':'保留到分'):'取消')+pair('补金差重进货来源',material(x.cost_material),after?material(y.cost_material):'释放原耗用')+pair('料费付款人',teamMemberName(x.cost_material_payer),after?teamMemberName(y.cost_material_payer):'原来源留档')+pair('进货工费',labor(x.cost_labor),after?labor(y.cost_labor):'取消')+pair('工费付款人',teamMemberName(x.cost_labor_payer),after?teamMemberName(y.cost_labor_payer):'原来源留档')+pair('实际费用',fees(before),after?fees(after):'冲正原费用');
let rows=pair('业务日期',before.date,after?.date||'取消原记录')+pair('客户',before.customer,after?.customer)+pair('开单人',before.salesperson,after?.salesperson)+pair('归属',teamMemberName(before.member),after?teamMemberName(after.member):'沿用原身份留档')+pair('旧料逐项称重',old(before),after?old(after):'冲正原库存及关联购料')+pair('旧料入库货盘',pocketLabel(before.old_pocket??'回收旧料'),after?pocketLabel(after.old_pocket??'回收旧料'):'冲回原入库货盘')+pair('旧料入库数量(对)',stockCountText(before.old_stock_count==null?null:Number(before.old_stock_count)),after?stockCountText(after.old_stock_count==null?null:Number(after.old_stock_count)):'冲回原入库数量')+pair('回收单价(元/克)',before.buy_rate,after?.buy_rate)+pair('回收结算额(元)',before.buy_total,after?.buy_total)+pair('实际收付款账户',accountDisplayName(before.payment_account),after?accountDisplayName(after.payment_account):'冲正原收付记录')+pair('付款人',teamMemberName(before.payer),after?teamMemberName(after.payer):'原付款流水保留')+pair('备注',before.note,after?.note);
if(before.exchange?.products||after?.exchange?.products){const items=x=>(x?.products??(x?[x]:[])).map((p,i)=>(i+1)+' · '+p.name+' · '+p.quantity+'g · '+(pocketLabel(p.pocket)||'外配')+' · 销售工费 '+p.labor_rate+(p.labor_mode==='total'?'元':'元/克')+' · 进货工费 '+(p.cost_labor?.rate??p.cost_labor?.amount??'待补')+' · '+teamMemberName(p.cost_labor_payer)+(p.stockCount==null?'':' · '+p.stockCount+'对')).join(';');rows+=pair('逐件置换商品',items(before.exchange),after?items(after.exchange):'冲回全部新货出库');}
if(before.mode==='exchange')rows+=pair('置换新货',x.name,y.name)+pair('新货克重(g)',x.quantity,y.quantity)+pair('实际货盘',pocketLabel(x.pocket)||'外配',after?(pocketLabel(y.pocket)||'外配'):'冲回原出库货盘')+pair('出库数量(对)',stockCountText(x.stockCount==null?null:Number(x.stockCount)),stockCountText(y.stockCount==null?null:Number(y.stockCount)))+pair('销售金价(元/克)',x.gold_price,y.gold_price)+pair('销售工费',x.labor_rate+'元/'+(x.labor_mode==='gram'?'克':'总额'),after?y.labor_rate+'元/'+(y.labor_mode==='gram'?'克':'总额'):'取消')+pair('折旧计费克重/单价',x.depreciation_weight+'g × '+x.depreciation_rate+'元/克',after?y.depreciation_weight+'g × '+y.depreciation_rate+'元/克':'取消')+pair('附加收费',charges(before),after?charges(after):'取消')+pair('优惠(元)',x.discount,y.discount)+pair('取整方式',x.rounding_mode==='yuan'?'四舍五入到元':'保留到分',after?(y.rounding_mode==='yuan'?'四舍五入到元':'保留到分'):'取消')+pair('补金差重进货来源',material(x.cost_material),after?material(y.cost_material):'释放原耗用')+pair('料费付款人',teamMemberName(x.cost_material_payer),after?teamMemberName(y.cost_material_payer):'原来源留档')+pair('进货工费',labor(x.cost_labor),after?labor(y.cost_labor):'取消')+pair('工费付款人',teamMemberName(x.cost_labor_payer),after?teamMemberName(y.cost_labor_payer):'原来源留档')+pair('实际费用',fees(before),after?fees(after):'冲正原费用');
const a=request.summary.before||{},b=request.summary.after||{};rows+=[['实际收客户','cashReceipt'],['实际付客户','cashPayment'],['购料成本','purchaseAmount'],['订单货品成本','goodsCost'],['实际费用','directCost'],['原账利润','profit']].map(([title,key])=>pair(title,a[key]==null?'待核实':'¥'+yuan(a[key]),after?(b[key]==null?'待核实':'¥'+yuan(b[key])):'取消后冲正')).join('');
return `${request.summary.legacyCountNotice?'<p class="note">'+e(request.summary.legacyCountNotice)+(request.summary.legacyCountVerified?'(申请人已确认)':'')+'</p>':''}<div class="table-wrap recovery-change-comparison"><table class="order-change-table" aria-label="回收更正原值与申请值"><thead><tr><th>核对项目</th><th>原值</th><th>${request.action==='cancel'?'取消后':'申请值'}</th></tr></thead><tbody>${rows}</tbody></table></div>${request.action==='cancel'?recoveryBlockedHTML(request.summary.blockedUsages||[],false)+recoveryCancellationMaterialHTML():''}`;
}