Skip to content

Commit f61b576

Browse files
committed
Enhance budget comparison logic to prevent double-counting of transfers
- Introduced a Set to track transaction IDs from expense transactions, ensuring transfers already counted are excluded from calculations. - Updated comments for clarity on the handling of transfer transactions, specifically regarding the exclusion of already counted transfers.
1 parent e4b0a72 commit f61b576

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/utils/dataTransform.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,18 @@ function calculateBudgetComparison(
120120
categorySpending.set(monthName, currentAmount + integerToAmount(Math.abs(t.amount)));
121121
});
122122

123+
// Create a Set of transaction IDs from expenseTransactions to avoid double-counting
124+
const expenseTransactionIds = new Set(expenseTransactions.map(t => t.id));
125+
123126
// Include transfer transactions (only expense transfers, i.e., negative amounts)
127+
// BUT exclude transfers that are already in expenseTransactions to avoid double-counting
124128
transferTransactions.forEach(t => {
125129
// Only include transfers that are expenses (negative amounts)
126130
if (t.amount >= 0) return;
127131

132+
// Skip if this transfer is already in expenseTransactions (to avoid double-counting)
133+
if (expenseTransactionIds.has(t.id)) return;
134+
128135
const date = parseISO(t.date);
129136
const monthName = MONTHS[date.getMonth()];
130137
const isOffBudget = accountOffbudgetMap.get(t.account) || false;

0 commit comments

Comments
 (0)