|
Lines 2773-2778
sub CanBookBeRenewed {
Link Here
|
| 2773 |
'no_auto_renewal_after_hard_limit', |
2773 |
'no_auto_renewal_after_hard_limit', |
| 2774 |
'lengthunit', |
2774 |
'lengthunit', |
| 2775 |
'norenewalbefore', |
2775 |
'norenewalbefore', |
|
|
2776 |
'unseen_renewals_allowed' |
| 2776 |
] |
2777 |
] |
| 2777 |
} |
2778 |
} |
| 2778 |
); |
2779 |
); |
|
Lines 2951-2962
sub CanBookBeRenewed {
Link Here
|
| 2951 |
|
2952 |
|
| 2952 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed |
2953 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed |
| 2953 |
|
2954 |
|
|
|
2955 |
return ( 1, undef ) if $override_limit; |
| 2956 |
|
| 2957 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
| 2958 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
| 2959 |
{ |
| 2960 |
categorycode => $patron->categorycode, |
| 2961 |
itemtype => $item->effective_itemtype, |
| 2962 |
branchcode => $branchcode, |
| 2963 |
rules => [ |
| 2964 |
'renewalsallowed', |
| 2965 |
'no_auto_renewal_after', |
| 2966 |
'no_auto_renewal_after_hard_limit', |
| 2967 |
'lengthunit', |
| 2968 |
'norenewalbefore', |
| 2969 |
'unseen_renewals_allowed' |
| 2970 |
] |
| 2971 |
} |
| 2972 |
); |
| 2973 |
|
| 2974 |
return ( 0, "too_many" ) |
| 2975 |
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; |
| 2976 |
|
| 2977 |
return ( 0, "too_unseen" ) |
| 2978 |
if C4::Context->preference('UnseenRenewals') && |
| 2979 |
$issuing_rule->{unseen_renewals_allowed} && |
| 2980 |
$issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; |
| 2981 |
|
| 2982 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
| 2983 |
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); |
| 2984 |
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? |
| 2985 |
my $restricted = $patron->is_debarred; |
| 2986 |
my $hasoverdues = $patron->has_overdues; |
| 2987 |
|
| 2988 |
if ( $restricted and $restrictionblockrenewing ) { |
| 2989 |
return ( 0, 'restriction'); |
| 2990 |
} elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { |
| 2991 |
return ( 0, 'overdue'); |
| 2992 |
} |
| 2993 |
|
| 2994 |
if ( $issue->auto_renew ) { |
| 2995 |
|
| 2996 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
| 2997 |
return ( 0, 'auto_account_expired' ); |
| 2998 |
} |
| 2999 |
|
| 3000 |
if ( defined $issuing_rule->{no_auto_renewal_after} |
| 3001 |
and $issuing_rule->{no_auto_renewal_after} ne "" ) { |
| 3002 |
# Get issue_date and add no_auto_renewal_after |
| 3003 |
# If this is greater than today, it's too late for renewal. |
| 3004 |
my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); |
| 3005 |
$maximum_renewal_date->add( |
| 3006 |
$issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after} |
| 3007 |
); |
| 3008 |
my $now = dt_from_string; |
| 3009 |
if ( $now >= $maximum_renewal_date ) { |
| 3010 |
return ( 0, "auto_too_late" ); |
| 3011 |
} |
| 3012 |
} |
| 3013 |
if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit} |
| 3014 |
and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) { |
| 3015 |
# If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal |
| 3016 |
if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) { |
| 3017 |
return ( 0, "auto_too_late" ); |
| 3018 |
} |
| 3019 |
} |
| 3020 |
|
| 3021 |
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { |
| 3022 |
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); |
| 3023 |
my $amountoutstanding = |
| 3024 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredit") |
| 3025 |
? $patron->account->balance |
| 3026 |
: $patron->account->outstanding_debits->total_outstanding; |
| 3027 |
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { |
| 3028 |
return ( 0, "auto_too_much_oweing" ); |
| 3029 |
} |
| 3030 |
} |
| 3031 |
} |
| 3032 |
|
| 3033 |
if ( defined $issuing_rule->{norenewalbefore} |
| 3034 |
and $issuing_rule->{norenewalbefore} ne "" ) |
| 3035 |
{ |
| 3036 |
|
| 3037 |
# Calculate soonest renewal by subtracting 'No renewal before' from due date |
| 3038 |
my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( |
| 3039 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
| 3040 |
|
| 3041 |
# Depending on syspref reset the exact time, only check the date |
| 3042 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
| 3043 |
and $issuing_rule->{lengthunit} eq 'days' ) |
| 3044 |
{ |
| 3045 |
$soonestrenewal->truncate( to => 'day' ); |
| 3046 |
} |
| 3047 |
|
| 3048 |
if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) |
| 3049 |
{ |
| 3050 |
return ( 0, "auto_too_soon" ) if $issue->auto_renew; |
| 3051 |
return ( 0, "too_soon" ); |
| 3052 |
} |
| 3053 |
elsif ( $issue->auto_renew ) { |
| 3054 |
return ( 0, "auto_renew" ); |
| 3055 |
} |
| 3056 |
} |
| 3057 |
|
| 3058 |
# Fallback for automatic renewals: |
| 3059 |
# If norenewalbefore is undef, don't renew before due date. |
| 3060 |
if ( $issue->auto_renew ) { |
| 3061 |
my $now = dt_from_string; |
| 3062 |
return ( 0, "auto_renew" ) |
| 3063 |
if $now >= dt_from_string( $issue->date_due, 'sql' ); |
| 3064 |
return ( 0, "auto_too_soon" ); |
| 3065 |
} |
| 3066 |
|
| 2954 |
return ( 1, undef ); |
3067 |
return ( 1, undef ); |
| 2955 |
} |
3068 |
} |
| 2956 |
|
3069 |
|
| 2957 |
=head2 AddRenewal |
3070 |
=head2 AddRenewal |
| 2958 |
|
3071 |
|
| 2959 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate]); |
3072 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate], [$seen]); |
| 2960 |
|
3073 |
|
| 2961 |
Renews a loan. |
3074 |
Renews a loan. |
| 2962 |
|
3075 |
|
|
Lines 2981-2986
syspref)
Link Here
|
| 2981 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
3094 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
| 2982 |
from the book's item type. |
3095 |
from the book's item type. |
| 2983 |
|
3096 |
|
|
|
3097 |
C<$seen> is a boolean flag indicating if the item was seen or not during the renewal. This |
| 3098 |
informs the incrementing of the unseen_renewals column. If this flag is not supplied, we |
| 3099 |
fallback to a true value |
| 3100 |
|
| 2984 |
=cut |
3101 |
=cut |
| 2985 |
|
3102 |
|
| 2986 |
sub AddRenewal { |
3103 |
sub AddRenewal { |
|
Lines 2990-2995
sub AddRenewal {
Link Here
|
| 2990 |
my $datedue = shift; |
3107 |
my $datedue = shift; |
| 2991 |
my $lastreneweddate = shift || dt_from_string(); |
3108 |
my $lastreneweddate = shift || dt_from_string(); |
| 2992 |
my $skipfinecalc = shift; |
3109 |
my $skipfinecalc = shift; |
|
|
3110 |
my $seen = shift; |
| 3111 |
|
| 3112 |
# Fallback on a 'seen' renewal |
| 3113 |
$seen = defined $seen && $seen == 0 ? 0 : 1; |
| 2993 |
|
3114 |
|
| 2994 |
my $item_object = Koha::Items->find($itemnumber) or return; |
3115 |
my $item_object = Koha::Items->find($itemnumber) or return; |
| 2995 |
my $biblio = $item_object->biblio; |
3116 |
my $biblio = $item_object->biblio; |
|
Lines 3042-3056
sub AddRenewal {
Link Here
|
| 3042 |
} |
3163 |
} |
| 3043 |
); |
3164 |
); |
| 3044 |
|
3165 |
|
|
|
3166 |
# Increment the unseen renewals, if appropriate |
| 3167 |
# We only do so if the syspref is enabled and |
| 3168 |
# a maximum value has been set in the circ rules |
| 3169 |
my $unseen_renewals = $issue->unseen_renewals; |
| 3170 |
if (C4::Context->preference('UnseenRenewals')) { |
| 3171 |
my $rule = Koha::CirculationRules->get_effective_rule( |
| 3172 |
{ categorycode => $patron->categorycode, |
| 3173 |
itemtype => $item_object->effective_itemtype, |
| 3174 |
branchcode => $circ_library->branchcode, |
| 3175 |
rule_name => 'unseen_renewals_allowed' |
| 3176 |
} |
| 3177 |
); |
| 3178 |
if (!$seen && $rule && $rule->rule_value) { |
| 3179 |
$unseen_renewals++; |
| 3180 |
} else { |
| 3181 |
# If the renewal is seen, unseen should revert to 0 |
| 3182 |
$unseen_renewals = 0; |
| 3183 |
} |
| 3184 |
} |
| 3185 |
|
| 3045 |
# Update the issues record to have the new due date, and a new count |
3186 |
# Update the issues record to have the new due date, and a new count |
| 3046 |
# of how many times it has been renewed. |
3187 |
# of how many times it has been renewed. |
| 3047 |
my $renews = ( $issue->renewals || 0 ) + 1; |
3188 |
my $renews = ( $issue->renewals || 0 ) + 1; |
| 3048 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
3189 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? |
| 3049 |
WHERE borrowernumber=? |
3190 |
WHERE borrowernumber=? |
| 3050 |
AND itemnumber=?" |
3191 |
AND itemnumber=?" |
| 3051 |
); |
3192 |
); |
| 3052 |
|
3193 |
|
| 3053 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
3194 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $borrowernumber, $itemnumber ); |
| 3054 |
|
3195 |
|
| 3055 |
# Update the renewal count on the item, and tell zebra to reindex |
3196 |
# Update the renewal count on the item, and tell zebra to reindex |
| 3056 |
$renews = ( $item_object->renewals || 0 ) + 1; |
3197 |
$renews = ( $item_object->renewals || 0 ) + 1; |
|
Lines 3137-3144
sub GetRenewCount {
Link Here
|
| 3137 |
my ( $bornum, $itemno ) = @_; |
3278 |
my ( $bornum, $itemno ) = @_; |
| 3138 |
my $dbh = C4::Context->dbh; |
3279 |
my $dbh = C4::Context->dbh; |
| 3139 |
my $renewcount = 0; |
3280 |
my $renewcount = 0; |
|
|
3281 |
my $unseencount = 0; |
| 3140 |
my $renewsallowed = 0; |
3282 |
my $renewsallowed = 0; |
|
|
3283 |
my $unseenallowed = 0; |
| 3141 |
my $renewsleft = 0; |
3284 |
my $renewsleft = 0; |
|
|
3285 |
my $unseenleft = 0; |
| 3142 |
|
3286 |
|
| 3143 |
my $patron = Koha::Patrons->find( $bornum ); |
3287 |
my $patron = Koha::Patrons->find( $bornum ); |
| 3144 |
my $item = Koha::Items->find($itemno); |
3288 |
my $item = Koha::Items->find($itemno); |
|
Lines 3157-3178
sub GetRenewCount {
Link Here
|
| 3157 |
$sth->execute( $bornum, $itemno ); |
3301 |
$sth->execute( $bornum, $itemno ); |
| 3158 |
my $data = $sth->fetchrow_hashref; |
3302 |
my $data = $sth->fetchrow_hashref; |
| 3159 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
3303 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
|
|
3304 |
$unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'}; |
| 3160 |
# $item and $borrower should be calculated |
3305 |
# $item and $borrower should be calculated |
| 3161 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
3306 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
| 3162 |
|
3307 |
|
| 3163 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3308 |
my $rules = Koha::CirculationRules->get_effective_rules( |
| 3164 |
{ |
3309 |
{ |
| 3165 |
categorycode => $patron->categorycode, |
3310 |
categorycode => $patron->categorycode, |
| 3166 |
itemtype => $item->effective_itemtype, |
3311 |
itemtype => $item->effective_itemtype, |
| 3167 |
branchcode => $branchcode, |
3312 |
branchcode => $branchcode, |
| 3168 |
rule_name => 'renewalsallowed', |
3313 |
rules => [ 'renewalsallowed', 'unseen_renewals_allowed' ] |
| 3169 |
} |
3314 |
} |
| 3170 |
); |
3315 |
); |
| 3171 |
|
3316 |
$renewsallowed = $rules ? $rules->{renewalsallowed} : 0; |
| 3172 |
$renewsallowed = $rule ? $rule->rule_value : 0; |
3317 |
$unseenallowed = $rules->{unseen_renewals_allowed} ? |
|
|
3318 |
$rules->{unseen_renewals_allowed} : |
| 3319 |
0; |
| 3173 |
$renewsleft = $renewsallowed - $renewcount; |
3320 |
$renewsleft = $renewsallowed - $renewcount; |
|
|
3321 |
$unseenleft = $unseenallowed - $unseencount; |
| 3174 |
if($renewsleft < 0){ $renewsleft = 0; } |
3322 |
if($renewsleft < 0){ $renewsleft = 0; } |
| 3175 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
3323 |
if($unseenleft < 0){ $unseenleft = 0; } |
|
|
3324 |
return ( |
| 3325 |
$renewcount, |
| 3326 |
$renewsallowed, |
| 3327 |
$renewsleft, |
| 3328 |
$unseencount, |
| 3329 |
$unseenallowed, |
| 3330 |
$unseenleft |
| 3331 |
); |
| 3176 |
} |
3332 |
} |
| 3177 |
|
3333 |
|
| 3178 |
=head2 GetSoonestRenewDate |
3334 |
=head2 GetSoonestRenewDate |