Add available balance
This commit is contained in:
@ -43,9 +43,34 @@ SELECT categories.id, categories.name, category_groups.name as group,
|
||||
WHERE categories.id = t_this.category_id
|
||||
AND t_this.date BETWEEN @from_date AND @to_date
|
||||
)
|
||||
, 0)::decimal(12,2) as activity
|
||||
, 0)::decimal(12,2) as activity,
|
||||
COALESCE(
|
||||
(
|
||||
SELECT SUM(a_hist.amount)
|
||||
FROM assignments a_hist
|
||||
WHERE categories.id = a_hist.category_id
|
||||
AND a_hist.date BETWEEN @from_date AND @to_date
|
||||
)
|
||||
,0)::decimal(12,2) as assigned
|
||||
|
||||
FROM categories
|
||||
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
|
||||
WHERE category_groups.budget_id = @budget_id
|
||||
GROUP BY categories.id, categories.name, category_groups.name
|
||||
ORDER BY category_groups.name, categories.name;
|
||||
ORDER BY category_groups.name, categories.name;
|
||||
|
||||
-- name: GetAvailableBalance :one
|
||||
SELECT
|
||||
((
|
||||
SELECT SUM(transactions.amount)
|
||||
FROM transactions
|
||||
LEFT JOIN categories ON categories.id = transactions.category_id
|
||||
LEFT JOIN budgets ON budgets.income_category_id = categories.id
|
||||
WHERE budgets.id = @budget_id
|
||||
) - (
|
||||
SELECT SUM(assignments.amount)
|
||||
FROM assignments
|
||||
INNER JOIN categories ON categories.id = assignments.category_id
|
||||
INNER JOIN category_groups ON category_groups.id = categories.category_group_id
|
||||
WHERE category_groups.budget_id = @budget_id
|
||||
))::decimal(12,2);
|
Reference in New Issue
Block a user