v9.0.0: rename 'user' to 'account' where appropriate

This commit is contained in:
Juerd Waalboer 2025-04-10 23:03:55 +02:00
parent 996159a2ad
commit 4c90277fa9
33 changed files with 249 additions and 172 deletions

View file

@ -34,7 +34,7 @@ sub username($self, $cart, $name, @) {
if any sub { $_ eq $name }, $plugin->Tab('command');
}
RevBank::Users::create( $name );
RevBank::Accounts::create( $name );
return ACCEPT;
}

View file

@ -31,13 +31,13 @@ sub command :Tab(cash) ($self, $cart, $command, @) {
sub hook_cash($class, @) {
printf "There should currently be (at least) %s in the cash box.\n",
-RevBank::Users::balance("-cash") || "0.00";
-RevBank::Accounts::balance("-cash") || "0.00";
}
our $suppress = 0;
sub hook_user_balance($class, $username, $old, $delta, $new, @) {
return if $username ne '-cash' or $delta->cents == 0;
sub hook_account_balance($class, $account, $old, $delta, $new, @) {
return if $account ne '-cash' or $delta->cents == 0;
return if $suppress;
# "-" accounts need to be inverted to display the intuitive value.
@ -55,7 +55,7 @@ sub hook_user_balance($class, $username, $old, $delta, $new, @) {
my $confirm_prompt = "Type 'fix pls' to apply a permanent correction, or 'abort' to abort";
sub check($self, $cart, $arg, @) {
my $should = -RevBank::Users::balance("-cash") || parse_amount(0);
my $should = -RevBank::Accounts::balance("-cash") || parse_amount(0);
my $have = parse_amount($arg);
return REJECT, "Invalid amount" if not defined $have;
@ -94,7 +94,7 @@ sub confirm($self, $cart, $arg, @) {
$cart->checkout('-expenses/discrepancies');
printf "\nDiscrepancy recorded; corrected cash box amount is %s.\n",
-RevBank::Users::balance("-cash") || "0.00";
-RevBank::Accounts::balance("-cash") || "0.00";
return ACCEPT;
}

View file

@ -15,8 +15,8 @@ sub hook_cash {
open_drawer();
}
sub hook_checkout($class, $cart, $user, $transaction_id, @) {
$user eq '-cash' or return;
sub hook_checkout($class, $cart, $account, $transaction_id, @) {
$account eq '-cash' or return;
open_drawer();
}

View file

@ -23,7 +23,7 @@ use List::Util qw(sum);
my $iban = "NL99ABCD1234567890";
my $beneficiary = "Account Name";
sub hook_checkout($class, $cart, $user, $transaction_id, @) {
sub hook_checkout($class, $cart, $account, $transaction_id, @) {
my @entries = $cart->entries("is_deposit");
my $amount = sum map $_->{amount}, grep $_->attribute('method') eq 'iban', @entries;
@ -41,7 +41,7 @@ sub hook_checkout($class, $cart, $user, $transaction_id, @) {
"EUR" . $amount, # Amount
"",
"",
"rb $user",
"rb $account",
"",
);
close $in;

View file

@ -5,7 +5,7 @@ HELP "dinnerbonus" => "Add fee for cooking supplies";
my $bonus = 1.00;
sub command :Tab(kookbonus,dinnerbonus) ($self, $cart, $command, @) {
my @users = map $_->{user}, map $_->contras, $cart->entries('is_take');
my @users = map $_->{account}, map $_->contras, $cart->entries('is_take');
(@users and $command eq 'kookpotje') # common mistake promoted to feature
or $command eq 'kookbonus'

View file

@ -9,8 +9,8 @@ sub command :Tab(grandtotal) ($self, $cart, $command, @) {
my $neg = 0;
for my $line (slurp 'revbank.accounts') {
my ($username, $balance) = split " ", $line;
next if RevBank::Users::is_special($username);
my ($account, $balance) = split " ", $line;
next if RevBank::Accounts::is_special($account);
my $credit = RevBank::Amount->parse_string($balance) or next;
$neg += $credit if $credit < 0;

View file

@ -75,17 +75,17 @@ sub hook_retry($class, $plugin, $reason, $abort, @) {
_log({ _ => "RETRY", plugin => $plugin, reason => $reason, abort => $abort });
}
sub hook_user_created($class, $username, @) {
_log({ _ => "NEWUSER", account => $username });
sub hook_account_created($class, $account, @) {
_log({ _ => "NEWUSER", account => $account });
}
# NB: stringify transaction_id because future ids might not be numeric.
sub hook_user_balance($class, $user, $old, $delta, $new, $transaction_id, @) {
_log({ _ => "BALANCE", account => $user, old => $old, delta => $delta, new => $new, transaction_id => "$transaction_id" });
sub hook_account_balance($class, $account, $old, $delta, $new, $transaction_id, @) {
_log({ _ => "BALANCE", account => $account, old => $old, delta => $delta, new => $new, transaction_id => "$transaction_id" });
}
sub hook_checkout($class, $cart, $username, $transaction_id, @) {
_log({ _ => "CHECKOUT", account => $username, transaction_id => "$transaction_id" });
sub hook_checkout($class, $cart, $account, $transaction_id, @) {
_log({ _ => "CHECKOUT", account => $account, transaction_id => "$transaction_id" });
}

View file

@ -30,18 +30,18 @@ sub hook_retry($class, $plugin, $reason, $abort, @) {
_log(RETRY => "[$plugin] $reason");
}
sub hook_user_created($class, $username, @) {
_log(NEWUSER => "$username");
sub hook_account_created($class, $account, @) {
_log(NEWUSER => "$account");
}
sub hook_user_balance($class, $user, $old, $delta, $new, $transaction_id, @) {
sub hook_account_balance($class, $account, $old, $delta, $new, $transaction_id, @) {
my $lost = $delta < 0 ? "lost" : "got";
$delta = $delta->abs;
$_ = $_->string("+") for $old, $new;
_log(BALANCE => "$transaction_id $user had $old, $lost $delta, now has $new");
_log(BALANCE => "$transaction_id $account had $old, $lost $delta, now has $new");
}
sub hook_checkout($class, $cart, $username, $transaction_id, @) {
sub hook_checkout($class, $cart, $account, $transaction_id, @) {
_log(CHECKOUT => "$transaction_id $_") for map $_->as_loggable, $cart->entries;
}

View file

@ -35,7 +35,7 @@ sub _inform($unresolved, $username, $skip_print = 0) {
my $broke_users = $entry->attribute('nomoney_users');
for my $account (sort keys %$broke_users) {
my $balance = RevBank::Users::balance($account);
my $balance = RevBank::Accounts::balance($account);
my $m = sprintf(
"%s have %s",
@ -60,9 +60,9 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
for my $account (keys %$deltas) {
next if $deltas->{$account} > 0;
next if RevBank::Users::is_special($account);
next if RevBank::Accounts::is_special($account);
my $old = $balances{$account} = RevBank::Users::balance($account);
my $old = $balances{$account} = RevBank::Accounts::balance($account);
my $new = $old + $deltas->{$account};
next if $new >= 0 or $new > $old;
@ -73,14 +73,14 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
next if none { $plugin eq $_ } @deny_plugins;
my @contra_users = uniqstr sort grep {
not RevBank::Users::is_special($_)
not RevBank::Accounts::is_special($_)
and $_ ne $username
} map {
$_->{user}
$_->{account}
} $entry->contras;
next if $allow_multi_user and @contra_users > 1;
next if none { $account eq $_ } $entry->user // $username, @contra_users;
next if none { $account eq $_ } $entry->account // $username, @contra_users;
$unresolved->add_entry($entry);
}
@ -112,7 +112,7 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
$entry->attribute('nomoney_users', \%broke_users);
for my $account (keys %$trial_deltas) {
next if RevBank::Users::is_special($account);
next if RevBank::Accounts::is_special($account);
next if $trial_deltas->{$account} > 0;
my $trial_balance = $resolved_balances{$account} + $trial_deltas->{$account};
@ -144,11 +144,11 @@ sub hook_abort($class, $cart, @) {
return;
}
sub hook_checkout_done($class, $cart, $username, $transaction_id, @) {
sub hook_checkout_done($class, $cart, $account, $transaction_id, @) {
my $n = $unresolved{$cart}->size or return;
print "\n";
_inform($unresolved{$cart}, $username);
_inform($unresolved{$cart}, $account);
delete $unresolved{$cart};
my $message = $n == 1 ? "THIS ENTRY WAS IGNORED" : "THESE ENTRIES WERE IGNORED";

View file

@ -35,7 +35,7 @@ sub data($self, $cart, $input, @) {
return ACCEPT;
}
sub hook_checkout($class, $cart, $username, $transaction_id, @) {
sub hook_checkout($class, $cart, $account, $transaction_id, @) {
my @barcodes;
for my $entry ($cart->entries('is_barcode')) {
push @barcodes, ($entry->attribute('barcode_data')) x $entry->quantity;

View file

@ -1,7 +1,7 @@
#!perl
sub hook_user_balance($class, $username, $old, $delta, $new, $transaction_id, @) {
my $msg = "$transaction_id ($username)";
sub hook_account_balance($class, $account, $old, $delta, $new, $transaction_id, @) {
my $msg = "$transaction_id ($account)";
$msg =~ s/[^\x20-\x7E]//g;
$msg =~ s/'//g;

View file

@ -57,7 +57,7 @@ sub hook_abort($class, $cart, $reason, @) {
for @ids;
}
sub hook_checkout($class, $cart, $user, $transaction_id, @) {
sub hook_checkout($class, $cart, $account, $transaction_id, @) {
# Opportunistic; ignore failures. Can't do anything about it anyway.
my @ids = map $_->attribute('mollie_id'), $cart->entries('mollie_id');

View file

@ -2,7 +2,7 @@
use Net::MQTT::Simple "mosquitto.space.revspace.nl";
sub hook_checkout($class, $cart, $user, $transaction_id, @) {
sub hook_checkout($class, $cart, $account, $transaction_id, @) {
my $filename = "revbank.sales";
my @entries = $cart->entries('product_id') or return;
my %already_retained;

View file

@ -10,16 +10,16 @@ sub _box(@lines) {
);
}
sub hook_checkout_done($class, $cart, $user, $transaction_id, @) {
defined $user or return; # hacks like 'undo' don't have an acting user
RevBank::Users::is_hidden($user) and return;
sub hook_checkout_done($class, $cart, $account, $transaction_id, @) {
defined $account or return; # hacks like 'undo' don't have an acting user
RevBank::Accounts::is_hidden($account) and return;
my $balance = RevBank::Users::balance($user) or return;
my $since = RevBank::Users::since($user);
my $balance = RevBank::Accounts::balance($account) or return;
my $since = RevBank::Accounts::since($account);
if ($balance < -22.00) {
_box(
"Hoi $user,",
"Hoi $account,",
"",
"Je saldo is $balance en dus lager dan toegestaan. Graag meteen aanvullen!",
"Zodra je een positief saldo hebt, mag je weer producten kopen.",
@ -33,7 +33,7 @@ sub hook_checkout_done($class, $cart, $user, $transaction_id, @) {
and $1 lt strftime('%Y-%m-%d_%H:%M:%S', localtime(time() - 14 * 86400))
) {
_box(
"Hoi $user,",
"Hoi $account,",
"",
"Je staat al sinds $1 negatief, dus meer dan 2 weken. Deelnemers",
"mogen rood staan, maar niet langdurig. Wil je je saldo even aanvullen?",

View file

@ -125,7 +125,7 @@ sub hook_undo($class, $cart) {
# Undo deposit refund: prohibit
for my $contra ($entry->contras) {
next if $contra->{amount} < 0;
next if List::Util::none { $contra->{user} eq $_ } _addon_accounts;
next if List::Util::none { $contra->{account} eq $_ } _addon_accounts;
return ABORT, "Sorry, deposit refunds cannot be undone.";
}
@ -151,14 +151,14 @@ sub _handle_undo($cart) {
}
}
sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
if ($username eq '-undo') {
sub hook_checkout_prepare($class, $cart, $account, $transaction_id, @) {
if ($account eq '-undo') {
_handle_undo($cart);
return;
}
# Read data
my $tokens_by_type = _read->{lc $username};
my $tokens_by_type = _read->{lc $account};
my $is_new = !defined $tokens_by_type;
$tokens_by_type = {} if $is_new;
my $time_is_reliable = _time_is_reliable;
@ -235,15 +235,15 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
# Store data
call_hooks(
"log_info",
"statiegeld_tokens: ${\scalar @created } created for $username: @created"
"statiegeld_tokens: ${\scalar @created } created for $account: @created"
) if @created;
call_hooks(
"log_info",
"statiegeld_tokens: ${\scalar @used } used by $username: @used"
"statiegeld_tokens: ${\scalar @used } used by $account: @used"
) if @used;
_write $username, $tokens_by_type, $is_new if $tokens_changed;
_write $account, $tokens_by_type, $is_new if $tokens_changed;
return ABORT if %warnings_by_type and not $cart->size;

View file

@ -21,7 +21,7 @@
}
}
sub hook_checkout($class, $cart, $user, $transaction_id, @) {
sub hook_checkout($class, $cart, $account, $transaction_id, @) {
# Hack42 for some reason used the dutch word in their revbank1 hack.
my $filename = -e("revbank.voorraad")
? "revbank.voorraad"

View file

@ -15,7 +15,7 @@ sub command :Tab(tail) ($self, $cart, $command, @) {
my ($dt, $c, $t_id, $u, $dir, $qty, $amount, undef, $desc) = split " ", $_, 9;
$c eq 'CHECKOUT' or next; # real check after expensive split
RevBank::Users::is_hidden($u) and next;
RevBank::Accounts::is_hidden($u) and next;
shift @lines if @lines == $n;

View file

@ -12,7 +12,7 @@ sub command :Tab(undeposit) ($self, $cart, $command, @) {
warn "\n\n\n";
warn "Enter 'abort' to abort.\n";
@TAB = grep /^[-+]deposit/, RevBank::Users::names
@TAB = grep /^[-+]deposit/, RevBank::Accounts::names
or return REJECT, "No contras available.";
print "Available contras:\n", map " $_\n", sort(@TAB);

View file

@ -13,11 +13,11 @@ sub command :Tab(undo) ($self, $cart, $command, @) {
my @log;
for my $line (slurp $filename) {
my ($tid, $user, $delta, $dt) = split " ", $line;
my ($tid, $account, $delta, $dt) = split " ", $line;
if (@log and $log[-1]{tid} eq $tid) {
push @{ $log[-1]{deltas} }, [ $user, $delta ];
push @{ $log[-1]{deltas} }, [ $account, $delta ];
} else {
push @log, { tid => $tid, dt => $dt, deltas => [ [ $user, $delta ] ] };
push @log, { tid => $tid, dt => $dt, deltas => [ [ $account, $delta ] ] };
}
}
@ -49,11 +49,11 @@ sub undo :Tab(&tab) ($self, $cart, $tid, @) {
return with_lock {
for my $line (slurp $filename) {
if ($line =~ /^\Q$tid\E\s/) {
my (undef, $user, $delta) = split " ", $line;
my (undef, $account, $delta) = split " ", $line;
$entry ||= $cart->add(0, $description, { undo_transaction_id => $tid });
$entry->add_contra($user, $delta, "Undo $tid");
$entry->add_contra($account, $delta, "Undo $tid");
}
}
@ -68,8 +68,8 @@ sub undo :Tab(&tab) ($self, $cart, $tid, @) {
};
}
sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
$username eq '-undo' or return;
sub hook_checkout_prepare($class, $cart, $account, $transaction_id, @) {
$account eq '-undo' or return;
for my $entry ($cart->entries) {
my $undo_tid = $entry->attribute('undo_transaction_id')
@ -85,8 +85,8 @@ sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
}
}
sub hook_user_balance($class, $username, $old, $delta, $new, $transaction_id, @) {
sub hook_account_balance($class, $account, $old, $delta, $new, $transaction_id, @) {
return if $doing_undo; # don't allow undoing undos
append $filename, join(" ", $transaction_id, $username, -$delta, now()), "\n";
append $filename, join(" ", $transaction_id, $account, -$delta, now()), "\n";
}

View file

@ -91,7 +91,7 @@ sub _recent($n, $u) {
sub balance($self, $u) {
_recent(10, $u);
call_hooks("user_info", $u);
my $balance = RevBank::Users::balance($u);
my $balance = RevBank::Accounts::balance($u);
my $red = $balance->cents < 0 ? "31;" : "";
printf "Balance for $u is \e[%s1m%s\e[0m\n", $red, $balance->string("+");
say "NB: Products/amounts/commands FIRST, username LAST.";

View file

@ -2,26 +2,26 @@ sub _read_vat {
my %vat;
for my $line (slurp "revbank.vat") {
my ($match, $vataccount, $pct) = split " ", $line;
$vat{lc $match} = { user => $vataccount, pct => $pct };
$vat{lc $match} = { account => $vataccount, pct => $pct };
}
return \%vat;
}
sub hook_checkout_prepare($class, $cart, $username, $transaction_id, @) {
sub hook_checkout_prepare($class, $cart, $account, $transaction_id, @) {
my $config = _read_vat;
for my $entry ($cart->entries) {
for my $contra ($entry->contras) {
my $vat = $config->{ lc $contra->{user} } or next;
my $vat = $config->{ lc $contra->{account} } or next;
my $amount = RevBank::Amount->new(
$contra->{amount}->cents * $vat->{pct} / (100 + $vat->{pct})
);
my $desc = "VAT ($vat->{pct}% * $contra->{amount})";
my $display = RevBank::Users::is_hidden($contra->{user}) ? undef : $desc;
$entry->add_contra($contra->{user}, -$amount, $desc, $display);
$entry->add_contra($vat->{user}, +$amount, $desc);
my $display = RevBank::Accounts::is_hidden($contra->{account}) ? undef : $desc;
$entry->add_contra($contra->{account}, -$amount, $desc, $display);
$entry->add_contra($vat->{account}, +$amount, $desc);
}
}
}