Lines 2916-2921
sub CanBookBeRenewed {
Link Here
|
2916 |
} |
2916 |
} |
2917 |
} |
2917 |
} |
2918 |
|
2918 |
|
|
|
2919 |
# Note: possible_reserves will contain all title level holds on this bib and item level |
2920 |
# holds on the checked out item |
2919 |
my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber); |
2921 |
my ( $resfound, $resrec, $possible_reserves ) = C4::Reserves::CheckReserves($itemnumber); |
2920 |
|
2922 |
|
2921 |
# If next hold is non priority, then check if any hold with priority (non_priority = 0) exists for the same biblionumber. |
2923 |
# If next hold is non priority, then check if any hold with priority (non_priority = 0) exists for the same biblionumber. |
Lines 2940-2973
sub CanBookBeRenewed {
Link Here
|
2940 |
else { |
2942 |
else { |
2941 |
|
2943 |
|
2942 |
# Get all other items that could possibly fill reserves |
2944 |
# Get all other items that could possibly fill reserves |
|
|
2945 |
# FIXME We could join reserves (or more tables) here to eliminate some checks later |
2943 |
my $items = Koha::Items->search({ |
2946 |
my $items = Koha::Items->search({ |
2944 |
biblionumber => $resrec->{biblionumber}, |
2947 |
biblionumber => $resrec->{biblionumber}, |
2945 |
onloan => undef, |
2948 |
onloan => undef, |
2946 |
notforloan => 0, |
2949 |
notforloan => 0, |
2947 |
-not => { itemnumber => $itemnumber } |
2950 |
-not => { itemnumber => $itemnumber } |
2948 |
}); |
2951 |
}); |
|
|
2952 |
my $item_count = $items->count(); |
2949 |
|
2953 |
|
2950 |
# Get all other reserves that could have been filled by this item |
2954 |
# Get all other reserves that could have been filled by this item |
2951 |
my @borrowernumbers = map { $_->{borrowernumber} } @$possible_reserves; |
2955 |
my @borrowernumbers = map { $_->{borrowernumber} } @$possible_reserves; |
|
|
2956 |
# Note: fetching the patrons in this manner means that a patron with 2 holds will |
2957 |
# not block renewal if one reserve can be satisfied i.e. each patron is checked once |
2952 |
my $patrons = Koha::Patrons->search({ |
2958 |
my $patrons = Koha::Patrons->search({ |
2953 |
borrowernumber => { -in => \@borrowernumbers } |
2959 |
borrowernumber => { -in => \@borrowernumbers } |
2954 |
}); |
2960 |
}); |
|
|
2961 |
my $patron_count = $patrons->count(); |
2955 |
|
2962 |
|
2956 |
# If the count of the union of the lists of reservable items for each borrower |
2963 |
return ( 0, "on_reserve" ) if ($patron_count > $item_count); |
2957 |
# is equal or greater than the number of borrowers, we know that all reserves |
2964 |
# We cannot possibly fill all reserves if we don't have enough items |
2958 |
# can be filled with available items. We can get the union of the sets simply |
2965 |
|
2959 |
# by pushing all the elements onto an array and removing the duplicates. |
2966 |
# If we can fill each hold that has been found with the available items on the record |
2960 |
my @reservable; |
2967 |
# then the patron can renew. If we cannot, they cannot renew. |
|
|
2968 |
# FIXME This code does not check whether the item we are renewing can fill |
2969 |
# any of the existing reserves. |
2970 |
my $reservable = 0; |
2961 |
my %matched_items; |
2971 |
my %matched_items; |
|
|
2972 |
my $seen = 0; |
2962 |
PATRON: while ( my $patron = $patrons->next ) { |
2973 |
PATRON: while ( my $patron = $patrons->next ) { |
|
|
2974 |
# If there is a reserve that cannot be filled we are done |
2975 |
return ( 0, "on_reserve" ) if ( $seen > $reservable ); |
2963 |
my $items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $item->biblionumber, patron => $patron }); |
2976 |
my $items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $item->biblionumber, patron => $patron }); |
2964 |
while ( my $other_item = $items->next ) { |
2977 |
while ( my $other_item = $items->next ) { |
2965 |
next if $matched_items{$other_item->itemnumber} == 1; |
2978 |
next if defined $matched_items{$other_item->itemnumber}; |
2966 |
next if IsItemOnHoldAndFound( $other_item->itemnumber ); |
2979 |
next if IsItemOnHoldAndFound( $other_item->itemnumber ); |
2967 |
next unless IsAvailableForItemLevelRequest($other_item, $patron, undef, $items_any_available); |
2980 |
next unless IsAvailableForItemLevelRequest($other_item, $patron, undef, $items_any_available); |
2968 |
next unless CanItemBeReserved($patron,$other_item,undef,{ignore_hold_counts=>1})->{status} eq 'OK'; |
2981 |
next unless CanItemBeReserved($patron,$other_item,undef,{ignore_hold_counts=>1})->{status} eq 'OK'; |
2969 |
push @reservable, $other_item->itemnumber; |
2982 |
# NOTE: At checkin we call 'CheckReserves' which checks hold 'policy' |
2970 |
if (@reservable >= @borrowernumbers) { |
2983 |
# CanItemBeReserved checks 'rules' and 'policies' which means |
|
|
2984 |
# items will fill holds at checkin that are rejected here |
2985 |
$reservable++; |
2986 |
if ($reservable >= $patron_count) { |
2971 |
$resfound = 0; |
2987 |
$resfound = 0; |
2972 |
last PATRON; |
2988 |
last PATRON; |
2973 |
} |
2989 |
} |
Lines 2975-2980
sub CanBookBeRenewed {
Link Here
|
2975 |
last; |
2991 |
last; |
2976 |
} |
2992 |
} |
2977 |
$items->reset; |
2993 |
$items->reset; |
|
|
2994 |
$seen++; |
2978 |
} |
2995 |
} |
2979 |
} |
2996 |
} |
2980 |
} |
2997 |
} |