每日对账按当天的垫付、利润与代收计算应转金额
This commit is contained in:
1 parent
39f80fbab7
commit
1cbcdc728c
7 files changed
+192
-45
No files matched your search
@@ -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};
|
||||
Reference in new issue
Block a user