Lines 2697-2702
sub CanBookBeRenewed {
Link Here
|
2697 |
'no_auto_renewal_after_hard_limit', |
2697 |
'no_auto_renewal_after_hard_limit', |
2698 |
'lengthunit', |
2698 |
'lengthunit', |
2699 |
'norenewalbefore', |
2699 |
'norenewalbefore', |
|
|
2700 |
'unseen_renewals_allowed' |
2700 |
] |
2701 |
] |
2701 |
} |
2702 |
} |
2702 |
); |
2703 |
); |
Lines 2875-2886
sub CanBookBeRenewed {
Link Here
|
2875 |
|
2876 |
|
2876 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed |
2877 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed |
2877 |
|
2878 |
|
|
|
2879 |
return ( 1, undef ) if $override_limit; |
2880 |
|
2881 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
2882 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
2883 |
{ |
2884 |
categorycode => $patron->categorycode, |
2885 |
itemtype => $item->effective_itemtype, |
2886 |
branchcode => $branchcode, |
2887 |
rules => [ |
2888 |
'renewalsallowed', |
2889 |
'no_auto_renewal_after', |
2890 |
'no_auto_renewal_after_hard_limit', |
2891 |
'lengthunit', |
2892 |
'norenewalbefore', |
2893 |
'unseen_renewals_allowed' |
2894 |
] |
2895 |
} |
2896 |
); |
2897 |
|
2898 |
return ( 0, "too_many" ) |
2899 |
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; |
2900 |
|
2901 |
return ( 0, "too_unseen" ) |
2902 |
if C4::Context->preference('UnseenRenewals') && |
2903 |
$issuing_rule->{unseen_renewals_allowed} && |
2904 |
$issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; |
2905 |
|
2906 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
2907 |
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); |
2908 |
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? |
2909 |
my $restricted = $patron->is_debarred; |
2910 |
my $hasoverdues = $patron->has_overdues; |
2911 |
|
2912 |
if ( $restricted and $restrictionblockrenewing ) { |
2913 |
return ( 0, 'restriction'); |
2914 |
} elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { |
2915 |
return ( 0, 'overdue'); |
2916 |
} |
2917 |
|
2918 |
if ( $issue->auto_renew ) { |
2919 |
|
2920 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
2921 |
return ( 0, 'auto_account_expired' ); |
2922 |
} |
2923 |
|
2924 |
if ( defined $issuing_rule->{no_auto_renewal_after} |
2925 |
and $issuing_rule->{no_auto_renewal_after} ne "" ) { |
2926 |
# Get issue_date and add no_auto_renewal_after |
2927 |
# If this is greater than today, it's too late for renewal. |
2928 |
my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); |
2929 |
$maximum_renewal_date->add( |
2930 |
$issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after} |
2931 |
); |
2932 |
my $now = dt_from_string; |
2933 |
if ( $now >= $maximum_renewal_date ) { |
2934 |
return ( 0, "auto_too_late" ); |
2935 |
} |
2936 |
} |
2937 |
if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit} |
2938 |
and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) { |
2939 |
# If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal |
2940 |
if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) { |
2941 |
return ( 0, "auto_too_late" ); |
2942 |
} |
2943 |
} |
2944 |
|
2945 |
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { |
2946 |
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); |
2947 |
my $amountoutstanding = |
2948 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredit") |
2949 |
? $patron->account->balance |
2950 |
: $patron->account->outstanding_debits->total_outstanding; |
2951 |
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { |
2952 |
return ( 0, "auto_too_much_oweing" ); |
2953 |
} |
2954 |
} |
2955 |
} |
2956 |
|
2957 |
if ( defined $issuing_rule->{norenewalbefore} |
2958 |
and $issuing_rule->{norenewalbefore} ne "" ) |
2959 |
{ |
2960 |
|
2961 |
# Calculate soonest renewal by subtracting 'No renewal before' from due date |
2962 |
my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( |
2963 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
2964 |
|
2965 |
# Depending on syspref reset the exact time, only check the date |
2966 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
2967 |
and $issuing_rule->{lengthunit} eq 'days' ) |
2968 |
{ |
2969 |
$soonestrenewal->truncate( to => 'day' ); |
2970 |
} |
2971 |
|
2972 |
if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) |
2973 |
{ |
2974 |
return ( 0, "auto_too_soon" ) if $issue->auto_renew; |
2975 |
return ( 0, "too_soon" ); |
2976 |
} |
2977 |
elsif ( $issue->auto_renew ) { |
2978 |
return ( 0, "auto_renew" ); |
2979 |
} |
2980 |
} |
2981 |
|
2982 |
# Fallback for automatic renewals: |
2983 |
# If norenewalbefore is undef, don't renew before due date. |
2984 |
if ( $issue->auto_renew ) { |
2985 |
my $now = dt_from_string; |
2986 |
return ( 0, "auto_renew" ) |
2987 |
if $now >= dt_from_string( $issue->date_due, 'sql' ); |
2988 |
return ( 0, "auto_too_soon" ); |
2989 |
} |
2990 |
|
2878 |
return ( 1, undef ); |
2991 |
return ( 1, undef ); |
2879 |
} |
2992 |
} |
2880 |
|
2993 |
|
2881 |
=head2 AddRenewal |
2994 |
=head2 AddRenewal |
2882 |
|
2995 |
|
2883 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate]); |
2996 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate], [$seen]); |
2884 |
|
2997 |
|
2885 |
Renews a loan. |
2998 |
Renews a loan. |
2886 |
|
2999 |
|
Lines 2905-2910
syspref)
Link Here
|
2905 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
3018 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
2906 |
from the book's item type. |
3019 |
from the book's item type. |
2907 |
|
3020 |
|
|
|
3021 |
C<$seen> is a boolean flag indicating if the item was seen or not during the renewal. This |
3022 |
informs the incrementing of the unseen_renewals column. If this flag is not supplied, we |
3023 |
fallback to a true value |
3024 |
|
2908 |
=cut |
3025 |
=cut |
2909 |
|
3026 |
|
2910 |
sub AddRenewal { |
3027 |
sub AddRenewal { |
Lines 2914-2919
sub AddRenewal {
Link Here
|
2914 |
my $datedue = shift; |
3031 |
my $datedue = shift; |
2915 |
my $lastreneweddate = shift || dt_from_string(); |
3032 |
my $lastreneweddate = shift || dt_from_string(); |
2916 |
my $skipfinecalc = shift; |
3033 |
my $skipfinecalc = shift; |
|
|
3034 |
my $seen = shift; |
3035 |
|
3036 |
# Fallback on a 'seen' renewal |
3037 |
$seen = defined $seen && $seen == 0 ? 0 : 1; |
2917 |
|
3038 |
|
2918 |
my $item_object = Koha::Items->find($itemnumber) or return; |
3039 |
my $item_object = Koha::Items->find($itemnumber) or return; |
2919 |
my $biblio = $item_object->biblio; |
3040 |
my $biblio = $item_object->biblio; |
Lines 2966-2980
sub AddRenewal {
Link Here
|
2966 |
} |
3087 |
} |
2967 |
); |
3088 |
); |
2968 |
|
3089 |
|
|
|
3090 |
# Increment the unseen renewals, if appropriate |
3091 |
# We only do so if the syspref is enabled and |
3092 |
# a maximum value has been set in the circ rules |
3093 |
my $unseen_renewals = $issue->unseen_renewals; |
3094 |
if (C4::Context->preference('UnseenRenewals')) { |
3095 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3096 |
{ categorycode => $patron->categorycode, |
3097 |
itemtype => $item_object->effective_itemtype, |
3098 |
branchcode => $circ_library->branchcode, |
3099 |
rule_name => 'unseen_renewals_allowed' |
3100 |
} |
3101 |
); |
3102 |
if (!$seen && $rule && $rule->rule_value) { |
3103 |
$unseen_renewals++; |
3104 |
} else { |
3105 |
# If the renewal is seen, unseen should revert to 0 |
3106 |
$unseen_renewals = 0; |
3107 |
} |
3108 |
} |
3109 |
|
2969 |
# Update the issues record to have the new due date, and a new count |
3110 |
# Update the issues record to have the new due date, and a new count |
2970 |
# of how many times it has been renewed. |
3111 |
# of how many times it has been renewed. |
2971 |
my $renews = ( $issue->renewals || 0 ) + 1; |
3112 |
my $renews = ( $issue->renewals || 0 ) + 1; |
2972 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
3113 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? |
2973 |
WHERE borrowernumber=? |
3114 |
WHERE borrowernumber=? |
2974 |
AND itemnumber=?" |
3115 |
AND itemnumber=?" |
2975 |
); |
3116 |
); |
2976 |
|
3117 |
|
2977 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
3118 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $borrowernumber, $itemnumber ); |
2978 |
|
3119 |
|
2979 |
# Update the renewal count on the item, and tell zebra to reindex |
3120 |
# Update the renewal count on the item, and tell zebra to reindex |
2980 |
$renews = ( $item_object->renewals || 0 ) + 1; |
3121 |
$renews = ( $item_object->renewals || 0 ) + 1; |
Lines 3061-3068
sub GetRenewCount {
Link Here
|
3061 |
my ( $bornum, $itemno ) = @_; |
3202 |
my ( $bornum, $itemno ) = @_; |
3062 |
my $dbh = C4::Context->dbh; |
3203 |
my $dbh = C4::Context->dbh; |
3063 |
my $renewcount = 0; |
3204 |
my $renewcount = 0; |
|
|
3205 |
my $unseencount = 0; |
3064 |
my $renewsallowed = 0; |
3206 |
my $renewsallowed = 0; |
|
|
3207 |
my $unseenallowed = 0; |
3065 |
my $renewsleft = 0; |
3208 |
my $renewsleft = 0; |
|
|
3209 |
my $unseenleft = 0; |
3066 |
|
3210 |
|
3067 |
my $patron = Koha::Patrons->find( $bornum ); |
3211 |
my $patron = Koha::Patrons->find( $bornum ); |
3068 |
my $item = Koha::Items->find($itemno); |
3212 |
my $item = Koha::Items->find($itemno); |
Lines 3081-3102
sub GetRenewCount {
Link Here
|
3081 |
$sth->execute( $bornum, $itemno ); |
3225 |
$sth->execute( $bornum, $itemno ); |
3082 |
my $data = $sth->fetchrow_hashref; |
3226 |
my $data = $sth->fetchrow_hashref; |
3083 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
3227 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
|
|
3228 |
$unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'}; |
3084 |
# $item and $borrower should be calculated |
3229 |
# $item and $borrower should be calculated |
3085 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
3230 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
3086 |
|
3231 |
|
3087 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3232 |
my $rules = Koha::CirculationRules->get_effective_rules( |
3088 |
{ |
3233 |
{ |
3089 |
categorycode => $patron->categorycode, |
3234 |
categorycode => $patron->categorycode, |
3090 |
itemtype => $item->effective_itemtype, |
3235 |
itemtype => $item->effective_itemtype, |
3091 |
branchcode => $branchcode, |
3236 |
branchcode => $branchcode, |
3092 |
rule_name => 'renewalsallowed', |
3237 |
rules => [ 'renewalsallowed', 'unseen_renewals_allowed' ] |
3093 |
} |
3238 |
} |
3094 |
); |
3239 |
); |
3095 |
|
3240 |
$renewsallowed = $rules ? $rules->{renewalsallowed} : 0; |
3096 |
$renewsallowed = $rule ? $rule->rule_value : 0; |
3241 |
$unseenallowed = $rules->{unseen_renewals_allowed} ? |
|
|
3242 |
$rules->{unseen_renewals_allowed} : |
3243 |
0; |
3097 |
$renewsleft = $renewsallowed - $renewcount; |
3244 |
$renewsleft = $renewsallowed - $renewcount; |
|
|
3245 |
$unseenleft = $unseenallowed - $unseencount; |
3098 |
if($renewsleft < 0){ $renewsleft = 0; } |
3246 |
if($renewsleft < 0){ $renewsleft = 0; } |
3099 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
3247 |
if($unseenleft < 0){ $unseenleft = 0; } |
|
|
3248 |
return ( |
3249 |
$renewcount, |
3250 |
$renewsallowed, |
3251 |
$renewsleft, |
3252 |
$unseencount, |
3253 |
$unseenallowed, |
3254 |
$unseenleft |
3255 |
); |
3100 |
} |
3256 |
} |
3101 |
|
3257 |
|
3102 |
=head2 GetSoonestRenewDate |
3258 |
=head2 GetSoonestRenewDate |