diff --git a/postgres/numeric/numeric.go b/postgres/numeric/numeric.go index 4988f9e..7405489 100644 --- a/postgres/numeric/numeric.go +++ b/postgres/numeric/numeric.go @@ -25,6 +25,13 @@ func FromInt64WithExp(value int64, exp int32) Numeric { return Numeric{Numeric: pgtype.Numeric{Int: big.NewInt(value), Exp: exp, Status: pgtype.Present}} } +func (n *Numeric) SetZero() { + n.Exp = 0 + n.Int = big.NewInt(0) + n.Status = pgtype.Present + n.NaN = false +} + func (n Numeric) GetFloat64() float64 { if n.Status != pgtype.Present { return 0 diff --git a/server/budgeting.go b/server/budgeting.go index 814d94b..8d3ef05 100644 --- a/server/budgeting.go +++ b/server/budgeting.go @@ -79,7 +79,7 @@ func (h *Handler) prepareBudgeting(ctx context.Context, budget postgres.Budget, return BudgetingForMonthResponse{}, fmt.Errorf("error loading balances: %w", err) } - categoriesWithBalance, moneyUsed := h.calculateBalances(firstOfNextMonth, firstOfMonth, categories, cumultativeBalances) + categoriesWithBalance, moneyUsed := h.calculateBalances(budget, firstOfNextMonth, firstOfMonth, categories, cumultativeBalances) availableBalance := h.getAvailableBalance(budget, moneyUsed, cumultativeBalances, categoriesWithBalance, firstOfNextMonth) data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance} @@ -107,17 +107,9 @@ func (*Handler) getAvailableBalance(budget postgres.Budget, } availableBalance.AddI(bal.Transactions) - availableBalance.AddI(bal.Assignments) + availableBalance.AddI(bal.Assignments) // should be zero, but who knows } - for i := range categoriesWithBalance { - cat := &categoriesWithBalance[i] - if cat.ID != budget.IncomeCategoryID { - continue - } - - cat.Available = availableBalance - } return availableBalance } @@ -155,7 +147,7 @@ func (h *Handler) getBudget(c *gin.Context, budgetUUID uuid.UUID) { c.JSON(http.StatusOK, data) } -func (h *Handler) calculateBalances(firstOfNextMonth time.Time, firstOfMonth time.Time, +func (h *Handler) calculateBalances(budget postgres.Budget, firstOfNextMonth time.Time, firstOfMonth time.Time, categories []postgres.GetCategoriesRow, cumultativeBalances []postgres.GetCumultativeBalancesRow, ) ([]CategoryWithBalance, numeric.Numeric) { categoriesWithBalance := []CategoryWithBalance{} @@ -163,6 +155,10 @@ func (h *Handler) calculateBalances(firstOfNextMonth time.Time, firstOfMonth tim moneyUsed := numeric.Zero() for i := range categories { cat := &categories[i] + if cat.ID == budget.IncomeCategoryID { + continue + } + categoryWithBalance := NewCategoryWithBalance(cat) for _, bal := range cumultativeBalances { if bal.CategoryID != cat.ID { diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts index 811dc4c..97d6dd3 100644 --- a/web/src/stores/budget-account.ts +++ b/web/src/stores/budget-account.ts @@ -113,7 +113,7 @@ export const useAccountStore = defineStore("budget/account", { const categoryGroups = []; let prev = undefined; for (const category of categories) { - if (category.ID == this.GetIncomeCategoryID) continue; + //if (category.ID == this.GetIncomeCategoryID) continue; if (prev == undefined || category.Group != prev.Name) { prev = {