完善订单审批、每日对账与信用卡手续费
加入助理订单变更复核、收款人汇总、每日报销和应转金额;优化库存筛选、订单明细与连续浏览。开单身份必填,信用卡手续费按实收4‰自动计算并默认由麦麦承担,打印优惠显示在人民币大写旁。 验证:484项测试通过;独立HTTP与浏览器覆盖普通订单、锁价、修改审批、断线恢复和打印隔离。旧报表兼容,本机升级原29表295行数据保持一致。
This commit is contained in:
1 parent
27a11e9b35
commit
a506fb1228
68 files changed
+3591
-259
No files matched your search
@@ -15,11 +15,11 @@ function lockCharges(root){return [...root.querySelectorAll('.charge-row')].map(
|
||||
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;}}
|
||||
function collectPriceLockCreate(){
|
||||
const form=$('#price-lock-create-form'),get=name=>lockFormValue(form,name);
|
||||
return {date:get('date'),customer:get('customer').trim(),salesperson:get('salesperson'),note:get('note'),discount:get('discount'),line:{name:get('name').trim(),unit:'g',pricingMode:'auto',quantity:get('quantity'),goldPrice:get('goldPrice'),laborRate:get('laborRate'),laborMode:get('laborMode'),pieces:get('pieces'),charges:lockCharges(form)},payment:{amount:get('received_amount'),account:get('payment_recipient')+get('payment_method'),verified:form.querySelector('[name="payment_verified"]').checked},material:{rate:get('material_rate'),payer:get('material_payer'),verified:form.querySelector('[name="material_verified"]').checked}};
|
||||
return {date:get('date'),customer:get('customer').trim(),salesperson:get('salesperson'),note:get('note'),discount:get('discount'),line:{name:get('name').trim(),unit:'g',pricingMode:'auto',quantity:get('quantity'),goldPrice:get('goldPrice'),laborRate:get('laborRate'),laborMode:get('laborMode'),pieces:get('pieces'),charges:lockCharges(form)},payment:{amount:get('received_amount'),account:get('payment_recipient')+get('payment_method'),credit_card_fee_payer:readCreditCardPayer(form),verified:form.querySelector('[name="payment_verified"]').checked},material:{rate:get('material_rate'),payer:get('material_payer'),verified:form.querySelector('[name="material_verified"]').checked}};
|
||||
}
|
||||
function renderPriceLockCreate(){
|
||||
const d=priceLockReadDraft(priceLockDraftKey())||{},line=d.line||{},payment=d.payment||{},material=d.material||{};
|
||||
$('#main').innerHTML=heading('GOLD PRICE LOCK','黄金锁价','每张锁价记录一件按克黄金;多件请分别锁价。保存后进入待交付,暂不出入库、不计利润。',priceLockCreateControls())+`<form id="price-lock-create-form"><section class="panel"><h2>客户与锁价日期</h2><div class="grid four">${field('锁价日期','date',d.date||state.today,'date',`required max="${e(state.today)}"`)}${field('客户称呼/代号','customer',d.customer||'','text','required maxlength="60"')}${field('经办人','salesperson',d.salesperson||session.user.name,'text','required maxlength="30"')}${field('黄金商品','name',line.name||'足金999','text','required maxlength="60"')}</div></section><section class="panel line-item" data-price-lock-sale><h2>锁定售价与预计克重</h2><div class="grid four">${field('锁定克重(g)','quantity',line.quantity||'','number','required min="0.001" step="0.001"')}${moneyField('锁定销售金价(元/克)','goldPrice',line.goldPrice||'')}${choice('销售工费方式','laborMode',[['gram','克工费'],['piece','件工费']],line.laborMode||'gram')}${moneyField('销售工费','laborRate',line.laborRate??'')}${field('计工费件数','pieces',line.pieces||'1','number','required min="1" step="1"')}</div><div class="sale-charges"><div class="panel-title"><strong>客户附加项目(选填)</strong>${button('+ 添加附加项目','add-charge')}</div><p class="small muted">沿用直接开单的收费默认值,可按实际修改;交付时会保留这些项目。</p><div class="charge-list">${(line.charges||[]).map(chargeHTML).join('')}</div></div><div class="grid two" style="margin-top:16px">${moneyField('整单优惠(元)','discount',d.discount??'0')}<label>客户可见备注<textarea name="note" maxlength="170" rows="2">${e(d.note||'')}</textarea></label></div><p id="lock-sale-estimate" class="calculation small" aria-live="polite"></p></section><section class="panel"><h2>客户实际已付款</h2><p class="small muted">填写已经收到的金额,可与预计报价不同;尚未收款填0。</p><div class="grid three">${moneyField('实际收款(元)','received_amount',payment.amount??'')}${accountFields(payment.account)}</div><label class="check"><input type="checkbox" name="payment_verified" ${payment.verified?'checked':''} required>已核实实际收款金额与账户。</label></section><section class="panel internal"><h2>原锁金料实际成本</h2><div class="grid three">${moneyField('原锁进货料价(元/克)','material_rate',material.rate??'')}${choice('原锁料费付款人','material_payer',[['owner','麦麦'],['assistant','助理']],material.payer||'owner')}<div><span class="small muted">这批金料已付金额</span><div id="lock-material-estimate" class="summary-amount">待填写</div></div></div><label class="check"><input type="checkbox" name="material_verified" ${material.verified?'checked':''} required>已核实原锁金料的实际付款。</label><p class="small muted">此处只记原锁金料付款;工费、快递等在交付时填写实际成本。库存归属也在交付时确认。</p></section><section class="panel"><div class="form-actions"><div><span class="small muted">预计成交额 · 四舍五入到元</span><div id="lock-create-total" class="summary-amount">待填写</div><div class="small muted">待交付,不计利润</div></div><button class="primary" type="submit">保存锁价待交付</button></div><div id="price-lock-error" aria-live="polite"></div></section></form>`;
|
||||
$('#main').innerHTML=heading('GOLD PRICE LOCK','黄金锁价','每张锁价记录一件按克黄金;多件请分别锁价。保存后进入待交付,暂不出入库、不计利润。',priceLockCreateControls())+`<form id="price-lock-create-form"><section class="panel"><h2>客户与锁价日期</h2><div class="grid four">${field('锁价日期','date',d.date||state.today,'date',`required max="${e(state.today)}"`)}${field('客户称呼/代号(必填)','customer',d.customer||'','text','required maxlength="60"')}${field('开单人(必填)','salesperson',d.salesperson||session.user.name,'text','required maxlength="30"')}${field('黄金商品','name',line.name||'足金999','text','required maxlength="60"')}</div></section><section class="panel line-item" data-price-lock-sale><h2>锁定售价与预计克重</h2><div class="grid four">${field('锁定克重(g)','quantity',line.quantity||'','number','required min="0.001" step="0.001"')}${moneyField('锁定销售金价(元/克)','goldPrice',line.goldPrice||'')}${choice('销售工费方式','laborMode',[['gram','克工费'],['piece','件工费']],line.laborMode||'gram')}${moneyField('销售工费','laborRate',line.laborRate??'')}${field('计工费件数','pieces',line.pieces||'1','number','required min="1" step="1"')}</div><div class="sale-charges"><div class="panel-title"><strong>客户附加项目(选填)</strong>${button('+ 添加附加项目','add-charge')}</div><p class="small muted">沿用直接开单的收费默认值,可按实际修改;交付时会保留这些项目。</p><div class="charge-list">${(line.charges||[]).map(chargeHTML).join('')}</div></div><div class="grid two" style="margin-top:16px">${moneyField('整单优惠(元)','discount',d.discount??'0')}<label>客户可见备注<textarea name="note" maxlength="170" rows="2">${e(d.note||'')}</textarea></label></div><p id="lock-sale-estimate" class="calculation small" aria-live="polite"></p></section><section class="panel"><h2>客户实际已付款</h2><p class="small muted">填写已经收到的金额,可与预计报价不同;尚未收款填0。</p><div class="grid three">${moneyField('实际收款(元)','received_amount',payment.amount??'')}${accountFields(payment.account)}</div><label class="check"><input type="checkbox" name="payment_verified" ${payment.verified?'checked':''} required>已核实实际收款金额与账户。</label>${creditCardPreviewHTML('lock-create-card-fee',payment.credit_card_fee_payer)}</section><section class="panel internal"><h2>原锁金料实际成本</h2><div class="grid three">${moneyField('原锁进货料价(元/克)','material_rate',material.rate??'')}${choice('原锁料费付款人','material_payer',[['owner','麦麦'],['assistant','助理']],material.payer||'owner')}<div><span class="small muted">这批金料已付金额</span><div id="lock-material-estimate" class="summary-amount">待填写</div></div></div><label class="check"><input type="checkbox" name="material_verified" ${material.verified?'checked':''} required>已核实原锁金料的实际付款。</label><p class="small muted">此处只记原锁金料付款;工费、快递等在交付时填写实际成本。库存归属也在交付时确认。</p></section><section class="panel"><div class="form-actions"><div><span class="small muted">预计成交额 · 四舍五入到元</span><div id="lock-create-total" class="summary-amount">待填写</div><div class="small muted">待交付,不计利润</div></div><button class="primary" type="submit">保存锁价待交付</button></div><div id="price-lock-error" aria-live="polite"></div></section></form>`;
|
||||
syncPriceLockForm();
|
||||
}
|
||||
function syncPriceLockCreate(){
|
||||
@@ -28,10 +28,17 @@ function syncPriceLockCreate(){
|
||||
const d=collectPriceLockCreate();
|
||||
try{const sale=LedgerCalc.sale(d.line),total=LedgerCalc.orderTotal([sale.sale],LedgerCalc.cents(d.discount),'yuan');$('#lock-create-total').textContent=orderAmount(total.total,'yuan');$('#lock-sale-estimate').textContent='商品及附加项目合计 ¥'+yuan(sale.sale)+';'+orderRoundingHint(total);}catch{$('#lock-create-total').textContent='待填写';$('#lock-sale-estimate').textContent='填写克重、销售金价与工费后显示预计报价。';}
|
||||
try{const cost=LedgerCalc.purchaseCosts({unit:'g',quantity:d.line.quantity,costParts:{material:'0',labor:'0',accessories:'0',other:'0'},costMaterial:{mode:'gram',rate:d.material.rate}});$('#lock-material-estimate').textContent=cost.total==null?'待填写':'¥'+yuan(cost.total);}catch{$('#lock-material-estimate').textContent='待填写';}
|
||||
let paymentCents=null;try{paymentCents=LedgerCalc.cents(d.payment.amount);}catch{}
|
||||
syncCreditCardPreview($('#lock-create-card-fee'),d.payment.account,paymentCents);
|
||||
localStorage.setItem(priceLockDraftKey(),JSON.stringify(d));
|
||||
}
|
||||
function priceLockCardFeeTotal(lock){return Number.isSafeInteger(lock.credit_card_fee_total)?lock.credit_card_fee_total:(lock.credit_card_fees||[]).reduce((sum,item)=>sum+item.amount,0);}
|
||||
function priceLockCardFeesHTML(lock){
|
||||
const fees=lock.credit_card_fees||[];if(!fees.length&&!priceLockCardFeeTotal(lock))return '';
|
||||
return `<div class="price-lock-card-fees internal"><strong>已记录的信用卡手续费 · ¥${yuan(priceLockCardFeeTotal(lock))}</strong><ul>${fees.map(item=>`<li><span>${e(item.date)} · ${e(priceLockPayerName(item.payer))}支付</span><b>¥${yuan(item.amount)}</b></li>`).join('')}</ul><p class="small muted">按每笔客户付款金额 × 4‰计入内部成本;交付时沿用,不重复收取。退款不冲回已发生的手续费。</p></div>`;
|
||||
}
|
||||
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){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>原锁料费<strong>¥${yuan(lock.material_amount)}</strong><small>${e(priceLockPayerName(lock.buy_payer))}支付,进货料价 ¥${yuan(lock.buy_rate)}/克</small></div><div>状态<strong>${lock.status==='pending'?'待交付,不计利润':'已交付'}</strong></div></div>`;}
|
||||
function priceLockFacts(lock){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>原锁料费<strong>¥${yuan(lock.material_amount)}</strong><small>${e(priceLockPayerName(lock.buy_payer))}支付,进货料价 ¥${yuan(lock.buy_rate)}/克</small></div><div>状态<strong>${lock.status==='pending'?'待交付,不计利润':'已交付'}</strong></div></div>`+priceLockCardFeesHTML(lock);}
|
||||
async function renderPriceLocks(){
|
||||
if(priceLockDeliveryId)return await renderPriceLockDelivery(priceLockDeliveryId);
|
||||
const request=++priceLockRequest,user=state.user.id;
|
||||
@@ -60,13 +67,13 @@ async function renderPriceLockDelivery(id){
|
||||
}
|
||||
currentPriceLock=lock;
|
||||
const saved=priceLockReadDraft(priceLockDeliveryKey(id)),draft=saved?.revision===lock.revision?saved:{},line=draft.line||priceLockLineInputs(lock),date=draft.date||state.today;
|
||||
$('#main').innerHTML=heading('LOCK DELIVERY','交付 · '+e(lock.customer),'最终克重全部按原锁销售金价结算;补重只新增进货成本。交付成功后生成正式销售单。',button('返回待交付','refresh-price-locks'))+`<section class="panel">${priceLockFacts(lock)}</section><form id="price-lock-delivery-form" data-id="${e(id)}" data-revision="${lock.revision}"><section class="panel"><div class="grid two">${field('交付日期','date',date,'date',`required min="${e(lock.date)}" max="${e(state.today)}"`)}${field('交付备注(客户可见,选填)','delivery_note',draft.note??lock.note??'','text','maxlength="170"')}</div></section><section class="panel price-lock-delivery-line"><div class="panel-title"><h2>最终商品与实际成本</h2><span class="small muted">一件黄金,保留原锁附加项目;可按实际增减。</span></div><div id="lines">${lineHTML(line,1)}</div></section><section class="panel internal"><h2>金料与库存确认</h2><p class="small muted">请选择本次交付所用的实际黄金货盘。已经记过入库的金料只出库,不会重复增加库存。</p><div class="grid two">${choice('原锁金料是否已记入这个货盘','original_stock',[['','请选择'],['receive','尚未记入,交付时先入库'],['stocked','此前已记入,只出库']],draft.inventory?.original||'')}<div id="lock-material-breakdown" class="lock-material-breakdown" aria-live="polite"></div></div><div id="lock-extra-material" hidden><h3>超出原锁克重的补重金料</h3><div class="grid three">${moneyField('补重进货料价(元/克)','extra_rate',draft.extraMaterial?.rate??'')}${choice('补重料费付款人','extra_payer',[['','请选择'],['owner','麦麦'],['assistant','助理']],draft.extraMaterial?.payer||'')}${choice('补重金料是否已记入所选货盘','extra_stock',[['','请选择'],['receive','尚未记入,交付时先入库'],['stocked','此前已记入,只出库']],draft.inventory?.extra||'')}</div><label class="check"><input type="checkbox" name="extra_verified" ${draft.extraMaterial?.verified?'checked':''}>已核实补重料费实际付款。</label></div><p id="lock-stock-note" class="note" aria-live="polite"></p></section>${feeHTML({...draft,date,fees_date:date})}<section class="panel"><div class="grid two">${moneyField('整单优惠(元)','discount',draft.discount??(lock.discount/100).toFixed(2))}<div><span class="small muted">最终成交额 · 四舍五入到元</span><div id="lock-final-total" class="summary-amount">待填写</div><p id="lock-rounding-note" class="small muted"></p></div></div><div class="lock-settlement"><h2 id="lock-settlement-title">客户补款/退款</h2><p id="lock-settlement-hint" class="small muted" aria-live="polite"></p><div id="lock-settlement-fields"><div class="grid three">${field('本次实际补退款(元)','settlement_amount','','number','readonly')}${accountFields(draft.settlement?.account||lock.cash_events.find(event=>event.kind==='receipt')?.account)}</div><label class="check"><input type="checkbox" name="settlement_verified" ${draft.settlement?.verified?'checked':''}>已核实本次补款到账/退款已实际完成。</label></div></div><label class="check"><input type="checkbox" name="delivery_verified" required>已核对实物、实际成本、出入库来源与客户收付款,确认交付。</label><div class="form-actions"><span class="small muted">保存后才记销售、完整成本和利润,可打印正式客户单据。</span><button type="submit" class="primary">确认交付并生成销售单</button></div><div id="price-lock-error" aria-live="polite"></div></section></form>`;
|
||||
$('#main').innerHTML=heading('LOCK DELIVERY','交付 · '+e(lock.customer),'最终克重全部按原锁销售金价结算;补重只新增进货成本。交付成功后生成正式销售单。',button('返回待交付','refresh-price-locks'))+`<section class="panel">${priceLockFacts(lock)}</section><form id="price-lock-delivery-form" data-id="${e(id)}" data-revision="${lock.revision}"><section class="panel"><div class="grid two">${field('交付日期','date',date,'date',`required min="${e(lock.date)}" max="${e(state.today)}"`)}${field('交付备注(客户可见,选填)','delivery_note',draft.note??lock.note??'','text','maxlength="170"')}</div></section><section class="panel price-lock-delivery-line"><div class="panel-title"><h2>最终商品与实际成本</h2><span class="small muted">一件黄金,保留原锁附加项目;可按实际增减。</span></div><div id="lines">${lineHTML(line,1)}</div></section><section class="panel internal"><h2>金料与库存确认</h2><p class="small muted">请选择本次交付所用的实际黄金货盘。已经记过入库的金料只出库,不会重复增加库存。</p><div class="grid two">${choice('原锁金料是否已记入这个货盘','original_stock',[['','请选择'],['receive','尚未记入,交付时先入库'],['stocked','此前已记入,只出库']],draft.inventory?.original||'')}<div id="lock-material-breakdown" class="lock-material-breakdown" aria-live="polite"></div></div><div id="lock-extra-material" hidden><h3>超出原锁克重的补重金料</h3><div class="grid three">${moneyField('补重进货料价(元/克)','extra_rate',draft.extraMaterial?.rate??'')}${choice('补重料费付款人','extra_payer',[['','请选择'],['owner','麦麦'],['assistant','助理']],draft.extraMaterial?.payer||'')}${choice('补重金料是否已记入所选货盘','extra_stock',[['','请选择'],['receive','尚未记入,交付时先入库'],['stocked','此前已记入,只出库']],draft.inventory?.extra||'')}</div><label class="check"><input type="checkbox" name="extra_verified" ${draft.extraMaterial?.verified?'checked':''}>已核实补重料费实际付款。</label></div><p id="lock-stock-note" class="note" aria-live="polite"></p></section>${feeHTML({...draft,date,fees_date:date},{cardPreview:false})}<section class="panel"><div class="grid two">${moneyField('整单优惠(元)','discount',draft.discount??(lock.discount/100).toFixed(2))}<div><span class="small muted">最终成交额 · 四舍五入到元</span><div id="lock-final-total" class="summary-amount">待填写</div><p id="lock-rounding-note" class="small muted"></p></div></div><div class="lock-settlement"><h2 id="lock-settlement-title">客户补款/退款</h2><p id="lock-settlement-hint" class="small muted" aria-live="polite"></p><div id="lock-settlement-fields"><div class="grid three">${field('本次实际补退款(元)','settlement_amount','','number','readonly')}${accountFields(draft.settlement?.account||lock.cash_events.find(event=>event.kind==='receipt')?.account)}</div><label class="check"><input type="checkbox" name="settlement_verified" ${draft.settlement?.verified?'checked':''}>已核实本次补款到账/退款已实际完成。</label></div></div>${creditCardPreviewHTML('lock-delivery-card-fee',draft.settlement?.credit_card_fee_payer)}<label class="check"><input type="checkbox" name="delivery_verified" required>已核对实物、实际成本、出入库来源与客户收付款,确认交付。</label><div class="form-actions"><span class="small muted">保存后才记销售、完整成本和利润,可打印正式客户单据。</span><button type="submit" class="primary">确认交付并生成销售单</button></div><div id="price-lock-error" aria-live="polite"></div></section></form>`;
|
||||
syncPriceLockForm();
|
||||
}catch(err){if(request===priceLockRequest&&tab==='price-locks'&&$('#price-lock-delivery-loading'))$('#price-lock-delivery-loading').innerHTML=`<div class="error">${e(err.message)}</div>${button('重新读取','deliver-price-lock','',`data-id="${e(id)}"`)}`;}
|
||||
}
|
||||
function collectPriceLockDelivery(){
|
||||
const form=$('#price-lock-delivery-form'),get=name=>lockFormValue(form,name),row=form.querySelector('#lines .line-item');
|
||||
return {revision:Number(form.dataset.revision),date:get('date'),note:get('delivery_note'),line:collectLine(row),discount:get('discount'),extraMaterial:{rate:get('extra_rate'),payer:get('extra_payer'),verified:form.querySelector('[name="extra_verified"]').checked},inventory:{pocket:row.querySelector('[name="pocket"]').value,original:get('original_stock'),extra:get('extra_stock')},settlement:{amount:get('settlement_amount'),account:get('payment_recipient')+get('payment_method'),verified:form.querySelector('[name="settlement_verified"]').checked},fee_items:readFeeRows(),fee_auto_initialized:true,verified:form.querySelector('[name="delivery_verified"]').checked};
|
||||
return {revision:Number(form.dataset.revision),date:get('date'),note:get('delivery_note'),line:collectLine(row),discount:get('discount'),extraMaterial:{rate:get('extra_rate'),payer:get('extra_payer'),verified:form.querySelector('[name="extra_verified"]').checked},inventory:{pocket:row.querySelector('[name="pocket"]').value,original:get('original_stock'),extra:get('extra_stock')},settlement:{amount:get('settlement_amount'),account:get('payment_recipient')+get('payment_method'),credit_card_fee_payer:readCreditCardPayer(form),verified:form.querySelector('[name="settlement_verified"]').checked},fee_items:readFeeRows(),fee_auto_initialized:true,verified:form.querySelector('[name="delivery_verified"]').checked};
|
||||
}
|
||||
function syncPriceLockDelivery(){
|
||||
const form=$('#price-lock-delivery-form'),lock=currentPriceLock;if(!form||!lock||form.dataset.id!==lock.id)return;
|
||||
@@ -89,8 +96,9 @@ function syncPriceLockDelivery(){
|
||||
$('#lock-material-breakdown').textContent=costs?`原锁料费已付 ¥${yuan(lock.material_amount)};本单耗用料费 ¥${yuan(costs.materialCost)}${costs.leftoverMg?';余料 '+grams(costs.leftoverMg)+'g,成本 ¥'+yuan(costs.leftoverCost):''}`:extra?'请填写补重料价,计算本次实际耗用成本。':'填写最终交付克重,自动计算实际耗料。';
|
||||
const original=d.inventory.original,pocket=d.inventory.pocket;
|
||||
$('#lock-stock-note').textContent=costs&&original&&pocket?`${original==='receive'?'原锁 '+grams(lock.locked_mg)+'g 先入库;':'原锁金料此前已入库;'}${costs.extraMg?(d.inventory.extra==='receive'?'补重 '+grams(costs.extraMg)+'g 先入库;':d.inventory.extra==='stocked'?'补重金料此前已入库;':'请选择补重金料是否已入库;'):''}从「${pocket}」出库 ${grams(costs.finalMg)}g。${costs.leftoverMg?'余料 '+grams(costs.leftoverMg)+'g 留在该货盘,按原进货价计成本,不重复入库。':''}`:'选择实际货盘和金料入库情况后,显示本次库存动作。';
|
||||
let difference=null;
|
||||
try{
|
||||
const total=LedgerCalc.orderTotal([LedgerCalc.sale(d.line).sale],LedgerCalc.cents(d.discount),'yuan'),difference=total.total-lock.netReceived;
|
||||
const total=LedgerCalc.orderTotal([LedgerCalc.sale(d.line).sale],LedgerCalc.cents(d.discount),'yuan');difference=total.total-lock.netReceived;
|
||||
$('#lock-final-total').textContent=orderAmount(total.total,'yuan');$('#lock-rounding-note').textContent=orderRoundingHint(total);
|
||||
$('#lock-settlement-title').textContent=difference>0?'客户需补款':difference<0?'应退还客户':'无需补款或退款';
|
||||
$('#lock-settlement-hint').textContent=`已收净额 ¥${yuan(lock.netReceived)};最终成交 ¥${yuan(total.total)}${difference?';本次'+(difference>0?'补收':'退款')+' ¥'+yuan(Math.abs(difference)):',金额已结清'}。`;
|
||||
@@ -98,7 +106,8 @@ function syncPriceLockDelivery(){
|
||||
form.querySelector('[name="settlement_amount"]').value=(Math.abs(difference)/100).toFixed(2);$('#lock-settlement-fields').hidden=!difference;
|
||||
for(const input of $('#lock-settlement-fields').querySelectorAll('input,select')){input.disabled=!difference;input.required=!!difference;}
|
||||
}catch(err){$('#lock-final-total').textContent='待填写';$('#lock-rounding-note').textContent=err.message;$('#lock-settlement-hint').textContent='先填写最终克重、销售工费及优惠,再核对客户补退款。';form.querySelector('[name="settlement_amount"]').value='';}
|
||||
try{const fees=readFeeRows(),missing=fees.filter(f=>f.amount==='').length;$('#fees-total').textContent='实际费用合计:¥'+yuan(fees.reduce((sum,f)=>sum+(f.amount===''?0:LedgerCalc.cents(f.amount)),0))+(missing?' · 还有 '+missing+' 项待补齐':'');}catch{$('#fees-total').textContent='请检查实际费用金额。';}
|
||||
const cardFee=syncCreditCardPreview($('#lock-delivery-card-fee'),d.settlement.account,difference,{enabled:difference===null||difference>0});
|
||||
updateFeeTotal(readFeeRows(),cardFee===null?null:priceLockCardFeeTotal(lock)+cardFee,{knownCardCost:priceLockCardFeeTotal(lock)});
|
||||
localStorage.setItem(priceLockDeliveryKey(lock.id),JSON.stringify(collectPriceLockDelivery()));
|
||||
}
|
||||
function syncPriceLockForm(){if($('#price-lock-create-form'))syncPriceLockCreate();else if($('#price-lock-delivery-form'))syncPriceLockDelivery();}
|
||||
@@ -123,19 +132,21 @@ async function finishPriceLockSave(url,data,result){
|
||||
async function submitPriceLockForm(form){
|
||||
syncPriceLockForm();$('#price-lock-error').innerHTML='';let url,data;
|
||||
if(form.id==='price-lock-create-form'){
|
||||
data=collectPriceLockCreate();url='/api/price-locks';
|
||||
data=validateOrderIdentity(collectPriceLockCreate());url='/api/price-locks';
|
||||
if(!data.customer||!data.line.name)throw new Error('请填写客户与黄金商品名称。');
|
||||
if(LedgerCalc.isSilver(data.line.name))throw new Error('锁价仅支持按克黄金,银饰请直接开单。');
|
||||
lockQuantityMg(data.line.quantity);if(LedgerCalc.cents(data.line.goldPrice)<=0||LedgerCalc.cents(data.material.rate)<=0)throw new Error('销售金价与原进货料价须大于0。');
|
||||
LedgerCalc.cents(data.payment.amount,'客户实际付款');LedgerCalc.orderTotal([LedgerCalc.sale(data.line).sale],LedgerCalc.cents(data.discount),'yuan');
|
||||
if(isCreditCardAccount(data.payment.account)&&!creditCardAvailable())throw new Error('信用卡收款暂未准备好,请刷新后重新核对。');
|
||||
if(!data.payment.verified||!data.material.verified)throw new Error('请核实客户实际付款与原锁料费实际付款。');
|
||||
}else{
|
||||
const lock=currentPriceLock;if(!lock||form.dataset.id!==lock.id)throw new Error('请重新读取锁价单后办理交付。');data=collectPriceLockDelivery();url='/api/price-locks/'+encodeURIComponent(lock.id)+'/deliver';
|
||||
const costs=LedgerCalc.priceLockCost({lockedQuantity:grams(lock.locked_mg),quantity:data.line.quantity,buyRate:(lock.buy_rate/100).toFixed(2),extraBuyRate:data.extraMaterial.rate});
|
||||
validateIssueDraft({lines:[data.line],fee_items:data.fee_items,discount:data.discount,rounding_mode:'yuan'});
|
||||
validateIssueDraft({lines:[data.line],fee_items:data.fee_items,discount:data.discount,rounding_mode:'yuan'},{requireIdentity:false});
|
||||
if(!state.pockets.includes(data.inventory.pocket)||!['receive','stocked'].includes(data.inventory.original))throw new Error('请选择实际出库货盘,并确认原锁金料是否已入库。');
|
||||
if(costs.extraMg&&(!['receive','stocked'].includes(data.inventory.extra)||!['owner','assistant'].includes(data.extraMaterial.payer)||!data.extraMaterial.verified))throw new Error('请填写补重料价、付款人、是否已入库,并确认实际付款。');
|
||||
const total=LedgerCalc.orderTotal([LedgerCalc.sale(data.line).sale],LedgerCalc.cents(data.discount),'yuan'),difference=total.total-lock.netReceived;
|
||||
if(difference>0&&isCreditCardAccount(data.settlement.account)&&!creditCardAvailable())throw new Error('信用卡收款暂未准备好,请刷新后重新核对。');
|
||||
if(difference&&!data.settlement.verified)throw new Error('请先核实客户补款或退款已实际完成。');
|
||||
if(!data.verified)throw new Error('请核对实物、实际成本、库存来源与客户收付款后确认交付。');
|
||||
const line=data.line;data.line={quantity:line.quantity,laborRate:line.laborRate,laborMode:line.laborMode,pieces:line.pieces,charges:line.charges,payer:line.payer,costParts:{labor:line.costParts.labor,accessories:line.costParts.accessories,other:line.costParts.other},costLabor:line.costLabor,costPayers:line.costPayers};
|
||||
|
||||
Reference in new issue
Block a user