|
Lines 2803-2808
sub CanBookBeRenewed {
Link Here
|
| 2803 |
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_much_oweing'; |
2803 |
return ( 0, $auto_renew ) if $auto_renew =~ 'auto_too_much_oweing'; |
| 2804 |
} |
2804 |
} |
| 2805 |
|
2805 |
|
|
|
2806 |
# Note: possible_reserves will contain all title level holds on this bib and item level |
| 2807 |
# holds on the checked out item |
| 2806 |
my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber); |
2808 |
my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber); |
| 2807 |
|
2809 |
|
| 2808 |
# If next hold is non priority, then check if any hold with priority (non_priority = 0) exists for the same biblionumber. |
2810 |
# If next hold is non priority, then check if any hold with priority (non_priority = 0) exists for the same biblionumber. |
|
Lines 2827-2860
sub CanBookBeRenewed {
Link Here
|
| 2827 |
else { |
2829 |
else { |
| 2828 |
|
2830 |
|
| 2829 |
# Get all other items that could possibly fill reserves |
2831 |
# Get all other items that could possibly fill reserves |
|
|
2832 |
# FIXME We could join reserves (or more tables) here to eliminate some checks later |
| 2830 |
my $items = Koha::Items->search({ |
2833 |
my $items = Koha::Items->search({ |
| 2831 |
biblionumber => $resrec->{biblionumber}, |
2834 |
biblionumber => $resrec->{biblionumber}, |
| 2832 |
onloan => undef, |
2835 |
onloan => undef, |
| 2833 |
notforloan => 0, |
2836 |
notforloan => 0, |
| 2834 |
-not => { itemnumber => $itemnumber } |
2837 |
-not => { itemnumber => $itemnumber } |
| 2835 |
}); |
2838 |
}); |
|
|
2839 |
my $item_count = $items->count(); |
| 2836 |
|
2840 |
|
| 2837 |
# Get all other reserves that could have been filled by this item |
2841 |
# Get all other reserves that could have been filled by this item |
| 2838 |
my @borrowernumbers = map { $_->{borrowernumber} } @$possible_reserves; |
2842 |
my @borrowernumbers = map { $_->{borrowernumber} } @$possible_reserves; |
|
|
2843 |
# Note: fetching the patrons in this manner means that a patron with 2 holds will |
| 2844 |
# not block renewal if one reserve can be satisfied i.e. each patron is checked once |
| 2839 |
my $patrons = Koha::Patrons->search({ |
2845 |
my $patrons = Koha::Patrons->search({ |
| 2840 |
borrowernumber => { -in => \@borrowernumbers } |
2846 |
borrowernumber => { -in => \@borrowernumbers } |
| 2841 |
}); |
2847 |
}); |
|
|
2848 |
my $patron_count = $patrons->count(); |
| 2842 |
|
2849 |
|
| 2843 |
# If the count of the union of the lists of reservable items for each borrower |
2850 |
return ( 0, "on_reserve" ) if ($patron_count > $item_count); |
| 2844 |
# is equal or greater than the number of borrowers, we know that all reserves |
2851 |
# We cannot possibly fill all reserves if we don't have enough items |
| 2845 |
# can be filled with available items. We can get the union of the sets simply |
2852 |
|
| 2846 |
# by pushing all the elements onto an array and removing the duplicates. |
2853 |
# If we can fill each hold that has been found with the available items on the record |
| 2847 |
my @reservable; |
2854 |
# then the patron can renew. If we cannot, they cannot renew. |
|
|
2855 |
# FIXME This code does not check whether the item we are renewing can fill |
| 2856 |
# any of the existing reserves. |
| 2857 |
my $reservable = 0; |
| 2848 |
my %matched_items; |
2858 |
my %matched_items; |
|
|
2859 |
my $seen = 0; |
| 2849 |
PATRON: while ( my $patron = $patrons->next ) { |
2860 |
PATRON: while ( my $patron = $patrons->next ) { |
|
|
2861 |
# If there is a reserve that cannot be filled we are done |
| 2862 |
return ( 0, "on_reserve" ) if ( $seen > $reservable ); |
| 2850 |
my $items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $item->biblionumber, patron => $patron }); |
2863 |
my $items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $item->biblionumber, patron => $patron }); |
| 2851 |
while ( my $other_item = $items->next ) { |
2864 |
while ( my $other_item = $items->next ) { |
| 2852 |
next if $matched_items{$other_item->itemnumber} == 1; |
2865 |
next if defined $matched_items{$other_item->itemnumber}; |
| 2853 |
next if IsItemOnHoldAndFound( $other_item->itemnumber ); |
2866 |
next if IsItemOnHoldAndFound( $other_item->itemnumber ); |
| 2854 |
next unless IsAvailableForItemLevelRequest($other_item, $patron, undef, $items_any_available); |
2867 |
next unless IsAvailableForItemLevelRequest($other_item, $patron, undef, $items_any_available); |
| 2855 |
next unless CanItemBeReserved($patron->borrowernumber,$other_item->itemnumber,undef,{ignore_hold_counts=>1})->{status} eq 'OK'; |
2868 |
next unless CanItemBeReserved($patron->borrowernumber,$other_item->itemnumber,undef,{ignore_hold_counts=>1})->{status} eq 'OK'; |
| 2856 |
push @reservable, $other_item->itemnumber; |
2869 |
# NOTE: At checkin we call 'CheckReserves' which checks hold 'policy' |
| 2857 |
if (@reservable >= @borrowernumbers) { |
2870 |
# CanItemBeReserved checks 'rules' and 'policies' which means |
|
|
2871 |
# items will fill holds at checkin that are rejected here |
| 2872 |
$reservable++; |
| 2873 |
if ($reservable >= $patron_count) { |
| 2858 |
$resfound = 0; |
2874 |
$resfound = 0; |
| 2859 |
last PATRON; |
2875 |
last PATRON; |
| 2860 |
} |
2876 |
} |
|
Lines 2862-2867
sub CanBookBeRenewed {
Link Here
|
| 2862 |
last; |
2878 |
last; |
| 2863 |
} |
2879 |
} |
| 2864 |
$items->reset; |
2880 |
$items->reset; |
|
|
2881 |
$seen++; |
| 2865 |
} |
2882 |
} |
| 2866 |
} |
2883 |
} |
| 2867 |
} |
2884 |
} |