View | Details | Raw Unified | Return to bug 25393
Collapse All | Expand All

(-)a/C4/Circulation.pm (-9 / +12 lines)
Lines 3413-3418 C<$patron> is the patron who currently has the item on loan. Link Here
3413
3413
3414
C<$issue> is the the item issue.
3414
C<$issue> is the the item issue.
3415
3415
3416
C<$is_auto> is this soonest renew date for an auto renewal?
3417
3416
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible
3418
C<$GetSoonestRenewDate> returns the DateTime of the soonest possible
3417
renew date, based on the value "No renewal before" of the applicable
3419
renew date, based on the value "No renewal before" of the applicable
3418
issuing rule. Returns the current date if the item can already be
3420
issuing rule. Returns the current date if the item can already be
Lines 3422-3434 cannot be found. Link Here
3422
=cut
3424
=cut
3423
3425
3424
sub GetSoonestRenewDate {
3426
sub GetSoonestRenewDate {
3425
    my ( $patron, $issue ) = @_;
3427
    my ( $patron, $issue, $is_auto ) = @_;
3426
    return unless $issue;
3428
    return unless $issue;
3427
    return unless $patron;
3429
    return unless $patron;
3428
3430
3429
    my $item = $issue->item;
3431
    my $item = $issue->item;
3430
    return unless $item;
3432
    return unless $item;
3431
3433
3434
    my $circ_rule = $is_auto ? 'noautorenewalbefore' : 'norenewalbefore';
3435
3432
    my $dbh = C4::Context->dbh;
3436
    my $dbh = C4::Context->dbh;
3433
3437
3434
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
3438
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
Lines 3437-3443 sub GetSoonestRenewDate { Link Here
3437
            itemtype     => $item->effective_itemtype,
3441
            itemtype     => $item->effective_itemtype,
3438
            branchcode   => $branchcode,
3442
            branchcode   => $branchcode,
3439
            rules => [
3443
            rules => [
3440
                'norenewalbefore',
3444
                $circ_rule,
3441
                'lengthunit',
3445
                'lengthunit',
3442
            ]
3446
            ]
3443
        }
3447
        }
Lines 3445-3456 sub GetSoonestRenewDate { Link Here
3445
3449
3446
    my $now = dt_from_string;
3450
    my $now = dt_from_string;
3447
3451
3448
    if ( defined $issuing_rule->{norenewalbefore}
3452
    if ( defined $issuing_rule->{$circ_rule}
3449
        and $issuing_rule->{norenewalbefore} ne "" )
3453
        and $issuing_rule->{$circ_rule} ne "" )
3450
    {
3454
    {
3451
        my $soonestrenewal =
3455
        my $soonestrenewal =
3452
          dt_from_string( $issue->date_due )->subtract(
3456
          dt_from_string( $issue->date_due )->subtract(
3453
            $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} );
3457
            $issuing_rule->{lengthunit} => $issuing_rule->{$circ_rule} );
3454
3458
3455
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
3459
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
3456
            and $issuing_rule->{lengthunit} eq 'days' )
3460
            and $issuing_rule->{lengthunit} eq 'days' )
Lines 3458-3465 sub GetSoonestRenewDate { Link Here
3458
            $soonestrenewal->truncate( to => 'day' );
3462
            $soonestrenewal->truncate( to => 'day' );
3459
        }
3463
        }
3460
        return $soonestrenewal if $now < $soonestrenewal;
3464
        return $soonestrenewal if $now < $soonestrenewal;
3461
    } elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
3465
    } elsif ( $is_auto && $issue->auto_renew && $patron->autorenew_checkouts ) {
3462
        # Checkouts with auto-renewing fall back to due date
3466
        # Checkouts with auto-renewing fall back to due date if noautorenewalbefore is undef
3463
        my $soonestrenewal = dt_from_string( $issue->date_due );
3467
        my $soonestrenewal = dt_from_string( $issue->date_due );
3464
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
3468
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
3465
            and $issuing_rule->{lengthunit} eq 'days' )
3469
            and $issuing_rule->{lengthunit} eq 'days' )
Lines 4552-4558 sub _CanBookBeAutoRenewed { Link Here
4552
        }
4556
        }
4553
    }
4557
    }
4554
4558
4555
    my $soonest = GetSoonestRenewDate($patron, $issue);
4559
    my $soonest = GetSoonestRenewDate( $patron, $issue, 1 );
4556
    if ( $soonest > dt_from_string() )
4560
    if ( $soonest > dt_from_string() )
4557
    {
4561
    {
4558
        return ( "auto_too_soon", $soonest );
4562
        return ( "auto_too_soon", $soonest );
4559
- 

Return to bug 25393