Add ability to select month for budget

This commit is contained in:
Jan Bader 2021-12-07 13:40:24 +00:00
parent 53c51ceb8d
commit 646560267a
2 changed files with 14 additions and 5 deletions

View File

@ -14,6 +14,9 @@ import (
type BudgetingData struct { type BudgetingData struct {
AlwaysNeededData AlwaysNeededData
Categories []postgres.GetCategoriesWithBalanceRow Categories []postgres.GetCategoriesWithBalanceRow
Date time.Time
Next time.Time
Previous time.Time
} }
func (h *Handler) budgeting(c *gin.Context) { func (h *Handler) budgeting(c *gin.Context) {
@ -48,12 +51,13 @@ func (h *Handler) budgeting(c *gin.Context) {
} }
firstOfMonth := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, now.Location()) firstOfMonth := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, now.Location())
lastOfMonth := firstOfMonth.AddDate(0, 1, -1) firstOfNextMonth := firstOfMonth.AddDate(0, 1, 0)
firstOfPreviousMonth := firstOfMonth.AddDate(0, -1, 0)
params := postgres.GetCategoriesWithBalanceParams{ params := postgres.GetCategoriesWithBalanceParams{
BudgetID: budgetUUID, BudgetID: budgetUUID,
FromDate: firstOfMonth, FromDate: firstOfMonth,
ToDate: lastOfMonth, ToDate: firstOfNextMonth,
} }
categories, err := h.Service.DB.GetCategoriesWithBalance(context.Background(), params) categories, err := h.Service.DB.GetCategoriesWithBalance(context.Background(), params)
if err != nil { if err != nil {
@ -64,6 +68,9 @@ func (h *Handler) budgeting(c *gin.Context) {
d := BudgetingData{ d := BudgetingData{
c.MustGet("data").(AlwaysNeededData), c.MustGet("data").(AlwaysNeededData),
categories, categories,
firstOfMonth,
firstOfNextMonth,
firstOfPreviousMonth,
} }
c.HTML(http.StatusOK, "budgeting.html", d) c.HTML(http.StatusOK, "budgeting.html", d)

View File

@ -1,7 +1,9 @@
{{template "base" .}} {{template "base" .}}
{{define "title"}}Budget{{end}} {{define "title"}}
{{printf "Budget for %s %d" .Date.Month .Date.Year}}
{{end}}
{{define "new"}} {{define "new"}}
{{template "transaction-new"}} {{template "transaction-new"}}
@ -13,8 +15,8 @@
<span class="time"></span> <span class="time"></span>
</div> </div>
<div> <div>
<a href="/budget/{{.Budget.ID}}/{{.Date.Year}}/{{.Date.Month}}">Next Month</a> <a href="{{printf "/budget/%s/%d/%d" .Budget.ID .Previous.Year .Previous.Month}}">Previous Month</a>
<a href="/budget/{{.Budget.ID}}/{{.Date.Year}}/{{.Date.Month}}">Previous 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">
{{range .Categories}} {{range .Categories}}