feat(dashboard): #162 include total sum of accounts compared to total savings
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 5m15s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 5m7s

This commit was merged in pull request #185.
This commit is contained in:
2025-06-16 23:00:38 +02:00
parent 596cc602d0
commit 06a8c80f1d
3 changed files with 38 additions and 11 deletions

View File

@@ -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
} }

View File

@@ -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>
} }

View File

@@ -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
} }