From 5181eddda0b020d3877dc93f6bd09c86326b6f44 Mon Sep 17 00:00:00 2001 From: Lyon3 Team Date: Mon, 8 Oct 2012 09:44:26 +0200 Subject: [PATCH] Block renewal for overdue documents Content-Type: text/plain; charset="utf-8" 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 http://bugs.koha-community.org/show_bug.cgi?id=8236 --- C4/Circulation.pm | 5 +++-- C4/ILSDI/Services.pm | 12 +++++++++++- 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 | 10 ++++++++-- opac/opac-user.pl | 11 +++++++++-- 11 files changed, 77 insertions(+), 14 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 7485de5..bbf62c0 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2417,7 +2417,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; @@ -2466,7 +2466,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 5a62954..7300041 100644 --- a/C4/ILSDI/Services.pm +++ b/C4/ILSDI/Services.pm @@ -555,7 +555,17 @@ sub RenewLoan { return { code => 'RecordNotFound' } unless $$item{itemnumber}; # Add renewal if possible - my @renewal = CanBookBeRenewed( $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 ); } my $issue = GetItemIssue($itemnumber); diff --git a/circ/circulation.pl b/circ/circulation.pl index b051281..6773686 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 a4fceea..3f9624d 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -386,3 +386,4 @@ INSERT INTO systempreferences (variable,value,explanation,type) VALUES('OPACdidy INSERT INTO systempreferences (variable,value,explanation,type) VALUES('INTRAdidyoumean',NULL,'Did you mean? configuration for the Intranet. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free'); INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('BlockReturnOfWithdrawnItems', '1', '0', 'If enabled, items that are marked as withdrawn cannot be returned.', 'YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('HoldsToPullStartDate','2','Set the default start date for the Holds to pull list to this many days ago',NULL,'Integer'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OverduesBlockRenew','allow','If any of patron\'s checked out documents is late, should renewal be allowed, blocked only on overdue items or blocked on whatever checked out document','allow|blockitem|blockall','Choice'); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e67bf3e..86df9a1 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -6011,6 +6011,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.09.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OverduesBlockRenew','allow','If any of a patrons checked out documents is late, should renewal be allowed, blocked only on overdue items or blocked on whatever checked out document','allow|blockitem|blockall','Choice')"); + print "Upgrade to $DBversion done (Add system preference BlockRenewal ))\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) 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 62938b4..602b8b8 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 @@ -277,6 +277,14 @@ Circulation: confirmation: Ask for confirmation - when checking out to a borrower that has overdues outstanding - + - If any of a patron's checked out documents is late, the renewal is + - pref: OverduesBlockRenew + type: choice + choices: + allow: allowed + blockall: blocked on whatever of his checked out documents + blockitem: blocked only on the overdue items + - - On checkin route the returned item to - pref: HomeOrHoldingBranchReturn type: choice 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 652cbf8..0fc0ac8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -805,7 +805,7 @@ No patron matched [% message %] [% IF ( todayissue.renewals ) %][% todayissue.renewals %][% ELSE %]0[% END %] [% IF ( todayissue.can_renew ) %] - [% IF ( todayissue.od ) %] + [% IF ( todayissue.od and !previssue.renew_error_overdue ) %] [% ELSE %] @@ -827,6 +827,9 @@ No patron matched [% message %] [% IF ( todayissue.renew_error_too_many ) %] Not renewable [% END %] + [% IF ( todayissue.renew_error_overdue ) %] + Renewal not allowed (overdue) + [% END %] [% IF ( todayissue.can_confirm ) %] [% END %] @@ -886,7 +889,7 @@ No patron matched [% message %] [% IF ( previssue.renewals ) %][% previssue.renewals %][% ELSE %]0[% END %] [% IF ( previssue.can_renew ) %] - [% IF ( previssue.od ) %] + [% IF ( previssue.od and !previssue.renew_error_overdue ) %] [% ELSE %] @@ -908,6 +911,9 @@ No patron matched [% message %] [% IF ( previssue.renew_error_too_many ) %] Not renewable [% END %] + [% IF ( previssue.renew_error_overdue ) %] + Renewal not allowed (overdue) + [% END %] [% IF ( previssue.can_confirm ) %] [% END %] @@ -947,7 +953,9 @@ No patron matched [% message %] [% END %] [% END %] + [% UNLESS ( norenewal ) %] + [% END %] [% IF export_remove_fields OR export_with_csv_profile %]

