Remove unneeded loop

This commit is contained in:
Jan Bader 2022-03-04 21:13:50 +00:00
parent fc29b1409d
commit 1e495a5e47

View File

@ -97,8 +97,7 @@ func (h *Handler) budgetingForMonth(c *gin.Context) {
categoriesWithBalance, moneyUsed := h.calculateBalances(
budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances)
availableBalance := h.getAvailableBalance(categories, budget, moneyUsed, cumultativeBalances, firstOfNextMonth)
availableBalance := h.getAvailableBalance(budget, moneyUsed, cumultativeBalances, firstOfNextMonth)
data := struct {
Categories []CategoryWithBalance
@ -107,18 +106,14 @@ func (h *Handler) budgetingForMonth(c *gin.Context) {
c.JSON(http.StatusOK, data)
}
func (*Handler) getAvailableBalance(categories []postgres.GetCategoriesRow, budget postgres.Budget,
func (*Handler) getAvailableBalance(budget postgres.Budget,
moneyUsed numeric.Numeric, cumultativeBalances []postgres.GetCumultativeBalancesRow,
firstOfNextMonth time.Time) numeric.Numeric {
availableBalance := numeric.Zero()
for _, cat := range categories {
if cat.ID != budget.IncomeCategoryID {
continue
}
availableBalance = moneyUsed
availableBalance := moneyUsed
fmt.Printf("%s: %f\n", "INC", moneyUsed.GetFloat64())
for _, bal := range cumultativeBalances {
if bal.CategoryID != cat.ID {
if bal.CategoryID != budget.IncomeCategoryID {
continue
}
@ -126,8 +121,8 @@ func (*Handler) getAvailableBalance(categories []postgres.GetCategoriesRow, budg
continue
}
availableBalance = availableBalance.Add(bal.Transactions)
}
availableBalance.AddI(bal.Transactions)
availableBalance.AddI(bal.Assignments)
}
return availableBalance
}