fix: 同月多条费用被 Array.find 丢弃导致数据不完整

- plan.js/finance.js 所有 ed.find 改为 filter+forEach 聚合同月 cost/paid
- computePlanMonthly 同步修复 bd.find 和 ed.find
- 明细行(expand panel) 的双重 find 也全部聚合
- 月度视图的 else 分支同改
This commit is contained in:
mac
2026-07-17 14:03:21 +08:00
parent ec457e9d40
commit d3a7252e26
2 changed files with 53 additions and 21 deletions

View File

@@ -367,13 +367,20 @@ function renderFinance() {
expenseArr.forEach(function(e) { allMonths[e.month || ''] = true; });
var detailRows = Object.keys(allMonths).filter(function(m) {
var b = budgetArr.find(function(x) { return x.month === m; }) || {};
var exp = expenseArr.find(function(x) { return x.month === m; }) || {};
var bRev = parseFloat(b.rev || 0), bGross = parseFloat(b.gross || 0), bPay = parseFloat(b.payment || 0);
var eCost = parseFloat(exp.cost || 0), ePaid = parseFloat(exp.paid || 0);
var eCost = 0, ePaid = 0;
expenseArr.filter(function(x) { return x.month === m; }).forEach(function(e) {
eCost += parseFloat(e.cost || 0) || 0;
ePaid += parseFloat(e.paid || 0) || 0;
});
return bRev || bGross || bPay || eCost || ePaid;
}).sort().map(function(m) {
var b = budgetArr.find(function(x) { return x.month === m; }) || {};
var exp = expenseArr.find(function(x) { return x.month === m; }) || {};
var eCost = 0, ePaid = 0;
expenseArr.filter(function(x) { return x.month === m; }).forEach(function(e) {
eCost += parseFloat(e.cost || 0) || 0;
ePaid += parseFloat(e.paid || 0) || 0;
});
var bRev = parseFloat(b.rev || 0), bGross = parseFloat(b.gross || 0), bPay = parseFloat(b.payment || 0);
var eCost = parseFloat(exp.cost || 0), ePaid = parseFloat(exp.paid || 0);
var bCf = bPay - ePaid;
@@ -405,12 +412,16 @@ function renderFinance() {
rev = Math.round(rev); payment = Math.round(payment); gross = Math.round(gross); cost = Math.round(cost); paid = Math.round(paid);
} else {
const b = bd.find(x => (x.month || "") === selMonth) || {};
const e = ed.find(x => (x.month || "") === selMonth) || {};
let cost2 = 0, paid2 = 0;
ed.filter(x => (x.month || "") === selMonth).forEach(e => {
cost2 += parseFloat(e.cost || 0) || 0;
paid2 += parseFloat(e.paid || 0) || 0;
});
rev = Math.round(parseFloat(b.rev || 0) || 0);
payment = Math.round(parseFloat(b.payment || 0) || 0);
gross = Math.round(parseFloat(b.gross || 0) || 0);
cost = Math.round(parseFloat(e.cost || 0) || 0);
paid = Math.round(parseFloat(e.paid || 0) || 0);
cost = Math.round(cost2);
paid = Math.round(paid2);
}
if (!rev && !payment && !cost && !paid && !gross) return;
dataItems.push({