Use in-place calculations
This commit is contained in:
parent
d89e702669
commit
8ecfd6b87a
@ -171,12 +171,13 @@ func (h *Handler) calculateBalances(budget postgres.Budget,
|
||||
cumultativeBalances []postgres.GetCumultativeBalancesRow) ([]CategoryWithBalance, numeric.Numeric) {
|
||||
categoriesWithBalance := []CategoryWithBalance{}
|
||||
|
||||
moneyUsed := numeric.Zero()
|
||||
moneyUsed2 := numeric.Zero()
|
||||
moneyUsed := &moneyUsed2
|
||||
for i := range categories {
|
||||
cat := &categories[i]
|
||||
// do not show hidden categories
|
||||
categoryWithBalance := h.CalculateCategoryBalances(cat, cumultativeBalances,
|
||||
firstOfNextMonth, &moneyUsed, firstOfMonth, budget)
|
||||
firstOfNextMonth, moneyUsed, firstOfMonth, budget)
|
||||
|
||||
if cat.ID == budget.IncomeCategoryID {
|
||||
continue
|
||||
@ -185,7 +186,7 @@ func (h *Handler) calculateBalances(budget postgres.Budget,
|
||||
categoriesWithBalance = append(categoriesWithBalance, categoryWithBalance)
|
||||
}
|
||||
|
||||
return categoriesWithBalance, moneyUsed
|
||||
return categoriesWithBalance, *moneyUsed
|
||||
}
|
||||
|
||||
func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow,
|
||||
@ -202,11 +203,11 @@ func (*Handler) CalculateCategoryBalances(cat *postgres.GetCategoriesRow,
|
||||
continue
|
||||
}
|
||||
|
||||
*moneyUsed = moneyUsed.Sub(bal.Assignments)
|
||||
moneyUsed.SubI(bal.Assignments)
|
||||
categoryWithBalance.Available = categoryWithBalance.Available.Add(bal.Assignments)
|
||||
categoryWithBalance.Available = categoryWithBalance.Available.Add(bal.Transactions)
|
||||
if !categoryWithBalance.Available.IsPositive() && bal.Date.Before(firstOfMonth) {
|
||||
*moneyUsed = moneyUsed.Add(categoryWithBalance.Available)
|
||||
moneyUsed.Add(categoryWithBalance.Available)
|
||||
categoryWithBalance.Available = numeric.Zero()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user