$items_query .= "WHERE items.notforloan = 0
AND holdingbranch IS NOT NULL
AND itemlost = 0
- AND wthdrawn = 0";
+ AND withdrawn = 0";
$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)
my @items = grep { ! scalar GetTransfers($_->{itemnumber}) } @$itm;
return [ grep {
my $rule = GetBranchItemRule($_->{homebranch}, $_->{itype});
- $_->{holdallowed} = $rule->{holdallowed} != 0
+ $_->{holdallowed} = $rule->{holdallowed};
} @items ];
}
$itemnumber = $item->{itemnumber};
last;
}
- $itemnumber ||= $holding_branch_items->[0]->{itemnumber};
}
else {
warn "No transport costs for $pickup_branch";
last PULL_BRANCHES;
}
}
- $itemnumber ||= $items_by_branch{$holdingbranch}->[0]->{itemnumber}
- if $holdingbranch;
+
+ unless ( $itemnumber ) {
+ foreach my $current_item ( @{ $items_by_branch{$holdingbranch} } ) {
+ if ( $holdingbranch && ( $current_item->{holdallowed} == 2 || $pickup_branch eq $current_item->{homebranch} ) ) {
+ $itemnumber = $current_item->{itemnumber};
+ last; # quit this loop as soon as we have a suitable item
+ }
+ }
+ }
}
if ($itemnumber) {