|
Lines 2724-2729
sub CanBookBeRenewed {
Link Here
|
| 2724 |
'no_auto_renewal_after_hard_limit', |
2724 |
'no_auto_renewal_after_hard_limit', |
| 2725 |
'lengthunit', |
2725 |
'lengthunit', |
| 2726 |
'norenewalbefore', |
2726 |
'norenewalbefore', |
|
|
2727 |
'unseen_renewals_allowed' |
| 2727 |
] |
2728 |
] |
| 2728 |
} |
2729 |
} |
| 2729 |
); |
2730 |
); |
|
Lines 2887-2898
sub CanBookBeRenewed {
Link Here
|
| 2887 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
2888 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
| 2888 |
return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed |
2889 |
return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed |
| 2889 |
|
2890 |
|
|
|
2891 |
return ( 1, undef ) if $override_limit; |
| 2892 |
|
| 2893 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
| 2894 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
| 2895 |
{ |
| 2896 |
categorycode => $patron->categorycode, |
| 2897 |
itemtype => $item->effective_itemtype, |
| 2898 |
branchcode => $branchcode, |
| 2899 |
rules => [ |
| 2900 |
'renewalsallowed', |
| 2901 |
'no_auto_renewal_after', |
| 2902 |
'no_auto_renewal_after_hard_limit', |
| 2903 |
'lengthunit', |
| 2904 |
'norenewalbefore', |
| 2905 |
'unseen_renewals_allowed' |
| 2906 |
] |
| 2907 |
} |
| 2908 |
); |
| 2909 |
|
| 2910 |
return ( 0, "too_many" ) |
| 2911 |
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; |
| 2912 |
|
| 2913 |
return ( 0, "too_unseen" ) |
| 2914 |
if C4::Context->preference('UnseenRenewals') && |
| 2915 |
$issuing_rule->{unseen_renewals_allowed} && |
| 2916 |
$issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; |
| 2917 |
|
| 2918 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
| 2919 |
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); |
| 2920 |
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? |
| 2921 |
my $restricted = $patron->is_debarred; |
| 2922 |
my $hasoverdues = $patron->has_overdues; |
| 2923 |
|
| 2924 |
if ( $restricted and $restrictionblockrenewing ) { |
| 2925 |
return ( 0, 'restriction'); |
| 2926 |
} elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { |
| 2927 |
return ( 0, 'overdue'); |
| 2928 |
} |
| 2929 |
|
| 2930 |
if ( $issue->auto_renew ) { |
| 2931 |
|
| 2932 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
| 2933 |
return ( 0, 'auto_account_expired' ); |
| 2934 |
} |
| 2935 |
|
| 2936 |
if ( defined $issuing_rule->{no_auto_renewal_after} |
| 2937 |
and $issuing_rule->{no_auto_renewal_after} ne "" ) { |
| 2938 |
# Get issue_date and add no_auto_renewal_after |
| 2939 |
# If this is greater than today, it's too late for renewal. |
| 2940 |
my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); |
| 2941 |
$maximum_renewal_date->add( |
| 2942 |
$issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after} |
| 2943 |
); |
| 2944 |
my $now = dt_from_string; |
| 2945 |
if ( $now >= $maximum_renewal_date ) { |
| 2946 |
return ( 0, "auto_too_late" ); |
| 2947 |
} |
| 2948 |
} |
| 2949 |
if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit} |
| 2950 |
and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) { |
| 2951 |
# If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal |
| 2952 |
if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) { |
| 2953 |
return ( 0, "auto_too_late" ); |
| 2954 |
} |
| 2955 |
} |
| 2956 |
|
| 2957 |
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { |
| 2958 |
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); |
| 2959 |
my $amountoutstanding = |
| 2960 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredit") |
| 2961 |
? $patron->account->balance |
| 2962 |
: $patron->account->outstanding_debits->total_outstanding; |
| 2963 |
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { |
| 2964 |
return ( 0, "auto_too_much_oweing" ); |
| 2965 |
} |
| 2966 |
} |
| 2967 |
} |
| 2968 |
|
| 2969 |
if ( defined $issuing_rule->{norenewalbefore} |
| 2970 |
and $issuing_rule->{norenewalbefore} ne "" ) |
| 2971 |
{ |
| 2972 |
|
| 2973 |
# Calculate soonest renewal by subtracting 'No renewal before' from due date |
| 2974 |
my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( |
| 2975 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
| 2976 |
|
| 2977 |
# Depending on syspref reset the exact time, only check the date |
| 2978 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
| 2979 |
and $issuing_rule->{lengthunit} eq 'days' ) |
| 2980 |
{ |
| 2981 |
$soonestrenewal->truncate( to => 'day' ); |
| 2982 |
} |
| 2983 |
|
| 2984 |
if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) |
| 2985 |
{ |
| 2986 |
return ( 0, "auto_too_soon" ) if $issue->auto_renew; |
| 2987 |
return ( 0, "too_soon" ); |
| 2988 |
} |
| 2989 |
elsif ( $issue->auto_renew ) { |
| 2990 |
return ( 0, "auto_renew" ); |
| 2991 |
} |
| 2992 |
} |
| 2993 |
|
| 2994 |
# Fallback for automatic renewals: |
| 2995 |
# If norenewalbefore is undef, don't renew before due date. |
| 2996 |
if ( $issue->auto_renew ) { |
| 2997 |
my $now = dt_from_string; |
| 2998 |
return ( 0, "auto_renew" ) |
| 2999 |
if $now >= dt_from_string( $issue->date_due, 'sql' ); |
| 3000 |
return ( 0, "auto_too_soon" ); |
| 3001 |
} |
| 3002 |
|
| 2890 |
return ( 1, undef ); |
3003 |
return ( 1, undef ); |
| 2891 |
} |
3004 |
} |
| 2892 |
|
3005 |
|
| 2893 |
=head2 AddRenewal |
3006 |
=head2 AddRenewal |
| 2894 |
|
3007 |
|
| 2895 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate]); |
3008 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate], [$seen]); |
| 2896 |
|
3009 |
|
| 2897 |
Renews a loan. |
3010 |
Renews a loan. |
| 2898 |
|
3011 |
|
|
Lines 2917-2922
syspref)
Link Here
|
| 2917 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
3030 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
| 2918 |
from the book's item type. |
3031 |
from the book's item type. |
| 2919 |
|
3032 |
|
|
|
3033 |
C<$seen> is a boolean flag indicating if the item was seen or not during the renewal. This |
| 3034 |
informs the incrementing of the unseen_renewals column. If this flag is not supplied, we |
| 3035 |
fallback to a true value |
| 3036 |
|
| 2920 |
=cut |
3037 |
=cut |
| 2921 |
|
3038 |
|
| 2922 |
sub AddRenewal { |
3039 |
sub AddRenewal { |
|
Lines 2926-2931
sub AddRenewal {
Link Here
|
| 2926 |
my $datedue = shift; |
3043 |
my $datedue = shift; |
| 2927 |
my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz); |
3044 |
my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz); |
| 2928 |
my $skipfinecalc = shift; |
3045 |
my $skipfinecalc = shift; |
|
|
3046 |
my $seen = shift; |
| 3047 |
|
| 3048 |
# Fallback on a 'seen' renewal |
| 3049 |
$seen = defined $seen && $seen == 0 ? 0 : 1; |
| 2929 |
|
3050 |
|
| 2930 |
my $item_object = Koha::Items->find($itemnumber) or return; |
3051 |
my $item_object = Koha::Items->find($itemnumber) or return; |
| 2931 |
my $biblio = $item_object->biblio; |
3052 |
my $biblio = $item_object->biblio; |
|
Lines 2978-2992
sub AddRenewal {
Link Here
|
| 2978 |
} |
3099 |
} |
| 2979 |
); |
3100 |
); |
| 2980 |
|
3101 |
|
|
|
3102 |
# Increment the unseen renewals, if appropriate |
| 3103 |
# We only do so if the syspref is enabled and |
| 3104 |
# a maximum value has been set in the circ rules |
| 3105 |
my $unseen_renewals = $issue->unseen_renewals; |
| 3106 |
if (C4::Context->preference('UnseenRenewals')) { |
| 3107 |
my $rule = Koha::CirculationRules->get_effective_rule( |
| 3108 |
{ categorycode => $patron->categorycode, |
| 3109 |
itemtype => $item_object->effective_itemtype, |
| 3110 |
branchcode => $circ_library->branchcode, |
| 3111 |
rule_name => 'unseen_renewals_allowed' |
| 3112 |
} |
| 3113 |
); |
| 3114 |
if (!$seen && $rule && $rule->rule_value) { |
| 3115 |
$unseen_renewals++; |
| 3116 |
} else { |
| 3117 |
# If the renewal is seen, unseen should revert to 0 |
| 3118 |
$unseen_renewals = 0; |
| 3119 |
} |
| 3120 |
} |
| 3121 |
|
| 2981 |
# Update the issues record to have the new due date, and a new count |
3122 |
# Update the issues record to have the new due date, and a new count |
| 2982 |
# of how many times it has been renewed. |
3123 |
# of how many times it has been renewed. |
| 2983 |
my $renews = ( $issue->renewals || 0 ) + 1; |
3124 |
my $renews = ( $issue->renewals || 0 ) + 1; |
| 2984 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
3125 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? |
| 2985 |
WHERE borrowernumber=? |
3126 |
WHERE borrowernumber=? |
| 2986 |
AND itemnumber=?" |
3127 |
AND itemnumber=?" |
| 2987 |
); |
3128 |
); |
| 2988 |
|
3129 |
|
| 2989 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
3130 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $borrowernumber, $itemnumber ); |
| 2990 |
|
3131 |
|
| 2991 |
# Update the renewal count on the item, and tell zebra to reindex |
3132 |
# Update the renewal count on the item, and tell zebra to reindex |
| 2992 |
$renews = ( $item_object->renewals || 0 ) + 1; |
3133 |
$renews = ( $item_object->renewals || 0 ) + 1; |
|
Lines 3068-3075
sub GetRenewCount {
Link Here
|
| 3068 |
my ( $bornum, $itemno ) = @_; |
3209 |
my ( $bornum, $itemno ) = @_; |
| 3069 |
my $dbh = C4::Context->dbh; |
3210 |
my $dbh = C4::Context->dbh; |
| 3070 |
my $renewcount = 0; |
3211 |
my $renewcount = 0; |
|
|
3212 |
my $unseencount = 0; |
| 3071 |
my $renewsallowed = 0; |
3213 |
my $renewsallowed = 0; |
|
|
3214 |
my $unseenallowed = 0; |
| 3072 |
my $renewsleft = 0; |
3215 |
my $renewsleft = 0; |
|
|
3216 |
my $unseenleft = 0; |
| 3073 |
|
3217 |
|
| 3074 |
my $patron = Koha::Patrons->find( $bornum ); |
3218 |
my $patron = Koha::Patrons->find( $bornum ); |
| 3075 |
my $item = Koha::Items->find($itemno); |
3219 |
my $item = Koha::Items->find($itemno); |
|
Lines 3088-3109
sub GetRenewCount {
Link Here
|
| 3088 |
$sth->execute( $bornum, $itemno ); |
3232 |
$sth->execute( $bornum, $itemno ); |
| 3089 |
my $data = $sth->fetchrow_hashref; |
3233 |
my $data = $sth->fetchrow_hashref; |
| 3090 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
3234 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
|
|
3235 |
$unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'}; |
| 3091 |
# $item and $borrower should be calculated |
3236 |
# $item and $borrower should be calculated |
| 3092 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
3237 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
| 3093 |
|
3238 |
|
| 3094 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3239 |
my $rules = Koha::CirculationRules->get_effective_rules( |
| 3095 |
{ |
3240 |
{ |
| 3096 |
categorycode => $patron->categorycode, |
3241 |
categorycode => $patron->categorycode, |
| 3097 |
itemtype => $item->effective_itemtype, |
3242 |
itemtype => $item->effective_itemtype, |
| 3098 |
branchcode => $branchcode, |
3243 |
branchcode => $branchcode, |
| 3099 |
rule_name => 'renewalsallowed', |
3244 |
rules => [ 'renewalsallowed', 'unseen_renewals_allowed' ] |
| 3100 |
} |
3245 |
} |
| 3101 |
); |
3246 |
); |
| 3102 |
|
3247 |
$renewsallowed = $rules ? $rules->{renewalsallowed} : 0; |
| 3103 |
$renewsallowed = $rule ? $rule->rule_value : 0; |
3248 |
$unseenallowed = $rules->{unseen_renewals_allowed} ? |
|
|
3249 |
$rules->{unseen_renewals_allowed} : |
| 3250 |
0; |
| 3104 |
$renewsleft = $renewsallowed - $renewcount; |
3251 |
$renewsleft = $renewsallowed - $renewcount; |
|
|
3252 |
$unseenleft = $unseenallowed - $unseencount; |
| 3105 |
if($renewsleft < 0){ $renewsleft = 0; } |
3253 |
if($renewsleft < 0){ $renewsleft = 0; } |
| 3106 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
3254 |
if($unseenleft < 0){ $unseenleft = 0; } |
|
|
3255 |
return ( |
| 3256 |
$renewcount, |
| 3257 |
$renewsallowed, |
| 3258 |
$renewsleft, |
| 3259 |
$unseencount, |
| 3260 |
$unseenallowed, |
| 3261 |
$unseenleft |
| 3262 |
); |
| 3107 |
} |
3263 |
} |
| 3108 |
|
3264 |
|
| 3109 |
=head2 GetSoonestRenewDate |
3265 |
=head2 GetSoonestRenewDate |