Remove unneeded loop
This commit is contained in:
parent
fc29b1409d
commit
1e495a5e47
@ -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,27 +106,23 @@ 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 {
|
||||
availableBalance := moneyUsed
|
||||
fmt.Printf("%s: %f\n", "INC", moneyUsed.GetFloat64())
|
||||
|
||||
for _, bal := range cumultativeBalances {
|
||||
if bal.CategoryID != budget.IncomeCategoryID {
|
||||
continue
|
||||
}
|
||||
availableBalance = moneyUsed
|
||||
|
||||
for _, bal := range cumultativeBalances {
|
||||
if bal.CategoryID != cat.ID {
|
||||
continue
|
||||
}
|
||||
|
||||
if !bal.Date.Before(firstOfNextMonth) {
|
||||
continue
|
||||
}
|
||||
|
||||
availableBalance = availableBalance.Add(bal.Transactions)
|
||||
if !bal.Date.Before(firstOfNextMonth) {
|
||||
continue
|
||||
}
|
||||
|
||||
availableBalance.AddI(bal.Transactions)
|
||||
availableBalance.AddI(bal.Assignments)
|
||||
}
|
||||
return availableBalance
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user