新增老板专属私域运营概况与订单新老客户统计

This commit is contained in:
summer committed 2026-12-04 02:03:31 +08:00
1 parent 000a80af3c
commit d18089aaf6
21 files changed
+248 -79

No files matched your search

+7 -7
View File
@@ -23,7 +23,7 @@ function collectMultiPriceLockOrderEdit(form,entry){
const single={...entry,inputs:{...original,lines:[line],price_lock_material:priceLockOrderEditMaterial(original,index),price_lock_extra_material:priceLockOrderEditExtra(original,index)}};
const value=collectPriceLockOrderEdit(root,single);return {...value.lines[0],lineId:line.lineId,price_lock_material:value.price_lock_material,...(value.price_lock_extra_material?{price_lock_extra_material:value.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),fee_cost_mode:$('#fee-rows')?.dataset?.feeCostMode||original.fee_cost_mode,lines,fee_items:$('#fee-rows')?readFeeRows():original.fee_items};
return {...original,date:get('date',original.date),customer:get('customer',original.customer),customer_type:get('customer_type',original.customer_type||'unknown'),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),fee_cost_mode:$('#fee-rows')?.dataset?.feeCostMode||original.fee_cost_mode,lines,fee_items:$('#fee-rows')?readFeeRows():original.fee_items};
}
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};
@@ -39,7 +39,7 @@ function collectPriceLockOrderEdit(form,entry=orderEditEntry){
let labor=get('lock_cost_labor_total',line.costParts?.labor??'');
if(laborMode==='gram'){try{const cost=LedgerCalc.purchaseCosts({unit:line.unit,quantity:line.quantity,costParts:{material:'0',labor:'0',accessories:'0',other:'0'},costMaterial:{mode:'total'},costLabor:{mode:'gram',rate:get('lock_cost_labor_rate',line.costLabor?.rate??'')}});labor=cost.parts.labor===null?'':(cost.parts.labor/100).toFixed(2);}catch{labor='';}}
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),
return {...original,date:get('date',original.date),customer:get('customer',original.customer),customer_type:get('customer_type',original.customer_type||'unknown'),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,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)}}],
@@ -140,12 +140,12 @@ function multiPriceLockOrderEditHTML(entry){
const fields=html.slice(start,end).replace(/id="lock-edit-manual-material"/g,'data-lock-edit-part="manual-material"').replace(/id="lock-edit-material-note"/g,'data-lock-edit-part="material-note"');
return `<div class="lock-edit-product" data-lock-edit-line data-line-id="${e(line.lineId)}"><div class="panel lock-edit-product-heading"><h2>商品 ${index+1} · ${e(line.name)}</h2><p class="small muted">${grams(entry.order.lines[index].quantity)}g · 原锁销售金价 ¥${yuan(entry.order.lines[index].goldPrice??0)}/克 · 货盘 ${e(pocketLabel(entry.order.lines[index].pocket)||'未提供')}</p></div>${fields}</div>`;
}).join('');
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)} · 共 ${draft.lines.length}件 · 成交 ${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>${cards}${feeHTML(draft,{cardPreview:false})}<section class="panel"><h2>整单更正后成本预览</h2><div id="lock-edit-cost-preview" class="lock-edit-cost-preview" aria-live="polite"></div></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"')}${typeof customerTypeField==='function'?customerTypeField(draft.customer_type||'unknown',false):''}${field('开单人(必填)','salesperson',draft.salesperson||'','text','required maxlength="30"')}</div><p class="small muted">原锁日期 ${e(lock.date)} · 共 ${draft.lines.length}件 · 成交 ${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>${cards}${feeHTML(draft,{cardPreview:false})}<section class="panel"><h2>整单更正后成本预览</h2><div id="lock-edit-cost-preview" class="lock-edit-cost-preview" aria-live="polite"></div></section>${orderEditReviewHTML(entry)}</form>`;
}
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>${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>`;
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"')}${typeof customerTypeField==='function'?customerTypeField(draft.customer_type||'unknown',false):''}${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){
@@ -217,9 +217,9 @@ function renderOrderEditForm(){
if(priceLockOrderEditable(entry)){
$('#main').innerHTML=headingHTML+priceLockOrderEditHTML(entry);syncPriceLockOrderEdit();
}else if(!entry.financialEditable){
$('#main').innerHTML=headingHTML+`<div class="note">${e(entry.message||intro)}</div>`+orderEditConflictHTML(entry)+`<form id="order-edit-meta-form"><section class="panel"><div class="grid two">${field('客户称呼/代号(必填)','customer',draft.customer||'','text','required maxlength="60"')}${field('开单人(必填)','salesperson',draft.salesperson||'','text','required maxlength="30"')}<label>客户单备注<textarea name="note" maxlength="240" rows="3">${e(draft.note||'')}</textarea></label></div>${orderInternalNoteField(draft.internal_note||'')}<p class="small muted">原单号 ${e(order.paper_number||order.number)} · 业务日期 ${e(order.date)} · 成交 ${orderAmount(order.total,order.rounding_mode)}</p></section>${orderEditReviewHTML(entry)}</form>`;
$('#main').innerHTML=headingHTML+`<div class="note">${e(entry.message||intro)}</div>`+orderEditConflictHTML(entry)+`<form id="order-edit-meta-form"><section class="panel"><div class="grid two">${field('客户称呼/代号(必填)','customer',draft.customer||'','text','required maxlength="60"')}${typeof customerTypeField==='function'?customerTypeField(draft.customer_type||'unknown',false):''}${field('开单人(必填)','salesperson',draft.salesperson||'','text','required maxlength="30"')}<label>客户单备注<textarea name="note" maxlength="240" rows="3">${e(draft.note||'')}</textarea></label></div>${orderInternalNoteField(draft.internal_note||'')}<p class="small muted">原单号 ${e(order.paper_number||order.number)} · 业务日期 ${e(order.date)} · 成交 ${orderAmount(order.total,order.rounding_mode)}</p></section>${orderEditReviewHTML(entry)}</form>`;
}else{
$('#main').innerHTML=headingHTML+`<div class="note" role="status" id="order-edit-save-intro">${e(intro)}本次沿用原单号 ${e(order.paper_number||order.number)}。</div>`+orderEditConflictHTML(entry)+`<form id="order-form" data-order-edit="true"><input type="hidden" name="rounding_mode" value="${e(draft.rounding_mode||'cent')}"><input type="hidden" name="orderId" value="${e(entry.id)}"><input type="hidden" name="revision" value="${e(entry.revision)}"><section class="panel"><div class="panel-title"><h2>客户与单据</h2><span class="small muted">修改内容单独暂存,可刷新后继续</span></div><div class="grid four">${dateField('date',draft.date)}${field('原纸单编号','paper_number',order.paper_number||order.number,'text','readonly')}${field('客户称呼/代号(必填)','customer',draft.customer||'','text','required maxlength="60"')}${field('开单人(必填)','salesperson',draft.salesperson||'','text','required maxlength="30"')}${accountFields(draft.payment_account)}</div><p class="small muted">选择客户实际付款的方式与收款人。修改业务日期会重新核算对应日期的订单与库存,原单号保留。</p></section><section class="panel"><div class="panel-title"><h2>商品明细</h2><span class="small muted">金价与工费分开填写</span></div><div id="lines">${draft.lines.map((line,index)=>lineHTML(line,index+1,{materialPool:true,historicalPocket:!!order.lines[index]&&line.pocket===order.lines[index].pocket})).join('')}</div><div class="form-actions">${button('+ 添加商品','add-line')}<span class="small muted">填写本单最终实际交付的商品、克重与金额。</span></div></section>${feeHTML(draft)}<section class="panel"><div class="grid two">${moneyField('整单优惠/抹零(元)','discount',draft.discount??'0')}<label>客户单备注<textarea name="note" maxlength="240" rows="2">${e(draft.note||'')}</textarea></label></div>${orderInternalNoteField(draft.internal_note||'')}<div class="form-actions"><div><span class="small muted">更正后成交合计/客户实收</span><div id="create-total" class="summary-amount">待填写</div><div id="create-rounding-note" class="small muted order-rounding-note" aria-live="polite"></div></div></div></section>${orderEditReviewHTML(entry)}</form>`;
$('#main').innerHTML=headingHTML+`<div class="note" role="status" id="order-edit-save-intro">${e(intro)}本次沿用原单号 ${e(order.paper_number||order.number)}。</div>`+orderEditConflictHTML(entry)+`<form id="order-form" data-order-edit="true"><input type="hidden" name="rounding_mode" value="${e(draft.rounding_mode||'cent')}"><input type="hidden" name="orderId" value="${e(entry.id)}"><input type="hidden" name="revision" value="${e(entry.revision)}"><section class="panel"><div class="panel-title"><h2>客户与单据</h2><span class="small muted">修改内容单独暂存,可刷新后继续</span></div><div class="grid four">${dateField('date',draft.date)}${field('原纸单编号','paper_number',order.paper_number||order.number,'text','readonly')}${field('客户称呼/代号(必填)','customer',draft.customer||'','text','required maxlength="60"')}${typeof customerTypeField==='function'?customerTypeField(draft.customer_type||'unknown',false):''}${field('开单人(必填)','salesperson',draft.salesperson||'','text','required maxlength="30"')}${accountFields(draft.payment_account)}</div><p class="small muted">选择客户实际付款的方式与收款人。修改业务日期会重新核算对应日期的订单与库存,原单号保留。</p></section><section class="panel"><div class="panel-title"><h2>商品明细</h2><span class="small muted">金价与工费分开填写</span></div><div id="lines">${draft.lines.map((line,index)=>lineHTML(line,index+1,{materialPool:true,historicalPocket:!!order.lines[index]&&line.pocket===order.lines[index].pocket})).join('')}</div><div class="form-actions">${button('+ 添加商品','add-line')}<span class="small muted">填写本单最终实际交付的商品、克重与金额。</span></div></section>${feeHTML(draft)}<section class="panel"><div class="grid two">${moneyField('整单优惠/抹零(元)','discount',draft.discount??'0')}<label>客户单备注<textarea name="note" maxlength="240" rows="2">${e(draft.note||'')}</textarea></label></div>${orderInternalNoteField(draft.internal_note||'')}<div class="form-actions"><div><span class="small muted">更正后成交合计/客户实收</span><div id="create-total" class="summary-amount">待填写</div><div id="create-rounding-note" class="small muted order-rounding-note" aria-live="polite"></div></div></div></section>${orderEditReviewHTML(entry)}</form>`;
const paymentNote=orderEditPaymentNote(order);if(paymentNote)$('#order-form [name="payment_recipient"]').closest('.grid').insertAdjacentHTML('afterend',paymentNote);
updateTotal();loadMaterialPoolChoices(true);if(typeof loadReimbursementFundingOptions==='function')loadReimbursementFundingOptions(true);
}
@@ -276,7 +276,7 @@ async function submitOrderEdit(form){
let input;
if(priceLockOrderEditable(entry))input=validatePriceLockOrderEdit(collectPriceLockOrderEdit(form),entry);
else if(entry.financialEditable){updateTotal();try{input=validateIssueDraft(collectDraft());}catch(err){err.message=err.message.replace('开单前','保存修改前');throw err;}}
else{const get=name=>form.querySelector(`[name="${name}"]`).value;input=validateOrderIdentity({customer:get('customer'),salesperson:get('salesperson'),note:get('note'),...(form.querySelector('[name="internal_note"]')?{internal_note:get('internal_note')}:{})});}
else{const get=name=>form.querySelector(`[name="${name}"]`).value;input={...(form.querySelector('[name="customer_type"]')?{customer_type:form.querySelector('[name="customer_type"]').value}:{}),...validateOrderIdentity({customer:get('customer'),salesperson:get('salesperson'),note:get('note'),...(form.querySelector('[name="internal_note"]')?{internal_note:get('internal_note')}:{})})};}
input={...input,revision:entry.revision,reason,verified:true};$('#order-error').innerHTML='';
const requiresApproval=orderEditNeedsApproval(entry,input.date??entry.order.date,input);entry.requiresApproval=requiresApproval;
try{