Bug 18789: (QA follow-up) Use is_child in circulation.pl
[koha.git] / circ / reserveratios.pl
index 56c84d8..104928a 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/;
@@ -31,6 +30,7 @@ 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 +55,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 +94,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{};
 
@@ -144,7 +154,7 @@ 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($data->{biblionumber});
+    my $record = GetMarcBiblio({ biblionumber => $data->{biblionumber} });
     $data->{subtitle} = GetRecordValue('subtitle', $record, GetFrameworkCode($data->{biblionumber}));
     push(
         @reservedata,