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