Add budgeting
This commit is contained in:
@ -90,11 +90,25 @@ 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, SUM(t_hist.amount)::decimal(12,2) as balance, SUM(t_this.amount)::decimal(12,2) as activity
|
||||
SELECT categories.id, categories.name, category_groups.name as group,
|
||||
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,
|
||||
COALESCE(
|
||||
(
|
||||
SELECT SUM(t_this.amount)
|
||||
FROM transactions t_this
|
||||
WHERE categories.id = t_this.category_id
|
||||
AND t_this.date BETWEEN $1 AND $2
|
||||
)
|
||||
, 0)::decimal(12,2) as activity
|
||||
FROM categories
|
||||
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
|
||||
INNER JOIN transactions t_hist ON categories.id = t_hist.category_id AND t_hist.date < $1
|
||||
INNER JOIN transactions t_this ON categories.id = t_this.category_id AND t_this.date >= $1 AND t_this.date < $2
|
||||
WHERE category_groups.budget_id = $3
|
||||
GROUP BY categories.id, categories.name, category_groups.name
|
||||
`
|
||||
|
Reference in New Issue
Block a user