Lines 2716-2721
sub CanBookBeRenewed {
Link Here
|
2716 |
'no_auto_renewal_after_hard_limit', |
2716 |
'no_auto_renewal_after_hard_limit', |
2717 |
'lengthunit', |
2717 |
'lengthunit', |
2718 |
'norenewalbefore', |
2718 |
'norenewalbefore', |
|
|
2719 |
'unseen_renewals_allowed' |
2719 |
] |
2720 |
] |
2720 |
} |
2721 |
} |
2721 |
); |
2722 |
); |
Lines 2879-2890
sub CanBookBeRenewed {
Link Here
|
2879 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
2880 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
2880 |
return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed |
2881 |
return ( 0, "auto_renew" ) if $auto_renew && !$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 2904-2909
this parameter is not supplied, lastreneweddate is set to the current date.
Link Here
|
2904 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
3017 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
2905 |
from the book's item type. |
3018 |
from the book's item type. |
2906 |
|
3019 |
|
|
|
3020 |
C<$seen> is a boolean flag indicating if the item was seen or not during the renewal. This |
3021 |
informs the incrementing of the unseen_renewals column. If this flag is not supplied, we |
3022 |
fallback to a true value |
3023 |
|
2907 |
=cut |
3024 |
=cut |
2908 |
|
3025 |
|
2909 |
sub AddRenewal { |
3026 |
sub AddRenewal { |
Lines 2912-2917
sub AddRenewal {
Link Here
|
2912 |
my $branch = shift; |
3029 |
my $branch = shift; |
2913 |
my $datedue = shift; |
3030 |
my $datedue = shift; |
2914 |
my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz); |
3031 |
my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz); |
|
|
3032 |
my $seen = shift; |
3033 |
|
3034 |
# Fallback on a 'seen' renewal |
3035 |
$seen = defined $seen && $seen == 0 ? 0 : 1; |
2915 |
|
3036 |
|
2916 |
my $item_object = Koha::Items->find($itemnumber) or return; |
3037 |
my $item_object = Koha::Items->find($itemnumber) or return; |
2917 |
my $biblio = $item_object->biblio; |
3038 |
my $biblio = $item_object->biblio; |
Lines 2964-2978
sub AddRenewal {
Link Here
|
2964 |
} |
3085 |
} |
2965 |
); |
3086 |
); |
2966 |
|
3087 |
|
|
|
3088 |
# Increment the unseen renewals, if appropriate |
3089 |
# We only do so if the syspref is enabled and |
3090 |
# a maximum value has been set in the circ rules |
3091 |
my $unseen_renewals = $issue->unseen_renewals; |
3092 |
if (C4::Context->preference('UnseenRenewals')) { |
3093 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3094 |
{ categorycode => $patron->categorycode, |
3095 |
itemtype => $item_object->effective_itemtype, |
3096 |
branchcode => $circ_library->branchcode, |
3097 |
rule_name => 'unseen_renewals_allowed' |
3098 |
} |
3099 |
); |
3100 |
if (!$seen && $rule && $rule->rule_value) { |
3101 |
$unseen_renewals++; |
3102 |
} else { |
3103 |
# If the renewal is seen, unseen should revert to 0 |
3104 |
$unseen_renewals = 0; |
3105 |
} |
3106 |
} |
3107 |
|
2967 |
# Update the issues record to have the new due date, and a new count |
3108 |
# Update the issues record to have the new due date, and a new count |
2968 |
# of how many times it has been renewed. |
3109 |
# of how many times it has been renewed. |
2969 |
my $renews = ( $issue->renewals || 0 ) + 1; |
3110 |
my $renews = ( $issue->renewals || 0 ) + 1; |
2970 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
3111 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? |
2971 |
WHERE borrowernumber=? |
3112 |
WHERE borrowernumber=? |
2972 |
AND itemnumber=?" |
3113 |
AND itemnumber=?" |
2973 |
); |
3114 |
); |
2974 |
|
3115 |
|
2975 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
3116 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $borrowernumber, $itemnumber ); |
2976 |
|
3117 |
|
2977 |
# Update the renewal count on the item, and tell zebra to reindex |
3118 |
# Update the renewal count on the item, and tell zebra to reindex |
2978 |
$renews = ( $item_object->renewals || 0 ) + 1; |
3119 |
$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 |