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

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

@@ -44,6 +44,12 @@ function check(report){
if(group.totalCost!==null){assert.equal(group.totalCost,group.knownTotalCost);assert.equal(group.selfCost+group.otherCost,group.totalCost);}
if(group.profit!==null){assert.notEqual(group.totalCost,null);assert.equal(group.sales-group.totalCost,group.profit);}
assert.equal(group.equation.revenue-group.sales,group.equation.basis==='netReceipts'?group.netReceipts-group.sales:0);
assert.equal(group.currentAccount.from,report.from);assert.equal(group.currentAccount.date,report.date);
assert.equal(group.currentAccount.days.reduce((sum,day)=>sum+day.knownProfit,0),group.knownProfit);
for(const day of group.currentAccount.days){
assert.ok(day.date>=report.from&&day.date<=report.date);assert.equal(day.knownAmount,day.knownMaterialCost+day.knownOtherCost+day.knownProfit-day.ownerNetReceipts);
assert.equal(day.amount,day.incomplete?null:day.knownAmount);
}
for(const pair of group.settlement.counterparts){assert.equal(pair.openingDue+pair.periodNew-pair.periodTransferred,pair.closingDue);assert.equal(pair.dueOut,Math.max(0,pair.closingDue));assert.equal(pair.dueIn,Math.max(0,-pair.closingDue));assert.notEqual(pair.member,group.member);}
if(group.settlement.available){assert.equal(group.settlement.dueOut,group.settlement.counterparts.reduce((sum,row)=>sum+row.dueOut,0));assert.equal(group.settlement.dueIn,group.settlement.counterparts.reduce((sum,row)=>sum+row.dueIn,0));}
}
@@ -192,3 +198,38 @@ test('未知池料归属不猜麦麦份额,预估未付只提示不计已垫
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,'合成维修');
});
test('当日往来包含本人净利润与麦麦代收,只取所选日,不受期初余额和实际已转影响',t=>{
const f=fixture(t);f.save('assistant',{lines:[line('2000','1800')]});demo(f,D2);f.transfer(D2,'assistant','owner','200');
const own=check(f.report(D2)).ownershipBusiness.assistant,day=own.currentAccount.days[0];
assert.deepEqual([day.date,day.materialCost,day.otherCost,day.profit,day.ownerNetReceipts,day.amount],[D2,0,68000,82000,20000,130000]);
assert.equal(own.settlement.dueOut,208000,'历史原余额不改变');assert.equal(day.amount,68000+82000-20000,'不能改成原团队不含利润的待转480或余额2080');
const monthly=check(f.report(D2,D)).ownershipBusiness.assistant.currentAccount;assert.deepEqual(monthly.days.map(day=>[day.date,day.amount]),[[D,200000],[D2,130000]]);
assert.deepEqual(check(f.report(D3)).ownershipBusiness.assistant.currentAccount.days,[],'空日不能带入以前的余额、利润或转账');
});
test('当日料费使用真实手填与料池耗用分摊,其他付款人成本不当作麦麦垫付,绝不叠加采购',t=>{
const f=fixture(t);f.purchase({grams:'1',total:'900',payer:'assistant'});f.purchase({grams:'2',total:'2000',payer:'owner'});
f.save('assistant',{lines:[{name:'足金池料',unit:'g',quantity:'2',pocket:'',payer:'assistant',sale:'3000',costParts:{material:'',labor:'30',accessories:'2',other:'0'},costPayers:{material:'assistant',labor:'owner'},costMaterial:{mode:'pool',poolId:D}}],fee_items:[{key:'shipping',note:'实付运费',amount:'6',payer:'owner'}]});
f.save('assistant',{payment_account:'麦麦支付宝',lines:[{name:'手填料费商品',unit:'件',quantity:'1',pocket:'',payer:'owner',sale:'1000',costParts:{material:'600',labor:'10',accessories:'2',other:'0'},costPayers:{material:'owner',labor:'assistant2'}}]});
const own=check(f.report()).ownershipBusiness.assistant,day=own.currentAccount.days[0];
assert.equal(day.materialCost,103333+60000);assert.equal(day.otherCost,3000+600+200);assert.equal(day.profit,own.profit);assert.equal(day.ownerNetReceipts,100000);
assert.equal(day.amount,day.materialCost+day.otherCost+own.profit-100000);assert.notEqual(day.materialCost,290000+60000,'未用采购不计入');assert.equal(own.ownerAdvances.days[0].knownAmount,day.materialCost+day.otherCost);
assert.deepEqual(day,check(f.report(D,D,'assistant')).ownershipBusiness.assistant.currentAccount.days[0]);
});
test('代收超过当日垫付和利润时应返款,跨日锁价收退款与交付分开逐日归集',t=>{
const f=fixture(t);f.save('assistant',{payment_account:'麦麦微信',lines:[line('100','60','assistant')]});
let day=check(f.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.materialCost,0);assert.equal(day.otherCost,0);assert.equal(day.profit,4000);assert.equal(day.ownerNetReceipts,10000);assert.equal(day.amount,-6000);
const locked=fixture(t),id=locked.lock();day=check(locked.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.materialCost,0);assert.equal(day.ownerNetReceipts,100000);assert.equal(day.amount,-100000);
locked.close();locked.deliver(id);const delivery=check(locked.report(D2)).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(delivery.materialCost,199000);assert.equal(delivery.otherCost,0);assert.equal(delivery.profit,23400);assert.equal(delivery.ownerNetReceipts,0);assert.equal(delivery.amount,222400);
const monthly=check(locked.report(D2,D)).ownershipBusiness.assistant.currentAccount.days;assert.deepEqual(monthly.map(row=>[row.date,row.ownerNetReceipts,row.amount]),[[D,100000,-100000],[D2,0,222400]]);assert.equal(check(locked.report()).close.stale,false);
});
test('当日成本待补或费用未入账时应转保持null,预估未付不计已垫付',t=>{
const f=fixture(t);f.save('assistant',{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}}]});
let day=check(f.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.materialCost,null);assert.equal(day.knownMaterialCost,0);assert.equal(day.otherCost,3000);assert.equal(day.profit,null);assert.equal(day.amount,null);assert.equal(day.incomplete,true);
f.purchase();day=check(f.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.materialCost,90000);assert.equal(day.profit,7000);assert.equal(day.amount,100000);
const estimated=fixture(t),id=estimated.save('assistant',{fee_items:[{key:'shipping',note:'预估运费',amount:'100',payer:'owner',status:'estimated'}]},false);estimated.action(id,'confirm');
day=check(estimated.report()).ownershipBusiness.assistant.currentAccount.days[0];assert.equal(day.knownOtherCost,0);assert.equal(day.pendingCostCount,1);assert.equal(day.profit,null);assert.equal(day.amount,null);
});