From 919caa19c888cd1a01f9ddbcbbb39caa85f096e6 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 Signed-off-by: Andrew Nugged Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- 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 3ed65938b7..995d63bd9c 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -188,27 +188,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.39.5