From cbda69e827b787f716f2a2417daa53071a131ef1 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Tue, 7 Dec 2021 21:00:14 +0000 Subject: [PATCH] Handle on_budget in available balance --- postgres/categories.sql.go | 2 ++ postgres/queries/categories.sql | 2 ++ 2 files changed, 4 insertions(+) diff --git a/postgres/categories.sql.go b/postgres/categories.sql.go index 9e1c599..2606bfd 100644 --- a/postgres/categories.sql.go +++ b/postgres/categories.sql.go @@ -55,8 +55,10 @@ SELECT FROM transactions LEFT JOIN categories ON categories.id = transactions.category_id LEFT JOIN budgets ON budgets.income_category_id = categories.id + INNER JOIN accounts ON accounts.id = transactions.account_id WHERE budgets.id = $1 AND transactions.date < $2 + AND accounts.on_budget ) - ( SELECT SUM(assignments.amount) FROM assignments diff --git a/postgres/queries/categories.sql b/postgres/queries/categories.sql index fd29a98..5d86bc0 100644 --- a/postgres/queries/categories.sql +++ b/postgres/queries/categories.sql @@ -66,8 +66,10 @@ SELECT FROM transactions LEFT JOIN categories ON categories.id = transactions.category_id LEFT JOIN budgets ON budgets.income_category_id = categories.id + INNER JOIN accounts ON accounts.id = transactions.account_id WHERE budgets.id = @budget_id AND transactions.date < @from_date + AND accounts.on_budget ) - ( SELECT SUM(assignments.amount) FROM assignments