From e38ab356b54f9786437d1f7f8d7d4979384b9f16 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 --- C4/Biblio.pm | 15 +++++++++++++-- C4/Reserves.pm | 2 +- C4/VirtualShelves/Page.pm | 2 +- opac/opac-ISBDdetail.pl | 2 +- opac/opac-MARCdetail.pl | 2 +- opac/opac-detail.pl | 2 +- opac/opac-search.pl | 2 +- 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 1b88286..d92a97a 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2637,9 +2637,20 @@ more. =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 a380bf0..62df806 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1441,7 +1441,7 @@ sub IsAvailableForItemLevelRequest { if (C4::Context->preference('AllowOnShelfHolds')) { return $available_per_item; } else { - return ($available_per_item and ($item->{onloan} or GetReserveStatus($itemnumber) eq "W")); + return ($available_per_item and ($item->{onloan} or $item->{notforloan} < 0 or GetReserveStatus($itemnumber) eq "W" )); } } diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index 586384d..7d1809c 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -271,7 +271,7 @@ sub shelfpage { $this_item->{'normalized_isbn'} = GetNormalizedISBN(undef,$record,$marcflavour); # Getting items infos for location display my @items_infos = &GetItemsLocationInfo( $this_item->{'biblionumber'}); - $this_item->{'itemsissued'} = CountItemsIssued( $this_item->{'biblionumber'} ); + $this_item->{'itemsissued'} = CountItemsIssued({ biblionumber => $this_item->{'biblionumber'} }); $this_item->{'ITEM_RESULTS'} = \@items_infos; if ( grep {$_ eq $biblionumber} @cart_list) { $this_item->{'incart'} = 1; diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index be62879..4b82fe2 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -81,7 +81,7 @@ if($query->cookie("bib_list")){ } $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); +$template->param( 'ItemsIssued' => CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) ); my $marcflavour = C4::Context->preference("marcflavour"); my $record = GetMarcBiblio($biblionumber); diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index ac13a9d..5926796 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -94,7 +94,7 @@ if($query->cookie("bib_list")){ } $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); +$template->param( 'ItemsIssued' => CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) ); # adding the $RequestOnOpac param my $RequestOnOpac; diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 94edb35..d86ca5c 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -390,7 +390,7 @@ if ($session->param('busc')) { $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); +$template->param( 'ItemsIssued' => CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) ); diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 97a7bc4..1ef7abf 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -550,7 +550,7 @@ for (my $i=0;$i<@servers;$i++) { $tag_quantity = C4::Context->preference('TagsShowOnList')) { foreach (@newresults) { my $bibnum = $_->{biblionumber} or next; - $_->{itemsissued} = CountItemsIssued( $bibnum ); + $_->{itemsissued} = CountItemsIssued({ biblionumber => $bibnum }); $_ ->{'TagLoop'} = get_tags({biblionumber=>$bibnum, approved=>1, 'sort'=>'-weight', limit=>$tag_quantity }); } -- 1.7.2.5