diff --git a/lib/RevBank/Cart/Entry.pm b/lib/RevBank/Cart/Entry.pm index 3660227..58724da 100644 --- a/lib/RevBank/Cart/Entry.pm +++ b/lib/RevBank/Cart/Entry.pm @@ -128,14 +128,14 @@ sub as_loggable { my $description = $quantity == 1 ? $_->{description} - : sprintf("%s [%sx %s]", $_->{description}, $quantity, abs($_->{amount})); + : sprintf("%s [%sx %s]", $_->{description}, $quantity, $_->{amount}->abs); push @s, sprintf( "%-12s %4s %3d %5s # %s", $_->{user}, - ($total > 0 ? 'GAIN' : $total < 0 ? 'LOSE' : ''), + ($total->cents > 0 ? 'GAIN' : $total->cents < 0 ? 'LOSE' : ''), $quantity, - abs($total), + $total->abs, $description ); } diff --git a/lib/RevBank/Messages.pm b/lib/RevBank/Messages.pm index 2949167..05b7b45 100644 --- a/lib/RevBank/Messages.pm +++ b/lib/RevBank/Messages.pm @@ -28,9 +28,9 @@ sub hook_cart_changed { $cart->display; if (not $cart->entries('refuse_checkout')) { - my $sum = $cart->sum; - my $what = $sum > 0 ? "add" : "pay"; - my $abs = $sum->abs; + my $sum = $cart->sum; + my $what = $sum->cents > 0 ? "add" : "pay"; + my $abs = $sum->abs; say "Enter username to $what $abs; type 'abort' to abort."; } } @@ -52,10 +52,11 @@ sub hook_reject { sub hook_user_balance { my ($class, $username, $old, $delta, $new) = @_; - my $sign = $delta >= 0 ? '+' : '-'; - my $rood = $new < 0 ? '31;' : ''; - my $abs = abs($delta); - my $warn = $new < -13.37 ? " \e[5;1m(!!)\e[0m" : ""; + my $sign = $delta->cents >= 0 ? '+' : '-'; + my $rood = $new->cents < 0 ? '31;' : ''; + my $abs = $delta->abs; + my $warn = $new->cents < -1337 ? " \e[5;1m(!!)\e[0m" : ""; + $_ = $_->string("+") for $old, $new; printf "New balance for $username: $old $sign $abs = \e[${rood}1m$new\e[0m$warn\n", } diff --git a/lib/RevBank/Users.pm b/lib/RevBank/Users.pm index 9683761..5623870 100644 --- a/lib/RevBank/Users.pm +++ b/lib/RevBank/Users.pm @@ -52,9 +52,12 @@ sub update { $new = $old + $delta; my $since = $a[3] // ""; - $since = "+\@" . now() if $new > 0 and (!$since or $old <= 0); - $since = "-\@" . now() if $new < 0 and (!$since or $old >= 0); - $since = "0\@" . now() if $new == 0 and (!$since or $old != 0); + + my $newc = $new->cents; + my $oldc = $old->cents; + $since = "+\@" . now() if $newc > 0 and (!$since or $oldc <= 0); + $since = "-\@" . now() if $newc < 0 and (!$since or $oldc >= 0); + $since = "0\@" . now() if $newc == 0 and (!$since or $oldc != 0); printf {$out} "%-16s %9s %s %s\n", ( $username, $new->string("+"), now(), $since