|
Lines 2752-2758
sub CanBookBeRenewed {
Link Here
|
| 2752 |
return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item }); |
2752 |
return ( 0, 'item_denied_renewal') if _item_denied_renewal({ item => $item }); |
| 2753 |
|
2753 |
|
| 2754 |
my $patron = $issue->patron or return; |
2754 |
my $patron = $issue->patron or return; |
| 2755 |
|
2755 |
my $soonest_renew_date; |
| 2756 |
# override_limit will override anything else except on_reserve |
2756 |
# override_limit will override anything else except on_reserve |
| 2757 |
unless ( $override_limit ){ |
2757 |
unless ( $override_limit ){ |
| 2758 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
2758 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
|
Lines 2764-2773
sub CanBookBeRenewed {
Link Here
|
| 2764 |
rules => [ |
2764 |
rules => [ |
| 2765 |
'renewalsallowed', |
2765 |
'renewalsallowed', |
| 2766 |
'lengthunit', |
2766 |
'lengthunit', |
| 2767 |
'unseen_renewals_allowed' |
2767 |
'unseen_renewals_allowed', |
|
|
2768 |
'no_auto_renewal_after', |
| 2769 |
'no_auto_renewal_after_hard_limit', |
| 2770 |
'norenewalbefore' |
| 2768 |
] |
2771 |
] |
| 2769 |
} |
2772 |
} |
| 2770 |
); |
2773 |
); |
|
|
2774 |
$soonest_renew_date = GetSoonestRenewDate($borrowernumber, $itemnumber, $branchcode, $issuing_rule); |
| 2771 |
|
2775 |
|
| 2772 |
return ( 0, "too_many" ) |
2776 |
return ( 0, "too_many" ) |
| 2773 |
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; |
2777 |
if not $issuing_rule->{renewalsallowed} or $issuing_rule->{renewalsallowed} <= $issue->renewals; |
|
Lines 2789-2800
sub CanBookBeRenewed {
Link Here
|
| 2789 |
return ( 0, 'overdue'); |
2793 |
return ( 0, 'overdue'); |
| 2790 |
} |
2794 |
} |
| 2791 |
|
2795 |
|
|
|
2796 |
|
| 2792 |
$auto_renew = _CanBookBeAutoRenewed({ |
2797 |
$auto_renew = _CanBookBeAutoRenewed({ |
| 2793 |
patron => $patron, |
2798 |
patron => $patron, |
| 2794 |
item => $item, |
2799 |
item => $item, |
| 2795 |
branchcode => $branchcode, |
2800 |
branchcode => $branchcode, |
| 2796 |
issue => $issue |
2801 |
issue => $issue, |
| 2797 |
}); |
2802 |
issuing_rule => $issuing_rule, |
|
|
2803 |
soonest => $soonest_renew_date |
| 2804 |
}) if $issue->auto_renew && $patron->autorenew_checkouts; |
| 2805 |
|
| 2798 |
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_soon' && $cron; |
2806 |
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_soon' && $cron; |
| 2799 |
# cron wants 'too_soon' over 'on_reserve' for performance and to avoid |
2807 |
# cron wants 'too_soon' over 'on_reserve' for performance and to avoid |
| 2800 |
# extra notices being sent. Cron also implies no override |
2808 |
# extra notices being sent. Cron also implies no override |
|
Lines 2863-2874
sub CanBookBeRenewed {
Link Here
|
| 2863 |
} |
2871 |
} |
| 2864 |
|
2872 |
|
| 2865 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
2873 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
| 2866 |
return ( 0, $auto_renew ) if $auto_renew =~ 'too_soon';#$auto_renew ne "no" && $auto_renew ne "ok"; |
2874 |
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_soon'; |
| 2867 |
if ( GetSoonestRenewDate($borrowernumber, $itemnumber) > dt_from_string() ){ |
2875 |
return (0, "too_soon") if !$override_limit && $soonest_renew_date > dt_from_string(); |
| 2868 |
return (0, "too_soon") unless $override_limit; |
|
|
| 2869 |
} |
| 2870 |
|
2876 |
|
| 2871 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed |
2877 |
return ( 0, "auto_renew" ) if $auto_renew eq "ok"; |
|
|
2878 |
# scheduled for automatic renewal, if overridden auto_renew is 'no' |
| 2872 |
|
2879 |
|
| 2873 |
return ( 1, undef ); |
2880 |
return ( 1, undef ); |
| 2874 |
} |
2881 |
} |
|
Lines 3161-3167
cannot be found.
Link Here
|
| 3161 |
=cut |
3168 |
=cut |
| 3162 |
|
3169 |
|
| 3163 |
sub GetSoonestRenewDate { |
3170 |
sub GetSoonestRenewDate { |
| 3164 |
my ( $borrowernumber, $itemnumber ) = @_; |
3171 |
my ( $borrowernumber, $itemnumber, $branchcode, $issuing_rule ) = @_; |
| 3165 |
|
3172 |
|
| 3166 |
my $dbh = C4::Context->dbh; |
3173 |
my $dbh = C4::Context->dbh; |
| 3167 |
|
3174 |
|
|
Lines 3172-3179
sub GetSoonestRenewDate {
Link Here
|
| 3172 |
my $patron = Koha::Patrons->find( $borrowernumber ) |
3179 |
my $patron = Koha::Patrons->find( $borrowernumber ) |
| 3173 |
or return; |
3180 |
or return; |
| 3174 |
|
3181 |
|
| 3175 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
3182 |
$branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ) unless $branchcode; |
| 3176 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
3183 |
$issuing_rule = Koha::CirculationRules->get_effective_rules( |
| 3177 |
{ categorycode => $patron->categorycode, |
3184 |
{ categorycode => $patron->categorycode, |
| 3178 |
itemtype => $item->effective_itemtype, |
3185 |
itemtype => $item->effective_itemtype, |
| 3179 |
branchcode => $branchcode, |
3186 |
branchcode => $branchcode, |
|
Lines 3182-3188
sub GetSoonestRenewDate {
Link Here
|
| 3182 |
'lengthunit', |
3189 |
'lengthunit', |
| 3183 |
] |
3190 |
] |
| 3184 |
} |
3191 |
} |
| 3185 |
); |
3192 |
) unless $issuing_rule; |
| 3186 |
|
3193 |
|
| 3187 |
my $now = dt_from_string; |
3194 |
my $now = dt_from_string; |
| 3188 |
return $now unless $issuing_rule; |
3195 |
return $now unless $issuing_rule; |
|
Lines 4262-4283
sub _CanBookBeAutoRenewed {
Link Here
|
| 4262 |
my $item = $params->{item}; |
4269 |
my $item = $params->{item}; |
| 4263 |
my $branchcode = $params->{branchcode}; |
4270 |
my $branchcode = $params->{branchcode}; |
| 4264 |
my $issue = $params->{issue}; |
4271 |
my $issue = $params->{issue}; |
| 4265 |
|
4272 |
my $soonest_renew_date = $params->{soonest}; |
| 4266 |
return "no" unless $issue->auto_renew && $patron->autorenew_checkouts; |
4273 |
my $issuing_rule = $params->{issuing_rule}; |
| 4267 |
|
|
|
| 4268 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
| 4269 |
{ |
| 4270 |
categorycode => $patron->categorycode, |
| 4271 |
itemtype => $item->effective_itemtype, |
| 4272 |
branchcode => $branchcode, |
| 4273 |
rules => [ |
| 4274 |
'no_auto_renewal_after', |
| 4275 |
'no_auto_renewal_after_hard_limit', |
| 4276 |
'lengthunit', |
| 4277 |
'norenewalbefore', |
| 4278 |
] |
| 4279 |
} |
| 4280 |
); |
| 4281 |
|
4274 |
|
| 4282 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
4275 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
| 4283 |
return 'auto_account_expired'; |
4276 |
return 'auto_account_expired'; |
|
Lines 4317-4323
sub _CanBookBeAutoRenewed {
Link Here
|
| 4317 |
|
4310 |
|
| 4318 |
if ( defined $issuing_rule->{norenewalbefore} |
4311 |
if ( defined $issuing_rule->{norenewalbefore} |
| 4319 |
and $issuing_rule->{norenewalbefore} ne "" ) { |
4312 |
and $issuing_rule->{norenewalbefore} ne "" ) { |
| 4320 |
if ( GetSoonestRenewDate($patron->id, $item->id) > dt_from_string()) { |
4313 |
if ( $soonest_renew_date > dt_from_string()) { |
| 4321 |
return "auto_too_soon"; |
4314 |
return "auto_too_soon"; |
| 4322 |
} else { |
4315 |
} else { |
| 4323 |
return "ok"; |
4316 |
return "ok"; |
| 4324 |
- |
|
|