From 8b14c15f47850055d50d0f67ba3aea154bf82912 Mon Sep 17 00:00:00 2001 From: Lyon3 Team Date: Mon, 19 Nov 2012 12:09:02 +0100 Subject: [PATCH] Bug 8236 Block renewing for overdue items If any of patron's document is late, renewal can be allowed, blocked on every checked out items or only on overdue ones. The renewal remains nevertheless possible for the librarian checking the Override renewal limit Signed-off-by: Kyle M Hall --- C4/Circulation.pm | 5 +++-- C4/ILSDI/Services.pm | 14 +++++++++++--- circ/circulation.pl | 12 +++++++++--- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++++++ .../en/modules/admin/preferences/circulation.pref | 8 ++++++++ .../prog/en/modules/circ/circulation.tt | 12 ++++++++++-- .../prog/en/modules/members/moremember.tt | 7 ++++++- koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt | 6 +++++- members/moremember.pl | 11 ++++++++--- opac/opac-user.pl | 10 +++++++++- 11 files changed, 77 insertions(+), 16 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 71fe20f..626cca5 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2424,7 +2424,7 @@ already renewed the loan. $error will contain the reason the renewal can not pro sub CanBookBeRenewed { # check renewal status - my ( $borrowernumber, $itemnumber, $override_limit ) = @_; + my ( $borrowernumber, $itemnumber, $override_limit, $overdue, $overduesblockrenew ) = @_; my $dbh = C4::Context->dbh; my $renews = 1; my $renewokay = 0; @@ -2473,7 +2473,8 @@ sub CanBookBeRenewed { if ( my $data1 = $sthcount->fetchrow_hashref ) { if ( ( $data1->{renewalsallowed} && $data1->{renewalsallowed} > $data1->{renewals} ) || $override_limit ) { - $renewokay = 1; + $renewokay = ($overduesblockrenew eq 'blockitem' and $overdue and !$override_limit)? 0 : 1; + $error = 'overdue' unless $renewokay; } else { $error="too_many"; diff --git a/C4/ILSDI/Services.pm b/C4/ILSDI/Services.pm index 68cbdb3..678b727 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -561,10 +561,18 @@ sub RenewLoan { return { code => 'RecordNotFound' } unless $$item{itemnumber}; # Add renewal if possible - my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber ); - if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); } - my $issue = GetItemIssue($itemnumber); + # Check for overdue on this document + my $dt_due = $issue->{'date_due'}->truncate( to => 'day' ); + my $dt_today = DateTime->now( time_zone => C4::Context->tz() ); + my $overdue = 1 if DateTime->compare( $dt_today,$dt_due ) == 1; + # Check if any of patron's documents is late + my ($memberblocked) = C4::Members::IsMemberBlocked($borrowernumber); + # Is renewal allowed on overdue documents ? + my $overduesblockrenew = C4::Context->preference('OverduesBlockRenew'); + my $norenewal = 1 if ( $overduesblockrenew eq 'blockall' and $memberblocked == -1 ) or ( $overduesblockrenew eq 'blockitem' and $overdue ) or $memberblocked == 1;# last to check if patron is restricted + my @renewal = $norenewal ? (0,'overdue') : CanBookBeRenewed( $borrowernumber, $itemnumber ); + if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); } # Hashref building my $out; diff --git a/circ/circulation.pl b/circ/circulation.pl index 91fd1a2..4361c4b 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -429,6 +429,13 @@ my $displayrelissues; our $totalprice = 0; +# Check if any of patron's documents is late +my ($memberblocked) = C4::Members::IsMemberBlocked($borrowernumber); +# and if renewal is allowed in that case +my $overduesblockrenew = C4::Context->preference('OverduesBlockRenew'); +my $norenewal = 1 if $overduesblockrenew eq 'blockall' and $memberblocked == -1; +$template->param( norenewal => 1 ) if $overduesblockrenew ne 'allow'; + sub build_issue_data { my $issueslist = shift; my $relatives = shift; @@ -444,9 +451,8 @@ sub build_issue_data { $it->{'itemnumber'}, $it->{'borrowernumber'} ); $it->{'charge'} = sprintf("%.2f", $it->{'charge'}); - my ($can_renew, $can_renew_error) = CanBookBeRenewed( - $it->{'borrowernumber'},$it->{'itemnumber'} - ); + my ($can_renew, $can_renew_error) = $norenewal ? (0, 'overdue') : CanBookBeRenewed( + $it->{'borrowernumber'},$it->{'itemnumber'}, undef, $it->{'overdue'}, $overduesblockrenew); $it->{"renew_error_${can_renew_error}"} = 1 if defined $can_renew_error; my ( $restype, $reserves, undef ) = CheckReserves( $it->{'itemnumber'} ); $it->{'can_renew'} = $can_renew; diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index d5d15d7..6633987 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -406,3 +406,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('NotesBlacklist','','List of notes fields that should not appear in the title notes/description separator of details',NULL,'free'); INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SCOUserCSS', '', NULL, 'Add CSS to be included in the SCO module in an embedded