Don't export fields : 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 abbf26f..6aea391 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -470,7 +470,7 @@ function validate1(date) { [% IF ( issueloo.norenew ) %] [% IF ( issueloo.can_confirm ) %] [% END %] + [% IF ( issueloo.norenew_reason_overdue ) %] + Renewal not allowed (overdue) + [% END %] [% IF ( issueloo.norenew_reason_on_reserve ) %] On Hold [% END %] @@ -520,7 +523,9 @@ function validate1(date) { [% END %] [% END %] + [% UNLESS ( norenewal ) %] + [% END %] [% ELSE %]

Patron has nothing checked out.

[% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt index 43b8329..b10651a 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-user.tt @@ -185,8 +185,11 @@ $.tablesorter.addParser({ [% IF ( OpacRenewalAllowed ) %] [% IF ( ISSUE.status ) %][% IF ( canrenew ) %] Renew[% END %] ([% ISSUE.renewsleft %] of [% ISSUE.renewsallowed %] renewals remaining) [% ELSE %] + [% IF ( ISSUE.norenew_overdue ) %] + Renewal not allowed (overdue on a document) + [% ELSE %] Not renewable[% IF ( ISSUE.too_many ) %] ([% ISSUE.renewsleft %] of [% ISSUE.renewsallowed %] renewals remaining)[% ELSE %][% IF ( ISSUE.on_reserve ) %] (On hold)[% END %][% END %] - [% END %] + [% END %][% END %] [% END %] [% IF ( OPACFinesTab ) %] [% IF ( ISSUE.charges ) %]Yes[% ELSE %]No[% END %] @@ -329,6 +332,7 @@ $.tablesorter.addParser({ [% ELSIF ( OVERDUE.status ) %] [% IF ( canrenew ) %]Renew[% END %] ([% OVERDUE.renewsleft %] of [% OVERDUE.renewsallowed %] renewals remaining) [% ELSIF ( OVERDUE.onreserve ) %]On hold +[% ELSIF ( OVERDUE.norenew_overdue ) %]Renewal not allowed(overdue on a document) [% ELSE %]No renewals left [% END %] [% END %] diff --git a/members/moremember.pl b/members/moremember.pl index 0524ecb..b7d6b39 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -256,6 +256,13 @@ my @borrowers_with_issues; my $overdues_exist = 0; my $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'; + my @issuedata = build_issue_data($issue); my @relissuedata = build_issue_data($relissue); @@ -512,8 +519,7 @@ sub build_issue_data { $row{'charge'} = sprintf( "%.2f", $charge ); my ( $renewokay, $renewerror ) = - CanBookBeRenewed( $borrowernumber, $issue->{itemnumber}, - $override_limit ); + my ( $renewokay, $renewerror ) = $norenewal ? (0, 'overdue') : CanBookBeRenewed( $borrowernumber, $issue->{itemnumber}, $override_limit, $issue->{overdue}, $overduesblockrenew ); $row{'norenew'} = !$renewokay; $row{'can_confirm'} = ( !$renewokay && $renewerror ne 'on_reserve' ); $row{"norenew_reason_$renewerror"} = 1 if $renewerror; diff --git a/opac/opac-user.pl b/opac/opac-user.pl index eee3d38..15d364b 100755 --- a/opac/opac-user.pl +++ b/opac/opac-user.pl @@ -153,6 +153,13 @@ my @overdues; my @issuedat; my $itemtypes = GetItemTypes(); my $issues = GetPendingIssues($borrowernumber); + +# 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; + if ($issues){ foreach my $issue ( sort { $b->{date_due}->datetime() cmp $a->{date_due}->datetime() } @{$issues} ) { # check for reserves @@ -179,14 +186,14 @@ if ($issues){ $issue->{$publictype} = 1; # check if item is renewable - my ($status,$renewerror) = CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'} ); + my ($status,$renewerror) = $norenewal ? (0, 'overdue') : CanBookBeRenewed( $borrowernumber, $issue->{'itemnumber'}, undef, $issue->{'overdue'}, $overduesblockrenew); ($issue->{'renewcount'},$issue->{'renewsallowed'},$issue->{'renewsleft'}) = GetRenewCount($borrowernumber, $issue->{'itemnumber'}); if($status && C4::Context->preference("OpacRenewalAllowed")){ $issue->{'status'} = $status; } $issue->{'too_many'} = 1 if $renewerror and $renewerror eq 'too_many'; $issue->{'on_reserve'} = 1 if $renewerror and $renewerror eq 'on_reserve'; - + $issue->{'norenew_overdue'} = 1 if $renewerror and $renewerror eq 'overdue'; if ( $issue->{'overdue'} ) { push @overdues, $issue; $overdues_count++; -- 1.7.2.5