Add query to find problematic transactions
This commit is contained in:
parent
c595f016b8
commit
43a4647d74
@ -46,3 +46,18 @@ AND accounts.id = transactions.account_id;
|
|||||||
SELECT *
|
SELECT *
|
||||||
FROM transactions_by_month
|
FROM transactions_by_month
|
||||||
WHERE transactions_by_month.budget_id = @budget_id;
|
WHERE transactions_by_month.budget_id = @budget_id;
|
||||||
|
|
||||||
|
-- name: GetProblematicTransactions :many
|
||||||
|
SELECT *
|
||||||
|
FROM transactions
|
||||||
|
LEFT JOIN accounts
|
||||||
|
ON transactions.account_id = accounts.id
|
||||||
|
LEFT JOIN transactions AS otherGroupTransaction
|
||||||
|
ON transactions.group_id = otherGroupTransaction.group_id
|
||||||
|
AND transactions.id != otherGroupTransaction.id
|
||||||
|
AND transactions.account_id != otherGroupTransaction.account_id
|
||||||
|
LEFT JOIn accounts AS otherGroupAccount
|
||||||
|
ON otherGroupTransaction.account_id = accounts.id
|
||||||
|
WHERE transactions.category_id IS NULL
|
||||||
|
AND accounts.on_budget
|
||||||
|
AND (otherGroupAccount.id IS NULL OR NOT otherGroupAccount.on_budget);
|
@ -7,6 +7,7 @@ package postgres
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
"git.javil.eu/jacob1123/budgeteer/postgres/numeric"
|
||||||
@ -117,6 +118,109 @@ func (q *Queries) GetAllTransactionsForBudget(ctx context.Context, budgetID uuid
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getProblematicTransactions = `-- name: GetProblematicTransactions :many
|
||||||
|
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.account_id, transactions.category_id, transactions.payee_id, transactions.group_id, transactions.status, accounts.id, accounts.budget_id, accounts.name, accounts.on_budget, accounts.is_open, accounts.last_reconciled, othergrouptransaction.id, othergrouptransaction.date, othergrouptransaction.memo, othergrouptransaction.amount, othergrouptransaction.account_id, othergrouptransaction.category_id, othergrouptransaction.payee_id, othergrouptransaction.group_id, othergrouptransaction.status, othergroupaccount.id, othergroupaccount.budget_id, othergroupaccount.name, othergroupaccount.on_budget, othergroupaccount.is_open, othergroupaccount.last_reconciled
|
||||||
|
FROM transactions
|
||||||
|
LEFT JOIN accounts
|
||||||
|
ON transactions.account_id = accounts.id
|
||||||
|
LEFT JOIN transactions AS otherGroupTransaction
|
||||||
|
ON transactions.group_id = otherGroupTransaction.group_id
|
||||||
|
AND transactions.id != otherGroupTransaction.id
|
||||||
|
AND transactions.account_id != otherGroupTransaction.account_id
|
||||||
|
LEFT JOIn accounts AS otherGroupAccount
|
||||||
|
ON otherGroupTransaction.account_id = accounts.id
|
||||||
|
WHERE transactions.category_id IS NULL
|
||||||
|
AND accounts.on_budget
|
||||||
|
AND (otherGroupAccount.id IS NULL OR NOT otherGroupAccount.on_budget)
|
||||||
|
`
|
||||||
|
|
||||||
|
type GetProblematicTransactionsRow struct {
|
||||||
|
ID uuid.UUID
|
||||||
|
Date time.Time
|
||||||
|
Memo string
|
||||||
|
Amount numeric.Numeric
|
||||||
|
AccountID uuid.UUID
|
||||||
|
CategoryID uuid.NullUUID
|
||||||
|
PayeeID uuid.NullUUID
|
||||||
|
GroupID uuid.NullUUID
|
||||||
|
Status TransactionStatus
|
||||||
|
ID_2 uuid.NullUUID
|
||||||
|
BudgetID uuid.NullUUID
|
||||||
|
Name sql.NullString
|
||||||
|
OnBudget sql.NullBool
|
||||||
|
IsOpen sql.NullBool
|
||||||
|
LastReconciled sql.NullTime
|
||||||
|
ID_3 uuid.UUID
|
||||||
|
Date_2 time.Time
|
||||||
|
Memo_2 string
|
||||||
|
Amount_2 numeric.Numeric
|
||||||
|
AccountID_2 uuid.UUID
|
||||||
|
CategoryID_2 uuid.NullUUID
|
||||||
|
PayeeID_2 uuid.NullUUID
|
||||||
|
GroupID_2 uuid.NullUUID
|
||||||
|
Status_2 TransactionStatus
|
||||||
|
ID_4 uuid.NullUUID
|
||||||
|
BudgetID_2 uuid.NullUUID
|
||||||
|
Name_2 sql.NullString
|
||||||
|
OnBudget_2 sql.NullBool
|
||||||
|
IsOpen_2 sql.NullBool
|
||||||
|
LastReconciled_2 sql.NullTime
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) GetProblematicTransactions(ctx context.Context) ([]GetProblematicTransactionsRow, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getProblematicTransactions)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []GetProblematicTransactionsRow
|
||||||
|
for rows.Next() {
|
||||||
|
var i GetProblematicTransactionsRow
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.Date,
|
||||||
|
&i.Memo,
|
||||||
|
&i.Amount,
|
||||||
|
&i.AccountID,
|
||||||
|
&i.CategoryID,
|
||||||
|
&i.PayeeID,
|
||||||
|
&i.GroupID,
|
||||||
|
&i.Status,
|
||||||
|
&i.ID_2,
|
||||||
|
&i.BudgetID,
|
||||||
|
&i.Name,
|
||||||
|
&i.OnBudget,
|
||||||
|
&i.IsOpen,
|
||||||
|
&i.LastReconciled,
|
||||||
|
&i.ID_3,
|
||||||
|
&i.Date_2,
|
||||||
|
&i.Memo_2,
|
||||||
|
&i.Amount_2,
|
||||||
|
&i.AccountID_2,
|
||||||
|
&i.CategoryID_2,
|
||||||
|
&i.PayeeID_2,
|
||||||
|
&i.GroupID_2,
|
||||||
|
&i.Status_2,
|
||||||
|
&i.ID_4,
|
||||||
|
&i.BudgetID_2,
|
||||||
|
&i.Name_2,
|
||||||
|
&i.OnBudget_2,
|
||||||
|
&i.IsOpen_2,
|
||||||
|
&i.LastReconciled_2,
|
||||||
|
); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Close(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
const getTransaction = `-- name: GetTransaction :one
|
const getTransaction = `-- name: GetTransaction :one
|
||||||
SELECT id, date, memo, amount, group_id, status, account, payee_id, category_id, payee, category_group, category, transfer_account, budget_id, account_id FROM display_transactions
|
SELECT id, date, memo, amount, group_id, status, account, payee_id, category_id, payee, category_group, category, transfer_account, budget_id, account_id FROM display_transactions
|
||||||
WHERE id = $1
|
WHERE id = $1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user