Bug 13407: Bumping required version of PDF::Reuse
[koha.git] / C4 / Bookseller.pm
index 768a8c3..3b1e58f 100644 (file)
@@ -28,7 +28,7 @@ use C4::Bookseller::Contact;
 # set the version for version checking
 our $VERSION   = 3.07.00.049;
 our @EXPORT_OK = qw(
-  GetBookSeller GetBooksellersWithLateOrders GetBookSellerFromId
+  GetBooksellersWithLateOrders
   ModBookseller
   DelBookseller
   AddBookseller
@@ -50,55 +50,6 @@ a bookseller.
 
 =head1 FUNCTIONS
 
-=head2 GetBookSeller
-
-@results = GetBookSeller($searchstring);
-
-Looks up a book seller. C<$searchstring> is a string to look for in the
-book seller's name.
-
-C<@results> is an array of hash_refs whose keys are the fields of of the
-aqbooksellers table in the Koha database.
-
-=cut
-
-sub GetBookSeller {
-    my $searchstring = shift;
-    $searchstring = q{%} . $searchstring . q{%};
-    my $query = "
-        SELECT aqbooksellers.*, count(*) AS basketcount
-        FROM aqbooksellers
-        LEFT JOIN aqbasket ON aqbasket.booksellerid = aqbooksellers.id
-        WHERE name LIKE ? GROUP BY aqbooksellers.id ORDER BY name
-    ";
-
-    my $dbh           = C4::Context->dbh;
-    my $sth           = $dbh->prepare($query);
-    $sth->execute($searchstring);
-    my $resultset_ref = $sth->fetchall_arrayref( {} );
-    return @{$resultset_ref};
-}
-
-sub GetBookSellerFromId {
-    my $id = shift or return;
-    my $dbh = C4::Context->dbh;
-    my $vendor =
-      $dbh->selectrow_hashref( 'SELECT * FROM aqbooksellers WHERE id = ?',
-        {}, $id );
-    if ($vendor) {
-        ( $vendor->{basketcount} ) = $dbh->selectrow_array(
-            'SELECT count(*) FROM aqbasket where booksellerid = ?',
-            {}, $id );
-        ( $vendor->{subscriptioncount} ) = $dbh->selectrow_array(
-            'SELECT count(*) FROM subscription WHERE aqbooksellerid = ?',
-            {}, $id );
-        $vendor->{'contacts'} = C4::Bookseller::Contact->get_from_bookseller($id);
-    }
-    return $vendor;
-}
-
-#-----------------------------------------------------------------#
-
 =head2 GetBooksellersWithLateOrders
 
 %results = GetBooksellersWithLateOrders( $delay, $estimateddeliverydatefrom, $estimateddeliverydateto );
@@ -209,10 +160,12 @@ sub AddBookseller {
     # return the id of this new supplier
     my $id = $dbh->{'mysql_insertid'};
     if ($id && $contacts) {
-        $contacts->[0] = C4::Bookseller::Contact->new( $contacts->[0] )
-          unless ref $contacts->[0] eq 'C4::Bookseller::Contact';
-        $contacts->[0]->bookseller($id);
-        $contacts->[0]->save();
+        foreach my $contact (@$contacts) {
+            $contact = C4::Bookseller::Contact->new( $contact )
+                unless ref $contacts eq 'C4::Bookseller::Contact';
+            $contact->bookseller($id);
+            $contact->save();
+        }
     }
     return $id;
 }
@@ -229,7 +182,7 @@ in the Koha database. It must contain entries for all of the fields.
 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
 
 The easiest way to get all of the necessary fields is to look up a
-book seller with C<&GetBookseller>, modify what's necessary, then call
+book seller with C<Koha::Acquisition::Bookseller>, modify what's necessary, then call
 C<&ModBookseller> with the result.
 
 =cut
@@ -246,7 +199,7 @@ sub ModBookseller {
             discount=?,notes=?,gstrate=?,deliverytime=?
         WHERE id=?';
     my $sth = $dbh->prepare($query);
-    return $sth->execute(
+    my $cnt = $sth->execute(
         $data->{'name'},         $data->{'address1'},
         $data->{'address2'},     $data->{'address3'},
         $data->{'address4'},     $data->{'postal'},
@@ -260,13 +213,23 @@ sub ModBookseller {
         $data->{'id'}
     );
     $contacts ||= $data->{'contacts'};
+    my $contactquery = "DELETE FROM aqcontacts WHERE booksellerid = ?";
+    my @contactparams = ($data->{'id'});
     if ($contacts) {
-        $contacts->[0] = C4::Bookseller::Contact->new( $contacts->[0] )
-          unless ref $contacts->[0] eq 'C4::Bookseller::Contact';
-        $contacts->[0]->bookseller($data->{'id'});
-        $contacts->[0]->save();
+        foreach my $contact (@$contacts) {
+            $contact = C4::Bookseller::Contact->new( $contact )
+                unless ref $contacts eq 'C4::Bookseller::Contact';
+            $contact->bookseller($data->{'id'});
+            $contact->save();
+            push @contactparams, $contact->id if $contact->id;
+        }
+        if ($#contactparams > 0) {
+            $contactquery .= ' AND id NOT IN (' . ('?, ' x ($#contactparams - 1)) . '?);';
+        }
     }
-    return;
+    $sth = $dbh->prepare($contactquery);
+    $sth->execute(@contactparams);
+    return $cnt;
 }
 
 =head2 DelBookseller