支持回收单修改取消、按归属人优先用料及锁价交付改单

This commit is contained in:
summer committed 2026-11-04 22:18:56 +08:00
1 parent 0e146739bc
commit 19b1b0263c
41 files changed
+1814 -203

No files matched your search

+6 -1
View File
@@ -108,6 +108,11 @@ function orderChangeInventoryHTML(inventory){
const table=(title,rows,changes=false)=>`<h3>${title}</h3>${rows.length?`<div class="table-wrap"><table class="order-change-inventory"><thead><tr><th>日期</th><th>货盘</th>${changes?'':'<th>库存业务</th>'}<th class="number">${changes?'本次增减':'已记克重'}</th></tr></thead><tbody>${rows.map(row=>`<tr><td>${e(row.date)}</td><td>${e(row.pocket)}</td>${changes?'':`<td>${e(row.kind||'未提供')}</td>`}<td class="number">${row.mg>0?'+':''}${grams(row.mg)}g</td></tr>`).join('')}</tbody></table></div>`:`<p class="small muted">${changes?'本次没有黄金货盘净变动。':'没有本单库存流水。'}</p>`}`;
return `<section class="order-change-inventory-summary"><h3>库存原值与批准后变化</h3><p class="small muted">以下为本单各日期、货盘的库存流水;正数为增加,负数为减少。按件商品或退回供应商不计黄金货盘。</p>${table('原库存记录',inventory.before)}${table('同意后的库存记录',inventory.after)}${table('本次库存净变化',inventory.changes,true)}</section>`;
}
function orderChangePriceLockCostsHTML(before,after){
if(!before.priceLockCosts&&!after.priceLockCosts)return '';
const a=before.priceLockCosts||{},b=after.priceLockCosts||{},source=value=>value==='pool'?'原锁料池':value==='manual'?'手填原锁料价':'未提供';
return '<tr class="change-section-row"><th colspan="3" scope="colgroup">锁价购料成本</th></tr>'+orderChangePair('原锁日期',a.date,b.date)+orderChangePair('原锁料费来源',source(a.materialSource),source(b.materialSource))+orderChangePair('原锁进货料价(每克)',orderChangeMoney(a.buyRate),orderChangeMoney(b.buyRate))+orderChangePair('原锁料费付款人',a.materialSource==='pool'?'按原锁料池分摊':orderChangePayer(a.buyPayer),b.materialSource==='pool'?'按原锁料池分摊':orderChangePayer(b.buyPayer))+orderChangePair('原锁整批料费',orderChangeMoney(a.materialAmount),orderChangeMoney(b.materialAmount))+orderChangePair('补重进货料价(每克)',orderChangeMoney(a.extraRate),orderChangeMoney(b.extraRate))+orderChangePair('补重料费付款人',a.extraPayer?orderChangePayer(a.extraPayer):'无补重',b.extraPayer?orderChangePayer(b.extraPayer):'无补重');
}
function orderChangeComparisonHTML(raw){
const request=validateOrderChangeRequest(raw),before=request.before,after=request.after;
const basic=[['业务日期','date'],['客户称呼/代号','customer'],['开单人','salesperson'],['收款方式与收款人','payment_account'],['客户单备注','note'],['内部备注(客户不可见)','internal_note']].map(([title,key])=>orderChangePair(title,key==='payment_account'?accountDisplayName(before[key]):before[key],key==='payment_account'?accountDisplayName(after[key]):after[key])).join('')+
@@ -116,7 +121,7 @@ function orderChangeComparisonHTML(raw){
const summary=[['成交金额','total'],['收款净额','netReceived'],['货品成本','goodsCost'],['实际费用合计','directCost'],['利润','profit'],['双方待结净额','settlementDue']].map(([title,key])=>orderChangePair(title,orderChangeMoney(request.summary.before[key]),orderChangeMoney(request.summary.after[key]))).join('');
const lines=Array.from({length:Math.max(before.lines.length,after.lines.length)},(_,index)=>`<tr class="change-section-row"><th colspan="3" scope="colgroup">商品 ${index+1}</th></tr>${[['商品与销售计价说明','name'],['商品编号','code'],['克重/数量','quantity'],['销售金价、工费与件数','pricing'],['成交金额(含附加收费)','sale'],['客户附加收费','charges'],['货盘','pocket'],['货品成本合计','cost'],['进货料价与料费','material'],['进货工费','labor'],['其他货品成本','extra'],['成本付款人','payers']].map(([title,key])=>orderChangePair(title,orderChangeLineValue(before.lines[index],key),orderChangeLineValue(after.lines[index],key))).join('')}`).join('');
const related=(request.relatedOrders||[]).map(item=>`<section class="order-change-related"><h3>同时受影响的关联订单:${e(item.number||item.id)}</h3><p class="small muted">本次修改会重新分配同批购料的成本及付款人。以下关联订单的利润与待结金额也会随批准一起更新。</p>${orderChangeComparisonHTML({...request,order_id:item.id,before:item.before,after:item.after,summary:item.summary,relatedOrders:[],relatedPriceLocks:[]})}</section>`).join('');
return `<div class="order-change-comparison"><p class="small muted">原值为申请时快照,申请值由服务器按本次变更试算。批准前请核对客户实付、商品、成本、费用及付款人。</p><div class="table-wrap"><table class="order-change-table" aria-label="变更申请原值与申请值对照"><thead><tr><th>核对项目</th><th>原值(申请时)</th><th>申请值(同意后)</th></tr></thead><tbody>${basic}${orderChangePair('订单状态',label[before.status]||before.status,label[after.status]||after.status)}${orderChangePair('退货日期',before.returned_date,after.returned_date)}${orderChangePair('整单优惠',orderChangeMoney(before.discount),orderChangeMoney(after.discount))}${summary}${lines}<tr class="change-section-row"><th colspan="3" scope="colgroup">逐笔收退款与实际费用</th></tr>${orderChangePair('有效客户收退款/账户',orderChangePaymentsValue(before),orderChangePaymentsValue(after))}${orderChangePair('已记实际费用/日期/付款人',orderChangeExpensesValue(before),orderChangeExpensesValue(after))}</tbody></table></div>${orderChangeInventoryHTML(request.summary.inventory)}${related}${relatedPriceLocksHTML(request.relatedPriceLocks)}<p class="small muted">双方已发生的实际交款保留;试算不会发起真实收款、退款或转账。批准时仍会校验订单和关联资料版本。</p></div>`;
return `<div class="order-change-comparison"><p class="small muted">原值为申请时快照,申请值由服务器按本次变更试算。批准前请核对客户实付、商品、成本、费用及付款人。</p><div class="table-wrap"><table class="order-change-table" aria-label="变更申请原值与申请值对照"><thead><tr><th>核对项目</th><th>原值(申请时)</th><th>申请值(同意后)</th></tr></thead><tbody>${basic}${orderChangePriceLockCostsHTML(before,after)}${orderChangePair('订单状态',label[before.status]||before.status,label[after.status]||after.status)}${orderChangePair('退货日期',before.returned_date,after.returned_date)}${orderChangePair('整单优惠',orderChangeMoney(before.discount),orderChangeMoney(after.discount))}${summary}${lines}<tr class="change-section-row"><th colspan="3" scope="colgroup">逐笔收退款与实际费用</th></tr>${orderChangePair('有效客户收退款/账户',orderChangePaymentsValue(before),orderChangePaymentsValue(after))}${orderChangePair('已记实际费用/日期/付款人',orderChangeExpensesValue(before),orderChangeExpensesValue(after))}</tbody></table></div>${orderChangeInventoryHTML(request.summary.inventory)}${related}${relatedPriceLocksHTML(request.relatedPriceLocks)}<p class="small muted">双方已发生的实际交款保留;试算不会发起真实收款、退款或转账。批准时仍会校验订单和关联资料版本。</p></div>`;
}
function requireOrderChangeDetail(){
if(busy)throw new Error('正在保存,请稍候。');