Bug 8566: [SIGNED-OFF] Enable koha-foreach to insert the instancename into commands
[koha_fer] / circ / returns.pl
index 55888a6..a95a17c 100755 (executable)
@@ -186,6 +186,33 @@ my $calendar    = Koha::Calendar->new( branchcode => $userenv_branch );
 #dropbox: get last open day (today - 1)
 my $today       = DateTime->now( time_zone => C4::Context->tz());
 my $dropboxdate = $calendar->addDate($today, -1);
+
+my $return_date_override = $query->param('return_date_override');
+my $return_date_override_remember =
+  $query->param('return_date_override_remember');
+if ($return_date_override) {
+    if ( C4::Context->preference('SpecifyReturnDate') ) {
+        # FIXME we really need to stop adding more uses of C4::Dates
+        if ( $return_date_override =~ C4::Dates->regexp('syspref') ) {
+
+            # note that we've overriden the return date
+            $template->param( return_date_was_overriden => 1);
+            # Save the original format if we are remembering for this series
+            $template->param(
+                return_date_override          => $return_date_override,
+                return_date_override_remember => 1
+            ) if ($return_date_override_remember);
+
+            my $dt = dt_from_string($return_date_override);
+            $return_date_override =
+              DateTime::Format::MySQL->format_datetime($dt);
+        }
+    }
+    else {
+        $return_date_override = q{};
+    }
+}
+
 if ($dotransfer){
 # An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer
     my $transferitem = $query->param('transferitem');
@@ -222,7 +249,7 @@ if ($barcode) {
 # save the return
 #
     ( $returned, $messages, $issueinformation, $borrower ) =
-      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode);     # do the return
+      AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode, $return_date_override );
     my $homeorholdingbranchreturn = C4::Context->preference('HomeOrHoldingBranchReturn');
     $homeorholdingbranchreturn ||= 'homebranch';
 
@@ -250,7 +277,8 @@ if ($barcode) {
         itemtype         => $biblio->{'itemtype'},
         ccode            => $biblio->{'ccode'},
         itembiblionumber => $biblio->{'biblionumber'},    
-       additional_materials => $biblio->{'materials'}
+        borrower         => $borrower,
+        additional_materials => $biblio->{'materials'},
     );
 
     my %input = (
@@ -473,6 +501,12 @@ foreach my $code ( keys %$messages ) {
         $err{debarborrowernumber} = $borrower->{borrowernumber};
         $err{debarname}           = "$borrower->{firstname} $borrower->{surname}";
     }
+    elsif ( $code eq 'PrevDebarred' ) {
+        $err{prevdebarred}        = $messages->{'PrevDebarred'};
+    }
+    elsif ( $code eq 'NotForLoanStatusUpdated' ) {
+        $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
+    }
     else {
         die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
         # This forces the issue of staying in sync w/ Circulation.pm