diff --git a/lib/RevBank/Cart/Entry.pm b/lib/RevBank/Cart/Entry.pm index e927e13..91b0138 100644 --- a/lib/RevBank/Cart/Entry.pm +++ b/lib/RevBank/Cart/Entry.pm @@ -38,6 +38,8 @@ sub add_contra($self, $user, $amount, $description) { }; $self->attribute('changed', 1); + + return $self; # for method chaining } sub has_attribute($self, $key) { diff --git a/lib/RevBank/Users.pm b/lib/RevBank/Users.pm index e08ab2b..3eb7f21 100644 --- a/lib/RevBank/Users.pm +++ b/lib/RevBank/Users.pm @@ -24,7 +24,7 @@ sub names() { } sub balance($username) { - return _read()->{ lc $username }->[1]; + return RevBank::Amount->new_from_float( _read()->{ lc $username }->[1] ); } sub since($username) { diff --git a/plugins/skim b/plugins/skim new file mode 100644 index 0000000..c8e0d93 --- /dev/null +++ b/plugins/skim @@ -0,0 +1,35 @@ +#!perl + +# Note: this plugin only makes sense if you have proper cashbox tracking, +# which requires the "deposit_methods" plugin for differentiating between +# bank transfers and cash deposits. +# +# If you ONLY allow cash deposits, and are not using the "deposit_methods" +# plugin, you could alternatively hack the "deposit" plugin to use the "-cash" +# contra instead of the "-deposits/other" contra. + +sub command :Tab(skim,unskim) ($self, $cart, $command, @) { + $command eq 'skim' or $command eq 'unskim' or return NEXT; + + $self->{command} = $command; + + printf "There should be (at least) %s in the cashbox.\n", + -RevBank::Users::balance("-cash"); + + return "Amount to $command", \&amount; +} + +sub amount($self, $cart, $arg, @) { + warn "Use 'unskim' to return (part of) a previously skimmed amount.\n" + if $arg =~ /^-/; + + my $amount = parse_amount($arg) or return REJECT, "Invalid amount"; + $amount = -$amount if $self->{command} eq 'unskim'; + + my $entry = $cart + ->add(0, "Skimmed $amount", { is_withdrawal => 1 }) + ->add_contra("-cash", +$amount, "Skimmed by \$you") + ->add_contra("-cash/skimmed", -$amount, "Skimmed by \$you"); + + return ACCEPT; +} diff --git a/revbank.plugins b/revbank.plugins index 40267a8..186fc43 100644 --- a/revbank.plugins +++ b/revbank.plugins @@ -30,4 +30,5 @@ withdraw # matches amounts users # matches usernames deposit # wants to be after 'users' #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))