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

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

Return to bug 24083