From e2c2386412e47c0671969f8a8488e17dc5b79125 Mon Sep 17 00:00:00 2001
From: Andrew <andrew@bywatersolutions.com>
Date: Fri, 20 Sep 2019 18:18:13 +0000
Subject: [PATCH] Bug 14697: Show an item has unresolved claims on checkin

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Lisette Scheer <lisetteslatah@gmail.com>
---
 C4/Circulation.pm                             | 14 ++++++++++++++
 Koha/Checkouts/ReturnClaim.pm                 | 12 ++++++++++++
 circ/returns.pl                               |  4 +++-
 .../prog/en/modules/circ/returns.tt           | 19 +++++++++++++++++++
 4 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 014c018628..87b15e6e80 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -60,6 +60,7 @@ use Koha::Account::Offsets;
 use Koha::Config::SysPrefs;
 use Koha::Charges::Fees;
 use Koha::Util::SystemPreferences;
+use Koha::Checkouts::ReturnClaims;
 use Carp;
 use List::MoreUtils qw( uniq any );
 use Scalar::Util qw( looks_like_number );
@@ -2121,6 +2122,19 @@ sub AddReturn {
         }
     }
 
+    if ( C4::Context->preference('ClaimReturnedLostValue') ) {
+        my $claims = Koha::Checkouts::ReturnClaims->search(
+           {
+               itemnumber => $item->id,
+               resolution => undef,
+           }
+        );
+
+        if ( $claims->count ) {
+            $messages->{ReturnClaims} = $claims;
+        }
+    }
+
     return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ));
 }
 
diff --git a/Koha/Checkouts/ReturnClaim.pm b/Koha/Checkouts/ReturnClaim.pm
index 3fff2e6608..de014bd627 100644
--- a/Koha/Checkouts/ReturnClaim.pm
+++ b/Koha/Checkouts/ReturnClaim.pm
@@ -23,6 +23,7 @@ use base qw(Koha::Object);
 
 use Koha::Checkouts;
 use Koha::Old::Checkouts;
+use Koha::Patrons;
 
 =head1 NAME
 
@@ -48,6 +49,17 @@ sub checkout {
     return Koha::Old::Checkout->_new_from_dbic( $old_issue ) if $old_issue;
 }
 
+=head3 patron
+
+=cut
+
+sub patron {
+    my ( $self ) = @_;
+
+    my $borrower = $self->_result->borrowernumber;
+    return Koha::Patron->_new_from_dbic( $borrower ) if $borrower;
+}
+
 =head3 _type
 
 =cut
diff --git a/circ/returns.pl b/circ/returns.pl
index 42226b4bcc..ddce95ab75 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -542,7 +542,9 @@ foreach my $code ( keys %$messages ) {
     elsif ( $code eq 'DataCorrupted' ) {
         $err{data_corrupted} = 1;
     }
-    else {
+    elsif ( $code eq 'ReturnClaims' ) {
+        $template->param( ReturnClaims => $messages->{ReturnClaims} );
+    } 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
     }
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt
index dd359dd881..6294c06d2a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt
@@ -156,6 +156,25 @@
                                 </div>
                             [% END %]
 
+							<!-- Item has return claim(s) -->
+							[% IF ( ReturnClaims ) %]
+								<div class="dialog alert return-claim">
+									<h3>
+										This item has been claimed as returned by:
+										<ul>
+										[% FOREACH rc IN ReturnClaims %]
+											[% SET patron = rc.patron %]
+											<li>
+												<a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% patron.borrowernumber | uri %]">
+													[% patron.firstname | html %] [% patron.surname | html %]
+												</a>
+											</li>
+										[% END %]
+										</ul>
+									</h3>
+								</div>
+							[% END %]
+
                             <!-- Patron has waiting holds -->
                             [% IF ( waiting_holds ) %]
                                 <div id="awaiting-pickup" class="dialog message">
-- 
2.21.0 (Apple Git-122)