From 785d764f38919e7b98e4d4e8ad8991aa44ed784c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 2 Dec 2020 09:23:42 +0100 Subject: [PATCH] Bug 27131: Add get_items_that_can_fill --- Koha/Holds.pm | 34 ++++++++++++++++++++++++++++++++++ circ/pendingreserves.pl | 19 +++---------------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/Koha/Holds.pm b/Koha/Holds.pm index 604953d4c9..4a25babff5 100644 --- a/Koha/Holds.pm +++ b/Koha/Holds.pm @@ -92,6 +92,40 @@ sub forced_hold_level { return; } +sub get_items_that_can_fill { + my ( $self ) = @_; + + my @biblionumbers = $self->get_column('biblionumber'); + + my @branchtransfers = map { $_->itemnumber } + Koha::Item::Transfers->search( + { datearrived => undef }, + { + columns => ['itemnumber'], + collapse => 1, + } + ); + my @waiting_holds = map { $_->itemnumber } + Koha::Holds->search( + { 'found' => 'W' }, + { + columns => ['itemnumber'], + collapse => 1, + } + ); + + return Koha::Items->search( + { + biblionumber => { in => \@biblionumbers }, + itemlost => 0, + withdrawn => 0, + notforloan => 0, + onloan => undef, + itemnumber => { -not_in => [ @branchtransfers, @waiting_holds ] }, + } + ); +} + =head3 type =cut diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index bc7b25b001..7017c5e5b7 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -186,27 +186,14 @@ if ( C4::Context->preference('IndependentBranches') ){ } # get all distinct unfulfilled reserves -my @biblionumbers = Koha::Holds->search( +my $holds = Koha::Holds->search( { %where }, { join => 'itembib', alias => 'reserve', distinct => 1, columns => qw[me.biblionumber] } -)->get_column('biblionumber'); - -my @branchtransfers = map { $_->itemnumber } Koha::Item::Transfers->search({ datearrived => undef }, { columns => [ 'itemnumber' ], collapse => 1 }); -my @waiting_holds = map { $_->itemnumber } Koha::Holds->search({'found' => 'W'}, { columns => [ 'itemnumber' ], collapse => 1 }); - -my @all_items = Koha::Items->search( - { - biblionumber => { in => \@biblionumbers }, - itemlost => 0, - withdrawn => 0, - notforloan => 0, - onloan => undef, - itemnumber => { -not_in => [ @branchtransfers, @waiting_holds ] }, - } ); +my @biblionumbers = $holds->get_column('biblionumber'); my $all_items; -foreach my $item ( @all_items ) { +foreach my $item ( $holds->get_items_that_can_fill ) { push @{$all_items->{$item->biblionumber}}, $item; } -- 2.20.1