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