@@ -, +, @@ --- C4/HoldsQueue.pm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) --- a/C4/HoldsQueue.pm +++ a/C4/HoldsQueue.pm @@ -320,7 +320,7 @@ sub GetItemsAvailableToFillHoldRequestsForBib { my ($biblionumber, $branches_to_use) = @_; my $dbh = C4::Context->dbh; - my $items_query = "SELECT itemnumber, homebranch, holdingbranch, itemtypes.itemtype AS itype + my $items_query = "SELECT items.itemnumber, homebranch, holdingbranch, itemtypes.itemtype AS itype FROM items "; if (C4::Context->preference('item-level_itypes')) { @@ -329,14 +329,17 @@ sub GetItemsAvailableToFillHoldRequestsForBib { $items_query .= "JOIN biblioitems USING (biblioitemnumber) LEFT JOIN itemtypes USING (itemtype) "; } - $items_query .= "WHERE items.notforloan = 0 + $items_query .= " LEFT JOIN branchtransfers ON (items.itemnumber = branchtransfers.itemnumber)"; + $items_query .= " WHERE items.notforloan = 0 AND holdingbranch IS NOT NULL AND itemlost = 0 AND withdrawn = 0"; + $items_query .= " AND branchtransfers.datearrived IS NULL + AND branchtransfers.datecancelled IS NULL"; $items_query .= " AND damaged = 0" unless C4::Context->preference('AllowHoldsOnDamagedItems'); $items_query .= " AND items.onloan IS NULL AND (itemtypes.notforloan IS NULL OR itemtypes.notforloan = 0) - AND itemnumber NOT IN ( + AND items.itemnumber NOT IN ( SELECT itemnumber FROM reserves WHERE biblionumber = ? @@ -354,12 +357,11 @@ sub GetItemsAvailableToFillHoldRequestsForBib { $sth->execute(@params); my $itm = $sth->fetchall_arrayref({}); - my @items = grep { ! scalar GetTransfers($_->{itemnumber}) } @$itm; return [ grep { my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype}); $_->{holdallowed} = $rule->{holdallowed}; $_->{hold_fulfillment_policy} = $rule->{hold_fulfillment_policy}; - } @items ]; + } @{$itm} ]; } =head2 _checkHoldPolicy --