每日对账展示料池耗用公式与麦麦垫付成本明细
This commit is contained in:
1 parent
9893ecf037
commit
a72f4a276e
7 files changed
+139
-3
No files matched your search
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
// 个人经营只读展示:收入、有效订单成本和累计往来分别复用原账,不另算利润或债务。
|
||||
const TeamMembers=require('./team-members');
|
||||
const Calc=require('./public/calculations');
|
||||
const members=TeamMembers.MEMBERS,keys=TeamMembers.KEYS;
|
||||
const name=member=>members.find(row=>row.member===member)?.label??member;
|
||||
const sum=(rows,read)=>rows.reduce((total,row)=>total+read(row),0);
|
||||
@@ -45,6 +46,42 @@ function difference(group,rows,receipts){
|
||||
if(group.incomplete)add('costs_incomplete','成本、费用或订单账务尚未补齐,仅显示已知成本与已核算利润,不能视为完整利润。');
|
||||
return {amount,reconciled:amount===0,reasons};
|
||||
}
|
||||
function poolMaterialCosts(ledger,rows,group){
|
||||
const empty=()=>({mg:0,amount:0,knownAmount:0,missingCount:0,byPayer:Object.fromEntries(keys.map(member=>[member,{amount:0,knownAmount:0}]))});
|
||||
const total={...empty(),hasPriceLocks:false},days=new Map();
|
||||
// 只展开本次已经过归属权限过滤的有效交付单。采购、未交付的预估和锁价预留不冒充耗用。
|
||||
for(const row of rows){
|
||||
if(row.kind==='afterSale'||row.status!=='delivered'||!row.costItems.some(item=>item.materialPoolId&&item.component==='material'))continue;
|
||||
const order=ledger.rawOrder(row.id);
|
||||
for(const line of order.lines){
|
||||
const pool=line.costMaterial?.mode==='pool'?line.materialPool:line.priceLockPool;
|
||||
const poolId=line.costMaterial?.mode==='pool'?line.costMaterial.poolId:pool?.poolId;
|
||||
if(!poolId)continue;
|
||||
if(line.priceLockPool)total.hasPriceLocks=true;
|
||||
const items=Calc.orderCosts({status:order.status,lines:[line]}).rows.filter(item=>item.kind==='goods'&&item.component==='material'&&item.materialPoolId===poolId);
|
||||
if(!items.length)continue;
|
||||
// 一件商品可能由多人垫付:金额沿原分摊相加,克重只记一次;不拿显示均价重算分币。
|
||||
const averageRate=pool?.averageRate??null,key=poolId+':'+averageRate;
|
||||
if(!days.has(key))days.set(key,{...empty(),poolId,date:pool?.date??poolId,averageRate});
|
||||
const day=days.get(key),mg=pool?.quantity??line.quantity,missing=items.some(item=>item.amount===null);
|
||||
for(const value of [day,total]){
|
||||
value.mg+=mg;
|
||||
if(missing)value.missingCount++;
|
||||
for(const item of items)if(item.amount!==null){value.knownAmount+=item.amount;value.byPayer[item.payer].knownAmount+=item.amount;}
|
||||
}
|
||||
}
|
||||
}
|
||||
const finish=value=>{
|
||||
value.amount=value.missingCount?null:value.knownAmount;
|
||||
// 成本待补时真实的FIFO垫付归属也未确定,不能把表单默认付款人当成已核实垫付。
|
||||
for(const payer of Object.values(value.byPayer))payer.amount=value.missingCount?null:payer.knownAmount;
|
||||
return value;
|
||||
};
|
||||
total.days=[...days.values()].sort((a,b)=>a.date.localeCompare(b.date)||(a.averageRate??0)-(b.averageRate??0)).map(finish);
|
||||
finish(total);
|
||||
total.otherCosts={knownAmount:group.knownTotalCost-total.knownAmount,amount:group.draftCount||group.pendingCostCount||group.missingCostCount>total.missingCount?null:group.knownTotalCost-total.knownAmount};
|
||||
return total;
|
||||
}
|
||||
function project(ledger,{rows,receipts,from,date,team}){
|
||||
const byMember=new Map(Object.keys(receipts).map(member=>[member,[]]));
|
||||
for(const row of rows){const member=row.member??recordMember(ledger,row.kind==='afterSale'?'after_sale':'order',row.id);byMember.get(member)?.push(row);}
|
||||
@@ -65,6 +102,7 @@ function project(ledger,{rows,receipts,from,date,team}){
|
||||
otherCost:other.some(row=>row.totalCost===null)?null:sum(other,row=>row.totalCost),knownOtherCost:sum(other,row=>row.knownTotalCost),
|
||||
profit:unknownProfitCount?null:knownProfit,knownProfit,incomplete:memberRows.some(row=>row.incomplete)||unknownProfitCount>0,
|
||||
missingCostCount:sum(memberRows,row=>row.missingCosts),pendingCostCount:sum(memberRows,row=>row.pendingCosts),unknownProfitCount,costByPayer};
|
||||
group.poolMaterial=poolMaterialCosts(ledger,memberRows,group);
|
||||
group.difference=difference(group,memberRows,income);
|
||||
const useReceipts=group.difference.reconciled&&!group.incomplete&&group.profit!==null&&group.totalCost!==null&&group.sales-group.totalCost===group.profit;
|
||||
group.equation={basis:useReceipts?'netReceipts':'sales',revenue:useReceipts?income.net:group.sales,totalCost:group.totalCost,profit:group.profit,complete:!group.incomplete&&group.profit!==null&&group.totalCost!==null};
|
||||
|
||||
@@ -63,6 +63,8 @@ input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer-
|
||||
.report-ownership-equation{display:flex;align-items:baseline;flex-wrap:wrap;gap:6px 12px;margin:12px 0;font-size:12px;color:var(--muted);font-variant-numeric:tabular-nums;overflow-wrap:anywhere}.report-ownership-equation b{font-weight:550;color:var(--ink)}.report-ownership-equation>strong{color:var(--green);font-weight:650}.report-ownership-accounts{display:flex;flex-wrap:wrap;gap:14px 28px;margin-top:16px;padding-top:14px;border-top:1px solid var(--border)}.report-ownership-account-group{flex:1 1 230px;min-width:0}.report-ownership-account-group h3{font-size:12px;color:var(--muted);font-weight:500;margin:0 0 8px}.report-ownership-account-group ul{list-style:none;padding:0;margin:0;display:grid;gap:9px}.report-ownership-account-group li{display:flex;align-items:baseline;justify-content:space-between;gap:12px;font-size:13px}.report-ownership-account-group li>div{min-width:0;overflow-wrap:anywhere}.report-ownership-account-group li small{display:block;font-size:10px;color:var(--muted);line-height:1.7;margin-top:2px}.report-ownership-account-group li>strong{font-size:14px;font-weight:550;max-width:50%;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}.report-ownership-account-group>p{margin:0}.report-ownership-empty{margin-bottom:0}.report-ownership-empty>p{margin:0}@media(max-width:650px){.report-ownership-equation{gap:6px 9px}.report-ownership-accounts{gap:17px}.report-ownership-account-group{flex-basis:100%}}
|
||||
.report-business-cost,.report-business-profit,.report-business-settlement{border-top:1px solid var(--border);margin-top:17px;padding-top:15px;min-width:0}.report-business-cost h3,.report-business-profit h3,.report-business-settlement h3{font-size:13px;font-weight:550;margin:0}.report-business-heading{display:flex;align-items:baseline;flex-wrap:wrap;gap:7px 18px}.report-business-heading h3 .small{margin-left:9px;font-size:11px;font-weight:400}.report-business-heading>strong{font-size:22px;font-weight:600;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}.report-business-paid{display:flex;flex-wrap:wrap;gap:10px 32px;margin-top:9px;font-size:13px}.report-business-paid>span{min-width:0;overflow-wrap:anywhere}.report-business-paid b{font-size:15px;font-weight:550;margin-left:5px;font-variant-numeric:tabular-nums}.report-business-paid small{display:block;font-size:11px;color:var(--muted);margin-top:4px}.report-business-profit{padding:13px 15px;background:#f1f5ed;border:1px solid #dce5d5;border-radius:7px}.report-business-profit-equation,.report-business-balance-equation{display:flex;align-items:baseline;flex-wrap:wrap;gap:5px 10px;font-size:13px;line-height:1.8;font-variant-numeric:tabular-nums;margin:7px 0 0;overflow-wrap:anywhere}.report-business-profit-equation b,.report-business-balance-equation b{font-weight:500}.report-business-profit-equation>strong{font-size:25px;font-weight:650;color:var(--green)}.report-business-profit-equation>strong.danger-text{color:var(--danger)}.report-business-profit-pending{display:block;font-size:22px;font-weight:600;margin-top:8px}.report-business-profit>p.small{margin:7px 0 0}.report-business-difference{font-size:11px;color:var(--muted);line-height:1.8;margin-top:9px}.report-business-difference p{margin:0}.report-business-difference ul{padding-left:17px;margin:5px 0 0}.report-business-dues{display:flex;flex-wrap:wrap;gap:12px 32px;margin-top:9px}.report-business-dues>div{display:flex;align-items:baseline;gap:10px;min-width:0;flex-wrap:wrap}.report-business-dues span{font-size:12px;color:var(--muted)}.report-business-dues strong{font-size:19px;font-weight:600;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}.report-business-settlement-notice{margin:9px 0 0;line-height:1.7;font-size:11px}.report-business-period{margin:9px 0 0;font-size:11px;color:var(--muted);line-height:1.8;overflow-wrap:anywhere;font-variant-numeric:tabular-nums}.report-business-period p{margin:3px 0 0}.report-business-counterparts{margin:13px 0 0}.report-business-counterparts>summary{font-size:12px;font-weight:500}.report-business-counterparts>section{border-top:1px solid var(--border);margin-top:12px;padding-top:12px}.report-business-counterparts h4{font-size:13px;font-weight:550;margin:0 0 6px}.report-business-counterparts p.small{margin:6px 0 0}.report-business-balance-equation{font-size:11px;gap:4px 8px}.report-business-balance-equation strong{font-weight:600}@media(max-width:650px){.report-business-heading{gap:6px 12px}.report-business-paid{gap:9px 18px}.report-business-profit{padding:12px}.report-business-profit-equation{font-size:12px}.report-business-profit-equation>strong{font-size:23px}.report-business-dues{gap:11px 20px}.report-business-dues>div{flex:1 1 175px}.report-business-balance-equation>span{max-width:100%}}
|
||||
|
||||
.report-pool-material{margin-top:13px;padding:12px 14px;background:var(--soft);border:1px solid var(--border);border-radius:7px;font-size:12px;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}.report-pool-material-heading{display:flex;align-items:baseline;gap:7px 16px;flex-wrap:wrap}.report-pool-material-heading>strong{font-size:18px;font-weight:600;color:var(--green)}.report-pool-material ul{list-style:none;padding:0;margin:9px 0;display:grid;gap:6px}.report-pool-material li{display:flex;align-items:baseline;flex-wrap:wrap;gap:3px 14px;line-height:1.8}.report-pool-material li>span{color:var(--muted)}.report-pool-material li>strong{font-weight:500}.report-pool-material p{margin:7px 0 0;line-height:1.7}.report-pool-material p b{font-size:14px;font-weight:550;margin-left:7px}.report-pool-material .small{font-size:11px}.report-pool-material .report-owner-advance{font-weight:550;line-height:1.9}@media(max-width:650px){.report-pool-material{padding:10px 11px}.report-pool-material li{display:block}.report-pool-material li>strong{display:block}}
|
||||
|
||||
/* 售后只登记实际费用,与销售订单同表查看。 */
|
||||
#after-sale-dialog{width:min(560px,96vw);padding:26px 28px}#after-sale-title{margin:0 0 9px}#after-sale-dialog>p{margin-bottom:20px;padding-right:24px}#after-sale-form .grid>label:last-child{grid-column:1/-1}#after-sale-form .form-actions{margin-top:22px}.after-sale-identity strong,.after-sale-identity span{display:block;overflow-wrap:anywhere}.after-sale-identity strong{font-size:12px;font-weight:600}.after-sale-identity span{font-size:12px;margin-top:2px}.report-payer-table td>.small{font-size:10px;margin-top:4px}.order-book-table .order-after-sale{background:#faf8f0}.order-after-sale .order-profit{color:var(--danger)}
|
||||
@media(max-width:650px){#after-sale-dialog{padding:22px 18px}#after-sale-form .form-actions{align-items:flex-start;gap:12px}.report-payer-table td>.small{font-size:10px}}
|
||||
|
||||
+34
-2
@@ -1423,9 +1423,28 @@ 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(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 reportPoolMaterialFormula(day){
|
||||
return `${grams(day.mg)}g × ${day.averageRate===null?'待补料价':'¥'+yuan(day.averageRate)+'/g'} = ${day.amount===null?'料费待补(已知 ¥'+yuan(day.knownAmount)+')':'¥'+yuan(day.amount)}`;
|
||||
}
|
||||
function reportOwnerPoolAdvance(business){
|
||||
const pool=business.poolMaterial;if(business.member==='owner'||!pool?.days.length)return '';
|
||||
const payer=business.costByPayer.owner,material=pool.byPayer.owner,other=payer.totalCost===null||material.amount===null?null:payer.totalCost-material.amount;
|
||||
const term=(value,known)=>value===null?'待补(已知 ¥'+yuan(known)+')':'¥'+yuan(value);
|
||||
return `麦麦垫付合计:料费 ${term(material.amount,material.knownAmount)} + 其他成本 ${term(other,payer.knownTotalCost-material.knownAmount)} = ${term(other===null?null:payer.totalCost,payer.knownTotalCost)}`;
|
||||
}
|
||||
function reportPoolMaterialHTML(business){
|
||||
const pool=business.poolMaterial;if(!pool?.days.length)return '';
|
||||
const owner=pool.byPayer.owner,ownerAdvance=reportOwnerPoolAdvance(business);
|
||||
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>${ownerAdvance?`<p class="report-owner-advance">${e(ownerAdvance)}</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,ownerAdvance=reportOwnerPoolAdvance(business);
|
||||
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)}(其余商品成本、工费与费用)`,...(ownerAdvance?[ownerAdvance]:[]),'料费按未四舍五入均价逐单核算,显示料价相乘可能有分币差。',...(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);
|
||||
return `<section class="report-business-cost" aria-label="${e(business.name)}所属订单成本"><div class="report-business-heading"><h3>所属订单总成本${business.afterSaleCount?`<span class="small muted">含售后 ${business.afterSaleCount} 笔</span>`:''}</h3><strong>${e(reportBusinessAmount(business.totalCost,business.knownTotalCost))}</strong>${business.totalCost===null?'<span class="badge warn">成本待补齐</span>':''}</div>${showPayers?`<div class="report-business-paid"><span>本人付款 <b>${e(reportBusinessAmount(business.selfCost,business.knownSelfCost))}</b></span><span>他人付款 <b>${e(reportBusinessAmount(business.otherCost,business.knownOtherCost))}</b>${others.length?`<small>${others.map(payer=>`${e(payer.name)} ${e(reportBusinessAmount(payer.totalCost,payer.knownTotalCost))}`).join(';')}</small>`:''}</span></div>`:''}</section>`;
|
||||
return `<section class="report-business-cost" aria-label="${e(business.name)}所属订单成本"><div class="report-business-heading"><h3>所属订单总成本${business.afterSaleCount?`<span class="small muted">含售后 ${business.afterSaleCount} 笔</span>`:''}</h3><strong>${e(reportBusinessAmount(business.totalCost,business.knownTotalCost))}</strong>${business.totalCost===null?'<span class="badge warn">成本待补齐</span>':''}</div>${reportPoolMaterialHTML(business)}${showPayers?`<div class="report-business-paid"><span>本人付款 <b>${e(reportBusinessAmount(business.selfCost,business.knownSelfCost))}</b></span><span>他人付款 <b>${e(reportBusinessAmount(business.otherCost,business.knownOtherCost))}</b>${others.length?`<small>${others.map(payer=>`${e(payer.name)} ${e(reportBusinessAmount(payer.totalCost,payer.knownTotalCost))}`).join(';')}</small>`:''}</span></div>`:''}</section>`;
|
||||
}
|
||||
function reportOwnershipProfitHTML(business,range){
|
||||
const equation=business.equation,title=reportMonth||range.from!==range.date?'本期利润':'当日利润',complete=equation.complete&&!business.incomplete&&business.totalCost!==null&&business.profit!==null,revenue=equation.basis==='netReceipts'?'所属订单净收入':'销售净额',difference=business.difference;
|
||||
@@ -1445,7 +1464,7 @@ function reportOwnershipReceiptsHTML(r,range){
|
||||
}
|
||||
function reportOwnershipBusinessText(business){
|
||||
const settlement=business.settlement;
|
||||
return [`所属订单总成本:${reportBusinessAmount(business.totalCost,business.knownTotalCost)};本人付款 ${reportBusinessAmount(business.selfCost,business.knownSelfCost)};他人付款 ${reportBusinessAmount(business.otherCost,business.knownOtherCost)}`,...teamMemberKeys.filter(key=>key!==business.member).map(key=>business.costByPayer[key]).filter(payer=>payer.knownTotalCost||payer.totalCost===null).map(payer=>`${payer.name}付款:${reportBusinessAmount(payer.totalCost,payer.knownTotalCost)}`),`本期利润:${business.equation.complete&&!business.incomplete&&business.profit!==null?'¥'+yuan(business.profit):'待核算,完整利润暂不显示'}`,...business.difference.reasons.map(reason=>reason.text),`截至 ${settlement.date} 待转:${settlement.available?(settlement.partial?'已知 ':'')+'本人应转他人 ¥'+yuan(settlement.dueOut)+';他人应转本人 ¥'+yuan(settlement.dueIn):'待核对历史结算,暂不显示金额'}`,...settlement.counterparts.filter(row=>row.openingDue||row.periodNew||row.periodTransferred||row.closingDue).map(row=>`${row.name}往来(正数本人转出,负数本人转入):此前 ${reportSettlementTerm(row.openingDue)} + 本期新增 ${reportSettlementTerm(row.periodNew)} − 本期实际已转 ${reportSettlementTerm(row.periodTransferred)} = 截至所选日 ${reportSettlementTerm(row.closingDue)}`),settlement.notice||''];
|
||||
return [`所属订单总成本:${reportBusinessAmount(business.totalCost,business.knownTotalCost)};本人付款 ${reportBusinessAmount(business.selfCost,business.knownSelfCost)};他人付款 ${reportBusinessAmount(business.otherCost,business.knownOtherCost)}`,...reportPoolMaterialText(business),...teamMemberKeys.filter(key=>key!==business.member).map(key=>business.costByPayer[key]).filter(payer=>payer.knownTotalCost||payer.totalCost===null).map(payer=>`${payer.name}付款:${reportBusinessAmount(payer.totalCost,payer.knownTotalCost)}`),`本期利润:${business.equation.complete&&!business.incomplete&&business.profit!==null?'¥'+yuan(business.profit):'待核算,完整利润暂不显示'}`,...business.difference.reasons.map(reason=>reason.text),`截至 ${settlement.date} 待转:${settlement.available?(settlement.partial?'已知 ':'')+'本人应转他人 ¥'+yuan(settlement.dueOut)+';他人应转本人 ¥'+yuan(settlement.dueIn):'待核对历史结算,暂不显示金额'}`,...settlement.counterparts.filter(row=>row.openingDue||row.periodNew||row.periodTransferred||row.closingDue).map(row=>`${row.name}往来(正数本人转出,负数本人转入):此前 ${reportSettlementTerm(row.openingDue)} + 本期新增 ${reportSettlementTerm(row.periodNew)} − 本期实际已转 ${reportSettlementTerm(row.periodTransferred)} = 截至所选日 ${reportSettlementTerm(row.closingDue)}`),settlement.notice||''];
|
||||
}
|
||||
function reportOwnershipReceiptsText(r){
|
||||
return ['按订单归属核对净收入(收款减退款,已含他人代收,尚未扣成本与费用)',...reportOwnershipKeys(r).flatMap(key=>{const person=r.ownershipReceipts[key];return [`${person.name}所属订单净收入:¥${yuan(person.net)};实收 ¥${yuan(person.receipt)};实退 ¥${yuan(person.refund)}`,...person.accounts.map(account=>`${account.recipient===person.member?'本人收款':'他人代收'} / ${account.account}:实收 ¥${yuan(account.receipt)},实退 ¥${yuan(account.refund)},净额 ¥${yuan(account.net)}`),...reportOwnershipBusinessText(r.ownershipBusiness[key]),''];})];
|
||||
@@ -1493,6 +1512,18 @@ function validateOwnershipReceipts(r){
|
||||
const identity=item=>JSON.stringify([item.id,item.kind,item.amount,item.account,item.date,item.order_id,item.price_lock_id]),actual=teamDataKeys(r.recipientReceipts).flatMap(key=>r.recipientReceipts[key].items).map(identity).sort(),copies=owned.map(identity).sort();
|
||||
if(actual.length!==copies.length||actual.some((value,index)=>value!==copies[index]))fail();
|
||||
}
|
||||
function validatePoolMaterialCosts(b,fail){
|
||||
const count=value=>Number.isSafeInteger(value)&&value>=0,nullable=value=>value===null||count(value),pool=b.poolMaterial;
|
||||
const valid=value=>value&&['mg','knownAmount','missingCount'].every(key=>count(value[key]))&&nullable(value.amount)&&value.amount===(value.missingCount?null:value.knownAmount)&&value.byPayer&&Object.keys(value.byPayer).length===teamMemberKeys.length&&teamMemberKeys.every(key=>{
|
||||
const payer=value.byPayer[key];return payer&&count(payer.knownAmount)&&nullable(payer.amount)&&payer.amount===(value.missingCount?null:payer.knownAmount);
|
||||
})&&teamMemberKeys.reduce((sum,key)=>sum+value.byPayer[key].knownAmount,0)===value.knownAmount;
|
||||
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(['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();
|
||||
}
|
||||
function validateOwnershipBusiness(r){
|
||||
const fail=()=>{throw new Error('所属订单成本、利润或待转资料未完整返回,请重新读取。');},money=value=>Number.isSafeInteger(value),nullable=value=>value===null||money(value),count=value=>money(value)&&value>=0,keys=teamDataKeys(r.ownershipReceipts);
|
||||
if(!r.ownershipBusiness||typeof r.ownershipBusiness!=='object'||Array.isArray(r.ownershipBusiness)||Object.keys(r.ownershipBusiness).length!==keys.length||!keys.every(key=>Object.hasOwn(r.ownershipBusiness,key)))fail();
|
||||
@@ -1502,6 +1533,7 @@ function validateOwnershipBusiness(r){
|
||||
if(!b.costByPayer||Object.keys(b.costByPayer).length!==teamMemberKeys.length)fail();
|
||||
for(const payer of teamMemberKeys){const row=b.costByPayer[payer];if(!row||row.member!==payer||typeof row.name!=='string'||!row.name||!nullable(row.totalCost)||!money(row.knownTotalCost)||!count(row.missingCount)||!count(row.pendingCount)||row.totalCost!==null&&row.totalCost!==row.knownTotalCost)fail();}
|
||||
if(teamMemberKeys.reduce((total,key)=>total+b.costByPayer[key].knownTotalCost,0)!==b.knownTotalCost||b.costByPayer[member].knownTotalCost!==b.knownSelfCost||teamMemberKeys.reduce((total,key)=>total+b.costByPayer[key].missingCount,0)!==b.missingCostCount||teamMemberKeys.reduce((total,key)=>total+b.costByPayer[key].pendingCount,0)!==b.pendingCostCount)fail();
|
||||
validatePoolMaterialCosts(b,fail);
|
||||
const difference=b.difference,equation=b.equation,settlement=b.settlement;
|
||||
if(!difference||difference.amount!==b.netReceipts-b.sales||typeof difference.reconciled!=='boolean'||!Array.isArray(difference.reasons)||!difference.reasons.every(reason=>reason&&typeof reason.code==='string'&&typeof reason.text==='string'))fail();
|
||||
if(!equation||!['netReceipts','sales'].includes(equation.basis)||equation.revenue!==(equation.basis==='netReceipts'?b.netReceipts:b.sales)||equation.totalCost!==b.totalCost||equation.profit!==b.profit||typeof equation.complete!=='boolean'||equation.complete&&(!money(equation.totalCost)||!money(equation.profit)||equation.revenue-equation.totalCost!==equation.profit))fail();
|
||||
|
||||
@@ -20,6 +20,7 @@ function reportForFunds(funds){
|
||||
const owned={member,name:member==='owner'?'麦麦':'助理',...funds.ownerReceipts,items,accounts:items.length?[{account:'麦麦微信',recipient:'owner',channel:'wechat',...funds.ownerReceipts,entryCount:items.length}]:[]};
|
||||
const ownershipReceipts={owner:owned,assistant:{member:'assistant',name:'助理',receipt:0,refund:0,net:0,accounts:[],items:[]}};
|
||||
const ownershipBusiness=Object.fromEntries(Object.entries(ownershipReceipts).map(([member,person])=>[member,{member,name:person.name,basis:'orderDate',from:funds.from,date:funds.date,sales:0,netReceipts:person.net,totalCost:0,knownTotalCost:0,selfCost:0,knownSelfCost:0,otherCost:0,knownOtherCost:0,profit:0,knownProfit:0,incomplete:false,missingCostCount:0,pendingCostCount:0,unknownProfitCount:0,draftCount:0,recordCount:0,orderCount:0,afterSaleCount:0,hasActivity:person.items.length>0,costByPayer:Object.fromEntries(['owner','assistant','assistant2'].map(key=>[key,{member:key,name:key,totalCost:0,knownTotalCost:0,missingCount:0,pendingCount:0}])),difference:{amount:person.net,reconciled:person.net===0,reasons:[]},equation:{basis:'sales',revenue:0,totalCost:0,profit:0,complete:true},settlement:{available:false,basis:'cumulative-through-date',from:funds.from,date:funds.date,dueOut:null,dueIn:null,partial:false,pendingCount:0,legacyCount:0,notice:'旧双人结算请核对原单。',counterparts:[]}}]));
|
||||
for(const b of Object.values(ownershipBusiness))b.poolMaterial={mg:0,amount:0,knownAmount:0,missingCount:0,hasPriceLocks:false,byPayer:Object.fromEntries(['owner','assistant','assistant2'].map(key=>[key,{amount:0,knownAmount:0}])),days:[],otherCosts:{amount:0,knownAmount:0}};
|
||||
return {basis:'orderDate',date:funds.date,from:funds.from,summary:{orderCount:0,completedCount:0,returnedCount:0,cancelledCount:0,draftCount:0,afterSaleCount:0,sale:0,profit:0,totalCost:0,missingCosts:0},orderRows:[],accounts:[],receiptsByOrderDate:funds.ownerReceipts,recipientReceipts,ownershipReceipts,ownershipBusiness,payerCosts:{owner:cost('麦麦'),assistant:cost('助理')},goods:0,expense:0,inventory:[],unsettled:[],warnings:[],customerBalance:0,settlementDue:0,close:null,dailyFunds:funds};
|
||||
}
|
||||
function attrs(tag){const result={};for(const match of tag.matchAll(/([\w-]+)="([^"]*)"/g))result[match[1]]=match[2].replace(/"/g,'"').replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');return result;}
|
||||
|
||||
@@ -99,12 +99,38 @@ test('日购料只把所属订单耗用计成本,不重复加整日采购;
|
||||
const paid=check(f.report()).ownershipBusiness.assistant;assert.equal(paid.totalCost,0);assert.equal(paid.profit,0);
|
||||
const report=check(f.report(D2)),own=report.ownershipBusiness.assistant;assert.equal(own.totalCost,274200);assert.equal(own.selfCost,3600);assert.equal(own.otherCost,270600);assert.equal(own.profit,25800);assert.equal(own.settlement.dueOut,270600);assert.notEqual(own.totalCost,900000);assert.equal(report.outlayTotal,4200);
|
||||
f.action(id,'return',{date:D3,reason:'合成池料退回',returnPockets:['金料'],verified:true});const returned=check(f.report(D2)).ownershipBusiness.assistant;assert.equal(returned.totalCost,600);assert.equal(returned.profit,-600);assert.equal(check(f.report(D3)).ownershipBusiness.assistant.settlement.dueOut,600);
|
||||
assert.equal(returned.poolMaterial.mg,0);assert.equal(returned.poolMaterial.amount,0);assert.deepEqual(returned.poolMaterial.days,[]);assert.equal(returned.poolMaterial.otherCosts.amount,600);
|
||||
});
|
||||
|
||||
test('所属订单料池明细克重不随多人FIFO分摊重复,分币用原金额,应转已经含麦麦垫付料费',t=>{
|
||||
const f=fixture(t);f.purchase({grams:'1',total:'900',payer:'assistant'});f.purchase({grams:'2',total:'2000',payer:'owner'});
|
||||
const pooled=(quantity,labor,accessories)=>({name:'足金合成挂件',unit:'g',quantity,pocket:'',payer:'assistant',sale:'3000',costParts:{material:'',labor,accessories,other:'0'},costPayers:{material:'owner',labor:'owner'},costMaterial:{mode:'pool',poolId:D}});
|
||||
f.save('assistant',{lines:[pooled('1.001','10','1')],fee_items:[{key:'shipping',note:'合成实付运费',amount:'6',payer:'owner'}]});f.save('assistant',{lines:[pooled('0.999','20','2')]});
|
||||
const report=check(f.report()),own=report.ownershipBusiness.assistant,pool=own.poolMaterial;
|
||||
assert.equal(pool.mg,2000);assert.equal(pool.amount,193333);assert.equal(pool.days.length,1);assert.equal(pool.days[0].averageRate,96667);assert.equal(pool.days[0].mg,2000);assert.equal(pool.days[0].amount,193333);
|
||||
assert.notEqual(pool.amount,pool.days[0].averageRate*2,'不能拿两位展示均价重新乘克重');assert.equal(pool.byPayer.assistant.amount,90000);assert.equal(pool.byPayer.owner.amount,103333);assert.equal(pool.byPayer.assistant2.amount,0);
|
||||
assert.equal(pool.otherCosts.amount,3900);assert.equal(own.totalCost,197233);assert.equal(own.settlement.dueOut,106933);assert.equal(own.settlement.counterparts.find(row=>row.member==='owner').periodNew,103333+3600);assert.equal(report.outlayGoods,293300,'采购现金保留原口径,未重复加耗用料费');
|
||||
const old=own.totalCost;f.save('assistant',{lines:[line('100','60')]});const mixed=check(f.report()).ownershipBusiness.assistant;assert.equal(mixed.poolMaterial.amount,193333);assert.equal(mixed.poolMaterial.otherCosts.amount,9900);assert.equal(mixed.totalCost,old+6000);assert.equal(mixed.settlement.dueOut,112933);
|
||||
const foreign=f.save('assistant2',{customer:'不可见池料客户',lines:[pooled('0.500','0','0')]});
|
||||
const personal=check(f.report(D,D,'assistant')).ownershipBusiness.assistant,filtered=check(f.report(D,D,'owner','assistant')).ownershipBusiness.assistant;
|
||||
assert.deepEqual(personal.poolMaterial,filtered.poolMaterial);assert.equal(personal.poolMaterial.mg,2000);assert.equal(personal.poolMaterial.amount,193333);assert.ok(!JSON.stringify(personal).includes(foreign));assert.ok(!JSON.stringify(personal).includes('不可见池料客户'));
|
||||
});
|
||||
|
||||
test('跨日多料池分别列原料价,未使用的采购及录错作废不计已用料费',t=>{
|
||||
const f=fixture(t);f.purchase();f.purchase({date:D2,grams:'10',total:'9500'});
|
||||
const pooled=(poolId,quantity)=>({name:'足金合成挂件',unit:'g',quantity,pocket:'',payer:'owner',sale:'3000',costParts:{material:'',labor:'0',accessories:'0',other:'0'},costMaterial:{mode:'pool',poolId}});
|
||||
assert.deepEqual(check(f.report()).ownershipBusiness.assistant.poolMaterial.days,[]);
|
||||
f.save('assistant',{date:D3,lines:[pooled(D,'1'),pooled(D2,'2')]});const pool=check(f.report(D3)).ownershipBusiness.assistant.poolMaterial;
|
||||
assert.equal(pool.mg,3000);assert.equal(pool.amount,280000);assert.deepEqual(pool.days.map(row=>[row.date,row.mg,row.averageRate,row.amount]),[[D,1000,90000,90000],[D2,2000,95000,190000]]);
|
||||
const mistaken=f.save('assistant',{date:D3,lines:[pooled(D2,'1')]});f.voidOrder(mistaken);const after=check(f.report(D3)).ownershipBusiness.assistant.poolMaterial;assert.equal(after.mg,3000);assert.equal(after.amount,280000);assert.equal(after.otherCosts.amount,0);
|
||||
});
|
||||
|
||||
test('成本缺失、料池待补与旧单未入账费用保留null和已知数,不能显示完整利润或结清',t=>{
|
||||
const f=fixture(t);f.save('assistant',{date:D2,lines:[{name:'足金合成待补',unit:'g',quantity:'1.000',pocket:'',payer:'owner',costPayers:{material:'owner',labor:'assistant'},sale:'1000',costParts:{material:'',labor:'30',accessories:'0',other:'0'},costMaterial:{mode:'pool',poolId:D}}],fee_items:[{key:'shipping',note:'合成实付运费',amount:'5',payer:'owner'}]});
|
||||
let own=check(f.report(D2)).ownershipBusiness.assistant;assert.equal(own.totalCost,null);assert.equal(own.knownTotalCost,3500);assert.equal(own.selfCost,3000);assert.equal(own.otherCost,null);assert.equal(own.knownOtherCost,500);assert.equal(own.profit,null);assert.equal(own.knownProfit,0);assert.equal(own.incomplete,true);assert.equal(own.missingCostCount,1);assert.equal(own.unknownProfitCount,1);assert.equal(own.equation.complete,false);assert.equal(own.settlement.partial,true);assert.ok(own.settlement.pendingCount>0);
|
||||
assert.equal(own.poolMaterial.mg,1000);assert.equal(own.poolMaterial.amount,null);assert.equal(own.poolMaterial.byPayer.owner.amount,null);assert.equal(own.poolMaterial.byPayer.assistant.amount,null);assert.equal(own.poolMaterial.otherCosts.amount,3500);assert.equal(own.poolMaterial.days[0].averageRate,null);
|
||||
f.purchase();own=check(f.report(D2)).ownershipBusiness.assistant;assert.equal(own.totalCost,93500);assert.equal(own.profit,6500);assert.equal(own.incomplete,false);
|
||||
assert.equal(own.poolMaterial.amount,90000);assert.equal(own.poolMaterial.byPayer.owner.amount,90000);assert.equal(own.poolMaterial.otherCosts.amount,3500);
|
||||
const old=f.save('assistant',{date:D2,lines:[line('100','60')],fee_items:[{key:'shipping',note:'合成旧单待核费',amount:'',payer:'owner',status:'estimated'}]},false);f.action(old,'confirm',{date:D2});
|
||||
own=check(f.report(D2)).ownershipBusiness.assistant;assert.equal(own.totalCost,null);assert.equal(own.profit,null);assert.equal(own.pendingCostCount,1);assert.equal(own.costByPayer.owner.pendingCount,1);assert.equal(own.settlement.partial,true);assert.ok(own.difference.reasons.some(row=>row.code==='unfinalized_orders'));
|
||||
f.save('assistant',{date:D2},false);own=check(f.report(D2)).ownershipBusiness.assistant;assert.equal(own.draftCount,1);assert.equal(own.costByPayer.assistant.totalCost,null);assert.equal(own.hasActivity,true);
|
||||
|
||||
@@ -29,12 +29,17 @@ test('同日少重交付只耗一次,随后补料同步原锁量、实际成
|
||||
f.buy('1','2000','assistant2');p=f.l.materialPools().current;const d=f.l.priceLockDetail(lock.id),o=f.l.detail(id);
|
||||
assert.equal(d.material_amount,200000);assert.equal(o.goodsCost,133333);assert.equal(o.profit,66667);assert.equal(d.delivery.leftover_cost,66667);assert.equal(p.consumedCost,133333);assert.equal(p.remainingCost,266667);assert.equal(p.totalAmount,p.consumedCost+p.remainingCost);
|
||||
assert.deepEqual(o.lines[0].materialAllocations.filter(a=>a.source==='original').map(a=>[a.payer,a.amount]),[['assistant',80000],['owner',53333]]);assert.equal(f.l.rows("SELECT * FROM team_fund_cash WHERE source_kind='price_lock' AND kind='outlay'").length,0);
|
||||
const report=f.l.asActor(f.actors.assistant).reportFor({date:D,basis:'orderDate'},f.actors.assistant),own=report.ownershipBusiness.assistant;
|
||||
assert.equal(own.poolMaterial.mg,1000);assert.equal(own.poolMaterial.amount,133333);assert.equal(own.poolMaterial.hasPriceLocks,true);assert.equal(own.poolMaterial.days[0].averageRate,133333);assert.equal(own.poolMaterial.byPayer.owner.amount,53333);assert.equal(own.poolMaterial.byPayer.assistant.amount,80000);assert.equal(own.poolMaterial.otherCosts.amount,0);assert.equal(own.settlement.dueOut,53333);
|
||||
});
|
||||
test('锁价日跨天冻结,少重余料按原成本与付款来源回交付日池,未用原锁重不进入期初',t=>{
|
||||
const f=fixture(t);f.buy('0.8','800','assistant',P);f.buy('1.2','1200','owner',P);f.enable(P);const lock=f.lock('1.500',P),old=f.l.priceLockDetail(lock.id);f.buy('1','3000');
|
||||
assert.equal(f.l.priceLockDetail(lock.id).material_amount,old.material_amount);assert.equal(f.l.materialPools().current.opening.mg,500);assert.equal(f.l.materialPools().current.opening.amount,50000);
|
||||
const id=f.deliver(lock.id,'0.500').id,p=f.l.materialPools().current;assert.equal(f.l.detail(id).goodsCost,50000);assert.equal(p.totalMg,2500);assert.equal(p.totalAmount,450000);assert.equal(p.usedMg,0);assert.equal(p.remainingMg,2500);assert.equal(f.l.priceLockDetail(lock.id).delivery.leftover_cost,100000);
|
||||
const ret=f.l.rows('SELECT * FROM price_lock_pool_returns WHERE price_lock_id=?',lock.id);assert.equal(ret.length,1);assert.deepEqual(JSON.parse(ret[0].allocations),[{payer:'assistant',amount:30000},{payer:'owner',amount:70000}]);assert.equal(f.l.rows("SELECT * FROM team_fund_cash WHERE source_kind='price_lock' AND kind='outlay'").length,0);
|
||||
const report=date=>f.l.asActor(f.actors.assistant).reportFor({date,basis:'orderDate'},f.actors.assistant).ownershipBusiness.assistant,original=report(P),delivery=report(D),poolCost=delivery.poolMaterial;
|
||||
assert.equal(original.poolMaterial.mg,0);assert.equal(original.poolMaterial.amount,0);assert.equal(original.settlement.dueOut,70000,'原锁日预留已产生往来,不能等交付再加');
|
||||
assert.equal(poolCost.mg,500);assert.equal(poolCost.amount,50000);assert.equal(poolCost.days[0].date,P);assert.equal(poolCost.days[0].averageRate,100000);assert.equal(poolCost.byPayer.owner.amount,0);assert.equal(poolCost.byPayer.assistant.amount,50000);assert.equal(delivery.settlement.dueOut,0);assert.equal(delivery.settlement.counterparts.find(row=>row.member==='owner').periodNew,-70000,'交付日只释放原锁余料,交付耗用不再增加一次往来');
|
||||
});
|
||||
test('采购删除造成锁价成本待补,拒绝交付并完整回滚,补料恢复成本和付款归属',t=>{
|
||||
const f=fixture(t);f.buy('0.8','800','assistant');const b=f.buy('1.2','1200');f.enable();const lock=f.lock();f.run({},()=>f.l.deleteMaterialPurchase(b.id,{revision:1},f.actors.owner));
|
||||
|
||||
@@ -10,7 +10,7 @@ function ownershipPerson(member,name,items){
|
||||
}
|
||||
function businessPerson(person,date=D,from=date,extra={}){
|
||||
const costByPayer=Object.fromEntries(['owner','assistant','assistant2'].map(member=>[member,{member,name:{owner:'麦麦',assistant:'助理1',assistant2:'助理2'}[member],totalCost:0,knownTotalCost:0,missingCount:0,pendingCount:0,...extra.costByPayer?.[member]}])),payers=Object.values(costByPayer),others=payers.filter(row=>row.member!==person.member),knownTotalCost=payers.reduce((total,row)=>total+row.knownTotalCost,0),totalCost=payers.some(row=>row.totalCost===null)?null:knownTotalCost,sales=extra.sales??person.net,profit=Object.hasOwn(extra,'profit')?extra.profit:totalCost===null?null:sales-totalCost,incomplete=extra.incomplete??(totalCost===null||profit===null);
|
||||
const result={member:person.member,name:person.name,basis:'orderDate',from,date,sales,netReceipts:person.net,totalCost,knownTotalCost,selfCost:costByPayer[person.member].totalCost,knownSelfCost:costByPayer[person.member].knownTotalCost,otherCost:others.some(row=>row.totalCost===null)?null:others.reduce((total,row)=>total+row.totalCost,0),knownOtherCost:others.reduce((total,row)=>total+row.knownTotalCost,0),profit,knownProfit:profit??0,incomplete,missingCostCount:payers.reduce((total,row)=>total+row.missingCount,0),pendingCostCount:payers.reduce((total,row)=>total+row.pendingCount,0),unknownProfitCount:profit===null?1:0,draftCount:0,recordCount:person.items.length,orderCount:person.items.length,afterSaleCount:0,hasActivity:person.items.length>0,costByPayer,difference:{amount:person.net-sales,reconciled:person.net===sales,reasons:person.net===sales?[]:[{code:'payment_sales_difference',text:'净收款与销售不同,按原账核对利润。'}]},equation:{basis:person.net===sales&&!incomplete?'netReceipts':'sales',revenue:person.net===sales&&!incomplete?person.net:sales,totalCost,profit,complete:!incomplete},settlement:{available:false,basis:'cumulative-through-date',from,date,dueOut:null,dueIn:null,partial:false,pendingCount:0,legacyCount:0,notice:'历史结算请核对原单。',counterparts:[]},...extra,costByPayer};return result;
|
||||
const result={member:person.member,name:person.name,basis:'orderDate',from,date,sales,netReceipts:person.net,totalCost,knownTotalCost,selfCost:costByPayer[person.member].totalCost,knownSelfCost:costByPayer[person.member].knownTotalCost,otherCost:others.some(row=>row.totalCost===null)?null:others.reduce((total,row)=>total+row.totalCost,0),knownOtherCost:others.reduce((total,row)=>total+row.knownTotalCost,0),profit,knownProfit:profit??0,incomplete,missingCostCount:payers.reduce((total,row)=>total+row.missingCount,0),pendingCostCount:payers.reduce((total,row)=>total+row.pendingCount,0),unknownProfitCount:profit===null?1:0,draftCount:0,recordCount:person.items.length,orderCount:person.items.length,afterSaleCount:0,hasActivity:person.items.length>0,costByPayer,difference:{amount:person.net-sales,reconciled:person.net===sales,reasons:person.net===sales?[]:[{code:'payment_sales_difference',text:'净收款与销售不同,按原账核对利润。'}]},equation:{basis:person.net===sales&&!incomplete?'netReceipts':'sales',revenue:person.net===sales&&!incomplete?person.net:sales,totalCost,profit,complete:!incomplete},settlement:{available:false,basis:'cumulative-through-date',from,date,dueOut:null,dueIn:null,partial:false,pendingCount:0,legacyCount:0,notice:'历史结算请核对原单。',counterparts:[]},...extra,costByPayer};return {...result,poolMaterial:extra.poolMaterial??{mg:0,amount:0,knownAmount:0,missingCount:0,hasPriceLocks:false,byPayer:Object.fromEntries(['owner','assistant','assistant2'].map(key=>[key,{amount:0,knownAmount:0}])),days:[],otherCosts:{amount:result.totalCost,knownAmount:result.knownTotalCost}}};
|
||||
}
|
||||
function syncBusiness(response){response.ownershipBusiness=Object.fromEntries(Object.entries(response.ownershipReceipts).map(([member,person])=>[member,businessPerson(person,response.date,response.from)]));return response;}
|
||||
function report(date=D,from=date,empty=false){
|
||||
@@ -195,3 +195,35 @@ test('经营投影缺失、付款不平、利润等式或待转构成错误均
|
||||
for(const change of changes){const response=businessReport();change(response);const h=businessHarness(response);await h.run('renderReport()');assert.equal(h.run('currentReport'),null);assert.match(h.content.innerHTML,/所属订单成本、利润或待转资料未完整返回/);assert.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);}
|
||||
const legacy=report();legacy.ownershipBusiness.assistant.settlement.partial=true;legacy.ownershipBusiness.assistant.settlement.legacyCount=1;const h=harness(legacy);await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/待核对历史结算,暂不显示待转金额/);assert.doesNotMatch(html,/本人应转他人<\/span><strong>¥0\.00|已结清/);
|
||||
});
|
||||
|
||||
function poolBusinessReport(){
|
||||
const response=businessReport(),byPayer={owner:{amount:103333,knownAmount:103333},assistant:{amount:90000,knownAmount:90000},assistant2:{amount:0,knownAmount:0}},day={poolId:D,date:D,mg:2000,averageRate:96667,amount:193333,knownAmount:193333,missingCount:0,byPayer};
|
||||
response.ownershipBusiness.assistant=businessPerson(response.ownershipReceipts.assistant,D,D,{costByPayer:{owner:{totalCost:106933,knownTotalCost:106933},assistant:{totalCost:90300,knownTotalCost:90300}},poolMaterial:{mg:2000,amount:193333,knownAmount:193333,missingCount:0,hasPriceLocks:false,byPayer,days:[day],otherCosts:{amount:3900,knownAmount:3900}},settlement:settlement([counterpart('owner',50000,86933)])});
|
||||
return response;
|
||||
}
|
||||
test('料池用料在所属订单卡直接可见,保留原分币金额、麦麦垫付和其他成本,待转不再加一次',async()=>{
|
||||
const h=businessHarness(poolBusinessReport());await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');
|
||||
assert.match(html,/所属订单总成本<\/h3><strong>¥1,972\.33/);assert.match(html,/料池已用料费<\/span><strong>¥1,933\.33/);assert.match(html,/2\.000g × ¥966\.67\/g = ¥1,933\.33/);assert.match(html,/其中麦麦垫付 <b>¥1,033\.33/);assert.match(html,/其他成本 <b>¥39\.00/);assert.match(html,/本人应转他人<\/span><strong>¥1,369\.33/);assert.match(html,/已记入待转的部分不再另加/);assert.match(html,/未四舍五入均价/);assert.doesNotMatch(html,/1,933\.34|3,302\.66/);
|
||||
assert.match(html,/麦麦垫付合计:料费 ¥1,033\.33 + 其他成本 ¥36\.00 = ¥1,069\.33/);assert.doesNotMatch(html,/麦麦垫付合计:料费 ¥1,033\.33 + 其他成本 ¥39\.00/);
|
||||
const text=h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))');assert.match(text,/料池已用料费:¥1,933\.33/);assert.match(text,/2\.000g × ¥966\.67\/g = ¥1,933\.33/);assert.match(text,/其中麦麦垫付:¥1,033\.33/);assert.match(text,/其他成本:¥39\.00/);
|
||||
assert.match(text,/麦麦垫付合计:料费 ¥1,033\.33 + 其他成本 ¥36\.00 = ¥1,069\.33/);
|
||||
});
|
||||
|
||||
test('多日料池各列原均价与耗用额,跨日锁价说明不把交付料费当作本日新往来',async()=>{
|
||||
const response=poolBusinessReport(),pool=response.ownershipBusiness.assistant.poolMaterial,prior='2026-10-21';
|
||||
pool.hasPriceLocks=true;pool.days=[{...pool.days[0],poolId:prior,date:prior,mg:1000,averageRate:90000,amount:90000,knownAmount:90000,byPayer:{owner:{amount:0,knownAmount:0},assistant:{amount:90000,knownAmount:90000},assistant2:{amount:0,knownAmount:0}}},{...pool.days[0],mg:1000,averageRate:103333,amount:103333,knownAmount:103333,byPayer:{owner:{amount:103333,knownAmount:103333},assistant:{amount:0,knownAmount:0},assistant2:{amount:0,knownAmount:0}}}];
|
||||
const h=businessHarness(response);await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/2026-10-21 料池/);assert.match(html,/1\.000g × ¥900\.00\/g = ¥900\.00/);assert.match(html,/2026-10-22 料池/);assert.match(html,/1\.000g × ¥1,033\.33\/g = ¥1,033\.33/);assert.match(html,/原预留与回料日期记往来,交付日不再加一次/);assert.match(html,/本人应转他人<\/span><strong>¥1,369\.33/);
|
||||
});
|
||||
|
||||
test('待补料费与未知FIFO付款人显示已知额和待补,其他已核实成本继续显示',async()=>{
|
||||
const response=poolBusinessReport(),pool=response.ownershipBusiness.assistant.poolMaterial;
|
||||
pool.amount=null;pool.knownAmount=0;pool.missingCount=1;pool.byPayer=Object.fromEntries(['owner','assistant','assistant2'].map(key=>[key,{amount:null,knownAmount:0}]));pool.days=[{poolId:D,date:D,mg:2000,averageRate:null,amount:null,knownAmount:0,missingCount:1,byPayer:pool.byPayer}];
|
||||
response.ownershipBusiness.assistant=businessPerson(response.ownershipReceipts.assistant,D,D,{costByPayer:{owner:{totalCost:null,knownTotalCost:3600,missingCount:1},assistant:{totalCost:300,knownTotalCost:300}},poolMaterial:pool,settlement:settlement([],D,D,{partial:true,pendingCount:1})});
|
||||
const h=businessHarness(response);await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/2\.000g × 待补料价 = 料费待补(已知 ¥0\.00)/);assert.match(html,/其中麦麦垫付 <b>已知 ¥0\.00/);assert.match(html,/其他成本 <b>¥39\.00/);assert.match(html,/待核算/);assert.doesNotMatch(html,/2\.000g × ¥0\.00/);
|
||||
assert.match(html,/麦麦垫付合计:料费 待补(已知 ¥0\.00) + 其他成本 待补(已知 ¥36\.00) = 待补(已知 ¥36\.00)/);
|
||||
});
|
||||
|
||||
test('料费分项、克重、付款归属和其他成本必须守恒,缺失投影不会把料费隐藏成0',async()=>{
|
||||
const changes=[r=>delete r.ownershipBusiness.assistant.poolMaterial,r=>r.ownershipBusiness.assistant.poolMaterial.mg++,r=>r.ownershipBusiness.assistant.poolMaterial.days[0].amount++,r=>r.ownershipBusiness.assistant.poolMaterial.byPayer.owner.knownAmount++,r=>r.ownershipBusiness.assistant.poolMaterial.otherCosts.knownAmount++];
|
||||
for(const change of changes){const response=poolBusinessReport();change(response);const h=businessHarness(response);await h.run('renderReport()');assert.equal(h.run('currentReport'),null);assert.match(h.content.innerHTML,/所属订单成本、利润或待转资料未完整返回/);assert.doesNotMatch(h.content.innerHTML,/料池已用料费<\/span>/);}
|
||||
});
|
||||
Reference in new issue
Block a user