Add support for user-accessible accounts that are excluded from grandtotal
This commit is contained in:
parent
df8c84672d
commit
d54428b092
4 changed files with 30 additions and 6 deletions
|
@ -33,8 +33,12 @@ sub Tab($self, $method) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delete $completions{USERS}) {
|
if (delete $completions{USERS}) {
|
||||||
$completions{$_}++ for grep !RevBank::Users::is_hidden($_),
|
for my $name (RevBank::Users::names()) {
|
||||||
RevBank::Users::names();
|
next if RevBank::Users::is_hidden($name);
|
||||||
|
|
||||||
|
$completions{ $name }++;
|
||||||
|
$completions{ $1 }++ if $name =~ /^\*(.*)/;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return keys %completions;
|
return keys %completions;
|
||||||
|
|
|
@ -7,17 +7,33 @@ use experimental 'signatures'; # stable since v5.36
|
||||||
use RevBank::Global;
|
use RevBank::Global;
|
||||||
use RevBank::Plugins;
|
use RevBank::Plugins;
|
||||||
use Carp ();
|
use Carp ();
|
||||||
|
use List::Util ();
|
||||||
|
|
||||||
my $filename = "revbank.accounts";
|
my $filename = "revbank.accounts";
|
||||||
|
|
||||||
sub _read() {
|
sub _read() {
|
||||||
my @users;
|
my @users;
|
||||||
/\S/ and push @users, [split " "] for slurp $filename;
|
/\S/ and push @users, [split " "] for slurp $filename;
|
||||||
return { map { lc($_->[0]) => $_ } @users };
|
|
||||||
|
my %users;
|
||||||
|
for (@users) {
|
||||||
|
my $name = $_->[0];
|
||||||
|
if ($name =~ /^\*/) {
|
||||||
|
# user-accessible special account: support without * prefix
|
||||||
|
$users{ lc($name) =~ s/^\*//r } = $_;
|
||||||
|
|
||||||
|
# also support literal account name with * prefix
|
||||||
|
$users{ lc($name) } = $_;
|
||||||
|
} else {
|
||||||
|
# hidden or normal account
|
||||||
|
$users{ lc($name) } = $_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return \%users;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub names() {
|
sub names() {
|
||||||
return map $_->[0], values %{ _read() };
|
return List::Util::uniqstr map $_->[0], values %{ _read() };
|
||||||
}
|
}
|
||||||
|
|
||||||
sub balance($username) {
|
sub balance($username) {
|
||||||
|
@ -73,6 +89,10 @@ sub is_hidden($username) {
|
||||||
return $username =~ /^[-+]/;
|
return $username =~ /^[-+]/;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub is_special($username) {
|
||||||
|
return $username =~ /^[-+*]/;
|
||||||
|
}
|
||||||
|
|
||||||
sub parse_user($username) {
|
sub parse_user($username) {
|
||||||
return undef if is_hidden($username);
|
return undef if is_hidden($username);
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ sub command :Tab(grandtotal) ($self, $cart, $command, @) {
|
||||||
|
|
||||||
for my $line (slurp 'revbank.accounts') {
|
for my $line (slurp 'revbank.accounts') {
|
||||||
my ($username, $balance) = split " ", $line;
|
my ($username, $balance) = split " ", $line;
|
||||||
next if RevBank::Users::is_hidden($username);
|
next if RevBank::Users::is_special($username);
|
||||||
|
|
||||||
my $credit = $balance;
|
my $credit = $balance;
|
||||||
$neg += $credit if $credit < 0;
|
$neg += $credit if $credit < 0;
|
||||||
|
|
2
revbank
2
revbank
|
@ -17,7 +17,7 @@ use RevBank::Global;
|
||||||
use RevBank::Messages;
|
use RevBank::Messages;
|
||||||
use RevBank::Cart;
|
use RevBank::Cart;
|
||||||
|
|
||||||
our $VERSION = "4.1.1";
|
our $VERSION = "4.2.0";
|
||||||
our %HELP1 = (
|
our %HELP1 = (
|
||||||
"abort" => "Abort the current transaction",
|
"abort" => "Abort the current transaction",
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue