diff --git a/新账系统/ownership-business.js b/新账系统/ownership-business.js index 4456fc7..b267a42 100644 --- a/新账系统/ownership-business.js +++ b/新账系统/ownership-business.js @@ -82,6 +82,31 @@ function poolMaterialCosts(ledger,rows,group){ total.otherCosts={knownAmount:group.knownTotalCost-total.knownAmount,amount:group.draftCount||group.pendingCostCount||group.missingCostCount>total.missingCount?null:group.knownTotalCost-total.knownAmount}; return total; } +function ownerAdvances(rows,from,date){ + const days=new Map(); + for(const row of rows){ + if(row.status==='draft'||row.datedate)continue; + for(const item of [...row.costItems,...row.pendingCostItems]){ + if(item.kind==='goods'&&row.status!=='delivered')continue; + const poolMaterial=item.component==='material'&&!!item.materialPoolId,allocationPending=poolMaterial&&item.amount===null; + if((item.payer!=='owner'&&!allocationPending)||item.amount===0)continue; + if(!days.has(row.date))days.set(row.date,{date:row.date,items:[]}); + const pending=item.kind==='pending',status=pending?'pending':item.amount===null?'missing':'recorded'; + days.get(row.date).items.push({date:row.date,kind:row.kind==='afterSale'?'afterSale':'order',id:row.id, + number:row.number,paperNumber:row.paper_number??'',customer:row.customer, + name:poolMaterial?(allocationPending?'料池料费 · 麦麦份额待补':'料池料费 · 麦麦垫付部分'):item.name, + source:item.source,component:item.component,poolId:item.materialPoolId??null,poolMaterial,allocationPending, + amount:pending?null:item.amount,estimatedAmount:pending?item.amount:null,status}); + } + } + return {basis:'orderDate',from,date,days:[...days.values()].sort((a,b)=>a.date.localeCompare(b.date)).map(day=>{ + const recorded=day.items.filter(item=>item.status==='recorded'),missing=day.items.filter(item=>item.status==='missing'); + const knownAmount=sum(recorded,item=>item.amount),knownPoolAmount=sum(recorded.filter(item=>item.poolMaterial),item=>item.amount),knownOtherAmount=knownAmount-knownPoolAmount; + return {...day,knownAmount,amount:missing.length?null:knownAmount,missingCount:missing.length,pendingCount:day.items.filter(item=>item.status==='pending').length, + poolAmount:missing.some(item=>item.poolMaterial)?null:knownPoolAmount,knownPoolAmount, + otherAmount:missing.some(item=>!item.poolMaterial)?null:knownOtherAmount,knownOtherAmount}; + })}; +} 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);} @@ -103,6 +128,7 @@ function project(ledger,{rows,receipts,from,date,team}){ 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.ownerAdvances=ownerAdvances(memberRows,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}; diff --git a/新账系统/public/app.css b/新账系统/public/app.css index b868c80..d171161 100644 --- a/新账系统/public/app.css +++ b/新账系统/public/app.css @@ -65,6 +65,8 @@ input[type=number]::-webkit-inner-spin-button,input[type=number]::-webkit-outer- .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}} +.report-owner-advances{margin-top:17px;padding-top:15px;border-top:1px solid var(--border);min-width:0}.report-owner-advances>h3{font-size:13px;font-weight:550;margin:0}.report-owner-advances>p.small{font-size:11px;line-height:1.7;margin:7px 0 0}.report-owner-advance-day{margin-top:12px;padding-top:11px;border-top:1px solid var(--border)}.report-owner-advance-day>header{display:flex;align-items:baseline;flex-wrap:wrap;gap:7px 22px;font-size:12px}.report-owner-advance-day h4{font-size:13px;font-weight:550;margin:0}.report-owner-advance-day header strong{font-size:18px;color:var(--green);margin-left:9px;font-variant-numeric:tabular-nums}.report-owner-advance-day>.report-owner-advance{font-size:12px;line-height:1.8;margin:8px 0}.report-owner-advance-day>.table-wrap{margin-top:10px}.report-owner-advance-table{font-size:12px;min-width:510px}.report-owner-advance-table th,.report-owner-advance-table td{padding:10px 9px;white-space:normal;overflow-wrap:anywhere}.report-owner-advance-table th:first-child{width:100px}.report-owner-advance-table th:nth-child(2){width:25%}.report-owner-advance-table th:last-child{width:155px;text-align:right}.report-owner-advance-table small{display:block;font-size:10px;line-height:1.7;margin-top:4px}.report-owner-advance-table .link-button{font-size:12px}.report-business-history>summary{font-size:12px;color:var(--muted);font-weight:500}.report-business-history>p.small{font-size:11px;line-height:1.7}@media(max-width:650px){.report-owner-advance-table{min-width:430px;font-size:11px}.report-owner-advance-table th,.report-owner-advance-table td{padding:8px 6px}.report-owner-advance-table th:first-child{width:86px}.report-owner-advance-table th:last-child{width:120px}} + /* 售后只登记实际费用,与销售订单同表查看。 */ #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}} diff --git a/新账系统/public/app.js b/新账系统/public/app.js index 74c9e92..75d4b4c 100644 --- a/新账系统/public/app.js +++ b/新账系统/public/app.js @@ -1426,21 +1426,35 @@ function reportBusinessAmount(value,known){return (value===null?'已知 ':'')+' 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 reportOwnerAdvanceAmount(value,known){return value===null?'待补(已知 ¥'+yuan(known)+')':'¥'+yuan(value);} +function reportOwnerAdvanceFormula(business,day){ + return `${business.member==='owner'?'麦麦付款合计':'麦麦垫付合计'}:料池料费 ${reportOwnerAdvanceAmount(day.poolAmount,day.knownPoolAmount)} + 其他成本 ${reportOwnerAdvanceAmount(day.otherAmount,day.knownOtherAmount)} = ${reportOwnerAdvanceAmount(day.amount,day.knownAmount)}`; +} +function reportOwnerAdvanceItemAmount(item){ + if(item.status==='pending')return '待核对'+(item.estimatedAmount===null?'(金额待补)':'(预估 ¥'+yuan(item.estimatedAmount)+')')+',未计垫付'; + return item.amount===null?'待补齐':'¥'+yuan(item.amount); +} +function reportOwnerAdvanceIdentity(item){ + return item.kind==='order'?`${e(item.paperNumber||item.number)}`:`${e(item.customer||'未填客户')}售后记录`; +} +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 `

