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