Bug 6328 fine in days does not work
authorPaul Poulain <paul.poulain@biblibre.com>
Wed, 11 May 2011 14:54:56 +0000 (16:54 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Fri, 25 Nov 2011 13:00:47 +0000 (14:00 +0100)
Some code coming from BibLibre has been lost in the process of inclusion in
3.4. The result is that fine in days does not work at all (you can setup rules,
but it does nothing)

Step to reproduce:

- Koha > Admin > circ rules > set 1 day fine every day of overdue for default
  rule
- Issue a book return date last week
- check-in the book => no debarment is set

The following patch will fix all of those problems by :

* updating borrowers.debarred to a date field (instead of tinyint). It contains
  the limit of the debarment
* changing API of DebarMember and UpdateBorrowerDebarred to pass a date
* display debarrdate where applicable. Note that a debarrdate of 31/12/9999 is
  considered as unlimited and not displayed
* added a debarrcomment, usefull to explain why a patron is debarred (this is
  independant from debarrdate changes and can be used when placing an unlimited
  debarment too)

[2011-05-12] F. Demians. It works as described. And I can confirm this
functionality is impatiently awaited by French libraries since one year. Thanks
BibLibre for the good work and for contributing this code.

Bug 6328 Followup--update DB structure

Thanks Katrin.

Bug 6328: make comment a textbox / fix debar by notice trigger

Debarring by notice triggers was broken, because the new function
expects a date as second parameter.

The comment field in patron account details was a very long text field.
Patch changes it to be a textbox instead.

Bug 6328: Lift debarment leaves patron account

'Lift debarment' redirects to an empty circulation page.

BZ6328 follow-up 3

Fixes comment 23 from Fernando L. Canizo : when the patron was debarred and debar removed
he still could not check-out.

The changes in the IsMemberBlocked (that were on biblibre/master) were lost somewhere
The sub was still checking for old_issues instead of calling CheckBorrowerDebarred
to get a debardate if applicable

Note : this bug was appearing only is you had issuing rules defined for itemtype/categorycode/branch.
Seemed to work if you had only default rules. That's probably why it hadn't been spotted before

BZ6328 follow-up 4
Comments fron Zeno Tajoli: The patch is OK and I sign-off it. Two little changes done on
installer/data/mysql/kohastructure.sql and installer/data/mysql/updatedatabase.pl

Signed-off-by: koha <koha@kohabase.localdomain>
17 files changed:
C4/Circulation.pm
C4/Members.pm
C4/Overdues.pm
circ/circulation.pl
circ/returns.pl
installer/data/mysql/kohastructure.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt
koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt
koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt
members/memberentry.pl
members/moremember.pl
members/setstatus.pl
misc/cronjobs/overdue_notices.pl
opac/opac-user.pl

index d2c5f59..debef01 100644 (file)
@@ -42,6 +42,7 @@ use Date::Calc qw(
   Date_to_Days
   Day_of_Week
   Add_Delta_Days       
+  check_date
 );
 use POSIX qw(strftime);
 use C4::Branch; # GetBranches
@@ -1631,6 +1632,10 @@ sub AddReturn {
     if ($borrowernumber) {
         my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox);
         defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!";  # zero is OK, check defined
+        
+        # fix fine days
+        my $debardate = _FixFineDaysOnReturn( $borrower, $item, $issue->{date_due} );
+        $messages->{'Debarred'} = $debardate if ($debardate);
     }
 
     # find reserves.....
@@ -1754,6 +1759,61 @@ sub MarkIssueReturned {
     $sth_del->execute($borrowernumber, $itemnumber);
 }
 
+=head2 _FixFineDaysOnReturn
+
+    &_FixFineDaysOnReturn($borrower, $item, $datedue);
+
+C<$borrower> borrower hashref
+
+C<$item> item hashref
+
+C<$datedue> date due
+
+Internal function, called only by AddReturn that calculate and update the user fine days, and debars him
+
+=cut
+
+sub _FixFineDaysOnReturn {
+    my ( $borrower, $item, $datedue ) = @_;
+
+    if ($datedue) {
+        $datedue = C4::Dates->new( $datedue, "iso" );
+    } else {
+        return;
+    }
+
+    my $branchcode = _GetCircControlBranch( $item, $borrower );
+    my $calendar = C4::Calendar->new( branchcode => $branchcode );
+    my $today = C4::Dates->new();
+
+    my $deltadays = $calendar->daysBetween( $datedue, C4::Dates->new() );
+
+    my $circcontrol = C4::Context::preference('CircControl');
+    my $issuingrule = GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
+    my $finedays    = $issuingrule->{finedays};
+
+    # exit if no finedays defined
+    return unless $finedays;
+    my $grace = $issuingrule->{firstremind};
+
+    if ( $deltadays - $grace > 0 ) {
+        my @newdate = Add_Delta_Days( Today(), $deltadays * $finedays );
+        my $isonewdate = join( '-', @newdate );
+        my ( $deby, $debm, $debd ) = split( /-/, $borrower->{debarred} );
+        if ( check_date( $deby, $debm, $debd ) ) {
+            my @olddate = split( /-/, $borrower->{debarred} );
+
+            if ( Delta_Days( @olddate, @newdate ) > 0 ) {
+                C4::Members::DebarMember( $borrower->{borrowernumber}, $isonewdate );
+                return $isonewdate;
+            }
+        } else {
+            C4::Members::DebarMember( $borrower->{borrowernumber}, $isonewdate );
+            return $isonewdate;
+        }
+    }
+}
+
 =head2 _FixOverduesOnReturn
 
    &_FixOverduesOnReturn($brn,$itm, $exemptfine, $dropboxmode);
index 4f5a299..27b6b0e 100644 (file)
@@ -623,39 +623,12 @@ sub IsMemberBlocked {
     my $borrowernumber = shift;
     my $dbh            = C4::Context->dbh;
 
-    # does patron have current fine days?
-       my $strsth=qq{
-            SELECT
-            ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due) ) AS blockingdate,
-            DATEDIFF(ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due)),NOW()) AS blockedcount
-            FROM old_issues
-       };
-    if(C4::Context->preference("item-level_itypes")){
-        $strsth.=
-               qq{ LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber)
-            LEFT JOIN issuingrules ON (issuingrules.itemtype=items.itype)}
-    }else{
-        $strsth .= 
-               qq{ LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber)
-            LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
-            LEFT JOIN issuingrules ON (issuingrules.itemtype=biblioitems.itemtype) };
-    }
-       $strsth.=
-        qq{ WHERE finedays IS NOT NULL
-            AND  date_due < returndate
-            AND borrowernumber = ?
-            ORDER BY blockingdate DESC, blockedcount DESC
-            LIMIT 1};
-       my $sth=$dbh->prepare($strsth);
-    $sth->execute($borrowernumber);
-    my $row = $sth->fetchrow_hashref;
-    my $blockeddate  = $row->{'blockeddate'};
-    my $blockedcount = $row->{'blockedcount'};
+    my $blockeddate = CheckBorrowerDebarred($borrowernumber);
 
