diff --git a/internal/service/dashboard.go b/internal/service/dashboard.go index 1d69649..61a9914 100644 --- a/internal/service/dashboard.go +++ b/internal/service/dashboard.go @@ -81,5 +81,31 @@ func (s Dashboard) Summary(ctx context.Context, user *types.User, month time.Tim summary.Total = summary.Income + summary.Expenses 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 } diff --git a/internal/template/dashboard/dashboard.templ b/internal/template/dashboard/dashboard.templ index f69f88c..7767d2d 100644 --- a/internal/template/dashboard/dashboard.templ +++ b/internal/template/dashboard/dashboard.templ @@ -32,6 +32,15 @@ templ DashboardData(summary *types.DashboardMonthlySummary) { @balance(summary.Expenses) @balance(summary.Total) +
+ Total Savings + Total Account Balance + Net + + { types.FormatEuros(summary.SumOfSavings) } + { types.FormatEuros(summary.SumOfAccounts) } + @balance(summary.SumOfAccounts - summary.SumOfSavings) +
} diff --git a/internal/types/dashboard.go b/internal/types/dashboard.go index 3991699..dfc5595 100644 --- a/internal/types/dashboard.go +++ b/internal/types/dashboard.go @@ -2,17 +2,6 @@ package types 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 { Month time.Time // Sum of all Transactions with TreasureChests and no Accounts @@ -23,4 +12,7 @@ type DashboardMonthlySummary struct { Expenses int64 // Income - Expenses Total int64 + + SumOfSavings int64 + SumOfAccounts int64 }