汇总每日料池用量并精简老板专属月度利润分成表
This commit is contained in:
1 parent
dec01a3dca
commit
39f80fbab7
16 files changed
+276
-32
No files matched your search
+20
-5
@@ -125,7 +125,8 @@ async function refresh(renderPage=true,stillCurrent){const latest=await api('/ap
|
||||
function heading(kicker,title,desc,actions=''){return `<div class="page-heading"><div><div class="eyebrow">${kicker}</div><h1>${title}</h1><p class="muted">${desc}</p></div><div class="actions">${actions}</div></div>`;}
|
||||
async function render(){
|
||||
window.scrollTo(0,0);
|
||||
document.querySelectorAll('nav button').forEach(b=>b.classList.toggle('active',b.dataset.tab===(tab==='order-edit'?'orders':tab)));
|
||||
if(tab==='team-funds'&&state.user.role!=='owner')tab='report';
|
||||
document.querySelectorAll('nav button').forEach(b=>{if(b.dataset.tab==='team-funds')b.hidden=b.disabled=state.user.role!=='owner';b.classList.toggle('active',b.dataset.tab===(tab==='order-edit'?'orders':tab));});
|
||||
if(tab==='order-edit')return await renderOrderEdit();
|
||||
if(tab==='create')renderCreate();if(tab==='price-locks')await renderPriceLocks();if(tab==='material-pools')await renderMaterialPools();if(tab==='recoveries'&&typeof renderRecoveries==='function')await renderRecoveries();if(tab==='orders')await renderOrders();if(tab==='stock')await renderStock();if(tab==='report')await renderReport();if(tab==='settings')renderSettings();if(tab==='team-funds')await renderTeamFunds();
|
||||
}
|
||||
@@ -1162,7 +1163,7 @@ function showAction(action){
|
||||
if(action==='cost')html=`<div class="note">进货料价和克工费按该行克重自动计算;原单合计金额保留,改按克录入时需填写实际单价。没有的成本填0,完成销售记账后锁定。快递和附加费用可从“补记旧单费用”填写。</div>${o.lines.map((l,i)=>`<div class="internal cost-editor"><h3>${e(l.name)} · ${l.unit==='g'?grams(l.quantity)+'g':l.quantity+'件'}</h3><div class="cost-fallback-payer">${choice('配件及其他成本付款人','goodsPayer',teamMemberOptions(),l.payer||'owner')}</div>${!l.costParts&&l.cost!==null?`<p class="small">原记录未分项,总额 ¥${yuan(l.cost)};请按凭据拆分,不要把总额再填入每个项目。</p>`:''}<div class="cost-fields grid">${costFields(l.costParts?Object.fromEntries(Object.entries(l.costParts).map(([k,v])=>[k,v===null?'':(v/100).toFixed(2)])):{material:'',labor:'',accessories:'0',other:'0'},'cost-'+i+'-',true,{mode:l.costLabor?.mode||'total',rate:l.costLabor?.rate==null?'':(l.costLabor.rate/100).toFixed(2)},{...materialCostInput(l),...(l.costMaterial?.mode==='gram'?{rate:l.costMaterial.rate==null?'':(l.costMaterial.rate/100).toFixed(2)}:{})},{},l.unit,costPayerInput(l))}</div><div class="cost-summary small"></div></div>`).join('')}`;
|
||||
if(action==='complete')html=`${dt}<p>补齐这张旧单的销售记账:按填写金额记录实际费用、从原货盘扣减黄金并计入销售与利润。款项未收齐或成本金额有空白时,请先补齐。</p><label class="check"><input type="checkbox" name="verified" required>已核实全额收款、商品已交付,所填费用为实际已付金额,没有发生的已填0。</label>`;
|
||||
if(action==='return')html=`${dt}${field('退货原因','reason','','text','required maxlength="200"')}<div class="grid two">${o.lines.map((l,i)=>choice(l.name+' · 实物去向','return-'+i,l.unit==='g'?[...(l.pocket||l.costMaterial?.mode==='pool'?[]:[['','已退供应商,不留店内']]),...state.pockets]:[['','按件商品,不记黄金货盘']],l.pocket||(l.costMaterial?.mode==='pool'?state.pockets[0]:''))).join('')}</div><div class="note">本入口办理整单退货,原销售额与货品成本在退货日冲回。已花费的运费等仍保留。换货先退原单,再开新单;部分退货暂未开放。</div><label class="check"><input type="checkbox" name="verified" required>已核实本单全部商品退回,所选去向与实际一致。</label>`;
|
||||
if(action==='settlement'&&teamMode())throw new Error('三人经营款请在“团队账目”核对并登记实际转账。');
|
||||
if(action==='settlement'&&teamMode())throw new Error('三人成员往来请在每日对账核对。');
|
||||
if(action==='settlement'&&(o.materialCostPending||o.settlementDue==null))throw new Error('本批料费尚未补齐,补足采购后再核对实际交款。');
|
||||
if(action==='settlement')html=`<div class="grid three">${dt}${choice('转款方向','direction',[['toOwner','娜娜 → 麦麦'],['toAssistant','麦麦 → 娜娜']],o.settlementDue<0?'toAssistant':'toOwner')}${choice('本笔归属','bucket',[['cost','货款'],['profit','利润']],'cost')}</div><div class="grid two">${moneyField('实际转账金额','amount')}${field('转账凭据/说明','note','','text','required maxlength="150"')}</div><p class="small muted">${o.ownerCredit?'麦麦已直接收到部分客户款,先按实际情况核清归属。':`货款待结 ¥${yuan(o.costDue)};利润待结 ¥${yuan(o.profitDue)}(负数为麦麦需转回)。`}</p><label class="check"><input type="checkbox" name="verified" required>已核实各人实际转账,不是仅记录计划交款。</label>`;
|
||||
if(action==='correct'){
|
||||
@@ -1426,9 +1427,20 @@ function reportOwnershipAccountsHTML(person){
|
||||
return `<p class="report-ownership-equation"><span>本人收款净额 <b>¥${yuan(net(ownAccounts))}</b></span><span aria-hidden="true">+</span><span>${otherAccounts.length===1?e(accountDisplayName(otherAccounts[0].account))+'代收':'他人代收'}净额 <b>¥${yuan(net(otherAccounts))}</b></span><span aria-hidden="true">=</span><strong>¥${yuan(person.net)}</strong></p><div class="report-ownership-accounts">${group('本人收款',ownAccounts)}${group('他人代收',otherAccounts)}</div>`;
|
||||
}
|
||||
function reportBusinessAmount(value,known){return (value===null?'已知 ':'')+'¥'+yuan(value===null?known:value);}
|
||||
function reportPoolMaterialSourceLabel(source){
|
||||
return (source.kind==='personal_recovery'?teamMemberName(source.member)+'个人回收料':'公共料')+(source.priceLocked?'(含锁价原料)':'');
|
||||
}
|
||||
function reportPoolMaterialFormula(day){
|
||||
if(day.sources)return day.sources.map(source=>`${reportPoolMaterialSourceLabel(source)} ${grams(source.mg)}g × ${source.averageRate===null?'待补料价':'¥'+yuan(source.averageRate)+'/g'}`).join(' + ')+` = ${day.amount===null?'料费待补(已知 ¥'+yuan(day.knownAmount)+')':'¥'+yuan(day.amount)}`;
|
||||
return `${grams(day.mg)}g × ${day.averageRate===null?'待补料价':'¥'+yuan(day.averageRate)+'/g'} = ${day.amount===null?'料费待补(已知 ¥'+yuan(day.knownAmount)+')':'¥'+yuan(day.amount)}`;
|
||||
}
|
||||
function reportPoolMaterialDayHTML(day){
|
||||
if(!day.sources)return `<li><span>${e(day.date)} 料池</span><strong>${e(reportPoolMaterialFormula(day))}</strong></li>`;
|
||||
return `<li class="report-pool-material-day"><div class="report-pool-material-day-total"><span>${e(day.date)} 料池</span><b>已用 ${e(grams(day.mg))}g · 料费 ${e(reportBusinessAmount(day.amount,day.knownAmount))}</b></div><div class="report-pool-material-sources">${day.sources.map(source=>`<p><span>${e(reportPoolMaterialSourceLabel(source))}</span><strong>${e(reportPoolMaterialFormula(source))}</strong></p>`).join('')}</div></li>`;
|
||||
}
|
||||
function reportPoolMaterialPendingNote(pool){
|
||||
return pool.days.some(day=>day.sources&&day.sources.reduce((total,source)=>total+source.knownAmount,0)>day.knownAmount)?'部分来源已可核对,料费待补的订单尚未计入已知料费。':'';
|
||||
}
|
||||
function reportOwnerAdvanceAmount(value,known){return value===null?'待补(已知 ¥'+yuan(known)+')':'¥'+yuan(value);}
|
||||
function reportOwnerAdvanceFormula(business,day){
|
||||
return `${business.member==='owner'?'麦麦付款合计':'麦麦垫付合计'}:料池料费 ${reportOwnerAdvanceAmount(day.poolAmount,day.knownPoolAmount)} + 其他成本 ${reportOwnerAdvanceAmount(day.otherAmount,day.knownOtherAmount)} = ${reportOwnerAdvanceAmount(day.amount,day.knownAmount)}`;
|
||||
@@ -1452,12 +1464,12 @@ function reportOwnerAdvancesText(business){
|
||||
function reportPoolMaterialHTML(business){
|
||||
const pool=business.poolMaterial;if(!pool?.days.length)return '';
|
||||
const owner=pool.byPayer.owner;
|
||||
return `<div class="report-pool-material" aria-label="${e(business.name)}所属订单料池用料"><div class="report-pool-material-heading"><span>料池已用料费</span><strong>${e(reportBusinessAmount(pool.amount,pool.knownAmount))}</strong>${pool.missingCount?'<span class="badge warn">料费待补</span>':''}</div><ul>${pool.days.map(day=>`<li><span>${e(day.date)} 料池</span><strong>${e(reportPoolMaterialFormula(day))}</strong></li>`).join('')}</ul><p>其中麦麦垫付 <b>${e(reportBusinessAmount(owner.amount,owner.knownAmount))}</b></p><p>其他成本 <b>${e(reportBusinessAmount(pool.otherCosts.amount,pool.otherCosts.knownAmount))}</b><small class="muted">(其余商品成本、工费与费用)</small></p><p class="small muted">料费已计入总成本,已记入待转的部分不再另加。按未四舍五入均价逐单核算,显示料价相乘可能有分币差。${pool.hasPriceLocks?'锁价料费按原预留与回料日期记往来,交付日不再加一次。':''}</p></div>`;
|
||||
return `<div class="report-pool-material" aria-label="${e(business.name)}所属订单料池用料"><div class="report-pool-material-heading"><span>已用料合计</span><strong>${e(grams(pool.mg))}g</strong><span>料池已用料费</span><strong>${e(reportBusinessAmount(pool.amount,pool.knownAmount))}</strong>${pool.missingCount?'<span class="badge warn">料费待补</span>':''}</div><ul>${pool.days.map(reportPoolMaterialDayHTML).join('')}</ul>${reportPoolMaterialPendingNote(pool)?`<p class="small muted">${e(reportPoolMaterialPendingNote(pool))}</p>`:''}<p>其中麦麦垫付 <b>${e(reportBusinessAmount(owner.amount,owner.knownAmount))}</b></p><p>其他成本 <b>${e(reportBusinessAmount(pool.otherCosts.amount,pool.otherCosts.knownAmount))}</b><small class="muted">(其余商品成本、工费与费用)</small></p><p class="small muted">料费已计入总成本,已记入待转的部分不再另加。按未四舍五入均价逐单核算,显示料价相乘可能有分币差。${pool.hasPriceLocks?'锁价料费按原预留与回料日期记往来,交付日不再加一次。':''}</p></div>`;
|
||||
}
|
||||
function reportPoolMaterialText(business){
|
||||
const pool=business.poolMaterial;if(!pool?.days.length)return [];
|
||||
const owner=pool.byPayer.owner;
|
||||
return [`料池已用料费:${reportBusinessAmount(pool.amount,pool.knownAmount)}(已计入总成本,已记入待转的部分不再另加)`,...pool.days.map(day=>`${day.date} 料池:${reportPoolMaterialFormula(day)}`),`其中麦麦垫付:${reportBusinessAmount(owner.amount,owner.knownAmount)}`,`其他成本:${reportBusinessAmount(pool.otherCosts.amount,pool.otherCosts.knownAmount)}(其余商品成本、工费与费用)`,'料费按未四舍五入均价逐单核算,显示料价相乘可能有分币差。',...(pool.hasPriceLocks?['锁价料费按原预留与回料日期记往来,交付日不再加一次。']:[])];
|
||||
return [`已用料合计:${grams(pool.mg)}g`,`料池已用料费:${reportBusinessAmount(pool.amount,pool.knownAmount)}(已计入总成本,已记入待转的部分不再另加)`,...pool.days.map(day=>`${day.date} 料池(已用 ${grams(day.mg)}g):${reportPoolMaterialFormula(day)}`),...(reportPoolMaterialPendingNote(pool)?[reportPoolMaterialPendingNote(pool)]:[]),`其中麦麦垫付:${reportBusinessAmount(owner.amount,owner.knownAmount)}`,`其他成本:${reportBusinessAmount(pool.otherCosts.amount,pool.otherCosts.knownAmount)}(其余商品成本、工费与费用)`,'料费按未四舍五入均价逐单核算,显示料价相乘可能有分币差。',...(pool.hasPriceLocks?['锁价料费按原预留与回料日期记往来,交付日不再加一次。']:[])];
|
||||
}
|
||||
function reportOwnershipCostHTML(business){
|
||||
const showPayers=business.knownTotalCost!==0||business.totalCost===null,others=teamMemberKeys.filter(key=>key!==business.member).map(key=>business.costByPayer[key]).filter(payer=>payer.knownTotalCost!==0||payer.totalCost===null);
|
||||
@@ -1559,7 +1571,10 @@ function validatePoolMaterialCosts(b,fail){
|
||||
if(!valid(pool)||typeof pool.hasPriceLocks!=='boolean'||!Array.isArray(pool.days)||pool.missingCount>b.missingCostCount||!pool.otherCosts||!count(pool.otherCosts.knownAmount)||!nullable(pool.otherCosts.amount)||pool.otherCosts.amount!==null&&pool.otherCosts.amount!==pool.otherCosts.knownAmount)fail();
|
||||
const seen=new Set();for(const day of pool.days){
|
||||
if(!valid(day)||day.mg<=0||!/^\d{4}-\d{2}-\d{2}$/.test(day.poolId)||day.date!==day.poolId||!nullable(day.averageRate))fail();
|
||||
const key=day.poolId+':'+day.averageRate;if(seen.has(key))fail();seen.add(key);
|
||||
if(day.sources!==undefined){
|
||||
if(!Array.isArray(day.sources)||!day.sources.length||day.sources.some(source=>!source||!['public','personal_recovery'].includes(source.kind)||(source.kind==='personal_recovery'?!teamMemberKeys.includes(source.member):source.member!==null)||typeof source.priceLocked!=='boolean'||!count(source.mg)||source.mg<=0||!nullable(source.averageRate)||!count(source.knownAmount)||!count(source.missingCount)||!nullable(source.amount)||source.amount!==(source.missingCount?null:source.knownAmount))||day.sources.reduce((sum,source)=>sum+source.mg,0)!==day.mg||day.sources.reduce((sum,source)=>sum+source.knownAmount,0)<day.knownAmount||!day.missingCount&&(day.sources.some(source=>source.missingCount)||day.sources.reduce((sum,source)=>sum+source.knownAmount,0)!==day.knownAmount)||day.averageRate!==(day.sources.length===1?day.sources[0].averageRate:null))fail();
|
||||
}
|
||||
const key=day.poolId+':'+(day.sources?'sources':day.averageRate);if(seen.has(key))fail();seen.add(key);
|
||||
}
|
||||
if(['mg','knownAmount','missingCount'].some(key=>pool.days.reduce((sum,day)=>sum+day[key],0)!==pool[key])||teamMemberKeys.some(key=>pool.days.reduce((sum,day)=>sum+day.byPayer[key].knownAmount,0)!==pool.byPayer[key].knownAmount||pool.byPayer[key].knownAmount>b.costByPayer[key].knownTotalCost)||pool.knownAmount+pool.otherCosts.knownAmount!==b.knownTotalCost||b.totalCost!==null&&(pool.amount===null||pool.otherCosts.amount===null||pool.amount+pool.otherCosts.amount!==b.totalCost))fail();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user