From 29ea405729155ace5ee69d86db8d03a4d7fe10af Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Sun, 20 Oct 2013 18:39:15 -0400
Subject: [PATCH] Bug 10694 - Allow arbitrary backdating of returns - QA Followup

---
 Koha/Template/Plugin/Borrowers.pm                  |   40 ++++++++++++++++++++
 circ/returns.pl                                    |    3 +-
 .../intranet-tmpl/prog/en/modules/circ/returns.tt  |   12 ++++++
 3 files changed, 54 insertions(+), 1 deletions(-)
 create mode 100644 Koha/Template/Plugin/Borrowers.pm

diff --git a/Koha/Template/Plugin/Borrowers.pm b/Koha/Template/Plugin/Borrowers.pm
new file mode 100644
index 0000000..45c4071
--- /dev/null
+++ b/Koha/Template/Plugin/Borrowers.pm
@@ -0,0 +1,40 @@
+package Koha::Template::Plugin::Borrowers;
+
+# Copyright ByWater Solutions 2013
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+
+use base qw( Template::Plugin );
+
+use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/;
+
+use C4::Koha;
+
+sub IsDebarred {
+    my ( $self, $borrower ) = @_;
+
+    if ( $borrower->{'debarred'} && check_date( split( /-/, $borrower->{'debarred'} ) ) ) {
+        if ( Date_to_Days(Date::Calc::Today) < Date_to_Days( split( /-/, $borrower->{'debarred'} ) ) ) {
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+1;
diff --git a/circ/returns.pl b/circ/returns.pl
index f8c4608..a38455a 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -268,7 +268,8 @@ if ($barcode) {
         itemtype         => $biblio->{'itemtype'},
         ccode            => $biblio->{'ccode'},
         itembiblionumber => $biblio->{'biblionumber'},    
-	additional_materials => $biblio->{'materials'}
+        borrower         => $borrower,
+        additional_materials => $biblio->{'materials'},
     );
 
     my %input = (
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 a6cea69..2bfc9b1 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt
@@ -1,6 +1,7 @@
 [% USE KohaDates %]
 [% USE Branches %]
 [% USE Koha %]
+[% USE Borrowers %]
 
 [% INCLUDE 'doc-head-open.inc' %]
 <title>Koha &rsaquo; Circulation &rsaquo; Check in [% title |html %]</title>
@@ -102,6 +103,17 @@ $(document).ready(function () {
     </div>
 [% END %]
 
+<!-- Patron is restricted and checkin was backdated -->
+[% IF return_date_override && Borrowers.IsDebarred( borrower ) %]
+    <div id="restricted_backdated" class="dialog message">
+        <h3>
+            <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=[% borrower.borrowernumber %]">
+                [% borrower.firstname %] [% borrower.surname %]
+            </a>
+            is retricted. Please verify this patron should still be restricted.
+        </h3>
+    </div>
+[% END %]
 
 [% IF ( wrongbranch ) %]
 <div class="dialog alert"><h3>Cannot check in</h3><p>This item must be checked in at its home library. <strong>NOT CHECKED IN</strong></p>
-- 
1.7.2.5