revbank/plugins/grandtotal
2022-08-29 17:50:12 +02:00

26 lines
654 B
Perl

#!perl
HELP "grandtotal" => "Summary of all accounts";
sub command :Tab(grandtotal) ($self, $cart, $command, @) {
return NEXT if $command ne 'grandtotal';
my $pos = 0;
my $neg = 0;
for my $line (slurp 'revbank.accounts') {
my ($username, $balance) = split " ", $line;
next if RevBank::Users::is_hidden($username);
my $credit = $balance;
$neg += $credit if $credit < 0;
$pos += $credit if $credit > 0;
}
printf "Total positive: %8.2f\n", $pos;
printf "Total negative: \e[31;1m%8.2f\e[0m\n", $neg;
printf "GRAND TOTAL: \e[1m%8.2f\e[0m\n", $pos + $neg;
return ACCEPT;
}