Also display account & payee
This commit is contained in:
parent
a4659c7133
commit
276fdb4ade
@ -11,7 +11,7 @@ import (
|
||||
|
||||
type BudgetData struct {
|
||||
Budget *postgres.Budget
|
||||
Transactions []postgres.Transaction
|
||||
Transactions []postgres.GetTransactionsForBudgetRow
|
||||
}
|
||||
|
||||
func (h *Handler) budget(c *gin.Context) {
|
||||
|
@ -48,3 +48,17 @@ func (tx Transaction) GetPositive() bool {
|
||||
amount := tx.GetAmount()
|
||||
return amount >= 0
|
||||
}
|
||||
|
||||
func (tx GetTransactionsForBudgetRow) GetAmount() float64 {
|
||||
var amount float64
|
||||
err := tx.Amount.AssignTo(&amount)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return amount
|
||||
}
|
||||
|
||||
func (tx GetTransactionsForBudgetRow) GetPositive() bool {
|
||||
amount := tx.GetAmount()
|
||||
return amount >= 0
|
||||
}
|
||||
|
@ -5,8 +5,11 @@ VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING *;
|
||||
|
||||
-- name: GetTransactionsForBudget :many
|
||||
SELECT transactions.* FROM transactions
|
||||
LEFT JOIN accounts ON accounts.id = transactions.account_id
|
||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount,
|
||||
accounts.name as account, payees.name as payee
|
||||
FROM transactions
|
||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||
INNER JOIN payees ON payees.id = transactions.payee_id
|
||||
WHERE accounts.budget_id = $1
|
||||
ORDER BY transactions.date DESC
|
||||
LIMIT 200;
|
||||
|
@ -81,29 +81,41 @@ func (q *Queries) GetTransactionsForAccount(ctx context.Context, accountID uuid.
|
||||
}
|
||||
|
||||
const getTransactionsForBudget = `-- name: GetTransactionsForBudget :many
|
||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount, transactions.account_id, transactions.payee_id FROM transactions
|
||||
LEFT JOIN accounts ON accounts.id = transactions.account_id
|
||||
SELECT transactions.id, transactions.date, transactions.memo, transactions.amount,
|
||||
accounts.name as account, payees.name as payee
|
||||
FROM transactions
|
||||
INNER JOIN accounts ON accounts.id = transactions.account_id
|
||||
INNER JOIN payees ON payees.id = transactions.payee_id
|
||||
WHERE accounts.budget_id = $1
|
||||
ORDER BY transactions.date DESC
|
||||
LIMIT 200
|
||||
`
|
||||
|
||||
func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]Transaction, error) {
|
||||
type GetTransactionsForBudgetRow struct {
|
||||
ID uuid.UUID
|
||||
Date time.Time
|
||||
Memo string
|
||||
Amount pgtype.Numeric
|
||||
Account string
|
||||
Payee string
|
||||
}
|
||||
|
||||
func (q *Queries) GetTransactionsForBudget(ctx context.Context, budgetID uuid.UUID) ([]GetTransactionsForBudgetRow, error) {
|
||||
rows, err := q.db.Query(ctx, getTransactionsForBudget, budgetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Transaction
|
||||
var items []GetTransactionsForBudgetRow
|
||||
for rows.Next() {
|
||||
var i Transaction
|
||||
var i GetTransactionsForBudgetRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Date,
|
||||
&i.Memo,
|
||||
&i.Amount,
|
||||
&i.AccountID,
|
||||
&i.PayeeID,
|
||||
&i.Account,
|
||||
&i.Payee,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -16,6 +16,12 @@
|
||||
{{range .Transactions}}
|
||||
<tr>
|
||||
<td>{{.Date}}</td>
|
||||
<td>
|
||||
{{.Account}}
|
||||
</td>
|
||||
<td>
|
||||
{{.Payee}}
|
||||
</td>
|
||||
<td>
|
||||
<a href="transaction/{{.ID}}">{{.Memo}}</a>
|
||||
</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user