Only show last month's overflow
This commit is contained in:
parent
11179a1593
commit
5e18d51b5d
@ -67,6 +67,7 @@ func (h *Handler) budgeting(c *gin.Context) {
|
|||||||
BudgetID: budgetUUID,
|
BudgetID: budgetUUID,
|
||||||
FromDate: firstOfMonth,
|
FromDate: firstOfMonth,
|
||||||
ToDate: firstOfNextMonth,
|
ToDate: firstOfNextMonth,
|
||||||
|
PrevFromDate: firstOfMonth.AddDate(0, -1, 0),
|
||||||
}
|
}
|
||||||
categories, err := h.Service.DB.GetCategoriesWithBalance(c.Request.Context(), params)
|
categories, err := h.Service.DB.GetCategoriesWithBalance(c.Request.Context(), params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -133,14 +133,27 @@ SELECT categories.id, categories.name, category_groups.name as group,
|
|||||||
WHERE categories.id = t_hist.category_id AND t_hist.date < $1
|
WHERE categories.id = t_hist.category_id AND t_hist.date < $1
|
||||||
), 0)
|
), 0)
|
||||||
)::decimal(12,2) as available,
|
)::decimal(12,2) as available,
|
||||||
(
|
( COALESCE((
|
||||||
COALESCE((
|
|
||||||
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
||||||
WHERE categories.id = a_hist.category_id AND a_hist.date < $2
|
WHERE categories.id = a_hist.category_id AND a_hist.date < $2
|
||||||
), 0)+COALESCE((
|
), 0)+COALESCE((
|
||||||
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
||||||
WHERE categories.id = t_hist.category_id AND t_hist.date < $2
|
WHERE categories.id = t_hist.category_id AND t_hist.date < $2
|
||||||
), 0)
|
), 0)-CASE WHEN (COALESCE((
|
||||||
|
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
||||||
|
WHERE categories.id = a_hist.category_id AND a_hist.date < $3
|
||||||
|
), 0)+COALESCE((
|
||||||
|
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
||||||
|
WHERE categories.id = t_hist.category_id AND t_hist.date < $3
|
||||||
|
), 0)) < 0 THEN (COALESCE((
|
||||||
|
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
||||||
|
WHERE categories.id = a_hist.category_id AND a_hist.date < $3
|
||||||
|
), 0)+COALESCE((
|
||||||
|
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
||||||
|
WHERE categories.id = t_hist.category_id AND t_hist.date < $3
|
||||||
|
), 0)) ELSE 0 END
|
||||||
|
|
||||||
|
|
||||||
)::decimal(12,2) as available_last_month,
|
)::decimal(12,2) as available_last_month,
|
||||||
COALESCE((
|
COALESCE((
|
||||||
SELECT SUM(t_this.amount) FROM transactions t_this
|
SELECT SUM(t_this.amount) FROM transactions t_this
|
||||||
@ -153,7 +166,7 @@ SELECT categories.id, categories.name, category_groups.name as group,
|
|||||||
|
|
||||||
FROM categories
|
FROM categories
|
||||||
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
|
INNER JOIN category_groups ON categories.category_group_id = category_groups.id
|
||||||
WHERE category_groups.budget_id = $3
|
WHERE category_groups.budget_id = $4
|
||||||
GROUP BY categories.id, categories.name, category_groups.name
|
GROUP BY categories.id, categories.name, category_groups.name
|
||||||
ORDER BY category_groups.name, categories.name
|
ORDER BY category_groups.name, categories.name
|
||||||
`
|
`
|
||||||
@ -161,6 +174,7 @@ ORDER BY category_groups.name, categories.name
|
|||||||
type GetCategoriesWithBalanceParams struct {
|
type GetCategoriesWithBalanceParams struct {
|
||||||
ToDate time.Time
|
ToDate time.Time
|
||||||
FromDate time.Time
|
FromDate time.Time
|
||||||
|
PrevFromDate time.Time
|
||||||
BudgetID uuid.UUID
|
BudgetID uuid.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +189,12 @@ type GetCategoriesWithBalanceRow struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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.ToDate, arg.FromDate, arg.BudgetID)
|
rows, err := q.db.QueryContext(ctx, getCategoriesWithBalance,
|
||||||
|
arg.ToDate,
|
||||||
|
arg.FromDate,
|
||||||
|
arg.PrevFromDate,
|
||||||
|
arg.BudgetID,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,27 @@ SELECT categories.id, categories.name, category_groups.name as group,
|
|||||||
WHERE categories.id = t_hist.category_id AND t_hist.date < @to_date
|
WHERE categories.id = t_hist.category_id AND t_hist.date < @to_date
|
||||||
), 0)
|
), 0)
|
||||||
)::decimal(12,2) as available,
|
)::decimal(12,2) as available,
|
||||||
(
|
( COALESCE((
|
||||||
COALESCE((
|
|
||||||
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
||||||
WHERE categories.id = a_hist.category_id AND a_hist.date < @from_date
|
WHERE categories.id = a_hist.category_id AND a_hist.date < @from_date
|
||||||
), 0)+COALESCE((
|
), 0)+COALESCE((
|
||||||
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
||||||
WHERE categories.id = t_hist.category_id AND t_hist.date < @from_date
|
WHERE categories.id = t_hist.category_id AND t_hist.date < @from_date
|
||||||
), 0)
|
), 0)-CASE WHEN (COALESCE((
|
||||||
|
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
||||||
|
WHERE categories.id = a_hist.category_id AND a_hist.date < @prev_from_date
|
||||||
|
), 0)+COALESCE((
|
||||||
|
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
||||||
|
WHERE categories.id = t_hist.category_id AND t_hist.date < @prev_from_date
|
||||||
|
), 0)) < 0 THEN (COALESCE((
|
||||||
|
SELECT SUM(a_hist.amount) FROM assignments a_hist
|
||||||
|
WHERE categories.id = a_hist.category_id AND a_hist.date < @prev_from_date
|
||||||
|
), 0)+COALESCE((
|
||||||
|
SELECT SUM(t_hist.amount) FROM transactions t_hist
|
||||||
|
WHERE categories.id = t_hist.category_id AND t_hist.date < @prev_from_date
|
||||||
|
), 0)) ELSE 0 END
|
||||||
|
|
||||||
|
|
||||||
)::decimal(12,2) as available_last_month,
|
)::decimal(12,2) as available_last_month,
|
||||||
COALESCE((
|
COALESCE((
|
||||||
SELECT SUM(t_this.amount) FROM transactions t_this
|
SELECT SUM(t_this.amount) FROM transactions t_this
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
<th>Category</th>
|
<th>Category</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
|
<th>Leftover</th>
|
||||||
<th>Assigned</th>
|
<th>Assigned</th>
|
||||||
<th>Activity</th>
|
<th>Activity</th>
|
||||||
<th>Available</th>
|
<th>Available</th>
|
||||||
@ -40,6 +41,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
</td>
|
</td>
|
||||||
|
{{template "amount-cell" .AvailableLastMonth}}
|
||||||
{{template "amount-cell" .Assigned}}
|
{{template "amount-cell" .Assigned}}
|
||||||
{{template "amount-cell" .Activity}}
|
{{template "amount-cell" .Activity}}
|
||||||
{{template "amount-cell" .Available}}
|
{{template "amount-cell" .Available}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user