Bug 18259: Koha::Biblio - Remove GetSubscriptionsId
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 13 Mar 2017 18:38:54 +0000 (15:38 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 14 Jul 2017 15:02:30 +0000 (12:02 -0300)
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

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Biblio.pm
acqui/basket.pl
acqui/parcel.pl

index 78cafdf..f55a383 100644 (file)
@@ -101,7 +101,6 @@ BEGIN {
 
       &CountItemsIssued
       &CountBiblioInOrders
-      &GetSubscriptionsId
     );
 
     # To modify something
@@ -3434,26 +3433,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 );
index b3dfa8b..02b9eba 100755 (executable)
@@ -134,10 +134,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}),
@@ -145,7 +145,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}),
@@ -474,20 +474,20 @@ 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 );
         my $itemholds  = $biblio->holds->search({ itemnumber => { -in => \@items } })->count;
 
         # 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;
index 4ba5b5f..14518a8 100755 (executable)
@@ -241,7 +241,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 );
@@ -253,13 +253,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;