锁价交付补重支持当日料池,内部备注移至客户名旁
This commit is contained in:
1 parent
ac9073471d
commit
c5883351c1
20 files changed
+196
-66
No files matched your search
@@ -28,7 +28,7 @@ function collectMultiPriceLockOrderEdit(form,entry){
|
||||
function priceLockEditFinancialValue(input){
|
||||
if(input?.lines?.length>1)return {date:input.date,fees_date:input.fees_date,fee_cost_mode:input.fee_cost_mode||'legacy',lines:input.lines.map((line,index)=>({lineId:line.lineId,...priceLockEditFinancialValue({lines:[line],price_lock_material:priceLockOrderEditMaterial(input,index),price_lock_extra_material:priceLockOrderEditExtra(input,index),fee_items:[]})})),fees:priceLockEditFinancialValue({...input,lines:[]}).fees};
|
||||
const line=input?.lines?.[0]||{},material=input?.price_lock_material||{},extra=input?.price_lock_extra_material;
|
||||
return {date:input?.date,fees_date:input?.fees_date,fee_cost_mode:input?.fee_cost_mode||'legacy',material:material.source==='pool'?{source:'pool'}:{source:material.source,rate:priceLockEditAmount(material.rate),payer:material.payer},extra:extra?{rate:priceLockEditAmount(extra.rate),payer:extra.payer}:null,
|
||||
return {date:input?.date,fees_date:input?.fees_date,fee_cost_mode:input?.fee_cost_mode||'legacy',material:material.source==='pool'?{source:'pool'}:{source:material.source,rate:priceLockEditAmount(material.rate),payer:material.payer},extra:extra?{...(extra.source==='pool'?{source:'pool'}:{}),rate:priceLockEditAmount(extra.rate),payer:extra.payer}:null,
|
||||
costs:{labor:priceLockEditAmount(line.costParts?.labor),accessories:priceLockEditAmount(line.costParts?.accessories),other:priceLockEditAmount(line.costParts?.other),payer:line.payer,laborPayer:line.costPayers?.labor,laborMode:line.costLabor?.mode||'total',...(line.costLabor?.mode==='gram'?{laborRate:priceLockEditAmount(line.costLabor.rate)}:{})},
|
||||
fees:(input?.fee_items||[]).map(fee=>({key:fee.key,expense_id:fee.expense_id||'',date:fee.date||input.fees_date,note:fee.note,payer:fee.payer,amount:priceLockEditAmount(fee.amount),funding:fee.funding??null})).sort((a,b)=>String(a.key).localeCompare(String(b.key)))};
|
||||
}
|
||||
@@ -41,7 +41,7 @@ function collectPriceLockOrderEdit(form,entry=orderEditEntry){
|
||||
const material=original.price_lock_material||{},extra=original.price_lock_extra_material;
|
||||
return {...original,date:get('date',original.date),customer:get('customer',original.customer),salesperson:get('salesperson',original.salesperson),note:get('note',original.note),internal_note:get('internal_note',original.internal_note||''),fees_date:get('fees_date',original.fees_date),
|
||||
price_lock_material:{...material,source:get('lock_material_source',material.source),rate:get('lock_material_rate',material.rate),payer:get('lock_material_payer',material.payer),verified:form.querySelector('[name="lock_material_verified"]')?.checked??(material.verified===true)},
|
||||
...(extra?{price_lock_extra_material:{...extra,rate:get('lock_extra_rate',extra.rate),payer:get('lock_extra_payer',extra.payer),verified:form.querySelector('[name="lock_extra_verified"]')?.checked??(extra.verified===true)}}:{}),
|
||||
...(extra?{price_lock_extra_material:{...extra,source:get('lock_extra_source',extra.source||'manual'),rate:get('lock_extra_rate',extra.rate),payer:get('lock_extra_payer',extra.payer),verified:form.querySelector('[name="lock_extra_verified"]')?.checked??(extra.verified===true)}}:{}),
|
||||
lines:[{...line,payer:get('lock_cost_payer',line.payer),costLabor:{mode:laborMode,...(laborMode==='gram'?{rate:get('lock_cost_labor_rate',line.costLabor?.rate??'')}:{})},costParts:{...line.costParts,labor,accessories:get('lock_cost_accessories',line.costParts?.accessories??'0'),other:get('lock_cost_other',line.costParts?.other??'0')},costPayers:{...line.costPayers,labor:get('lock_cost_labor_payer',line.costPayers?.labor)}}],
|
||||
fee_cost_mode:$('#fee-rows')?.dataset?.feeCostMode||original.fee_cost_mode,fee_items:$('#fee-rows')?readFeeRows():original.fee_items};
|
||||
}
|
||||
@@ -145,7 +145,7 @@ function multiPriceLockOrderEditHTML(entry){
|
||||
function priceLockOrderEditHTML(entry){
|
||||
if(entry.inputs.lines.length>1)return multiPriceLockOrderEditHTML(entry);
|
||||
const draft=entry.inputs,lock=entry.priceLock,line=draft.lines[0],material=draft.price_lock_material,extra=draft.price_lock_extra_material,raw=entry.order.lines[0],sourceOptions=lock.materialSource==='pool'?[['pool','保留原锁料池'],...(lock.canSwitchToManual?[['manual','改为手填原锁料价']]:[])]:[['manual','手填原锁料价']];
|
||||
return `<div class="note" id="order-edit-save-intro">更正交付日期与实际成本,原锁日期、销售金价、克重和收付款保留。</div>${orderEditConflictHTML(entry)}<form id="order-edit-meta-form" data-price-lock-edit="true"><section class="panel"><div class="panel-title"><h2>交付与客户资料</h2><span class="small muted">原单号 ${e(entry.order.paper_number||entry.order.number)}</span></div><div class="grid three">${field('交付日期','date',draft.date,'date',`required min="${e(lock.date)}" max="${e(state.today)}"`)}${field('客户称呼/代号(必填)','customer',draft.customer||'','text','required maxlength="60"')}${field('开单人(必填)','salesperson',draft.salesperson||'','text','required maxlength="30"')}</div><p class="small muted">原锁日期 ${e(lock.date)} · ${e(raw.name)} · ${grams(raw.quantity)}g · 原锁销售金价 ¥${yuan(raw.goldPrice??0)}/克 · 成交 ${orderAmount(entry.order.total,entry.order.rounding_mode)}</p><label>客户单备注<textarea name="note" maxlength="240" rows="2">${e(draft.note||'')}</textarea></label>${orderInternalNoteField(draft.internal_note||'')}</section><section class="panel internal price-lock-edit-costs"><h2>原锁金料与补重</h2>${choice('原锁料费来源','lock_material_source',sourceOptions,material.source)}<p id="lock-edit-material-note" class="note" aria-live="polite"></p><div id="lock-edit-manual-material"><div class="grid two">${moneyField('原锁进货料价(元/克)','lock_material_rate',material.rate??'')}${choice('原锁料费实际付款人','lock_material_payer',[['','请选择'],...teamMemberOptions()],material.payer||'')}</div><label class="check"><input type="checkbox" name="lock_material_verified" ${material.verified?'checked':''}>已核实手填原锁料费和实际付款人。</label></div>${extra?`<div class="lock-edit-extra"><h3>补重金料 ${grams(lock.extraMg)}g</h3><div class="grid two">${moneyField('补重进货料价(元/克)','lock_extra_rate',extra.rate??'')}${choice('补重料费实际付款人','lock_extra_payer',[['','请选择'],...teamMemberOptions()],extra.payer||'')}</div><label class="check"><input type="checkbox" name="lock_extra_verified" ${extra.verified?'checked':''}>已核实补重料费和实际付款人。</label></div>`:''}</section><section class="panel internal price-lock-edit-costs"><h2>交付进货成本</h2><div class="grid three">${choice('进货工费方式','lock_cost_labor_mode',[['total','总工费'],['gram','克工费']],line.costLabor?.mode||'total')}${moneyField('进货克工费(元/克)','lock_cost_labor_rate',line.costLabor?.rate??'')}${moneyField('进货总工费(元)','lock_cost_labor_total',line.costParts?.labor??'')}${choice('进货工费付款人','lock_cost_labor_payer',[['','请选择'],...teamMemberOptions()],line.costPayers?.labor||'')}${moneyField('配件成本(元)','lock_cost_accessories',line.costParts?.accessories??'0')}${moneyField('其他货品成本(元)','lock_cost_other',line.costParts?.other??'0')}${choice('配件及其他成本付款人','lock_cost_payer',[['','请选择'],...teamMemberOptions()],line.payer||'')}</div></section>${feeHTML(draft,{cardPreview:false})}<section class="panel"><h2>更正后成本预览</h2><div id="lock-edit-cost-preview" class="lock-edit-cost-preview" aria-live="polite"></div><p class="small muted">按本页成本预估,保存或复核同意后按原账更新利润。</p></section>${orderEditReviewHTML(entry)}</form>`;
|
||||
return `<div class="note" id="order-edit-save-intro">更正交付日期与实际成本,原锁日期、销售金价、克重和收付款保留。</div>${orderEditConflictHTML(entry)}<form id="order-edit-meta-form" data-price-lock-edit="true"><section class="panel"><div class="panel-title"><h2>交付与客户资料</h2><span class="small muted">原单号 ${e(entry.order.paper_number||entry.order.number)}</span></div><div class="grid three">${field('交付日期','date',draft.date,'date',`required min="${e(lock.date)}" max="${e(state.today)}"`)}${field('客户称呼/代号(必填)','customer',draft.customer||'','text','required maxlength="60"')}${field('开单人(必填)','salesperson',draft.salesperson||'','text','required maxlength="30"')}</div><p class="small muted">原锁日期 ${e(lock.date)} · ${e(raw.name)} · ${grams(raw.quantity)}g · 原锁销售金价 ¥${yuan(raw.goldPrice??0)}/克 · 成交 ${orderAmount(entry.order.total,entry.order.rounding_mode)}</p><label>客户单备注<textarea name="note" maxlength="240" rows="2">${e(draft.note||'')}</textarea></label>${orderInternalNoteField(draft.internal_note||'')}</section><section class="panel internal price-lock-edit-costs"><h2>原锁金料与补重</h2>${choice('原锁料费来源','lock_material_source',sourceOptions,material.source)}<p id="lock-edit-material-note" class="note" aria-live="polite"></p><div id="lock-edit-manual-material"><div class="grid two">${moneyField('原锁进货料价(元/克)','lock_material_rate',material.rate??'')}${choice('原锁料费实际付款人','lock_material_payer',[['','请选择'],...teamMemberOptions()],material.payer||'')}</div><label class="check"><input type="checkbox" name="lock_material_verified" ${material.verified?'checked':''}>已核实手填原锁料费和实际付款人。</label></div>${extra?`<div class="lock-edit-extra"><h3>补重金料 ${grams(lock.extraMg)}g</h3>${raw.priceLockExtraPool?choice('补重料费来源','lock_extra_source',[['pool','保留交付料池'],['manual','改为手填补重料价']],extra.source):''}<div class="grid two">${moneyField('补重进货料价(元/克)','lock_extra_rate',extra.rate??'')}${choice('补重料费实际付款人','lock_extra_payer',[['','请选择'],...teamMemberOptions()],extra.payer||'')}</div><label class="check"><input type="checkbox" name="lock_extra_verified" ${extra.verified?'checked':''}>已核实补重料费和实际付款人。</label></div>`:''}</section><section class="panel internal price-lock-edit-costs"><h2>交付进货成本</h2><div class="grid three">${choice('进货工费方式','lock_cost_labor_mode',[['total','总工费'],['gram','克工费']],line.costLabor?.mode||'total')}${moneyField('进货克工费(元/克)','lock_cost_labor_rate',line.costLabor?.rate??'')}${moneyField('进货总工费(元)','lock_cost_labor_total',line.costParts?.labor??'')}${choice('进货工费付款人','lock_cost_labor_payer',[['','请选择'],...teamMemberOptions()],line.costPayers?.labor||'')}${moneyField('配件成本(元)','lock_cost_accessories',line.costParts?.accessories??'0')}${moneyField('其他货品成本(元)','lock_cost_other',line.costParts?.other??'0')}${choice('配件及其他成本付款人','lock_cost_payer',[['','请选择'],...teamMemberOptions()],line.payer||'')}</div></section>${feeHTML(draft,{cardPreview:false})}<section class="panel"><h2>更正后成本预览</h2><div id="lock-edit-cost-preview" class="lock-edit-cost-preview" aria-live="polite"></div><p class="small muted">按本页成本预估,保存或复核同意后按原账更新利润。</p></section>${orderEditReviewHTML(entry)}</form>`;
|
||||
}
|
||||
function priceLockEditGramCost(mg,rate){return LedgerCalc.purchaseCosts({unit:'g',quantity:grams(mg),costParts:{material:'0',labor:'0',accessories:'0',other:'0'},costMaterial:{mode:'gram',rate},costLabor:{mode:'total'}}).parts.material;}
|
||||
function priceLockOrderEditPreview(input,entry=orderEditEntry){
|
||||
@@ -153,12 +153,13 @@ function priceLockOrderEditPreview(input,entry=orderEditEntry){
|
||||
const costs={material:0,labor:0,accessories:0,other:0,fees:input.fee_items.reduce((sum,fee)=>sum+LedgerCalc.cents(fee.amount,'实际费用'),0)};
|
||||
input.lines.forEach((line,index)=>{const old=entry.originalInputs,meta=priceLockOrderEditMeta(entry,index),singleInput={...input,lines:[line],price_lock_material:priceLockOrderEditMaterial(input,index),price_lock_extra_material:priceLockOrderEditExtra(input,index),fee_items:[]},singleEntry={...entry,originalInputs:{...old,lines:[old.lines[index]],price_lock_material:priceLockOrderEditMaterial(old,index),price_lock_extra_material:priceLockOrderEditExtra(old,index)},priceLock:{...entry.priceLock,...meta},order:{...entry.order,lines:[entry.order.lines[index]]}};const value=priceLockOrderEditPreview(singleInput,singleEntry);for(const key of ['material','labor','accessories','other'])costs[key]+=value[key];});costs.total=Object.values(costs).reduce((sum,value)=>sum+value,0);costs.profit=entry.order.total-costs.total;return costs;
|
||||
}
|
||||
const original=entry.originalInputs,line=input.lines[0],extraMg=entry.priceLock.extraMg,usedMg=entry.order.lines[0].quantity-extraMg,oldExtra=extraMg?priceLockEditGramCost(extraMg,original.price_lock_extra_material.rate):0;
|
||||
const originalMaterial=input.price_lock_material.source==='pool'?LedgerCalc.cents(original.lines[0].costParts.material,'原料费')-oldExtra:priceLockEditGramCost(usedMg,input.price_lock_material.rate),extra=extraMg?priceLockEditGramCost(extraMg,input.price_lock_extra_material.rate):0;
|
||||
const original=entry.originalInputs,line=input.lines[0],extraMg=entry.priceLock.extraMg,usedMg=entry.order.lines[0].quantity-extraMg,oldExtra=extraMg?(original.price_lock_extra_material.source==='pool'?original.price_lock_extra_material.amount:priceLockEditGramCost(extraMg,original.price_lock_extra_material.rate)):0;
|
||||
const originalMaterial=input.price_lock_material.source==='pool'?LedgerCalc.cents(original.lines[0].costParts.material,'原料费')-oldExtra:priceLockEditGramCost(usedMg,input.price_lock_material.rate),extra=extraMg?(input.price_lock_extra_material.source==='pool'?original.price_lock_extra_material.amount:priceLockEditGramCost(extraMg,input.price_lock_extra_material.rate)):0;
|
||||
if(!Number.isSafeInteger(originalMaterial)||originalMaterial<0||!Number.isSafeInteger(extra))throw new Error('原锁料费尚未完整,请核对原料价与补重料价。');
|
||||
const costs={material:originalMaterial+extra,labor:LedgerCalc.cents(line.costParts.labor,'进货工费'),accessories:LedgerCalc.cents(line.costParts.accessories,'配件成本'),other:LedgerCalc.cents(line.costParts.other,'其他货品成本'),fees:input.fee_items.reduce((total,fee)=>total+LedgerCalc.cents(fee.amount,'实际费用'),0)};costs.total=Object.values(costs).reduce((total,amount)=>total+amount,0);costs.profit=entry.order.total-costs.total;return costs;
|
||||
}
|
||||
function syncMultiPriceLockOrderEdit(changed='',target=null){
|
||||
syncLockExtraEditControls(orderEditForm());
|
||||
const entry=orderEditEntry,form=orderEditForm(),roots=[...form.querySelectorAll('[data-lock-edit-line]')];
|
||||
roots.forEach((root,index)=>{
|
||||
const meta=priceLockOrderEditMeta(entry,index),get=name=>root.querySelector('[name="'+name+'"]'),manual=get('lock_material_source').value==='manual',affected=!target||target.closest('[data-lock-edit-line]')===root;
|
||||
@@ -175,6 +176,7 @@ function syncMultiPriceLockOrderEdit(changed='',target=null){
|
||||
updateOrderEditApprovalMode();
|
||||
}
|
||||
function syncPriceLockOrderEdit(changed='',target=null){
|
||||
syncLockExtraEditControls(orderEditForm());
|
||||
if(priceLockOrderEditable()&&orderEditEntry.inputs.lines.length>1)return syncMultiPriceLockOrderEdit(changed,target);
|
||||
if(!priceLockOrderEditable())return;const form=orderEditForm();if(!form||form.dataset.priceLockEdit!=='true')return;
|
||||
const get=name=>form.querySelector('[name="'+name+'"]'),source=get('lock_material_source')?.value||orderEditEntry.inputs.price_lock_material.source,manual=source==='manual';
|
||||
@@ -322,3 +324,7 @@ function rememberOrderEditChange(event){
|
||||
}
|
||||
document.addEventListener('input',rememberOrderEditChange);
|
||||
document.addEventListener('change',rememberOrderEditChange);
|
||||
|
||||
function syncLockExtraEditControls(form){
|
||||
for(const select of form?.querySelectorAll('[name="lock_extra_source"]')||[]){const area=select.closest('.lock-edit-extra'),pooled=select.value==='pool';for(const name of ['lock_extra_rate','lock_extra_payer','lock_extra_verified']){const control=area.querySelector('[name="'+name+'"]');if(control){control.disabled=pooled;control.closest('label').hidden=pooled;}}let note=area.querySelector('[data-extra-pool-note]');if(!note){note=document.createElement('p');note.dataset.extraPoolNote='true';note.className='note';area.append(note);}note.hidden=!pooled;note.textContent='沿用交付料池的成本和付款来源,不重复登记付款;更改交付日期时按对应日期料池重新核算。';}
|
||||
}
|
||||
Reference in new issue
Block a user