Add ability to select month for budget

This commit is contained in:
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 {
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)