From: erickson Date: Thu, 1 Apr 2010 19:09:33 +0000 (+0000) Subject: Patch from Joe Atzberger: Cleanup subs in Actor X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=75f644c50d6b13aa121a4a25543e76e27919e1fa;p=evergreen%2Fbjwebb.git Patch from Joe Atzberger: Cleanup subs in Actor For the first, @xact was never used. The 3 part conditional only had two different outcomes. There is still a problem with user_transactions reproducing a lot of the functionality of user_transaction_history, which it already calls to do the real query. But it doesn't reproduce all of it. Recommend relying on user_transaction_history as much as possible, but that kind of work is out of scope for this review. For the other, remove unused var and unnecessary array. You don't need to build an array when all you do at the end is count its elements. Signed-off-by: Joe Atzberger git-svn-id: svn://svn.open-ils.org/ILS/trunk@16092 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index ee3b20394..a37c13aa0 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -1641,31 +1641,15 @@ sub user_transactions { $login_session, $user_id, 'VIEW_USER_TRANSACTIONS' ); return $evt if $evt; - my $api = $self->api_name(); - my $trans; - my @xact; - - if(defined($type)) { @xact = (xact_type => $type); - - } else { @xact = (); } - - ($trans) = $self - ->method_lookup('open-ils.actor.user.transactions.history.still_open') - ->run($login_session => $user_id => $type); - - - if($api =~ /have_charge/o) { - - $trans = [ grep { int($_->total_owed * 100) > 0 } @$trans ]; + my $api = $self->api_name(); - } elsif($api =~ /have_balance/o) { + my ($trans) = $self->method_lookup( + 'open-ils.actor.user.transactions.history.still_open') + ->run( $login_session, $user_id, $type ); - $trans = [ grep { int($_->balance_owed * 100) != 0 } @$trans ]; - } else { - - $trans = [ grep { int($_->total_owed * 100) > 0 } @$trans ]; - - } + $trans = ($api =~ /have_balance/o) ? + [ grep { int($_->balance_owed * 100) != 0 } @$trans ] : + [ grep { int($_->total_owed * 100) > 0 } @$trans ] ; if($api =~ /total/o) { my $total = 0.0; @@ -1677,8 +1661,8 @@ sub user_transactions { return $total; } - if($api =~ /count/o) { return scalar @$trans; } - if($api !~ /fleshed/o) { return $trans; } + ($api =~ /count/o ) and return scalar @$trans; + ($api !~ /fleshed/o) and return $trans; my @resp; for my $t (@$trans) { @@ -1863,17 +1847,15 @@ sub checkedout_count { my $parser = DateTime::Format::ISO8601->new; - my (@out,@overdue); + my $overdue = 0; for my $c (@$circs) { my $due_dt = $parser->parse_datetime( cleanse_ISO8601( $c->due_date ) ); - my $due = $due_dt->epoch; - - if ($due < DateTime->today->epoch) { - push @overdue, $c; + if ($due_dt->epoch < DateTime->today->epoch) { + $overdue++; } } - return { total => scalar(@$circs), overdue => scalar(@overdue) }; + return { total => scalar(@$circs), overdue => $overdue }; }