diff --git a/http/ynab-import.go b/http/ynab-import.go index 1b22bf2..f710922 100644 --- a/http/ynab-import.go +++ b/http/ynab-import.go @@ -123,7 +123,16 @@ func GetAmount(inflow string, outflow string) (pgtype.Numeric, error) { num := pgtype.Numeric{} err := num.Set(inflow) if err != nil { - return num, fmt.Errorf("Could not inflow %s: %w", inflow, err) + return num, fmt.Errorf("Could not parse inflow %s: %w", inflow, err) + } + + if num.Int.Int64() != 0 { + return num, nil + } + + err = num.Set("-" + outflow) + if err != nil { + return num, fmt.Errorf("Could not parse outflow %s: %w", inflow, err) } return num, nil } diff --git a/postgres/conn.go b/postgres/conn.go index 00d0c18..8f38c69 100644 --- a/postgres/conn.go +++ b/postgres/conn.go @@ -43,3 +43,13 @@ func (tx Transaction) GetAmount() float64 { } return amount } + +func (tx Transaction) GetAmountString() string { + amount := tx.GetAmount() + return fmt.Sprintf("%.2f", amount) +} + +func (tx Transaction) GetPositive() bool { + amount := tx.GetAmount() + return amount >= 0 +} diff --git a/web/budget.html b/web/budget.html index 696befc..fe9ea2d 100644 --- a/web/budget.html +++ b/web/budget.html @@ -19,7 +19,7 @@