Private
Public Access
1
0

Include uncategorized spending and show all categories on dashboard

Remove CategoryId.HasValue filter so uncategorized transactions appear
in the spending breakdown. Remove Take(N) limit to show all categories.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Catherine Renelle
2026-02-15 15:42:04 -05:00
parent e2b69b41f4
commit d5c90a9197
+4 -4
View File
@@ -52,20 +52,20 @@ public class DashboardService : IDashboardService
var changePercent = lastMonthSpending == 0 ? 0 : ((thisMonthSpending - lastMonthSpending) / lastMonthSpending) * 100;
var spendingByCategory = await _db.Transactions
.Where(t => t.Account.UserId == userId && t.Date >= startOfMonth && t.Amount < 0 && !t.IsVoid && t.CategoryId.HasValue)
.Where(t => t.Account.UserId == userId && t.Date >= startOfMonth && t.Amount < 0 && !t.IsVoid)
.GroupBy(t => t.CategoryId)
.Select(g => new { CategoryId = g.Key, Total = -g.Sum(t => t.Amount) })
.OrderByDescending(x => x.Total)
.Take(5)
.ToListAsync();
var categoryIds = spendingByCategory.Where(x => x.CategoryId.HasValue).Select(x => x.CategoryId!.Value);
var categoryNames = await _db.Categories
.Where(c => spendingByCategory.Select(x => x.CategoryId).Contains(c.Id))
.Where(c => categoryIds.Contains(c.Id))
.ToDictionaryAsync(c => c.Id, c => c.Name);
var totalSpending = spendingByCategory.Sum(x => x.Total);
var topCategories = spendingByCategory.Select(x => new CategorySpending(
categoryNames.GetValueOrDefault(x.CategoryId!.Value, "Unknown"),
x.CategoryId.HasValue ? categoryNames.GetValueOrDefault(x.CategoryId.Value, "Unknown") : "Uncategorized",
x.Total,
totalSpending > 0 ? (x.Total / totalSpending) * 100 : 0,
null)).ToList();