Show available balance including activities of this month
This commit is contained in:
parent
a19d3d6932
commit
edd1319222
@ -138,13 +138,13 @@ SELECT categories.id, categories.name, category_groups.name as group,
|
||||
WHERE categories.id = t_hist.category_id
|
||||
AND t_hist.date < $1
|
||||
)
|
||||
, 0))::decimal(12,2) as balance,
|
||||
, 0))::decimal(12,2) as available,
|
||||
COALESCE(
|
||||
(
|
||||
SELECT SUM(t_this.amount)
|
||||
FROM transactions t_this
|
||||
WHERE categories.id = t_this.category_id
|
||||
AND t_this.date >= $1 AND t_this.date < $2
|
||||
AND t_this.date >= $2 AND t_this.date < $1
|
||||
)
|
||||
, 0)::decimal(12,2) as activity,
|
||||
COALESCE(
|
||||
@ -152,7 +152,7 @@ SELECT categories.id, categories.name, category_groups.name as group,
|
||||
SELECT SUM(a_hist.amount)
|
||||
FROM assignments a_hist
|
||||
WHERE categories.id = a_hist.category_id
|
||||
AND a_hist.date >= $1 AND a_hist.date < $2
|
||||
AND a_hist.date >= $2 AND a_hist.date < $1
|
||||
)
|
||||
,0)::decimal(12,2) as assigned
|
||||
|
||||
@ -164,8 +164,8 @@ ORDER BY category_groups.name, categories.name
|
||||
`
|
||||
|
||||
type GetCategoriesWithBalanceParams struct {
|
||||
FromDate time.Time
|
||||
ToDate time.Time
|
||||
FromDate time.Time
|
||||
BudgetID uuid.UUID
|
||||
}
|
||||
|
||||
@ -173,13 +173,13 @@ type GetCategoriesWithBalanceRow struct {
|
||||
ID uuid.UUID
|
||||
Name string
|
||||
Group string
|
||||
Balance Numeric
|
||||
Available Numeric
|
||||
Activity Numeric
|
||||
Assigned Numeric
|
||||
}
|
||||
|
||||
func (q *Queries) GetCategoriesWithBalance(ctx context.Context, arg GetCategoriesWithBalanceParams) ([]GetCategoriesWithBalanceRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getCategoriesWithBalance, arg.FromDate, arg.ToDate, arg.BudgetID)
|
||||
rows, err := q.db.QueryContext(ctx, getCategoriesWithBalance, arg.ToDate, arg.FromDate, arg.BudgetID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -191,7 +191,7 @@ func (q *Queries) GetCategoriesWithBalance(ctx context.Context, arg GetCategorie
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Group,
|
||||
&i.Balance,
|
||||
&i.Available,
|
||||
&i.Activity,
|
||||
&i.Assigned,
|
||||
); err != nil {
|
||||
|
@ -26,16 +26,16 @@ SELECT categories.id, categories.name, category_groups.name as group,
|
||||
SELECT SUM(a_hist.amount)
|
||||
FROM assignments a_hist
|
||||
WHERE categories.id = a_hist.category_id
|
||||
AND a_hist.date < @from_date
|
||||
AND a_hist.date < @to_date
|
||||
)
|
||||
, 0)+COALESCE(
|
||||
(
|
||||
SELECT SUM(t_hist.amount)
|
||||
FROM transactions t_hist
|
||||
WHERE categories.id = t_hist.category_id
|
||||
AND t_hist.date < @from_date
|
||||
AND t_hist.date < @to_date
|
||||
)
|
||||
, 0))::decimal(12,2) as balance,
|
||||
, 0))::decimal(12,2) as available,
|
||||
COALESCE(
|
||||
(
|
||||
SELECT SUM(t_this.amount)
|
||||
|
@ -1,5 +1,5 @@
|
||||
-- +goose Up
|
||||
ALTER TABLE accounts ADD COLUMN on_budget boolean DEFAULT 'true' NOT NULL;
|
||||
ALTER TABLE accounts ADD COLUMN on_budget boolean DEFAULT TRUE NOT NULL;
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE accounts DROP COLUMN on_budget;
|
@ -29,8 +29,8 @@
|
||||
<th></th>
|
||||
<th></th>
|
||||
<th>Assigned</th>
|
||||
<th>Balance</th>
|
||||
<th>Activity</th>
|
||||
<th>Available</th>
|
||||
</tr>
|
||||
{{range .Categories}}
|
||||
<tr>
|
||||
@ -41,8 +41,8 @@
|
||||
<td>
|
||||
</td>
|
||||
{{template "amount-cell" .Assigned}}
|
||||
{{template "amount-cell" .Balance}}
|
||||
{{template "amount-cell" .Activity}}
|
||||
{{template "amount-cell" .Available}}
|
||||
</tr>
|
||||
{{end}}
|
||||
</table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user