Skip to content

Commit

Permalink
dues: display payments only
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardini687 committed Apr 10, 2023
1 parent 525e50b commit 99fcf8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
11 changes: 6 additions & 5 deletions kakebo.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,9 @@ type Due struct {
//
// Output example:
//
// Incoming 1200,00
// Xyzzy 65,75
// Baz -6,00
// Foo -10,00
// Bar -34,50
// Foo -10,00
// Baz -6,00
func DisplayDues(dueData string) string {
var dues []Due

Expand All @@ -247,7 +245,10 @@ func DisplayDues(dueData string) string {
if err != nil {
return "invalid dues"
}
dues = append(dues, Due{val, fields[2]})

if val.LessThan(decimal.Zero) {
dues = append(dues, Due{decimal.Decimal.Abs(val), fields[2]})
}
}

sort.SliceStable(dues, func(a, b int) bool {
Expand Down
8 changes: 3 additions & 5 deletions kakebo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,9 @@ func TestDisplayDues(t *testing.T) {
1200 M incoming
`

want := `Incoming 1200,00
Xyzzy 65,75
Baz -6,00
Foo -10,00
Bar -34,50
want := `Bar 34,50
Foo 10,00
Baz 6,00
`

got := DisplayDues(dues)
Expand Down

0 comments on commit 99fcf8a

Please sign in to comment.