From e2b1e607fb030c2ea440b458f99049b933eba547 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 +++++++++++++-- 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 ++-- 6 files changed, 19 insertions(+), 8 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index b259176557..732ca3ccf0 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -2686,9 +2686,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/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index a3cb1a9705..53e66c5836 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -79,7 +79,7 @@ if(my $cart_list = $query->cookie("bib_list")){ } } -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); +$template->param( 'ItemsIssued' => CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) ); my $marcflavour = C4::Context->preference("marcflavour"); diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 9605cdd7e6..52238d9df1 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -137,7 +137,7 @@ for my $itm (@all_items) { } $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds ); -$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 819e42692f..c1c97ba8e9 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -459,7 +459,7 @@ if ($session->param('busc')) { } -$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); +$template->param( 'ItemsIssued' => CountItemsIssued({ biblionumber => $biblionumber, count_on_order => 1 }) ); $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") ); # adding items linked via host biblios diff --git a/opac/opac-search.pl b/opac/opac-search.pl index ccde617022..7824339547 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -674,7 +674,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 8804e6292a..888bf58c19 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -85,7 +85,7 @@ if ( $op eq 'form' ) { $biblio->{subtitle} = GetRecordValue( 'subtitle', $record, GetFrameworkCode( $record_id ) ); $biblio->{itemnumbers} = C4::Items::GetItemnumbersForBiblio( $record_id ); $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 @@ -134,7 +134,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