Merge balance and balanceassignments
This commit is contained in:
parent
0b0b20c5ec
commit
6bcf94661e
@ -91,22 +91,21 @@ func (q *Queries) GetCategories(ctx context.Context, budgetID uuid.UUID) ([]GetC
|
|||||||
|
|
||||||
const getCategoriesWithBalance = `-- name: GetCategoriesWithBalance :many
|
const getCategoriesWithBalance = `-- name: GetCategoriesWithBalance :many
|
||||||
SELECT categories.id, categories.name, category_groups.name as group,
|
SELECT categories.id, categories.name, category_groups.name as group,
|
||||||
COALESCE(
|
(COALESCE(
|
||||||
(
|
(
|
||||||
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 < $1
|
||||||
)
|
)
|
||||||
, 0)::decimal(12,2) as balance_assignments,
|
, 0)+COALESCE(
|
||||||
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 < $1
|
AND t_hist.date < $1
|
||||||
)
|
)
|
||||||
, 0)::decimal(12,2) as balance,
|
, 0))::decimal(12,2) as balance,
|
||||||
COALESCE(
|
COALESCE(
|
||||||
(
|
(
|
||||||
SELECT SUM(t_this.amount)
|
SELECT SUM(t_this.amount)
|
||||||
@ -132,7 +131,6 @@ type GetCategoriesWithBalanceRow struct {
|
|||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
Name string
|
Name string
|
||||||
Group string
|
Group string
|
||||||
BalanceAssignments Numeric
|
|
||||||
Balance Numeric
|
Balance Numeric
|
||||||
Activity Numeric
|
Activity Numeric
|
||||||
}
|
}
|
||||||
@ -150,7 +148,6 @@ func (q *Queries) GetCategoriesWithBalance(ctx context.Context, arg GetCategorie
|
|||||||
&i.ID,
|
&i.ID,
|
||||||
&i.Name,
|
&i.Name,
|
||||||
&i.Group,
|
&i.Group,
|
||||||
&i.BalanceAssignments,
|
|
||||||
&i.Balance,
|
&i.Balance,
|
||||||
&i.Activity,
|
&i.Activity,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
@ -21,22 +21,21 @@ WHERE category_groups.budget_id = $1;
|
|||||||
|
|
||||||
-- name: GetCategoriesWithBalance :many
|
-- name: GetCategoriesWithBalance :many
|
||||||
SELECT categories.id, categories.name, category_groups.name as group,
|
SELECT categories.id, categories.name, category_groups.name as group,
|
||||||
COALESCE(
|
(COALESCE(
|
||||||
(
|
(
|
||||||
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 < @from_date
|
||||||
)
|
)
|
||||||
, 0)::decimal(12,2) as balance_assignments,
|
, 0)+COALESCE(
|
||||||
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 < @from_date
|
||||||
)
|
)
|
||||||
, 0)::decimal(12,2) as balance,
|
, 0))::decimal(12,2) as balance,
|
||||||
COALESCE(
|
COALESCE(
|
||||||
(
|
(
|
||||||
SELECT SUM(t_this.amount)
|
SELECT SUM(t_this.amount)
|
||||||
|
@ -20,6 +20,14 @@
|
|||||||
<a href="{{printf "/budget/%s/%d/%d" .Budget.ID .Next.Year .Next.Month}}">Next Month</a>
|
<a href="{{printf "/budget/%s/%d/%d" .Budget.ID .Next.Year .Next.Month}}">Next Month</a>
|
||||||
</div>
|
</div>
|
||||||
<table class="container col-lg-12" id="content">
|
<table class="container col-lg-12" id="content">
|
||||||
|
<tr>
|
||||||
|
<th>Group</th>
|
||||||
|
<th>Category</th>
|
||||||
|
<th></th>
|
||||||
|
<th></th>
|
||||||
|
<th>Balance</th>
|
||||||
|
<th>Activity</th>
|
||||||
|
</tr>
|
||||||
{{range .Categories}}
|
{{range .Categories}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{.Group}}</td>
|
<td>{{.Group}}</td>
|
||||||
@ -29,7 +37,6 @@
|
|||||||
<td>
|
<td>
|
||||||
</td>
|
</td>
|
||||||
{{template "amount-cell" .Balance}}
|
{{template "amount-cell" .Balance}}
|
||||||
{{template "amount-cell" .BalanceAssignments}}
|
|
||||||
{{template "amount-cell" .Activity}}
|
{{template "amount-cell" .Activity}}
|
||||||
</tr>
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user