fix: 修复年度净收入计算错误 - 避免数据重复累加
问题:grandTotal 累加了 UNION ALL 的所有行数据, 包括月明细和年汇总,导致总额约为实际值的2倍。 修复:只累加 month='00' 的年度汇总数据。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
ac2d21a5a0
commit
6467048f38
@@ -101,9 +101,10 @@ router.get('/yearly-net-income', (req, res) => {
|
|||||||
let grandTotal = { total_income: 0, total_expense: 0 };
|
let grandTotal = { total_income: 0, total_expense: 0 };
|
||||||
|
|
||||||
combined.forEach(row => {
|
combined.forEach(row => {
|
||||||
|
// grandTotal 只累加年度汇总数据(month='00'),避免重复计算月明细
|
||||||
|
if (row.month === '00') {
|
||||||
grandTotal.total_income += row.total_income;
|
grandTotal.total_income += row.total_income;
|
||||||
grandTotal.total_expense += row.total_expense;
|
grandTotal.total_expense += row.total_expense;
|
||||||
if (row.month === '00') {
|
|
||||||
yearlyStats.push({
|
yearlyStats.push({
|
||||||
year: row.year,
|
year: row.year,
|
||||||
total_income: row.total_income,
|
total_income: row.total_income,
|
||||||
|
|||||||
Reference in New Issue
Block a user