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

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

+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/);
});