每日对账底部新增按归属人逐日利润表
This commit is contained in:
1 parent
d8daf90b00
commit
f4ac7502d3
8 files changed
+141
-10
No files matched your search
@@ -12,7 +12,8 @@ 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}}};
|
||||
}
|
||||
function syncBusiness(response){response.ownershipBusiness=Object.fromEntries(Object.entries(response.ownershipReceipts).map(([member,person])=>[member,businessPerson(person,response.date,response.from)]));return response;}
|
||||
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;}
|
||||
function report(date=D,from=date,empty=false){
|
||||
const items=empty?[]:[
|
||||
payment('a','receipt',12345,'助理微信'),payment('b','receipt',2000,'助理支付宝'),payment('c','receipt',-1000,'助理微信',{reference:'更正收款'}),
|
||||
@@ -37,7 +38,7 @@ function report(date=D,from=date,empty=false){
|
||||
}
|
||||
function harness(initial=report()){
|
||||
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-date',{value:D}],['#report-month',{checked:false}]])nodes.set(selector,node);
|
||||
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)},
|
||||
@@ -179,7 +180,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,/销售净额 <b>¥1,700\.00/);assert.match(html,/<strong class="">¥1,020\.00/);assert.match(html,/差额 ¥-200\.00/);assert.match(html,/锁价跨日与<原单>分开核对/);assert.doesNotMatch(html,/<原单>|<strong class="">¥820\.00/);
|
||||
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>本期利润<\/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;}h.range(D,true);await h.run('renderReport()');assert.match(memberCard(h.content.innerHTML,'assistant'),/<h3>本期利润<\/h3>/);
|
||||
});
|
||||
|
||||
test('成本待补只显示已知付款和待核算,已核算利润不能冒充完整利润或结清',async()=>{
|
||||
@@ -247,7 +248,7 @@ test('麦麦逐笔垫付默认展开且客户可打开原单,多人池料子
|
||||
|
||||
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.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;}
|
||||
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>按日核对麦麦垫付明细<\/h3>/);assert.match(card,/<h4>2026-10-21<\/h4><span>垫付小计 <strong>¥100\.00/);assert.match(card,/<h4>2026-10-22<\/h4><span>垫付小计 <strong>¥1,069\.33/);assert.doesNotMatch(card,/垫付小计 <strong>¥1,169\.33|<h4>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/);
|
||||
@@ -263,3 +264,24 @@ test('垫付明细缺失、日期越界、小计不平或付款项目错误时
|
||||
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()'),/正在读取或已失效/);}
|
||||
});
|
||||
|
||||
function dailyProfitReport(){
|
||||
const response=report(D,D,true),rows=[{date:D,member:'owner',name:'麦麦',recordCount:1,orderCount:0,afterSaleCount:1,draftCount:0,sales:0,totalCost:500,knownTotalCost:500,profit:-500,knownProfit:-500,unknownCostCount:0,unknownProfitCount:0,incomplete:false},{date:D,member:'assistant',name:'助理',recordCount:1,orderCount:1,afterSaleCount:0,draftCount:0,sales:50000,totalCost:40000,knownTotalCost:40000,profit:10000,knownProfit:10000,unknownCostCount:0,unknownProfitCount:0,incomplete:false}];
|
||||
const summary={...emptyDailyProfits(D).summary,recordCount:2,orderCount:1,afterSaleCount:1,sales:50000,totalCost:40500,knownTotalCost:40500,profit:9500,knownProfit:9500};response.dailyProfits={basis:'orderDate',from:D,date:D,rows,summary};Object.assign(response.summary,{recordCount:2,orderCount:1,completedCount:1,afterSaleCount:1,sale:50000,totalCost:40500,profit:9500});
|
||||
response.orderRows=rows.map((row,index)=>({id:'profit-'+index,date:D,member:row.member,kind:index===0?'afterSale':undefined,status:index===0?'after_sale':'delivered',number:'XS-'+index,customer:'合成利润客户',project:'合成维修',sale:row.sales,totalCost:row.totalCost,profit:row.profit,known:{sale:row.sales,totalCost:row.knownTotalCost,profit:row.knownProfit},costItems:[{kind:index===0?'afterSale':'goods',component:index===0?'fee':'unallocated',payer:row.member,amount:row.totalCost}],pendingCostItems:[]}));return response;
|
||||
}
|
||||
test('每日利润表位于资金核对之后的页面最后,列出归属、销售成本利润及合计,负数和两种下载一致',async()=>{
|
||||
const h=harness(dailyProfitReport());await h.run('renderReport()');const html=h.nodes.get('#report-daily-profits-content').innerHTML,profit=table(html,'每日利润明细'),page=h.nodes.get('#main').innerHTML;assert.ok(html.startsWith('<section class="panel report-daily-profits"'));assert.ok(page.indexOf('id="daily-funds-content"')<page.indexOf('id="report-daily-profits-content"'));assert.match(page,/<div id="report-daily-profits-content" aria-live="polite"><\/div>$/);assert.doesNotMatch(h.content.innerHTML,/每日利润表/);assert.match(html,/勾选“汇总当月”可查看当月逐日利润/);assert.match(profit,/<th scope="col">日期<\/th><th scope="col">归属人/);assert.match(profit,/data-date="2026-10-22" data-member="owner"/);assert.match(profit,/class="number danger-text">¥-5\.00/);assert.match(profit,/所选范围合计<\/td><td class="number">¥500\.00<\/td><td class="number">¥405\.00<\/td><td class="number">¥95\.00/);
|
||||
assert.match(h.run('reportDownloadText(requireCurrentReport())'),/2026-10-22 \/ 麦麦 \/ 销售净额 ¥0\.00 \/ 成本 ¥5\.00 \/ 利润 ¥-5\.00/);h.context.dailyFundsDownloadText=()=>[];assert.match(h.run('reportTeamDownloadText(requireCurrentReport())'),/每日利润表/);assert.match(h.run('reportTeamDownloadText(requireCurrentReport())'),/所选范围合计:销售净额 ¥500\.00 \/ 成本 ¥405\.00 \/ 利润 ¥95\.00/);
|
||||
});
|
||||
|
||||
test('成本和利润待补显示待核算及已核算部分,不把销售减已知成本冒充利润;空日不造业务行',async()=>{
|
||||
const response=dailyProfitReport(),row=response.dailyProfits.rows[1],summary=response.dailyProfits.summary;Object.assign(row,{totalCost:null,profit:null,knownProfit:0,unknownCostCount:1,unknownProfitCount:1,incomplete:true});Object.assign(summary,{totalCost:null,profit:null,knownProfit:-500,unknownCostCount:1,unknownProfitCount:1,incomplete:true});Object.assign(response.summary,{profit:-500,unknownCostCount:1,unknownProfitCount:1});response.orderRows[1].totalCost=null;response.orderRows[1].profit=null;response.orderRows[1].known.profit=0;
|
||||
const h=harness(response);await h.run('renderReport()');const html=table(h.nodes.get('#report-daily-profits-content').innerHTML,'每日利润明细');assert.match(html,/待补齐(已知 ¥400\.00)/);assert.match(html,/待核算(已核算 ¥0\.00)/);assert.match(html,/待核算(已核算 ¥-5\.00)/);assert.doesNotMatch(html,/利润<[^>]*>¥100\.00|¥95\.00/);
|
||||
h.context.__response=report(D,D,true);await h.run('renderReport()');const empty=table(h.nodes.get('#report-daily-profits-content').innerHTML,'每日利润明细');assert.match(empty,/所选范围暂无订单或售后记录/);assert.doesNotMatch(empty,/data-date=/);
|
||||
});
|
||||
|
||||
test('每日利润缺失、越权归属、利润错误、日期越界或合计不平会阻止保存和下载',async()=>{
|
||||
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()'),/正在读取或已失效/);}
|
||||
});
|
||||
Reference in new issue
Block a user