完善订单审批、每日对账与信用卡手续费
加入助理订单变更复核、收款人汇总、每日报销和应转金额;优化库存筛选、订单明细与连续浏览。开单身份必填,信用卡手续费按实收4‰自动计算并默认由麦麦承担,打印优惠显示在人民币大写旁。 验证:484项测试通过;独立HTTP与浏览器覆盖普通订单、锁价、修改审批、断线恢复和打印隔离。旧报表兼容,本机升级原29表295行数据保持一致。
This commit is contained in:
1 parent
27a11e9b35
commit
a506fb1228
68 files changed
+3591
-259
No files matched your search
+50
-8
@@ -2,6 +2,7 @@
|
||||
// 利润沿用订单消耗成本;锁价实际收付另按发生日核对,避免定金和料费跨日重复。
|
||||
const {createHash}=require('node:crypto');
|
||||
const Calc=require('./public/calculations');
|
||||
const DailyFunds=require('./daily-funds');
|
||||
const COST_COMPONENTS=Object.fromEntries(Object.entries(Calc.costLabels).map(([key,name])=>[name,key]));
|
||||
|
||||
function payerSummary(payer,name){return {payer,name,goods:0,paidFees:0,total:0,missingCount:0,pendingCount:0,items:[]};}
|
||||
@@ -71,7 +72,34 @@ function actualCostSummaries(ledger,book){
|
||||
return payers;
|
||||
}
|
||||
|
||||
function reportRevision(book){
|
||||
function recipientSummaries(ledger,book,payments){
|
||||
const recipients={assistant:{recipient:'assistant',name:'助理',receipt:0,refund:0,net:0,items:[]},
|
||||
owner:{recipient:'owner',name:'麦麦',receipt:0,refund:0,net:0,items:[]}};
|
||||
const accountRecipients=Object.fromEntries(['微信','支付宝','现金','信用卡'].flatMap(channel=>[
|
||||
['助理'+channel,'assistant'],['麦麦'+channel,'owner']]));
|
||||
const orders=new Map(book.rows.filter(row=>row.kind!=='afterSale').map(row=>[row.id,row])),locks=new Map();
|
||||
for(const payment of payments){
|
||||
const recipient=recipients[accountRecipients[payment.account]];
|
||||
if(!recipient||!['receipt','refund'].includes(payment.kind))continue;
|
||||
// 只补查每张锁价单的唯一身份。不要展开订单继承的全部付款,否则定金会再次计入。
|
||||
if(payment.price_lock_id&&!locks.has(payment.price_lock_id))locks.set(payment.price_lock_id,ledger.one(`
|
||||
SELECT l.final_order_id AS order_id,l.number,l.customer,l.note,o.date AS order_date,o.paper_number
|
||||
FROM price_locks l LEFT JOIN orders o ON o.id=l.final_order_id WHERE l.id=?`,payment.price_lock_id));
|
||||
const lock=locks.get(payment.price_lock_id),order=orders.get(payment.order_id);
|
||||
recipient.items.push({id:payment.id,date:payment.date,kind:payment.kind,amount:payment.amount,account:payment.account,
|
||||
order_id:payment.order_id??lock?.order_id??null,price_lock_id:payment.price_lock_id??order?.price_lock_id??null,
|
||||
order_date:payment.order_date??order?.date??lock?.order_date??null,
|
||||
number:payment.number??order?.number??lock?.number??'',paper_number:payment.paper_number??order?.paper_number??lock?.paper_number??null,
|
||||
customer:payment.customer??order?.customer??lock?.customer??'',reference:payment.reference??'',
|
||||
note:payment.note??order?.note??lock?.note??'',created:payment.created});
|
||||
// 更正冲回沿用原种类的负数,不改成退款,也不丢弃已作废单据的原始流水。
|
||||
recipient[payment.kind]+=payment.amount;
|
||||
}
|
||||
for(const recipient of Object.values(recipients))recipient.net=recipient.receipt-recipient.refund;
|
||||
return recipients;
|
||||
}
|
||||
|
||||
function reportRevision(book,dailyFundsState=null){
|
||||
// 复核、打印、库存和其他日期的账务不会改变本日的财务核对状态。
|
||||
// 新增展示用计数不改变旧快照版本;售后本身已包含在财务行和金额中。
|
||||
const {afterSaleCount,recordCount,...summary}=book.summary;
|
||||
@@ -89,6 +117,7 @@ function reportRevision(book){
|
||||
totalCost:row.totalCost,profit:row.profit,ownerCost:row.ownerCost,assistantCost:row.assistantCost,
|
||||
known:row.known,costItems:row.costItems,pendingCostItems:row.pendingCostItems,balance:row.balance}));
|
||||
const financial={basis:'orderDate',date:book.date,from:book.from,summary,rows,receipts:book.receiptsByOrderDate};
|
||||
if(dailyFundsState)financial.dailyFunds=dailyFundsState;
|
||||
if(book.priceLockActivity.summary.eventCount){
|
||||
// 只把原日不可变的收付款项目纳入版本。之后交付关联出的状态、单号和待交信息,
|
||||
// 不能让已经核对的原锁价日重新过期。没有锁价活动的旧日保持原哈希完全兼容。
|
||||
@@ -117,14 +146,28 @@ function closeState(ledger,date,revision,previous){
|
||||
staleReason:stale?(sameBasis?'开单日订单或账务有变动,请重新核对':'核对口径已更新,请重新核对'):null};
|
||||
}
|
||||
|
||||
function reportByOrderDate(ledger,date,from=date){
|
||||
function orderDatePayments(ledger,book){
|
||||
const payments=ledger.rows('SELECT e.*,o.number,o.paper_number,o.date AS order_date FROM payments e JOIN orders o ON o.id=e.order_id WHERE o.date>=? AND o.date<=? ORDER BY o.date,e.date,e.created,e.id',book.from,book.date);
|
||||
const linkedOrders=new Set(book.rows.filter(row=>row.price_lock_id).map(row=>row.id));
|
||||
return [...payments.filter(payment=>!linkedOrders.has(payment.order_id)),...book.priceLockActivity.customerCash,...book.priceLockActivity.orderPayments];
|
||||
}
|
||||
function dailyFundsReceipts(ledger,date){
|
||||
const book=ledger.orderBook({date,from:date,status:'all'}),payments=orderDatePayments(ledger,book),owner=recipientSummaries(ledger,book,payments).owner;
|
||||
return {ownerReceipts:{receipt:owner.receipt,refund:owner.refund,net:owner.net},hasActivity:payments.length>0};
|
||||
}
|
||||
function reportByOrderDate(ledger,date,from=date,actor=null,env){
|
||||
const book=ledger.orderBook({date,from,status:'all'});
|
||||
const previous=ledger.report(book.date,book.from),orderPayerCosts=costSummaries(ledger,book.rows),payerCosts=actualCostSummaries(ledger,book);
|
||||
const revision=reportRevision(book);
|
||||
const revision=reportRevision(book,DailyFunds.financialState(ledger,book.from,book.date));
|
||||
const entries=table=>ledger.rows(`SELECT e.*,o.number,o.paper_number,o.date AS order_date FROM ${table} e JOIN orders o ON o.id=e.order_id WHERE o.date>=? AND o.date<=? ORDER BY o.date,e.date,e.created,e.id`,book.from,book.date);
|
||||
const linkedOrders=new Set(book.rows.filter(row=>row.price_lock_id).map(row=>row.id));
|
||||
const pendingMaterialOrders=new Set(book.rows.filter(row=>row.materialCostPending).map(row=>row.id));
|
||||
const outlayGoods=payerCosts.owner.goods+payerCosts.assistant.goods,outlayExpense=payerCosts.owner.paidFees+payerCosts.assistant.paidFees;
|
||||
const payments=orderDatePayments(ledger,book);
|
||||
const recipientReceipts=recipientSummaries(ledger,book,payments);
|
||||
const dailyFunds=DailyFunds.report(ledger,{date:book.date,from:book.from},actor,env,day=>{
|
||||
if(book.from===book.date&&day===book.date){const owner=recipientReceipts.owner;return {ownerReceipts:{receipt:owner.receipt,refund:owner.refund,net:owner.net},hasActivity:payments.length>0};}
|
||||
return dailyFundsReceipts(ledger,day);
|
||||
},{allowLong:true});
|
||||
return {...previous,basis:'orderDate',summary:book.summary,orderRows:book.rows,payerCosts,orderPayerCosts,peopleCount:book.peopleCount,
|
||||
priceLockActivity:book.priceLockActivity,materialPoolActivity:book.materialPoolActivity,outlayGoods,outlayExpense,outlayTotal:outlayGoods+outlayExpense,
|
||||
receiptsByOrderDate:book.receiptsByOrderDate,accounts:book.receiptsByOrderDate.accounts,
|
||||
@@ -133,10 +176,9 @@ function reportByOrderDate(ledger,date,from=date){
|
||||
materialCostPending:pendingMaterialOrders.size>0,pendingMaterialCount:pendingMaterialOrders.size,
|
||||
expense:orderPayerCosts.owner.paidFees+orderPayerCosts.assistant.paidFees,totalCost:book.summary.totalCost,
|
||||
profit:book.summary.profit,delivered:book.summary.completedCount,returns:book.summary.returnedCount,
|
||||
payments:[...entries('payments').filter(payment=>!linkedOrders.has(payment.order_id)),
|
||||
...book.priceLockActivity.customerCash,...book.priceLockActivity.orderPayments],
|
||||
payments,recipientReceipts,
|
||||
settlements:entries('settlements'),journal:entries('journal').map(row=>pendingMaterialOrders.has(row.order_id)?{...row,goods:null,profit:null,materialCostPending:true}:row),
|
||||
reportRevision:revision,close:book.from===book.date?closeState(ledger,book.date,revision,previous.close):null};
|
||||
dailyFunds,reportRevision:revision,close:book.from===book.date?closeState(ledger,book.date,revision,previous.close):null};
|
||||
}
|
||||
|
||||
module.exports={reportByOrderDate};
|
||||
module.exports={reportByOrderDate,dailyFundsReceipts};
|
||||
Reference in new issue
Block a user