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

(-)a/C4/Circulation.pm (-113 / +5 lines)
Lines 2698-2703 sub CanBookBeRenewed { Link Here
2698
        return ( 0, "too_many" )
2698
        return ( 0, "too_many" )
2699
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2699
          if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2700
2700
2701
        return ( 0, "too_unseen" )
2702
          if C4::Context->preference('UnseenRenewals') &&
2703
            $issuing_rule->{unseen_renewals_allowed} &&
2704
            $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
2705
2701
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2706
        my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2702
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2707
        my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2703
        $patron         = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
2708
        $patron         = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
Lines 2869-2986 sub CanBookBeRenewed { Link Here
2869
2874
2870
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2875
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2871
2876
2872
    return ( 1, undef ) if $override_limit;
2873
2874
    my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed );
2875
    my $issuing_rule = Koha::CirculationRules->get_effective_rules(
2876
        {
2877
            categorycode => $patron->categorycode,
2878
            itemtype     => $item->effective_itemtype,
2879
            branchcode   => $branchcode,
2880
            rules => [
2881
                'renewalsallowed',
2882
                'no_auto_renewal_after',
2883
                'no_auto_renewal_after_hard_limit',
2884
                'lengthunit',
2885
                'norenewalbefore',
2886
                'unseen_renewals_allowed'
2887
            ]
2888
        }
2889
    );
2890
2891
    return ( 0, "too_many" )
2892
      if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals;
2893
2894
    return ( 0, "too_unseen" )
2895
      if C4::Context->preference('UnseenRenewals') &&
2896
        $issuing_rule->{unseen_renewals_allowed} &&
2897
        $issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals;
2898
2899
    my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing');
2900
    my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing');
2901
    $patron         = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful?
2902
    my $restricted  = $patron->is_debarred;
2903
    my $hasoverdues = $patron->has_overdues;
2904
2905
    if ( $restricted and $restrictionblockrenewing ) {
2906
        return ( 0, 'restriction');
2907
    } elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) {
2908
        return ( 0, 'overdue');
2909
    }
2910
2911
    if ( $issue->auto_renew ) {
2912
2913
        if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) {
2914
            return ( 0, 'auto_account_expired' );
2915
        }
2916
2917
        if ( defined $issuing_rule->{no_auto_renewal_after}
2918
                and $issuing_rule->{no_auto_renewal_after} ne "" ) {
2919
            # Get issue_date and add no_auto_renewal_after
2920
            # If this is greater than today, it's too late for renewal.
2921
            my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql');
2922
            $maximum_renewal_date->add(
2923
                $issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after}
2924
            );
2925
            my $now = dt_from_string;
2926
            if ( $now >= $maximum_renewal_date ) {
2927
                return ( 0, "auto_too_late" );
2928
            }
2929
        }
2930
        if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit}
2931
                      and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) {
2932
            # If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal
2933
            if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) {
2934
                return ( 0, "auto_too_late" );
2935
            }
2936
        }
2937
2938
        if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) {
2939
            my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals");
2940
            my $amountoutstanding =
2941
              C4::Context->preference("OPACFineNoRenewalsIncludeCredit")
2942
              ? $patron->account->balance
2943
              : $patron->account->outstanding_debits->total_outstanding;
2944
            if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) {
2945
                return ( 0, "auto_too_much_oweing" );
2946
            }
2947
        }
2948
    }
2949
2950
    if ( defined $issuing_rule->{norenewalbefore}
2951
        and $issuing_rule->{norenewalbefore} ne "" )
2952
    {
2953
2954
        # Calculate soonest renewal by subtracting 'No renewal before' from due date
2955
        my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract(
2956
            $issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} );
2957
2958
        # Depending on syspref reset the exact time, only check the date
2959
        if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date'
2960
            and $issuing_rule->{lengthunit} eq 'days' )
2961
        {
2962
            $soonestrenewal->truncate( to => 'day' );
2963
        }
2964
2965
        if ( $soonestrenewal > dt_from_string() )
2966
        {
2967
            return ( 0, "auto_too_soon" ) if $issue->auto_renew;
2968
            return ( 0, "too_soon" );
2969
        }
2970
        elsif ( $issue->auto_renew ) {
2971
            return ( 0, "auto_renew" );
2972
        }
2973
    }
2974
2975
    # Fallback for automatic renewals:
2976
    # If norenewalbefore is undef, don't renew before due date.
2977
    if ( $issue->auto_renew ) {
2978
        my $now = dt_from_string;
2979
        return ( 0, "auto_renew" )
2980
          if $now >= dt_from_string( $issue->date_due, 'sql' );
2981
        return ( 0, "auto_too_soon" );
2982
    }
2983
2984
    return ( 1, undef );
2877
    return ( 1, undef );
2985
}
2878
}
2986
2879
2987
- 

Return to bug 24083