Lines 2701-2706
sub CanBookBeRenewed {
Link Here
|
2701 |
'no_auto_renewal_after_hard_limit', |
2701 |
'no_auto_renewal_after_hard_limit', |
2702 |
'lengthunit', |
2702 |
'lengthunit', |
2703 |
'norenewalbefore', |
2703 |
'norenewalbefore', |
|
|
2704 |
'unseen_renewals_allowed' |
2704 |
] |
2705 |
] |
2705 |
} |
2706 |
} |
2706 |
); |
2707 |
); |
Lines 2879-2890
sub CanBookBeRenewed {
Link Here
|
2879 |
|
2880 |
|
2880 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed |
2881 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed |
2881 |
|
2882 |
|
|
|
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 > DateTime->now( time_zone => C4::Context->tz() ) ) |
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 |
|
2882 |
return ( 1, undef ); |
2995 |
return ( 1, undef ); |
2883 |
} |
2996 |
} |
2884 |
|
2997 |
|
2885 |
=head2 AddRenewal |
2998 |
=head2 AddRenewal |
2886 |
|
2999 |
|
2887 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate]); |
3000 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate], [$seen]); |
2888 |
|
3001 |
|
2889 |
Renews a loan. |
3002 |
Renews a loan. |
2890 |
|
3003 |
|
Lines 2909-2914
syspref)
Link Here
|
2909 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
3022 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
2910 |
from the book's item type. |
3023 |
from the book's item type. |
2911 |
|
3024 |
|
|
|
3025 |
C<$seen> is a boolean flag indicating if the item was seen or not during the renewal. This |
3026 |
informs the incrementing of the unseen_renewals column. If this flag is not supplied, we |
3027 |
fallback to a true value |
3028 |
|
2912 |
=cut |
3029 |
=cut |
2913 |
|
3030 |
|
2914 |
sub AddRenewal { |
3031 |
sub AddRenewal { |
Lines 2918-2923
sub AddRenewal {
Link Here
|
2918 |
my $datedue = shift; |
3035 |
my $datedue = shift; |
2919 |
my $lastreneweddate = shift || dt_from_string(); |
3036 |
my $lastreneweddate = shift || dt_from_string(); |
2920 |
my $skipfinecalc = shift; |
3037 |
my $skipfinecalc = shift; |
|
|
3038 |
my $seen = shift; |
3039 |
|
3040 |
# Fallback on a 'seen' renewal |
3041 |
$seen = defined $seen && $seen == 0 ? 0 : 1; |
2921 |
|
3042 |
|
2922 |
my $item_object = Koha::Items->find($itemnumber) or return; |
3043 |
my $item_object = Koha::Items->find($itemnumber) or return; |
2923 |
my $biblio = $item_object->biblio; |
3044 |
my $biblio = $item_object->biblio; |
Lines 2970-2984
sub AddRenewal {
Link Here
|
2970 |
} |
3091 |
} |
2971 |
); |
3092 |
); |
2972 |
|
3093 |
|
|
|
3094 |
# Increment the unseen renewals, if appropriate |
3095 |
# We only do so if the syspref is enabled and |
3096 |
# a maximum value has been set in the circ rules |
3097 |
my $unseen_renewals = $issue->unseen_renewals; |
3098 |
if (C4::Context->preference('UnseenRenewals')) { |
3099 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3100 |
{ categorycode => $patron->categorycode, |
3101 |
itemtype => $item_object->effective_itemtype, |
3102 |
branchcode => $circ_library->branchcode, |
3103 |
rule_name => 'unseen_renewals_allowed' |
3104 |
} |
3105 |
); |
3106 |
if (!$seen && $rule && $rule->rule_value) { |
3107 |
$unseen_renewals++; |
3108 |
} else { |
3109 |
# If the renewal is seen, unseen should revert to 0 |
3110 |
$unseen_renewals = 0; |
3111 |
} |
3112 |
} |
3113 |
|
2973 |
# Update the issues record to have the new due date, and a new count |
3114 |
# Update the issues record to have the new due date, and a new count |
2974 |
# of how many times it has been renewed. |
3115 |
# of how many times it has been renewed. |
2975 |
my $renews = ( $issue->renewals || 0 ) + 1; |
3116 |
my $renews = ( $issue->renewals || 0 ) + 1; |
2976 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
3117 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? |
2977 |
WHERE borrowernumber=? |
3118 |
WHERE borrowernumber=? |
2978 |
AND itemnumber=?" |
3119 |
AND itemnumber=?" |
2979 |
); |
3120 |
); |
2980 |
|
3121 |
|
2981 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
3122 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $borrowernumber, $itemnumber ); |
2982 |
|
3123 |
|
2983 |
# Update the renewal count on the item, and tell zebra to reindex |
3124 |
# Update the renewal count on the item, and tell zebra to reindex |
2984 |
$renews = ( $item_object->renewals || 0 ) + 1; |
3125 |
$renews = ( $item_object->renewals || 0 ) + 1; |
Lines 3065-3072
sub GetRenewCount {
Link Here
|
3065 |
my ( $bornum, $itemno ) = @_; |
3206 |
my ( $bornum, $itemno ) = @_; |
3066 |
my $dbh = C4::Context->dbh; |
3207 |
my $dbh = C4::Context->dbh; |
3067 |
my $renewcount = 0; |
3208 |
my $renewcount = 0; |
|
|
3209 |
my $unseencount = 0; |
3068 |
my $renewsallowed = 0; |
3210 |
my $renewsallowed = 0; |
|
|
3211 |
my $unseenallowed = 0; |
3069 |
my $renewsleft = 0; |
3212 |
my $renewsleft = 0; |
|
|
3213 |
my $unseenleft = 0; |
3070 |
|
3214 |
|
3071 |
my $patron = Koha::Patrons->find( $bornum ); |
3215 |
my $patron = Koha::Patrons->find( $bornum ); |
3072 |
my $item = Koha::Items->find($itemno); |
3216 |
my $item = Koha::Items->find($itemno); |
Lines 3085-3106
sub GetRenewCount {
Link Here
|
3085 |
$sth->execute( $bornum, $itemno ); |
3229 |
$sth->execute( $bornum, $itemno ); |
3086 |
my $data = $sth->fetchrow_hashref; |
3230 |
my $data = $sth->fetchrow_hashref; |
3087 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
3231 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
|
|
3232 |
$unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'}; |
3088 |
# $item and $borrower should be calculated |
3233 |
# $item and $borrower should be calculated |
3089 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
3234 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
3090 |
|
3235 |
|
3091 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3236 |
my $rules = Koha::CirculationRules->get_effective_rules( |
3092 |
{ |
3237 |
{ |
3093 |
categorycode => $patron->categorycode, |
3238 |
categorycode => $patron->categorycode, |
3094 |
itemtype => $item->effective_itemtype, |
3239 |
itemtype => $item->effective_itemtype, |
3095 |
branchcode => $branchcode, |
3240 |
branchcode => $branchcode, |
3096 |
rule_name => 'renewalsallowed', |
3241 |
rules => [ 'renewalsallowed', 'unseen_renewals_allowed' ] |
3097 |
} |
3242 |
} |
3098 |
); |
3243 |
); |
3099 |
|
3244 |
$renewsallowed = $rules ? $rules->{renewalsallowed} : 0; |
3100 |
$renewsallowed = $rule ? $rule->rule_value : 0; |
3245 |
$unseenallowed = $rules->{unseen_renewals_allowed} ? |
|
|
3246 |
$rules->{unseen_renewals_allowed} : |
3247 |
0; |
3101 |
$renewsleft = $renewsallowed - $renewcount; |
3248 |
$renewsleft = $renewsallowed - $renewcount; |
|
|
3249 |
$unseenleft = $unseenallowed - $unseencount; |
3102 |
if($renewsleft < 0){ $renewsleft = 0; } |
3250 |
if($renewsleft < 0){ $renewsleft = 0; } |
3103 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
3251 |
if($unseenleft < 0){ $unseenleft = 0; } |
|
|
3252 |
return ( |
3253 |
$renewcount, |
3254 |
$renewsallowed, |
3255 |
$renewsleft, |
3256 |
$unseencount, |
3257 |
$unseenallowed, |
3258 |
$unseenleft |
3259 |
); |
3104 |
} |
3260 |
} |
3105 |
|
3261 |
|
3106 |
=head2 GetSoonestRenewDate |
3262 |
=head2 GetSoonestRenewDate |