每日对账按当天的垫付、利润与代收计算应转金额

This commit is contained in:
summer committed 2026-11-07 00:30:02 +08:00
1 parent 39f80fbab7
commit 1cbcdc728c
7 files changed
+192 -45

No files matched your search

+39 -2
View File
@@ -1,5 +1,5 @@
'use strict';
// 个人经营只读展示:收入、有效订单成本和累计往来分别复用原账,不另算利润或债务。
// 个人经营只读展示:复用原收入、有效耗用成本与利润,不写入或改变原债务。
const TeamMembers=require('./team-members');
const Calc=require('./public/calculations');
const members=TeamMembers.MEMBERS,keys=TeamMembers.KEYS;
@@ -138,6 +138,42 @@ function ownerAdvances(rows,from,date){
otherAmount:missing.some(item=>!item.poolMaterial)?null:knownOtherAmount,knownOtherAmount};
})};
}
function currentAccount(rows,income,advances,from,date){
const days=new Map(),dayOf=day=>{
if(!days.has(day))days.set(day,{date:day,recordCount:0,knownMaterialCost:0,knownOtherCost:0,knownProfit:0,
ownerNetReceipts:0,missingCostCount:0,pendingCostCount:0,unknownProfitCount:0,incomplete:false,
materialMissing:false,otherMissing:false});
return days.get(day);
};
for(const row of rows){
const day=dayOf(row.date);day.recordCount++;day.knownProfit+=row.known.profit;
if(row.profit===null)day.unknownProfitCount++;
day.incomplete ||= row.incomplete||row.profit===null;
}
for(const advance of advances.days){
const day=dayOf(advance.date);day.missingCostCount+=advance.missingCount;day.pendingCostCount+=advance.pendingCount;
day.incomplete ||= !!(advance.missingCount||advance.pendingCount);
for(const item of advance.items){
// 手填料费、锁价料费和料池分摊都沿用原成本金额,不能再叠加整池采购或显示均价。
const material=item.component==='material';
if(item.status==='recorded')day[material?'knownMaterialCost':'knownOtherCost']+=item.amount;
if(item.status==='missing')day[material?'materialMissing':'otherMissing']=true;
}
}
const ownerAccounts=new Set(income.accounts.filter(account=>account.recipient==='owner').map(account=>account.account));
for(const item of income.items){
// 和所属订单收款表一致:普通单按开单日,锁价收退款按实际发生日。
const dateKey=item.price_lock_id?item.date:item.order_date;
if(!dateKey||dateKey<from||dateKey>date)continue;
const day=dayOf(dateKey);
if(ownerAccounts.has(item.account))day.ownerNetReceipts+=item.kind==='receipt'?item.amount:-item.amount;
}
return {basis:'orderDate',from,date,days:[...days.values()].sort((a,b)=>a.date.localeCompare(b.date)).map(({materialMissing,otherMissing,...day})=>{
const knownAmount=day.knownMaterialCost+day.knownOtherCost+day.knownProfit-day.ownerNetReceipts;
return {...day,materialCost:materialMissing?null:day.knownMaterialCost,otherCost:otherMissing?null:day.knownOtherCost,
profit:day.unknownProfitCount?null:day.knownProfit,knownAmount,amount:day.incomplete?null:knownAmount};
})};
}
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);}
@@ -160,6 +196,7 @@ function project(ledger,{rows,receipts,from,date,team}){
missingCostCount:sum(memberRows,row=>row.missingCosts),pendingCostCount:sum(memberRows,row=>row.pendingCosts),unknownProfitCount,costByPayer};
group.poolMaterial=poolMaterialCosts(ledger,memberRows,group);
group.ownerAdvances=ownerAdvances(memberRows,from,date);
group.currentAccount=currentAccount(memberRows,income,group.ownerAdvances,from,date);
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};
@@ -169,4 +206,4 @@ function project(ledger,{rows,receipts,from,date,team}){
}
return result;
}
module.exports={project};
module.exports={project,currentAccount};
+2
View File
@@ -191,3 +191,5 @@ button.order-copy-button:focus-visible{outline:3px solid var(--gold);outline-off
.material-source-segments{display:grid;gap:6px;width:100%;margin:8px 0}.material-source-segments>div{display:flex;align-items:baseline;flex-wrap:wrap;gap:6px 12px;padding:7px 10px;border:1px solid var(--border);border-radius:8px}.material-source-segments small{color:var(--muted)}.material-personal-pool+.material-personal-pool{margin-top:14px;padding-top:14px;border-top:1px solid var(--border)}.material-personal-totals{display:flex;flex-wrap:wrap;gap:8px 20px;margin:8px 0 12px}.material-personal-pools li{margin:5px 0;overflow-wrap:anywhere}
.report-pool-material li.report-pool-material-day{display:block;padding-top:7px;border-top:1px solid var(--border)}.report-pool-material-day-total{display:flex;justify-content:space-between;align-items:baseline;gap:4px 16px;flex-wrap:wrap}.report-pool-material-day-total>span{color:var(--muted)}.report-pool-material-day-total>b{font-weight:550}.report-pool-material-sources>p{display:flex;justify-content:space-between;align-items:baseline;gap:3px 14px;flex-wrap:wrap;margin:5px 0 0}.report-pool-material-sources>p>strong{font-weight:500}@media(max-width:650px){.report-pool-material-sources>p{display:block}.report-pool-material-sources>p>strong{display:block}}
.report-business-current>h3{font-size:14px}.report-business-current>p.small{font-size:11px;line-height:1.8;margin:8px 0;color:var(--muted)}.report-current-day{margin-top:12px;padding-top:12px;border-top:1px solid var(--border);min-width:0}.report-current-day>header{display:flex;align-items:baseline;flex-wrap:wrap;gap:7px 16px;overflow-wrap:anywhere}.report-current-day h4{font-size:14px;font-weight:550;margin:0}.report-current-day header>span{font-size:13px}.report-current-day header>strong{font-size:23px;font-weight:650;font-variant-numeric:tabular-nums;color:var(--green)}.report-current-day header>strong.danger-text{color:var(--danger)}.report-current-day>.report-business-balance-equation{font-size:12px;line-height:1.9}.report-current-day>p.small{font-size:11px;line-height:1.8;margin-bottom:0}@media(max-width:650px){.report-current-day>header{gap:6px 12px}.report-current-day header>strong{font-size:21px}.report-current-day>.report-business-balance-equation{font-size:11px}}
+47 -15
View File
@@ -1419,7 +1419,7 @@ function reportActiveAccounts(r){
}
function reportOwnershipKeys(r){
const keys=teamDataKeys(r.ownershipReceipts);
return state.user.role==='owner'&&!reportMember?keys.filter(key=>{const person=r.ownershipReceipts[key];return person.items.length||person.receipt!==0||person.refund!==0||person.net!==0||r.ownershipBusiness[key].hasActivity;}):keys;
return state.user.role==='owner'&&!reportMember?keys.filter(key=>{const person=r.ownershipReceipts[key];return person.items.length||person.receipt!==0||person.refund!==0||person.net!==0||r.ownershipBusiness[key].recordCount||r.ownershipBusiness[key].currentAccount.days.length;}):keys;
}
function reportOwnershipAccountsHTML(person){
const ownAccounts=person.accounts.filter(account=>account.recipient===person.member),otherAccounts=person.accounts.filter(account=>account.recipient!==person.member),net=accounts=>accounts.reduce((total,account)=>total+account.net,0);
@@ -1455,7 +1455,7 @@ function reportOwnerAdvanceIdentity(item){
function reportOwnerAdvancesHTML(business){
const advances=business.ownerAdvances,single=advances.from===advances.date,label=business.member==='owner'?'麦麦付款明细':'麦麦垫付明细';
const days=advances.days.length?advances.days:single?[{date:advances.date,amount:0,knownAmount:0,missingCount:0,pendingCount:0,items:[]}]:[];
return `<details class="report-owner-advances" aria-label="${e(business.name+label)}"><summary>${single?'当日':'按日核对'}${label}</summary><p class="small muted">按所属订单开单日、售后记录日归集;仅列所选日期,不累计历史垫付。垫付与扣除代收、转账后的净往来分别核对。</p>${days.map(day=>`<div class="report-owner-advance-day"><header><h4>${e(day.date)}</h4><span>${day.missingCount?'已知':''}${business.member==='owner'?'付款':'垫付'}小计 <strong>${e(reportOwnerAdvanceAmount(day.amount,day.knownAmount))}</strong></span></header>${day.items.some(item=>item.poolMaterial)?`<p class="report-owner-advance">${e(reportOwnerAdvanceFormula(business,day))}</p>`:''}${day.items.length?`<div class="table-wrap"><table class="report-owner-advance-table" aria-label="${e(day.date+' '+label)}"><thead><tr><th>日期</th><th>客户/单号</th><th>成本项目</th><th class="number">麦麦承担金额</th></tr></thead><tbody>${day.items.map(item=>`<tr${item.status==='recorded'?'':' class="report-pending-cost"'}><td>${e(item.date)}</td><td>${reportOwnerAdvanceIdentity(item)}</td><td>${e(item.name)}${item.source?`<small class="muted">${e(item.source)}</small>`:''}</td><td class="number">${e(reportOwnerAdvanceItemAmount(item))}</td></tr>`).join('')}</tbody></table></div>`:'<p class="small muted">当天没有已登记的'+(business.member==='owner'?'麦麦付款':'麦麦垫付')+'明细。</p>'}${day.pendingCount?'<p class="small muted">待核对项目尚未入账,预估金额不计垫付小计。</p>':''}</div>`).join('')||'<p class="small muted">所选月份暂无已登记的'+label+'。</p>'}</details>`;
return `<details class="report-owner-advances" aria-label="${e(business.name+label)}"><summary>${single?'当日':'按日核对'}${label}</summary><p class="small muted">按所属订单开单日、售后记录日归集;仅列所选日期,不累计历史垫付。当日往来另列利润与麦麦代收,未扣实际转账。</p>${days.map(day=>`<div class="report-owner-advance-day"><header><h4>${e(day.date)}</h4><span>${day.missingCount?'已知':''}${business.member==='owner'?'付款':'垫付'}小计 <strong>${e(reportOwnerAdvanceAmount(day.amount,day.knownAmount))}</strong></span></header>${day.items.some(item=>item.poolMaterial)?`<p class="report-owner-advance">${e(reportOwnerAdvanceFormula(business,day))}</p>`:''}${day.items.length?`<div class="table-wrap"><table class="report-owner-advance-table" aria-label="${e(day.date+' '+label)}"><thead><tr><th>日期</th><th>客户/单号</th><th>成本项目</th><th class="number">麦麦承担金额</th></tr></thead><tbody>${day.items.map(item=>`<tr${item.status==='recorded'?'':' class="report-pending-cost"'}><td>${e(item.date)}</td><td>${reportOwnerAdvanceIdentity(item)}</td><td>${e(item.name)}${item.source?`<small class="muted">${e(item.source)}</small>`:''}</td><td class="number">${e(reportOwnerAdvanceItemAmount(item))}</td></tr>`).join('')}</tbody></table></div>`:'<p class="small muted">当天没有已登记的'+(business.member==='owner'?'麦麦付款':'麦麦垫付')+'明细。</p>'}${day.pendingCount?'<p class="small muted">待核对项目尚未入账,预估金额不计垫付小计。</p>':''}</div>`).join('')||'<p class="small muted">所选月份暂无已登记的'+label+'。</p>'}</details>`;
}
function reportOwnerAdvancesText(business){
const advances=business.ownerAdvances,label=business.member==='owner'?'麦麦付款明细':'麦麦垫付明细';
@@ -1464,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(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>`;
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 [`已用料合计:${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?['锁价料费按原预留与回料日期记往来,交付日不再加一次。']:[])];
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);
@@ -1479,21 +1479,32 @@ 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;
return `<section class="report-business-profit" aria-label="${e(business.name+title)}"><h3>${title}</h3>${complete?`<p class="report-business-profit-equation"><span>${revenue} <b>¥${yuan(equation.revenue)}</b></span><span aria-hidden="true">−</span><span>订单总成本 <b>¥${yuan(equation.totalCost)}</b></span><span aria-hidden="true">=</span><strong class="${business.profit<0?'danger-text':''}">¥${yuan(business.profit)}</strong></p>`:'<strong class="report-business-profit-pending">待核算</strong><p class="small muted">成本或利润资料尚未完整,先核对原单;完整利润暂不显示。</p>'}${difference.amount!==0||!difference.reconciled?`<div class="report-business-difference"><p>所属净收款 ¥${yuan(business.netReceipts)},销售净额 ¥${yuan(business.sales)},差额 ¥${yuan(difference.amount)}。</p>${difference.reasons.length?`<ul>${difference.reasons.map(reason=>`<li>${e(reason.text)}</li>`).join('')}</ul>`:'<p>按原账销售与成本核对利润。</p>'}</div>`:''}</section>`;
}
function reportCounterpartDirection(counterpart){return counterpart.dueOut?`本人应转${counterpart.name} ¥${yuan(counterpart.dueOut)}`:counterpart.dueIn?`${counterpart.name}应转本人 ¥${yuan(counterpart.dueIn)}`:`与${counterpart.name}的已知待转为 ¥0.00`;}
function reportSettlementTerm(value){return value<0?'(−¥'+yuan(-value)+')':'¥'+yuan(value);}
function reportSettlementDirection(name,value){return (value<0?name+'→本人':'本人→'+name)+' ¥'+yuan(Math.abs(value));}
function reportOwnershipSettlementHTML(business){
const settlement=business.settlement,rows=settlement.counterparts.filter(row=>row.openingDue||row.periodNew||row.periodTransferred||row.closingDue||row.dueOut||row.dueIn);
return `<details class="report-business-settlement report-business-history"><summary>累计往来(含历史,截至 ${e(settlement.date)})</summary><p class="small muted">这里包含历史余额,与上方当日垫付小计不同;实际转账和代收仍按原团队账目核对。</p>${settlement.available?`<div class="report-business-dues"><div><span>${settlement.partial?'已知':''}本人应转他人</span><strong>¥${yuan(settlement.dueOut)}</strong></div><div><span>${settlement.partial?'已知':''}他人应转本人</span><strong>¥${yuan(settlement.dueIn)}</strong></div></div>${rows.length?`<div class="report-business-period">${rows.map(row=>`<p>此前 ${e(reportSettlementDirection(row.name,row.openingDue))} · 本期新增 ${e(reportSettlementDirection(row.name,row.periodNew))}${row.periodTransferred?' · 本期已转 '+e(reportSettlementDirection(row.name,row.periodTransferred)):''}</p>`).join('')}</div><details class="report-business-counterparts"><summary>逐人核对待转(${rows.length} 人)</summary>${rows.map(row=>`<section><h4>${e(reportCounterpartDirection(row))}</h4><p class="small muted">正数为本人应转${e(row.name)},负数为${e(row.name)}应转本人。</p><p class="report-business-balance-equation"><span>此前待转 <b>${reportSettlementTerm(row.openingDue)}</b></span><span aria-hidden="true">+</span><span>本期新增往来 <b>${reportSettlementTerm(row.periodNew)}</b></span><span aria-hidden="true">−</span><span>本期实际已转 <b>${reportSettlementTerm(row.periodTransferred)}</b></span><span aria-hidden="true">=</span><span>截至所选日待转 <strong>${reportSettlementTerm(row.closingDue)}</strong></span></p>${row.offset?`<p class="small muted">累计双向往来已抵扣 ¥${yuan(row.offset)},已计入上方余额。</p>`:''}</section>`).join('')}</details>`:''}`:'<p class="small muted">待核对历史结算,暂不显示待转金额。</p>'}${settlement.notice&&(settlement.partial||!settlement.available)?`<p class="small ${settlement.partial?'danger-text':'muted'} report-business-settlement-notice">${e(settlement.notice)}</p>`:''}</details>`;
function reportCurrentAccountDays(business){
const account=business.currentAccount;
return account.days.length?account.days:account.from===account.date?[{date:account.date,materialCost:0,knownMaterialCost:0,otherCost:0,knownOtherCost:0,profit:0,knownProfit:0,ownerNetReceipts:0,amount:0,incomplete:false}]:[];
}
function reportOwnershipBusinessHTML(business,range){return reportOwnershipCostHTML(business)+reportOwnerAdvancesHTML(business)+reportOwnershipProfitHTML(business,range)+reportOwnershipSettlementHTML(business);}
function reportCurrentAccountDirection(business,day){
return day.amount===null?'应转金额待核算':day.amount>0?business.name+'应转麦麦':day.amount<0?'麦麦应转'+business.name:'当日无需转款';
}
function reportCurrentAccountFormula(day){
return `麦麦垫付已用料费 ${reportOwnerAdvanceAmount(day.materialCost,day.knownMaterialCost)} + 麦麦垫付其他订单成本 ${reportOwnerAdvanceAmount(day.otherCost,day.knownOtherCost)} + 本人当日订单净利润 ${reportDailyProfitAmount(day.profit,day.knownProfit,true)} − 麦麦代收净额 ¥${yuan(day.ownerNetReceipts)} = ${day.amount===null?'待核算':'¥'+yuan(day.amount)}`;
}
function reportOwnershipCurrentAccountHTML(business){
if(business.member==='owner')return '';
const account=business.currentAccount,days=reportCurrentAccountDays(business);
return `<section class="report-business-settlement report-business-current" aria-label="${e(business.name)}当日往来账"><h3>当日往来账</h3><p class="small muted">${account.from===account.date?'仅核对所选单日。':'按所选范围逐日核对,不将月合计当作日金额。'}普通订单按开单日、锁价成单按交付日、售后按记录日归集;锁价代收按实际收付日。此处不含历史余额,也未扣实际转账。</p>${days.map(day=>`<div class="report-current-day" data-date="${e(day.date)}"><header><h4>${e(day.date)}</h4><span>${e(reportCurrentAccountDirection(business,day))}</span>${day.amount===null?'<strong class="danger-text">待核算</strong>':`<strong>¥${yuan(Math.abs(day.amount))}</strong>`}</header><p class="report-business-balance-equation">${e(reportCurrentAccountFormula(day))}</p>${day.incomplete?'<p class="small danger-text">成本或利润尚未补齐,暂不显示完整应转金额;预估未付项目不计垫付。</p>':''}</div>`).join('')||'<p class="small muted">所选范围暂无当日往来记录。</p>'}</section>`;
}
function reportCurrentAccountText(business){
if(business.member==='owner')return [];
return ['当日往来账(逐日核对,不含历史余额,未扣实际转账)',...reportCurrentAccountDays(business).flatMap(day=>[`${day.date} / ${reportCurrentAccountDirection(business,day)}${day.amount===null?'':' ¥'+yuan(Math.abs(day.amount))}`,reportCurrentAccountFormula(day),...(day.incomplete?['成本或利润尚未补齐,暂不显示完整应转金额;预估未付项目不计垫付。']:[])])];
}
function reportOwnershipBusinessHTML(business,range){return reportOwnershipCostHTML(business)+reportOwnerAdvancesHTML(business)+reportOwnershipProfitHTML(business,range)+reportOwnershipCurrentAccountHTML(business);}
function reportOwnershipReceiptsHTML(r,range){
const keys=reportOwnershipKeys(r);
return `<section class="report-receipts report-ownership-receipts" aria-label="按订单归属汇总净收入"><p class="small muted report-receipt-scope">${e(reportPeriod(range))}:所属订单净收入=收款−退款,已包含他人代收。成本含售后,料池仅计已耗用部分;麦麦垫付明细逐日核对,历史往来在折叠区查看。</p><div class="report-recipient-grid">${keys.length?keys.map(key=>{const person=r.ownershipReceipts[key],details={...person,name:person.name+'所属订单'};return `<article class="panel report-recipient report-ownership-recipient" data-member="${e(key)}" aria-labelledby="report-ownership-${key}-title"><header class="report-recipient-summary"><h2 id="report-ownership-${key}-title">${e(person.name)}所属订单净收入</h2><div class="report-recipient-total">¥${yuan(person.net)}</div><p class="report-recipient-net"><span>实收 ¥${yuan(person.receipt)}</span><span>实退 ¥${yuan(person.refund)}</span></p></header>${person.items.length?reportOwnershipAccountsHTML(person):''}${reportOwnershipBusinessHTML(r.ownershipBusiness[key],range)}${person.items.length?reportRecipientDetailsHTML(details)+(person.items.some(item=>item.kind==='refund')?reportRecipientDetailsHTML(details,'refund'):''):'<p class="small muted report-ownership-empty">所选范围暂无收退款记录。</p>'}</article>`;}).join(''):'<div class="panel report-ownership-empty"><p class="muted">所选范围暂无所属订单收入、成本或待转记录。</p></div>'}</div></section>`;
return `<section class="report-receipts report-ownership-receipts" aria-label="按订单归属汇总净收入"><p class="small muted report-receipt-scope">${e(reportPeriod(range))}:所属订单净收入=收款−退款,已包含他人代收。成本含售后,料池仅计已耗用部分;麦麦垫付和当日往来逐日核对。</p><div class="report-recipient-grid">${keys.length?keys.map(key=>{const person=r.ownershipReceipts[key],details={...person,name:person.name+'所属订单'};return `<article class="panel report-recipient report-ownership-recipient" data-member="${e(key)}" aria-labelledby="report-ownership-${key}-title"><header class="report-recipient-summary"><h2 id="report-ownership-${key}-title">${e(person.name)}所属订单净收入</h2><div class="report-recipient-total">¥${yuan(person.net)}</div><p class="report-recipient-net"><span>实收 ¥${yuan(person.receipt)}</span><span>实退 ¥${yuan(person.refund)}</span></p></header>${person.items.length?reportOwnershipAccountsHTML(person):''}${reportOwnershipBusinessHTML(r.ownershipBusiness[key],range)}${person.items.length?reportRecipientDetailsHTML(details)+(person.items.some(item=>item.kind==='refund')?reportRecipientDetailsHTML(details,'refund'):''):'<p class="small muted report-ownership-empty">所选范围暂无收退款记录。</p>'}</article>`;}).join(''):'<div class="panel report-ownership-empty"><p class="muted">所选范围暂无所属订单收入、成本或当日往来记录。</p></div>'}</div></section>`;
}
function reportOwnershipBusinessText(business){
const settlement=business.settlement;
return [`所属订单总成本:${reportBusinessAmount(business.totalCost,business.knownTotalCost)};本人付款 ${reportBusinessAmount(business.selfCost,business.knownSelfCost)};他人付款 ${reportBusinessAmount(business.otherCost,business.knownOtherCost)}`,...reportPoolMaterialText(business),...reportOwnerAdvancesText(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||''];
return [`所属订单总成本:${reportBusinessAmount(business.totalCost,business.knownTotalCost)};本人付款 ${reportBusinessAmount(business.selfCost,business.knownSelfCost)};他人付款 ${reportBusinessAmount(business.otherCost,business.knownOtherCost)}`,...reportPoolMaterialText(business),...reportOwnerAdvancesText(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),...reportCurrentAccountText(business)];
}
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?'本人收款':'他人代收'} / ${accountDisplayName(account.account)}:实收 ¥${yuan(account.receipt)},实退 ¥${yuan(account.refund)},净额 ¥${yuan(account.net)}`),...reportOwnershipBusinessText(r.ownershipBusiness[key]),''];})];
@@ -1605,6 +1616,7 @@ function validateOwnershipBusiness(r){
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);
validateOwnerAdvances(b,fail);
validateCurrentAccount(b,r.ownershipReceipts[member],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();
@@ -1614,6 +1626,26 @@ function validateOwnershipBusiness(r){
if(settlement.available&&['dueOut','dueIn'].some(key=>settlement.counterparts.reduce((total,row)=>total+row[key],0)!==settlement[key]))fail();
}
}
function validateCurrentAccount(b,income,fail){
const account=b.currentAccount,money=Number.isSafeInteger,count=value=>money(value)&&value>=0,nullable=value=>value===null||money(value);
if(!account||account.basis!=='orderDate'||account.from!==b.from||account.date!==b.date||!Array.isArray(account.days))fail();
const ownerAccounts=new Set(income.accounts.filter(row=>row.recipient==='owner').map(row=>row.account)),received=new Map();
for(const item of income.items){
const date=item.price_lock_id?item.date:item.order_date;
if(!date||date<b.from||date>b.date)continue;
if(ownerAccounts.has(item.account))received.set(date,(received.get(date)||0)+(item.kind==='receipt'?item.amount:-item.amount));
}
const seen=new Set();let previous='';
for(const day of account.days){
if(!day||!validOrderDate(day.date)||day.date<b.from||day.date>b.date||day.date<=previous||!['recordCount','missingCostCount','pendingCostCount','unknownProfitCount'].every(key=>count(day[key]))||!['knownMaterialCost','knownOtherCost','knownProfit','ownerNetReceipts','knownAmount'].every(key=>money(day[key]))||!['materialCost','otherCost','profit','amount'].every(key=>nullable(day[key]))||typeof day.incomplete!=='boolean')fail();
if(day.materialCost!==null&&day.materialCost!==day.knownMaterialCost||day.otherCost!==null&&day.otherCost!==day.knownOtherCost||day.profit!==(day.unknownProfitCount?null:day.knownProfit)||day.knownAmount!==day.knownMaterialCost+day.knownOtherCost+day.knownProfit-day.ownerNetReceipts||day.amount!==(day.incomplete?null:day.knownAmount)||(day.missingCostCount||day.pendingCostCount||day.unknownProfitCount)&&!day.incomplete||day.ownerNetReceipts!==(received.get(day.date)||0))fail();
const advance=b.ownerAdvances.days.find(row=>row.date===day.date),items=advance?.items||[],recorded=items.filter(item=>item.status==='recorded');
const material=rows=>rows.filter(item=>item.component==='material'),other=rows=>rows.filter(item=>item.component!=='material'),sum=rows=>rows.reduce((total,item)=>total+item.amount,0),missing=items.filter(item=>item.status==='missing');
if(day.knownMaterialCost!==sum(material(recorded))||day.knownOtherCost!==sum(other(recorded))||day.materialCost!==(material(missing).length?null:day.knownMaterialCost)||day.otherCost!==(other(missing).length?null:day.knownOtherCost)||day.missingCostCount!==(advance?.missingCount||0)||day.pendingCostCount!==(advance?.pendingCount||0))fail();
seen.add(day.date);previous=day.date;
}
if([...received.keys(),...b.ownerAdvances.days.map(day=>day.date)].some(date=>!seen.has(date))||account.days.reduce((sum,day)=>sum+day.knownProfit,0)!==b.knownProfit||account.days.reduce((sum,day)=>sum+day.unknownProfitCount,0)!==b.unknownProfitCount||account.days.reduce((sum,day)=>sum+day.recordCount,0)!==b.recordCount||account.days.some(day=>day.incomplete)!==b.incomplete)fail();
}
async function renderReport(){
if(!reportDateInitialized){reportDate=reportDate||state.today;reportDateInitialized=true;}
invalidateReport();const request=reportRequest,user=state.user.id||state.user.name;let range;
@@ -1645,7 +1677,7 @@ function renderReportContent(r,range){
const close=r.close,closeStatus=reportMonth?'月汇总显示月初至所选日的订单与售后;单日核对快照请取消“汇总当月”后保存。':close?`${close.date} 已由${close.actor}保存快照。${close.stale?(close.staleReason||'之后有补录,请重新核对。'):'快照保留,不等于支付平台账单已核实。'}`:'尚未保存所选日对账快照(含当日售后)。';
body.setAttribute('aria-busy','false');
body.innerHTML=`${reportOwnershipReceiptsHTML(r,range)}<div class="order-people-strip report-people-strip">${peopleCountHTML(r.peopleCount)}</div><div class="cards report-cards">${card('所选'+(reportMonth?'月':'日')+'销售净额',e(reportSummaryAmount(s,'sale')),e(countHints))}${card('本期实收','¥'+yuan(receipts.receipt),'普通订单累计收款+本期锁价实收')}${card('本期实退','¥'+yuan(receipts.refund),'普通订单累计退款+本期锁价实退')}${card('本期净利润'+(profitMissing?'(已核算部分)':''),e(reportSummaryAmount(s,'profit')),profitMissing?profitMissing+' 单利润待补齐'+(r.pendingMaterialCount?',其中 '+r.pendingMaterialCount+' 单料费待补':''):'销售净额 − 订单耗用成本 − 实际费用(含售后)',true)}</div><div class="report-primary"><section class="panel report-accounts"><h2>按收款账户核对</h2><p class="small muted">${e(reportPeriod(range))}普通订单当前收付,加上同期锁价实际收付。</p><div class="table-wrap"><table aria-label="按收款账户核对"><thead><tr><th>账户</th><th class="number">实收</th><th class="number">实退</th><th class="number">净额</th></tr></thead><tbody>${reportActiveAccounts(r).map(a=>`<tr><td>${e(accountDisplayName(a.account))}</td><td class="number">¥${yuan(a.receipt)}</td><td class="number">¥${yuan(a.refund)}</td><td class="number">¥${yuan(a.net)}</td></tr>`).join('')||'<tr><td colspan="4" class="muted">所选范围没有收退款活动账户。</td></tr>'}</tbody><tfoot><tr><td>合计</td><td class="number">¥${yuan(receipts.receipt)}</td><td class="number">¥${yuan(receipts.refund)}</td><td class="number">¥${yuan(receipts.net)}</td></tr></tfoot></table></div><p class="small muted report-cost-note">请按这些订单的收退款记录与微信、支付宝、现金、信用卡核对;系统尚未接入支付平台账单。</p></section>${reportPayerCostsHTML(r)}</div>`;
body.insertAdjacentHTML('beforeend',priceLockActivityHTML(r.priceLockActivity)+materialPoolActivityHTML(r.materialPoolActivity)+reportOrderNetHTML(r,range)+reportGlobalHTML(r)+`<section class="panel"><div class="panel-title"><h2>需要查看 ${r.warnings.length} 项</h2><span class="small muted">截至现在所有订单,不受日期筛选</span></div>${r.warnings.length?`<ul>${r.warnings.map(w=>`<li>${w.id?`<button class="link-button" data-action="open-order" data-id="${e(w.id)}">${e(w.number)}</button> `:''}${e(w.message)}</li>`).join('')}</ul>`:'<p class="ok">系统内未发现待补成本、待退款和待复核项。实际到账仍需核对。</p>'}<div class="form-actions"><div class="small ${close?.stale?'danger-text':'muted'}">${e(closeStatus)}</div><div class="actions">${button('下载对账报告','download-report')}${state.user.role==='owner'&&!reportMonth?button('保存核对快照','close-day','primary'):''}</div></div></section>`+(teamMode()?teamHistoricalReportHTML(r):reportUnsettledHTML(r)+materialPoolGlobalSettlementHTML(r.materialPoolSettlement)));
body.insertAdjacentHTML('beforeend',priceLockActivityHTML(r.priceLockActivity)+materialPoolActivityHTML(r.materialPoolActivity)+reportOrderNetHTML(r,range)+reportGlobalHTML(r)+`<section class="panel"><div class="panel-title"><h2>需要查看 ${r.warnings.length} 项</h2><span class="small muted">截至现在所有订单,不受日期筛选</span></div>${r.warnings.length?`<ul>${r.warnings.map(w=>`<li>${w.id?`<button class="link-button" data-action="open-order" data-id="${e(w.id)}">${e(w.number)}</button> `:''}${e(w.message)}</li>`).join('')}</ul>`:'<p class="ok">系统内未发现待补成本、待退款和待复核项。实际到账仍需核对。</p>'}<div class="form-actions"><div class="small ${close?.stale?'danger-text':'muted'}">${e(closeStatus)}</div><div class="actions">${button('下载对账报告','download-report')}${state.user.role==='owner'&&!reportMonth?button('保存核对快照','close-day','primary'):''}</div></div></section>`+(teamMode()?'':reportUnsettledHTML(r)+materialPoolGlobalSettlementHTML(r.materialPoolSettlement)));
$('#report-daily-profits-content').innerHTML=reportDailyProfitsHTML(r);
}
function requireCurrentReport(){
+2 -2
View File
@@ -198,7 +198,7 @@ async function finishDailyFundsSave(url,input,result,origin=null){
}
function dailyFundsDownloadText(report){
const range={date:report.date,from:report.from,month:reportMonth},data=report.dailyFunds;
if(data?.team)return ['团队成员往来(累计)',...data.team.pairs.map(pair=>teamMemberName(pair.members[0])+' ↔ '+teamMemberName(pair.members[1])+':'+(pair.due?teamMemberName(pair.fromMember)+'转'+teamMemberName(pair.toMember)+' ¥'+yuan(pair.due):'已结清')),'历史两人结算不计入团队新债务。',''];
if(data?.team)return ['每日报销单(按报销日期归集,已批准报销不在当日订单往来重复相加)',...data.reimbursements.flatMap(row=>[`${row.date} / ${row.requester_name} / ${reimbursementStatusNames[row.status]} / 合计 ¥${yuan(row.total)}`,...row.items.map(item=>`${item.name}:¥${yuan(item.amount)}`)]),''];
if(!data||data.rangeUnsupported)return ['每天转账核对','尚未取得完整转账资料,不输出应转金额。',''];
try{validateDailyFunds(data,range);}catch{return ['每天转账核对','资料未完整返回,不输出应转金额。',''];}
const result=['每天转账核对(应转合计,未扣已转)',`麦麦实收 ¥${yuan(data.ownerReceipts.receipt)} − 实退 ¥${yuan(data.ownerReceipts.refund)} = 净收款 ¥${yuan(data.ownerReceipts.net)}`];
@@ -268,5 +268,5 @@ async function loadDailyReimbursements(){
}
function renderTeamDailyFundsHTML(entry,month,period){
const data=entry.data;
return `${entry.error?dailyFundsStatusHTML(entry.error,true):dailyFundsLoading?dailyFundsStatusHTML('正在读取成员往来与报销…'):''}<section class="panel"><div class="panel-title"><h2>成员往来</h2><span class="small muted">${e(period)}${month?' · 只读汇总':''}</span></div><p class="small muted">代收、垫付、订单实际耗用料款与已批报销按成员两两核对。利润留在店里,各自记业绩;实际付款与往来转账分别记录。</p>${data?.team?teamFundsBodyHTML(data.team,{compact:true}):'<p class="muted">正在读取团队账目…</p>'}</section><section class="panel daily-reimbursements" aria-label="每日报销单"><div class="panel-title"><h2>每日报销单</h2><div class="actions">${data?button('待复核('+data.pendingCount+')','reimbursement-open-list'):''}${data&&!month?button('新增报销单','reimbursement-new','primary'):''}</div></div><p class="small muted">每项单独指定承担人;已批准报销只读。请勿将已经计入订单、购料或其他付款记录的支出再次提交。</p>${!month?reimbursementEditorHTML(entry)+reimbursementReviewHTML(entry):''}${data?reimbursementRowsHTML(data,month):'<p class="muted">报销资料尚未读到,草稿保留。</p>'}</section>`;
return `${entry.error?dailyFundsStatusHTML(entry.error,true):dailyFundsLoading?dailyFundsStatusHTML('正在读取报销…'):''}<section class="panel daily-reimbursements" aria-label="每日报销单"><div class="panel-title"><h2>每日报销单</h2><span class="small muted">${e(period)}${month?' · 只读汇总':''}</span><div class="actions">${data?button('待复核('+data.pendingCount+')','reimbursement-open-list'):''}${data&&!month?button('新增报销单','reimbursement-new','primary'):''}</div></div><p class="small muted">每项单独指定承担人;已批准报销只读。请勿将已经计入订单、购料或其他付款记录的支出再次提交。</p>${!month?reimbursementEditorHTML(entry)+reimbursementReviewHTML(entry):''}${data?reimbursementRowsHTML(data,month):'<p class="muted">报销资料尚未读到,草稿保留。</p>'}</section>`;
}
+10 -1
View File
@@ -3,6 +3,7 @@ const test=require('node:test'),assert=require('node:assert/strict'),fs=require(
const {randomUUID}=require('node:crypto'),Calc=require('../public/calculations');
const D='2026-10-22',TODAY='2026-10-23',RID='11111111-1111-4111-8111-111111111111';
const clone=value=>JSON.parse(JSON.stringify(value));
const {currentAccount}=require('../ownership-business');
const sixItems=()=>[80,90,173,63,80,10].map((value,index)=>({name:'报销项目'+(index+1),amount:value*100}));
function claim(extra={}){return {id:RID,date:D,items:sixItems(),total:49600,note:'合成报销',status:'pending',revision:1,requester_id:'assistant',requester_name:'助理',reviewer_id:null,reviewer_name:null,reviewed:null,review_note:'',created:D+'T01:00:00Z',updated:D+'T01:00:00Z',canEdit:true,canApprove:true,...extra};}
function data(extra={}){
@@ -21,7 +22,7 @@ function reportForFunds(funds){
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}};
for(const b of Object.values(ownershipBusiness))b.ownerAdvances={basis:'orderDate',from:funds.from,date:funds.date,days:[]};
for(const b of Object.values(ownershipBusiness)){b.ownerAdvances={basis:'orderDate',from:funds.from,date:funds.date,days:[]};b.currentAccount=currentAccount([],ownershipReceipts[b.member],b.ownerAdvances,funds.from,funds.date);}
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,dailyProfits:{basis:'orderDate',date:funds.date,from:funds.from,rows:[],summary:{recordCount:0,orderCount:0,afterSaleCount:0,draftCount:0,sales:0,knownTotalCost:0,knownProfit:0,totalCost:0,profit:0,unknownCostCount:0,unknownProfitCount:0,incomplete:false}},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(/&quot;/g,'"').replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');return result;}
@@ -203,3 +204,11 @@ test('不完整返回不显示0元结论,也不允许提交',async()=>{
const value=data();value.sources.total=999;const h=harness(value);await h.load();assert.match(h.html(),/未完整返回/);assert.doesNotMatch(h.html(),/class="daily-transfer-result"/);assert.equal(h.posts().length,0);
assert.equal(h.run('currentReport.basis'),'orderDate','新区域资料缺失不能遮掉原报表');assert.match(h.nodes.get('#report-content').innerHTML,/按收款账户核对/);assert.match(h.run('dailyFundsDownloadText(currentReport).join(String.fromCharCode(10))'),/不输出应转金额/);
});
test('团队每日报销保留入口和逐项明细,移除重复累计成员面板及对应导出',()=>{
const h=harness(),funds=data({reimbursements:[claim()],pendingCount:1,team:{pairs:[{members:['owner','assistant'],due:999900,fromMember:'assistant',toMember:'owner'}]}});
h.context.__entry={key:'synthetic-team',range:{date:D,from:D,month:false},data:funds,error:''};h.context.__report={date:D,from:D,dailyFunds:funds};
const html=h.run(`renderTeamDailyFundsHTML(__entry,false,'${D}')`),text=h.run('dailyFundsDownloadText(__report).join(String.fromCharCode(10))');
assert.match(html,/每日报销单/);assert.match(html,/2026-10-22/);assert.match(html,/data-action="reimbursement-new"/);assert.match(html,/data-action="reimbursement-open-list"/);assert.match(html,/报销项目1/);assert.match(html,/¥496\.00/);
assert.doesNotMatch(html,/成员往来<\/h2>|剩余待转|累计往来|9,999\.00/);assert.match(text,/每日报销单/);assert.match(text,/待麦麦复核 \/ 合计 ¥496\.00/);assert.match(text,/报销项目1:¥80\.00/);assert.doesNotMatch(text,/团队成员往来|累计|9,999\.00/);
});
@@ -44,6 +44,12 @@ function check(report){
if(group.totalCost!==null){assert.equal(group.totalCost,group.knownTotalCost);assert.equal(group.selfCost+group.otherCost,group.totalCost);}
if(group.profit!==null){assert.notEqual(group.totalCost,null);assert.equal(group.sales-group.totalCost,group.profit);}
assert.equal(group.equation.revenue-group.sales,group.equation.basis==='netReceipts'?group.netReceipts-group.sales:0);
assert.equal(group.currentAccount.from,report.from);assert.equal(group.currentAccount.date,report.date);
assert.equal(group.currentAccount.days.reduce((sum,day)=>sum+day.knownProfit,0),group.knownProfit);
for(const day of group.currentAccount.days){
assert.ok(day.date>=report.from&&day.date<=report.date);assert.equal(day.knownAmount,day.knownMaterialCost+day.knownOtherCost+day.knownProfit-day.ownerNetReceipts);
assert.equal(day.amount,day.incomplete?null:day.knownAmount);
}
for(const pair of group.settlement.counterparts){assert.equal(pair.openingDue+pair.periodNew-pair.periodTransferred,pair.closingDue);assert.equal(pair.dueOut,Math.max(0,pair.closingDue));assert.equal(pair.dueIn,Math.max(0,-pair.closingDue));assert.notEqual(pair.member,group.member);}
if(group.settlement.available){assert.equal(group.settlement.dueOut,group.settlement.counterparts.reduce((sum,row)=>sum+row.dueOut,0));assert.equal(group.settlement.dueIn,group.settlement.counterparts.reduce((sum,row)=>sum+row.dueIn,0));}
}
@@ -192,3 +198,38 @@ test('未知池料归属不猜麦麦份额,预估未付只提示不计已垫
const zero=fixture(t);zero.after('assistant',{amount:'0'});const cancelled=zero.save('assistant');zero.voidOrder(cancelled);assert.deepEqual(check(zero.report()).ownershipBusiness.assistant.ownerAdvances.days,[]);
zero.after('assistant',{amount:'12.34',project:'合成维修'});const after=check(zero.report()).ownershipBusiness.assistant.ownerAdvances.days[0];assert.equal(after.amount,1234);assert.equal(after.items[0].kind,'afterSale');assert.equal(after.items[0].name,'合成维修');
});
test('当日往来包含本人净利润与麦麦代收,只取所选日,不受期初余额和实际已转影响',t=>{
const f=fixture(t);f.save('assistant',{lines:[line('2000','1800')]});demo(f,D2);f.transfer(D2,'assistant','owner','200');
const own=check(f.report(D2)).ownershipBusiness.assistant,day=own.currentAccount.days[0];
assert.deepEqual([day.date,day.materialCost,day.otherCost,day.profit,day.ownerNetReceipts,day.amount],[D2,0,68000,82000,20000,130000]);
assert.equal(own.settlement.dueOut,208000,'历史原余额不改变');assert.equal(day.amount,68000+82000-20000,'不能改成原团队不含利润的待转480或余额2080');
const monthly=check(f.report(D2,D)).ownershipBusiness.assistant.currentAccount;assert.deepEqual(monthly.days.map(day=>[day.date,day.amount]),[[D,200000],[D2,130000]]);
assert.deepEqual(check(f.report(D3)).ownershipBusiness.assistant.currentAccount.days,[],'空日不能带入以前的余额、利润或转账');
});
test('当日料费使用真实手填与料池耗用分摊,其他付款人成本不当作麦麦垫付,绝不叠加采购',t=>{
const f=fixture(t);f.purchase({grams:'1',total:'900',payer:'assistant'});f.purchase({grams:'2',total:'2000',payer:'owner'});
f.save('assistant',{lines:[{name:'足金池料',unit:'g',quantity:'2',pocket:'',payer:'assistant',sale:'3000',costParts:{material:'',labor:'30',accessories:'2',other:'0'},costPayers:{material:'assistant',labor:'owner'},costMaterial:{mode:'pool',poolId:D}}],fee_items:[{key:'shipping',note:'实付运费',amount:'6',payer:'owner'}]});
f.save('assistant',{payment_account:'麦麦支付宝',lines:[{name:'手填料费商品',unit:'件',quantity:'1',pocket:'',payer:'owner',sale:'1000',costParts:{material:'600',labor:'10',accessories:'2',other:'0'},costPayers:{material:'owner',labor:'assistant2'}}]});
const own=check(f.report()).ownershipBusiness.assistant,day=own.currentAccount.days[0];
assert.equal(day.materialCost,103333+60000);assert.equal(day.otherCost,3000+600+200);assert.equal(day.profit,own.profit);assert.equal(day.ownerNetReceipts,100000);
assert.equal(day.amount,day.materialCost+day.otherCost+own.profit-100000);assert.notEqual(day.materialCost,290000+60000,'未用采购不计入');assert.equal(own.ownerAdvances.days[0].knownAmount,day.materialCost+day.otherCost);
assert.deepEqual(day,check(f.report(D,D,'assistant')).ownershipBusiness.assistant.currentAccount.days[0]);
});
test('代收超过当日垫付和利润时应返款,跨日锁价收退款与交付分开逐日归集',t=>{
const f=fixture(t);f.save('assistant',{payment_account:'麦麦微信',lines:[line('100','60','assistant')]});
let day=check(f.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.materialCost,0);assert.equal(day.otherCost,0);assert.equal(day.profit,4000);assert.equal(day.ownerNetReceipts,10000);assert.equal(day.amount,-6000);
const locked=fixture(t),id=locked.lock();day=check(locked.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.materialCost,0);assert.equal(day.ownerNetReceipts,100000);assert.equal(day.amount,-100000);
locked.close();locked.deliver(id);const delivery=check(locked.report(D2)).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(delivery.materialCost,199000);assert.equal(delivery.otherCost,0);assert.equal(delivery.profit,23400);assert.equal(delivery.ownerNetReceipts,0);assert.equal(delivery.amount,222400);
const monthly=check(locked.report(D2,D)).ownershipBusiness.assistant.currentAccount.days;assert.deepEqual(monthly.map(row=>[row.date,row.ownerNetReceipts,row.amount]),[[D,100000,-100000],[D2,0,222400]]);assert.equal(check(locked.report()).close.stale,false);
});
test('当日成本待补或费用未入账时应转保持null,预估未付不计已垫付',t=>{
const f=fixture(t);f.save('assistant',{lines:[{name:'待补池料',unit:'g',quantity:'1',pocket:'',payer:'assistant',sale:'1000',costParts:{material:'',labor:'30',accessories:'0',other:'0'},costPayers:{material:'assistant',labor:'owner'},costMaterial:{mode:'pool',poolId:D}}]});
let day=check(f.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.materialCost,null);assert.equal(day.knownMaterialCost,0);assert.equal(day.otherCost,3000);assert.equal(day.profit,null);assert.equal(day.amount,null);assert.equal(day.incomplete,true);
f.purchase();day=check(f.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.materialCost,90000);assert.equal(day.profit,7000);assert.equal(day.amount,100000);
const estimated=fixture(t),id=estimated.save('assistant',{fee_items:[{key:'shipping',note:'预估运费',amount:'100',payer:'owner',status:'estimated'}]},false);estimated.action(id,'confirm');
day=check(estimated.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.knownOtherCost,0);assert.equal(day.pendingCostCount,1);assert.equal(day.profit,null);assert.equal(day.amount,null);
});
+51 -25
View File
@@ -1,6 +1,7 @@
'use strict';
const {test}=require('node:test'),assert=require('node:assert/strict'),fs=require('node:fs'),path=require('node:path'),vm=require('node:vm');
const {randomUUID}=require('node:crypto');
const {currentAccount}=require('../ownership-business');
const D='2026-10-22',NEXT='2026-10-23',user={id:'receipts-ui-user',name:'合成麦麦',role:'owner'};
const payment=(id,kind,amount,account,extra={})=>({id,kind,amount,account,date:NEXT,order_date:D,order_id:'order-'+id,price_lock_id:null,number:'XS-'+id,paper_number:'纸单-'+id,customer:'客户-'+id,reference:'',created:NEXT+'T01:00:00Z',...extra});
function ownershipPerson(member,name,items){
@@ -10,7 +11,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,ownerAdvances:extra.ownerAdvances??{basis:'orderDate',from,date,days:[]},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}}};
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,ownerAdvances:extra.ownerAdvances??advances(costByPayer.owner.knownTotalCost||costByPayer.owner.missingCount||costByPayer.owner.pendingCount?[advanceDay(date,[...(costByPayer.owner.knownTotalCost?[advanceItem('owner-paid','原订单成本',costByPayer.owner.knownTotalCost,{component:'unallocated'})]:[]),...Array.from({length:costByPayer.owner.missingCount},(_,i)=>advanceItem('missing-'+i,'成本待补',null)),...Array.from({length:costByPayer.owner.pendingCount},(_,i)=>advanceItem('pending-'+i,'费用待核对',null,{status:'pending'}))])]:[],from,date),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 emptyDailyProfits(date,from=date){return {basis:'orderDate',date,from,rows:[],summary:{recordCount:0,orderCount:0,afterSaleCount:0,draftCount:0,sales:0,knownTotalCost:0,knownProfit:0,totalCost:0,profit:0,unknownCostCount:0,unknownProfitCount:0,incomplete:false}};}
function syncBusiness(response){response.dailyProfits=emptyDailyProfits(response.date,response.from);response.ownershipBusiness=Object.fromEntries(Object.entries(response.ownershipReceipts).map(([member,person])=>[member,businessPerson(person,response.date,response.from)]));return response;}
@@ -36,16 +37,25 @@ function report(date=D,from=date,empty=false){
orderRows:[],accounts,receiptsByOrderDate:{receipt,refund,net:receipt-refund},recipientReceipts,ownershipReceipts,payerCosts:{assistant:cost('助理'),owner:cost('麦麦')},
goods:0,expense:0,customerBalance:0,settlementDue:0,inventory:[],unsettled:[],warnings:[],close:null,priceLockActivity:null,materialPoolActivity:null});
}
function attachCurrentAccounts(response){
for(const b of Object.values(response.ownershipBusiness||{})){
if(b.currentAccount||!response.ownershipReceipts?.[b.member]||!b.ownerAdvances)continue;
const rows=Array.from({length:b.recordCount},(_,index)=>({date:b.date,profit:index<b.unknownProfitCount?null:0,known:{profit:index===0?b.knownProfit:0},incomplete:index===0&&b.incomplete}));
b.currentAccount=currentAccount(rows,response.ownershipReceipts[b.member],b.ownerAdvances,b.from,b.date);
}
return response;
}
function harness(initial=report()){
attachCurrentAccounts(initial);
const nodes=new Map(),handlers={},calls=[],saved=new Map(),content={innerHTML:'',attributes:{},setAttribute(name,value){this.attributes[name]=value;},insertAdjacentHTML(position,html){assert.equal(position,'beforeend');this.innerHTML+=html;}};
for(const [selector,node] of [['#main',{innerHTML:''}],['#report-content',content],['#report-daily-profits-content',{innerHTML:''}],['#report-date',{value:D}],['#report-month',{checked:false}]])nodes.set(selector,node);
const context=vm.createContext({console,URLSearchParams,crypto:{randomUUID},setInterval(){},setTimeout(){},clearTimeout(){},
document:{addEventListener(type,fn){(handlers[type]??=[]).push(fn);},querySelector:selector=>nodes.get(selector)||null,querySelectorAll:()=>[]},window:{scrollTo(){}},
localStorage:{getItem:key=>saved.get(key)??null,setItem:(key,value)=>saved.set(key,String(value)),removeItem:key=>saved.delete(key)},
__response:initial,__user:user,__calls:calls});
__response:initial,__user:user,__calls:calls,__attachCurrentAccounts:attachCurrentAccounts});
const run=code=>vm.runInContext(code,context);
for(const file of ['price-locks-ui.js','material-pools-ui.js','team-funds-ui.js','app.js'])run(fs.readFileSync(path.join(__dirname,'../public',file),'utf8').replace(/\ninit\(\);\s*$/,''));
run(`session={user:__user};state={user:__user,today:'${NEXT}'};tab='report';reportDate='${D}';api=async function(url){__calls.push({url});return __response;};openOrder=async function(id){__calls.push({openOrder:id});};openPriceLock=async function(id){__calls.push({openPriceLock:id});};`);
run(`session={user:__user};state={user:__user,today:'${NEXT}'};tab='report';reportDate='${D}';api=async function(url){__calls.push({url});return __attachCurrentAccounts(__response);};openOrder=async function(id){__calls.push({openOrder:id});};openPriceLock=async function(id){__calls.push({openPriceLock:id});};`);
const range=(date,month=false)=>{context.__date=date;context.__month=month;run('reportDate=__date;reportMonth=__month;');nodes.get('#report-date').value=date;nodes.get('#report-month').checked=month;};
return {context,run,nodes,handlers,calls,content,range};
}
@@ -86,7 +96,7 @@ test('单号与锁价单沿用现有只读打开动作,客户和备注安全
test('老板全部成员空日显示简洁空态,只有退款时仍显示退款及负净收入',async()=>{
const h=harness(report(D,D,true));await h.run('renderReport()');const html=h.content.innerHTML;
assert.equal((html.match(/class="report-recipient-total">¥0\.00/g)||[]).length,0);
assert.match(html,/所选范围暂无所属订单收入、成本或待转记录/);assert.doesNotMatch(html,/aria-label="助理所属订单退款明细"/);
assert.match(html,/所选范围暂无所属订单收入、成本或当日往来记录/);assert.doesNotMatch(html,/aria-label="助理所属订单退款明细"/);
const response=report(D,D,true),refund=payment('only-refund','refund',100,'助理现金');response.recipientReceipts.assistant={recipient:'assistant',name:'助理',receipt:0,refund:100,net:-100,items:[refund]};response.receiptsByOrderDate={receipt:0,refund:100,net:-100};response.ownershipReceipts.assistant=ownershipPerson('assistant','助理',[refund]);response.accounts=[{account:'助理现金',receipt:0,refund:100,net:-100}];syncBusiness(response);
h.context.__response=response;await h.run('renderReport()');assert.match(h.content.innerHTML,/<header class="report-recipient-summary"><h2 id="report-ownership-assistant-title">助理所属订单净收入<\/h2><div class="report-recipient-total">¥-1\.00/);assert.match(h.content.innerHTML,/实收 ¥0\.00<\/span><span>实退 ¥1\.00/);assert.match(table(h.content.innerHTML,'助理所属订单收款逐笔明细'),/所选范围没有助理所属订单收款记录/);assert.match(table(h.content.innerHTML,'助理所属订单退款逐笔明细'),/客户-only-refund/);
});
@@ -95,8 +105,8 @@ test('切换日月立即清空旧明细,晚到响应和失败不恢复旧收
const h=harness();await h.run('renderReport()');assert.equal(h.run('requireCurrentReport().date'),D);
const pending=[];h.context.__pending=pending;h.run('api=function(url){__calls.push({url});return new Promise((resolve,reject)=>__pending.push({resolve,reject}));};');
h.range(NEXT);const first=h.run('renderReport()');assert.equal(h.run('currentReport'),null);assert.equal(h.content.attributes['aria-busy'],'true');assert.doesNotMatch(h.content.innerHTML,/收款明细|133\.45/);assert.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);
h.range(NEXT,true);const second=h.run('renderReport()'),month=report(NEXT,'2026-10-01',true);pending[1].resolve(month);await second;
assert.equal(h.run('requireCurrentReport().from'),'2026-10-01');assert.match(h.content.innerHTML,/2026-10-01 至 2026-10-23/);assert.match(h.content.innerHTML,/所选范围暂无所属订单收入、成本或待转记录/);
h.range(NEXT,true);const second=h.run('renderReport()'),month=attachCurrentAccounts(report(NEXT,'2026-10-01',true));pending[1].resolve(month);await second;
assert.equal(h.run('requireCurrentReport().from'),'2026-10-01');assert.match(h.content.innerHTML,/2026-10-01 至 2026-10-23/);assert.match(h.content.innerHTML,/所选范围暂无所属订单收入、成本或当日往来记录/);
pending[0].resolve(report(NEXT));await first;assert.equal(h.run('currentReport.from'),'2026-10-01');assert.doesNotMatch(h.content.innerHTML,/客户-a/);
const failure=h.run('renderReport()');pending[2].reject(new Error('合成网络失败'));await failure;assert.equal(h.run('currentReport'),null);assert.equal(h.content.attributes['aria-busy'],'false');assert.match(h.content.innerHTML,/合成网络失败/);assert.doesNotMatch(h.content.innerHTML,/收款明细/);assert.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);
const wrongUser=h.run('renderReport()');h.run("state={...state,user:{id:'different-user'}};");pending[3].resolve(month);await wrongUser;assert.equal(h.run('currentReport'),null);assert.doesNotMatch(h.content.innerHTML,/收款明细/);
@@ -167,34 +177,35 @@ function businessReport(){
function memberCard(html,member){const match=html.match(new RegExp('<article[^>]*data-member="'+member+'"[^>]*>([\\s\\S]*?)</article>'));assert.ok(match,'应显示 '+member+' 个人经营卡');return match[1];}
function businessHarness(response=businessReport()){const h=harness(response);h.run("state={...state,user:{...state.user,member:'owner'}};");return h;}
test('个人经营卡闭环1500收入、680麦麦付款、820利润;本期480与累计2280分别展示',async()=>{
const h=businessHarness();await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/report-recipient-total">¥1,500\.00/);assert.match(html,/所属订单总成本<\/h3><strong>¥680\.00/);assert.match(html,/本人付款 <b>¥0\.00/);assert.match(html,/他人付款 <b>¥680\.00/);assert.match(html,/麦麦 ¥680\.00/);assert.match(html,/所属订单净收入 <b>¥1,500\.00<\/b>/);assert.match(html,/订单总成本 <b>¥680\.00<\/b>/);assert.match(html,/<strong class="">¥820\.00/);
assert.match(html,/本人应转他人<\/span><strong>¥2,280\.00/);assert.match(html,/此前 本人→麦麦 ¥1,800\.00 · 本期新增 本人→麦麦 ¥480\.00/);assert.match(html,/本期实际已转 <b>¥0\.00/);assert.match(html,/截至所选日待转 <strong>¥2,280\.00/);assert.doesNotMatch(html,/本人应转他人<\/span><strong>¥680\.00/);assert.equal(h.calls.length,1);
const lines=h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))');assert.match(lines,/所属订单总成本:¥680\.00;本人付款 ¥0\.00;他人付款 ¥680\.00/);assert.match(lines,/本期利润:¥820\.00/);assert.match(lines,/此前 ¥1,800\.00 + 本期新增 ¥480\.00 − 本期实际已转 ¥0\.00 = 截至所选日 ¥2,280\.00/);
test('当日往来用680垫付加820净利润减200代收得到1300,历史2280不进入页面或导出',async()=>{
const h=businessHarness();await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/report-recipient-total">¥1,500\.00/);assert.match(html,/所属订单总成本<\/h3><strong>¥680\.00/);assert.match(html,/本人付款 <b>¥0\.00/);assert.match(html,/他人付款 <b>¥680\.00/);assert.match(html,/<strong class="">¥820\.00/);
assert.match(html,/<h3>当日往来账<\/h3>/);assert.match(html,/<h4>2026-10-22<\/h4><span>助理1应转麦麦<\/span><strong>¥1,300\.00/);assert.match(html,/麦麦垫付已用料费 ¥0\.00 + 麦麦垫付其他订单成本 ¥680\.00 + 本人当日订单净利润 ¥820\.00 − 麦麦代收净额 ¥200\.00 = ¥1,300\.00/);
assert.doesNotMatch(h.content.innerHTML,/累计往来|逐人核对待转|历史两人结算|¥2,280\.00|此前待转/);assert.equal(h.calls.length,1);
const lines=h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))');assert.match(lines,/当日往来账/);assert.match(lines,/助理1应转麦麦 ¥1,300\.00/);assert.doesNotMatch(lines,/累计往来|逐人核对待转|此前|¥2,280\.00/);
});
test('老板全部保留售后成本only、0元真实售后和纯待转卡,没有收入不漏经营活动',async()=>{
const response=businessReport();response.ownershipBusiness.owner=businessPerson(response.ownershipReceipts.owner,D,D,{hasActivity:true,recordCount:1,afterSaleCount:1,costByPayer:{assistant2:{totalCost:1200,knownTotalCost:1200}}});response.ownershipBusiness.assistant2=businessPerson(response.ownershipReceipts.assistant2,D,D,{hasActivity:true,settlement:settlement([counterpart('owner',0,-1200)])});const h=businessHarness(response);await h.run('renderReport()');const owner=memberCard(h.content.innerHTML,'owner'),helper=memberCard(h.content.innerHTML,'assistant2');assert.match(owner,/含售后 1 笔/);assert.match(owner,/助理2 ¥12\.00/);assert.match(owner,/<strong class="danger-text">¥-12\.00/);assert.doesNotMatch(owner,/<h3>本人收款<\/h3>/);assert.match(helper,/他人应转本人<\/span><strong>¥12\.00/);
test('老板全部保留真实售后和0元售后,不因历史余额生成无当日活动卡',async()=>{
const response=businessReport();response.ownershipBusiness.owner=businessPerson(response.ownershipReceipts.owner,D,D,{hasActivity:true,recordCount:1,afterSaleCount:1,costByPayer:{assistant2:{totalCost:1200,knownTotalCost:1200}}});response.ownershipBusiness.assistant2=businessPerson(response.ownershipReceipts.assistant2,D,D,{hasActivity:true,settlement:settlement([counterpart('owner',0,-1200)])});const h=businessHarness(response);await h.run('renderReport()');const owner=memberCard(h.content.innerHTML,'owner');assert.match(owner,/含售后 1 笔/);assert.match(owner,/助理2 ¥12\.00/);assert.match(owner,/<strong class="danger-text">¥-12\.00/);assert.doesNotMatch(owner,/<h3>本人收款<\/h3>|当日往来账|麦麦应转麦麦/);assert.doesNotMatch(h.content.innerHTML,/report-ownership-assistant2-title/);
response.ownershipBusiness.owner=businessPerson(response.ownershipReceipts.owner,D,D,{hasActivity:true,recordCount:1,afterSaleCount:1});await h.run('renderReport()');assert.match(memberCard(h.content.innerHTML,'owner'),/含售后 1 笔/);
});
test('现金净收与销售不同使用原销售利润式,差异说明转义,月汇总名称准确',async()=>{
const response=businessReport();response.ownershipBusiness.assistant=businessPerson(response.ownershipReceipts.assistant,D,D,{sales:170000,costByPayer:{owner:{totalCost:68000,knownTotalCost:68000}},difference:{amount:-20000,reconciled:false,reasons:[{code:'price_lock_timing',text:'锁价跨日与<原单>分开核对。'}]}});const h=businessHarness(response);await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/销售净额 <b>¥1,700\.00/);assert.match(html,/<strong class="">¥1,020\.00/);assert.match(html,/差额 ¥-200\.00/);assert.match(html,/锁价跨日与&lt;原单&gt;分开核对/);assert.doesNotMatch(html,/<原单>|<strong class="">¥820\.00/);
response.from='2026-10-01';response.dailyProfits.from=response.from;for(const b of Object.values(response.ownershipBusiness)){b.from=response.from;b.settlement.from=response.from;b.ownerAdvances.from=response.from;}h.range(D,true);await h.run('renderReport()');assert.match(memberCard(h.content.innerHTML,'assistant'),/<h3>本期利润<\/h3>/);
response.from='2026-10-01';response.dailyProfits.from=response.from;for(const b of Object.values(response.ownershipBusiness)){b.from=response.from;b.settlement.from=response.from;b.ownerAdvances.from=response.from;delete b.currentAccount;}h.range(D,true);await h.run('renderReport()');assert.match(memberCard(h.content.innerHTML,'assistant'),/<h3>本期利润<\/h3>/);
});
test('成本待补只显示已知付款和待核算,已核算利润不能冒充完整利润或结清',async()=>{
const response=businessReport();response.ownershipBusiness.assistant=businessPerson(response.ownershipReceipts.assistant,D,D,{knownProfit:82000,profit:null,costByPayer:{owner:{totalCost:null,knownTotalCost:68000,missingCount:1}},settlement:settlement([] ,D,D,{partial:true,pendingCount:1,notice:'成本待补,仅列已知往来。'})});const h=businessHarness(response);await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/已知 ¥680\.00/);assert.match(html,/成本待补齐/);assert.match(html,/report-business-profit-pending">待核算/);assert.match(html,/已知本人应转他人/);assert.match(html,/成本待补,仅列已知往来/);assert.doesNotMatch(html,/¥820\.00|已结清/);const text=h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))');assert.match(text,/本期利润:待核算/);assert.doesNotMatch(text,/本期利润:¥820\.00/);
test('成本待补保留已知垫付与已核算利润,但不输出完整应转或已结清',async()=>{
const response=businessReport();response.ownershipBusiness.assistant=businessPerson(response.ownershipReceipts.assistant,D,D,{knownProfit:82000,profit:null,costByPayer:{owner:{totalCost:null,knownTotalCost:68000,missingCount:1}},settlement:settlement([] ,D,D,{partial:true,pendingCount:1,notice:'成本待补,仅列已知往来。'})});const h=businessHarness(response);await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/已知 ¥680\.00/);assert.match(html,/成本待补齐/);assert.match(html,/report-business-profit-pending">待核算/);assert.match(html,/应转金额待核算/);assert.match(html,/本人当日订单净利润 待核算(已核算 ¥820\.00)/);assert.match(html,/暂不显示完整应转金额/);assert.doesNotMatch(html,/助理1应转麦麦|已结清/);const text=h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))');assert.match(text,/本期利润:待核算/);assert.doesNotMatch(text,/本期利润:¥820\.00|应转麦麦 ¥/);
});
test('逐人待转保留双向余额与负数转入,期初加本期减实转,不抵销成一个净数字',async()=>{
const response=businessReport();response.ownershipBusiness.assistant.settlement=settlement([counterpart('owner',-5000,8000,10000),counterpart('assistant2',10000,-3000,-2000)]);const h=businessHarness(response);await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/本人应转他人<\/span><strong>¥90\.00/);assert.match(html,/他人应转本人<\/span><strong>¥70\.00/);assert.match(html,/此前 麦麦→本人 ¥50\.00/);assert.match(html,/本期已转 助理2→本人 ¥20\.00/);assert.match(html,/本期实际已转 <b>(−¥20\.00)/);assert.match(html,/麦麦应转本人 ¥70\.00/);assert.match(html,/本人应转助理2 ¥90\.00/);assert.doesNotMatch(html,/本人应转他人<\/span><strong>¥20\.00/);
test('当日计算为负时明确麦麦转给归属人,历史双向余额和已转均不混入',async()=>{
const response=businessReport();response.ownershipBusiness.assistant=businessPerson(response.ownershipReceipts.assistant,D,D,{sales:13000,costByPayer:{owner:{totalCost:68000,knownTotalCost:68000}},settlement:settlement([counterpart('owner',-5000,8000,10000),counterpart('assistant2',10000,-3000,-2000)])});const h=businessHarness(response);await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant');assert.match(html,/麦麦应转助理1<\/span><strong>¥70\.00/);assert.match(html,/本人当日订单净利润 ¥-550\.00 − 麦麦代收净额 ¥200\.00 = ¥-70\.00/);assert.doesNotMatch(html,/逐人核对待转|此前待转|累计往来|本人应转他人/);assert.match(h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))'),/麦麦应转助理1 ¥70\.00/);
});
test('经营投影缺失、付款不平、利润等式或待转构成错误均阻止保存;历史待转不冒充0',async()=>{
const changes=[r=>delete r.ownershipBusiness,r=>r.ownershipBusiness.assistant.netReceipts++,r=>r.ownershipBusiness.assistant.knownTotalCost++,r=>r.ownershipBusiness.assistant.equation.profit++,r=>r.ownershipBusiness.assistant.settlement.counterparts[0].closingDue++,r=>delete r.ownershipBusiness.assistant.costByPayer.owner];
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|已结清/);
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,/待核对历史结算|累计往来/);assert.doesNotMatch(html,/本人应转他人<\/span><strong>¥0\.00|已结清/);
});
function advanceItem(id,name,amount,extra={}){return {date:D,kind:'order',id,number:'XS-'+id,paperNumber:'纸单-'+id,customer:'垫付客户-'+id,name,source:'合成真实成本',component:'fee',poolId:null,poolMaterial:false,allocationPending:false,amount,estimatedAmount:null,status:amount===null?'missing':'recorded',...extra};}
@@ -211,7 +222,7 @@ function poolBusinessReport(){
}
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,/所属订单总成本<\/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,/助理1应转麦麦<\/span><strong>¥397\.00/);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/);
@@ -239,7 +250,7 @@ test('同日不同锁价原均价分别显示,不合成新料价;来源不
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/);
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,/助理1应转麦麦<\/span><strong>¥397\.00/);
});
test('待补料费与未知FIFO付款人显示已知额和待补,其他已核实成本继续显示',async()=>{
@@ -268,9 +279,9 @@ test('麦麦逐笔垫付默认收起且客户可打开原单,多人池料子
const response=poolBusinessReport(),day=response.ownershipBusiness.assistant.ownerAdvances.days[0];day.items[0].customer='<img src=x>';day.items[1].name='<script>实际运费</script>';day.items[1].source='<b>付款备注</b>';
const h=businessHarness(response);await h.run('renderReport()');const card=memberCard(h.content.innerHTML,'assistant'),html=table(card,D+' 麦麦垫付明细');
assert.match(card,/<details class="report-owner-advances"[^>]*><summary>当日麦麦垫付明细<\/summary>/);assert.doesNotMatch(card,/<details[^>]*report-owner-advances[^>]*\sopen(?:\s|=|>)/);assert.match(card,/垫付小计 <strong>¥1,069\.33/);assert.match(html,/<th>日期<\/th><th>客户/单号<\/th><th>成本项目<\/th><th class="number">麦麦承担金额/);assert.match(html,/料池料费 · 麦麦垫付部分/);assert.match(html,/¥1,033\.33/);assert.doesNotMatch(html,/2\.000g|×/);assert.match(html,/&lt;img src=x&gt;/);assert.match(html,/&lt;script&gt;实际运费&lt;\/script&gt;/);assert.match(html,/&lt;b&gt;付款备注&lt;\/b&gt;/);assert.doesNotMatch(html,/<img|<script|<b>/);
assert.ok(card.indexOf('report-owner-advances')<card.indexOf('report-business-history'));assert.match(card,/<details class="report-business-settlement report-business-history"><summary>累计往来(含历史/);assert.doesNotMatch(card,/<details[^>]*report-business-history[^>]* open/);
assert.ok(card.indexOf('report-owner-advances')<card.indexOf('report-business-current'));assert.match(card,/<section class="report-business-settlement report-business-current"/);assert.doesNotMatch(card,/report-business-history|累计往来|逐人核对待转/);
const button={dataset:{action:'open-order',id:'pool'},closest(){return null;}};for(const handler of h.handlers.click)await handler({target:{closest:()=>button}});assert.deepEqual(JSON.parse(JSON.stringify(h.calls.slice(1))),[{openOrder:'pool'}]);
const text=h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))');assert.match(text,/2026-10-22 垫付小计:¥1,069\.33/);assert.match(text,/累计往来(含历史,截至 2026-10-22)/);
const text=h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))');assert.match(text,/2026-10-22 垫付小计:¥1,069\.33/);assert.match(text,/2026-10-22 \/ 助理1应转麦麦 ¥397\.00/);assert.doesNotMatch(text,/累计往来|逐人核对待转/);
});
test('月份垫付明细只列实际记录日期及各日小计,不把月合计或历史余额当每天垫付',async()=>{
@@ -281,10 +292,10 @@ test('月份垫付明细只列实际记录日期及各日小计,不把月合
const text=h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))');assert.match(text,/2026-10-21 垫付小计:¥100\.00/);assert.match(text,/2026-10-22 垫付小计:¥1,069\.33/);assert.doesNotMatch(text,/垫付小计:¥1,169\.33/);
});
test('只有历史余额的空日垫付显示0且不暗示结清,预估未付款仍不计垫付小计',async()=>{
test('只有历史余额的空日不显示历史卡,所选成员显示当日0,预估未付不计垫付',async()=>{
const response=report(D,D,true);response.ownershipBusiness.assistant.hasActivity=true;response.ownershipBusiness.assistant.settlement=settlement([counterpart('owner',50000,0)]);
const h=harness(response);await h.run('renderReport()');let card=memberCard(h.content.innerHTML,'assistant');assert.match(card,/垫付小计 <strong>¥0\.00/);assert.match(card,/当天没有已登记的麦麦垫付明细/);assert.match(card,/累计往来(含历史/);assert.doesNotMatch(card,/已结清|垫付小计 <strong>¥500\.00/);
response.ownershipBusiness.assistant.ownerAdvances=advances([advanceDay(D,[advanceItem('estimate','预估未付运费',null,{status:'pending',estimatedAmount:100000})])]);await h.run('renderReport()');card=memberCard(h.content.innerHTML,'assistant');assert.match(card,/垫付小计 <strong>¥0\.00/);assert.match(table(card,D+' 麦麦垫付明细'),/待核对(预估 ¥1,000\.00),未计垫付/);assert.match(card,/预估金额不计垫付小计/);
const h=harness(response);await h.run('renderReport()');assert.doesNotMatch(h.content.innerHTML,/report-ownership-assistant-title|累计往来/);h.run("reportMember='assistant';");await h.run('renderReport()');let card=memberCard(h.content.innerHTML,'assistant');assert.match(card,/垫付小计 <strong>¥0\.00/);assert.match(card,/当日无需转款<\/span><strong>¥0\.00/);assert.doesNotMatch(card,/已结清|¥500\.00|累计往来/);
const b=response.ownershipBusiness.assistant;b.recordCount=1;b.unknownProfitCount=1;b.profit=null;b.incomplete=true;b.equation.profit=null;b.equation.complete=false;b.ownerAdvances=advances([advanceDay(D,[advanceItem('estimate','预估未付运费',null,{status:'pending',estimatedAmount:100000})])]);delete b.currentAccount;await h.run('renderReport()');card=memberCard(h.content.innerHTML,'assistant');assert.match(card,/垫付小计 <strong>¥0\.00/);assert.match(table(card,D+' 麦麦垫付明细'),/待核对(预估 ¥1,000\.00),未计垫付/);assert.match(card,/预估金额不计垫付小计/);assert.match(card,/应转金额待核算/);
});
test('垫付明细缺失、日期越界、小计不平或付款项目错误时阻止回执和下载',async()=>{
@@ -312,3 +323,18 @@ test('每日利润缺失、越权归属、利润错误、日期越界或合计
const changes=[r=>delete r.dailyProfits,r=>r.dailyProfits.rows[0].member='assistant2',r=>r.dailyProfits.rows[0].profit++,r=>r.dailyProfits.rows[0].date='2026-10-21',r=>r.dailyProfits.summary.knownProfit++];
for(const change of changes){const response=dailyProfitReport();change(response);const h=harness(response);await h.run('renderReport()');assert.equal(h.run('currentReport'),null);assert.match(h.content.innerHTML,/每日利润表未完整返回或与当前对账金额不一致/);assert.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);}
});
test('月模式当日往来逐日列日期方向和金额,不将月利润或合计贴在某一天',async()=>{
const response=businessReport(),from='2026-10-01',prior='2026-10-21';response.from=from;response.dailyProfits.from=from;
for(const b of Object.values(response.ownershipBusiness)){b.from=from;b.ownerAdvances.from=from;b.settlement.from=from;}
const b=businessPerson(response.ownershipReceipts.assistant,D,from,{recordCount:2,orderCount:2,costByPayer:{owner:{totalCost:78000,knownTotalCost:78000}},ownerAdvances:advances([advanceDay(prior,[advanceItem('prior','昨日已付成本',10000)]),advanceDay(D,[advanceItem('today','今日已付成本',68000)])],from,D),settlement:settlement([counterpart('owner',500000,78000)],D,from)});
b.currentAccount=currentAccount([{date:prior,known:{profit:1000},profit:1000,incomplete:false},{date:D,known:{profit:71000},profit:71000,incomplete:false}],response.ownershipReceipts.assistant,b.ownerAdvances,from,D);response.ownershipBusiness.assistant=b;
const h=businessHarness(response);h.range(D,true);await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant'),section=html.slice(html.indexOf('report-business-current'));
assert.match(section,/按所选范围逐日核对/);assert.match(section,/<h4>2026-10-21<\/h4><span>助理1应转麦麦<\/span><strong>¥110\.00/);assert.match(section,/<h4>2026-10-22<\/h4><span>助理1应转麦麦<\/span><strong>¥1,190\.00/);assert.doesNotMatch(section,/<strong>¥1,300\.00|累计往来|逐人核对待转/);assert.equal((section.match(/class="report-current-day"/g)||[]).length,2);
const text=h.run('reportOwnershipReceiptsText(currentReport).join(String.fromCharCode(10))');assert.match(text,/2026-10-21 \/ 助理1应转麦麦 ¥110\.00/);assert.match(text,/2026-10-22 \/ 助理1应转麦麦 ¥1,190\.00/);
});
test('当日往来缺失、日期越界、成本分类或等式不平时不输出伪造0或允许下载',async()=>{
const changes=[b=>delete b.currentAccount,b=>b.currentAccount.days[0].date='2026-10-21',b=>b.currentAccount.days[0].amount++,b=>b.currentAccount.days[0].knownMaterialCost++,b=>b.currentAccount.days[0].ownerNetReceipts++,b=>b.currentAccount.days=[]];
for(const change of changes){const response=poolBusinessReport(),h=businessHarness(response);change(response.ownershipBusiness.assistant);h.run('api=async function(){return __response;};');await h.run('renderReport()');assert.equal(h.run('currentReport'),null);assert.match(h.content.innerHTML,/所属订单成本、利润或待转资料未完整返回/);assert.doesNotMatch(h.content.innerHTML,/report-business-current/);assert.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);}
});