From 13fe2e013d88945aaa372f0c394a2464ca986786 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Sun, 4 May 2014 19:13:44 +0000 Subject: [PATCH] Bug 11665: (follow-up) simplify code This patch replaces some of the logic with more direct Boolean expressions. Signed-off-by: Galen Charlton --- acqui/neworderempty.pl | 11 ++++------- circ/reserveratios.pl | 28 +++++++++++++--------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index f82b1ab54c..bc73a8dd36 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -360,13 +360,10 @@ my @gst_values = map { option => $_ + 0.0 }, split( '\|', C4::Context->preference("gist") ); -my $quantity = $data->{'quantity'}; -{ - defined($quantity) && last; - my $rr_quantity_to_order = $input->param('rr_quantity_to_order'); - (defined($rr_quantity_to_order) && $rr_quantity_to_order) || last; - $quantity = $rr_quantity_to_order; -} +my $quantity = $input->param('rr_quantity_to_order') ? + $input->param('rr_quantity_to_order') : + $data->{'quantity'}; +$quantity //= 0; $template->param( existing => $biblionumber, diff --git a/circ/reserveratios.pl b/circ/reserveratios.pl index f7abddb43e..216fb0b638 100755 --- a/circ/reserveratios.pl +++ b/circ/reserveratios.pl @@ -166,13 +166,9 @@ while ( my $data = $sth->fetchrow_hashref ) { ); } -{ - for my $rd ( @reservedata ) { - $rd->{biblionumber} || next; - my $pcnt = CountPendingOrdersByBiblionumber( $rd->{biblionumber} ); - $pcnt || next; - $rd->{pendingorders} = $pcnt; - } +for my $rd ( @reservedata ) { + next unless $rd->{biblionumber}; + $rd->{pendingorders} = CountPendingOrdersByBiblionumber( $rd->{biblionumber} ); } $template->param( @@ -189,13 +185,15 @@ output_html_with_http_headers $input, $cookie, $template->output; sub CountPendingOrdersByBiblionumber { my $biblionumber = shift; my @orders = GetOrdersByBiblionumber( $biblionumber ); - scalar(@orders) || return(0); - my $cnt=0; for my $order ( @orders ) { - defined($order->{datecancellationprinted}) && $order->{datecancellationprinted} && next; - my $onum = $order->{quantity} // 0; - my $rnum = $order->{quantityreceived} // 0; - $rnum >= $onum && next; - $cnt+=$onum; $cnt-=$rnum; + my $cnt = 0; + if (scalar(@orders)) { + for my $order ( @orders ) { + next if $order->{datecancellationprinted}; + my $onum = $order->{quantity} // 0; + my $rnum = $order->{quantityreceived} // 0; + next if $rnum >= $onum; + $cnt += ($onum - $rnum); + } } - $cnt; + return $cnt; } -- 2.39.5