Lines 2982-2988
sub CanBookBeRenewed {
Link Here
|
2982 |
} |
2982 |
} |
2983 |
|
2983 |
|
2984 |
return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; |
2984 |
return ( 0, $auto_renew, { soonest_renew_date => $soonest } ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; |
2985 |
$soonest = GetSoonestRenewDate($borrowernumber, $itemnumber); |
2985 |
$soonest = GetSoonestRenewDate($issue); |
2986 |
if ( $soonest > dt_from_string() ){ |
2986 |
if ( $soonest > dt_from_string() ){ |
2987 |
return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit; |
2987 |
return (0, "too_soon", { soonest_renew_date => $soonest } ) unless $override_limit; |
2988 |
} |
2988 |
} |
Lines 3272-3285
sub GetRenewCount {
Link Here
|
3272 |
|
3272 |
|
3273 |
=head2 GetSoonestRenewDate |
3273 |
=head2 GetSoonestRenewDate |
3274 |
|
3274 |
|
3275 |
$NoRenewalBeforeThisDate = &GetSoonestRenewDate($borrowernumber, $itemnumber); |
3275 |
$NoRenewalBeforeThisDate = &GetSoonestRenewDate($issue); |
3276 |
|
3276 |
|
3277 |
Find out the soonest possible renew date of a borrowed item. |
3277 |
Find out the soonest possible renew date of a borrowed item. |
3278 |
|
3278 |
|
3279 |
C<$borrowernumber> is the borrower number of the patron who currently |
3279 |
C<$checkout> is the checkout object to renew. |
3280 |
has the item on loan. |
|
|
3281 |
|
3282 |
C<$itemnumber> is the number of the item to renew. |
3283 |
|
3280 |
|
3284 |
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible |
3281 |
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible |
3285 |
renew date, based on the value "No renewal before" of the applicable |
3282 |
renew date, based on the value "No renewal before" of the applicable |
Lines 3290-3305
cannot be found.
Link Here
|
3290 |
=cut |
3287 |
=cut |
3291 |
|
3288 |
|
3292 |
sub GetSoonestRenewDate { |
3289 |
sub GetSoonestRenewDate { |
3293 |
my ( $borrowernumber, $itemnumber ) = @_; |
3290 |
my ( $checkout ) = @_; |
3294 |
|
3291 |
|
3295 |
my $dbh = C4::Context->dbh; |
3292 |
my $item = $checkout->item or return; |
3296 |
|
3293 |
my $patron = $checkout->patron or return; |
3297 |
my $item = Koha::Items->find($itemnumber) or return; |
|
|
3298 |
my $itemissue = $item->checkout or return; |
3299 |
|
3300 |
$borrowernumber ||= $itemissue->borrowernumber; |
3301 |
my $patron = Koha::Patrons->find( $borrowernumber ) |
3302 |
or return; |
3303 |
|
3294 |
|
3304 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
3295 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
3305 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
3296 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
Lines 3319-3325
sub GetSoonestRenewDate {
Link Here
|
3319 |
and $issuing_rule->{norenewalbefore} ne "" ) |
3310 |
and $issuing_rule->{norenewalbefore} ne "" ) |
3320 |
{ |
3311 |
{ |
3321 |
my $soonestrenewal = |
3312 |
my $soonestrenewal = |
3322 |
dt_from_string( $itemissue->date_due )->subtract( |
3313 |
dt_from_string( $checkout->date_due )->subtract( |
3323 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
3314 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
3324 |
|
3315 |
|
3325 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3316 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
Lines 3328-3336
sub GetSoonestRenewDate {
Link Here
|
3328 |
$soonestrenewal->truncate( to => 'day' ); |
3319 |
$soonestrenewal->truncate( to => 'day' ); |
3329 |
} |
3320 |
} |
3330 |
return $soonestrenewal if $now < $soonestrenewal; |
3321 |
return $soonestrenewal if $now < $soonestrenewal; |
3331 |
} elsif ( $itemissue->auto_renew && $patron->autorenew_checkouts ) { |
3322 |
} elsif ( $checkout->auto_renew && $patron->autorenew_checkouts ) { |
3332 |
# Checkouts with auto-renewing fall back to due date |
3323 |
# Checkouts with auto-renewing fall back to due date |
3333 |
my $soonestrenewal = dt_from_string( $itemissue->date_due ); |
3324 |
my $soonestrenewal = dt_from_string( $checkout->date_due ); |
3334 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3325 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3335 |
and $issuing_rule->{lengthunit} eq 'days' ) |
3326 |
and $issuing_rule->{lengthunit} eq 'days' ) |
3336 |
{ |
3327 |
{ |
Lines 4423-4429
sub _CanBookBeAutoRenewed {
Link Here
|
4423 |
} |
4414 |
} |
4424 |
} |
4415 |
} |
4425 |
|
4416 |
|
4426 |
my $soonest = GetSoonestRenewDate($patron->id, $item->id); |
4417 |
my $soonest = GetSoonestRenewDate($issue); |
4427 |
if ( $soonest > dt_from_string() ) |
4418 |
if ( $soonest > dt_from_string() ) |
4428 |
{ |
4419 |
{ |
4429 |
return ( "auto_too_soon", $soonest ); |
4420 |
return ( "auto_too_soon", $soonest ); |