From c2b9184f2cd9a451e0273e19e8020faf60a80581 Mon Sep 17 00:00:00 2001 From: jerick Date: Tue, 21 Apr 2026 10:43:00 -0400 Subject: [PATCH] Changed budget allocation --- src/app/(app)/budgets/page.tsx | 4 ++-- src/app/(app)/dashboard/page.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/(app)/budgets/page.tsx b/src/app/(app)/budgets/page.tsx index d52e5b4..67322e4 100644 --- a/src/app/(app)/budgets/page.tsx +++ b/src/app/(app)/budgets/page.tsx @@ -26,12 +26,12 @@ export default async function BudgetsPage({ searchParams }: { searchParams: Sear orderBy: { createdAt: 'asc' }, }), prisma.$queryRaw<{ budgetId: string; total: bigint }[]>` - SELECT t."budgetId", COALESCE(SUM(t."amountCents"), 0)::bigint AS total + SELECT t."budgetId", + COALESCE(SUM(CASE WHEN t.type = 'DEBIT' THEN t."amountCents" ELSE -t."amountCents" END), 0)::bigint AS total FROM "Transaction" t JOIN "Account" a ON t."accountId" = a.id WHERE a."userId" = ${userId} AND t."budgetId" IS NOT NULL - AND (a.type = 'CREDIT_CARD' OR t.type = 'DEBIT') AND t.date >= ${start} AND t.date <= ${end} GROUP BY t."budgetId" diff --git a/src/app/(app)/dashboard/page.tsx b/src/app/(app)/dashboard/page.tsx index 9adef9a..ad6668f 100644 --- a/src/app/(app)/dashboard/page.tsx +++ b/src/app/(app)/dashboard/page.tsx @@ -41,12 +41,12 @@ export default async function DashboardPage({ searchParams }: { searchParams: Se orderBy: { name: 'asc' }, }), prisma.$queryRaw<{ budgetId: string; total: bigint }[]>` - SELECT t."budgetId", COALESCE(SUM(t."amountCents"), 0)::bigint AS total + SELECT t."budgetId", + COALESCE(SUM(CASE WHEN t.type = 'DEBIT' THEN t."amountCents" ELSE -t."amountCents" END), 0)::bigint AS total FROM "Transaction" t JOIN "Account" a ON t."accountId" = a.id WHERE a."userId" = ${userId} AND t."budgetId" IS NOT NULL - AND (a.type = 'CREDIT_CARD' OR t.type = 'DEBIT') AND t.date >= ${start} AND t.date <= ${end} GROUP BY t."budgetId"