From 9e125a7a75a4023b68bd93806a01725fae56590d Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 7 Jan 2013 09:34:24 -0500 Subject: [PATCH] Bug 6918: Can't place holds on 'on order' items with AllowOnShelfHolds off Test Plan: 1) Apply patch 2) Turn off AllowOnShelfHolds 3) Create a bib with one item, mark the item as 'on order' 4) Attempt to place a hold on the item, you should now be able to do so Signed-off-by: Andrew Fuerste-Henry --- C4/Biblio.pm | 17 ++++++++++++++--- C4/Reserves.pm | 12 +++++------- opac/opac-ISBDdetail.pl | 2 +- opac/opac-MARCdetail.pl | 2 +- opac/opac-detail.pl | 2 +- opac/opac-search.pl | 2 +- tools/batch_delete_records.pl | 4 ++-- 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 9eb3696a54..d327d584ab 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2523,14 +2523,25 @@ sub _adjust_pubyear { =head2 CountItemsIssued - my $count = CountItemsIssued( $biblionumber ); + my $count = CountItemsIssued( { biblionumber => $biblionumber, count_on_order => 0 || 1 ); =cut sub CountItemsIssued { - my ($biblionumber) = @_; + my ($params) = @_; + my $biblionumber = $params->{'biblionumber'}; + my $count_on_order = $params->{'count_on_order'}; + + my $sql = 'SELECT COUNT(*) AS issuedCount FROM items LEFT JOIN issues ON items.itemnumber = issues.itemnumber WHERE items.biblionumber = ?'; + + if ( $count_on_order ) { + $sql .= ' AND ( issues.itemnumber IS NOT NULL OR items.notforloan < 0 )'; + } else { + $sql .= ' AND issues.itemnumber IS NOT NULL'; + } + my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare('SELECT COUNT(*) as issuedCount FROM items, issues WHERE items.itemnumber = issues.itemnumber AND items.biblionumber = ?'); + my $sth = $dbh->prepare( $sql ); $sth->execute($biblionumber); my $row = $sth->fetchrow_hashref(); return $row->{'issuedCount'}; diff --git a/C4/Reserves.pm b/C4/Reserves.pm index 9c040bdc12..ba4d6a6342 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1279,17 +1279,15 @@ sub IsAvailableForItemLevelRequest { if ( $on_shelf_holds == 1 ) { return 1; - } elsif ( $on_shelf_holds == 2 ) { + } elsif ( $on_shelf_holds == 2 ) { # On shelf holds == "If all unavailable" # if we have this param predefined from outer caller sub, we just need # to return it, so we saving from having loop inside other loop: - return $items_any_available ? 0 : 1 - if defined $items_any_available; + $items_any_available //= ItemsAnyAvailableForHold( { biblionumber => $item->biblionumber, patron => $patron }); - my $any_available = ItemsAnyAvailableForHold( { biblionumber => $item->biblionumber, patron => $patron }); - return $any_available ? 0 : 1; + return !$items_any_available; } else { # on_shelf_holds == 0 "If any unavailable" (the description is rather cryptic and could still be improved) - return $item->onloan || IsItemOnHoldAndFound( $item->itemnumber ); + return $item->notforloan < 0 || $item->onloan || IsItemOnHoldAndFound( $item->itemnumber ); } } @@ -1319,7 +1317,7 @@ sub ItemsAnyAvailableForHold { $any_available = 1 unless $i->itemlost - || $i->notforloan > 0 + || $i->notforloan != 0 || $i->withdrawn || $i->onloan || IsItemOnHoldAndFound( $i->id ) diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index cc4b5b8d1a..dac22e0732 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -182,7 +182,7 @@ while ( my $item = $items->next ) { unless $allow_onshelf_holds; } -if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) { +if( $allow_onshelf_holds || CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) || $biblio->has_items_waiting_or_intransit ) { $template->param( ReservableItems => 1 ); } diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index b835f1bdea..b934a9c009 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -143,7 +143,7 @@ for my $itm (@all_items) { last if $allow_onshelf_holds; } -if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) { +if ( $allow_onshelf_holds || CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) || $biblio->has_items_waiting_or_intransit ) { $template->param( ReservableItems => 1 ); } diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index f1100878bd..422a9de151 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -731,7 +731,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { } } -if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) { +if ( $allow_onshelf_holds || CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) || $biblio->has_items_waiting_or_intransit ) { $template->param( ReservableItems => 1 ); } diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 01887f283a..b6bea2858c 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -710,7 +710,7 @@ for (my $i=0;$i<@servers;$i++) { if (C4::Context->preference('TagsEnabled') and C4::Context->preference('TagsShowOnList')) { if ( my $bibnum = $res->{biblionumber} ) { - $res->{itemsissued} = CountItemsIssued( $bibnum ); + $res->{itemsissued} = CountItemsIssued( { biblionumber => $bibnum } ); $res->{'TagLoop'} = get_tags({ biblionumber => $bibnum, approved => 1, diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl index 1dccbae99f..18cf20b023 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -96,7 +96,7 @@ if ( $op eq 'form' ) { my $record = &GetMarcBiblio({ biblionumber => $record_id }); $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')]; $biblio->{holds_count} = $holds_count; - $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id ); + $biblio->{issues_count} = C4::Biblio::CountItemsIssued({ biblionumber => $record_id, count_on_order => 1 }); push @records, $biblio; } else { # Retrieve authority information @@ -145,7 +145,7 @@ if ( $op eq 'form' ) { my $biblio = Koha::Biblios->find( $biblionumber ); # TODO Replace with $biblio->get_issues->count - if ( C4::Biblio::CountItemsIssued( $biblionumber ) ) { + if ( C4::Biblio::CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) ) { push @messages, { type => 'warning', code => 'item_issued', -- 2.11.0