From 00d4796008e873cec1150132e874d4dab27b054b Mon Sep 17 00:00:00 2001 From: jerick Date: Tue, 21 Apr 2026 16:40:03 -0400 Subject: [PATCH] Fix budget totals going negative Budget formula now sums DEBIT transactions only, matching the intended "current-month DEBIT total" behavior. Previously, CREDIT transactions (CC payments) assigned to a budget would subtract and push totals negative. Co-Authored-By: Claude Sonnet 4.6 --- src/app/(app)/budgets/page.tsx | 2 +- src/app/(app)/dashboard/page.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/(app)/budgets/page.tsx b/src/app/(app)/budgets/page.tsx index 67322e4..5aee553 100644 --- a/src/app/(app)/budgets/page.tsx +++ b/src/app/(app)/budgets/page.tsx @@ -27,7 +27,7 @@ export default async function BudgetsPage({ searchParams }: { searchParams: Sear }), prisma.$queryRaw<{ budgetId: string; total: bigint }[]>` SELECT t."budgetId", - COALESCE(SUM(CASE WHEN t.type = 'DEBIT' THEN t."amountCents" ELSE -t."amountCents" END), 0)::bigint AS total + COALESCE(SUM(CASE WHEN t.type = 'DEBIT' THEN t."amountCents" ELSE 0 END), 0)::bigint AS total FROM "Transaction" t JOIN "Account" a ON t."accountId" = a.id WHERE a."userId" = ${userId} diff --git a/src/app/(app)/dashboard/page.tsx b/src/app/(app)/dashboard/page.tsx index ed91244..1e8b56e 100644 --- a/src/app/(app)/dashboard/page.tsx +++ b/src/app/(app)/dashboard/page.tsx @@ -42,7 +42,7 @@ export default async function DashboardPage({ searchParams }: { searchParams: Se }), prisma.$queryRaw<{ budgetId: string; total: bigint }[]>` SELECT t."budgetId", - COALESCE(SUM(CASE WHEN t.type = 'DEBIT' THEN t."amountCents" ELSE -t."amountCents" END), 0)::bigint AS total + COALESCE(SUM(CASE WHEN t.type = 'DEBIT' THEN t."amountCents" ELSE 0 END), 0)::bigint AS total FROM "Transaction" t JOIN "Account" a ON t."accountId" = a.id WHERE a."userId" = ${userId}