-    return (1, $blockedcount) if $blockedcount > 0;
+    return ( 1, $blockeddate ) if $blockeddate;
 
     # if he have late issues
-    $sth = $dbh->prepare(
+    my $sth = $dbh->prepare(
         "SELECT COUNT(*) as latedocs
          FROM issues
          WHERE borrowernumber = ?
@@ -664,9 +637,9 @@ sub IsMemberBlocked {
     $sth->execute($borrowernumber);
     my $latedocs = $sth->fetchrow_hashref->{'latedocs'};
 
-    return (-1, $latedocs) if $latedocs > 0;
+    return ( -1, $latedocs ) if $latedocs > 0;
 
-    return (0, 0);
+    return ( 0, 0 );
 }
 
 =head2 GetMemberIssuesAndFines
@@ -2078,7 +2051,7 @@ sub GetBorrowersNamesAndLatestIssue {
 
 =head2 DebarMember
 
-  my $success = DebarMember( $borrowernumber );
+my $success = DebarMember( $borrowernumber, $todate );
 
 marks a Member as debarred, and therefore unable to checkout any more
 items.
@@ -2090,13 +2063,16 @@ true on success, false on failure
 
 sub DebarMember {
     my $borrowernumber = shift;
+    my $todate         = shift;
 
     return unless defined $borrowernumber;
     return unless $borrowernumber =~ /^\d+$/;
 
-    return ModMember( borrowernumber => $borrowernumber,
-                      debarred       => 1 );
-    
+    return ModMember(
+        borrowernumber => $borrowernumber,
+        debarred       => $todate
+    );
+
 }
 
 =head2 ModPrivacy
index 9f4b22f..7e9b9c9 100644 (file)
@@ -1077,16 +1077,17 @@ sub CheckBorrowerDebarred {
         SELECT debarred
         FROM borrowers
         WHERE borrowernumber=?
+        AND debarred > NOW()
     |;
     my $sth = $dbh->prepare($query);
     $sth->execute($borrowernumber);
-    my ($debarredstatus) = $sth->fetchrow;
-    return ( $debarredstatus eq '1' ? 1 : 0 );
+    my $debarredstatus = $sth->fetchrow;
+    return $debarredstatus;
 }
 
 =head2 UpdateBorrowerDebarred
 
-    ($borrowerstatut) = &UpdateBorrowerDebarred($borrowernumber);
+($borrowerstatut) = &UpdateBorrowerDebarred($borrowernumber, $todate);
 
 update status of borrowers in borrowers table (field debarred)
 
@@ -1095,16 +1096,16 @@ C<$borrowernumber> borrower number
 =cut
 
 sub UpdateBorrowerDebarred{
-    my($borrowernumber) = @_;
-    my $dbh = C4::Context->dbh;
-        my $query=qq|UPDATE borrowers
-             SET debarred='1'
+    my ( $borrowernumber, $todate ) = @_;
+    my $dbh   = C4::Context->dbh;
+    my $query = qq|UPDATE borrowers
+             SET debarred=?
                      WHERE borrowernumber=?
             |;
-    my $sth=$dbh->prepare($query);
-        $sth->execute($borrowernumber);
-        $sth->finish;
-        return 1;
+    my $sth = $dbh->prepare($query);
+    $sth->execute( $todate, $borrowernumber );
+    $sth->finish;
+    return 1;
 }
 
 =head2 CheckExistantNotifyid
index 378956e..fa043dd 100755 (executable)
@@ -30,6 +30,7 @@ use C4::Dates qw/format_date/;
 use C4::Branch; # GetBranches
 use C4::Koha;   # GetPrinter
 use C4::Circulation;
+use C4::Overdues qw/CheckBorrowerDebarred/;
 use C4::Members;
 use C4::Biblio;
 use C4::Reserves;
@@ -260,6 +261,16 @@ if ($borrowernumber) {
         issuecount   => $issue,
         finetotal    => $fines
     );
+
+    my $debar = CheckBorrowerDebarred($borrowernumber);
+    if ($debar) {
+        $template->param( 'userdebarred'    => 1 );
+        $template->param( 'debarredcomment' => $borrower->{debarredcomment} );
+        if ( $debar ne "9999-12-31" ) {
+            $template->param( 'userdebarreddate' => C4::Dates::format_date($debar) );
+        }
+    }
+
 }
 
 #
index afe574f..98d310e 100755 (executable)
@@ -459,7 +459,12 @@ foreach my $code ( keys %$messages ) {
     }
     elsif ( $code eq 'Wrongbranch' ) {
     }
-
+    elsif ( $code eq 'Debarred' ) {
+        $err{debarred}            = format_date( $messages->{'Debarred'} );
+        $err{debarcardnumber}     = $borrower->{cardnumber};
+        $err{debarborrowernumber} = $borrower->{borrowernumber};
+        $err{debarname}           = "$borrower->{firstname} $borrower->{surname}";
+    }
     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 e4388a4..452173d 100644 (file)
@@ -232,7 +232,8 @@ CREATE TABLE `borrowers` ( -- this table includes information about your patrons
   `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
   `gonenoaddress` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having an unconfirmed address
   `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
-  `debarred` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as being restricted
+  `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYY-MM-DD)
+  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of the patron
   `contactname` mediumtext, -- used for children and profesionals to include surname or last name of guarentor or organization name
   `contactfirstname` text, -- used for children to include first name of guarentor
   `contacttitle` text, -- used for children to include title (Mr., Mrs., etc) of guarentor
@@ -693,7 +694,8 @@ CREATE TABLE `deletedborrowers` ( -- stores data related to the patrons/borrower
   `dateexpiry` date default NULL, -- date the patron/borrower's card is set to expire (YYYY-MM-DD)
   `gonenoaddress` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having an unconfirmed address
   `lost` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as having lost their card
-  `debarred` tinyint(1) default NULL, -- set to 1 for yes and 0 for no, flag to note that library marked this patron/borrower as being restricted
+  `debarred` date default NULL, -- until this date the patron can only check-in (no loans, no holds, etc.), is a fine based on days instead of money (YYY-MM-DD)
+  `debarredcomment` VARCHAR(255) DEFAULT NULL, -- comment on the stop of patron
   `contactname` mediumtext, -- used for children and profesionals to include surname or last name of guarentor or organization name
   `contactfirstname` text, -- used for children to include first name of guarentor
   `contacttitle` text, -- used for children to include title (Mr., Mrs., etc) of guarentor
index 815a71d..5a1dc97 100755 (executable)
@@ -4438,6 +4438,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion($DBversion);
 }
 
+
 $DBversion = "3.05.00.011";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACResultsSidebar','','Define HTML to be included on the search results page, underneath the facets sidebar','70|10','Textarea')");
@@ -4550,6 +4551,20 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.05.00.XXX";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    my $borrowers = $dbh->selectcol_arrayref( "SELECT borrowernumber from borrowers where debarred <>0;", { Columns => [1] } );
+    $dbh->do("ALTER TABLE borrowers MODIFY debarred DATE DEFAULT NULL;");
+    $dbh->do( "UPDATE borrowers set debarred='9999-12-31' where borrowernumber IN (" . join( ",", @$borrowers ) . ");" ) if ($borrowers and scalar(@$borrowers)>0);
+    $dbh->do("ALTER TABLE borrowers ADD COLUMN debarredcomment VARCHAR(255) DEFAULT NULL AFTER debarred;");
+    $dbh->do("ALTER TABLE deletedborrowers MODIFY debarred DATE DEFAULT NULL;");
+    $dbh->do("ALTER TABLE deletedborrowers ADD COLUMN debarredcomment VARCHAR(255) DEFAULT NULL AFTER debarred;");
+    print "Upgrade done (Change borrowers.debarred into Date )\n";
+
+    SetVersion($DBversion);
+}
+
+
 =head1 FUNCTIONS
 
 =head2 DropAllForeignKeys($table)
index f98ff1d..5fadb18 100644 (file)
@@ -563,6 +563,17 @@ No patron matched <span class="ex">[% message %]</span>
                        <li class="blocker"><span class="circ-hlt">Lost: </span>Patron's card is lost</li>
                        [% END %]
 
+            [% IF ( userdebarred ) %]
+               <li class="blocker">
+               <span class="circ-hlt"> Restricted:</span> Patron's account is restricted [% IF (userdebarreddate ) %] until [% userdebarreddate %] [% END %] [% IF (debarredcomment ) %]([% debarredcomment %])[% END %]
+               <form class="inline compact" action="/cgi-bin/koha/members/setstatus.pl" method="post">
+                       <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
+                       <input type="hidden" name="destination" value="circ" />
+                       <input type="hidden" name="cardnumber" value="[% cardnumber %]" />
+                       <input type="submit" value="Lift Debarment" />
+               </form>
+                       </li>[% END %]
+
             [% IF ( dbarred ) %]<li class="blocker">
                <span class="circ-hlt"> Restricted:</span> Patron's account is restricted <a href="/cgi-bin/koha/members/setstatus.pl?borrowernumber=[% borrowernumber %]&amp;cardnumber=[% cardnumber %]&amp;destination=circ&amp;status=0">Lift restriction</a>
 </li>[% END %]
index 65df373..70367ae 100644 (file)
@@ -321,6 +321,9 @@ function Dopop(link) {
                     [% IF ( errmsgloo.withdrawn ) %]
                         <p class="problem">Item is withdrawn.</p>
                     [% END %]
+                    [% 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 %] </p>
+                    [% END %]
             [% END %]
 [% IF ( soundon ) %]
 <audio src="/intranet-tmpl/prog/sound/critical.ogg" autoplay="autoplay" autobuffer="autobuffer"></audio>
index 47ea6c9..937b28e 100644 (file)
                                <input type="radio" id="no[% flagloo.name %]" name="[% flagloo.name %]" value="0" />
                                [% END %]
 
-</li>
+            </li>
                        [% END %]
+                       <li>
+                               <label for="yesdebarred" class="radio">Debarred: </label>
+                               [% IF ( debarred ) %]
+                               <label for="yesdebarred">Yes </label>
+                               <input type="radio" id="yesdebarred" name="debarred" value="1" checked="checked"/>
+                <label for="nodebarred">No </label>
+                <input type="radio" id="nodebarred" name="debarred" value="0"/>
+                               [% ELSE %]
+                               <label for="yesdebarred">Yes </label>
+                               <input type="radio" id="yesdebarred" name="debarred" value="1" />
+                <label for="nodebarred">No </label>
+                <input type="radio" id="nodebarred" name="debarred" value="0" checked="checked"/>
+                               [% END %]
+                               
+                               <br />
+                               <label for="datedebarred" class="radio">until:</label> 
+                               <input type="text" name="datedebarred" id="debarred" class="debarred" value="[% datedebarred %]"[% IF ( opduplicate ) %] onclick="this.value=''"[% END %] />
+                               <img src="[% themelang %]/lib/calendar/cal.gif" id="debarred_button" alt="Show Calendar" />
+                        <script language="JavaScript" type="text/javascript">
+                           Calendar.setup(
+                           {
+                               inputField : "debarred",
+                               ifFormat : "[% DHTMLcalendar_dateformat %]",
+                               button : "debarred_button"
+                           }
+                           );
+                       </script>
+                       <br />
+                       <label for="debarredcomment" class="radio">Comment:</label>
+                               <textarea id="debarredcomment" name="debarredcomment" cols="55" rows="3" [% IF ( opduplicate ) %] onclick="this.value=''"[% END %]>[% debarredcomment %]</textarea>
+               </li>
+
                        </ol>
                        </fieldset>
+    
                [% END %]       
 
 [% END %]
index cce4cd9..454032c 100644 (file)
@@ -164,12 +164,11 @@ function validate1(date) {
 
     [% IF ( flagged ) %]
     <ul>
-        [% IF ( debarred ) %]
-            <li>Patron is restricted
+        [% IF ( userdebarred ) %]
+            <li>Patron is restricted[% IF ( userdebarreddate ) %] until [% userdebarreddate%] [% IF (debarredcomment ) %]([% debarredcomment %])[% END %][% END %]
             <form class="inline compact" action="/cgi-bin/koha/members/setdebar.pl" method="post">
                 <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" />
-                <input type="hidden" name="status" value="0" />
-                <input type="submit" value="Lift Restriction" />
+                <input type="submit" value="Lift Debarment" />
             </form>
             </li>
         [% END %]
index daa5636..0971f46 100644 (file)
@@ -93,7 +93,7 @@ $.tablesorter.addParser({
                <div class="dialog alert">
         <ul>
             [% IF ( BORROWER_INF.debarred ) %]
-                <li><strong>Please note:</strong> Your account has been frozen. Usually the reason for freezing an account is old overdues or damage fees.If <a href="/cgi-bin/koha/opac-user.pl">your account page</a> shows your account to be clear, please contact the library.</li>
+                <li><strong>Please note:</strong> Your account has been frozen until [% BORROWER_INF.debarred %] - [% BORROWER_INF.debarredcomment %]. Usually the reason for freezing an account is old overdues or damage fees.If <a href="/cgi-bin/koha/opac-user.pl">your account page</a> shows your account to be clear, please contact the library.</li>
             [% END %]
             [% IF ( BORROWER_INF.gonenoaddress ) %]
                 <li><strong>Please note:</strong> According to our records, we don't have up-to-date [% UNLESS ( BORROWER_INF.OPACPatronDetails ) %]<a href="/cgi-bin/koha/opac-userupdate.pl">contact information</a>[% ELSE %]contact information[% END %] on file.  Please contact the library[% IF ( BORROWER_INF.OPACPatronDetails ) %] or use the <a href="/cgi-bin/koha/opac-userupdate.pl">online update form</a> to submit current information (<em>Please note:</em> there may be a delay in restoring your account if you submit online)[% END %].</li>
index f01261e..d169dbd 100755 (executable)
@@ -131,6 +131,17 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' )
             $newdata{$key} =~ s/\"/&quot;/g unless $key eq 'borrowernotes' or $key eq 'opacnote';
         }
     }
+
+    ## Manipulate debarred
+    if ( $newdata{debarred} ) {
+        $newdata{debarred} = $newdata{datedebarred} ? $newdata{datedebarred} : "9999-12-31";
+    } elsif ( exists( $newdata{debarred} ) && !( $newdata{debarred} ) ) {
+        undef( $newdata{debarred} );
+        undef( $newdata{debarredcomment} );
+    } elsif ( exists( $newdata{debarredcomment} ) && $newdata{debarredcomment} eq "" ) {
+        undef( $newdata{debarredcomment} );
+    }
+    
     my $dateobject = C4::Dates->new();
     my $syspref = $dateobject->regexp();               # same syspref format for all 3 dates
     my $iso     = $dateobject->regexp('iso');  #
@@ -515,8 +526,7 @@ while (@relationships) {
 }
 
 my %flags = ( 'gonenoaddress' => ['gonenoaddress' ],
-        'lost'          => ['lost'],
-        'debarred'      => ['debarred']);
+        'lost'          => ['lost']);
 
  
 my @flagdata;
@@ -637,7 +647,10 @@ if (C4::Context->preference('uppercasesurnames')) {
        $data{'surname'}    =uc($data{'surname'}    );
        $data{'contactname'}=uc($data{'contactname'});
 }
-foreach (qw(dateenrolled dateexpiry dateofbirth)) {
+
+$data{debarred} = C4::Overdues::CheckBorrowerDebarred($borrowernumber);
+$data{datedebarred} = $data{debarred} if ( $data{debarred} ne "9999-12-31" );
+foreach (qw(dateenrolled dateexpiry dateofbirth datedebarred)) {
        $data{$_} = format_date($data{$_});     # back to syspref for display
        $template->param( $_ => $data{$_});
 }
index f264377..6e5407c 100755 (executable)
@@ -49,6 +49,7 @@ use C4::Letters;
 use C4::Biblio;
 use C4::Reserves;
 use C4::Branch; # GetBranchName
+use C4::Overdues qw/CheckBorrowerDebarred/;
 use C4::Form::MessagingPreferences;
 use C4::NewsChannels; #get slip news
 use List::MoreUtils qw/uniq/;
@@ -146,10 +147,19 @@ foreach (qw(dateenrolled dateexpiry dateofbirth)) {
 }
 $data->{'IS_ADULT'} = ( $data->{'categorycode'} ne 'I' );
 
-for (qw(debarred gonenoaddress lost borrowernotes)) {
+for (qw(gonenoaddress lost borrowernotes)) {
         $data->{$_} and $template->param(flagged => 1) and last;
 }
 
+my $debar = CheckBorrowerDebarred($borrowernumber);
+if ($debar) {
+    $template->param( 'userdebarred' => 1, 'flagged' => 1 );
+    if ( $debar ne "9999-12-31" ) {
+        $template->param( 'userdebarreddate' => C4::Dates::format_date($debar) );
+        $template->param( 'debarredcomment'  => $data->{debarredcomment} );
+    }
+}
+
 $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
 $data->{ "sex_".$data->{'sex'}."_p" } = 1;
 
index addeeb3..a45a331 100755 (executable)
@@ -51,8 +51,8 @@ if ( $reregistration eq 'y' ) {
        # re-reregistration function to automatic calcul of date expiry
        $dateexpiry = ExtendMemberSubscriptionTo( $borrowernumber );
 } else {
-       my $sth=$dbh->prepare("Update borrowers set debarred = ? where borrowernumber = ?");
-       $sth->execute($status,$borrowernumber); 
+    my $sth = $dbh->prepare("UPDATE borrowers SET debarred = ?, debarredcomment = '' WHERE borrowernumber = ?");
+    $sth->execute( $status, $borrowernumber );
        $sth->finish;
        }
 
index 37774b5..5646efc 100755 (executable)
@@ -473,7 +473,7 @@ END_SQL
                 if ( $overdue_rules->{"debarred$i"} ) {
     
                     #action taken is debarring
-                    C4::Members::DebarMember($borrowernumber);
+                    C4::Members::DebarMember($borrowernumber, '9999-12-31');
                     $verbose and warn "debarring $borrowernumber $firstname $lastname\n";
                 }
                 my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays ));
index ca18288..9806c9f 100755 (executable)
@@ -104,6 +104,7 @@ if ( $borr->{'amountoutstanding'} < 0 ) {
 }
 
 $borr->{'amountoutstanding'} = sprintf "%.02f", $borr->{'amountoutstanding'};
+$borr->{'debarred'} = C4::Dates->new($borr->{'debarred'},'iso')->output;
 
 my @bordat;
 $bordat[0] = $borr;