From e8ef898427a6b95c4b5520bda43d344db00debf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Mei=C3=9Fner?= Date: Fri, 24 Jan 2014 10:21:09 +0100 Subject: [PATCH] Bug 7413: Add new error "too_soon" in CanBookBeRenewed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch modifies CanBookBeRenewed in Ciculation.pm, so that based on issuingrules.norenewalbefore a new error "too_soon" can be returned. For this error intranet HTML templates will display "Not renewable yet" instead of "Not renewable". To test: 1) Create an issuing rule with "No renewal before" set to value X and "Unit" set to days. 2) Confirm that items can't be renewed if current date is more than X days before due date. 3) Confirm that items can be renewed if "No renewal before" is undefined or current date is X or less days before due date. 4) Confirm that "Renewals allowed (count)" has priority, i.e. if the number of allowed renewals is exceeded "Not renewable" is displayed, no matter what "No renewal before" is set to. 5) Test the same things with "Unit" set to hours. 6) Test for both circulation.tt and moremember.tt. Sponsored-by: Hochschule für Gesundheit (hsg), Germany --- C4/Circulation.pm | 26 +++++++++++++++++--- .../prog/en/modules/circ/circulation.tt | 11 ++++++--- .../prog/en/modules/members/moremember.tt | 7 +++++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index f8b204a..e17193f 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2472,7 +2472,7 @@ sub CanBookBeRenewed { my $dbh = C4::Context->dbh; my $renews = 1; - my $renewokay = 0; + my $renewokay = 1; my $error; my $item = GetItem($itemnumber) or return ( 0, 'no_item' ); @@ -2486,12 +2486,30 @@ sub CanBookBeRenewed { my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); - if ( ( $issuingrule->{renewalsallowed} > $itemissue->{renewals} ) || $override_limit ) { - $renewokay = 1; - } else { + if ( $issuingrule->{norenewalbefore} ) { + + # Get current time and add norenewalbefore. If this is smaller than date_due, it's too soon for renewal. + if ( + DateTime->now( time_zone => C4::Context->tz() )->add( + $issuingrule->{lengthunit} => $issuingrule->{norenewalbefore} + ) < $itemissue->{date_due} + ) + { + $renewokay = 0; + $error = "too_soon"; + } + } + + if ( $issuingrule->{renewalsallowed} <= $itemissue->{renewals} ) { + $renewokay = 0; $error = "too_many"; } + if ( $override_limit ) { + $renewokay = 1; + $error = undef; + } + my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves( $itemnumber ); if ( $resfound ) { # '' when no hold was found 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 5a6a82d..27a007c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -785,10 +785,15 @@ No patron matched [% message %] [% END %] [% IF ( todayissue.renew_error_on_reserve ) %] On hold - [% END %] - [% IF ( todayissue.renew_error_too_many ) %] - Not renewable + [% ELSE %] + [% IF ( todayissue.renew_error_too_many ) %] + Not renewable + [% ELSE %] + [% IF ( todayissue.renew_error_too_soon ) %] + Not renewable yet [% END %] + [% END %] + [% END %] [% IF ( todayissue.can_confirm ) %] [% 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 79d319e..b392494 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt @@ -507,10 +507,15 @@ function validate1(date) { [% END %] [% IF ( issueloo.norenew_reason_on_reserve ) %] On Hold - [% END %] + [% ELSE %] [% IF ( issueloo.norenew_reason_too_many ) %] Not renewable + [% ELSE %] + [% IF ( issueloo.norenew_reason_too_soon ) %] + Not renewable yet + [% END %] [% END %] + [% END %] [% IF ( issueloo.can_confirm ) %] [% END %] -- 1.7.10.4