@@ -, +, @@ GetSoonestRenewDate --- C4/Circulation.pm | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) --- a/C4/Circulation.pm +++ a/C4/Circulation.pm @@ -2750,38 +2750,28 @@ sub CanBookBeRenewed { } } - if ( defined $issuing_rule->norenewalbefore - and $issuing_rule->norenewalbefore ne "" ) - { - - # Calculate soonest renewal by subtracting 'No renewal before' from due date - my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( - $issuing_rule->lengthunit => $issuing_rule->norenewalbefore ); + #NOTE: If norenewalbefore is undef, $soonestrenewal will equal $now + my $soonestrenewal = GetSoonestRenewDate($borrowernumber, $itemnumber); + my $now = dt_from_string; - # Depending on syspref reset the exact time, only check the date - if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' - and $issuing_rule->lengthunit eq 'days' ) - { - $soonestrenewal->truncate( to => 'day' ); + if ( $issue->auto_renew ){ + if ( $soonestrenewal > $now ){ + return ( 0, "auto_too_soon" ); } - - if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) - { - return ( 0, "auto_too_soon" ) if $issue->auto_renew; - return ( 0, "too_soon" ); - } - elsif ( $issue->auto_renew ) { - return ( 0, "auto_renew" ); + else { + #Fallback: if norenewalbefore is undef, don't renew before due date + if ( dt_from_string( $issue->date_due, 'sql' ) > $now ){ + return ( 0, "auto_too_soon" ); + } + else { + return ( 0, "auto_renew" ); + } } } - - # Fallback for automatic renewals: - # If norenewalbefore is undef, don't renew before due date. - if ( $issue->auto_renew ) { - my $now = dt_from_string; - return ( 0, "auto_renew" ) - if $now >= dt_from_string( $issue->date_due, 'sql' ); - return ( 0, "auto_too_soon" ); + else { + if ( $soonestrenewal > $now ){ + return ( 0, "too_soon" ); + } } return ( 1, undef ); --