@@ -, +, @@ given a delay UPDATE issues SET issuedate = "yyyy-mm-dd hh:mm:ss" WHERE itemnumber = YOUR_ITEMNUMBER; --- C4/Circulation.pm | 18 ++++++++- admin/smart-rules.pl | 3 ++ installer/data/mysql/atomicupdate/bug_15581.sql | 1 + installer/data/mysql/kohastructure.sql | 1 + .../prog/en/modules/admin/smart-rules.tt | 4 ++ .../intranet-tmpl/prog/en/modules/circ/renew.tt | 12 ++++++ t/db_dependent/Circulation.t | 41 ++++++++++++++++++++ 7 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 installer/data/mysql/atomicupdate/bug_15581.sql --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2888,6 +2888,22 @@ sub CanBookBeRenewed { return ( 0, 'overdue'); } + if ( $itemissue->{auto_renew} + and defined $issuingrule->{no_auto_renewal_after} + and $issuingrule->{no_auto_renewal_after} ne "" ) { + + # Get issue_date and add no_auto_renewal_after + # If this is greater than today, it's too late for renewal. + my $maximum_renewal_date = dt_from_string($itemissue->{issuedate}); + $maximum_renewal_date->add( + $issuingrule->{lengthunit} => $issuingrule->{no_auto_renewal_after} + ); + my $now = dt_from_string; + if ( $now >= $maximum_renewal_date ) { + return ( 0, "auto_too_late" ); + } + } + if ( defined $issuingrule->{norenewalbefore} and $issuingrule->{norenewalbefore} ne "" ) { @@ -2917,7 +2933,7 @@ sub CanBookBeRenewed { # Fallback for automatic renewals: # If norenewalbefore is undef, don't renew before due date. - elsif ( $itemissue->{auto_renew} ) { + if ( $itemissue->{auto_renew} ) { my $now = dt_from_string; return ( 0, "auto_renew" ) if $now >= $itemissue->{date_due}; --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -133,6 +133,8 @@ elsif ($op eq 'add') { my $norenewalbefore = $input->param('norenewalbefore'); $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/; my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0; + my $no_auto_renewal_after = $input->param('no_auto_renewal_after'); + $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/; my $reservesallowed = $input->param('reservesallowed'); my $onshelfholds = $input->param('onshelfholds') || 0; $maxissueqty =~ s/\s//g; @@ -168,6 +170,7 @@ elsif ($op eq 'add') { renewalperiod => $renewalperiod, norenewalbefore => $norenewalbefore, auto_renew => $auto_renew, + no_auto_renewal_after => $no_auto_renewal_after, reservesallowed => $reservesallowed, issuelength => $issuelength, lengthunit => $lengthunit, --- a/installer/data/mysql/atomicupdate/bug_15581.sql +++ a/installer/data/mysql/atomicupdate/bug_15581.sql @@ -0,0 +1, @@ +ALTER TABLE issuingrules ADD COLUMN no_auto_renewal_after INT(4) DEFAULT NULL AFTER auto_renew; --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1206,6 +1206,7 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules `renewalperiod` int(4) default NULL, -- renewal period in the unit set in issuingrules.lengthunit `norenewalbefore` int(4) default NULL, -- no renewal allowed until X days or hours before due date. `auto_renew` BOOLEAN default FALSE, -- automatic renewal + `no_auto_renewal_after` int(4) default NULL, -- no auto renewal allowed after X days or hours after the issue date `reservesallowed` smallint(6) NOT NULL default "0", -- how many holds are allowed `branchcode` varchar(10) NOT NULL default '', -- the branch this rule is for (branches.branchcode) overduefinescap decimal(28,6) default NULL, -- the maximum amount of an overdue fine --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -169,6 +169,7 @@ for="tobranch">Clone these rules to: Clone these rules to: Clone these rules to: Yes +