Merge pull request 'Also handle transactions without category' (#51) from transactions_without_category into master
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #51
This commit is contained in:
commit
4563fcbbaf
@ -19,7 +19,7 @@ SELECT COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id),
|
|||||||
COALESCE(tra.amount, 0)::decimal(12,2) as transactions
|
COALESCE(tra.amount, 0)::decimal(12,2) as transactions
|
||||||
FROM assignments_by_month as ass
|
FROM assignments_by_month as ass
|
||||||
FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
|
FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
|
||||||
WHERE (ass.budget_id IS NULL OR ass.budget_id = $1) AND (tra.budget_id IS NULL OR tra.budget_id = $1)
|
WHERE COALESCE(ass.budget_id, tra.budget_id) = $1
|
||||||
ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.amount, tra.amount)
|
ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.amount, tra.amount)
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -4,5 +4,5 @@ SELECT COALESCE(ass.date, tra.date), COALESCE(ass.category_id, tra.category_id),
|
|||||||
COALESCE(tra.amount, 0)::decimal(12,2) as transactions
|
COALESCE(tra.amount, 0)::decimal(12,2) as transactions
|
||||||
FROM assignments_by_month as ass
|
FROM assignments_by_month as ass
|
||||||
FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
|
FULL OUTER JOIN transactions_by_month as tra ON ass.date = tra.date AND ass.category_id = tra.category_id
|
||||||
WHERE (ass.budget_id IS NULL OR ass.budget_id = @budget_id) AND (tra.budget_id IS NULL OR tra.budget_id = @budget_id)
|
WHERE COALESCE(ass.budget_id, tra.budget_id) = @budget_id
|
||||||
ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.amount, tra.amount);
|
ORDER BY COALESCE(ass.date, tra.date), COALESCE(ass.amount, tra.amount);
|
@ -34,8 +34,7 @@ WHERE t.budget_id = $1;
|
|||||||
-- name: GetTransactionsForAccount :many
|
-- name: GetTransactionsForAccount :many
|
||||||
SELECT t.*
|
SELECT t.*
|
||||||
FROM display_transactions AS t
|
FROM display_transactions AS t
|
||||||
WHERE t.account_id = $1
|
WHERE t.account_id = $1;
|
||||||
LIMIT 200;
|
|
||||||
|
|
||||||
-- name: DeleteAllTransactions :execrows
|
-- name: DeleteAllTransactions :execrows
|
||||||
DELETE FROM transactions
|
DELETE FROM transactions
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
-- +goose Up
|
||||||
|
CREATE OR REPLACE VIEW transactions_by_month AS
|
||||||
|
SELECT date_trunc('month', transactions.date)::date as date, transactions.category_id, accounts.budget_id, SUM(amount) as amount
|
||||||
|
FROM transactions
|
||||||
|
INNER JOIN accounts ON accounts.id = transactions.account_id AND accounts.on_budget
|
||||||
|
GROUP BY date_trunc('month', transactions.date), transactions.category_id, accounts.budget_id;
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
CREATE OR REPLACE VIEW transactions_by_month AS
|
||||||
|
SELECT date_trunc('month', transactions.date)::date as date, transactions.category_id, accounts.budget_id, SUM(amount) as amount
|
||||||
|
FROM transactions
|
||||||
|
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||||
|
GROUP BY date_trunc('month', transactions.date), transactions.category_id, accounts.budget_id;
|
@ -183,7 +183,6 @@ const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many
|
|||||||
SELECT t.id, t.date, t.memo, t.amount, t.group_id, t.status, t.account, t.payee_id, t.category_id, t.payee, t.category_group, t.category, t.transfer_account, t.budget_id, t.account_id
|
SELECT t.id, t.date, t.memo, t.amount, t.group_id, t.status, t.account, t.payee_id, t.category_id, t.payee, t.category_group, t.category, t.transfer_account, t.budget_id, t.account_id
|
||||||
FROM display_transactions AS t
|
FROM display_transactions AS t
|
||||||
WHERE t.account_id = $1
|
WHERE t.account_id = $1
|
||||||
LIMIT 200
|
|
||||||
`
|
`
|
||||||
|
|
||||||
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]DisplayTransaction, error) {
|
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]DisplayTransaction, error) {
|
||||||
|
@ -139,6 +139,11 @@ func (h *Handler) calculateBalances(budget postgres.Budget, month Month,
|
|||||||
categoriesWithBalance := []CategoryWithBalance{}
|
categoriesWithBalance := []CategoryWithBalance{}
|
||||||
|
|
||||||
moneyUsed := numeric.Zero()
|
moneyUsed := numeric.Zero()
|
||||||
|
categories = append(categories, postgres.GetCategoriesRow{
|
||||||
|
Group: "Income",
|
||||||
|
Name: "No Category",
|
||||||
|
ID: uuid.UUID{},
|
||||||
|
})
|
||||||
for i := range categories {
|
for i := range categories {
|
||||||
cat := &categories[i]
|
cat := &categories[i]
|
||||||
if cat.ID == budget.IncomeCategoryID {
|
if cat.ID == budget.IncomeCategoryID {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user