# building query parameters
my %where = (
'me.found' => undef,
- 'me.priority' => 1,
+ 'me.priority' => { '!=' => 0 },
'me.suspend' => 0,
'itembib.itemlost' => 0,
'itembib.withdrawn' => 0,
'itembib.notforloan' => 0,
- 'itembib.itemnumber' => { -not_in => \'SELECT itemnumber FROM branchtransfers WHERE datearrived IS NULL' }
+ 'itembib.itemnumber' => { -not_in => \'SELECT itemnumber FROM branchtransfers WHERE datearrived IS NULL AND datecancelled IS NULL' }
);
# date boundaries
# get all distinct unfulfilled reserves
my $holds = Koha::Holds->search(
{ %where },
- { join => 'itembib', distinct => 1, columns => qw[me.biblionumber] }
+ { join => 'itembib', distinct => 1, columns => qw[me.biblionumber] }
);
+
my @biblionumbers = $holds->get_column('biblionumber');
my $all_items;
-foreach my $item ( $holds->get_items_that_can_fill ) {
- push @{$all_items->{$item->biblionumber}}, $item;
+if ( $holds->count ) {
+ foreach my $item ( $holds->get_items_that_can_fill->as_list ) {
+ push @{ $all_items->{ $item->biblionumber } }, $item;
+ }
}
# patrons count per biblio
my $patrons_count = {
map { $_->{biblionumber} => $_->{patrons_count} } @{ Koha::Holds->search(
- {},
+ { 'suspend' => 0 },
{
select => [ 'biblionumber', { count => { distinct => 'borrowernumber' } } ],
as => [qw( biblionumber patrons_count )],
{
join => ['itembib', 'biblio'],
select => ['me.biblionumber', 'me.reserve_id'],
+ order_by => { -desc => 'priority' }
}
)->unblessed
}
# make final holds_info array and fill with info
my @holds_info;
+my $seen = {};
foreach my $bibnum ( @biblionumbers ){
+ # Skip this record if it's already been handled
+ next if $seen->{$bibnum};
+ $seen->{$bibnum} = 1;
my $hold_info;
my $items = $all_items->{$bibnum};
from => $startdate,
to => $enddate,
holds_info => \@holds_info,
- "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1,
HoldsToPullStartDate => C4::Context->preference('HoldsToPullStartDate') || PULL_INTERVAL,
HoldsToPullEndDate => C4::Context->preference('ConfirmFutureHolds') || 0,
messages => \@messages,