Bug 12430: Fix selenium/regressions.t failure
[koha-ffzg.git] / circ / reserveratios.pl
index 1beb559..47b0375 100755 (executable)
@@ -22,6 +22,7 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use Date::Calc qw/Today Add_Delta_YM/;
+use POSIX qw( ceil );
 
 use C4::Context;
 use C4::Output;
@@ -31,18 +32,18 @@ use C4::Acquisition qw/GetOrdersByBiblionumber/;
 use Koha::DateUtils;
 use Koha::Acquisition::Baskets;
 
-my $input = new CGI;
+my $input = CGI->new;
 my $startdate       = $input->param('from');
 my $enddate         = $input->param('to');
 my $ratio           = $input->param('ratio');
 my $include_ordered = $input->param('include_ordered');
+my $include_suspended = $input->param('include_suspended');
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
         template_name   => "circ/reserveratios.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { circulate => "circulate_remaining_permissions" },
         debug           => 1,
     }
@@ -103,6 +104,7 @@ my $include_aqorders_qty_join =
   : q{};
 
 my $nfl_comparison = $include_ordered ? '<=' : '=';
+my $sus_comparison = $include_suspended ? '<=' : '<';
 my $strsth =
 "SELECT reservedate,
         reserves.borrowernumber as borrowernumber,
@@ -137,6 +139,7 @@ my $strsth =
  $include_aqorders_qty_join
  WHERE
  notforloan $nfl_comparison 0 AND damaged = 0 AND itemlost = 0 AND withdrawn = 0
+ AND suspend $sus_comparison 1
  $sqldatewhere
 ";
 
@@ -154,7 +157,7 @@ $sth->execute(@query_params);
 my @reservedata;
 while ( my $data = $sth->fetchrow_hashref ) {
     my $thisratio = $data->{reservecount} / $data->{itemcount};
-    my $ratiocalc = $data->{reservecount}/$ratio - $data->{itemcount};
+    my $ratiocalc = ceil($data->{reservecount}/$ratio - $data->{itemcount});
     $ratiocalc >= 1 or next;  # TODO: tighter targeting -- get ratio limit into SQL using HAVING clause
     push(
         @reservedata,
@@ -198,6 +201,7 @@ $template->param(
     to              => $enddate,
     ratio           => $ratio,
     include_ordered => $include_ordered,
+    include_suspended => $include_suspended,
     reserveloop     => \@reservedata,
 );