Add cash box tracking with new plugin "cash"
This commit is contained in:
parent
681db369e7
commit
064841c25e
5 changed files with 64 additions and 9 deletions
|
@ -82,7 +82,9 @@ sub checkout($self, $user) {
|
||||||
my $transaction_id = time() - 1300000000;
|
my $transaction_id = time() - 1300000000;
|
||||||
RevBank::Plugins::call_hooks("checkout", $self, $user, $transaction_id);
|
RevBank::Plugins::call_hooks("checkout", $self, $user, $transaction_id);
|
||||||
|
|
||||||
for my $account (keys %deltas) {
|
for my $account (reverse sort keys %deltas) {
|
||||||
|
# The reverse sort is a lazy way to make the "-" accounts come last,
|
||||||
|
# which looks nicer with the "cash" plugin.
|
||||||
RevBank::Users::update($account, $deltas{$account}, $transaction_id)
|
RevBank::Users::update($account, $deltas{$account}, $transaction_id)
|
||||||
if $deltas{$account} != 0;
|
if $deltas{$account} != 0;
|
||||||
}
|
}
|
||||||
|
|
42
plugins/cash
Normal file
42
plugins/cash
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#!perl
|
||||||
|
|
||||||
|
# Use this plugin for cashbox contents tracking. For it to make sense,
|
||||||
|
# you will also need the "deposit_methods" plugin to let users distinguish
|
||||||
|
# between cash deposits and other deposit methods.
|
||||||
|
|
||||||
|
# This plugin should be loaded *before* the 'stock' plugin in
|
||||||
|
# the 'revbank.plugins' configuration file.
|
||||||
|
|
||||||
|
HELP1 "cash" => "Checkout without a user account";
|
||||||
|
|
||||||
|
sub command :Tab(cash) ($self, $cart, $command, @) {
|
||||||
|
return NEXT if $command ne 'cash';
|
||||||
|
|
||||||
|
if ($cart->size) {
|
||||||
|
$cart->checkout('-cash');
|
||||||
|
} else {
|
||||||
|
call_hooks 'cash';
|
||||||
|
}
|
||||||
|
|
||||||
|
return ACCEPT;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub hook_cash($class, @) {
|
||||||
|
printf "There should currently be (at least) %s in the cash box.\n",
|
||||||
|
-RevBank::Users::balance("-cash");
|
||||||
|
}
|
||||||
|
|
||||||
|
sub hook_user_balance($class, $username, $old, $delta, $new, @) {
|
||||||
|
return if $username ne '-cash' or $delta->cents == 0;
|
||||||
|
|
||||||
|
# "-" accounts need to be inverted to display the intuitive value.
|
||||||
|
my $actual_delta = -$delta;
|
||||||
|
my $actual_new = -$new;
|
||||||
|
|
||||||
|
printf "\nProceed to %s %s %s the cash box;\n it should then have (at least) %s%s.\n",
|
||||||
|
($actual_delta->cents < 0 ? "remove" : "put"),
|
||||||
|
abs($delta),
|
||||||
|
($actual_delta->cents < 0 ? "from" : "into"),
|
||||||
|
$actual_new,
|
||||||
|
($actual_delta->cents < 0 ? " remaining" : " in it");
|
||||||
|
}
|
|
@ -13,8 +13,7 @@ sub command :Tab(skim,unskim) ($self, $cart, $command, @) {
|
||||||
|
|
||||||
$self->{command} = $command;
|
$self->{command} = $command;
|
||||||
|
|
||||||
printf "There should be (at least) %s in the cashbox.\n",
|
call_hooks("cash");
|
||||||
-RevBank::Users::balance("-cash");
|
|
||||||
|
|
||||||
return "Amount to $command", \&amount;
|
return "Amount to $command", \&amount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
#!perl
|
#!perl
|
||||||
|
|
||||||
HELP1 "cash" => "Checkout without a user account";
|
{
|
||||||
|
# If you want to keep track of stock, you need a way for people to
|
||||||
|
# register cash payments. The 'cash' plugin takes care of that, but
|
||||||
|
# that also assumes deposit_methods. So here's a minimal fallback
|
||||||
|
# implementation for the 'cash' command.
|
||||||
|
|
||||||
sub command :Tab(cash) ($self, $cart, $command, @) {
|
# If you use the 'cash' plugin, make sure it is loaded *before*
|
||||||
return NEXT if $command ne 'cash';
|
# the 'stock' plugin in 'revbank.plugins'.
|
||||||
|
|
||||||
$cart->checkout('-cash');
|
HELP1 "cash" => "Checkout without a user account";
|
||||||
|
|
||||||
return ACCEPT;
|
sub command :Tab(cash) ($self, $cart, $command, @) {
|
||||||
|
return NEXT if $command ne 'cash';
|
||||||
|
return NEXT if not $cart->size;
|
||||||
|
|
||||||
|
$cart->checkout('-cash');
|
||||||
|
|
||||||
|
return ACCEPT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub hook_checkout($class, $cart, $user, $transaction_id, @) {
|
sub hook_checkout($class, $cart, $user, $transaction_id, @) {
|
||||||
|
|
|
@ -14,6 +14,8 @@ grandtotal
|
||||||
take
|
take
|
||||||
split
|
split
|
||||||
#pfand # makes little sense in a self service environment
|
#pfand # makes little sense in a self service environment
|
||||||
|
#cash # cash tracking also requires deposit_methods to make sense
|
||||||
|
#skim # cash tracking also requires deposit_methods to make sense
|
||||||
stock
|
stock
|
||||||
unlisted
|
unlisted
|
||||||
#warnings
|
#warnings
|
||||||
|
@ -30,5 +32,4 @@ withdraw # matches amounts
|
||||||
users # matches usernames
|
users # matches usernames
|
||||||
deposit # wants to be after 'users'
|
deposit # wants to be after 'users'
|
||||||
#deposit_methods # Extra options for 'deposit'. Edit/configure first!
|
#deposit_methods # Extra options for 'deposit'. Edit/configure first!
|
||||||
#skim # only makes sense if you also use deposit_methods
|
|
||||||
#deposit_iban_qr # QR code display, edit/configure first! (needs qrencode(1))
|
#deposit_iban_qr # QR code display, edit/configure first! (needs qrencode(1))
|
||||||
|
|
Loading…
Add table
Reference in a new issue