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