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