revbank/plugins/withdraw
Juerd Waalboer e3a04a0e36 Keep track of cash
First attempt at keeping track of where cash goes using the new hidden
'-cash' account.
2022-06-11 17:18:31 +02:00

26 lines
842 B
Perl

#!perl
HELP1 "withdraw <amount>" => "Withdraw from your account";
sub command :Tab(withdraw) ($self, $cart, $command, @) {
if (defined parse_amount($command)) {
warn "Note: raw amounts for withdrawal or unlisted products are no longer supported.\n\n";
warn "Please use the 'withdraw' command to take money out of your revbank account, or\n";
warn "the 'unlisted' command to pay for an unlisted product.\n\n";
}
$command eq 'withdraw' or return NEXT;
return "Amount to withdraw from your account", \&amount;
}
sub amount($self, $cart, $arg, @) {
my $amount = parse_amount($arg);
defined $amount or return REJECT, "Invalid amount";
$cart
->add(-$amount, "Withdrawal", { is_withdrawal => 1 })
->add_contra("-cash", +$amount, "Withdrawn by \$you");
return ACCEPT;
}