Implement assignment import and clear of budget
This commit is contained in:
13
postgres/queries/assignments.sql
Normal file
13
postgres/queries/assignments.sql
Normal file
@ -0,0 +1,13 @@
|
||||
-- name: CreateAssignment :one
|
||||
INSERT INTO assignments (
|
||||
date, amount, category_id
|
||||
) VALUES (
|
||||
$1, $2, $3
|
||||
)
|
||||
RETURNING *;
|
||||
|
||||
-- name: DeleteAllAssignments :execrows
|
||||
DELETE FROM assignments
|
||||
USING categories
|
||||
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
|
||||
WHERE categories.id = assignments.category_id AND category_groups.budget_id = @budget_id;
|
@ -21,6 +21,14 @@ WHERE category_groups.budget_id = $1;
|
||||
|
||||
-- name: GetCategoriesWithBalance :many
|
||||
SELECT categories.id, categories.name, category_groups.name as group,
|
||||
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(
|
||||
(
|
||||
SELECT SUM(t_hist.amount)
|
||||
|
@ -26,4 +26,10 @@ LEFT JOIN categories ON categories.id = transactions.category_id
|
||||
LEFT JOIN category_groups ON category_groups.id = categories.category_group_id
|
||||
WHERE transactions.account_id = $1
|
||||
ORDER BY transactions.date DESC
|
||||
LIMIT 200;
|
||||
LIMIT 200;
|
||||
|
||||
-- name: DeleteAllTransactions :execrows
|
||||
DELETE FROM transactions
|
||||
USING accounts
|
||||
WHERE accounts.budget_id = @budget_id
|
||||
AND accounts.id = transactions.account_id;
|
Reference in New Issue
Block a user