Remove income category from result
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Jan Bader 2022-04-06 20:29:56 +00:00
parent cef62574bb
commit 01c407d4f1
3 changed files with 15 additions and 12 deletions

View File

@ -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}} 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 { func (n Numeric) GetFloat64() float64 {
if n.Status != pgtype.Present { if n.Status != pgtype.Present {
return 0 return 0

View File

@ -79,7 +79,7 @@ func (h *Handler) prepareBudgeting(ctx context.Context, budget postgres.Budget,
return BudgetingForMonthResponse{}, fmt.Errorf("error loading balances: %w", err) 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) availableBalance := h.getAvailableBalance(budget, moneyUsed, cumultativeBalances, categoriesWithBalance, firstOfNextMonth)
data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance} data := BudgetingForMonthResponse{categoriesWithBalance, availableBalance}
@ -107,17 +107,9 @@ func (*Handler) getAvailableBalance(budget postgres.Budget,
} }
availableBalance.AddI(bal.Transactions) 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 return availableBalance
} }
@ -155,7 +147,7 @@ func (h *Handler) getBudget(c *gin.Context, budgetUUID uuid.UUID) {
c.JSON(http.StatusOK, data) 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, categories []postgres.GetCategoriesRow, cumultativeBalances []postgres.GetCumultativeBalancesRow,
) ([]CategoryWithBalance, numeric.Numeric) { ) ([]CategoryWithBalance, numeric.Numeric) {
categoriesWithBalance := []CategoryWithBalance{} categoriesWithBalance := []CategoryWithBalance{}
@ -163,6 +155,10 @@ func (h *Handler) calculateBalances(firstOfNextMonth time.Time, firstOfMonth tim
moneyUsed := numeric.Zero() moneyUsed := numeric.Zero()
for i := range categories { for i := range categories {
cat := &categories[i] cat := &categories[i]
if cat.ID == budget.IncomeCategoryID {
continue
}
categoryWithBalance := NewCategoryWithBalance(cat) categoryWithBalance := NewCategoryWithBalance(cat)
for _, bal := range cumultativeBalances { for _, bal := range cumultativeBalances {
if bal.CategoryID != cat.ID { if bal.CategoryID != cat.ID {

View File

@ -113,7 +113,7 @@ export const useAccountStore = defineStore("budget/account", {
const categoryGroups = []; const categoryGroups = [];
let prev = undefined; let prev = undefined;
for (const category of categories) { for (const category of categories) {
if (category.ID == this.GetIncomeCategoryID) continue; //if (category.ID == this.GetIncomeCategoryID) continue;
if (prev == undefined || category.Group != prev.Name) { if (prev == undefined || category.Group != prev.Name) {
prev = { prev = {