Bug 19487: Do not return an item if not checked out
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 18 Oct 2017 16:59:56 +0000 (13:59 -0300)
committerKatrin Fischer <katrin.fischer.83@web.de>
Mon, 20 Nov 2017 21:26:00 +0000 (22:26 +0100)
To recreate:
1 - Manually add a lost fine to a ptron and include a barcode
2 - Attempt to write off the fine
3 - Internal server error
4 - Checkout an item and mark lost to checkin and fine
5 - Attempt to write off line
6 - Internal server error

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit 7b5c1fce5880f8592c5a9dbd40614a760bb2607e)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
(cherry picked from commit 243009bc9a07f89adbe14a4c8f35df85030f3dab)
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

C4/Circulation.pm

index e409ae1..1f6ae4d 100644 (file)
@@ -2131,6 +2131,11 @@ routine in C<C4::Accounts>.
 sub MarkIssueReturned {
     my ( $borrowernumber, $itemnumber, $dropbox_branch, $returndate, $privacy ) = @_;
 
+
+    # Retrieve the issue
+    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
+    my $issue_id = $issue->issue_id;
+
     my $anonymouspatron;
     if ( $privacy == 2 ) {
         # The default of 0 will not work due to foreign key constraints
@@ -2145,11 +2150,6 @@ sub MarkIssueReturned {
     my $schema   = $database->schema;
     my $dbh   = C4::Context->dbh;
 
-    my $issue_id = $dbh->selectrow_array(
-        q|SELECT issue_id FROM issues WHERE itemnumber = ?|,
-        undef, $itemnumber
-    );
-
     my $query = 'UPDATE issues SET returndate=';
     my @bind;
     if ($dropbox_branch) {
@@ -2172,9 +2172,6 @@ sub MarkIssueReturned {
         # Update the returndate
         $dbh->do( $query, undef, @bind );
 
-        # Retrieve the issue
-        my $issue = Koha::Checkouts->find( $issue_id ); # FIXME should be fetched earlier
-
         # Create the old_issues entry
         my $old_checkout = Koha::OldIssue->new($issue->unblessed)->store;