Get 'cash' working again

Now implemented via a hidden user called '-cash'.

This also introduces the concept of hidden accounts, that begin with '+' or
'-', for result accounts and balance accounts. Future versions can further
use this for more detailed bookkeeping. The idea behind the sign is that
'-' accounts should be inverted to get the intuitive value. So if the account
'-cash' has -13.37, that means there should be +13.37 in the cash box (or,
well, once the rest of this is implemented and the initial values are then set
correctly.)
This commit is contained in:
Juerd Waalboer 2022-06-11 16:58:20 +02:00
parent f262bce57c
commit ccae71021a
6 changed files with 27 additions and 4 deletions

View file

@ -13,8 +13,10 @@ use base 'RevBank::Plugin';
BEGIN {
RevBank::Plugins::register("RevBank::Messages");
*hidden = \&RevBank::Users::is_hidden;
}
sub command { return NEXT; }
sub id { 'built in messages' }
@ -53,6 +55,8 @@ sub hook_reject($class, $plugin, $reason, $abort, @) {
}
sub hook_user_balance($class, $username, $old, $delta, $new, @) {
return if hidden $username;
my $sign = $delta->cents >= 0 ? '+' : '-';
my $rood = $new->cents < 0 ? '31;' : '';
my $abs = $delta->abs;
@ -63,6 +67,8 @@ sub hook_user_balance($class, $username, $old, $delta, $new, @) {
}
sub hook_user_created($class, $username, @) {
return if hidden $username;
say "New account '$username' created.";
}