${single?'当日':'按日核对'}${label}

按所属订单开单日、售后记录日归集;仅列所选日期,不累计历史垫付。垫付与扣除代收、转账后的净往来分别核对。

${days.map(day=>`

${e(day.date)}

${day.missingCount?'已知':''}${business.member==='owner'?'付款':'垫付'}小计 ${e(reportOwnerAdvanceAmount(day.amount,day.knownAmount))}
${day.items.some(item=>item.poolMaterial)?`

${e(reportOwnerAdvanceFormula(business,day))}

`:''}${day.items.length?`
${day.items.map(item=>``).join('')}
日期客户/单号成本项目麦麦承担金额
${e(item.date)}${reportOwnerAdvanceIdentity(item)}${e(item.name)}${item.source?`${e(item.source)}`:''}${e(reportOwnerAdvanceItemAmount(item))}
`:'

当天没有已登记的'+(business.member==='owner'?'麦麦付款':'麦麦垫付')+'明细。

'}${day.pendingCount?'

待核对项目尚未入账,预估金额不计垫付小计。

':''}
`).join('')||'

所选月份暂无已登记的'+label+'。

'}
`; +} +function reportOwnerAdvancesText(business){ + const advances=business.ownerAdvances,label=business.member==='owner'?'麦麦付款明细':'麦麦垫付明细'; + return [label+'(按所属订单开单日/售后记录日逐日核对,不累计历史;预估未付不计实付)',...(advances.days.length?advances.days.flatMap(day=>[`${day.date} ${business.member==='owner'?'付款':'垫付'}小计:${reportOwnerAdvanceAmount(day.amount,day.knownAmount)}`,...(day.items.some(item=>item.poolMaterial)?[reportOwnerAdvanceFormula(business,day)]:[]),...day.items.map(item=>`${item.date} / ${item.customer||'未填客户'} / ${item.paperNumber||item.number} / ${item.name} / ${reportOwnerAdvanceItemAmount(item)}`)]):[advances.from===advances.date?advances.date+' 当日已登记垫付 ¥0.00,无明细。':'所选月份暂无已登记明细。'])]; } function reportPoolMaterialHTML(business){ const pool=business.poolMaterial;if(!pool?.days.length)return ''; - const owner=pool.byPayer.owner,ownerAdvance=reportOwnerPoolAdvance(business); - return `
料池已用料费${e(reportBusinessAmount(pool.amount,pool.knownAmount))}${pool.missingCount?'料费待补':''}

其中麦麦垫付 ${e(reportBusinessAmount(owner.amount,owner.knownAmount))}

其他成本 ${e(reportBusinessAmount(pool.otherCosts.amount,pool.otherCosts.knownAmount))}(其余商品成本、工费与费用)

${ownerAdvance?`

${e(ownerAdvance)}

`:''}

料费已计入总成本,已记入待转的部分不再另加。按未四舍五入均价逐单核算,显示料价相乘可能有分币差。${pool.hasPriceLocks?'锁价料费按原预留与回料日期记往来,交付日不再加一次。':''}

`; + const owner=pool.byPayer.owner; + return `
料池已用料费${e(reportBusinessAmount(pool.amount,pool.knownAmount))}${pool.missingCount?'料费待补':''}

其中麦麦垫付 ${e(reportBusinessAmount(owner.amount,owner.knownAmount))}

其他成本 ${e(reportBusinessAmount(pool.otherCosts.amount,pool.otherCosts.knownAmount))}(其余商品成本、工费与费用)

料费已计入总成本,已记入待转的部分不再另加。按未四舍五入均价逐单核算,显示料价相乘可能有分币差。${pool.hasPriceLocks?'锁价料费按原预留与回料日期记往来,交付日不再加一次。':''}

`; } 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?['锁价料费按原预留与回料日期记往来,交付日不再加一次。']:[])]; + const owner=pool.byPayer.owner; + return [`料池已用料费:${reportBusinessAmount(pool.amount,pool.knownAmount)}(已计入总成本,已记入待转的部分不再另加)`,...pool.days.map(day=>`${day.date} 料池:${reportPoolMaterialFormula(day)}`),`其中麦麦垫付:${reportBusinessAmount(owner.amount,owner.knownAmount)}`,`其他成本:${reportBusinessAmount(pool.otherCosts.amount,pool.otherCosts.knownAmount)}(其余商品成本、工费与费用)`,'料费按未四舍五入均价逐单核算,显示料价相乘可能有分币差。',...(pool.hasPriceLocks?['锁价料费按原预留与回料日期记往来,交付日不再加一次。']:[])]; } 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); @@ -1455,16 +1469,16 @@ function reportSettlementTerm(value){return value<0?'(−¥'+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 `

截至 ${e(settlement.date)} 待转

${settlement.available?`
${settlement.partial?'已知':''}本人应转他人¥${yuan(settlement.dueOut)}
${settlement.partial?'已知':''}他人应转本人¥${yuan(settlement.dueIn)}
${rows.length?`
${rows.map(row=>`

此前 ${e(reportSettlementDirection(row.name,row.openingDue))} · 本期新增 ${e(reportSettlementDirection(row.name,row.periodNew))}${row.periodTransferred?' · 本期已转 '+e(reportSettlementDirection(row.name,row.periodTransferred)):''}

`).join('')}
逐人核对待转(${rows.length} 人)${rows.map(row=>`

${e(reportCounterpartDirection(row))}

正数为本人应转${e(row.name)},负数为${e(row.name)}应转本人。

此前待转 ${reportSettlementTerm(row.openingDue)}本期新增往来 ${reportSettlementTerm(row.periodNew)}本期实际已转 ${reportSettlementTerm(row.periodTransferred)}截至所选日待转 ${reportSettlementTerm(row.closingDue)}

${row.offset?`

累计双向往来已抵扣 ¥${yuan(row.offset)},已计入上方余额。

`:''}
`).join('')}
`:''}`:'

待核对历史结算,暂不显示待转金额。

'}${settlement.notice&&(settlement.partial||!settlement.available)?`

${e(settlement.notice)}

`:''}
`; + return `
累计往来(含历史,截至 ${e(settlement.date)})

这里包含历史余额,与上方当日垫付小计不同;实际转账和代收仍按原团队账目核对。

${settlement.available?`
${settlement.partial?'已知':''}本人应转他人¥${yuan(settlement.dueOut)}
${settlement.partial?'已知':''}他人应转本人¥${yuan(settlement.dueIn)}
${rows.length?`
${rows.map(row=>`

此前 ${e(reportSettlementDirection(row.name,row.openingDue))} · 本期新增 ${e(reportSettlementDirection(row.name,row.periodNew))}${row.periodTransferred?' · 本期已转 '+e(reportSettlementDirection(row.name,row.periodTransferred)):''}

`).join('')}
逐人核对待转(${rows.length} 人)${rows.map(row=>`

${e(reportCounterpartDirection(row))}

正数为本人应转${e(row.name)},负数为${e(row.name)}应转本人。

此前待转 ${reportSettlementTerm(row.openingDue)}本期新增往来 ${reportSettlementTerm(row.periodNew)}本期实际已转 ${reportSettlementTerm(row.periodTransferred)}截至所选日待转 ${reportSettlementTerm(row.closingDue)}

${row.offset?`

累计双向往来已抵扣 ¥${yuan(row.offset)},已计入上方余额。

`:''}
`).join('')}
`:''}`:'

待核对历史结算,暂不显示待转金额。

'}${settlement.notice&&(settlement.partial||!settlement.available)?`

${e(settlement.notice)}

`:''}
`; } -function reportOwnershipBusinessHTML(business,range){return reportOwnershipCostHTML(business)+reportOwnershipProfitHTML(business,range)+reportOwnershipSettlementHTML(business);} +function reportOwnershipBusinessHTML(business,range){return reportOwnershipCostHTML(business)+reportOwnerAdvancesHTML(business)+reportOwnershipProfitHTML(business,range)+reportOwnershipSettlementHTML(business);} function reportOwnershipReceiptsHTML(r,range){ const keys=reportOwnershipKeys(r); - return `

${e(reportPeriod(range))}:所属订单净收入=收款−退款,已包含他人代收。成本含售后,料池仅计已耗用部分;待转按截至所选日的累计往来核对。

${keys.length?keys.map(key=>{const person=r.ownershipReceipts[key],details={...person,name:person.name+'所属订单'};return `

${e(person.name)}所属订单净收入

¥${yuan(person.net)}

实收 ¥${yuan(person.receipt)}实退 ¥${yuan(person.refund)}

${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'):''):'

所选范围暂无收退款记录。

'}
`;}).join(''):'

所选范围暂无所属订单收入、成本或待转记录。

'}
`; + return `

${e(reportPeriod(range))}:所属订单净收入=收款−退款,已包含他人代收。成本含售后,料池仅计已耗用部分;麦麦垫付明细逐日核对,历史往来在折叠区查看。

${keys.length?keys.map(key=>{const person=r.ownershipReceipts[key],details={...person,name:person.name+'所属订单'};return `

${e(person.name)}所属订单净收入

¥${yuan(person.net)}

实收 ¥${yuan(person.receipt)}实退 ¥${yuan(person.refund)}

${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'):''):'

所选范围暂无收退款记录。

'}
`;}).join(''):'

所选范围暂无所属订单收入、成本或待转记录。

'}
`; } 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),...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),`累计往来(含历史,截至 ${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]),''];})]; @@ -1524,6 +1538,22 @@ function validatePoolMaterialCosts(b,fail){ } 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 validateOwnerAdvances(b,fail){ + const count=value=>Number.isSafeInteger(value)&&value>=0,nullable=value=>value===null||count(value),advances=b.ownerAdvances; + if(!advances||advances.basis!=='orderDate'||advances.from!==b.from||advances.date!==b.date||!Array.isArray(advances.days))fail(); + let previous='',knownTotal=0; + for(const day of advances.days){ + if(!day||typeof day.date!=='string'||day.dateb.date||day.date<=previous||!/^\d{4}-\d{2}-\d{2}$/.test(day.date)||!Array.isArray(day.items)||!day.items.length||!['knownAmount','missingCount','pendingCount','knownPoolAmount','knownOtherAmount'].every(key=>count(day[key]))||!['amount','poolAmount','otherAmount'].every(key=>nullable(day[key])))fail(); + for(const item of day.items){ + if(!item||item.date!==day.date||!['order','afterSale'].includes(item.kind)||!['id','number','paperNumber','customer','name','source','component'].every(key=>typeof item[key]==='string')||!item.id||!item.name||typeof item.poolMaterial!=='boolean'||typeof item.allocationPending!=='boolean'||item.poolMaterial!==(item.poolId!==null)||item.poolId!==null&&!/^\d{4}-\d{2}-\d{2}$/.test(item.poolId)||!['recorded','missing','pending'].includes(item.status)||!nullable(item.amount)||!nullable(item.estimatedAmount))fail(); + if(item.status==='recorded'?(item.amount===null||item.amount<=0||item.estimatedAmount!==null||item.allocationPending):(item.amount!==null||item.status==='missing'&&item.estimatedAmount!==null||item.allocationPending&&(!item.poolMaterial||item.status!=='missing')))fail(); + } + const recorded=day.items.filter(item=>item.status==='recorded'),missing=day.items.filter(item=>item.status==='missing'),total=rows=>rows.reduce((sum,item)=>sum+item.amount,0),poolMissing=missing.some(item=>item.poolMaterial),otherMissing=missing.some(item=>!item.poolMaterial); + if(day.knownAmount!==total(recorded)||day.knownPoolAmount!==total(recorded.filter(item=>item.poolMaterial))||day.knownOtherAmount!==day.knownAmount-day.knownPoolAmount||day.missingCount!==missing.length||day.pendingCount!==day.items.filter(item=>item.status==='pending').length||day.amount!==(missing.length?null:day.knownAmount)||day.poolAmount!==(poolMissing?null:day.knownPoolAmount)||day.otherAmount!==(otherMissing?null:day.knownOtherAmount))fail(); + previous=day.date;knownTotal+=day.knownAmount; + } + if(knownTotal>b.costByPayer.owner.knownTotalCost)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(); @@ -1534,6 +1564,7 @@ function validateOwnershipBusiness(r){ 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); + validateOwnerAdvances(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(); diff --git a/新账系统/test/daily-funds-ui.test.js b/新账系统/test/daily-funds-ui.test.js index 1b268f5..04b3a61 100644 --- a/新账系统/test/daily-funds-ui.test.js +++ b/新账系统/test/daily-funds-ui.test.js @@ -21,6 +21,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:[]}; 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;} diff --git a/新账系统/test/ownership-business.test.js b/新账系统/test/ownership-business.test.js index 92ab87c..5d4738b 100644 --- a/新账系统/test/ownership-business.test.js +++ b/新账系统/test/ownership-business.test.js @@ -165,3 +165,30 @@ test('新增个人经营展示不改变旧字段、原hash和核对状态,读 for(const key of Object.keys(stored).filter(key=>key!=='close'))assert.deepEqual(JSON.parse(JSON.stringify(current[key])),stored[key],key+'原返回值保持不变'); assert.deepEqual(f.report(),current);f.report(D,D,'assistant');f.report(D,D,'assistant2');f.report(D3,D);f.report(D3);assert.equal(f.ledger.one('SELECT total_changes() AS count').count,changes);assert.equal(contents(f.ledger),before); }); + +test('麦麦垫付逐笔只列所选日所属订单和原分摊金额,昨日垫付与另一助理客户不混入',t=>{ + const f=fixture(t);f.purchase();const yesterday=f.save('assistant',{customer:'昨日垫付客户',lines:[line('100','60')]}); + const pooled=f.save('assistant',{date:D2,customer:'本日池料客户',lines:[{name:'足金合成挂件',unit:'g',quantity:'3',pocket:'',payer:'assistant',sale:'3000',costParts:{material:'',labor:'30',accessories:'5',other:'0'},costPayers:{material:'owner',labor:'owner'},costMaterial:{mode:'pool',poolId:D}}],fee_items:[{key:'shipping',note:'本日实付运费',amount:'6',payer:'owner'}]}); + const manual=f.save('assistant',{date:D2,customer:'本日配件客户',lines:[line('100','10')]});f.save('assistant2',{date:D2,customer:'另一助理秘密客户',payment_account:'助理2微信',lines:[line('1000','700')]}); + const report=check(f.report(D2,D2,'assistant')),own=report.ownershipBusiness.assistant,advances=own.ownerAdvances,day=advances.days[0]; + assert.deepEqual(advances.days.map(row=>row.date),[D2]);assert.equal(day.amount,274600);assert.equal(day.poolAmount,270000);assert.equal(day.otherAmount,4600);assert.equal(day.items.length,4);assert.deepEqual([...new Set(day.items.map(row=>row.id))].sort(),[pooled,manual].sort()); + const material=day.items.find(row=>row.poolMaterial);assert.equal(material.date,D2);assert.equal(material.poolId,D);assert.equal(material.name,'料池料费 · 麦麦垫付部分');assert.equal(material.amount,270000);assert.ok(!Object.hasOwn(material,'calculation'),'付款子行不携带整商品克重乘均价的误导公式'); + assert.ok(!JSON.stringify(advances).includes(yesterday));assert.ok(!JSON.stringify(advances).includes('另一助理'));assert.equal(own.settlement.dueOut,280600,'团队原累计余额继续保留,不能当成本日垫付');assert.deepEqual(advances,f.report(D2,D2,'owner','assistant').ownershipBusiness.assistant.ownerAdvances); + f.action(pooled,'return',{date:D3,reason:'合成本日退回',returnPockets:['金料'],verified:true});const returned=check(f.report(D2,D2,'assistant')).ownershipBusiness.assistant.ownerAdvances.days[0];assert.equal(returned.amount,1600);assert.equal(returned.poolAmount,0);assert.ok(returned.items.every(row=>row.name!=='进货工费'&&!row.poolMaterial)); +}); + +test('月汇总麦麦垫付按开单日逐日展开,费用付款日仍可追溯,空日不从历史累计造垫付',t=>{ + const f=fixture(t),id=f.save('assistant',{customer:'月内第一天',lines:[line('100','60')]});f.save('assistant',{date:D2,customer:'月内第二天',lines:[line('100','70')]});f.action(id,'expense',{date:D3,amount:'5',payer:'owner',note:'跨日实际运费'}); + const before=contents(f.ledger),changes=f.ledger.one('SELECT total_changes() AS count').count,monthly=check(f.report(D2,D)).ownershipBusiness.assistant.ownerAdvances; + assert.deepEqual(monthly.days.map(day=>[day.date,day.amount]),[[D,6500],[D2,7000]]);const fee=monthly.days[0].items.find(item=>item.name==='跨日实际运费');assert.equal(fee.date,D);assert.equal(fee.source,D3);assert.equal(fee.amount,500); + assert.deepEqual(check(f.report(D3)).ownershipBusiness.assistant.ownerAdvances.days,[]);assert.equal(f.ledger.one('SELECT total_changes() AS count').count,changes);assert.equal(contents(f.ledger),before); +}); + +test('未知池料归属不猜麦麦份额,预估未付只提示不计已垫付,零元和作废成本不列明细',t=>{ + const f=fixture(t);f.save('assistant',{date:D2,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}}]}); + const pending=check(f.report(D2)).ownershipBusiness.assistant.ownerAdvances.days[0];assert.equal(pending.amount,null);assert.equal(pending.knownAmount,3000);assert.equal(pending.poolAmount,null);assert.equal(pending.otherAmount,3000);const missing=pending.items.find(item=>item.allocationPending);assert.equal(missing.amount,null);assert.equal(missing.name,'料池料费 · 麦麦份额待补'); + const other=fixture(t),old=other.save('assistant',{lines:[line('100','60')],fee_items:[{key:'shipping',note:'尚未实际付款运费',amount:'10',payer:'owner',status:'estimated'}]},false);other.action(old,'confirm'); + const estimate=check(other.report()).ownershipBusiness.assistant.ownerAdvances.days[0];assert.equal(estimate.amount,0);assert.equal(estimate.knownAmount,0);assert.equal(estimate.pendingCount,1);assert.equal(estimate.items[0].amount,null);assert.equal(estimate.items[0].estimatedAmount,1000);assert.equal(estimate.items[0].status,'pending'); + 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,'合成维修'); +}); diff --git a/新账系统/test/report-receipts-ui.test.js b/新账系统/test/report-receipts-ui.test.js index afe8fb5..e2db149 100644 --- a/新账系统/test/report-receipts-ui.test.js +++ b/新账系统/test/report-receipts-ui.test.js @@ -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,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??{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}}}; } 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){ @@ -179,7 +179,7 @@ test('老板全部保留售后成本only、0元真实售后和纯待转卡,没 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,/销售净额 ¥1,700\.00/);assert.match(html,/¥1,020\.00/);assert.match(html,/差额 ¥-200\.00/);assert.match(html,/锁价跨日与<原单>分开核对/);assert.doesNotMatch(html,/<原单>|¥820\.00/); - response.from='2026-10-01';for(const b of Object.values(response.ownershipBusiness)){b.from=response.from;b.settlement.from=response.from;}h.range(D,true);await h.run('renderReport()');assert.match(memberCard(h.content.innerHTML,'assistant'),/

本期利润<\/h3>/); + response.from='2026-10-01';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>/); }); test('成本待补只显示已知付款和待核算,已核算利润不能冒充完整利润或结清',async()=>{ @@ -196,17 +196,24 @@ test('经营投影缺失、付款不平、利润等式或待转构成错误均 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>¥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};} +function advanceDay(date,items){ + const recorded=items.filter(item=>item.status==='recorded'),missing=items.filter(item=>item.status==='missing'),sum=rows=>rows.reduce((total,item)=>total+item.amount,0),knownAmount=sum(recorded),knownPoolAmount=sum(recorded.filter(item=>item.poolMaterial)),knownOtherAmount=knownAmount-knownPoolAmount; + return {date,items:items.map(item=>({...item,date})),knownAmount,amount:missing.length?null:knownAmount,missingCount:missing.length,pendingCount:items.filter(item=>item.status==='pending').length,poolAmount:missing.some(item=>item.poolMaterial)?null:knownPoolAmount,knownPoolAmount,otherAmount:missing.some(item=>!item.poolMaterial)?null:knownOtherAmount,knownOtherAmount}; +} +function advances(days,from=D,date=D){return {basis:'orderDate',from,date,days};} 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)])}); + response.ownershipBusiness.assistant.ownerAdvances=advances([advanceDay(D,[advanceItem('pool','料池料费 · 麦麦垫付部分',103333,{component:'material',poolId:D,poolMaterial:true}),advanceItem('fee','实际工费与运费',3600)])]); return response; } test('料池用料在所属订单卡直接可见,保留原分币金额、麦麦垫付和其他成本,待转不再加一次',async()=>{ const h=businessHarness(poolBusinessReport());await h.run('renderReport()');const html=memberCard(h.content.innerHTML,'assistant'); assert.match(html,/所属订单总成本<\/h3>¥1,972\.33/);assert.match(html,/料池已用料费<\/span>¥1,933\.33/);assert.match(html,/2\.000g × ¥966\.67\/g = ¥1,933\.33/);assert.match(html,/其中麦麦垫付 ¥1,033\.33/);assert.match(html,/其他成本 ¥39\.00/);assert.match(html,/本人应转他人<\/span>¥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/); + 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/); + assert.match(text,/麦麦垫付合计:料池料费 ¥1,033\.33 + 其他成本 ¥36\.00 = ¥1,069\.33/); }); test('多日料池各列原均价与耗用额,跨日锁价说明不把交付料费当作本日新往来',async()=>{ @@ -219,11 +226,40 @@ test('待补料费与未知FIFO付款人显示已知额和待补,其他已核 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})}); + response.ownershipBusiness.assistant.ownerAdvances=advances([advanceDay(D,[advanceItem('missing-pool','料池料费 · 麦麦份额待补',null,{component:'material',poolId:D,poolMaterial:true,allocationPending:true}),advanceItem('paid-fee','实际工费与运费',3600)])]); 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,/其中麦麦垫付 已知 ¥0\.00/);assert.match(html,/其他成本 ¥39\.00/);assert.match(html,/待核算/);assert.doesNotMatch(html,/2\.000g × ¥0\.00/); - assert.match(html,/麦麦垫付合计:料费 待补(已知 ¥0\.00) + 其他成本 待补(已知 ¥36\.00) = 待补(已知 ¥36\.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>/);} }); + +test('麦麦逐笔垫付默认展开且客户可打开原单,多人池料子行只显示分摊金额,所有文字转义',async()=>{ + const response=poolBusinessReport(),day=response.ownershipBusiness.assistant.ownerAdvances.days[0];day.items[0].customer='';day.items[1].name='';day.items[1].source='付款备注'; + const h=businessHarness(response);await h.run('renderReport()');const card=memberCard(h.content.innerHTML,'assistant'),html=table(card,D+' 麦麦垫付明细'); + assert.match(card,/
]*>

当日麦麦垫付明细<\/h3>/);assert.match(card,/垫付小计 ¥1,069\.33/);assert.match(html,/日期<\/th>客户/单号<\/th>成本项目<\/th>麦麦承担金额/);assert.match(html,/料池料费 · 麦麦垫付部分/);assert.match(html,/¥1,033\.33/);assert.doesNotMatch(html,/2\.000g|×/);assert.match(html,/<img src=x>/);assert.match(html,/<script>实际运费<\/script>/);assert.match(html,/<b>付款备注<\/b>/);assert.doesNotMatch(html,//); + assert.ok(card.indexOf('report-owner-advances')累计往来(含历史/);assert.doesNotMatch(card,/]*report-business-history[^>]* open/); + 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)/); +}); + +test('月份垫付明细只列实际记录日期及各日小计,不把月合计或历史余额当每天垫付',async()=>{ + const response=poolBusinessReport(),from='2026-10-01',prior='2026-10-21',old=response.ownershipBusiness.assistant; + response.from=from;for(const b of Object.values(response.ownershipBusiness)){b.from=from;b.ownerAdvances.from=from;b.settlement.from=from;} + response.ownershipBusiness.assistant=businessPerson(response.ownershipReceipts.assistant,D,from,{costByPayer:{owner:{totalCost:116933,knownTotalCost:116933},assistant:{totalCost:90300,knownTotalCost:90300}},poolMaterial:{...old.poolMaterial,otherCosts:{amount:13900,knownAmount:13900}},ownerAdvances:advances([advanceDay(prior,[advanceItem('yesterday','昨日实际配件',10000)]),...old.ownerAdvances.days],from,D),settlement:settlement([counterpart('owner',50000,96933)],D,from)}); + const h=businessHarness(response);h.range(D,true);await h.run('renderReport()');const card=memberCard(h.content.innerHTML,'assistant');assert.match(card,/

按日核对麦麦垫付明细<\/h3>/);assert.match(card,/

2026-10-21<\/h4>垫付小计 ¥100\.00/);assert.match(card,/

2026-10-22<\/h4>垫付小计 ¥1,069\.33/);assert.doesNotMatch(card,/垫付小计 ¥1,169\.33|

2026-10-01/);assert.equal((card.match(/class="report-owner-advance-day"/g)||[]).length,2); + 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()=>{ + 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,/垫付小计 ¥0\.00/);assert.match(card,/当天没有已登记的麦麦垫付明细/);assert.match(card,/累计往来(含历史/);assert.doesNotMatch(card,/已结清|垫付小计 ¥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,/垫付小计 ¥0\.00/);assert.match(table(card,D+' 麦麦垫付明细'),/待核对(预估 ¥1,000\.00),未计垫付/);assert.match(card,/预估金额不计垫付小计/); +}); + +test('垫付明细缺失、日期越界、小计不平或付款项目错误时阻止回执和下载',async()=>{ + const changes=[r=>delete r.ownershipBusiness.assistant.ownerAdvances,r=>r.ownershipBusiness.assistant.ownerAdvances.days[0].date='2026-10-21',r=>r.ownershipBusiness.assistant.ownerAdvances.days[0].amount++,r=>r.ownershipBusiness.assistant.ownerAdvances.days[0].items[0].amount++,r=>r.ownershipBusiness.assistant.ownerAdvances.days[0].items[0].status='pending']; + 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.throws(()=>h.run('requireCurrentReport()'),/正在读取或已失效/);} +});