diff --git a/server/budgeting.go b/server/budgeting.go index 3f7cd42..dca6c71 100644 --- a/server/budgeting.go +++ b/server/budgeting.go @@ -81,15 +81,7 @@ func (h *Handler) prepareBudgeting(ctx context.Context, budget postgres.Budget, categoriesWithBalance, moneyUsed := h.calculateBalances( budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances) - availableBalance := h.getAvailableBalance(budget, moneyUsed, cumultativeBalances, firstOfNextMonth) - for i := range categoriesWithBalance { - cat := &categoriesWithBalance[i] - if cat.ID != budget.IncomeCategoryID { - continue - } - - cat.Available = availableBalance - } + availableBalance := h.getAvailableBalance(budget, moneyUsed, cumultativeBalances, categoriesWithBalance, firstOfNextMonth) data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance} return data, nil @@ -102,7 +94,7 @@ type BudgetingForMonthResponse struct { func (*Handler) getAvailableBalance(budget postgres.Budget, moneyUsed numeric.Numeric, cumultativeBalances []postgres.GetCumultativeBalancesRow, - firstOfNextMonth time.Time, + categoriesWithBalance []CategoryWithBalance, firstOfNextMonth time.Time, ) numeric.Numeric { availableBalance := moneyUsed @@ -118,6 +110,15 @@ func (*Handler) getAvailableBalance(budget postgres.Budget, availableBalance.AddI(bal.Transactions) availableBalance.AddI(bal.Assignments) } + + for i := range categoriesWithBalance { + cat := &categoriesWithBalance[i] + if cat.ID != budget.IncomeCategoryID { + continue + } + + cat.Available = availableBalance + } return availableBalance }