Bug 17738: Replace GetReservesFromBorrowernumber with Koha::Patron->get_holds
[koha-ffzg.git] / circ / returns.pl
index 3ef887f..a6041d1 100755 (executable)
@@ -50,8 +50,9 @@ use C4::RotatingCollections;
 use Koha::AuthorisedValues;
 use Koha::DateUtils;
 use Koha::Calendar;
-use Koha::Checkouts;
 use Koha::BiblioFrameworks;
+use Koha::Checkouts;
+use Koha::Patrons;
 
 my $query = new CGI;
 
@@ -282,7 +283,9 @@ if ($barcode) {
 
     my $materials = $biblio->{'materials'};
     my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
-    $materials = $descriptions->{lib} // '';
+    $materials = $descriptions->{lib} // $materials;
+
+    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
 
     $template->param(
         title            => $biblio->{'title'},
@@ -297,6 +300,7 @@ if ($barcode) {
         biblionumber     => $biblio->{'biblionumber'},
         borrower         => $borrower,
         additional_materials => $materials,
+        issue            => $issue,
     );
 
     my %input = (
@@ -336,13 +340,8 @@ if ($barcode) {
 
         if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
             #Check for waiting holds
-            my @reserves = GetReservesFromBorrowernumber($borrower->{'borrowernumber'});
-            my $waiting_holds = 0;
-            foreach my $num_res (@reserves) {
-                if ( $num_res->{'found'} eq 'W' && $num_res->{'branchcode'} eq $userenv_branch) {
-                    $waiting_holds++;
-                }
-            }
+            my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
+            my $waiting_holds = $patron->holds->search({ found => 'W', branchcode => $userenv_branch })->count;
             if ($waiting_holds > 0) {
                 $template->param(
                     waiting_holds       => $waiting_holds,