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