Bug 10694: (follow-up) fix various issues
[koha_fer] / opac / opac-reserve.pl
index b633d3d..473ead8 100755 (executable)
@@ -147,8 +147,8 @@ foreach my $biblioNumber (@biblionumbers) {
     }
 
     # Compute the priority rank.
-    my ( $rank, $reserves ) =
-      GetReservesFromBiblionumber( $biblioNumber, 1 );
+    my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblioNumber, all_dates => 1 });
+    my $rank = scalar( @$reserves );
     $biblioData->{reservecount} = 1;    # new reserve
     foreach my $res (@{$reserves}) {
         my $found = $res->{found};
@@ -307,7 +307,7 @@ if ( $borr->{lost} && ($borr->{lost} == 1) ) {
                      lost    => 1
                     );
 }
-if ( CheckBorrowerDebarred($borrowernumber) ) {
+if ( $borr->{'debarred'} ) {
     $noreserves = 1;
     $template->param(
                      message  => 1,
@@ -426,18 +426,18 @@ foreach my $biblioNum (@biblionumbers) {
         # change the background color.
         my $issues= GetItemIssue($itemNum);
         if ( $issues->{'date_due'} ) {
-            $itemLoopIter->{dateDue} = format_sqlduedatetime($issues->{date_due});
+            $itemLoopIter->{dateDue} = output_pref({ dt => dt_from_string($issues->{date_due}, 'sql'), as_due_date => 1 });
             $itemLoopIter->{backgroundcolor} = 'onloan';
         }
 
         # checking reserve
-        my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemNum);
+        my ($reservedate,$reservedfor,$expectedAt,undef,$wait) = GetReservesFromItemnumber($itemNum);
         my $ItemBorrowerReserveInfo = GetMemberDetails( $reservedfor, 0);
 
-       # the item could be reserved for this borrower vi a host record, flag this
-       if ($reservedfor eq $borrowernumber){
-               $itemLoopIter->{already_reserved} = 1;
-       }
+        # the item could be reserved for this borrower vi a host record, flag this
+        if ($reservedfor eq $borrowernumber){
+            $itemLoopIter->{already_reserved} = 1;
+        }
 
         if ( defined $reservedate ) {
             $itemLoopIter->{backgroundcolor} = 'reserved';
@@ -446,6 +446,8 @@ foreach my $biblioNum (@biblionumbers) {
             $itemLoopIter->{ReservedForSurname}        = $ItemBorrowerReserveInfo->{'surname'};
             $itemLoopIter->{ReservedForFirstname}      = $ItemBorrowerReserveInfo->{'firstname'};
             $itemLoopIter->{ExpectedAtLibrary}         = $expectedAt;
+            #waiting status
+            $itemLoopIter->{waitingdate} = $wait;
         }
 
         $itemLoopIter->{notforloan} = $itemInfo->{notforloan};
@@ -490,7 +492,7 @@ foreach my $biblioNum (@biblionumbers) {
         # If there is no loan, return and transfer, we show a checkbox.
         $itemLoopIter->{notforloan} = $itemLoopIter->{notforloan} || 0;
 
-        my $branch = ( C4::Context->preference('ReservesControlBranch') eq 'ItemHomeLibrary' ) ? $itemInfo->{'homebranch'} : $borr->{'branchcode'};
+        my $branch = GetReservesControlBranch( $itemInfo, $borr );
 
         my $branchitemrule = GetBranchItemRule( $branch, $itemInfo->{'itype'} );
         my $policy_holdallowed = 1;
@@ -505,14 +507,7 @@ foreach my $biblioNum (@biblionumbers) {
             $numCopiesAvailable++;
         }
 
-       # FIXME: move this to a pm
-        my $dbh = C4::Context->dbh;
-        my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
-        $sth2->execute($itemLoopIter->{ReservedForBorrowernumber}, $itemNum);
-        while (my $wait_hashref = $sth2->fetchrow_hashref) {
-            $itemLoopIter->{waitingdate} = format_date($wait_hashref->{waitingdate});
-        }
-       $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemTypes->{ $itemInfo->{itype} }{imageurl} );
+        $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemTypes->{ $itemInfo->{itype} }{imageurl} );
 
     # Show serial enumeration when needed
         if ($itemLoopIter->{enumchron}) {
@@ -556,8 +551,8 @@ if (! $template->{VARS}->{'singleBranchMode'}) {
     $itemTableColspan--;
 }
 $itemTableColspan-- if !$show_holds_count && !$show_priority;
-my $show_notes=C4::Context->preference('OPACShowHoldNotes');
-$template->param(OPACShowHoldNotes=>$show_notes);
+my $show_notes=C4::Context->preference('OpacHoldNotes');
+$template->param(OpacHoldNotes=>$show_notes);
 $itemTableColspan-- if !$show_notes;
 $template->param(itemtable_colspan => $itemTableColspan);