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

(-)a/C4/Circulation.pm (-77 / +102 lines)
Lines 2757-2766 sub CanBookBeRenewed { Link Here
2757
                branchcode   => $branchcode,
2757
                branchcode   => $branchcode,
2758
                rules => [
2758
                rules => [
2759
                    'renewalsallowed',
2759
                    'renewalsallowed',
2760
                    'no_auto_renewal_after',
2761
                    'no_auto_renewal_after_hard_limit',
2762
                    'lengthunit',
2760
                    'lengthunit',
2763
                    'norenewalbefore',
2764
                    'unseen_renewals_allowed'
2761
                    'unseen_renewals_allowed'
2765
                ]
2762
                ]
2766
            }
2763
            }
Lines 2786-2864 sub CanBookBeRenewed { Link Here
2786
            return ( 0, 'overdue');
2783
            return ( 0, 'overdue');
2787
        }
2784
        }
2788
2785
2789
        if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2786
        $auto_renew = _CanBookBeAutoRenewed($borrowernumber, $itemnumber);
2790
2787
        return ( 0, $auto_renew  ) if $auto_renew =~ 'auto_account_expired';
2791
            if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2788
        return ( 0, $auto_renew  ) if $auto_renew =~ 'auto_too_late';
2792
                return ( 0, 'auto_account_expired' );
2789
        return ( 0, $auto_renew  ) if $auto_renew =~ 'auto_too_much_oweing';
2793
            }
2794
2795
            if ( defined $issuing_rule->{no_auto_renewal_after}
2796
                    and $issuing_rule->{no_auto_renewal_after} ne "" ) {
2797
                # Get issue_date and add no_auto_renewal_after
2798
                # If this is greater than today, it's too late for renewal.
2799
                my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql');
2800
                $maximum_renewal_date->add(
2801
                    $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after}
2802
                );
2803
                my $now = dt_from_string;
2804
                if ( $now >= $maximum_renewal_date ) {
2805
                    return ( 0, "auto_too_late" );
2806
                }
2807
            }
2808
            if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
2809
                          and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
2810
                # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
2811
                if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
2812
                    return ( 0, "auto_too_late" );
2813
                }
2814
            }
2815
2816
            if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
2817
                my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
2818
                my $amountoutstanding =
2819
                  C4::Context->preference("OPACFineNoRenewalsIncludeCredit")
2820
                  ? $patron->account->balance
2821
                  : $patron->account->outstanding_debits->total_outstanding;
2822
                if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2823
                    return ( 0, "auto_too_much_oweing" );
2824
                }
2825
            }
2826
        }
2827
2828
        if ( defined $issuing_rule->{norenewalbefore}
2829
            and $issuing_rule->{norenewalbefore} ne "" )
2830
        {
2831
2832
            # Calculate soonest renewal by subtracting 'No renewal before' from due date
2833
            my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract(
2834
                $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} );
2835
2836
            # Depending on syspref reset the exact time, only check the date
2837
            if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
2838
                and $issuing_rule->{lengthunit} eq 'days' )
2839
            {
2840
                $soonestrenewal->truncate( to => 'day' );
2841
            }
2842
2843
            if ( $soonestrenewal > dt_from_string() )
2844
            {
2845
                $auto_renew = ($issue->auto_renew && $patron->autorenew_checkouts) ? "auto_too_soon" : "too_soon";
2846
            }
2847
            elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
2848
                $auto_renew = "ok";
2849
            }
2850
        }
2851
2852
        # Fallback for automatic renewals:
2853
        # If norenewalbefore is undef, don't renew before due date.
2854
        if ( $issue->auto_renew && $auto_renew eq "no" && $patron->autorenew_checkouts ) {
2855
            my $now = dt_from_string;
2856
            if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
2857
                $auto_renew = "ok";
2858
            } else {
2859
                $auto_renew = "auto_too_soon";
2860
            }
2861
        }
2862
    }
2790
    }
2863
2791
2864
    my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber);
2792
    my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber);
Lines 4306-4311 sub _CalculateAndUpdateFine { Link Here
4306
    }
4234
    }
4307
}
4235
}
4308
4236
4237
sub _CanBookBeAutoRenewed {
4238
    my ( $borrowernumber, $itemnumber ) = @_;
4239
4240
    my $item = Koha::Items->find($itemnumber);
4241
    my $issue = $item->checkout;
4242
    my $patron = $issue->patron;
4243
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
4244
4245
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
4246
        {
4247
            categorycode => $patron->categorycode,
4248
            itemtype     => $item->effective_itemtype,
4249
            branchcode   => $branchcode,
4250
            rules => [
4251
                'no_auto_renewal_after',
4252
                'no_auto_renewal_after_hard_limit',
4253
                'lengthunit',
4254
                'norenewalbefore',
4255
            ]
4256
        }
4257
    );
4258
4259
    if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
4260
4261
        if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
4262
            return 'auto_account_expired';
4263
        }
4264
4265
        if ( defined $issuing_rule->{no_auto_renewal_after}
4266
                and $issuing_rule->{no_auto_renewal_after} ne "" ) {
4267
            # Get issue_date and add no_auto_renewal_after
4268
            # If this is greater than today, it's too late for renewal.
4269
            my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql');
4270
            $maximum_renewal_date->add(
4271
                $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after}
4272
            );
4273
            my $now = dt_from_string;
4274
            if ( $now >= $maximum_renewal_date ) {
4275
                return "auto_too_late";
4276
            }
4277
        }
4278
        if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
4279
                      and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
4280
            # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
4281
            if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
4282
                return "auto_too_late";
4283
            }
4284
        }
4285
4286
        if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
4287
            my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
4288
            my $amountoutstanding =
4289
              C4::Context->preference("OPACFineNoRenewalsIncludeCredit")
4290
              ? $patron->account->balance
4291
              : $patron->account->outstanding_debits->total_outstanding;
4292
            if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
4293
                return "auto_too_much_oweing";
4294
            }
4295
        }
4296
    }
4297
4298
    if ( defined $issuing_rule->{norenewalbefore}
4299
        and $issuing_rule->{norenewalbefore} ne "" )
4300
    {
4301
4302
        # Calculate soonest renewal by subtracting 'No renewal before' from due date
4303
        my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract(
4304
            $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} );
4305
4306
        # Depending on syspref reset the exact time, only check the date
4307
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
4308
            and $issuing_rule->{lengthunit} eq 'days' )
4309
        {
4310
            $soonestrenewal->truncate( to => 'day' );
4311
        }
4312
4313
        if ( $soonestrenewal > dt_from_string() )
4314
        {
4315
            return ($issue->auto_renew && $patron->autorenew_checkouts) ? "auto_too_soon" : "too_soon";
4316
        }
4317
        elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) {
4318
            return "ok";
4319
        }
4320
    }
4321
4322
    # Fallback for automatic renewals:
4323
    # If norenewalbefore is undef, don't renew before due date.
4324
    if ( $issue->auto_renew && $patron->autorenew_checkouts ) {
4325
        my $now = dt_from_string;
4326
        if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){
4327
            return "ok";
4328
        } else {
4329
            return "auto_too_soon";
4330
        }
4331
    }
4332
    return "no";
4333
}
4334
4309
sub _item_denied_renewal {
4335
sub _item_denied_renewal {
4310
    my ($params) = @_;
4336
    my ($params) = @_;
4311
4337
4312
- 

Return to bug 27032