Add ability to select month for budget
This commit is contained in:
parent
53c51ceb8d
commit
646560267a
@ -14,6 +14,9 @@ import (
|
||||
type BudgetingData struct {
|
||||
AlwaysNeededData
|
||||
Categories []postgres.GetCategoriesWithBalanceRow
|
||||
Date time.Time
|
||||
Next time.Time
|
||||
Previous time.Time
|
||||
}
|
||||
|
||||
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())
|
||||
lastOfMonth := firstOfMonth.AddDate(0, 1, -1)
|
||||
firstOfNextMonth := firstOfMonth.AddDate(0, 1, 0)
|
||||
firstOfPreviousMonth := firstOfMonth.AddDate(0, -1, 0)
|
||||
|
||||
params := postgres.GetCategoriesWithBalanceParams{
|
||||
BudgetID: budgetUUID,
|
||||
FromDate: firstOfMonth,
|
||||
ToDate: lastOfMonth,
|
||||
ToDate: firstOfNextMonth,
|
||||
}
|
||||
categories, err := h.Service.DB.GetCategoriesWithBalance(context.Background(), params)
|
||||
if err != nil {
|
||||
@ -64,6 +68,9 @@ func (h *Handler) budgeting(c *gin.Context) {
|
||||
d := BudgetingData{
|
||||
c.MustGet("data").(AlwaysNeededData),
|
||||
categories,
|
||||
firstOfMonth,
|
||||
firstOfNextMonth,
|
||||
firstOfPreviousMonth,
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "budgeting.html", d)
|
||||
|
@ -1,7 +1,9 @@
|
||||
|
||||
{{template "base" .}}
|
||||
|
||||
{{define "title"}}Budget{{end}}
|
||||
{{define "title"}}
|
||||
{{printf "Budget for %s %d" .Date.Month .Date.Year}}
|
||||
{{end}}
|
||||
|
||||
{{define "new"}}
|
||||
{{template "transaction-new"}}
|
||||
@ -13,8 +15,8 @@
|
||||
<span class="time"></span>
|
||||
</div>
|
||||
<div>
|
||||
<a href="/budget/{{.Budget.ID}}/{{.Date.Year}}/{{.Date.Month}}">Next Month</a>
|
||||
<a href="/budget/{{.Budget.ID}}/{{.Date.Year}}/{{.Date.Month}}">Previous Month</a>
|
||||
<a href="{{printf "/budget/%s/%d/%d" .Budget.ID .Previous.Year .Previous.Month}}">Previous Month</a>
|
||||
<a href="{{printf "/budget/%s/%d/%d" .Budget.ID .Next.Year .Next.Month}}">Next Month</a>
|
||||
</div>
|
||||
<table class="container col-lg-12" id="content">
|
||||
{{range .Categories}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user