Bug 14504: (QA followup) use TestBuilder, remove do_not_commit
[koha.git] / opac / opac-reserve.pl
index 60232cc..58dac17 100755 (executable)
@@ -18,8 +18,8 @@
 # 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 C4::Auth;    # checkauth, getborrowernumber.
 use C4::Koha;
@@ -34,9 +34,10 @@ use C4::Branch; # GetBranches
 use C4::Overdues;
 use C4::Debug;
 use Koha::DateUtils;
-use Koha::Borrower::Debarments qw(IsDebarred);
+use Koha::Libraries;
+use Koha::Patrons;
 use Date::Calc qw/Today Date_to_Days/;
-# use Data::Dumper;
+use List::MoreUtils qw/uniq/;
 
 my $maxreserves = C4::Context->preference("maxreserves");
 
@@ -228,7 +229,7 @@ if ( $query->param('place_reserve') ) {
 
         my $canreserve = 0;
 
-        my $singleBranchMode = C4::Context->preference("singleBranchMode");
+        my $singleBranchMode = Koha::Libraries->search->count == 1;
         if ( $singleBranchMode || !$OPACChooseBranch )
         {    # single branch mode or disabled user choosing
             $branch = $borr->{'branchcode'};
@@ -281,15 +282,16 @@ if ( $query->param('place_reserve') ) {
             $canreserve = 0;
         }
 
+        my $itemtype = $query->param('itemtype') || undef;
+        $itemtype = undef if $itemNum;
+
         # Here we actually do the reserveration. Stage 3.
         if ($canreserve) {
             my $reserve_id = AddReserve(
-                $branch,      $borrowernumber,
-                $biblioNum,
-                [$biblioNum], $rank,
-                $startdate,   $expiration_date,
-                $notes,       $biblioData->{title},
-                $itemNum,     $found
+                $branch,          $borrowernumber, $biblioNum,
+                [$biblioNum],     $rank,           $startdate,
+                $expiration_date, $notes,          $biblioData->{title},
+                $itemNum,         $found,          $itemtype,
             );
             $failed_holds++ unless $reserve_id;
             ++$reserve_cnt;
@@ -314,6 +316,7 @@ if ( $borr->{'amountoutstanding'} && ($borr->{'amountoutstanding'} > $maxoutstan
     $noreserves = 1;
     $template->param( too_much_oweing => $amount );
 }
+
 if ( $borr->{gonenoaddress} && ($borr->{gonenoaddress} == 1) ) {
     $noreserves = 1;
     $template->param(
@@ -321,6 +324,7 @@ if ( $borr->{gonenoaddress} && ($borr->{gonenoaddress} == 1) ) {
         GNA     => 1
     );
 }
+
 if ( $borr->{lost} && ($borr->{lost} == 1) ) {
     $noreserves = 1;
     $template->param(
@@ -328,11 +332,14 @@ if ( $borr->{lost} && ($borr->{lost} == 1) ) {
         lost    => 1
     );
 }
-if ( IsDebarred($borrowernumber) ) {
+
+if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) {
     $noreserves = 1;
     $template->param(
-        message  => 1,
-        debarred => 1
+        message          => 1,
+        debarred         => 1,
+        debarred_comment => $borr->{debarredcomment},
+        debarred_date    => $borr->{debarred},
     );
 }
 
@@ -436,6 +443,7 @@ foreach my $biblioNum (@biblionumbers) {
         $itemLoopIter->{copynumber} = $itemInfo->{copynumber};
         if ($itemLevelTypes) {
             $itemLoopIter->{translated_description} = $itemInfo->{translated_description};
+            $itemLoopIter->{itype} = $itemInfo->{itype};
             $itemLoopIter->{imageurl} = $itemInfo->{imageurl};
         }
 
@@ -566,6 +574,7 @@ foreach my $biblioNum (@biblionumbers) {
     $anyholdable = 1 if $biblioLoopIter{holdable};
 }
 
+
 if ( $numBibsAvailable == 0 || $anyholdable == 0) {
     $template->param( none_available => 1 );
 }