Bug 17738: Replace GetReservesFromBorrowernumber with Koha::Patron->get_holds
[koha-ffzg.git] / circ / returns.pl
index ec13c04..a6041d1 100755 (executable)
@@ -50,11 +50,14 @@ use C4::RotatingCollections;
 use Koha::AuthorisedValues;
 use Koha::DateUtils;
 use Koha::Calendar;
+use Koha::BiblioFrameworks;
+use Koha::Checkouts;
+use Koha::Patrons;
 
 my $query = new CGI;
 
 #getting the template
-my ( $template, $librarian, $cookie ) = get_template_and_user(
+my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
     {
         template_name   => "circ/returns.tt",
         query           => $query,
@@ -90,7 +93,7 @@ my $printer = $userenv->{'branchprinter'} // '';
 my $forgivemanualholdsexpire = $query->param('forgivemanualholdsexpire');
 
 my $overduecharges = (C4::Context->preference('finesMode') && C4::Context->preference('finesMode') ne 'off');
-#
+ #
 # Some code to handle the error if there is no branch or printer setting.....
 #
 
@@ -279,11 +282,10 @@ if ($barcode) {
     $returnbranch = $biblio->{$hbr};
 
     my $materials = $biblio->{'materials'};
-    my $avcode = GetAuthValCode('items.materials');
-    if ($avcode) {
-        my $av = Koha::AuthorisedValues->search({ category => $avcode, authorised_value => $materials });
-        $materials = $av->count ? $av->next->lib : '';
-    }
+    my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
+    $materials = $descriptions->{lib} // $materials;
+
+    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
 
     $template->param(
         title            => $biblio->{'title'},
@@ -298,6 +300,7 @@ if ($barcode) {
         biblionumber     => $biblio->{'biblionumber'},
         borrower         => $borrower,
         additional_materials => $materials,
+        issue            => $issue,
     );
 
     my %input = (
@@ -326,22 +329,19 @@ if ($barcode) {
         push( @inputloop, \%input );
 
         if ( C4::Context->preference("FineNotifyAtCheckin") ) {
-            my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrower->{'borrowernumber'} );
-            if ($fines && $fines > 0) {
-                $template->param( fines => sprintf("%.2f",$fines) );
+            my $patron = Koha::Patrons->find( $borrower->{borrowernumber} );
+            my $balance = $patron->account->balance;
+
+            if ($balance > 0) {
+                $template->param( fines => sprintf("%.2f", $balance) );
                 $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
             }
         }
 
         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,
@@ -412,11 +412,14 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
             wbortitle       => $borr->{'title'},
             wborphone       => $borr->{'phone'},
             wboremail       => $borr->{'email'},
-            wborstnum       => $borr->{streetnumber},
-            wboraddress     => $borr->{'address'},
-            wboraddress2    => $borr->{'address2'},
-            wborcity        => $borr->{'city'},
-            wborzip         => $borr->{'zipcode'},
+            streetnumber    => $borr->{streetnumber},
+            streettype      => $borr->{streettype},
+            address         => $borr->{'address'},
+            address2        => $borr->{'address2'},
+            city            => $borr->{'city'},
+            zipcode         => $borr->{'zipcode'},
+            state           => $borr->{'state'},
+            country         => $borr->{'country'},
             wborrowernumber => $reserve->{'borrowernumber'},
             wborcnum        => $borr->{'cardnumber'},
             wtransfertFrom  => $userenv_branch,
@@ -454,11 +457,14 @@ if ( $messages->{'ResFound'}) {
             bortitle       => $borr->{'title'},
             borphone       => $borr->{'phone'},
             boremail       => $borr->{'email'},
-            boraddress     => $borr->{'address'},
-            boraddress2    => $borr->{'address2'},
-            borstnum       => $borr->{streetnumber},
-            borcity        => $borr->{'city'},
-            borzip         => $borr->{'zipcode'},
+            streetnumber   => $borr->{streetnumber},
+            streettype     => $borr->{streettype},
+            address        => $borr->{'address'},
+            address2       => $borr->{'address2'},
+            city           => $borr->{'city'},
+            zipcode        => $borr->{'zipcode'},
+            state          => $borr->{'state'},
+            country        => $borr->{'country'},
             borcnum        => $borr->{'cardnumber'},
             debarred       => $borr->{'debarred'},
             gonenoaddress  => $borr->{'gonenoaddress'},
@@ -467,6 +473,7 @@ if ( $messages->{'ResFound'}) {
             borrowernumber => $reserve->{'borrowernumber'},
             itemnumber     => $reserve->{'itemnumber'},
             reservenotes   => $reserve->{'reservenotes'},
+            reserve_id     => $reserve->{reserve_id},
             bormessagepref => $holdmsgpreferences->{'transports'},
         );
     } # else { ; }  # error?
@@ -554,7 +561,8 @@ $template->param( errmsgloop => \@errmsgloop );
 my $returned_counter = ( C4::Context->preference('numReturnedItemsToShow') ) ? C4::Context->preference('numReturnedItemsToShow') : 8;
 my $count = 0;
 my @riloop;
-my $shelflocations = GetKohaAuthorisedValues('items.location','');
+my $shelflocations =
+  { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' } ) };
 foreach ( sort { $a <=> $b } keys %returneditems ) {
     my %ri;
     if ( $count++ < $returned_counter ) {
@@ -580,6 +588,7 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
             $ri{bortitle}       = $b->{'title'};
             $ri{bornote}        = $b->{'borrowernotes'};
             $ri{borcategorycode}= $b->{'categorycode'};
+            $ri{borissuescount} = Koha::Checkouts->count( { borrowernumber => $b->{'borrowernumber'} } );
         }
         else {
             $ri{borrowernumber} = $riborrowernumber{$_};
@@ -645,5 +654,8 @@ if ( $itemnumber ) {
     }
 }
 
+# Checking if there is a Fast Cataloging Framework
+$template->param( fast_cataloging => 1 ) if Koha::BiblioFrameworks->find( 'FA' );
+
 # actually print the page!
 output_html_with_http_headers $query, $cookie, $template->output;