From 1b5a7e2f5721ed14d1539abc6edc6b3015369739 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 | 7 ++++++- 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, 24 insertions(+), 8 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 7af8619..6792b75 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2619,9 +2619,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 5ff12e4..e6b4aef 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -1465,7 +1465,12 @@ sub IsAvailableForItemLevelRequest { if (C4::Context->preference('AllowOnShelfHolds')) { return $available_per_item; } else { - return ($available_per_item and ($item->{onloan} or GetReserveStatus($itemnumber) eq "Waiting")); + return ( + $available_per_item + and ($item->{onloan} + or GetReserveStatus($itemnumber) eq "Waiting" + or $item->{notforloan} < 0 ) + ); } } diff --git a/C4/VirtualShelves/Page.pm b/C4/VirtualShelves/Page.pm index dd7d5f4..0355559 100644 --- a/C4/VirtualShelves/Page.pm +++ b/C4/VirtualShelves/Page.pm @@ -278,7 +278,7 @@ sub shelfpage { if(!defined($this_item->{'size'})) { $this_item->{'size'} = "" }; #TT has problems with size # 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 94055a9..73a54d9 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 2a69244..c7f7fb4 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 9d0851f..73ca0db 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -391,7 +391,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 dfe651e..efcc944 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -593,7 +593,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, -- 1.7.2.5