|
Lines 2764-2773
sub CanBookBeRenewed {
Link Here
|
| 2764 |
branchcode => $branchcode, |
2764 |
branchcode => $branchcode, |
| 2765 |
rules => [ |
2765 |
rules => [ |
| 2766 |
'renewalsallowed', |
2766 |
'renewalsallowed', |
| 2767 |
'no_auto_renewal_after', |
|
|
| 2768 |
'no_auto_renewal_after_hard_limit', |
| 2769 |
'lengthunit', |
2767 |
'lengthunit', |
| 2770 |
'norenewalbefore', |
|
|
| 2771 |
'unseen_renewals_allowed' |
2768 |
'unseen_renewals_allowed' |
| 2772 |
] |
2769 |
] |
| 2773 |
} |
2770 |
} |
|
Lines 2793-2871
sub CanBookBeRenewed {
Link Here
|
| 2793 |
return ( 0, 'overdue'); |
2790 |
return ( 0, 'overdue'); |
| 2794 |
} |
2791 |
} |
| 2795 |
|
2792 |
|
| 2796 |
if ( $issue->auto_renew && $patron->autorenew_checkouts ) { |
2793 |
$auto_renew = _CanBookBeAutoRenewed($borrowernumber, $itemnumber); |
| 2797 |
|
2794 |
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_account_expired'; |
| 2798 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
2795 |
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_late'; |
| 2799 |
return ( 0, 'auto_account_expired' ); |
2796 |
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_much_oweing'; |
| 2800 |
} |
|
|
| 2801 |
|
| 2802 |
if ( defined $issuing_rule->{no_auto_renewal_after} |
| 2803 |
and $issuing_rule->{no_auto_renewal_after} ne "" ) { |
| 2804 |
# Get issue_date and add no_auto_renewal_after |
| 2805 |
# If this is greater than today, it's too late for renewal. |
| 2806 |
my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); |
| 2807 |
$maximum_renewal_date->add( |
| 2808 |
$issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after} |
| 2809 |
); |
| 2810 |
my $now = dt_from_string; |
| 2811 |
if ( $now >= $maximum_renewal_date ) { |
| 2812 |
return ( 0, "auto_too_late" ); |
| 2813 |
} |
| 2814 |
} |
| 2815 |
if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit} |
| 2816 |
and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) { |
| 2817 |
# If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal |
| 2818 |
if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) { |
| 2819 |
return ( 0, "auto_too_late" ); |
| 2820 |
} |
| 2821 |
} |
| 2822 |
|
| 2823 |
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { |
| 2824 |
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); |
| 2825 |
my $amountoutstanding = |
| 2826 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredit") |
| 2827 |
? $patron->account->balance |
| 2828 |
: $patron->account->outstanding_debits->total_outstanding; |
| 2829 |
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { |
| 2830 |
return ( 0, "auto_too_much_oweing" ); |
| 2831 |
} |
| 2832 |
} |
| 2833 |
} |
| 2834 |
|
| 2835 |
if ( defined $issuing_rule->{norenewalbefore} |
| 2836 |
and $issuing_rule->{norenewalbefore} ne "" ) |
| 2837 |
{ |
| 2838 |
|
| 2839 |
# Calculate soonest renewal by subtracting 'No renewal before' from due date |
| 2840 |
my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( |
| 2841 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
| 2842 |
|
| 2843 |
# Depending on syspref reset the exact time, only check the date |
| 2844 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
| 2845 |
and $issuing_rule->{lengthunit} eq 'days' ) |
| 2846 |
{ |
| 2847 |
$soonestrenewal->truncate( to => 'day' ); |
| 2848 |
} |
| 2849 |
|
| 2850 |
if ( $soonestrenewal > dt_from_string() ) |
| 2851 |
{ |
| 2852 |
$auto_renew = ($issue->auto_renew && $patron->autorenew_checkouts) ? "auto_too_soon" : "too_soon"; |
| 2853 |
} |
| 2854 |
elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) { |
| 2855 |
$auto_renew = "ok"; |
| 2856 |
} |
| 2857 |
} |
| 2858 |
|
| 2859 |
# Fallback for automatic renewals: |
| 2860 |
# If norenewalbefore is undef, don't renew before due date. |
| 2861 |
if ( $issue->auto_renew && $auto_renew eq "no" && $patron->autorenew_checkouts ) { |
| 2862 |
my $now = dt_from_string; |
| 2863 |
if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){ |
| 2864 |
$auto_renew = "ok"; |
| 2865 |
} else { |
| 2866 |
$auto_renew = "auto_too_soon"; |
| 2867 |
} |
| 2868 |
} |
| 2869 |
} |
2797 |
} |
| 2870 |
|
2798 |
|
| 2871 |
my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber); |
2799 |
my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber); |
|
Lines 4308-4313
sub _CalculateAndUpdateFine {
Link Here
|
| 4308 |
} |
4236 |
} |
| 4309 |
} |
4237 |
} |
| 4310 |
|
4238 |
|
|
|
4239 |
sub _CanBookBeAutoRenewed { |
| 4240 |
my ( $borrowernumber, $itemnumber ) = @_; |
| 4241 |
|
| 4242 |
my $item = Koha::Items->find($itemnumber); |
| 4243 |
my $issue = $item->checkout; |
| 4244 |
my $patron = $issue->patron; |
| 4245 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
| 4246 |
|
| 4247 |
my $issuing_rule = Koha::CirculationRules->get_effective_rules( |
| 4248 |
{ |
| 4249 |
categorycode => $patron->categorycode, |
| 4250 |
itemtype => $item->effective_itemtype, |
| 4251 |
branchcode => $branchcode, |
| 4252 |
rules => [ |
| 4253 |
'no_auto_renewal_after', |
| 4254 |
'no_auto_renewal_after_hard_limit', |
| 4255 |
'lengthunit', |
| 4256 |
'norenewalbefore', |
| 4257 |
] |
| 4258 |
} |
| 4259 |
); |
| 4260 |
|
| 4261 |
if ( $issue->auto_renew && $patron->autorenew_checkouts ) { |
| 4262 |
|
| 4263 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
| 4264 |
return 'auto_account_expired'; |
| 4265 |
} |
| 4266 |
|
| 4267 |
if ( defined $issuing_rule->{no_auto_renewal_after} |
| 4268 |
and $issuing_rule->{no_auto_renewal_after} ne "" ) { |
| 4269 |
# Get issue_date and add no_auto_renewal_after |
| 4270 |
# If this is greater than today, it's too late for renewal. |
| 4271 |
my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); |
| 4272 |
$maximum_renewal_date->add( |
| 4273 |
$issuing_rule->{lengthunit} => $issuing_rule->{no_auto_renewal_after} |
| 4274 |
); |
| 4275 |
my $now = dt_from_string; |
| 4276 |
if ( $now >= $maximum_renewal_date ) { |
| 4277 |
return "auto_too_late"; |
| 4278 |
} |
| 4279 |
} |
| 4280 |
if ( defined $issuing_rule->{no_auto_renewal_after_hard_limit} |
| 4281 |
and $issuing_rule->{no_auto_renewal_after_hard_limit} ne "" ) { |
| 4282 |
# If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal |
| 4283 |
if ( dt_from_string >= dt_from_string( $issuing_rule->{no_auto_renewal_after_hard_limit} ) ) { |
| 4284 |
return "auto_too_late"; |
| 4285 |
} |
| 4286 |
} |
| 4287 |
|
| 4288 |
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { |
| 4289 |
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); |
| 4290 |
my $amountoutstanding = |
| 4291 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredit") |
| 4292 |
? $patron->account->balance |
| 4293 |
: $patron->account->outstanding_debits->total_outstanding; |
| 4294 |
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { |
| 4295 |
return "auto_too_much_oweing"; |
| 4296 |
} |
| 4297 |
} |
| 4298 |
} |
| 4299 |
|
| 4300 |
if ( defined $issuing_rule->{norenewalbefore} |
| 4301 |
and $issuing_rule->{norenewalbefore} ne "" ) |
| 4302 |
{ |
| 4303 |
|
| 4304 |
# Calculate soonest renewal by subtracting 'No renewal before' from due date |
| 4305 |
my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( |
| 4306 |
$issuing_rule->{lengthunit} => $issuing_rule->{norenewalbefore} ); |
| 4307 |
|
| 4308 |
# Depending on syspref reset the exact time, only check the date |
| 4309 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
| 4310 |
and $issuing_rule->{lengthunit} eq 'days' ) |
| 4311 |
{ |
| 4312 |
$soonestrenewal->truncate( to => 'day' ); |
| 4313 |
} |
| 4314 |
|
| 4315 |
if ( $soonestrenewal > dt_from_string() ) |
| 4316 |
{ |
| 4317 |
return ($issue->auto_renew && $patron->autorenew_checkouts) ? "auto_too_soon" : "too_soon"; |
| 4318 |
} |
| 4319 |
elsif ( $issue->auto_renew && $patron->autorenew_checkouts ) { |
| 4320 |
return "ok"; |
| 4321 |
} |
| 4322 |
} |
| 4323 |
|
| 4324 |
# Fallback for automatic renewals: |
| 4325 |
# If norenewalbefore is undef, don't renew before due date. |
| 4326 |
if ( $issue->auto_renew && $patron->autorenew_checkouts ) { |
| 4327 |
my $now = dt_from_string; |
| 4328 |
if ( $now >= dt_from_string( $issue->date_due, 'sql' ) ){ |
| 4329 |
return "ok"; |
| 4330 |
} else { |
| 4331 |
return "auto_too_soon"; |
| 4332 |
} |
| 4333 |
} |
| 4334 |
return "no"; |
| 4335 |
} |
| 4336 |
|
| 4311 |
sub _item_denied_renewal { |
4337 |
sub _item_denied_renewal { |
| 4312 |
my ($params) = @_; |
4338 |
my ($params) = @_; |
| 4313 |
|
4339 |
|
| 4314 |
- |
|
|