Use amount object directly internally,
instead of relying on operator overloading, but keep the ones where direct use would result in overly messy code.
This commit is contained in:
parent
58f49cbffb
commit
1661661ffd
3 changed files with 17 additions and 13 deletions
|
@ -128,14 +128,14 @@ sub as_loggable {
|
||||||
my $description =
|
my $description =
|
||||||
$quantity == 1
|
$quantity == 1
|
||||||
? $_->{description}
|
? $_->{description}
|
||||||
: sprintf("%s [%sx %s]", $_->{description}, $quantity, abs($_->{amount}));
|
: sprintf("%s [%sx %s]", $_->{description}, $quantity, $_->{amount}->abs);
|
||||||
|
|
||||||
push @s, sprintf(
|
push @s, sprintf(
|
||||||
"%-12s %4s %3d %5s # %s",
|
"%-12s %4s %3d %5s # %s",
|
||||||
$_->{user},
|
$_->{user},
|
||||||
($total > 0 ? 'GAIN' : $total < 0 ? 'LOSE' : ''),
|
($total->cents > 0 ? 'GAIN' : $total->cents < 0 ? 'LOSE' : ''),
|
||||||
$quantity,
|
$quantity,
|
||||||
abs($total),
|
$total->abs,
|
||||||
$description
|
$description
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ sub hook_cart_changed {
|
||||||
|
|
||||||
if (not $cart->entries('refuse_checkout')) {
|
if (not $cart->entries('refuse_checkout')) {
|
||||||
my $sum = $cart->sum;
|
my $sum = $cart->sum;
|
||||||
my $what = $sum > 0 ? "add" : "pay";
|
my $what = $sum->cents > 0 ? "add" : "pay";
|
||||||
my $abs = $sum->abs;
|
my $abs = $sum->abs;
|
||||||
say "Enter username to $what $abs; type 'abort' to abort.";
|
say "Enter username to $what $abs; type 'abort' to abort.";
|
||||||
}
|
}
|
||||||
|
@ -52,10 +52,11 @@ sub hook_reject {
|
||||||
|
|
||||||
sub hook_user_balance {
|
sub hook_user_balance {
|
||||||
my ($class, $username, $old, $delta, $new) = @_;
|
my ($class, $username, $old, $delta, $new) = @_;
|
||||||
my $sign = $delta >= 0 ? '+' : '-';
|
my $sign = $delta->cents >= 0 ? '+' : '-';
|
||||||
my $rood = $new < 0 ? '31;' : '';
|
my $rood = $new->cents < 0 ? '31;' : '';
|
||||||
my $abs = abs($delta);
|
my $abs = $delta->abs;
|
||||||
my $warn = $new < -13.37 ? " \e[5;1m(!!)\e[0m" : "";
|
my $warn = $new->cents < -1337 ? " \e[5;1m(!!)\e[0m" : "";
|
||||||
|
|
||||||
$_ = $_->string("+") for $old, $new;
|
$_ = $_->string("+") for $old, $new;
|
||||||
printf "New balance for $username: $old $sign $abs = \e[${rood}1m$new\e[0m$warn\n",
|
printf "New balance for $username: $old $sign $abs = \e[${rood}1m$new\e[0m$warn\n",
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,9 +52,12 @@ sub update {
|
||||||
$new = $old + $delta;
|
$new = $old + $delta;
|
||||||
|
|
||||||
my $since = $a[3] // "";
|
my $since = $a[3] // "";
|
||||||
$since = "+\@" . now() if $new > 0 and (!$since or $old <= 0);
|
|
||||||
$since = "-\@" . now() if $new < 0 and (!$since or $old >= 0);
|
my $newc = $new->cents;
|
||||||
$since = "0\@" . now() if $new == 0 and (!$since or $old != 0);
|
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", (
|
printf {$out} "%-16s %9s %s %s\n", (
|
||||||
$username, $new->string("+"), now(), $since
|
$username, $new->string("+"), now(), $since
|
||||||
|
|
Loading…
Add table
Reference in a new issue