From 1d9fc31d907e6ae198be21378551b09577b203c4 Mon Sep 17 00:00:00 2001
From: Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
Date: Thu, 2 Mar 2017 13:41:32 +0100
Subject: [PATCH] Bug 7317: Allow journey to 'COMP' status.

* Koha/Illrequest.pm (_core_status_graph): Add 'COMP' journey,
  and method.
  (mark_completed): new procedure.
* ill/ill-requests.pl: Handle mark_completed.
---
 Koha/Illrequest.pm  | 21 +++++++++++++++++----
 ill/ill-requests.pl | 11 +++++++++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm
index d975edef12..0f8bca8107 100644
--- a/Koha/Illrequest.pm
+++ b/Koha/Illrequest.pm
@@ -209,7 +209,7 @@ sub _core_status_graph {
             name           => 'Requested',
             ui_method_name => 'Confirm request',
             method         => 'confirm',
-            next_actions   => [ 'REQREV', 'CANCREQ' ],
+            next_actions   => [ 'REQREV', 'CANCREQ', 'COMP' ],
             ui_method_icon => 'fa-check',
         },
         GENREQ => {
@@ -252,10 +252,10 @@ sub _core_status_graph {
             prev_actions   => [ 'REQ' ],
             id             => 'COMP',
             name           => 'Completed',
-            ui_method_name => 0,
-            method         => 0,
+            ui_method_name => 'Mark completed',
+            method         => 'mark_completed',
             next_actions   => [ ],
-            ui_method_icon => 0,
+            ui_method_icon => 'fa-check',
         },
         KILL => {
             prev_actions   => [ 'QUEUED', 'REQREV', 'NEW' ],
@@ -384,6 +384,19 @@ sub available_actions {
     return \@available_actions;
 }
 
+sub mark_completed {
+    my ( $self ) = @_;
+    $self->status('COMP')->store unless ( $permitted );
+    return {
+        error   => 0,
+        status  => '',
+        message => '',
+        method  => 'mark_completed',
+        stage   => 'commit',
+        next    => 'illview',
+    };
+}
+
 sub backend_confirm {
     my ( $self, $params ) = @_;
 
diff --git a/ill/ill-requests.pl b/ill/ill-requests.pl
index a267a8db4d..5ab56b8722 100755
--- a/ill/ill-requests.pl
+++ b/ill/ill-requests.pl
@@ -160,6 +160,17 @@ if ( $op eq 'illview' ) {
             $params->{illrequest_id});
     }
 
+} elsif ( $op eq 'mark_completed' ) {
+    my $request = Koha::Illrequests->find($params->{illrequest_id});
+    my $backend_result = $request->mark_completed($params);
+    $template->param(
+        whole => $backend_result,
+        request => $request,
+    );
+
+    # handle special commit rules & update type
+    handle_commit_maybe($backend_result, $request);
+
 } elsif ( $op eq 'generic_confirm' ) {
     my $request = Koha::Illrequests->find($params->{illrequest_id});
     $params->{current_branchcode} = C4::Context->mybranch;
-- 
2.11.0