From 6bcf94661e8d8b55b9500d999596acaac012eaec Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Tue, 7 Dec 2021 15:33:08 +0000 Subject: [PATCH] Merge balance and balanceassignments --- postgres/categories.sql.go | 19 ++++++++----------- postgres/queries/categories.sql | 7 +++---- web/budgeting.html | 9 ++++++++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/postgres/categories.sql.go b/postgres/categories.sql.go index ce590e6..644d219 100644 --- a/postgres/categories.sql.go +++ b/postgres/categories.sql.go @@ -91,22 +91,21 @@ func (q *Queries) GetCategories(ctx context.Context, budgetID uuid.UUID) ([]GetC const getCategoriesWithBalance = `-- name: GetCategoriesWithBalance :many SELECT categories.id, categories.name, category_groups.name as group, - COALESCE( + (COALESCE( ( SELECT SUM(a_hist.amount) FROM assignments a_hist WHERE categories.id = a_hist.category_id AND a_hist.date < $1 ) - , 0)::decimal(12,2) as balance_assignments, - COALESCE( + , 0)+COALESCE( ( SELECT SUM(t_hist.amount) FROM transactions t_hist WHERE categories.id = t_hist.category_id AND t_hist.date < $1 ) - , 0)::decimal(12,2) as balance, + , 0))::decimal(12,2) as balance, COALESCE( ( SELECT SUM(t_this.amount) @@ -129,12 +128,11 @@ type GetCategoriesWithBalanceParams struct { } type GetCategoriesWithBalanceRow struct { - ID uuid.UUID - Name string - Group string - BalanceAssignments Numeric - Balance Numeric - Activity Numeric + ID uuid.UUID + Name string + Group string + Balance Numeric + Activity Numeric } func (q *Queries) GetCategoriesWithBalance(ctx context.Context, arg GetCategoriesWithBalanceParams) ([]GetCategoriesWithBalanceRow, error) { @@ -150,7 +148,6 @@ func (q *Queries) GetCategoriesWithBalance(ctx context.Context, arg GetCategorie &i.ID, &i.Name, &i.Group, - &i.BalanceAssignments, &i.Balance, &i.Activity, ); err != nil { diff --git a/postgres/queries/categories.sql b/postgres/queries/categories.sql index 7a8f9ae..85d0c7c 100644 --- a/postgres/queries/categories.sql +++ b/postgres/queries/categories.sql @@ -21,22 +21,21 @@ WHERE category_groups.budget_id = $1; -- name: GetCategoriesWithBalance :many SELECT categories.id, categories.name, category_groups.name as group, - COALESCE( + (COALESCE( ( SELECT SUM(a_hist.amount) FROM assignments a_hist WHERE categories.id = a_hist.category_id AND a_hist.date < @from_date ) - , 0)::decimal(12,2) as balance_assignments, - COALESCE( + , 0)+COALESCE( ( SELECT SUM(t_hist.amount) FROM transactions t_hist WHERE categories.id = t_hist.category_id AND t_hist.date < @from_date ) - , 0)::decimal(12,2) as balance, + , 0))::decimal(12,2) as balance, COALESCE( ( SELECT SUM(t_this.amount) diff --git a/web/budgeting.html b/web/budgeting.html index ccdb2a1..08b2b05 100644 --- a/web/budgeting.html +++ b/web/budgeting.html @@ -20,6 +20,14 @@ Next Month + + + + + + + + {{range .Categories}} @@ -29,7 +37,6 @@ {{template "amount-cell" .Balance}} - {{template "amount-cell" .BalanceAssignments}} {{template "amount-cell" .Activity}} {{end}}
GroupCategoryBalanceActivity
{{.Group}}