|
Lines 2671-2676
sub CanBookBeRenewed {
Link Here
|
| 2671 |
'no_auto_renewal_after_hard_limit', |
2671 |
'no_auto_renewal_after_hard_limit', |
| 2672 |
'lengthunit', |
2672 |
'lengthunit', |
| 2673 |
'norenewalbefore', |
2673 |
'norenewalbefore', |
|
|
2674 |
'unseen_renewals_allowed' |
| 2674 |
] |
2675 |
] |
| 2675 |
} |
2676 |
} |
| 2676 |
); |
2677 |
); |
|
Lines 2849-2860
sub CanBookBeRenewed {
Link Here
|
| 2849 |
|
2850 |
|
| 2850 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed |
2851 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed |
| 2851 |
|
2852 |
|
|
|
2853 |
return ( 1, undef ) if $override_limit; |
| 2854 |
|
| 2855 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
| 2856 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
| 2857 |
{ |
| 2858 |
categorycode => $patron->categorycode, |
| 2859 |
itemtype => $item->effective_itemtype, |
| 2860 |
branchcode => $branchcode, |
| 2861 |
rules => [ |
| 2862 |
'renewalsallowed', |
| 2863 |
'no_auto_renewal_after', |
| 2864 |
'no_auto_renewal_after_hard_limit', |
| 2865 |
'lengthunit', |
| 2866 |
'norenewalbefore', |
| 2867 |
'unseen_renewals_allowed' |
| 2868 |
] |
| 2869 |
} |
| 2870 |
); |
| 2871 |
|
| 2872 |
return ( 0, "too_many" ) |
| 2873 |
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; |
| 2874 |
|
| 2875 |
return ( 0, "too_unseen" ) |
| 2876 |
if C4::Context->preference('UnseenRenewals') && |
| 2877 |
$issuing_rule->{unseen_renewals_allowed} && |
| 2878 |
$issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; |
| 2879 |
|
| 2880 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
| 2881 |
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); |
| 2882 |
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? |
| 2883 |
my $restricted = $patron->is_debarred; |
| 2884 |
my $hasoverdues = $patron->has_overdues; |
| 2885 |
|
| 2886 |
if ( $restricted and $restrictionblockrenewing ) { |
| 2887 |
return ( 0, 'restriction'); |
| 2888 |
} elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { |
| 2889 |
return ( 0, 'overdue'); |
| 2890 |
} |
| 2891 |
|
| 2892 |
if ( $issue->auto_renew ) { |
| 2893 |
|
| 2894 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
| 2895 |
return ( 0, 'auto_account_expired' ); |
| 2896 |
} |
| 2897 |
|
| 2898 |
if ( defined $issuing_rule->{no_auto_renewal_after} |
| 2899 |
and $issuing_rule->{no_auto_renewal_after} ne "" ) { |
| 2900 |
# Get issue_date and add no_auto_renewal_after |
| 2901 |
# If this is greater than today, it's too late for renewal. |
| 2902 |
my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); |
| 2903 |
$maximum_renewal_date->add( |
| 2904 |
$issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after} |
| 2905 |
); |
| 2906 |
my $now = dt_from_string; |
| 2907 |
if ( $now >= $maximum_renewal_date ) { |
| 2908 |
return ( 0, "auto_too_late" ); |
| 2909 |
} |
| 2910 |
} |
| 2911 |
if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit} |
| 2912 |
and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) { |
| 2913 |
# If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal |
| 2914 |
if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) { |
| 2915 |
return ( 0, "auto_too_late" ); |
| 2916 |
} |
| 2917 |
} |
| 2918 |
|
| 2919 |
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { |
| 2920 |
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); |
| 2921 |
my $amountoutstanding = |
| 2922 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredit") |
| 2923 |
? $patron->account->balance |
| 2924 |
: $patron->account->outstanding_debits->total_outstanding; |
| 2925 |
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { |
| 2926 |
return ( 0, "auto_too_much_oweing" ); |
| 2927 |
} |
| 2928 |
} |
| 2929 |
} |
| 2930 |
|
| 2931 |
if ( defined $issuing_rule->{norenewalbefore} |
| 2932 |
and $issuing_rule->{norenewalbefore} ne "" ) |
| 2933 |
{ |
| 2934 |
|
| 2935 |
# Calculate soonest renewal by subtracting 'No renewal before' from due date |
| 2936 |
my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( |
| 2937 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
| 2938 |
|
| 2939 |
# Depending on syspref reset the exact time, only check the date |
| 2940 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
| 2941 |
and $issuing_rule->{lengthunit} eq 'days' ) |
| 2942 |
{ |
| 2943 |
$soonestrenewal->truncate( to => 'day' ); |
| 2944 |
} |
| 2945 |
|
| 2946 |
if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) |
| 2947 |
{ |
| 2948 |
return ( 0, "auto_too_soon" ) if $issue->auto_renew; |
| 2949 |
return ( 0, "too_soon" ); |
| 2950 |
} |
| 2951 |
elsif ( $issue->auto_renew ) { |
| 2952 |
return ( 0, "auto_renew" ); |
| 2953 |
} |
| 2954 |
} |
| 2955 |
|
| 2956 |
# Fallback for automatic renewals: |
| 2957 |
# If norenewalbefore is undef, don't renew before due date. |
| 2958 |
if ( $issue->auto_renew ) { |
| 2959 |
my $now = dt_from_string; |
| 2960 |
return ( 0, "auto_renew" ) |
| 2961 |
if $now >= dt_from_string( $issue->date_due, 'sql' ); |
| 2962 |
return ( 0, "auto_too_soon" ); |
| 2963 |
} |
| 2964 |
|
| 2852 |
return ( 1, undef ); |
2965 |
return ( 1, undef ); |
| 2853 |
} |
2966 |
} |
| 2854 |
|
2967 |
|
| 2855 |
=head2 AddRenewal |
2968 |
=head2 AddRenewal |
| 2856 |
|
2969 |
|
| 2857 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate]); |
2970 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate], [$seen]); |
| 2858 |
|
2971 |
|
| 2859 |
Renews a loan. |
2972 |
Renews a loan. |
| 2860 |
|
2973 |
|
|
Lines 2879-2884
syspref)
Link Here
|
| 2879 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
2992 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
| 2880 |
from the book's item type. |
2993 |
from the book's item type. |
| 2881 |
|
2994 |
|
|
|
2995 |
C<$seen> is a boolean flag indicating if the item was seen or not during the renewal. This |
| 2996 |
informs the incrementing of the unseen_renewals column. If this flag is not supplied, we |
| 2997 |
fallback to a true value |
| 2998 |
|
| 2882 |
=cut |
2999 |
=cut |
| 2883 |
|
3000 |
|
| 2884 |
sub AddRenewal { |
3001 |
sub AddRenewal { |
|
Lines 2888-2893
sub AddRenewal {
Link Here
|
| 2888 |
my $datedue = shift; |
3005 |
my $datedue = shift; |
| 2889 |
my $lastreneweddate = shift || dt_from_string(); |
3006 |
my $lastreneweddate = shift || dt_from_string(); |
| 2890 |
my $skipfinecalc = shift; |
3007 |
my $skipfinecalc = shift; |
|
|
3008 |
my $seen = shift; |
| 3009 |
|
| 3010 |
# Fallback on a 'seen' renewal |
| 3011 |
$seen = defined $seen && $seen == 0 ? 0 : 1; |
| 2891 |
|
3012 |
|
| 2892 |
my $item_object = Koha::Items->find($itemnumber) or return; |
3013 |
my $item_object = Koha::Items->find($itemnumber) or return; |
| 2893 |
my $biblio = $item_object->biblio; |
3014 |
my $biblio = $item_object->biblio; |
|
Lines 2940-2954
sub AddRenewal {
Link Here
|
| 2940 |
} |
3061 |
} |
| 2941 |
); |
3062 |
); |
| 2942 |
|
3063 |
|
|
|
3064 |
# Increment the unseen renewals, if appropriate |
| 3065 |
# We only do so if the syspref is enabled and |
| 3066 |
# a maximum value has been set in the circ rules |
| 3067 |
my $unseen_renewals = $issue->unseen_renewals; |
| 3068 |
if (C4::Context->preference('UnseenRenewals')) { |
| 3069 |
my $rule = Koha::CirculationRules->get_effective_rule( |
| 3070 |
{ categorycode => $patron->categorycode, |
| 3071 |
itemtype => $item_object->effective_itemtype, |
| 3072 |
branchcode => $circ_library->branchcode, |
| 3073 |
rule_name => 'unseen_renewals_allowed' |
| 3074 |
} |
| 3075 |
); |
| 3076 |
if (!$seen && $rule && $rule->rule_value) { |
| 3077 |
$unseen_renewals++; |
| 3078 |
} else { |
| 3079 |
# If the renewal is seen, unseen should revert to 0 |
| 3080 |
$unseen_renewals = 0; |
| 3081 |
} |
| 3082 |
} |
| 3083 |
|
| 2943 |
# Update the issues record to have the new due date, and a new count |
3084 |
# Update the issues record to have the new due date, and a new count |
| 2944 |
# of how many times it has been renewed. |
3085 |
# of how many times it has been renewed. |
| 2945 |
my $renews = ( $issue->renewals || 0 ) + 1; |
3086 |
my $renews = ( $issue->renewals || 0 ) + 1; |
| 2946 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
3087 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? |
| 2947 |
WHERE borrowernumber=? |
3088 |
WHERE borrowernumber=? |
| 2948 |
AND itemnumber=?" |
3089 |
AND itemnumber=?" |
| 2949 |
); |
3090 |
); |
| 2950 |
|
3091 |
|
| 2951 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
3092 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $borrowernumber, $itemnumber ); |
| 2952 |
|
3093 |
|
| 2953 |
# Update the renewal count on the item, and tell zebra to reindex |
3094 |
# Update the renewal count on the item, and tell zebra to reindex |
| 2954 |
$renews = ( $item_object->renewals || 0 ) + 1; |
3095 |
$renews = ( $item_object->renewals || 0 ) + 1; |
|
Lines 3035-3042
sub GetRenewCount {
Link Here
|
| 3035 |
my ( $bornum, $itemno ) = @_; |
3176 |
my ( $bornum, $itemno ) = @_; |
| 3036 |
my $dbh = C4::Context->dbh; |
3177 |
my $dbh = C4::Context->dbh; |
| 3037 |
my $renewcount = 0; |
3178 |
my $renewcount = 0; |
|
|
3179 |
my $unseencount = 0; |
| 3038 |
my $renewsallowed = 0; |
3180 |
my $renewsallowed = 0; |
|
|
3181 |
my $unseenallowed = 0; |
| 3039 |
my $renewsleft = 0; |
3182 |
my $renewsleft = 0; |
|
|
3183 |
my $unseenleft = 0; |
| 3040 |
|
3184 |
|
| 3041 |
my $patron = Koha::Patrons->find( $bornum ); |
3185 |
my $patron = Koha::Patrons->find( $bornum ); |
| 3042 |
my $item = Koha::Items->find($itemno); |
3186 |
my $item = Koha::Items->find($itemno); |
|
Lines 3055-3076
sub GetRenewCount {
Link Here
|
| 3055 |
$sth->execute( $bornum, $itemno ); |
3199 |
$sth->execute( $bornum, $itemno ); |
| 3056 |
my $data = $sth->fetchrow_hashref; |
3200 |
my $data = $sth->fetchrow_hashref; |
| 3057 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
3201 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
|
|
3202 |
$unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'}; |
| 3058 |
# $item and $borrower should be calculated |
3203 |
# $item and $borrower should be calculated |
| 3059 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
3204 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
| 3060 |
|
3205 |
|
| 3061 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3206 |
my $rules = Koha::CirculationRules->get_effective_rules( |
| 3062 |
{ |
3207 |
{ |
| 3063 |
categorycode => $patron->categorycode, |
3208 |
categorycode => $patron->categorycode, |
| 3064 |
itemtype => $item->effective_itemtype, |
3209 |
itemtype => $item->effective_itemtype, |
| 3065 |
branchcode => $branchcode, |
3210 |
branchcode => $branchcode, |
| 3066 |
rule_name => 'renewalsallowed', |
3211 |
rules => [ 'renewalsallowed', 'unseen_renewals_allowed' ] |
| 3067 |
} |
3212 |
} |
| 3068 |
); |
3213 |
); |
| 3069 |
|
3214 |
$renewsallowed = $rules ? $rules->{renewalsallowed} : 0; |
| 3070 |
$renewsallowed = $rule ? $rule->rule_value : 0; |
3215 |
$unseenallowed = $rules->{unseen_renewals_allowed} ? |
|
|
3216 |
$rules->{unseen_renewals_allowed} : |
| 3217 |
0; |
| 3071 |
$renewsleft = $renewsallowed - $renewcount; |
3218 |
$renewsleft = $renewsallowed - $renewcount; |
|
|
3219 |
$unseenleft = $unseenallowed - $unseencount; |
| 3072 |
if($renewsleft < 0){ $renewsleft = 0; } |
3220 |
if($renewsleft < 0){ $renewsleft = 0; } |
| 3073 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
3221 |
if($unseenleft < 0){ $unseenleft = 0; } |
|
|
3222 |
return ( |
| 3223 |
$renewcount, |
| 3224 |
$renewsallowed, |
| 3225 |
$renewsleft, |
| 3226 |
$unseencount, |
| 3227 |
$unseenallowed, |
| 3228 |
$unseenleft |
| 3229 |
); |
| 3074 |
} |
3230 |
} |
| 3075 |
|
3231 |
|
| 3076 |
=head2 GetSoonestRenewDate |
3232 |
=head2 GetSoonestRenewDate |