} else {
- # order non-cancelled holds by ready-for-pickup, then active, followed by suspended
+ # order non-cancelled holds by shelf_time, then active, followed by suspended
$holds_query->{order_by} = {ahr => ['shelf_time', 'frozen', 'request_time']};
$holds_query->{where}->{cancel_time} = undef;
}
my $hold_ids = $e->json_query($holds_query);
$hold_ids = [ map { $_->{id} } @$hold_ids ];
+ # do a follow up sort to determine which holds
+ # are in fact on the pickup lib's holds shelf.
+ # XXX not finding any way to compare column values in the
+ # order_by, which would make this much better/faster/cleaner
+ if($self->api_name !~ /canceled/) {
+
+ # find the available holds
+ my @avail_ids = map {$_->{id}}
+ @{$e->json_query({
+ select => {ahr => ['id']},
+ from => 'ahr',
+ where => {
+ id => $hold_ids,
+ current_shelf_lib => {'=' => {'+ahr' => 'pickup_lib'}}
+ }
+ })
+ };
+ # find the non-available holds
+ my @non_avail;
+ for my $id (@$hold_ids) {
+ push(@non_avail, $id) unless grep { $_ == $id } @avail_ids;
+ }
+ $hold_ids = [@avail_ids, @non_avail];
+ }
+
return $hold_ids if $self->api_name =~ /id_list/;
my @holds;