'use strict'; // 月度业绩只重排原订单与售后利润,不生成结算、转账或新的利润分录。 const DailyProfit=require('./daily-profit'); const {MEMBERS}=require('./team-members'); const SHARE_RATE=30; function share(profit){ if(profit===null)return null; const sign=profit<0?-1n:1n; return Number(sign*((BigInt(Math.abs(profit))*BigInt(SHARE_RATE)+50n)/100n)); } function report(ledger,query={},actor=ledger.actor,env){ if(actor?.role!=='owner')env.fail('团队账目仅麦麦账号可查看',403); const today=env.today(),month=String(query.month??today.slice(0,7)); if(!/^\d{4}-(0[1-9]|1[0-2])$/.test(month)||month<'2000-01'||month>today.slice(0,7))env.fail('请选择2000年1月至本月之间的有效月份'); const from=month+'-01',[year,number]=month.split('-').map(Number); const monthEnd=new Date(Date.UTC(year,number,0)).toISOString().slice(0,10),date=monthEnd{ const book=ledger.orderBook({from,date,status:'all'}); const rows=MEMBERS.filter(row=>row.member!=='owner').map(({member,label})=>{ const summary=DailyProfit.project(ledger,{rows:book.rows,groups:{[member]:{name:label}},from,date}).summary; const profit=summary.incomplete?null:summary.profit; return {member,name:label,...summary,profit,shareRate:SHARE_RATE,estimatedShare:share(profit)}; }); return {basis:'orderDate',month,from,date,rows}; },null); } module.exports={report};