From 2f12cdad51c1908dabf9980026640dda1ad0b3b2 Mon Sep 17 00:00:00 2001
From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com>
Date: Mon, 29 Jul 2019 09:10:04 +0100
Subject: [PATCH] Bug 23112: Update request status on return

This patch updates a request's status to RET upon return

Sponsored-by: Loughborough University
---
 C4/Circulation.pm  | 10 ++++++++++
 Koha/Illrequest.pm | 11 ++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 860d965cf1..ee6c420158 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -44,6 +44,7 @@ use Koha::Biblioitems;
 use Koha::DateUtils;
 use Koha::Calendar;
 use Koha::Checkouts;
+use Koha::Illrequests;
 use Koha::Items;
 use Koha::Patrons;
 use Koha::Patron::Debarments;
@@ -2130,6 +2131,15 @@ sub AddReturn {
         DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
     }
 
+	# Check if this item belongs to a biblio record that is attached to an
+	# ILL request, if it is we need to update the ILL request's status
+	if (C4::Context->preference('CirculateILL')) {
+		my $request = Koha::Illrequests->find(
+			{ biblio_id => $item->biblio->biblionumber }
+		);
+		$request->status('RET') if $request;
+	}
+
     # Transfer to returnbranch if Automatic transfer set or append message NeedsTransfer
     if (!$is_in_rotating_collection && ($doreturn or $messages->{'NotIssued'}) and !$resfound and ($branch ne $returnbranch) and not $messages->{'WrongTransfer'}){
         my $BranchTransferLimitsType = C4::Context->preference("BranchTransferLimitsType") eq 'itemtype' ? 'effective_itemtype' : 'ccode';
diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm
index 998422a788..a0c9402322 100644
--- a/Koha/Illrequest.pm
+++ b/Koha/Illrequest.pm
@@ -498,7 +498,16 @@ sub _core_status_graph {
             method         => 'check_out',
             next_actions   => [ ],
             ui_method_icon => 'fa-upload',
-        }
+        },
+		RET => {
+			prev_actions   => [ 'CHK' ],
+			id             => 'RET',
+			name           => 'Returned to library',
+			ui_method_name => 'Check in',
+			method         => 'check_in',
+			next_actions   => [ 'COMP' ],
+			ui_method_icon => 'fa-download',
+		}
     };
 }
 
-- 
2.11.0