取消已用回收单时将关联用料转入公共料池

This commit is contained in:
summer committed 2026-11-05 00:04:01 +08:00
1 parent 19b1b0263c
commit dec01a3dca
18 files changed
+380 -56

No files matched your search

+7 -4
View File
@@ -14,7 +14,9 @@ function lockFormValue(form,name){return form.querySelector(`[name="${name}"]`)?
function lockCharges(root){return [...root.querySelectorAll('.charge-row')].map(row=>{const value=name=>row.querySelector(`[name="${name}"]`).value,type=value('chargeType'),customName=value('chargeName');return {id:row.dataset.chargeId,nameType:type,customName,name:type==='其他'?customName:type,amount:value('chargeAmount'),chargePrices:JSON.parse(row.dataset.chargePrices)};});}
function syncLockChargeFields(root){for(const row of root.querySelectorAll('.charge-row')){const custom=row.querySelector('[name="chargeType"]').value==='其他',input=row.querySelector('[name="chargeName"]');input.closest('label').hidden=!custom;input.disabled=!custom;input.required=custom;}}
const priceLockUsesPool=lock=>lock?.material_source==='pool';
function priceLockMaterialAllocations(lock){return priceLockUsesPool(lock)?lock.materialPool?.allocations||[]:[{payer:lock.buy_payer,amount:lock.material_amount}];}
const priceLockMaterialPending=lock=>lock?.material_amount===null||priceLockUsesPool(lock)&&(lock.materialPool?.status==='pending'||lock.materialPool?.amount===null);
function priceLockMaterialAmountText(lock){const amount=priceLockUsesPool(lock)&&Number.isSafeInteger(lock.materialPool?.amount)?lock.materialPool.amount:lock.material_amount;return priceLockMaterialPending(lock)||!Number.isSafeInteger(amount)?'料费待补':'¥'+yuan(amount);}
function priceLockMaterialAllocations(lock){return priceLockMaterialPending(lock)?[]:priceLockUsesPool(lock)?lock.materialPool?.allocations||[]:[{payer:lock.buy_payer,amount:lock.material_amount}];}
function priceLockAllocationText(allocations){return allocations.map(part=>priceLockPayerName(part.payer)+' ¥'+yuan(part.amount)).join(';');}
function priceLockAllocationHTML(allocations){return allocations.map(part=>`<span>${e(priceLockPayerName(part.payer))} <b>¥${yuan(part.amount)}</b></span>`).join('');}
function priceLockCreateMaterialHTML(material){
@@ -104,8 +106,9 @@ function priceLockCardFeesHTML(lock){
}
function priceLockDialog(){let dialog=$('#price-lock-dialog');if(!dialog){dialog=document.createElement('dialog');dialog.id='price-lock-dialog';document.body.append(dialog);}return dialog;}
function priceLockFacts(lock){
const pool=priceLockUsesPool(lock),material=lock.materialPool;
return `<div class="grid three price-lock-facts"><div>锁价日期<strong>${e(lock.date)}</strong></div><div>原锁克重<strong>${grams(lock.locked_mg)}g</strong></div><div>锁定销售金价<strong>¥${yuan(lock.sell_rate)}/克</strong></div><div>${lock.status==='delivered'?'锁价及交付阶段净收款':'客户实际已付净额'}<strong>¥${yuan(lock.netReceived)}</strong>${lock.status==='delivered'?'<small>后续收退款请查看销售单。</small>':''}</div><div>原锁料费 · ${pool?'当日加权料池':'手动独立购料'}<strong>¥${yuan(lock.material_amount)}</strong><small>${pool?material?.materialSources?.length?e(materialSourceSegmentsText(material.materialSources)):`${e(material?.date||lock.material_pool_id||lock.date)}料池,加权均价约 ¥${yuan(material?.averageRate??lock.buy_rate)}/克`:`${e(priceLockPayerName(lock.buy_payer))}支付,进货料价 ¥${yuan(lock.buy_rate)}/克`}</small>${pool?`<small>${e(priceLockAllocationText(priceLockMaterialAllocations(lock)))}</small><small>${material?.frozen?'已冻结锁价日成本':'当天补料继续加权'},不重复记购料付款。</small>`:''}</div><div>状态<strong>${lock.status==='pending'?'待交付,不计利润':'已交付'}</strong></div></div>`+priceLockCardFeesHTML(lock);
const pool=priceLockUsesPool(lock),material=lock.materialPool,pendingMaterial=priceLockMaterialPending(lock);
const source=pendingMaterial?'<small>关联用料不足,补足购料后自动核算料费与付款来源。</small>':`<small>${pool?material?.materialSources?.length?e(materialSourceSegmentsText(material.materialSources)):`${e(material?.date||lock.material_pool_id||lock.date)}料池,加权均价约 ¥${yuan(material?.averageRate??lock.buy_rate)}/克`:`${e(priceLockPayerName(lock.buy_payer))}支付,进货料价 ¥${yuan(lock.buy_rate)}/克`}</small>${pool?`<small>${e(priceLockAllocationText(priceLockMaterialAllocations(lock)))}</small><small>${material?.frozen?'已冻结锁价日成本':'当天补料继续加权'},不重复记购料付款。</small>`:''}`;
return `<div class="grid three price-lock-facts"><div>锁价日期<strong>${e(lock.date)}</strong></div><div>原锁克重<strong>${grams(lock.locked_mg)}g</strong></div><div>锁定销售金价<strong>¥${yuan(lock.sell_rate)}/克</strong></div><div>${lock.status==='delivered'?'锁价及交付阶段净收款':'客户实际已付净额'}<strong>¥${yuan(lock.netReceived)}</strong>${lock.status==='delivered'?'<small>后续收退款请查看销售单。</small>':''}</div><div>原锁料费 · ${pool?'当日加权料池':'手动独立购料'}<strong>${priceLockMaterialAmountText(lock)}</strong>${source}</div><div>状态<strong>${lock.status==='pending'?'待交付,不计利润':'已交付'}</strong></div></div>`+priceLockCardFeesHTML(lock);
}
function priceLockSplitMaterialSources(pool,mg){
let left=mg;const taken=[],rest=[];if(!Array.isArray(pool.materialSources)||pool.materialSources.reduce((sum,source)=>sum+source.quantity,0)!==pool.quantity||pool.materialSources.reduce((sum,source)=>sum+source.amount,0)!==pool.amount)throw new Error('原锁分来源克重或成本未完整读到,请重新读取。');
@@ -138,7 +141,7 @@ async function renderPriceLocks(){
const request=++priceLockRequest,user=state.user.id;
$('#main').innerHTML=heading('PENDING DELIVERY','待交付','显示所有日期的锁价待交付记录。锁价时只记实际收付,交付后才计销售、成本和利润。',button('新增锁价','new-price-lock','primary')+button('刷新','refresh-price-locks'))+'<section class="panel"><div id="price-lock-list" aria-live="polite">正在读取待交付记录…</div></section>';
try{const result=await api('/api/price-locks?status=pending');if(request!==priceLockRequest||tab!=='price-locks'||state.user.id!==user||!$('#price-lock-list'))return;if(!Array.isArray(result.rows))throw new Error('待交付记录未完整返回,请重试。');
$('#price-lock-list').innerHTML=result.rows.length?`<div class="table-wrap"><table class="price-lock-list"><thead><tr><th>锁价日期/客户</th><th>黄金商品</th><th class="number">锁定克重</th><th class="number">销售金价</th><th class="number">已收净额</th><th>原料来源/成本</th><th>操作</th></tr></thead><tbody>${result.rows.map(lock=>`<tr><td>${e(lock.date)}<br>${e(lock.customer)}</td><td>${e(lock.line?.name||lock.product||'黄金')}</td><td class="number">${grams(lock.locked_mg)}g</td><td class="number">¥${yuan(lock.sell_rate)}/克</td><td class="number">¥${yuan(lock.netReceived)}</td><td><strong>${priceLockUsesPool(lock)?'当日加权料池':'手动独立购料'}</strong><br>¥${yuan(lock.material_amount)}<div class="small muted">${e(priceLockAllocationText(priceLockMaterialAllocations(lock)))}</div></td><td><div class="actions">${button('查看','open-price-lock','',`data-id="${e(lock.id)}"`)}${button('交付','deliver-price-lock','primary',`data-id="${e(lock.id)}"`)}</div></td></tr>`).join('')}</tbody></table></div>`:'<div class="empty"><strong>目前没有锁价待交付记录</strong>已交付记录会进入订单列表。</div>';
$('#price-lock-list').innerHTML=result.rows.length?`<div class="table-wrap"><table class="price-lock-list"><thead><tr><th>锁价日期/客户</th><th>黄金商品</th><th class="number">锁定克重</th><th class="number">销售金价</th><th class="number">已收净额</th><th>原料来源/成本</th><th>操作</th></tr></thead><tbody>${result.rows.map(lock=>`<tr><td>${e(lock.date)}<br>${e(lock.customer)}</td><td>${e(lock.line?.name||lock.product||'黄金')}</td><td class="number">${grams(lock.locked_mg)}g</td><td class="number">¥${yuan(lock.sell_rate)}/克</td><td class="number">¥${yuan(lock.netReceived)}</td><td><strong>${priceLockUsesPool(lock)?'当日加权料池':'手动独立购料'}</strong><br>${priceLockMaterialAmountText(lock)}<div class="small muted">${priceLockMaterialPending(lock)?'补足购料后自动核算付款来源':e(priceLockAllocationText(priceLockMaterialAllocations(lock)))}</div></td><td><div class="actions">${button('查看','open-price-lock','',`data-id="${e(lock.id)}"`)}${button('交付','deliver-price-lock','primary',`data-id="${e(lock.id)}"`)}</div></td></tr>`).join('')}</tbody></table></div>`:'<div class="empty"><strong>目前没有锁价待交付记录</strong>已交付记录会进入订单列表。</div>';
}catch(err){if(request===priceLockRequest&&tab==='price-locks'&&$('#price-lock-list'))$('#price-lock-list').innerHTML=`<div class="error">${e(err.message)} ${button('重新读取','refresh-price-locks')}</div>`;}
}
async function openPriceLock(id){