Bug 8231: display warning at check in if borrower is restricted
authorLyon3 Team <koha@univ-lyon3.fr>
Mon, 13 Jan 2014 11:09:01 +0000 (12:09 +0100)
committerGalen Charlton <gmc@esilibrary.com>
Mon, 5 May 2014 00:41:32 +0000 (00:41 +0000)
Display, at check in, a reminder of an already existing suspension date
even if the returned document is not late.

Test plan :
1) Apply the patch
2) Go to a borrower checkout page and checkout some documents with
   different passed duedate using "Specify due date" function. Checkout out
   one with the default duedate.
3) Check in the document with the bigger delay :
   You will get the message : 'X is now restricted until ...'
4) Check in one of the document with a smaller delay :
   You'll get a different message : 'Reminder : Patron was earlier
   restricted until...'.
5) Check in the document which is not late :
   You 'll get the same message as the previous one

Signed-off-by: JMBroust <jean-manuel.broust@univ-lyon2.fr>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/Circulation.pm
circ/returns.pl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt

index 91ed2db..39fbc68 100644 (file)
@@ -1888,10 +1888,21 @@ sub AddReturn {
         defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
         
         if ( $issue->{overdue} && $issue->{date_due} ) {
-# fix fine days
-            my $debardate =
-              _debar_user_on_return( $borrower, $item, $issue->{date_due}, $today );
-            $messages->{Debarred} = $debardate if ($debardate);
+        # fix fine days
+            my ($debardate,$reminder) = _debar_user_on_return( $borrower, $item, $issue->{date_due}, $today );
+            if ($reminder){
+                $messages->{'PrevDebarred'} = $debardate;
+            } else {
+                $messages->{'Debarred'} = $debardate if $debardate;
+            }
+        # 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'};
+             }
         }
     }
 
@@ -2083,7 +2094,10 @@ sub _debar_user_on_return {
                 expiration     => $new_debar_dt->ymd(),
                 type           => 'SUSPENSION',
             });
-
+            # if borrower was already debarred but does not get an extra debarment
+            if ( $borrower->{debarred} eq Koha::Borrower::Debarments::IsDebarred($borrower->{borrowernumber}) ) {
+                    return ($borrower->{debarred},1);
+            }
             return $new_debar_dt->ymd();
         }
     }
index 004fc50..6daddc4 100755 (executable)
@@ -501,6 +501,9 @@ foreach my $code ( keys %$messages ) {
         $err{debarborrowernumber} = $borrower->{borrowernumber};
         $err{debarname}           = "$borrower->{firstname} $borrower->{surname}";
     }
+    elsif ( $code eq 'PrevDebarred' ) {
+        $err{prevdebarred}        = $messages->{'PrevDebarred'};
+    }
     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
index 1fa1e14..2e48106 100644 (file)
@@ -402,6 +402,9 @@ $(document).ready(function () {
                     [% IF ( errmsgloo.debarred ) %]
                         <p class="problem"><a href="/cgi-bin/koha/circ/circulation.pl?borrowernumber=[% errmsgloo.debarborrowernumber %]">[% errmsgloo.debarname %]([% errmsgloo.debarcardnumber %])</a> is now debarred until [% errmsgloo.debarred | $KohaDates %] </p>
                     [% END %]
+                    [% IF ( errmsgloo.prevdebarred ) %]
+                        <p class="problem"><b>Reminder: </b>Patron was earlier restricted until [% errmsgloo.prevdebarred | $KohaDates %]</p>
+                    [% END %]
             [% END %]
 [% IF ( soundon ) %]
 <audio src="[% interface %]/[% theme %]/sound/critical.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>