Display category in accounts view

This commit is contained in:
Jan Bader 2021-12-06 20:26:06 +00:00
parent 495bc2b7c3
commit e2d22a1080
3 changed files with 19 additions and 8 deletions

View File

@ -16,10 +16,12 @@ LIMIT 200;
-- name: GetTransactionsForAccount :many -- name: GetTransactionsForAccount :many
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, SELECT transactions.id, transactions.date, transactions.memo, transactions.amount,
accounts.name as account, payees.name as payee accounts.name as account, payees.name as payee, category_groups.name as category_group, categories.name as category
FROM transactions FROM transactions
INNER JOIN accounts ON accounts.id = transactions.account_id INNER JOIN accounts ON accounts.id = transactions.account_id
INNER JOIN payees ON payees.id = transactions.payee_id INNER JOIN payees ON payees.id = transactions.payee_id
INNER JOIN categories ON categories.id = transactions.category_id
INNER JOIN category_groups ON category_groups.id = categories.category_group_id
WHERE transactions.account_id = $1 WHERE transactions.account_id = $1
ORDER BY transactions.date DESC ORDER BY transactions.date DESC
LIMIT 200; LIMIT 200;

View File

@ -50,22 +50,26 @@ func (q *Queries) CreateTransaction(ctx context.Context, arg CreateTransactionPa
const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many const getTransactionsForAccount = `-- name: GetTransactionsForAccount :many
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, SELECT transactions.id, transactions.date, transactions.memo, transactions.amount,
accounts.name as account, payees.name as payee accounts.name as account, payees.name as payee, category_groups.name as category_group, categories.name as category
FROM transactions FROM transactions
INNER JOIN accounts ON accounts.id = transactions.account_id INNER JOIN accounts ON accounts.id = transactions.account_id
INNER JOIN payees ON payees.id = transactions.payee_id INNER JOIN payees ON payees.id = transactions.payee_id
INNER JOIN categories ON categories.id = transactions.category_id
INNER JOIN category_groups ON category_groups.id = categories.category_group_id
WHERE transactions.account_id = $1 WHERE transactions.account_id = $1
ORDER BY transactions.date DESC ORDER BY transactions.date DESC
LIMIT 200 LIMIT 200
` `
type GetTransactionsForAccountRow struct { type GetTransactionsForAccountRow struct {
ID uuid.UUID ID uuid.UUID
Date time.Time Date time.Time
Memo string Memo string
Amount Numeric Amount Numeric
Account string Account string
Payee string Payee string
CategoryGroup string
Category string
} }
func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) { func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.UUID) ([]GetTransactionsForAccountRow, error) {
@ -84,6 +88,8 @@ func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.
&i.Amount, &i.Amount,
&i.Account, &i.Account,
&i.Payee, &i.Payee,
&i.CategoryGroup,
&i.Category,
); err != nil { ); err != nil {
return nil, err return nil, err
} }

View File

@ -21,6 +21,9 @@
<td> <td>
{{.Payee}} {{.Payee}}
</td> </td>
<td>
{{.Category}}
</td>
<td> <td>
<a href="transaction/{{.ID}}">{{.Memo}}</a> <a href="transaction/{{.ID}}">{{.Memo}}</a>
</td> </td>