|
Lines 2676-2681
sub CanBookBeRenewed {
Link Here
|
| 2676 |
|
2676 |
|
| 2677 |
my $patron = $issue->patron or return; |
2677 |
my $patron = $issue->patron or return; |
| 2678 |
|
2678 |
|
|
|
2679 |
# override_limit will override anything else except on_reserve |
| 2680 |
unless ( $override_limit ){ |
| 2681 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
| 2682 |
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( |
| 2683 |
{ categorycode => $patron->categorycode, |
| 2684 |
itemtype => $item->effective_itemtype, |
| 2685 |
branchcode => $branchcode |
| 2686 |
} |
| 2687 |
); |
| 2688 |
|
| 2689 |
return ( 0, "too_many" ) |
| 2690 |
if not $issuing_rule or $issuing_rule->renewalsallowed <= $issue->renewals; |
| 2691 |
|
| 2692 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
| 2693 |
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); |
| 2694 |
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? |
| 2695 |
my $restricted = $patron->is_debarred; |
| 2696 |
my $hasoverdues = $patron->has_overdues; |
| 2697 |
|
| 2698 |
if ( $restricted and $restrictionblockrenewing ) { |
| 2699 |
return ( 0, 'restriction'); |
| 2700 |
} elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { |
| 2701 |
return ( 0, 'overdue'); |
| 2702 |
} |
| 2703 |
|
| 2704 |
if ( $issue->auto_renew ) { |
| 2705 |
|
| 2706 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
| 2707 |
return ( 0, 'auto_account_expired' ); |
| 2708 |
} |
| 2709 |
|
| 2710 |
if ( defined $issuing_rule->no_auto_renewal_after |
| 2711 |
and $issuing_rule->no_auto_renewal_after ne "" ) { |
| 2712 |
# Get issue_date and add no_auto_renewal_after |
| 2713 |
# If this is greater than today, it's too late for renewal. |
| 2714 |
my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); |
| 2715 |
$maximum_renewal_date->add( |
| 2716 |
$issuing_rule->lengthunit => $issuing_rule->no_auto_renewal_after |
| 2717 |
); |
| 2718 |
my $now = dt_from_string; |
| 2719 |
if ( $now >= $maximum_renewal_date ) { |
| 2720 |
return ( 0, "auto_too_late" ); |
| 2721 |
} |
| 2722 |
} |
| 2723 |
if ( defined $issuing_rule->no_auto_renewal_after_hard_limit |
| 2724 |
and $issuing_rule->no_auto_renewal_after_hard_limit ne "" ) { |
| 2725 |
# If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal |
| 2726 |
if ( dt_from_string >= dt_from_string( $issuing_rule->no_auto_renewal_after_hard_limit ) ) { |
| 2727 |
return ( 0, "auto_too_late" ); |
| 2728 |
} |
| 2729 |
} |
| 2730 |
|
| 2731 |
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { |
| 2732 |
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); |
| 2733 |
my $amountoutstanding = |
| 2734 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredit") |
| 2735 |
? $patron->account->balance |
| 2736 |
: $patron->account->outstanding_debits->total_outstanding; |
| 2737 |
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { |
| 2738 |
return ( 0, "auto_too_much_oweing" ); |
| 2739 |
} |
| 2740 |
} |
| 2741 |
} |
| 2742 |
|
| 2743 |
if ( defined $issuing_rule->norenewalbefore |
| 2744 |
and $issuing_rule->norenewalbefore ne "" ) |
| 2745 |
{ |
| 2746 |
|
| 2747 |
# Calculate soonest renewal by subtracting 'No renewal before' from due date |
| 2748 |
my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( |
| 2749 |
$issuing_rule->lengthunit => $issuing_rule->norenewalbefore ); |
| 2750 |
|
| 2751 |
# Depending on syspref reset the exact time, only check the date |
| 2752 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
| 2753 |
and $issuing_rule->lengthunit eq 'days' ) |
| 2754 |
{ |
| 2755 |
$soonestrenewal->truncate( to => 'day' ); |
| 2756 |
} |
| 2757 |
|
| 2758 |
if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) |
| 2759 |
{ |
| 2760 |
return ( 0, "auto_too_soon" ) if $issue->auto_renew; |
| 2761 |
return ( 0, "too_soon" ); |
| 2762 |
} |
| 2763 |
elsif ( $issue->auto_renew ) { |
| 2764 |
return ( 0, "auto_renew" ); |
| 2765 |
} |
| 2766 |
} |
| 2767 |
|
| 2768 |
# Fallback for automatic renewals: |
| 2769 |
# If norenewalbefore is undef, don't renew before due date. |
| 2770 |
if ( $issue->auto_renew ) { |
| 2771 |
my $now = dt_from_string; |
| 2772 |
return ( 0, "auto_renew" ) |
| 2773 |
if $now >= dt_from_string( $issue->date_due, 'sql' ); |
| 2774 |
return ( 0, "auto_too_soon" ); |
| 2775 |
} |
| 2776 |
} |
| 2777 |
|
| 2679 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); |
2778 |
my ( $resfound, $resrec, undef ) = C4::Reserves::CheckReserves($itemnumber); |
| 2680 |
|
2779 |
|
| 2681 |
# This item can fill one or more unfilled reserve, can those unfilled reserves |
2780 |
# This item can fill one or more unfilled reserve, can those unfilled reserves |
|
Lines 2743-2846
sub CanBookBeRenewed {
Link Here
|
| 2743 |
} |
2842 |
} |
| 2744 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
2843 |
return ( 0, "on_reserve" ) if $resfound; # '' when no hold was found |
| 2745 |
|
2844 |
|
| 2746 |
return ( 1, undef ) if $override_limit; |
|
|
| 2747 |
|
| 2748 |
my $branchcode = _GetCircControlBranch( $item->unblessed, $patron->unblessed ); |
| 2749 |
my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( |
| 2750 |
{ categorycode => $patron->categorycode, |
| 2751 |
itemtype => $item->effective_itemtype, |
| 2752 |
branchcode => $branchcode |
| 2753 |
} |
| 2754 |
); |
| 2755 |
|
| 2756 |
return ( 0, "too_many" ) |
| 2757 |
if not $issuing_rule or $issuing_rule->renewalsallowed <= $issue->renewals; |
| 2758 |
|
| 2759 |
my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); |
| 2760 |
my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); |
| 2761 |
$patron = Koha::Patrons->find($borrowernumber); # FIXME Is this really useful? |
| 2762 |
my $restricted = $patron->is_debarred; |
| 2763 |
my $hasoverdues = $patron->has_overdues; |
| 2764 |
|
| 2765 |
if ( $restricted and $restrictionblockrenewing ) { |
| 2766 |
return ( 0, 'restriction'); |
| 2767 |
} elsif ( ($hasoverdues and $overduesblockrenewing eq 'block') || ($issue->is_overdue and $overduesblockrenewing eq 'blockitem') ) { |
| 2768 |
return ( 0, 'overdue'); |
| 2769 |
} |
| 2770 |
|
| 2771 |
if ( $issue->auto_renew ) { |
| 2772 |
|
| 2773 |
if ( $patron->category->effective_BlockExpiredPatronOpacActions and $patron->is_expired ) { |
| 2774 |
return ( 0, 'auto_account_expired' ); |
| 2775 |
} |
| 2776 |
|
| 2777 |
if ( defined $issuing_rule->no_auto_renewal_after |
| 2778 |
and $issuing_rule->no_auto_renewal_after ne "" ) { |
| 2779 |
# Get issue_date and add no_auto_renewal_after |
| 2780 |
# If this is greater than today, it's too late for renewal. |
| 2781 |
my $maximum_renewal_date = dt_from_string($issue->issuedate, 'sql'); |
| 2782 |
$maximum_renewal_date->add( |
| 2783 |
$issuing_rule->lengthunit => $issuing_rule->no_auto_renewal_after |
| 2784 |
); |
| 2785 |
my $now = dt_from_string; |
| 2786 |
if ( $now >= $maximum_renewal_date ) { |
| 2787 |
return ( 0, "auto_too_late" ); |
| 2788 |
} |
| 2789 |
} |
| 2790 |
if ( defined $issuing_rule->no_auto_renewal_after_hard_limit |
| 2791 |
and $issuing_rule->no_auto_renewal_after_hard_limit ne "" ) { |
| 2792 |
# If no_auto_renewal_after_hard_limit is >= today, it's also too late for renewal |
| 2793 |
if ( dt_from_string >= dt_from_string( $issuing_rule->no_auto_renewal_after_hard_limit ) ) { |
| 2794 |
return ( 0, "auto_too_late" ); |
| 2795 |
} |
| 2796 |
} |
| 2797 |
|
| 2798 |
if ( C4::Context->preference('OPACFineNoRenewalsBlockAutoRenew') ) { |
| 2799 |
my $fine_no_renewals = C4::Context->preference("OPACFineNoRenewals"); |
| 2800 |
my $amountoutstanding = |
| 2801 |
C4::Context->preference("OPACFineNoRenewalsIncludeCredit") |
| 2802 |
? $patron->account->balance |
| 2803 |
: $patron->account->outstanding_debits->total_outstanding; |
| 2804 |
if ( $amountoutstanding and $amountoutstanding > $fine_no_renewals ) { |
| 2805 |
return ( 0, "auto_too_much_oweing" ); |
| 2806 |
} |
| 2807 |
} |
| 2808 |
} |
| 2809 |
|
| 2810 |
if ( defined $issuing_rule->norenewalbefore |
| 2811 |
and $issuing_rule->norenewalbefore ne "" ) |
| 2812 |
{ |
| 2813 |
|
| 2814 |
# Calculate soonest renewal by subtracting 'No renewal before' from due date |
| 2815 |
my $soonestrenewal = dt_from_string( $issue->date_due, 'sql' )->subtract( |
| 2816 |
$issuing_rule->lengthunit => $issuing_rule->norenewalbefore ); |
| 2817 |
|
| 2818 |
# Depending on syspref reset the exact time, only check the date |
| 2819 |
if ( C4::Context->preference('NoRenewalBeforePrecision') eq 'date' |
| 2820 |
and $issuing_rule->lengthunit eq 'days' ) |
| 2821 |
{ |
| 2822 |
$soonestrenewal->truncate( to => 'day' ); |
| 2823 |
} |
| 2824 |
|
| 2825 |
if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) |
| 2826 |
{ |
| 2827 |
return ( 0, "auto_too_soon" ) if $issue->auto_renew; |
| 2828 |
return ( 0, "too_soon" ); |
| 2829 |
} |
| 2830 |
elsif ( $issue->auto_renew ) { |
| 2831 |
return ( 0, "auto_renew" ); |
| 2832 |
} |
| 2833 |
} |
| 2834 |
|
| 2835 |
# Fallback for automatic renewals: |
| 2836 |
# If norenewalbefore is undef, don't renew before due date. |
| 2837 |
if ( $issue->auto_renew ) { |
| 2838 |
my $now = dt_from_string; |
| 2839 |
return ( 0, "auto_renew" ) |
| 2840 |
if $now >= dt_from_string( $issue->date_due, 'sql' ); |
| 2841 |
return ( 0, "auto_too_soon" ); |
| 2842 |
} |
| 2843 |
|
| 2844 |
return ( 1, undef ); |
2845 |
return ( 1, undef ); |
| 2845 |
} |
2846 |
} |
| 2846 |
|
2847 |
|
| 2847 |
- |
|
|