Lines 3433-3438
C<$patron> is the patron who currently has the item on loan.
Link Here
|
3433 |
|
3433 |
|
3434 |
C<$issue> is the the item issue. |
3434 |
C<$issue> is the the item issue. |
3435 |
|
3435 |
|
|
|
3436 |
C<$is_auto> is this soonest renew date for an auto renewal? |
3437 |
|
3436 |
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible |
3438 |
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible |
3437 |
renew date, based on the value "No renewal before" of the applicable |
3439 |
renew date, based on the value "No renewal before" of the applicable |
3438 |
issuing rule. Returns the current date if the item can already be |
3440 |
issuing rule. Returns the current date if the item can already be |
Lines 3442-3454
cannot be found.
Link Here
|
3442 |
=cut |
3444 |
=cut |
3443 |
|
3445 |
|
3444 |
sub GetSoonestRenewDate { |
3446 |
sub GetSoonestRenewDate { |
3445 |
my ( $patron, $issue ) = @_; |
3447 |
my ( $patron, $issue, $is_auto ) = @_; |
3446 |
return unless $issue; |
3448 |
return unless $issue; |
3447 |
return unless $patron; |
3449 |
return unless $patron; |
3448 |
|
3450 |
|
3449 |
my $item = $issue->item; |
3451 |
my $item = $issue->item; |
3450 |
return unless $item; |
3452 |
return unless $item; |
3451 |
|
3453 |
|
|
|
3454 |
my $circ_rule = $is_auto ? 'noautorenewalbefore' : 'norenewalbefore'; |
3455 |
|
3452 |
my $dbh = C4::Context->dbh; |
3456 |
my $dbh = C4::Context->dbh; |
3453 |
|
3457 |
|
3454 |
my $branchcode = _GetCircControlBranch( $item, $patron ); |
3458 |
my $branchcode = _GetCircControlBranch( $item, $patron ); |
Lines 3457-3463
sub GetSoonestRenewDate {
Link Here
|
3457 |
itemtype => $item->effective_itemtype, |
3461 |
itemtype => $item->effective_itemtype, |
3458 |
branchcode => $branchcode, |
3462 |
branchcode => $branchcode, |
3459 |
rules => [ |
3463 |
rules => [ |
3460 |
'norenewalbefore', |
3464 |
$circ_rule, |
3461 |
'lengthunit', |
3465 |
'lengthunit', |
3462 |
] |
3466 |
] |
3463 |
} |
3467 |
} |
Lines 3465-3476
sub GetSoonestRenewDate {
Link Here
|
3465 |
|
3469 |
|
3466 |
my $now = dt_from_string; |
3470 |
my $now = dt_from_string; |
3467 |
|
3471 |
|
3468 |
if ( defined $issuing_rule->{norenewalbefore} |
3472 |
if ( defined $issuing_rule->{$circ_rule} |
3469 |
and $issuing_rule->{norenewalbefore} ne "" ) |
3473 |
and $issuing_rule->{$circ_rule} ne "" ) |
3470 |
{ |
3474 |
{ |
3471 |
my $soonestrenewal = |
3475 |
my $soonestrenewal = |
3472 |
dt_from_string( $issue->date_due )->subtract( |
3476 |
dt_from_string( $issue->date_due )->subtract( |
3473 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
3477 |
$issuing_rule->{lengthunit} => $issuing_rule->{$circ_rule} ); |
3474 |
|
3478 |
|
3475 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3479 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3476 |
and $issuing_rule->{lengthunit} eq 'days' ) |
3480 |
and $issuing_rule->{lengthunit} eq 'days' ) |
Lines 3478-3485
sub GetSoonestRenewDate {
Link Here
|
3478 |
$soonestrenewal->truncate( to => 'day' ); |
3482 |
$soonestrenewal->truncate( to => 'day' ); |
3479 |
} |
3483 |
} |
3480 |
return $soonestrenewal; |
3484 |
return $soonestrenewal; |
3481 |
} elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) { |
3485 |
} elsif ( $is_auto && $issue->auto_renew && $patron->autorenew_checkouts ) { |
3482 |
# Checkouts with auto-renewing fall back to due date |
3486 |
# Checkouts with auto-renewing fall back to due date if noautorenewalbefore is undef |
3483 |
my $soonestrenewal = dt_from_string( $issue->date_due ); |
3487 |
my $soonestrenewal = dt_from_string( $issue->date_due ); |
3484 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3488 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
3485 |
and $issuing_rule->{lengthunit} eq 'days' ) |
3489 |
and $issuing_rule->{lengthunit} eq 'days' ) |
Lines 4572-4578
sub _CanBookBeAutoRenewed {
Link Here
|
4572 |
} |
4576 |
} |
4573 |
} |
4577 |
} |
4574 |
|
4578 |
|
4575 |
my $soonest = GetSoonestRenewDate($patron, $issue); |
4579 |
my $soonest = GetSoonestRenewDate( $patron, $issue, 1 ); |
4576 |
if ( $soonest > dt_from_string() ) |
4580 |
if ( $soonest > dt_from_string() ) |
4577 |
{ |
4581 |
{ |
4578 |
return ( "auto_too_soon", $soonest ); |
4582 |
return ( "auto_too_soon", $soonest ); |
4579 |
- |
|
|