Move code to other method
This commit is contained in:
parent
f0993fd9c3
commit
cf39db52fb
@ -81,15 +81,7 @@ func (h *Handler) prepareBudgeting(ctx context.Context, budget postgres.Budget,
|
|||||||
|
|
||||||
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(budget, moneyUsed, cumultativeBalances, categoriesWithBalance, firstOfNextMonth)
|
||||||
for i := range categoriesWithBalance {
|
|
||||||
cat := &categoriesWithBalance[i]
|
|
||||||
if cat.ID != budget.IncomeCategoryID {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
cat.Available = availableBalance
|
|
||||||
}
|
|
||||||
|
|
||||||
data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance}
|
data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance}
|
||||||
return data, nil
|
return data, nil
|
||||||
@ -102,7 +94,7 @@ type BudgetingForMonthResponse struct {
|
|||||||
|
|
||||||
func (*Handler) getAvailableBalance(budget postgres.Budget,
|
func (*Handler) getAvailableBalance(budget postgres.Budget,
|
||||||
moneyUsed numeric.Numeric, cumultativeBalances []postgres.GetCumultativeBalancesRow,
|
moneyUsed numeric.Numeric, cumultativeBalances []postgres.GetCumultativeBalancesRow,
|
||||||
firstOfNextMonth time.Time,
|
categoriesWithBalance []CategoryWithBalance, firstOfNextMonth time.Time,
|
||||||
) numeric.Numeric {
|
) numeric.Numeric {
|
||||||
availableBalance := moneyUsed
|
availableBalance := moneyUsed
|
||||||
|
|
||||||
@ -118,6 +110,15 @@ func (*Handler) getAvailableBalance(budget postgres.Budget,
|
|||||||
availableBalance.AddI(bal.Transactions)
|
availableBalance.AddI(bal.Transactions)
|
||||||
availableBalance.AddI(bal.Assignments)
|
availableBalance.AddI(bal.Assignments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := range categoriesWithBalance {
|
||||||
|
cat := &categoriesWithBalance[i]
|
||||||
|
if cat.ID != budget.IncomeCategoryID {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
cat.Available = availableBalance
|
||||||
|
}
|
||||||
return availableBalance
|
return availableBalance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user