Bug 13757: OPAC changes
[koha.git] / circ / reserveratios.pl
index bd51b7c..56c84d8 100755 (executable)
@@ -83,6 +83,16 @@ push @query_params, output_pref({ dt => $startdate, dateformat => 'iso' }) ;
 $sqldatewhere .= " AND reservedate <= ?";
 push @query_params, output_pref({ dt => $enddate, dateformat => 'iso' });
 
+my $include_aqorders_qty =
+  C4::Context->preference('AcqCreateItem') eq 'receiving'
+  ? '+ COALESCE(aqorders.quantity, 0) - COALESCE(aqorders.quantityreceived, 0)'
+  : q{};
+
+my $include_aqorders_qty_join =
+  C4::Context->preference('AcqCreateItem') eq 'receiving'
+  ? 'LEFT JOIN aqorders ON reserves.biblionumber=aqorders.biblionumber'
+  : q{};
+
 my $nfl_comparison = $include_ordered ? '<=' : '=';
 my $strsth =
 "SELECT reservedate,
@@ -93,24 +103,25 @@ my $strsth =
         items.itemcallnumber,
         items.itemnumber,
         GROUP_CONCAT(DISTINCT items.itemcallnumber 
-                       ORDER BY items.itemnumber SEPARATOR '<br/>') as listcall,
+            ORDER BY items.itemnumber SEPARATOR '|') as listcall,
         GROUP_CONCAT(DISTINCT homebranch
-            ORDER BY items.itemnumber SEPARATOR '<br/>') as homebranch_list,
+            ORDER BY items.itemnumber SEPARATOR '|') as homebranch_list,
         GROUP_CONCAT(DISTINCT holdingbranch 
-            ORDER BY items.itemnumber SEPARATOR '<br/>') as holdingbranch_list,
+            ORDER BY items.itemnumber SEPARATOR '|') as holdingbranch_list,
         GROUP_CONCAT(DISTINCT items.location 
-                       ORDER BY items.itemnumber SEPARATOR '<br/>') as l_location,
+            ORDER BY items.itemnumber SEPARATOR '|') as l_location,
         GROUP_CONCAT(DISTINCT items.itype 
-                       ORDER BY items.itemnumber SEPARATOR '<br/>') as l_itype,
+            ORDER BY items.itemnumber SEPARATOR '|') as l_itype,
 
         reserves.found,
         biblio.title,
         biblio.author,
         count(DISTINCT reserves.borrowernumber) as reservecount, 
-        count(DISTINCT items.itemnumber) as itemcount 
+        count(DISTINCT items.itemnumber) $include_aqorders_qty as itemcount
  FROM  reserves
  LEFT JOIN items ON items.biblionumber=reserves.biblionumber 
  LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber
+ $include_aqorders_qty_join
  WHERE
  notforloan $nfl_comparison 0 AND damaged = 0 AND itemlost = 0 AND withdrawn = 0
  $sqldatewhere
@@ -147,18 +158,18 @@ while ( my $data = $sth->fetchrow_hashref ) {
             itemnum            => $data->{itemnumber},
             biblionumber       => $data->{biblionumber},
             holdingbranch      => $data->{holdingbranch},
-            homebranch_list    => $data->{homebranch_list},
-            holdingbranch_list => $data->{holdingbranch_list},
+            homebranch_list    => [split('\|', $data->{homebranch_list})],
+            holdingbranch_list => [split('\|', $data->{holdingbranch_list})],
             branch             => $data->{branch},
             itemcallnumber     => $data->{itemcallnumber},
-            location           => $data->{l_location},
-            itype              => $data->{l_itype},
+            location           => [split('\|', $data->{l_location})],
+            itype              => [split('\|', $data->{l_itype})],
             reservecount       => $data->{reservecount},
             itemcount          => $data->{itemcount},
             ratiocalc          => sprintf( "%.0d", $ratio_atleast1 ? ( $thisratio / $ratio ) : $thisratio ),
             thisratio => sprintf( "%.2f", $thisratio ),
             thisratio_atleast1 => ( $thisratio >= 1 ) ? 1 : 0,
-            listcall => $data->{listcall}
+            listcall           => [split('\|', $data->{listcall})]
         }
     );
 }