diff --git a/postgres/categories.sql.go b/postgres/categories.sql.go index 2606bfd..2acf888 100644 --- a/postgres/categories.sql.go +++ b/postgres/categories.sql.go @@ -138,13 +138,13 @@ SELECT categories.id, categories.name, category_groups.name as group, WHERE categories.id = t_hist.category_id AND t_hist.date < $1 ) - , 0))::decimal(12,2) as balance, + , 0))::decimal(12,2) as available, COALESCE( ( SELECT SUM(t_this.amount) FROM transactions t_this WHERE categories.id = t_this.category_id - AND t_this.date >= $1 AND t_this.date < $2 + AND t_this.date >= $2 AND t_this.date < $1 ) , 0)::decimal(12,2) as activity, COALESCE( @@ -152,7 +152,7 @@ SELECT categories.id, categories.name, category_groups.name as group, SELECT SUM(a_hist.amount) FROM assignments a_hist WHERE categories.id = a_hist.category_id - AND a_hist.date >= $1 AND a_hist.date < $2 + AND a_hist.date >= $2 AND a_hist.date < $1 ) ,0)::decimal(12,2) as assigned @@ -164,22 +164,22 @@ ORDER BY category_groups.name, categories.name ` type GetCategoriesWithBalanceParams struct { - FromDate time.Time ToDate time.Time + FromDate time.Time BudgetID uuid.UUID } type GetCategoriesWithBalanceRow struct { - ID uuid.UUID - Name string - Group string - Balance Numeric - Activity Numeric - Assigned Numeric + ID uuid.UUID + Name string + Group string + Available Numeric + Activity Numeric + Assigned Numeric } func (q *Queries) GetCategoriesWithBalance(ctx context.Context, arg GetCategoriesWithBalanceParams) ([]GetCategoriesWithBalanceRow, error) { - rows, err := q.db.QueryContext(ctx, getCategoriesWithBalance, arg.FromDate, arg.ToDate, arg.BudgetID) + rows, err := q.db.QueryContext(ctx, getCategoriesWithBalance, arg.ToDate, arg.FromDate, arg.BudgetID) if err != nil { return nil, err } @@ -191,7 +191,7 @@ func (q *Queries) GetCategoriesWithBalance(ctx context.Context, arg GetCategorie &i.ID, &i.Name, &i.Group, - &i.Balance, + &i.Available, &i.Activity, &i.Assigned, ); err != nil { diff --git a/postgres/queries/categories.sql b/postgres/queries/categories.sql index 5d86bc0..a1d1546 100644 --- a/postgres/queries/categories.sql +++ b/postgres/queries/categories.sql @@ -26,16 +26,16 @@ SELECT categories.id, categories.name, category_groups.name as group, SELECT SUM(a_hist.amount) FROM assignments a_hist WHERE categories.id = a_hist.category_id - AND a_hist.date < @from_date + AND a_hist.date < @to_date ) , 0)+COALESCE( ( SELECT SUM(t_hist.amount) FROM transactions t_hist WHERE categories.id = t_hist.category_id - AND t_hist.date < @from_date + AND t_hist.date < @to_date ) - , 0))::decimal(12,2) as balance, + , 0))::decimal(12,2) as available, COALESCE( ( SELECT SUM(t_this.amount) diff --git a/postgres/schema/202112072148_off-budget-accounts.sql b/postgres/schema/202112072148_off-budget-accounts.sql index 148d709..ce5762f 100644 --- a/postgres/schema/202112072148_off-budget-accounts.sql +++ b/postgres/schema/202112072148_off-budget-accounts.sql @@ -1,5 +1,5 @@ -- +goose Up -ALTER TABLE accounts ADD COLUMN on_budget boolean DEFAULT 'true' NOT NULL; +ALTER TABLE accounts ADD COLUMN on_budget boolean DEFAULT TRUE NOT NULL; -- +goose Down ALTER TABLE accounts DROP COLUMN on_budget; \ No newline at end of file diff --git a/web/budgeting.html b/web/budgeting.html index b1d8911..d424499 100644 --- a/web/budgeting.html +++ b/web/budgeting.html @@ -29,8 +29,8 @@ Assigned - Balance Activity + Available {{range .Categories}} @@ -41,8 +41,8 @@ {{template "amount-cell" .Assigned}} - {{template "amount-cell" .Balance}} {{template "amount-cell" .Activity}} + {{template "amount-cell" .Available}} {{end}}