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

(-)a/C4/Circulation.pm (-77 / +102 lines)
Lines 2767-2776 sub CanBookBeRenewed { Link Here
2767
                branchcode   => $branchcode,
2767
                branchcode   => $branchcode,
2768
                rules => [
2768
                rules => [
2769
                    'renewalsallowed',
2769
                    'renewalsallowed',
2770
                    'no_auto_renewal_after',
2771
                    'no_auto_renewal_after_hard_limit',
2772
                    'lengthunit',
2770
                    'lengthunit',
2773
                    'norenewalbefore',
2774
                    'unseen_renewals_allowed'
2771
                    'unseen_renewals_allowed'
2775
                ]
2772
                ]
2776
            }
2773
            }
Lines 2796-2874 sub CanBookBeRenewed { Link Here
2796
            return ( 0, 'overdue');
2793
            return ( 0, 'overdue');
2797
        }
2794
        }
2798
2795
2799
        if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2796
        $auto_renew = _CanBookBeAutoRenewed($borrowernumber, $itemnumber);
2800
2797
        return ( 0, $auto_renew  ) if $auto_renew =~ 'auto_account_expired';
2801
            if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2798
        return ( 0, $auto_renew  ) if $auto_renew =~ 'auto_too_late';
2802
                return ( 0, 'auto_account_expired' );
2799
        return ( 0, $auto_renew  ) if $auto_renew =~ 'auto_too_much_oweing';
2803
            }
2804
2805
            if ( defined $issuing_rule->{no_auto_renewal_after}
2806
                    and $issuing_rule->{no_auto_renewal_after} ne "" ) {
2807
                # Get issue_date and add no_auto_renewal_after
2808
                # If this is greater than today, it's too late for renewal.
2809
                my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql');
2810
                $maximum_renewal_date->add(
2811
                    $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after}
2812
                );
2813
                my $now = dt_from_string;
2814
                if ( $now >= $maximum_renewal_date ) {
2815
                    return ( 0, "auto_too_late" );
2816
                }
2817
            }
2818
            if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
2819
                          and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
2820
                # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
2821
                if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
2822
                    return ( 0, "auto_too_late" );
2823
                }
2824
            }
2825
2826
            if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
2827
                my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
2828
                my $amountoutstanding =
2829
                  C4::Context->preference("OPACFineNoRenewalsIncludeCredit")
2830
                  ? $patron->account->balance
2831
                  : $patron->account->outstanding_debits->total_outstanding;
2832
                if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2833
                    return ( 0, "auto_too_much_oweing" );
2834
                }
2835
            }
2836
        }
2837
2838
        if ( defined $issuing_rule->{norenewalbefore}
2839
            and $issuing_rule->{norenewalbefore} ne "" )
2840
        {
2841
2842
            # Calculate soonest renewal by subtracting 'No renewal before' from due date
2843
            my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract(
2844
                $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} );
2845
2846
            # Depending on syspref reset the exact time, only check the date
2847
            if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
2848
                and $issuing_rule->{lengthunit} eq 'days' )
2849
            {
2850
                $soonestrenewal->truncate( to => 'day' );
2851
            }
2852
2853
            if ( $soonestrenewal > dt_from_string() )
2854
            {
2855
                $auto_renew = ($issue->auto_renew && $patron->autorenew_checkouts) ? "auto_too_soon" : "too_soon";
2856
            }
2857
            elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2858
                $auto_renew = "ok";
2859
            }
2860
        }
2861
2862
        # Fallback for automatic renewals:
2863
        # If norenewalbefore is undef, don't renew before due date.
2864
        if ( $issue->auto_renew && $auto_renew eq "no" && $patron->autorenew_checkouts ) {
2865
            my $now = dt_from_string;
2866
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2867
                $auto_renew = "ok";
2868
            } else {
2869
                $auto_renew = "auto_too_soon";
2870
            }
2871
        }
2872
    }
2800
    }
2873
2801
2874
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
2802
    my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber);
Lines 4375-4380 sub _CalculateAndUpdateFine { Link Here
4375
    }
4303
    }
4376
}
4304
}
4377
4305
4306
sub _CanBookBeAutoRenewed {
4307
    my ( $borrowernumber, $itemnumber ) = @_;
4308
4309
    my $item = Koha::Items->find($itemnumber);
4310
    my $issue = $item->checkout;
4311
    my $patron = $issue->patron;
4312
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
4313
4314
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
4315
        {
4316
            categorycode => $patron->categorycode,
4317
            itemtype     => $item->effective_itemtype,
4318
            branchcode   => $branchcode,
4319
            rules => [
4320
                'no_auto_renewal_after',
4321
                'no_auto_renewal_after_hard_limit',
4322
                'lengthunit',
4323
                'norenewalbefore',
4324
            ]
4325
        }
4326
    );
4327
4328
    if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
4329
4330
        if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
4331
            return 'auto_account_expired';
4332
        }
4333
4334
        if ( defined $issuing_rule->{no_auto_renewal_after}
4335
                and $issuing_rule->{no_auto_renewal_after} ne "" ) {
4336
            # Get issue_date and add no_auto_renewal_after
4337
            # If this is greater than today, it's too late for renewal.
4338
            my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql');
4339
            $maximum_renewal_date->add(
4340
                $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after}
4341
            );
4342
            my $now = dt_from_string;
4343
            if ( $now >= $maximum_renewal_date ) {
4344
                return "auto_too_late";
4345
            }
4346
        }
4347
        if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
4348
                      and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
4349
            # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
4350
            if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
4351
                return "auto_too_late";
4352
            }
4353
        }
4354
4355
        if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
4356
            my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
4357
            my $amountoutstanding =
4358
              C4::Context->preference("OPACFineNoRenewalsIncludeCredit")
4359
              ? $patron->account->balance
4360
              : $patron->account->outstanding_debits->total_outstanding;
4361
            if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
4362
                return "auto_too_much_oweing";
4363
            }
4364
        }
4365
    }
4366
4367
    if ( defined $issuing_rule->{norenewalbefore}
4368
        and $issuing_rule->{norenewalbefore} ne "" )
4369
    {
4370
4371
        # Calculate soonest renewal by subtracting 'No renewal before' from due date
4372
        my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract(
4373
            $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} );
4374
4375
        # Depending on syspref reset the exact time, only check the date
4376
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
4377
            and $issuing_rule->{lengthunit} eq 'days' )
4378
        {
4379
            $soonestrenewal->truncate( to => 'day' );
4380
        }
4381
4382
        if ( $soonestrenewal > dt_from_string() )
4383
        {
4384
            return ($issue->auto_renew && $patron->autorenew_checkouts) ? "auto_too_soon" : "too_soon";
4385
        }
4386
        elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
4387
            return "ok";
4388
        }
4389
    }
4390
4391
    # Fallback for automatic renewals:
4392
    # If norenewalbefore is undef, don't renew before due date.
4393
    if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
4394
        my $now = dt_from_string;
4395
        if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
4396
            return "ok";
4397
        } else {
4398
            return "auto_too_soon";
4399
        }
4400
    }
4401
    return "no";
4402
}
4403
4378
sub _item_denied_renewal {
4404
sub _item_denied_renewal {
4379
    my ($params) = @_;
4405
    my ($params) = @_;
4380
4406
4381
- 

Return to bug 27032