Bug 17698: (follow-up) Fixing things in Comment 57
[koha.git] / circ / returns.pl
index fab6bc2..103d290 100755 (executable)
@@ -27,8 +27,7 @@ script to execute returns of books
 
 =cut
 
-use strict;
-use warnings;
+use Modern::Perl;
 
 # FIXME There are weird things going on with $patron and $borrowernumber in this script
 
@@ -50,10 +49,10 @@ use Koha::AuthorisedValues;
 use Koha::DateUtils;
 use Koha::Calendar;
 use Koha::BiblioFrameworks;
-use Koha::Checkouts;
 use Koha::Holds;
 use Koha::Items;
 use Koha::Patrons;
+use Koha::Checkouts;
 
 my $query = new CGI;
 
@@ -80,8 +79,9 @@ if ($session->param('branch') eq 'NO_LIBRARY_SET'){
 if ( $query->param('print_slip') ) {
     $template->param(
         print_slip     => 1,
-        borrowernumber => scalar $query->param('borrowernumber'),
+        borrowernumber => scalar $query->param('borrowernumber'), # FIXME We should send a Koha::Patron and raise an error if not exist.
         biblionumber   => scalar $query->param('biblionumber'),
+        itemnumber     => scalar $query->param('itemnumber'),
     );
 }
 
@@ -179,11 +179,7 @@ if ( $query->param('reserve_id') ) {
             itembiblionumber => $biblio->biblionumber,
             iteminfo       => $biblio->author,
             name           => $name,
-            borrowernumber => $borrowernumber,
-            borcnum        => $patron->cardnumber,
-            borfirstname   => $patron->firstname,
-            borsurname     => $patron->surname,
-            borcategory    => $patron->category->description,
+            patron         => $patron,
             diffbranch     => 1,
         );
     }
@@ -295,7 +291,6 @@ if ($barcode) {
             ccode            => $item->ccode,
             itembiblionumber => $biblio->biblionumber,
             biblionumber     => $biblio->biblionumber,
-            borrower         => $borrower,
             additional_materials => $materials,
             issue            => $checkout,
         );
@@ -406,23 +401,7 @@ if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
         my $patron = Koha::Patrons->find( $reserve->{'borrowernumber'} );
         my $name = $patron->surname . ", " . $patron->title . " " . $patron->firstname;
         $template->param(
-            # FIXME The full patron object should be passed to the template
-                wname           => $name,
-                wborfirstname   => $patron->firstname,
-                wborsurname     => $patron->surname,
-                wborcategory    => $patron->category->description,
-                wbortitle       => $patron->title,
-                wborphone       => $patron->phone,
-                wboremail       => $patron->email,
-                streetnumber    => $patron->streetnumber,
-                address         => $patron->address,
-                address2        => $patron->address2,
-                city            => $patron->city,
-                zipcode         => $patron->zipcode,
-                state           => $patron->state,
-                country         => $patron->country,
-                wborrowernumber => $reserve->{'borrowernumber'},
-                wborcnum        => $patron->cardnumber,
+            patron => $patron,
         );
     }
     $template->param(
@@ -455,26 +434,9 @@ if ( $messages->{'ResFound'}) {
         $template->param(
             # FIXME The full patron object should be passed to the template
             found          => 1,
-            name           => $patron->surname . ", " . $patron->title . " " . $patron->firstname,
-            borfirstname   => $patron->firstname,
-            borsurname     => $patron->surname,
-            borcategory    => $patron->category->description,
-            bortitle       => $patron->title,
-            borphone       => $patron->phone,
-            boremail       => $patron->email,
-            boraddress     => $patron->address,
-            boraddress2    => $patron->address2,
-            streetnumber   => $patron->streetnumber,
-            city           => $patron->city,
-            zipcode        => $patron->zipcode,
-            state          => $patron->state,
-            country        => $patron->country,
-            borcnum        => $patron->cardnumber,
-            debarred       => $patron->debarred,
-            gonenoaddress  => $patron->gonenoaddress,
+            patron         => $patron,
             barcode        => $barcode,
             destbranch     => $reserve->{'branchcode'},
-            borrowernumber => $reserve->{'borrowernumber'},
             itemnumber     => $reserve->{'itemnumber'},
             reservenotes   => $reserve->{'reservenotes'},
             reserve_id     => $reserve->{reserve_id},
@@ -495,7 +457,6 @@ foreach my $code ( keys %$messages ) {
     elsif ( $code eq 'NotIssued' ) {
         $err{notissued} = 1;
         $err{msg} = '';
-        $err{msg} = $messages->{'IsPermanent'} if $messages->{'IsPermanent'};
     }
     elsif ( $code eq 'LocalUse' ) {
         $err{localuse} = 1;
@@ -520,12 +481,6 @@ foreach my $code ( keys %$messages ) {
         $err{withdrawn} = 1;
         $exit_required_p = 1 if C4::Context->preference("BlockReturnOfWithdrawnItems");
     }
-    elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
-        if ( $messages->{'IsPermanent'} ne $userenv_branch ) {
-            $err{ispermanent} = 1;
-            $err{msg}         = $messages->{'IsPermanent'};
-        }
-    }
     elsif ( $code eq 'WrongTransfer' ) {
         ;    # FIXME... anything to do here?
     }
@@ -589,14 +544,8 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
             } else {
                 $ri{return_overdue} = 1 if (DateTime->compare($duedate, $dropboxdate) == -1);
             }
-            $ri{borrowernumber} = $patron->borrowernumber;
-            $ri{borcnum}        = $patron->cardnumber;
-            $ri{borfirstname}   = $patron->firstname;
-            $ri{borsurname}     = $patron->surname;
-            $ri{bortitle}       = $patron->title;
-            $ri{bornote}        = $patron->borrowernotes;
-            $ri{borcategorycode}= $patron->categorycode;
-            $ri{borissuescount} = Koha::Checkouts->count( { borrowernumber => $patron->borrowernumber } );
+            $ri{patron} = $patron,
+            $ri{borissuescount} = $patron->checkouts->count;
         }
         else {
             $ri{borrowernumber} = $riborrowernumber{$_};
@@ -620,7 +569,7 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
         $ri{homebranch}          = $item->homebranch;
         $ri{holdingbranch}       = $item->holdingbranch;
 
-        $ri{location}         = $biblio->{'location'};
+        $ri{location} = $item->location;
         my $shelfcode = $ri{'location'};
         $ri{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
 
@@ -631,6 +580,8 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
     push @riloop, \%ri;
 }
 
+my $pending_checkout_notes = Koha::Checkouts->search({ noteseen => 0 })->count;
+
 $template->param(
     riloop         => \@riloop,
     printer        => $printer,
@@ -641,6 +592,7 @@ $template->param(
     forgivemanualholdsexpire => $forgivemanualholdsexpire,
     overduecharges => $overduecharges,
     AudioAlerts        => C4::Context->preference("AudioAlerts"),
+    pending_checkout_notes => $pending_checkout_notes,
 );
 
 $itemnumber = GetItemnumberFromBarcode( $barcode );