|
Lines 2664-2669
sub CanBookBeRenewed {
Link Here
|
| 2664 |
'no_auto_renewal_after_hard_limit', |
2664 |
'no_auto_renewal_after_hard_limit', |
| 2665 |
'lengthunit', |
2665 |
'lengthunit', |
| 2666 |
'norenewalbefore', |
2666 |
'norenewalbefore', |
|
|
2667 |
'unseen_renewals_allowed' |
| 2667 |
] |
2668 |
] |
| 2668 |
} |
2669 |
} |
| 2669 |
); |
2670 |
); |
|
Lines 2836-2847
sub CanBookBeRenewed {
Link Here
|
| 2836 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
2837 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
| 2837 |
return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed |
2838 |
return ( 0, "auto_renew" ) if $auto_renew && !$override_limit; # 0 if auto-renewal should not succeed |
| 2838 |
|
2839 |
|
|
|
2840 |
return ( 1, undef ) if $override_limit; |
| 2841 |
|
| 2842 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
| 2843 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
| 2844 |
{ |
| 2845 |
categorycode => $patron->categorycode, |
| 2846 |
itemtype => $item->effective_itemtype, |
| 2847 |
branchcode => $branchcode, |
| 2848 |
rules => [ |
| 2849 |
'renewalsallowed', |
| 2850 |
'no_auto_renewal_after', |
| 2851 |
'no_auto_renewal_after_hard_limit', |
| 2852 |
'lengthunit', |
| 2853 |
'norenewalbefore', |
| 2854 |
'unseen_renewals_allowed' |
| 2855 |
] |
| 2856 |
} |
| 2857 |
); |
| 2858 |
|
| 2859 |
return ( 0, "too_many" ) |
| 2860 |
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; |
| 2861 |
|
| 2862 |
return ( 0, "too_unseen" ) |
| 2863 |
if C4::Context->preference('UnseenRenewals') && |
| 2864 |
$issuing_rule->{unseen_renewals_allowed} && |
| 2865 |
$issuing_rule->{unseen_renewals_allowed} <= $issue->unseen_renewals; |
| 2866 |
|
| 2867 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
| 2868 |
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); |
| 2869 |
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? |
| 2870 |
my $restricted = $patron->is_debarred; |
| 2871 |
my $hasoverdues = $patron->has_overdues; |
| 2872 |
|
| 2873 |
if ( $restricted and $restrictionblockrenewing ) { |
| 2874 |
return ( 0, 'restriction'); |
| 2875 |
} elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { |
| 2876 |
return ( 0, 'overdue'); |
| 2877 |
} |
| 2878 |
|
| 2879 |
if ( $issue->auto_renew ) { |
| 2880 |
|
| 2881 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
| 2882 |
return ( 0, 'auto_account_expired' ); |
| 2883 |
} |
| 2884 |
|
| 2885 |
if ( defined $issuing_rule->{no_auto_renewal_after} |
| 2886 |
and $issuing_rule->{no_auto_renewal_after} ne "" ) { |
| 2887 |
# Get issue_date and add no_auto_renewal_after |
| 2888 |
# If this is greater than today, it's too late for renewal. |
| 2889 |
my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); |
| 2890 |
$maximum_renewal_date->add( |
| 2891 |
$issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after} |
| 2892 |
); |
| 2893 |
my $now = dt_from_string; |
| 2894 |
if ( $now >= $maximum_renewal_date ) { |
| 2895 |
return ( 0, "auto_too_late" ); |
| 2896 |
} |
| 2897 |
} |
| 2898 |
if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit} |
| 2899 |
and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) { |
| 2900 |
# If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal |
| 2901 |
if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) { |
| 2902 |
return ( 0, "auto_too_late" ); |
| 2903 |
} |
| 2904 |
} |
| 2905 |
|
| 2906 |
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { |
| 2907 |
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); |
| 2908 |
my $amountoutstanding = |
| 2909 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredit") |
| 2910 |
? $patron->account->balance |
| 2911 |
: $patron->account->outstanding_debits->total_outstanding; |
| 2912 |
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { |
| 2913 |
return ( 0, "auto_too_much_oweing" ); |
| 2914 |
} |
| 2915 |
} |
| 2916 |
} |
| 2917 |
|
| 2918 |
if ( defined $issuing_rule->{norenewalbefore} |
| 2919 |
and $issuing_rule->{norenewalbefore} ne "" ) |
| 2920 |
{ |
| 2921 |
|
| 2922 |
# Calculate soonest renewal by subtracting 'No renewal before' from due date |
| 2923 |
my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( |
| 2924 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
| 2925 |
|
| 2926 |
# Depending on syspref reset the exact time, only check the date |
| 2927 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
| 2928 |
and $issuing_rule->{lengthunit} eq 'days' ) |
| 2929 |
{ |
| 2930 |
$soonestrenewal->truncate( to => 'day' ); |
| 2931 |
} |
| 2932 |
|
| 2933 |
if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) |
| 2934 |
{ |
| 2935 |
return ( 0, "auto_too_soon" ) if $issue->auto_renew; |
| 2936 |
return ( 0, "too_soon" ); |
| 2937 |
} |
| 2938 |
elsif ( $issue->auto_renew ) { |
| 2939 |
return ( 0, "auto_renew" ); |
| 2940 |
} |
| 2941 |
} |
| 2942 |
|
| 2943 |
# Fallback for automatic renewals: |
| 2944 |
# If norenewalbefore is undef, don't renew before due date. |
| 2945 |
if ( $issue->auto_renew ) { |
| 2946 |
my $now = dt_from_string; |
| 2947 |
return ( 0, "auto_renew" ) |
| 2948 |
if $now >= dt_from_string( $issue->date_due, 'sql' ); |
| 2949 |
return ( 0, "auto_too_soon" ); |
| 2950 |
} |
| 2951 |
|
| 2839 |
return ( 1, undef ); |
2952 |
return ( 1, undef ); |
| 2840 |
} |
2953 |
} |
| 2841 |
|
2954 |
|
| 2842 |
=head2 AddRenewal |
2955 |
=head2 AddRenewal |
| 2843 |
|
2956 |
|
| 2844 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate]); |
2957 |
&AddRenewal($borrowernumber, $itemnumber, $branch, [$datedue], [$lastreneweddate], [$seen]); |
| 2845 |
|
2958 |
|
| 2846 |
Renews a loan. |
2959 |
Renews a loan. |
| 2847 |
|
2960 |
|
|
Lines 2866-2871
syspref)
Link Here
|
| 2866 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
2979 |
If C<$datedue> is the empty string, C<&AddRenewal> will calculate the due date automatically |
| 2867 |
from the book's item type. |
2980 |
from the book's item type. |
| 2868 |
|
2981 |
|
|
|
2982 |
C<$seen> is a boolean flag indicating if the item was seen or not during the renewal. This |
| 2983 |
informs the incrementing of the unseen_renewals column. If this flag is not supplied, we |
| 2984 |
fallback to a true value |
| 2985 |
|
| 2869 |
=cut |
2986 |
=cut |
| 2870 |
|
2987 |
|
| 2871 |
sub AddRenewal { |
2988 |
sub AddRenewal { |
|
Lines 2875-2880
sub AddRenewal {
Link Here
|
| 2875 |
my $datedue = shift; |
2992 |
my $datedue = shift; |
| 2876 |
my $lastreneweddate = shift || dt_from_string(); |
2993 |
my $lastreneweddate = shift || dt_from_string(); |
| 2877 |
my $skipfinecalc = shift; |
2994 |
my $skipfinecalc = shift; |
|
|
2995 |
my $seen = shift; |
| 2996 |
|
| 2997 |
# Fallback on a 'seen' renewal |
| 2998 |
$seen = defined $seen && $seen == 0 ? 0 : 1; |
| 2878 |
|
2999 |
|
| 2879 |
my $item_object = Koha::Items->find($itemnumber) or return; |
3000 |
my $item_object = Koha::Items->find($itemnumber) or return; |
| 2880 |
my $biblio = $item_object->biblio; |
3001 |
my $biblio = $item_object->biblio; |
|
Lines 2927-2941
sub AddRenewal {
Link Here
|
| 2927 |
} |
3048 |
} |
| 2928 |
); |
3049 |
); |
| 2929 |
|
3050 |
|
|
|
3051 |
# Increment the unseen renewals, if appropriate |
| 3052 |
# We only do so if the syspref is enabled and |
| 3053 |
# a maximum value has been set in the circ rules |
| 3054 |
my $unseen_renewals = $issue->unseen_renewals; |
| 3055 |
if (C4::Context->preference('UnseenRenewals')) { |
| 3056 |
my $rule = Koha::CirculationRules->get_effective_rule( |
| 3057 |
{ categorycode => $patron->categorycode, |
| 3058 |
itemtype => $item_object->effective_itemtype, |
| 3059 |
branchcode => $circ_library->branchcode, |
| 3060 |
rule_name => 'unseen_renewals_allowed' |
| 3061 |
} |
| 3062 |
); |
| 3063 |
if (!$seen && $rule && $rule->rule_value) { |
| 3064 |
$unseen_renewals++; |
| 3065 |
} else { |
| 3066 |
# If the renewal is seen, unseen should revert to 0 |
| 3067 |
$unseen_renewals = 0; |
| 3068 |
} |
| 3069 |
} |
| 3070 |
|
| 2930 |
# Update the issues record to have the new due date, and a new count |
3071 |
# Update the issues record to have the new due date, and a new count |
| 2931 |
# of how many times it has been renewed. |
3072 |
# of how many times it has been renewed. |
| 2932 |
my $renews = ( $issue->renewals || 0 ) + 1; |
3073 |
my $renews = ( $issue->renewals || 0 ) + 1; |
| 2933 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
3074 |
my $sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, unseen_renewals = ?, lastreneweddate = ? |
| 2934 |
WHERE borrowernumber=? |
3075 |
WHERE borrowernumber=? |
| 2935 |
AND itemnumber=?" |
3076 |
AND itemnumber=?" |
| 2936 |
); |
3077 |
); |
| 2937 |
|
3078 |
|
| 2938 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
3079 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $unseen_renewals, $lastreneweddate, $borrowernumber, $itemnumber ); |
| 2939 |
|
3080 |
|
| 2940 |
# Update the renewal count on the item, and tell zebra to reindex |
3081 |
# Update the renewal count on the item, and tell zebra to reindex |
| 2941 |
$renews = ( $item_object->renewals || 0 ) + 1; |
3082 |
$renews = ( $item_object->renewals || 0 ) + 1; |
|
Lines 3022-3029
sub GetRenewCount {
Link Here
|
| 3022 |
my ( $bornum, $itemno ) = @_; |
3163 |
my ( $bornum, $itemno ) = @_; |
| 3023 |
my $dbh = C4::Context->dbh; |
3164 |
my $dbh = C4::Context->dbh; |
| 3024 |
my $renewcount = 0; |
3165 |
my $renewcount = 0; |
|
|
3166 |
my $unseencount = 0; |
| 3025 |
my $renewsallowed = 0; |
3167 |
my $renewsallowed = 0; |
|
|
3168 |
my $unseenallowed = 0; |
| 3026 |
my $renewsleft = 0; |
3169 |
my $renewsleft = 0; |
|
|
3170 |
my $unseenleft = 0; |
| 3027 |
|
3171 |
|
| 3028 |
my $patron = Koha::Patrons->find( $bornum ); |
3172 |
my $patron = Koha::Patrons->find( $bornum ); |
| 3029 |
my $item = Koha::Items->find($itemno); |
3173 |
my $item = Koha::Items->find($itemno); |
|
Lines 3042-3063
sub GetRenewCount {
Link Here
|
| 3042 |
$sth->execute( $bornum, $itemno ); |
3186 |
$sth->execute( $bornum, $itemno ); |
| 3043 |
my $data = $sth->fetchrow_hashref; |
3187 |
my $data = $sth->fetchrow_hashref; |
| 3044 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
3188 |
$renewcount = $data->{'renewals'} if $data->{'renewals'}; |
|
|
3189 |
$unseencount = $data->{'unseen_renewals'} if $data->{'unseen_renewals'}; |
| 3045 |
# $item and $borrower should be calculated |
3190 |
# $item and $borrower should be calculated |
| 3046 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
3191 |
my $branchcode = _GetCircControlBranch($item->unblessed, $patron->unblessed); |
| 3047 |
|
3192 |
|
| 3048 |
my $rule = Koha::CirculationRules->get_effective_rule( |
3193 |
my $rules = Koha::CirculationRules->get_effective_rules( |
| 3049 |
{ |
3194 |
{ |
| 3050 |
categorycode => $patron->categorycode, |
3195 |
categorycode => $patron->categorycode, |
| 3051 |
itemtype => $item->effective_itemtype, |
3196 |
itemtype => $item->effective_itemtype, |
| 3052 |
branchcode => $branchcode, |
3197 |
branchcode => $branchcode, |
| 3053 |
rule_name => 'renewalsallowed', |
3198 |
rules => [ 'renewalsallowed', 'unseen_renewals_allowed' ] |
| 3054 |
} |
3199 |
} |
| 3055 |
); |
3200 |
); |
| 3056 |
|
3201 |
$renewsallowed = $rules ? $rules->{renewalsallowed} : 0; |
| 3057 |
$renewsallowed = $rule ? $rule->rule_value : 0; |
3202 |
$unseenallowed = $rules->{unseen_renewals_allowed} ? |
|
|
3203 |
$rules->{unseen_renewals_allowed} : |
| 3204 |
0; |
| 3058 |
$renewsleft = $renewsallowed - $renewcount; |
3205 |
$renewsleft = $renewsallowed - $renewcount; |
|
|
3206 |
$unseenleft = $unseenallowed - $unseencount; |
| 3059 |
if($renewsleft < 0){ $renewsleft = 0; } |
3207 |
if($renewsleft < 0){ $renewsleft = 0; } |
| 3060 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
3208 |
if($unseenleft < 0){ $unseenleft = 0; } |
|
|
3209 |
return ( |
| 3210 |
$renewcount, |
| 3211 |
$renewsallowed, |
| 3212 |
$renewsleft, |
| 3213 |
$unseencount, |
| 3214 |
$unseenallowed, |
| 3215 |
$unseenleft |
| 3216 |
); |
| 3061 |
} |
3217 |
} |
| 3062 |
|
3218 |
|
| 3063 |
=head2 GetSoonestRenewDate |
3219 |
=head2 GetSoonestRenewDate |