每日对账逐日展示麦麦垫付明细,区分历史累计往来

This commit is contained in:
summer committed 2026-11-02 21:34:17 +08:00
1 parent a72f4a276e
commit d8daf90b00
6 files changed
+141 -18

No files matched your search

+26
View File
@@ -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.date<from||row.date>date)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};