revbank/plugins/users
Juerd Waalboer fa60e1081a chmod 644 plugins/*
Undoes 714b337 because github seems to no longer require chmod +x
for syntax highlighting extensionless files.
2019-08-07 15:42:16 +02:00

58 lines
1.5 KiB
Perl

#!perl
HELP "<account>" => "[Pay with your account and] show balance";
HELP "list" => "List accounts and balances";
HELP "shame" => "Display Hall of Shame (negative balances)";
sub command :Tab(list,ls,shame,USERS) {
my ($self, $cart, $command) = @_;
return $self->list if $command eq 'list';
return $self->list if $command eq 'ls';
return $self->shame if $command eq 'shame';
my $user = parse_user($command)
or return NEXT;
return $self->balance($user) if not $cart->size;
$cart->checkout($user);
return ACCEPT;
}
sub hook_checkout {
my ($class, $cart, $user, $transaction_id) = @_;
my $line = "-" x 40;
say "/$line";
say "| Final (transaction ID = $transaction_id):";
$cart->display("| ");
say "\\$line";
}
sub list {
system "sort -f revbank.accounts | grep -v ^# | perl -pe's/( -[\\d.]+)/\\e[31;1m\$1\\e[0m/' | more";
return ACCEPT;
}
sub shame {
system "sort -k2 -n revbank.accounts | grep -v ^# | grep -- ' -' | perl -pe's/( -[\\d.]+)/\\e[31;1m\$1\\e[0m/' | more";
return ACCEPT;
}
sub recent {
my ($n, $u) = @_;
$n += 0;
print "Last $n transactions for $u:\n";
system "perl -lane'lc(\$F[3]) eq lc(qq[\Q$u\E]) or next; s/CHECKOUT\\s+\\S+\\s+\\S+\\s+// or next; s/ #// or next; s/_/ /; print' .revbank.log | tail -n$n";
}
sub balance {
my ($self, $u) = @_;
recent(10, $u);
printf "Balance for $u is \e[1m%+.2f\e[0m\n", RevBank::Users::balance($u);
say "NB: Products/amounts/commands FIRST, username LAST.";
return ABORT;
}