Bug 11529: Remove duplicate column name from select query
[koha-ffzg.git] / circ / reserveratios.pl
index e7c28c7..66eebd3 100755 (executable)
@@ -18,8 +18,7 @@
 # You should have received a copy of the GNU General Public License
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
-use strict;
-use warnings;
+use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use Date::Calc qw/Today Add_Delta_YM/;
@@ -28,9 +27,9 @@ use C4::Context;
 use C4::Output;
 use C4::Auth;
 use C4::Debug;
-use C4::Biblio qw/GetMarcBiblio GetRecordValue GetFrameworkCode/;
 use C4::Acquisition qw/GetOrdersByBiblionumber/;
 use Koha::DateUtils;
+use Koha::Acquisition::Baskets;
 
 my $input = new CGI;
 my $startdate       = $input->param('from');
@@ -55,6 +54,16 @@ if ($booksellerid && $basketno) {
      $template->param( booksellerid => $booksellerid, basketno => $basketno );
 }
 
+my $effective_create_items = q{};
+if ( $basketno ){
+    my $basket = Koha::Acquisition::Baskets->find( $basketno );
+    if ($basket){
+        $effective_create_items = $basket->effective_create_items;
+    } else {
+        $effective_create_items = C4::Context->preference('AcqCreateItem');
+    }
+}
+
 $startdate = eval { dt_from_string( $startdate ) } if $startdate;
 $enddate = eval { dt_from_string( $enddate ) } if $enddate;
 
@@ -84,12 +93,12 @@ $sqldatewhere .= " AND reservedate <= ?";
 push @query_params, output_pref({ dt => $enddate, dateformat => 'iso' });
 
 my $include_aqorders_qty =
-  C4::Context->preference('AcqCreateItem') eq 'receiving'
+  $effective_create_items eq 'receiving'
   ? '+ COALESCE(aqorders.quantity, 0) - COALESCE(aqorders.quantityreceived, 0)'
   : q{};
 
 my $include_aqorders_qty_join =
-  C4::Context->preference('AcqCreateItem') eq 'receiving'
+  $effective_create_items eq 'receiving'
   ? 'LEFT JOIN aqorders ON reserves.biblionumber=aqorders.biblionumber'
   : q{};
 
@@ -115,6 +124,10 @@ my $strsth =
 
         reserves.found,
         biblio.title,
+        biblio.subtitle,
+        biblio.medium,
+        biblio.part_number,
+        biblio.part_name,
         biblio.author,
         count(DISTINCT reserves.borrowernumber) as reservecount, 
         count(DISTINCT items.itemnumber) $include_aqorders_qty as itemcount
@@ -144,8 +157,6 @@ while ( my $data = $sth->fetchrow_hashref ) {
     my $thisratio = $data->{reservecount} / $data->{itemcount};
     my $ratiocalc = ($thisratio / $ratio);
     ($thisratio / $ratio) >= 1 or next;  # TODO: tighter targeting -- get ratio limit into SQL using HAVING clause
-    my $record = GetMarcBiblio({ biblionumber => $data->{biblionumber} });
-    $data->{subtitle} = GetRecordValue('subtitle', $record, GetFrameworkCode($data->{biblionumber}));
     push(
         @reservedata,
         {
@@ -153,7 +164,7 @@ while ( my $data = $sth->fetchrow_hashref ) {
             priority           => $data->{priority},
             name               => $data->{borrower},
             title              => $data->{title},
-            subtitle           => $data->{subtitle},
+            subtitle           => C4::Biblio::SplitKohaField($data->{'subtitle'}),
             author             => $data->{author},
             itemnum            => $data->{itemnumber},
             biblionumber       => $data->{biblionumber},