Bug 21719: Fix typos
[koha.git] / circ / returns.pl
index a82bdc1..63cf75b 100755 (executable)
@@ -360,7 +360,7 @@ my $waiting  = 0;
 my $reserved = 0;
 
 # new op dev : we check if the document must be returned to his homebranch directly,
-#  if the document is transfered, we have warning message .
+#  if the document is transferred, we have warning message .
 
 if ( $messages->{'WasTransfered'} ) {
     $template->param(
@@ -385,7 +385,7 @@ if ( $messages->{'Wrongbranch'} ){
     );
 }
 
-# case of wrong transfert, if the document wasn't transfered to the right library (according to branchtransfer (tobranch) BDD)
+# case of wrong transfert, if the document wasn't transferred to the right library (according to branchtransfer (tobranch) BDD)
 
 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
     $template->param(
@@ -415,7 +415,36 @@ if ( $messages->{'ResFound'}) {
     my $reserve    = $messages->{'ResFound'};
     my $patron = Koha::Patrons->find( $reserve->{borrowernumber} );
     my $holdmsgpreferences =  C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $reserve->{'borrowernumber'}, message_name   => 'Hold_Filled' } );
-    if ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
+
+    if ( $reserve->{'ResFound'} eq "Reserved" && C4::Context->preference('HoldsAutoFill') ) {
+        my $item = Koha::Items->find( $itemnumber );
+        my $biblio = $item->biblio;
+
+        my $diffBranchSend = ($userenv_branch ne $reserve->{branchcode}) ? $reserve->{branchcode} : undef;
+        ModReserveAffect( $reserve->{itemnumber}, $reserve->{borrowernumber}, $diffBranchSend, $reserve->{reserve_id} );
+        my ( $messages, $nextreservinfo ) = GetOtherReserves($reserve->{itemnumber});
+
+        my $patron = Koha::Patrons->find( $nextreservinfo );
+
+        $template->param(
+            hold_auto_filled => 1,
+            print_slip       => C4::Context->preference('HoldsAutoFillPrintSlip'),
+            patron           => $patron,
+            borrowernumber   => $patron->id,
+            biblionumber     => $biblio->id,
+        );
+
+        if ( $messages->{'transfert'} ) {
+            $template->param(
+                itemtitle      => $biblio->title,
+                itemnumber     => $item->itemnumber,
+                itembiblionumber => $biblio->biblionumber,
+                iteminfo       => $biblio->author,
+                diffbranch     => 1,
+            );
+        }
+    }
+    elsif ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
         if ( $reserve->{'ResFound'} eq "Waiting" ) {
             $template->param(
                 waiting      => ($userenv_branch eq $reserve->{'branchcode'} ? 1 : 0 ),
@@ -429,19 +458,19 @@ if ( $messages->{'ResFound'}) {
             );
         }
 
-        # same params for Waiting or Reserved
-        $template->param(
-            # FIXME The full patron object should be passed to the template
-            found          => 1,
-            patron         => $patron,
-            barcode        => $barcode,
-            destbranch     => $reserve->{'branchcode'},
-            itemnumber     => $reserve->{'itemnumber'},
-            reservenotes   => $reserve->{'reservenotes'},
-            reserve_id     => $reserve->{reserve_id},
-            bormessagepref => $holdmsgpreferences->{'transports'},
-        );
     } # else { ; }  # error?
+
+    # same params for Waiting or Reserved
+    $template->param(
+        found          => 1,
+        patron         => $patron,
+        barcode        => $barcode,
+        destbranch     => $reserve->{'branchcode'},
+        itemnumber     => $reserve->{'itemnumber'},
+        reservenotes   => $reserve->{'reservenotes'},
+        reserve_id     => $reserve->{reserve_id},
+        bormessagepref => $holdmsgpreferences->{'transports'},
+    );
 }
 
 # Error Messages
@@ -551,6 +580,8 @@ foreach ( sort { $a <=> $b } keys %returneditems ) {
         }
 
         my $item = Koha::Items->find({ barcode => $bar_code });
+        next unless $item; # FIXME The item has been deleted in the meantime,
+                           # we could handle that better displaying a message in the template
         my $biblio = $item->biblio;
         # FIXME pass $item to the template and we are done here...
         $ri{itembiblionumber}    = $biblio->biblionumber;
@@ -591,8 +622,9 @@ $template->param(
     AudioAlerts        => C4::Context->preference("AudioAlerts"),
 );
 
-$itemnumber = GetItemnumberFromBarcode( $barcode );
-if ( $itemnumber ) {
+my $item_from_barcode = Koha::Items->find({barcode => $barcode }); # How many times do we fetch this item?!?
+if ( $item_from_barcode ) {
+    $itemnumber = $item_from_barcode->itemnumber;
     my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
     if ( $holdingBranch and $collectionBranch ) {
         $holdingBranch //= '';