partial fix for mantis #1498
[koha_fer] / C4 / Bookseller.pm
index c549d82..c18769a 100644 (file)
@@ -24,6 +24,7 @@ use vars qw($VERSION @ISA @EXPORT);
 BEGIN {
        # set the version for version checking
        $VERSION = 3.01;
+    require Exporter;
        @ISA    = qw(Exporter);
        @EXPORT = qw(
                &GetBookSeller &GetBooksellersWithLateOrders &GetBookSellerFromId
@@ -62,19 +63,22 @@ aqbooksellers table in the Koha database.
 
 =cut
 
-sub GetBookSeller {
+# FIXME: This function is badly named.  It should be something like 
+# SearchBookSellersByName.  It is NOT a singular return value.
+
+sub GetBookSeller($) {
     my ($searchstring) = @_;
     my $dbh = C4::Context->dbh;
     my $query = "SELECT * FROM aqbooksellers WHERE name LIKE ?";
     my $sth =$dbh->prepare($query);
-    $sth->execute( "$searchstring%" );
+    $sth->execute( "%$searchstring%" );
     my @results;
     # count how many baskets this bookseller has.
     # if it has none, the bookseller can be deleted
     my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?");
     while ( my $data = $sth->fetchrow_hashref ) {
         $sth2->execute($data->{id});
-        ($data->{basketcount}) = $sth2->fetchrow();
+        $data->{basketcount} = $sth2->fetchrow();
         push( @results, $data );
     }
     $sth->finish;
@@ -82,23 +86,19 @@ sub GetBookSeller {
 }
 
 
-sub GetBookSellerFromId {
-       my ($id) = @_;
+sub GetBookSellerFromId($) {
+       my ($id) = shift or return undef;
        my $dbh = C4::Context->dbh();
        my $query = "SELECT * FROM aqbooksellers WHERE id = ?";
        my $sth =$dbh->prepare($query);
        $sth->execute( $id );
        if (my $data = $sth->fetchrow_hashref()){
-               my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?"); 
+               my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?");
                $sth2->execute($id);
                $data->{basketcount}=$sth2->fetchrow();
-               $sth->finish;
-               $sth2->finish;
-               return ($data);         
-       }
-       else {
-               return 0;
+               return ($data);
        }
+       return 0;
 }
 #-----------------------------------------------------------------#
 
@@ -111,7 +111,7 @@ Searches for suppliers with late orders.
 =cut
 
 sub GetBooksellersWithLateOrders {
-    my ($delay,$branch) = @_;
+    my ($delay,$branch) = @_;  # FIXME: Branch argument unused.
     my $dbh   = C4::Context->dbh;
 
 # FIXME NOT quite sure that this operation is valid for DBMs different from Mysql, HOPING so
@@ -196,6 +196,7 @@ sub AddBookseller {
     );
 
     # return the id of this new supplier
+    # FIXME: no protection against simultaneous addition: max(id) might be wrong!
     $query = "
         SELECT max(id)
         FROM   aqbooksellers
@@ -207,9 +208,9 @@ sub AddBookseller {
 
 #-----------------------------------------------------------------#
 
-=head2 ModSupplier
+=head2 ModBookseller
 
-&ModSupplier($bookseller);
+&ModBookseller($bookseller);
 
 Updates the information for a given bookseller. C<$bookseller> is a
 reference-to-hash whose keys are the fields of the aqbooksellers table
@@ -217,8 +218,8 @@ 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<&booksellers>, modify what's necessary, then call
-C<&ModSupplier> with the result.
+book seller with C<&GetBookseller>, modify what's necessary, then call
+C<&ModBookseller> with the result.
 
 =cut
 
@@ -231,8 +232,8 @@ sub ModBookseller {
             postal=?,phone=?,fax=?,url=?,contact=?,contpos=?,
             contphone=?,contfax=?,contaltphone=?,contemail=?,
             contnotes=?,active=?,listprice=?, invoiceprice=?,
-            gstreg=?, listincgst=?,invoiceincgst=?,
-            specialty=?,discount=?,invoicedisc=?,nocalc=?, notes=?
+            gstreg=?,listincgst=?,invoiceincgst=?,
+            specialty=?,discount=?,invoicedisc=?,nocalc=?,notes=?,gstrate=?
         WHERE id=?
     ";
     my $sth    = $dbh->prepare($query);
@@ -250,7 +251,8 @@ sub ModBookseller {
         $data->{'listincgst'},   $data->{'invoiceincgst'},
         $data->{'specialty'},    $data->{'discount'},
         $data->{'invoicedisc'},  $data->{'nocalc'},
-        $data->{'notes'},        $data->{'id'}
+        $data->{'notes'},        $data->{'gstrate'},
+        $data->{'id'}
     );
     $sth->finish;
 }