diff --git a/http/budgeting.go b/http/budgeting.go index c0bed4f..431c3b7 100644 --- a/http/budgeting.go +++ b/http/budgeting.go @@ -192,7 +192,6 @@ func (h *Handler) calculateBalances(c *gin.Context, budget postgres.Budget, firs categoryWithBalance.Activity = bal.Transactions categoryWithBalance.Assigned = bal.Assignments } - } // do not show hidden categories diff --git a/postgres/numeric.go b/postgres/numeric.go index 38e75b1..b5079c2 100644 --- a/postgres/numeric.go +++ b/postgres/numeric.go @@ -44,7 +44,7 @@ func (n Numeric) IsZero() bool { } func (n Numeric) MatchExp(exp int32) Numeric { - diffExp := exp - n.Exp + diffExp := n.Exp - exp factor := big.NewInt(0).Exp(big.NewInt(10), big.NewInt(int64(diffExp)), nil) return Numeric{pgtype.Numeric{ Exp: exp, @@ -55,34 +55,36 @@ func (n Numeric) MatchExp(exp int32) Numeric { } func (n Numeric) Sub(o Numeric) Numeric { - if n.Exp > o.Exp { - o = o.MatchExp(n.Exp) - } else if n.Exp < o.Exp { - n = n.MatchExp(o.Exp) + left := n + right := o + if n.Exp < o.Exp { + right = o.MatchExp(n.Exp) + } else if n.Exp > o.Exp { + left = n.MatchExp(o.Exp) } - if o.Exp == n.Exp { + if left.Exp == right.Exp { return Numeric{pgtype.Numeric{ - Exp: n.Exp, - Int: big.NewInt(0).Sub(o.Int, n.Int), + Exp: left.Exp, + Int: big.NewInt(0).Sub(left.Int, right.Int), }} } panic("Cannot subtract with different exponents") } func (n Numeric) Add(o Numeric) Numeric { - fmt.Println("N", n, "O", o) - if n.Exp > o.Exp { - o = o.MatchExp(n.Exp) - } else if n.Exp < o.Exp { - n = n.MatchExp(o.Exp) + left := n + right := o + if n.Exp < o.Exp { + right = o.MatchExp(n.Exp) + } else if n.Exp > o.Exp { + left = n.MatchExp(o.Exp) } - fmt.Println("NM", n, "OM", o) - if o.Exp == n.Exp { + if left.Exp == right.Exp { return Numeric{pgtype.Numeric{ - Exp: n.Exp, - Int: big.NewInt(0).Add(o.Int, n.Int), + Exp: left.Exp, + Int: big.NewInt(0).Add(left.Int, right.Int), }} }