From 370f3e212cba056a6dd11af274b1b84ffc57e8a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marc=20V=C3=A9ron?= <veron@veron.ch>
Date: Sat, 15 Nov 2014 17:14:10 +0100
Subject: [PATCH] Bug 13261 - Better check in message for patrons with
 indefinite restricition

This patch adds a better check in message for patrons with indefinite restriction.

To test:
Check out an item to a patron.
Add a manual restriction without expiry date to that patron.
Check in the item.

Without patch, the checkin message reads:
Reminder: Patron was earlier restricted until 9999-12-31

Apply patch and repeat steps above.
The message should now read:
Reminder: Patron has a restriction (no expiry date)

Signed-off-by: Frederic Demians <f.demians@tamil.fr>

Thanks Marc for catching this case. I was thinking like you that the wording
sounded strange while playing with bug 13242.
---
 C4/Circulation.pm                                       | 14 +++++++++-----
 circ/returns.pl                                         |  3 +++
 koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt |  4 ++++
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 0eb0863..d1d2b4b 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -1946,11 +1946,15 @@ sub AddReturn {
             }
         # there's no overdue on the item but borrower had been previously debarred
         } elsif ( $issue->{date_due} and $borrower->{'debarred'} ) {
-             my $borrower_debar_dt = dt_from_string( $borrower->{debarred} );
-             $borrower_debar_dt->truncate(to => 'day');
-             my $today_dt = $today->clone()->truncate(to => 'day');
-             if ( DateTime->compare( $borrower_debar_dt, $today_dt ) != -1 ) {
-                 $messages->{'PrevDebarred'} = $borrower->{'debarred'};
+             if ( $borrower->{debarred} eq "9999-12-31") {
+                $messages->{'ForeverDebarred'} = $borrower->{'debarred'};
+             } else {
+                  my $borrower_debar_dt = dt_from_string( $borrower->{debarred} );
+                  $borrower_debar_dt->truncate(to => 'day');
+                  my $today_dt = $today->clone()->truncate(to => 'day');
+                  if ( DateTime->compare( $borrower_debar_dt, $today_dt ) != -1 ) {
+                      $messages->{'PrevDebarred'} = $borrower->{'debarred'};
+                  }
              }
         }
     }
diff --git a/circ/returns.pl b/circ/returns.pl
index eeb0fe3..14997a1 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -506,6 +506,9 @@ foreach my $code ( keys %$messages ) {
     elsif ( $code eq 'PrevDebarred' ) {
         $err{prevdebarred}        = $messages->{'PrevDebarred'};
     }
+    elsif ( $code eq 'ForeverDebarred' ) {
+        $err{foreverdebarred}        = $messages->{'ForeverDebarred'};
+    }
     elsif ( $code eq 'NotForLoanStatusUpdated' ) {
         $err{NotForLoanStatusUpdated} = $messages->{NotForLoanStatusUpdated};
     }
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 8a12b8b..706fd0c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt
@@ -423,6 +423,10 @@ $(document).ready(function () {
                     [% IF ( errmsgloo.prevdebarred ) %]
                         <p class="problem"><b>Reminder: </b>Patron was earlier restricted until [% errmsgloo.prevdebarred | $KohaDates %]</p>
                     [% END %]
+                    [% IF ( errmsgloo.foreverdebarred ) %]
+                        <p class="problem"><b>Reminder: </b>Patron has a restriction (no expiry date)</p>
+                    [% END %]
+
             [% END %]
 [% IF ( soundon ) %]
 <audio src="[% interface %]/[% theme %]/sound/critical.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
-- 
2.1.2