feat(dashboard): #162 include total sum of accounts compared to total savings
This commit was merged in pull request #185.
This commit is contained in:
@@ -81,5 +81,31 @@ func (s Dashboard) Summary(ctx context.Context, user *types.User, month time.Tim
|
|||||||
summary.Total = summary.Income + summary.Expenses
|
summary.Total = summary.Income + summary.Expenses
|
||||||
summary.Month = month
|
summary.Month = month
|
||||||
|
|
||||||
|
err = s.db.GetContext(ctx, &value, `
|
||||||
|
SELECT SUM(current_balance)
|
||||||
|
FROM treasure_chest
|
||||||
|
WHERE user_id = $1`,
|
||||||
|
user.Id)
|
||||||
|
err = db.TransformAndLogDbError("dashboard", nil, err)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if value != nil {
|
||||||
|
summary.SumOfSavings = *value
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.db.GetContext(ctx, &value, `
|
||||||
|
SELECT SUM(current_balance)
|
||||||
|
FROM account
|
||||||
|
WHERE user_id = $1`,
|
||||||
|
user.Id)
|
||||||
|
err = db.TransformAndLogDbError("dashboard", nil, err)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if value != nil {
|
||||||
|
summary.SumOfAccounts = *value
|
||||||
|
}
|
||||||
|
|
||||||
return &summary, nil
|
return &summary, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,15 @@ templ DashboardData(summary *types.DashboardMonthlySummary) {
|
|||||||
@balance(summary.Expenses)
|
@balance(summary.Expenses)
|
||||||
@balance(summary.Total)
|
@balance(summary.Total)
|
||||||
</section>
|
</section>
|
||||||
|
<section class="grid grid-cols-[auto_auto_auto_1fr] gap-4">
|
||||||
|
<span>Total Savings</span>
|
||||||
|
<span>Total Account Balance</span>
|
||||||
|
<span>Net</span>
|
||||||
|
<span></span>
|
||||||
|
<span>{ types.FormatEuros(summary.SumOfSavings) }</span>
|
||||||
|
<span>{ types.FormatEuros(summary.SumOfAccounts) }</span>
|
||||||
|
@balance(summary.SumOfAccounts - summary.SumOfSavings)
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,17 +2,6 @@ package types
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// Account | TreasureChest | Value | Description
|
|
||||||
// --------|---------------|-------|----------------
|
|
||||||
// Y | Y | + | Invalid
|
|
||||||
// Y | Y | - | Expense
|
|
||||||
// Y | N | + | Deposit
|
|
||||||
// Y | N | - | Withdrawal (for moving between accounts)
|
|
||||||
// N | Y | + | Saving
|
|
||||||
// N | Y | - | Withdrawal (for moving between treasure chests)
|
|
||||||
// N | N | + | Invalid
|
|
||||||
// N | N | - | Invalid
|
|
||||||
|
|
||||||
type DashboardMonthlySummary struct {
|
type DashboardMonthlySummary struct {
|
||||||
Month time.Time
|
Month time.Time
|
||||||
// Sum of all Transactions with TreasureChests and no Accounts
|
// Sum of all Transactions with TreasureChests and no Accounts
|
||||||
@@ -23,4 +12,7 @@ type DashboardMonthlySummary struct {
|
|||||||
Expenses int64
|
Expenses int64
|
||||||
// Income - Expenses
|
// Income - Expenses
|
||||||
Total int64
|
Total int64
|
||||||
|
|
||||||
|
SumOfSavings int64
|
||||||
|
SumOfAccounts int64
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user