Bugzilla – Attachment 19414 Details for
Bug 2720
Overdues which debar automatically should undebar automatically when returned
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 2720 - Overdues which debar automatically should undebar automatically when returned
Bug-2720---Overdues-which-debar-automatically-shou.patch (text/plain), 56.76 KB, created by
Kyle M Hall (khall)
on 2013-07-05 14:05:33 UTC
(
hide
)
Description:
Bug 2720 - Overdues which debar automatically should undebar automatically when returned
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2013-07-05 14:05:33 UTC
Size:
56.76 KB
patch
obsolete
>From 6439b2449acb41e014401ec8136dd6728bb31aca Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 29 Jan 2013 09:34:13 -0500 >Subject: [PATCH] Bug 2720 - Overdues which debar automatically should undebar automatically when returned > >This patch adds a more extensible and flexible debarments system to Koha. The fields >borrowers.debarred and borrowers.debarredcomment are retained for compatibility and >speed. > >This system supports having debarments for multiple reasons. There are currently >three types of debarments: >OVERDUES - Generated by overdue_notices.pl if the notice should debar a patron >SUSPENSION - A punative debarment generated on checkin via an issuing rule >MANUAL - A debarment created manually by a librarian > >OVERDUE debarments are cleared automatically when all overdue items have been returned, >if the new system preference AutoRemoveOverduesRestrictions is enabled. It is disabled >by default to retain current default functionality. > >Whenever a borrowers debarments are modified, the system updates the borrowers debarment >fields with the highest expiration from all the borrowers debarments, and concatenates >the comments from the debarments together. > >Test plan: > 1) Apply patch > 2) Run updatedatabase.pl > 3) Verify the borrower_debarments table has been created and > populated with the pre-existing debarments > 4) Run t/db_dependent/Borrower_Debarments.t > 5) Manually debar a patron, with an expiration date > 6) Verify the patron cannot be issued to > 7) Add another manual debarment with a different expiration date > 8) Verify the 'restricted' message lists the date farthest into the future > 9) Add another manual debarment with no expiration date >10) Verify the borrower is now debarred indefinitely >11) Delete the indefinite debarment >12) Verify the debarment message lists an expiration date dagain >13) Enable the new system preference AutoRemoveOverduesRestrictions >14) Set an overdue notice to debar after 1 day of being overdue >15) Check out an item to a patron and backdate the due date to yesterday >16) Run overdue_notices.pl >17) Verify the OVERDUES debarment was created >18) Return the item >19) Verify the OVERDUES debarment was removed >20) Disable AutoRemoveOverduesRestrictions >21) Repeat steps 15 though 18, verify the OVERDUES debarment was *not* removed >22) Add issuing rules so that an overdue item causes a temporary debarment >23) Check out an item to a patron and backdate the due date by a year >24) Return the item >25) Verify the SUSPENSION debarment was added to the patron >--- > C4/Circulation.pm | 37 ++- > C4/Members.pm | 42 +-- > C4/Overdues.pm | 37 +-- > Koha/Borrower/Debarments.pm | 334 ++++++++++++++++++++ > circ/circulation.pl | 18 +- > installer/data/mysql/sysprefs.sql | 1 + > installer/data/mysql/updatedatabase.pl | 30 ++ > .../prog/en/includes/borrower_debarments.inc | 64 ++++ > .../en/modules/admin/preferences/circulation.pref | 6 + > .../prog/en/modules/circ/circulation.tt | 14 +- > .../prog/en/modules/members/memberentrygen.tt | 76 +++-- > .../prog/en/modules/members/moremember.tt | 8 +- > .../prog/en/modules/tools/modborrowers.tt | 6 - > members/memberentry.pl | 40 ++- > members/mod_debarment.pl | 63 ++++ > members/moremember.pl | 6 +- > members/setdebar.pl | 50 --- > misc/cronjobs/overdue_notices.pl | 12 +- > opac/opac-reserve.pl | 2 +- > opac/opac-user.pl | 3 +- > t/db_dependent/Borrower_Debarments.t | 102 ++++++ > t/db_dependent/lib/KohaTest/Members/DebarMember.pm | 44 --- > t/db_dependent/lib/KohaTest/Overdues.pm | 1 - > tools/modborrowers.pl | 18 +- > 24 files changed, 755 insertions(+), 259 deletions(-) > create mode 100644 Koha/Borrower/Debarments.pm > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc > create mode 100755 members/mod_debarment.pl > delete mode 100755 members/setdebar.pl > create mode 100755 t/db_dependent/Borrower_Debarments.t > delete mode 100644 t/db_dependent/lib/KohaTest/Members/DebarMember.pm > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index 30cbe2f..17d74d9 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -47,6 +47,7 @@ use Algorithm::CheckDigits; > use Data::Dumper; > use Koha::DateUtils; > use Koha::Calendar; >+use Koha::Borrower::Debarments; > use Carp; > use Date::Calc qw( > Today >@@ -1911,6 +1912,16 @@ sub AddReturn { > logaction("CIRCULATION", "RETURN", $borrowernumber, $item->{'itemnumber'}) > if C4::Context->preference("ReturnLog"); > >+ # Remove any OVERDUES related debarment if the borrower has no overdues >+ if ( $borrowernumber >+ && $borrower->{'debarred'} >+ && C4::Context->preference('AutoRemoveOverduesRestrictions') >+ && !HasOverdues( $borrowernumber ) >+ && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) } >+ ) { >+ DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); >+ } >+ > # FIXME: make this comment intelligible. > #adding message if holdingbranch is non equal a userenv branch to return the document to homebranch > #we check, if we don't have reserv or transfert for this document, if not, return it to homebranch . >@@ -2044,19 +2055,13 @@ sub _debar_user_on_return { > > my $new_debar_dt = > $dt_today->clone()->add_duration( $deltadays * $finedays ); >- if ( $borrower->{debarred} ) { >- my $borrower_debar_dt = dt_from_string( $borrower->{debarred} ); > >- # Update patron only if new date > old >- if ( DateTime->compare( $borrower_debar_dt, $new_debar_dt ) != >- -1 ) >- { >- return; >- } >+ Koha::Borrower::Debarments::AddUniqueDebarment({ >+ borrowernumber => $borrower->{borrowernumber}, >+ expiration => $new_debar_dt->ymd(), >+ type => 'SUSPENSION', >+ }); > >- } >- C4::Members::DebarMember( $borrower->{borrowernumber}, >- $new_debar_dt->ymd() ); > return $new_debar_dt->ymd(); > } > } >@@ -2601,6 +2606,16 @@ sub AddRenewal { > } > } > >+ # Remove any OVERDUES related debarment if the borrower has no overdues >+ my $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber ); >+ if ( $borrowernumber >+ && $borrower->{'debarred'} >+ && !HasOverdues( $borrowernumber ) >+ && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) } >+ ) { >+ DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); >+ } >+ > # Log the renewal > UpdateStats( $branch, 'renew', $charge, '', $itemnumber, $item->{itype}, $borrowernumber, undef, $item->{'ccode'}); > return $datedue; >diff --git a/C4/Members.pm b/C4/Members.pm >index 3221f53..a2e84fa 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -39,6 +39,7 @@ use C4::NewsChannels; #get slip news > use DateTime; > use DateTime::Format::DateParse; > use Koha::DateUtils; >+use Koha::Borrower::Debarments qw(IsDebarred); > use Text::Unaccent qw( unac_string ); > > our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug); >@@ -103,6 +104,8 @@ BEGIN { > > &IssueSlip > GetBorrowersWithEmail >+ >+ HasOverdues > ); > > #Modify data >@@ -636,7 +639,7 @@ sub IsMemberBlocked { > my $borrowernumber = shift; > my $dbh = C4::Context->dbh; > >- my $blockeddate = CheckBorrowerDebarred($borrowernumber); >+ my $blockeddate = Koha::Borrower::Debarments::IsDebarred($borrowernumber); > > return ( 1, $blockeddate ) if $blockeddate; > >@@ -2214,32 +2217,6 @@ sub GetBorrowersNamesAndLatestIssue { > return $results; > } > >-=head2 DebarMember >- >-my $success = DebarMember( $borrowernumber, $todate ); >- >-marks a Member as debarred, and therefore unable to checkout any more >-items. >- >-return : >-true on success, false on failure >- >-=cut >- >-sub DebarMember { >- my $borrowernumber = shift; >- my $todate = shift; >- >- return unless defined $borrowernumber; >- return unless $borrowernumber =~ /^\d+$/; >- >- return ModMember( >- borrowernumber => $borrowernumber, >- debarred => $todate >- ); >- >-} >- > =head2 ModPrivacy > > =over 4 >@@ -2509,6 +2486,17 @@ sub AddMember_Opac { > return ( $borrowernumber, $password ); > } > >+sub HasOverdues { >+ my ( $borrowernumber ) = @_; >+ >+ my $sql = "SELECT COUNT(*) FROM issues WHERE date_due < NOW() AND borrowernumber = ?"; >+ my $sth = C4::Context->dbh->prepare( $sql ); >+ $sth->execute( $borrowernumber ); >+ my ( $count ) = $sth->fetchrow_array(); >+ >+ return $count; >+} >+ > END { } # module clean-up code here (global destructor) > > 1; >diff --git a/C4/Overdues.pm b/C4/Overdues.pm >index 4fd0b84..33dbd98 100644 >--- a/C4/Overdues.pm >+++ b/C4/Overdues.pm >@@ -62,10 +62,10 @@ BEGIN { > push @EXPORT, qw( > &GetIssuesIteminfo > ); >- # subs to move to Members.pm >- push @EXPORT, qw( >- &CheckBorrowerDebarred >- ); >+ >+ # &GetIssuingRules - delete. >+ # use C4::Circulation::GetIssuingRule instead. >+ > # subs to move to Biblio.pm > push @EXPORT, qw( > &GetItems >@@ -759,35 +759,6 @@ sub GetBranchcodesWithOverdueRules { > return @branches; > } > >-=head2 CheckBorrowerDebarred >- >- ($debarredstatus) = &CheckBorrowerDebarred($borrowernumber); >- >-Check if the borrowers is already debarred >- >-C<$debarredstatus> return 0 for not debarred and return 1 for debarred >- >-C<$borrowernumber> contains the borrower number >- >-=cut >- >-# FIXME: Shouldn't this be in C4::Members? >-sub CheckBorrowerDebarred { >- my ($borrowernumber) = @_; >- my $dbh = C4::Context->dbh; >- my $query = qq| >- SELECT debarred >- FROM borrowers >- WHERE borrowernumber=? >- AND debarred > NOW() >- |; >- my $sth = $dbh->prepare($query); >- $sth->execute($borrowernumber); >- my $debarredstatus = $sth->fetchrow; >- return $debarredstatus; >-} >- >- > =head2 CheckItemNotify > > Sql request to check if the document has alreday been notified >diff --git a/Koha/Borrower/Debarments.pm b/Koha/Borrower/Debarments.pm >new file mode 100644 >index 0000000..03060df >--- /dev/null >+++ b/Koha/Borrower/Debarments.pm >@@ -0,0 +1,334 @@ >+package Koha::Borrower::Debarments; >+ >+# Copyright 2013 ByWater Solutions >+# >+# 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., 59 Temple Place, >+# Suite 330, Boston, MA 02111-1307 USA >+ >+use Modern::Perl; >+ >+use C4::Context; >+ >+use parent qw( Exporter ); >+ >+our @EXPORT = qw( >+ GetDebarments >+ >+ AddDebarment >+ DelDebarment >+ ModDebarment >+ >+ AddUniqueDebarment >+ DelUniqueDebarment >+ >+ IsDebarred >+); >+ >+=head1 Koha::Borrower::Debarments >+ >+Koha::Borrower::Debarments - Module for managing borrower debarments >+ >+=cut >+ >+=head2 GetDebarments >+ >+my $arrayref = GetDebarments( $borrowernumber, { key => $value } ); >+ >+=cut >+ >+sub GetDebarments { >+ my ($params) = @_; >+ >+ return unless ( $params->{'borrowernumber'} ); >+ >+ my @keys = keys %$params; >+ my @values = values %$params; >+ >+ my $where = join( ' AND ', map { "$_ = ?" } @keys ); >+ my $sql = "SELECT * FROM borrower_debarments WHERE $where"; >+ my $sth = C4::Context->dbh->prepare($sql); >+ $sth->execute(@values); >+ >+ return $sth->fetchall_arrayref( {} ); >+} >+ >+=head2 AddDebarment >+ >+my $success = AddDebarment({ >+ borrowernumber => $borrowernumber, >+ expiration => $expiration, >+ type => $type, ## enum('FINES','OVERDUES','MANUAL') >+ comment => $comment, >+}); >+ >+Creates a new debarment. >+ >+Required keys: borrowernumber, type >+ >+=cut >+ >+sub AddDebarment { >+ my ($params) = @_; >+ >+ my $borrowernumber = $params->{'borrowernumber'}; >+ my $expiration = $params->{'expiration'} || undef; >+ my $type = $params->{'type'} || 'MANUAL'; >+ my $comment = $params->{'comment'} || undef; >+ >+ return unless ( $borrowernumber && $type ); >+ >+ my $manager_id; >+ $manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; >+ >+ my $sql = " >+ INSERT INTO borrower_debarments ( borrowernumber, expiration, type, comment, manager_id, created ) >+ VALUES ( ?, ?, ?, ?, ?, NOW() ) >+ "; >+ >+ my $r = C4::Context->dbh->do( $sql, {}, ( $borrowernumber, $expiration, $type, $comment, $manager_id ) ); >+ >+ _UpdateBorrowerDebarmentFlags($borrowernumber); >+ >+ return $r; >+} >+ >+=head2 DelDebarment >+ >+my $success = DelDebarment( $borrower_debarment_id ); >+ >+Deletes a debarment. >+ >+=cut >+ >+sub DelDebarment { >+ my ($id) = @_; >+ >+ my $borrowernumber = _GetBorrowernumberByDebarmentId($id); >+ >+ my $sql = "DELETE FROM borrower_debarments WHERE borrower_debarment_id = ?"; >+ >+ my $r = C4::Context->dbh->do( $sql, {}, ($id) ); >+ >+ _UpdateBorrowerDebarmentFlags($borrowernumber); >+ >+ return $r; >+} >+ >+=head2 ModDebarment >+ >+my $success = ModDebarment({ >+ borrower_debarment_id => $borrower_debarment_id, >+ expiration => $expiration, >+ type => $type, ## enum('FINES','OVERDUES','MANUAL') >+ comment => $comment, >+}); >+ >+Updates an existing debarment. >+ >+Required keys: borrower_debarment_id >+ >+=cut >+ >+sub ModDebarment { >+ my ($params) = @_; >+ >+ my $borrower_debarment_id = $params->{'borrower_debarment_id'}; >+ >+ return unless ($borrower_debarment_id); >+ >+ delete( $params->{'borrower_debarment_id'} ); >+ >+ delete( $params->{'created'} ); >+ delete( $params->{'updated'} ); >+ >+ $params->{'manager_id'} = C4::Context->userenv->{'number'} if C4::Context->userenv; >+ >+ my @keys = keys %$params; >+ my @values = values %$params; >+ >+ my $sql = join( ',', map { "$_ = ?" } @keys ); >+ >+ $sql = "UPDATE borrower_debarments SET $sql, updated = NOW() WHERE borrower_debarment_id = ?"; >+ >+ my $r = C4::Context->dbh->do( $sql, {}, ( @values, $borrower_debarment_id ) ); >+ >+ _UpdateBorrowerDebarmentFlags( _GetBorrowernumberByDebarmentId($borrower_debarment_id) ); >+ >+ return $r; >+} >+ >+=head2 IsDebarred >+ >+my $debarment_expiration = IsDebarred( $borrowernumber ); >+ >+Returns the date a borrowers debarment will expire, or >+undef if the borrower is not debarred >+ >+=cut >+ >+sub IsDebarred { >+ my ($borrowernumber) = @_; >+ >+ return unless ($borrowernumber); >+ >+ my $sql = "SELECT debarred FROM borrowers WHERE borrowernumber = ?"; >+ my $sth = C4::Context->dbh->prepare($sql); >+ $sth->execute($borrowernumber); >+ my ($debarred) = $sth->fetchrow_array(); >+ >+ return $debarred; >+} >+ >+=head2 AddUniqueDebarment >+ >+my $success = AddUniqueDebarment({ >+ borrowernumber => $borrowernumber, >+ type => $type, >+ expiration => $expiration, >+ comment => $comment, >+}); >+ >+Creates a new debarment of the type defined by the key type. >+If a unique debarment already exists of the given type, it is updated instead. >+The current unique debarment types are OVERDUES, and SUSPENSION >+ >+Required keys: borrowernumber, type >+ >+=cut >+ >+sub AddUniqueDebarment { >+ my ($params) = @_; >+ >+ my $borrowernumber = $params->{'borrowernumber'}; >+ my $type = $params->{'type'}; >+ >+ return unless ( $borrowernumber && $type ); >+ >+ my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0]; >+ warn Data::Dumper::Dumper( $debarment ); >+ >+ my $r; >+ if ($debarment) { >+ >+ # We don't want to shorten a unique debarment's period, so if this 'update' would do so, just keep the current expiration date instead >+ $params->{'expiration'} = $debarment->{'expiration'} >+ if ( $debarment->{'expiration'} >+ && $debarment->{'expiration'} gt $params->{'expiration'} ); >+ >+ $params->{'borrower_debarment_id'} = >+ $debarment->{'borrower_debarment_id'}; >+ $r = ModDebarment($params); >+ } else { >+ >+ $r = AddDebarment($params); >+ } >+ >+ _UpdateBorrowerDebarmentFlags($borrowernumber); >+ >+ return $r; >+} >+ >+=head2 DelUniqueDebarment >+ >+my $success = _DelUniqueDebarment({ >+ borrowernumber => $borrowernumber, >+ type => $type, >+}); >+ >+Deletes a unique debarment of the type defined by the key type. >+The current unique debarment types are OVERDUES, and SUSPENSION >+ >+Required keys: borrowernumber, type >+ >+=cut >+ >+sub DelUniqueDebarment { >+ my ($params) = @_; >+ >+ my $borrowernumber = $params->{'borrowernumber'}; >+ my $type = $params->{'type'}; >+ >+ return unless ( $borrowernumber && $type ); >+ >+ my $debarment = @{ GetDebarments( { borrowernumber => $borrowernumber, type => $type } ) }[0]; >+ >+ return unless ( $debarment ); >+ >+ return DelDebarment( $debarment->{'borrower_debarment_id'} ); >+} >+ >+=head2 _UpdateBorrowerDebarmentFlags >+ >+my $success = _UpdateBorrowerDebarmentFlags( $borrowernumber ); >+ >+So as not to create additional latency, the fields borrowers.debarred >+and borrowers.debarredcomment remain in the borrowers table. Whenever >+the a borrowers debarrments are modified, this subroutine is run to >+decide if the borrower is currently debarred and update the 'quick flags' >+in the borrowers table accordingly. >+ >+=cut >+ >+sub _UpdateBorrowerDebarmentFlags { >+ my ($borrowernumber) = @_; >+ >+ return unless ($borrowernumber); >+ >+ my $dbh = C4::Context->dbh; >+ >+ my $sql = q{ >+ SELECT COUNT(*), COUNT(*) - COUNT(expiration), MAX(expiration), GROUP_CONCAT(comment SEPARATOR '\n') FROM borrower_debarments >+ WHERE ( expiration > CURRENT_DATE() OR expiration IS NULL ) AND borrowernumber = ? >+ }; >+ my $sth = $dbh->prepare($sql); >+ $sth->execute($borrowernumber); >+ my ( $count, $indefinite_expiration, $expiration, $comment ) = $sth->fetchrow_array(); >+ >+ if ($count) { >+ $expiration = "9999-12-31" if ($indefinite_expiration); >+ } else { >+ $expiration = undef; >+ $comment = undef; >+ } >+ >+ return $dbh->do( "UPDATE borrowers SET debarred = ?, debarredcomment = ? WHERE borrowernumber = ?", {}, ( $expiration, $comment, $borrowernumber ) ); >+} >+ >+=head2 _GetBorrowernumberByDebarmentId >+ >+my $borrowernumber = _GetBorrowernumberByDebarmentId( $borrower_debarment_id ); >+ >+=cut >+ >+sub _GetBorrowernumberByDebarmentId { >+ my ($borrower_debarment_id) = @_; >+ >+ return unless ($borrower_debarment_id); >+ >+ my $sql = "SELECT borrowernumber FROM borrower_debarments WHERE borrower_debarment_id = ?"; >+ my $sth = C4::Context->dbh->prepare($sql); >+ $sth->execute($borrower_debarment_id); >+ my ($borrowernumber) = $sth->fetchrow_array(); >+ >+ return $borrowernumber; >+} >+ >+1; >+ >+=head2 AUTHOR >+ >+Kyle M Hall <kyle@bywatersoltuions.com> >+ >+=cut >diff --git a/circ/circulation.pl b/circ/circulation.pl >index 52823f4..ce30f5a 100755 >--- a/circ/circulation.pl >+++ b/circ/circulation.pl >@@ -31,13 +31,13 @@ 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; > use C4::Context; > use CGI::Session; > use C4::Members::Attributes qw(GetBorrowerAttributes); >+use Koha::Borrower::Debarments qw(GetDebarments); > use Koha::DateUtils; > > use Date::Calc qw( >@@ -263,13 +263,12 @@ if ($borrowernumber) { > 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) ); >- } >+ $template->param( >+ 'userdebarred' => $borrower->{debarred}, >+ 'debarredcomment' => $borrower->{debarredcomment}, >+ ); >+ if ( $borrower->{debarred} ne "9999-12-31" ) { >+ $template->param( 'userdebarreddate' => C4::Dates::format_date( $borrower->{debarred} ) ); > } > > } >@@ -743,10 +742,11 @@ $template->param( > debt_confirmed => $debt_confirmed, > SpecifyDueDate => $duedatespec_allow, > CircAutocompl => C4::Context->preference("CircAutocompl"), >- AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"), >+ AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"), > export_remove_fields => C4::Context->preference("ExportRemoveFields"), > export_with_csv_profile => C4::Context->preference("ExportWithCsvProfile"), > canned_bor_notes_loop => $canned_notes, >+ debarments => GetDebarments({ borrowernumber => $borrowernumber }), > ); > > output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index fbd0387..d00efd9 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -427,3 +427,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' > INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('UseCourseReserves', '0', 'Enable the course reserves feature.', NULL, 'YesNo'); > INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacHoldNotes',0,'Show hold notes on OPAC','','YesNo'); > INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo'); >+INSERT IGNORE INTO systempreferences (variable,value,explanation,type) VALUES ('AutoRemoveOverduesRestrictions','0','Defines whether an OVERDUES debarment should be lifted automatically if all overdue items are returned by the patron.','YesNo'); >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index a6b0090..b9b19a0 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -7017,6 +7017,36 @@ if ( CheckVersion($DBversion) ) { > SetVersion($DBversion); > } > >+$DBversion ="3.13.00.XXX"; >+if ( CheckVersion($DBversion) ) { >+ $dbh->do(q{ >+CREATE TABLE borrower_debarments ( >+ borrower_debarment_id int(11) NOT NULL AUTO_INCREMENT, >+ borrowernumber int(11) NOT NULL, >+ expiration date DEFAULT NULL, >+ `type` enum('SUSPENSION','OVERDUES','MANUAL') NOT NULL DEFAULT 'MANUAL', >+ `comment` text, >+ manager_id int(11) DEFAULT NULL, >+ created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, >+ updated timestamp NULL DEFAULT NULL, >+ PRIMARY KEY (borrower_debarment_id), >+ KEY borrowernumber (borrowernumber) >+) ENGINE=InnoDB DEFAULT CHARSET=utf8; >+ }); >+ >+ $dbh->do(q{ >+INSERT INTO borrower_debarments ( borrowernumber, expiration, comment ) SELECT borrowernumber, debarred, debarredcomment FROM borrowers WHERE debarred IS NOT NULL >+ }); >+ >+ $dbh->do(q{ >+INSERT IGNORE INTO systempreferences (variable,value,explanation,type) VALUES >+('AutoRemoveOverduesRestrictions','0','Defines whether an OVERDUES debarment should be lifted automatically if all overdue items are returned by the patron.','YesNo') >+ }); >+ >+ print "Upgrade to $DBversion done (Bug 2720 - Overdues which debar automatically should undebar automatically when returned)\n"; >+ SetVersion($DBversion); >+} >+ > =head1 FUNCTIONS > > =head2 TableExists($table) >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc >new file mode 100644 >index 0000000..9cef519 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc >@@ -0,0 +1,64 @@ >+<script type="text/javascript"> >+ //<![CDATA[ >+ >+ function confirm_remove_restriction() { >+ return confirm(_("Remove restriction?")); >+ } >+ >+ //]]> >+</script> >+ >+<div id="reldebarments"> >+ [% UNLESS debarments %]<p>Patron is currently unrestricted.</p>[% END %] >+ >+ <table> >+ <thead> >+ <tr> >+ <th>Type</th> >+ <th>Comment</th> >+ <th>Expiration</th> >+ [% IF ( CAN_user_borrowers ) %] >+ <th> </th> >+ [% END %] >+ </tr> >+ </thead> >+ >+ <tbody> >+ [% FOREACH d IN debarments %] >+ <tr> >+ <td>[% d.type %]</td> >+ <td>[% d.comment %]</td> >+ <td>[% IF d.expiration %] [% d.expiration | $KohaDates %] [% ELSE %] <i>Indefinite</i> [% END %]</td> >+ [% IF ( CAN_user_borrowers )%] >+ <td> >+ <a href="/cgi-bin/koha/members/mod_debarment.pl?borrowernumber=[% borrowernumber %]&borrower_debarment_id=[% d.borrower_debarment_id %]&action=del" onclick="return confirm_remove_restriction()"> >+ Remove >+ </a> >+ </td> >+ [% END %] >+ </tr> >+ [% END %] >+ </tbody> >+ >+ [% IF ( CAN_user_borrowers )%] >+ <form method="post" action="/cgi-bin/koha/members/mod_debarment.pl"> >+ <input type="hidden" name="borrowernumber" value="[% borrowernumber %]" /> >+ <input type="hidden" name="action" value="add" /> >+ >+ <tfoot> >+ <tr> >+ <td>MANUAL</td> >+ <td><input type="text" name="comment" /></td> >+ <td> >+ <input name="expiration" id="expiration" size="10" readonly="readonly" value="" class="datepicker" /> >+ <a href='#' onclick="document.getElementById('expiration').value='';">Clear Date</a> >+ </td> >+ <td> >+ <input type="submit" value="Add restriction" /> >+ </td> >+ </tr> >+ </tfoot> >+ </form> >+ [% END %] >+ </table> >+</div> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >index 64cf338..4c3534a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >@@ -126,6 +126,12 @@ Circulation: > > Checkout Policy: > - >+ - pref: AutoRemoveOverduesRestrictions >+ choices: >+ yes: "Do" >+ no: "Do not" >+ - allow OVERDUES restrictions triggered by sent notices to be cleared automatically when all overdue items are returned by a patron. >+ - > - pref: AllowNotForLoanOverride > choices: > yes: Allow >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >index 95252e7..cb236cd 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt >@@ -673,14 +673,10 @@ No patron matched <span class="ex">[% message %]</span> > > [% IF ( userdebarred ) %] > <li class="blocker"> >- <span class="circ-hlt"> Restricted:</span> Patron's account is restricted [% IF (userdebarreddate ) %] until [% userdebarreddate %] [% END %] [% IF (debarredcomment ) %] with the comment "[% 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 restriction" /> >- </form> >- </li>[% END %] >+ <span class="circ-hlt"> Restricted:</span> Patron's account is restricted [% IF (userdebarreddate ) %] until [% userdebarreddate %] [% END %] [% IF (debarredcomment ) %] with the comment "[% debarredcomment %]"[% END %] >+ <a href="#reldebarments" onclick="$('#debarments-tab-link').click()">View restrictions</a> >+ </li> >+ [% END %] > > [% IF ( odues ) %]<li>[% IF ( nonreturns ) %]<span class="circ-hlt">Overdues:</span> Patron has <span class="circ-hlt">ITEMS OVERDUE</span>. See highlighted items <a href="#checkouts">below</a>[% END %]</li> > [% END %] >@@ -780,6 +776,7 @@ No patron matched <span class="ex">[% message %]</span> > [% ELSE %] > <a href="#reserves">0 Holds</a> > [% END %]</li> >+ <li><a id="debarments-tab-link" href="#reldebarments">[% debarments.size %] Restrictions</a></li> > > </ul> > >@@ -1092,6 +1089,7 @@ No patron matched <span class="ex">[% message %]</span> > </div> > [% END %]<!-- end displayrelissues --> > >+[% INCLUDE borrower_debarments.inc %] > > <div id="reserves"> > [% IF ( reservloop ) %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >index 1bb8e3e..dd60dfc 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt >@@ -1,3 +1,4 @@ >+[% USE KohaDates %] > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Patrons › > [% IF ( opadd ) %]Add[% ELSIF ( opduplicate ) %]Duplicate[% ELSE %] Modify[% END %] [% IF ( categoryname ) %] [% categoryname %] patron[% ELSE %][% IF ( I ) %] Organization patron[% END %][% IF ( A ) %] Adult patron[% END %][% IF ( C ) %] Child patron[% END %][% IF ( P ) %] Professional patron[% END %][% IF ( S ) %] Staff patron[% END %][% END %][% UNLESS ( opadd ) %] [% surname %], [% firstname %][% END %]</title> >@@ -1275,7 +1276,6 @@ > [% FOREACH flagloo IN flagloop %] > <li><label class="radio" for="yes[% flagloo.name %]"> > [% IF ( flagloo.key == 'gonenoaddress' ) %]Gone no address:[% END %] >- [% IF ( flagloo.key == 'debarred' ) %]Restricted:[% END %] > [% IF ( flagloo.key == 'lost' ) %]Lost card:[% END %] > </label> > <label for="yes[% flagloo.name %]">Yes </label> >@@ -1293,40 +1293,54 @@ > > </li> > [% END %] >- <li> >- <label for="yesdebarred" class="radio">Restricted: </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 %] >- >- <span id="debarreduntil"><label for="datedebarred" class="inline">Until:</label> >- [% IF opduplicate %] >- <input type="text" name="datedebarred" id="datedebarred" class="debarred datepicker" value="[% datedebarred %]" onclick="this.value=''" /> >- [% ELSE %] >- <input type="text" name="datedebarred" id="datedebarred" class="debarred datepicker" value="[% datedebarred %]" /> >- [% END %] >- <span class="hint">(optional)</span> </span> >- </li> >- <li> >- <label for="debarredcomment" class="radio">Comment:</label> >- [% IF ( opduplicate ) %] >- <textarea id="debarredcomment" name="debarredcomment" cols="55" rows="3" onclick="this.value=''">[% debarredcomment %]</textarea> >- [% ELSE %] >- <textarea id="debarredcomment" name="debarredcomment" cols="55" rows="3">[% debarredcomment %]</textarea> >- [% END %] >- </li> > > </ol> > </fieldset> > >+ <fieldset class="rows"> >+ <legend>Patron restrictions</legend> >+ >+ [% UNLESS debarments %]<p>Patron is currently unrestricted.</p>[% END %] >+ >+ <table> >+ <thead> >+ <tr> >+ <th>Type</th> >+ <th>Comment</th> >+ <th>Expiration</th> >+ <th>Remove?</th> >+ </tr> >+ </thead> >+ >+ <tbody> >+ [% FOREACH d IN debarments %] >+ <tr> >+ <td>[% d.type %]</td> >+ <td>[% d.comment %]</td> >+ <td>[% IF d.expiration %] [% d.expiration | $KohaDates %] [% ELSE %] <i>Indefinite</i> [% END %]</td> >+ <td> >+ <input type="checkbox" id="debarment_[% d.borrower_debarment_id %]" name="remove_debarment" value="[% d.borrower_debarment_id %]" /> >+ </td> >+ </tr> >+ [% END %] >+ </tbody> >+ >+ <tfoot> >+ <tr> >+ <td> >+ Add new >+ <input type="checkbox" id="add_debarment" name="add_debarment" value="1" /> >+ </td> >+ <td><input type="text" id="debarred_comment" name="debarred_comment" onchange="$('#add_debarment').prop('checked', true);" /></td> >+ <td> >+ <input name="debarred_expiration" id="debarred_expiration" size="10" readonly="readonly" value="" class="datepicker" onchange="$('#add_debarment').prop('checked', true);" /> >+ <a href='javascript:void(0)' onclick="$('#debarred_expiration').val('');">Clear date</a> >+ </td> >+ <td><a class="btn" href='javascript:void(0)' onclick="$('#debarred_expiration').val(''); $('#add_debarment').prop('checked', false); $('#debarred_comment').val('');">Clear new restriction</a></td> >+ </tr> >+ </tfoot> >+ </table> >+ </fieldset> > [% END %] > > [% END %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >index 1566a32..1e8de00 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt >@@ -194,10 +194,7 @@ function validate1(date) { > <ul> > [% IF ( userdebarred ) %] > <li class="blocker">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="submit" value="Lift restriction" /> >- </form> >+ <a href="#reldebarments" onclick="$('#debarments-tab-link').click()">View restrictions</a> > </li> > [% END %] > [% IF ( gonenoaddress ) %]<li class="blocker">Patron's address is in doubt.</li>[% END %] >@@ -439,6 +436,7 @@ function validate1(date) { > <a href="#onhold">[% countreserv %] Hold(s)</a> [% ELSE %] > <a href="#onhold">0 Holds</a> > [% END %]</li> >+ <li><a id="debarments-tab-link" href="#reldebarments">[% debarments.size %] Restrictions</a></li> > </ul> > > <form action="/cgi-bin/koha/reserve/renewscript.pl" method="post" class="checkboxed"> >@@ -614,6 +612,8 @@ function validate1(date) { > [% END %] > </div> > >+[% INCLUDE borrower_debarments.inc %] >+ > <div id="onhold"> > [% IF ( reservloop ) %] > <form action="/cgi-bin/koha/reserve/modrequest.pl" method="post"> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt >index 957d559..111db0c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/modborrowers.tt >@@ -210,7 +210,6 @@ > <th>Category</th> > <th>Registration date</th> > <th>Expiry date</th> >- <th>Restricted</th> > [% FOREACH attrh IN attributes_header %] > <th>[% attrh.attribute %]</th> > [% END %] >@@ -229,7 +228,6 @@ > <td>[% borrower.categorycode %]</td> > <td>[% borrower.dateenrolled | $KohaDates %]</td> > <td>[% borrower.dateexpiry | $KohaDates %]</td> >- <td>[% borrower.debarred | $KohaDates %]</td> > [% FOREACH pa IN borrower.patron_attributes %] > [% IF ( pa.code ) %] > <td>[% pa.code %]=[% pa.value %]</td> >@@ -274,10 +272,6 @@ > Registration date: > [% CASE 'dateexpiry' %] > Expiry date: >- [% CASE 'debarred' %] >- Restricted: >- [% CASE 'debarredcomment' %] >- Restriction comment: > [% CASE 'borrowernotes' %] > Circulation note: > [% END %] >diff --git a/members/memberentry.pl b/members/memberentry.pl >index b7123f2..5137c49 100755 >--- a/members/memberentry.pl >+++ b/members/memberentry.pl >@@ -41,6 +41,8 @@ use C4::Log; > use C4::Letters; > use C4::Branch; # GetBranches > use C4::Form::MessagingPreferences; >+use Koha::Borrower::Debarments; >+use Koha::DateUtils; > > use vars qw($debug); > >@@ -62,6 +64,7 @@ my ($template, $loggedinuser, $cookie) > flagsrequired => {borrowers => 1}, > debug => ($debug) ? 1 : 0, > }); >+ > my $guarantorid = $input->param('guarantorid'); > my $borrowernumber = $input->param('borrowernumber'); > my $actionType = $input->param('actionType') || ''; >@@ -90,6 +93,29 @@ my $borrower_data; > my $NoUpdateLogin; > my $userenv = C4::Context->userenv; > >+ >+## Deal with debarments >+$template->param( >+ debarments => GetDebarments( { borrowernumber => $borrowernumber } ) ); >+my @debarments_to_remove = $input->param('remove_debarment'); >+foreach my $d ( @debarments_to_remove ) { >+ DelDebarment( $d ); >+} >+if ( $input->param('add_debarment') ) { >+ >+ my $expiration = $input->param('debarred_expiration'); >+ $expiration = $expiration ? output_pref( dt_from_string($expiration), 'iso' ) : undef; >+ >+ AddUniqueDebarment( >+ { >+ borrowernumber => $borrowernumber, >+ type => 'MANUAL', >+ comment => $input->param('debarred_comment'), >+ expiration => $expiration, >+ } >+ ); >+} >+ > $template->param("uppercasesurnames" => C4::Context->preference('uppercasesurnames')); > > my $minpw = C4::Context->preference('minPasswordLength'); >@@ -142,16 +168,6 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' ) > } > } > >- ## 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'); # >@@ -661,9 +677,7 @@ if (C4::Context->preference('uppercasesurnames')) { > $data{'contactname'} &&= uc( $data{'contactname'} ); > } > >-$data{debarred} = C4::Overdues::CheckBorrowerDebarred($borrowernumber); >-$data{datedebarred} = $data{debarred} if ( $data{debarred} && $data{debarred} ne "9999-12-31" ); >-foreach (qw(dateenrolled dateexpiry dateofbirth datedebarred)) { >+foreach (qw(dateenrolled dateexpiry dateofbirth)) { > $data{$_} = format_date($data{$_}); # back to syspref for display > $template->param( $_ => $data{$_}); > } >diff --git a/members/mod_debarment.pl b/members/mod_debarment.pl >new file mode 100755 >index 0000000..0951b0e >--- /dev/null >+++ b/members/mod_debarment.pl >@@ -0,0 +1,63 @@ >+#!/usr/bin/perl >+ >+# Copyright 2013 ByWater Solutions >+# >+# 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 CGI; >+ >+use C4::Auth; >+use Koha::DateUtils; >+use Koha::Borrower::Debarments; >+ >+my $cgi = new CGI; >+ >+my ( $loggedinuser, $cookie, $sessionID ) = checkauth( $cgi, 0, { borrowers => 1 } ); >+ >+my $borrowernumber = $cgi->param('borrowernumber'); >+my $action = $cgi->param('action'); >+ >+if ( $action eq 'del' ) { >+ DelDebarment( $cgi->param('borrower_debarment_id') ); >+} elsif ( $action eq 'add' ) { >+ my $expiration = $cgi->param('expiration'); >+ if ($expiration) { >+ $expiration = dt_from_string($expiration); >+ $expiration = $expiration->ymd(); >+ } >+ >+ AddDebarment( >+ { borrowernumber => $borrowernumber, >+ type => 'MANUAL', >+ comment => $cgi->param('comment'), >+ expiration => $expiration, >+ } >+ ); >+} >+ >+if ( $ENV{HTTP_REFERER} =~ /moremember/ ) { >+ print $cgi->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber"); >+} else { >+ print $cgi->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber"); >+} >+ >+=head1 author >+ >+Kyle M Hall <kyle@bywatersolutions.com> >+ >+=cut >diff --git a/members/moremember.pl b/members/moremember.pl >index 598b07d..047e112 100755 >--- a/members/moremember.pl >+++ b/members/moremember.pl >@@ -48,11 +48,10 @@ use C4::Koha; > use C4::Letters; > use C4::Biblio; > use C4::Branch; # GetBranchName >-use C4::Overdues qw/CheckBorrowerDebarred/; > use C4::Form::MessagingPreferences; > use List::MoreUtils qw/uniq/; > use C4::Members::Attributes qw(GetBorrowerAttributes); >- >+use Koha::Borrower::Debarments qw(GetDebarments); > #use Smart::Comments; > #use Data::Dumper; > use DateTime; >@@ -147,7 +146,7 @@ for (qw(gonenoaddress lost borrowernotes)) { > $data->{$_} and $template->param(flagged => 1) and last; > } > >-my $debar = CheckBorrowerDebarred($borrowernumber); >+my $debar = $data->{'debarred'}; > if ($debar) { > $template->param( 'userdebarred' => 1, 'flagged' => 1 ); > if ( $debar ne "9999-12-31" ) { >@@ -426,6 +425,7 @@ $template->param( > AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'), > SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'), > RoutingSerials => C4::Context->preference('RoutingSerials'), >+ debarments => GetDebarments({ borrowernumber => $borrowernumber }), > ); > $template->param( $error => 1 ) if $error; > >diff --git a/members/setdebar.pl b/members/setdebar.pl >deleted file mode 100755 >index 280ffaa..0000000 >--- a/members/setdebar.pl >+++ /dev/null >@@ -1,50 +0,0 @@ >-#!/usr/bin/perl >- >-# Copyright 2000-2002 Katipo Communications >-# Parts copyright 2011 BibLibre >-# >-# 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. >- >- >-=head1 setdebar.pl >- >-script to set or lift debarred status >-written 2/8/04 >-by oleonard@athenscounty.lib.oh.us >- >-=cut >- >-use strict; >-use warnings; >- >-use CGI; >-use C4::Context; >-use C4::Auth; >- >-my $input = new CGI; >- >-checkauth( $input, 0, { borrowers => 1 }, 'intranet' ); >- >-my $borrowernumber = $input->param('borrowernumber'); >- >-my $dbh = C4::Context->dbh; >-my $sth = >- $dbh->prepare("Update borrowers set debarred = NULL where borrowernumber = ?"); >-$sth->execute( $borrowernumber ); >-$sth->finish; >- >-print $input->redirect( >- "/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber"); >diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl >index 5f285c0..9f63044 100755 >--- a/misc/cronjobs/overdue_notices.pl >+++ b/misc/cronjobs/overdue_notices.pl >@@ -42,6 +42,9 @@ use C4::Letters; > use C4::Overdues qw(GetFine); > use C4::Budgets qw(GetCurrency); > >+use Koha::Borrower::Debarments qw(AddUniqueDebarment); >+use Koha::DateUtils; >+ > =head1 NAME > > overdue_notices.pl - prepare messages to be sent to patrons for overdue items >@@ -515,7 +518,14 @@ END_SQL > if ( $overdue_rules->{"debarred$i"} ) { > > #action taken is debarring >- C4::Members::DebarMember($borrowernumber, '9999-12-31'); >+ AddUniqueDebarment( >+ { >+ borrowernumber => $borrowernumber, >+ type => 'OVERDUES', >+ comment => "Restriction added by overdues process " >+ . output_pref( dt_from_string() ), >+ } >+ ); > $verbose and warn "debarring $borr\n"; > } > my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays )); >diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl >index be72e84..c15b2bd 100755 >--- a/opac/opac-reserve.pl >+++ b/opac/opac-reserve.pl >@@ -307,7 +307,7 @@ if ( $borr->{lost} && ($borr->{lost} == 1) ) { > lost => 1 > ); > } >-if ( CheckBorrowerDebarred($borrowernumber) ) { >+if ( $borr->{'debarred'} ) { > $noreserves = 1; > $template->param( > message => 1, >diff --git a/opac/opac-user.pl b/opac/opac-user.pl >index 5c01ae2..16fa4fa 100755 >--- a/opac/opac-user.pl >+++ b/opac/opac-user.pl >@@ -30,7 +30,6 @@ use C4::Members; > use C4::Members::AttributeTypes; > use C4::Members::Attributes qw/GetBorrowerAttributeValue/; > use C4::Output; >-use C4::Overdues qw/CheckBorrowerDebarred/; > use C4::Biblio; > use C4::Items; > use C4::Letters; >@@ -80,7 +79,7 @@ my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpir > > $borr->{'ethnicity'} = fixEthnicity( $borr->{'ethnicity'} ); > >-my $debar = CheckBorrowerDebarred($borrowernumber); >+my $debar = $borr->{'debarred'}; > my $userdebarred; > > if ($debar) { >diff --git a/t/db_dependent/Borrower_Debarments.t b/t/db_dependent/Borrower_Debarments.t >new file mode 100755 >index 0000000..1ee1ebe >--- /dev/null >+++ b/t/db_dependent/Borrower_Debarments.t >@@ -0,0 +1,102 @@ >+#!/usr/bin/perl >+ >+use strict; >+use warnings; >+ >+use C4::Context; >+use C4::Members; >+ >+use Test::More tests => 18; >+ >+BEGIN { >+ use FindBin; >+ use lib $FindBin::Bin; >+ use_ok('Koha::Borrower::Debarments'); >+} >+ >+# Get a borrower with no current debarments >+my $dbh = C4::Context->dbh; >+my $query = " >+ SELECT b.borrowernumber FROM borrowers b >+ LEFT JOIN borrower_debarments bd ON ( b.borrowernumber = bd.borrowernumber ) >+ WHERE b.debarred IS NULL AND b.debarredcomment IS NULL AND bd.borrowernumber IS NULL >+ LIMIT 1 >+"; >+my $sth = $dbh->prepare($query); >+$sth->execute; >+my ($borrowernumber) = $sth->fetchrow_array(); >+diag("Using borrowernumber: $borrowernumber"); >+ >+ >+my $success = AddDebarment({ >+ borrowernumber => $borrowernumber, >+ expiration => '9999-06-10', >+ type => 'MANUAL', >+ comment => 'Test 1', >+}); >+ok( $success, "AddDebarment returned true" ); >+ >+ >+my $debarments = GetDebarments({ borrowernumber => $borrowernumber }); >+ok( @$debarments == 1, "GetDebarments returns 1 debarment" ); >+ok( $debarments->[0]->{'type'} eq 'MANUAL', "Correctly stored 'type'" ); >+ok( $debarments->[0]->{'expiration'} eq '9999-06-10', "Correctly stored 'expiration'" ); >+ok( $debarments->[0]->{'comment'} eq 'Test 1', "Correctly stored 'comment'" ); >+ >+ >+$success = AddDebarment({ >+ borrowernumber => $borrowernumber, >+ comment => 'Test 2', >+}); >+ >+$debarments = GetDebarments({ borrowernumber => $borrowernumber }); >+ok( @$debarments == 2, "GetDebarments returns 2 debarments" ); >+ok( $debarments->[1]->{'type'} eq 'MANUAL', "Correctly stored 'type'" ); >+ok( !$debarments->[1]->{'expiration'}, "Correctly stored debarrment with no expiration" ); >+ok( $debarments->[1]->{'comment'} eq 'Test 2', "Correctly stored 'comment'" ); >+ >+ >+ModDebarment({ >+ borrower_debarment_id => $debarments->[1]->{'borrower_debarment_id'}, >+ comment => 'Test 3', >+ expiration => '9998-06-10', >+}); >+$debarments = GetDebarments({ borrowernumber => $borrowernumber }); >+ok( $debarments->[1]->{'comment'} eq 'Test 3', "ModDebarment functions correctly" ); >+ >+ >+my $borrower = GetMember( borrowernumber => $borrowernumber ); >+ok( $borrower->{'debarred'} eq '9999-06-10', "Field borrowers.debarred set correctly" ); >+ok( $borrower->{'debarredcomment'} eq "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" ); >+ >+ >+AddUniqueDebarment({ >+ borrowernumber => $borrowernumber, >+ type => 'OVERDUES' >+}); >+$debarments = GetDebarments({ >+ borrowernumber => $borrowernumber, >+ type => 'OVERDUES', >+}); >+ok( @$debarments == 1, "GetDebarments returns 1 OVERDUES debarment" ); >+ok( $debarments->[0]->{'type'} eq 'OVERDUES', "AddOverduesDebarment created new debarment correctly" ); >+ >+AddUniqueDebarment({ >+ borrowernumber => $borrowernumber, >+ expiration => '9999-11-09', >+ type => 'OVERDUES' >+}); >+$debarments = GetDebarments({ >+ borrowernumber => $borrowernumber, >+ type => 'OVERDUES', >+}); >+ok( @$debarments == 1, "GetDebarments returns 1 OVERDUES debarment after running AddOverduesDebarment twice" ); >+ok( $debarments->[0]->{'expiration'} eq '9999-11-09', "AddOverduesDebarment updated OVERDUES debarment correctly" ); >+ >+ >+$debarments = GetDebarments({ borrowernumber => $borrowernumber }); >+foreach my $d ( @$debarments ) { >+ DelDebarment( $d->{'borrower_debarment_id'} ); >+} >+$debarments = GetDebarments({ borrowernumber => $borrowernumber }); >+ok( @$debarments == 0, "DelDebarment functions correctly" ) >\ No newline at end of file >diff --git a/t/db_dependent/lib/KohaTest/Members/DebarMember.pm b/t/db_dependent/lib/KohaTest/Members/DebarMember.pm >deleted file mode 100644 >index bf61b8a..0000000 >--- a/t/db_dependent/lib/KohaTest/Members/DebarMember.pm >+++ /dev/null >@@ -1,44 +0,0 @@ >-package KohaTest::Members::DebarMember; >-use base qw( KohaTest::Members ); >- >-use strict; >-use warnings; >- >-use Test::More; >- >-use C4::Members; >-sub testing_class { 'C4::Members' }; >- >- >-sub simple_usage : Test( 6 ) { >- my $self = shift; >- >- ok( $self->{'memberid'}, 'we have a valid memberid to test with' ); >- >- my $details = C4::Members::GetMemberDetails( $self->{'memberid'} ); >- ok( exists $details->{'flags'}, 'member details has a "flags" attribute'); >- isa_ok( $details->{'flags'}, 'HASH', 'the "flags" attribute is a hashref'); >- ok( ! $details->{'flags'}->{'DBARRED'}, 'this member is NOT debarred' ); >- >- # Now, let's debar this member and see what happens >- my $success = C4::Members::DebarMember( $self->{'memberid'}, '2099-12-31' ); >- >- ok( $success, 'we were able to debar the member' ); >- >- $details = C4::Members::GetMemberDetails( $self->{'memberid'} ); >- ok( $details->{'flags'}->{'DBARRED'}, 'this member is debarred now' ) >- or diag( Data::Dumper->Dump( [ $details->{'flags'} ], [ 'flags' ] ) ); >-} >- >-sub incorrect_usage : Test( 2 ) { >- my $self = shift; >- >- my $result = C4::Members::DebarMember(); >- ok( ! defined $result, 'DebarMember returns undef when passed no parameters' ); >- >- $result = C4::Members::DebarMember( 'this is not a borrowernumber' ); >- ok( ! defined $result, 'DebarMember returns undef when not passed a numeric argument' ); >- >-} >- >-1; >diff --git a/t/db_dependent/lib/KohaTest/Overdues.pm b/t/db_dependent/lib/KohaTest/Overdues.pm >index 5890d2b..f3d0053 100644 >--- a/t/db_dependent/lib/KohaTest/Overdues.pm >+++ b/t/db_dependent/lib/KohaTest/Overdues.pm >@@ -25,7 +25,6 @@ sub methods : Test( 1 ) { > NumberNotifyId > AmountNotify > GetItems >- CheckBorrowerDebarred > CheckItemNotify > GetOverduesForBranch > AddNotifyLine >diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl >index 1bba4a0..6a2f5c8 100755 >--- a/tools/modborrowers.pl >+++ b/tools/modborrowers.pl >@@ -21,7 +21,7 @@ > # > # Batch Edit Patrons > # Modification for patron's fields: >-# surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry debarred debarredcomment borrowernotes >+# surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry borrowernotes > # And for patron attributes. > > use Modern::Perl; >@@ -206,18 +206,6 @@ if ( $op eq 'show' ) { > } > , > { >- name => "debarred", >- type => "date", >- mandatory => ( grep /debarred/, @mandatoryFields ) ? 1 : 0, >- } >- , >- { >- name => "debarredcomment", >- type => "text", >- mandatory => ( grep /debarredcomment/, @mandatoryFields ) ? 1 : 0, >- } >- , >- { > name => "borrowernotes", > type => "text", > mandatory => ( grep /borrowernotes/, @mandatoryFields ) ? 1 : 0, >@@ -235,7 +223,7 @@ if ( $op eq 'do' ) { > > my @disabled = $input->param('disable_input'); > my $infos; >- for my $field ( qw/surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry debarred debarredcomment borrowernotes/ ) { >+ for my $field ( qw/surname firstname branchcode categorycode sort1 sort2 dateenrolled dateexpiry borrowernotes/ ) { > my $value = $input->param($field); > $infos->{$field} = $value if $value; > $infos->{$field} = "" if grep { /^$field$/ } @disabled; >@@ -327,7 +315,7 @@ sub GetBorrowerInfos { > my $borrower = GetMember( %info ); > if ( $borrower ) { > $borrower->{branchname} = GetBranchName( $borrower->{branchcode} ); >- for ( qw(dateenrolled dateexpiry debarred) ) { >+ for ( qw(dateenrolled dateexpiry) ) { > my $userdate = $borrower->{$_}; > unless ($userdate && $userdate ne "0000-00-00" and $userdate ne "9999-12-31") { > $borrower->{$_} = ''; >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 2720
:
15045
|
15050
|
15051
|
15052
|
16669
|
18213
|
19401
|
19414
|
19418
|
19419
|
19420
|
19421
|
19755
|
20655
|
20656
|
20657
|
20658
|
21366
|
21367
|
21368
|
21369
|
21405
|
21406
|
21407
|
21408
|
21409
|
21410
|
25575
|
25578