diff --git a/src/pages/Home/Home.tsx b/src/pages/Home/Home.tsx index bdb0259..f7037a9 100644 --- a/src/pages/Home/Home.tsx +++ b/src/pages/Home/Home.tsx @@ -99,7 +99,7 @@ function Home() { getSettings().catch(() => null), getBudgets().catch(() => []), getStreakInfo().catch(() => null), - getTransactions({ startDate: rangeStartStr, endDate: rangeEndStr, type: 'expense', pageSize: 1000 }), // Bulk fetch + getTransactions({ startDate: rangeStartStr, endDate: rangeEndStr, pageSize: 1000 }), // Bulk fetch (All types for AI) ]); setAccounts(accountsData || []); @@ -111,30 +111,36 @@ function Home() { // In-Memory Aggregation for Daily Spend (Fixes Timezone Issues) const allRangeTx = rangeTxData?.items || []; + const expenseRangeTx = allRangeTx.filter(t => t.type === 'expense'); - // Today - const todayTxItems = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), today)); + // Today (Expense Only) + const todayTxItems = expenseRangeTx.filter(t => isSameDay(new Date(t.transactionDate), today)); setTodayTransactions(todayTxItems); setTodaySpend(calculateTotalExpense(todayTxItems)); - // Yesterday - const yesterdayTxItems = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), yesterday)); + // Yesterday (Expense Only) + const yesterdayTxItems = expenseRangeTx.filter(t => isSameDay(new Date(t.transactionDate), yesterday)); setYesterdaySpend(calculateTotalExpense(yesterdayTxItems)); - // Last Week Same Day - const lastWeekTxItems = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), lastWeekSameDay)); + // Last Week Same Day (Expense Only) + const lastWeekTxItems = expenseRangeTx.filter(t => isSameDay(new Date(t.transactionDate), lastWeekSameDay)); setLastWeekSpend(calculateTotalExpense(lastWeekTxItems)); - // Last 7 Days Array (for chart) + // Last 7 Days Array (for chart - Expense Only) const last7DaysSpendArray = []; - const weekTxList: Transaction[] = []; + const weekTxList: Transaction[] = []; // Filtered by date, contains ALL types for (let i = 6; i >= 0; i--) { const d = new Date(today); d.setDate(d.getDate() - i); - const dayTx = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), d)); - last7DaysSpendArray.push(calculateTotalExpense(dayTx)); - weekTxList.push(...dayTx); + + // Expense for chart + const dayExpenseTx = expenseRangeTx.filter(t => isSameDay(new Date(t.transactionDate), d)); + last7DaysSpendArray.push(calculateTotalExpense(dayExpenseTx)); + + // All types for AI + const dayAllTx = allRangeTx.filter(t => isSameDay(new Date(t.transactionDate), d)); + weekTxList.push(...dayAllTx); } setLast7DaysSpend(last7DaysSpendArray); setWeekTransactions(weekTxList);