Bug 22417: Fix borrowernumber values
[srvgit] / circ / returns.pl
index 8044262..7a45995 100755 (executable)
@@ -65,7 +65,6 @@ my ( $template, $librarian, $cookie, $flags ) = get_template_and_user(
         template_name   => "circ/returns.tt",
         query           => $query,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { circulate => "circulate_remaining_permissions" },
     }
 );
@@ -77,9 +76,7 @@ my $session = get_session($sessionID);
 if ( $query->param('print_slip') ) {
     $template->param(
         print_slip     => 1,
-        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'),
+        reserve_id => scalar $query->param('reserve_id'),
     );
 }
 
@@ -274,18 +271,18 @@ if ($barcode) {
         my $checkout = $item->checkout;
         my $biblio   = $item->biblio;
         $template->param(
-            title            => $biblio->title,
-            homebranch       => $item->homebranch,
-            holdingbranch    => $item->holdingbranch,
-            returnbranch     => $returnbranch,
-            author           => $biblio->author,
-            itembarcode      => $item->barcode,
-            itemtype         => $item->effective_itemtype,
-            ccode            => $item->ccode,
-            itembiblionumber => $biblio->biblionumber,
-            biblionumber     => $biblio->biblionumber,
+            title                => $biblio->title,
+            homebranch           => $item->homebranch,
+            holdingbranch        => $item->holdingbranch,
+            returnbranch         => $returnbranch,
+            author               => $biblio->author,
+            itembarcode          => $item->barcode,
+            itemtype             => $item->effective_itemtype,
+            ccode                => $item->ccode,
+            itembiblionumber     => $biblio->biblionumber,
+            biblionumber         => $biblio->biblionumber,
             additional_materials => $materials,
-            issue            => $checkout,
+            issue                => $checkout,
         );
     } # FIXME else we should not call AddReturn but set BadBarcode directly instead
 
@@ -297,9 +294,19 @@ if ($barcode) {
 
     my $return_date = $dropboxmode ? $dropboxdate : $return_date_override_dt;
 
+    # Block return if multi-part and confirm has not been received
+    my $needs_confirm =
+         C4::Context->preference("CircConfirmItemParts")
+      && $item
+      && $item->materials
+      && !$query->param('multiple_confirm');
+    $template->param( 'multiple_confirmed' => 1 )
+      if $query->param('multiple_confirm');
+
     # do the return
     ( $returned, $messages, $issue, $borrower ) =
-      AddReturn( $barcode, $userenv_branch, $exemptfine, $return_date );
+      AddReturn( $barcode, $userenv_branch, $exemptfine, $return_date )
+          unless $needs_confirm;
 
     if ($returned) {
         my $time_now = dt_from_string()->truncate( to => 'minute');
@@ -340,16 +347,21 @@ if ($barcode) {
                 );
             }
         }
-    } elsif ( C4::Context->preference('ShowAllCheckins') and !$messages->{'BadBarcode'} ) {
+    } elsif ( C4::Context->preference('ShowAllCheckins') and !$messages->{'BadBarcode'} and !$needs_confirm ) {
         $input{duedate}   = 0;
         $returneditems{0} = $barcode;
         $riduedate{0}     = 0;
         push( @inputloop, \%input );
     }
     $template->param( privacy => $borrower->{privacy} );
+
+    if ( $needs_confirm ) {
+        $template->param( needs_confirm => $needs_confirm );
+    }
 }
 $template->param( inputloop => \@inputloop );
 
+
 my $found    = 0;
 my $waiting  = 0;
 my $reserved = 0;
@@ -420,23 +432,19 @@ if ( $messages->{'ResFound'}) {
         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,
+            reserve_id       => $nextreservinfo->{reserve_id},
+            itemnumber       => $itemnumber,
         );
 
         if ( $messages->{'transfert'} ) {
             $template->param(
-                itemtitle      => $biblio->title,
-                itemnumber     => $item->itemnumber,
+                itemtitle        => $biblio->title,
                 itembiblionumber => $biblio->biblionumber,
-                iteminfo       => $biblio->author,
-                diffbranch     => 1,
+                iteminfo         => $biblio->author,
+                diffbranch       => 1,
             );
         }
     }
@@ -451,6 +459,7 @@ if ( $messages->{'ResFound'}) {
                 transfertodo => $branchCheck ? undef : 1,
                 reserve_id   => $reserve->{reserve_id},
                 reserved     => 1,
+                itemnumber   => $itemnumber,
             );
         }
 
@@ -462,7 +471,6 @@ if ( $messages->{'ResFound'}) {
         patron         => $patron,
         barcode        => $barcode,
         destbranch     => $reserve->{'branchcode'},
-        itemnumber     => $reserve->{'itemnumber'},
         reservenotes   => $reserve->{'reservenotes'},
         reserve_id     => $reserve->{reserve_id},
         bormessagepref => $holdmsgpreferences->{'transports'},