my ( $borr ) = GetMember( borrowernumber => $borrowernumber );
my $patron = Koha::Patrons->find( $borrowernumber );
+my $can_place_hold_if_available_at_pickup = C4::Context->preference('OPACHoldsIfAvailableAtPickup');
+unless ( $can_place_hold_if_available_at_pickup ) {
+ my @patron_categories = split '\|', C4::Context->preference('OPACHoldsIfAvailableAtPickupExceptions');
+ if ( @patron_categories ) {
+ $can_place_hold_if_available_at_pickup = grep /$borr->{categorycode}/, @patron_categories;
+ }
+}
+
# check if this user can place a reserve, -1 means use sys pref, 0 means dont block, 1 means block
if ( $patron->category->effective_BlockExpiredPatronOpacActions ) {
$canreserve = 0;
}
- unless ( C4::Context->preference('OPACHoldsIfAvailableAtPickup') ) {
- $canreserve = 0 if Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch })->count;
+ unless ( $can_place_hold_if_available_at_pickup ) {
+ my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch });
+ my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
+ my $nb_of_items_unavailable = $items_in_this_library->search({ -or => { lost => { '!=' => 0 }, damaged => { '!=' => 0 }, } });
+ if ( $items_in_this_library->count > $nb_of_items_issued + $nb_of_items_unavailable ) {
+ $canreserve = 0
+ }
}
my $itemtype = $query->param('itemtype') || undef;
}
$numCopiesAvailable++;
- if ( not C4::Context->preference('OPACHoldsIfAvailableAtPickup') ) {
- push @not_available_at, $itemInfo->{holdingbranch};
+ unless ( $can_place_hold_if_available_at_pickup ) {
+ my $items_in_this_library = Koha::Items->search({ biblionumber => $itemInfo->{biblionumber}, holdingbranch => $itemInfo->{holdingbranch} });
+ my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
+ if ( $items_in_this_library->count > $nb_of_items_issued ) {
+ push @not_available_at, $itemInfo->{holdingbranch};
+ }
}
}
$biblioLoopIter{not_available_at} = \@not_available_at ;
}
- unless ( C4::Context->preference('OPACHoldsIfAvailableAtPickup') ) {
+ unless ( $can_place_hold_if_available_at_pickup ) {
@not_available_at = uniq @not_available_at;
$biblioLoopIter{not_available_at} = \@not_available_at ;
# The record is not holdable is not available at any of the libraries