Bug 11665: (follow-up) simplify code
authorGalen Charlton <gmc@esilibrary.com>
Sun, 4 May 2014 19:13:44 +0000 (19:13 +0000)
committerGalen Charlton <gmc@esilibrary.com>
Sun, 4 May 2014 19:13:44 +0000 (19:13 +0000)
This patch replaces some of the logic with more direct
Boolean expressions.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
acqui/neworderempty.pl
circ/reserveratios.pl

index f82b1ab..bc73a8d 100755 (executable)
@@ -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,
index f7abddb..216fb0b 100755 (executable)
@@ -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;
 }