From 26ad124667b05aec859d8f318a68a678764a5725 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 13 Mar 2017 15:38:54 -0300 Subject: [PATCH] Bug 18259: Koha::Biblio - Remove GetSubscriptionsId C4::Biblio::GetSubscriptionsId can be replaced using Koha::Biblio->subscriptions Test plan: Create a new order for a bibliographic record Create a new subscription on this biblio From the basket (acquisition), confirm that you are not able to delete the order with the biblio ("Can't cancel order and delete catalog record 1 subscription(s) left") Receive the order On the parcel page, confirm that you are not able to delete the order with the biblio --- C4/Biblio.pm | 21 --------------------- acqui/basket.pl | 14 +++++++------- acqui/parcel.pl | 8 ++++---- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index ef2e432..0493377 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -105,7 +105,6 @@ BEGIN { &CountItemsIssued &CountBiblioInOrders - &GetSubscriptionsId ); # To modify something @@ -3537,26 +3536,6 @@ sub CountBiblioInOrders { return ($count); } -=head2 GetSubscriptionsId - - $subscriptions = &GetSubscriptionsId($biblionumber); - -This function return an array of subscriptionid with $biblionumber - -=cut - -sub GetSubscriptionsId { - my ($biblionumber) = @_; - my $dbh = C4::Context->dbh; - my $query = "SELECT subscriptionid - FROM subscription - WHERE biblionumber=?"; - my $sth = $dbh->prepare($query); - $sth->execute($biblionumber); - my @subscriptions = $sth->fetchrow_array; - return (@subscriptions); -} - =head2 prepare_host_field $marcfield = prepare_host_field( $hostbiblioitem, $marcflavour ); diff --git a/acqui/basket.pl b/acqui/basket.pl index 4940821..9a339b3 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -133,10 +133,10 @@ if ( $op eq 'delete_confirm' ) { my $biblio = Koha::Biblios->find( $biblionumber ); my $countbiblio = CountBiblioInOrders($biblionumber); my $ordernumber = $myorder->{'ordernumber'}; - my $subscriptions = scalar GetSubscriptionsId ($biblionumber); + my $has_subscriptions = $biblio->subscriptions->count; my $itemcount = $biblio->items->count; my $error; - if ($countbiblio == 0 && $itemcount == 0 && $subscriptions == 0) { + if ($countbiblio == 0 && $itemcount == 0 && not $has_subscriptions ) { $error = DelBiblio($myorder->{biblionumber}) } else { push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}), @@ -144,7 +144,7 @@ if ( $op eq 'delete_confirm' ) { author=> $myorder->{'author'}, countbiblio=> $countbiblio, itemcount=>$itemcount, - subscriptions=>$subscriptions}; + subscriptions => $has_subscriptions}; } if ($error) { push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}), @@ -466,7 +466,7 @@ sub get_order_infos { my $biblio = Koha::Biblios->find( $biblionumber ); my $countbiblio = CountBiblioInOrders($biblionumber); my $ordernumber = $order->{'ordernumber'}; - my @subscriptions = GetSubscriptionsId ($biblionumber); + my $has_subscriptions = $biblio->subscriptions->count; my $itemcount = $biblio->items->count; my $holds_count = $biblio->holds->count; my @items = GetItemnumbersFromOrder( $ordernumber ); @@ -478,13 +478,13 @@ sub get_order_infos { } } # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680 - $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds_count); + $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !($has_subscriptions) && !($holds_count); $line{items} = ($itemcount) - (scalar @items); $line{left_item} = 1 if $line{items} >= 1; $line{left_biblio} = 1 if $countbiblio > 1; $line{biblios} = $countbiblio - 1; - $line{left_subscription} = 1 if scalar @subscriptions >= 1; - $line{subscriptions} = scalar @subscriptions; + $line{left_subscription} = 1 if $has_subscriptions; + $line{subscriptions} = $has_subscriptions; ($holds_count >= 1) ? $line{left_holds} = 1 : $line{left_holds} = 0; $line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); $line{holds} = $holds_count; diff --git a/acqui/parcel.pl b/acqui/parcel.pl index 4e11f2b..84ece95 100755 --- a/acqui/parcel.pl +++ b/acqui/parcel.pl @@ -239,7 +239,7 @@ unless( defined $invoice->{closedate} ) { my $biblio = Koha::Biblios->find( $biblionumber ); my $countbiblio = CountBiblioInOrders($biblionumber); my $ordernumber = $line{'ordernumber'}; - my @subscriptions = GetSubscriptionsId ($biblionumber); + my $has_subscriptions = $biblio->subscriptions->count; my $itemcount = $biblio->items->count; my $holds_count = $biblio->holds->count; my @items = GetItemnumbersFromOrder( $ordernumber ); @@ -257,13 +257,13 @@ unless( defined $invoice->{closedate} ) { $line{firstnamesuggestedby} = $suggestion->{firstnamesuggestedby}; # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680 - $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds_count); + $line{can_del_bib} = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !($has_subscriptions) && !($holds_count); $line{items} = ($itemcount) - (scalar @items); $line{left_item} = 1 if $line{items} >= 1; $line{left_biblio} = 1 if $countbiblio > 1; $line{biblios} = $countbiblio - 1; - $line{left_subscription} = 1 if scalar @subscriptions >= 1; - $line{subscriptions} = scalar @subscriptions; + $line{left_subscription} = 1 if $has_subscriptions; + $line{subscriptions} = $has_subscriptions; $line{left_holds} = ($holds_count >= 1) ? 1 : 0; $line{left_holds_on_order} = 1 if $line{left_holds}==1 && ($line{items} == 0 || $itemholds ); $line{holds} = $holds_count; -- 2.1.4