1 package C4::Bookseller;
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
24 use vars qw($VERSION @ISA @EXPORT);
26 # set the version for version checking
27 $VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
31 &GetBookSeller &GetBooksellersWithLateOrders
39 C4::Bookseller - Koha functions for dealing with booksellers.
47 The functions in this module deal with booksellers. They allow to
48 add a new bookseller, to modify it or to get some informations around
57 #-------------------------------------------------------------------#
63 @results = &GetBookSeller($searchstring);
65 Looks up a book seller. C<$searchstring> may be either a book seller
66 ID, or a string to look for in the book seller's name.
68 C<@results> is an array of references-to-hash, whose keys are the fields of of the
69 aqbooksellers table in the Koha database.
76 my ($searchstring) = @_;
77 my $dbh = C4::Context->dbh;
81 WHERE name LIKE ? OR id = ?
83 my $sth =$dbh->prepare($query);
84 $sth->execute("$searchstring%", $searchstring );
86 while ( my $data = $sth->fetchrow_hashref ) {
87 push( @results, $data );
94 #-----------------------------------------------------------------#
96 =head3 GetBooksellersWithLateOrders
100 %results = &GetBooksellersWithLateOrders;
102 Searches for suppliers with late orders.
108 sub GetBooksellersWithLateOrders {
110 my $dbh = C4::Context->dbh;
112 # FIXME NOT quite sure that this operation is valid for DBMs different from Mysql, HOPING so
113 # should be tested with other DBMs
116 my $dbdriver = C4::Context->config("db_scheme") || "mysql";
117 if ( $dbdriver eq "mysql" ) {
119 SELECT DISTINCT aqbasket.booksellerid, aqbooksellers.name
120 FROM aqorders, aqbasket
121 LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
122 WHERE aqorders.basketno = aqbasket.basketno
123 AND (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY)
124 AND (datereceived = '' OR datereceived IS NULL))
129 SELECT DISTINCT aqbasket.booksellerid, aqbooksellers.name
130 FROM aqorders, aqbasket
131 LEFT JOIN aqbooksellers ON aqbasket.aqbooksellerid = aqbooksellers.id
132 WHERE aqorders.basketno = aqbasket.basketno
133 AND (closedate < (CURDATE( )-(INTERVAL $delay DAY)))
134 AND (datereceived = '' OR datereceived IS NULL))
138 my $sth = $dbh->prepare($strsth);
141 while ( my ( $id, $name ) = $sth->fetchrow ) {
142 $supplierlist{$id} = $name;
145 return %supplierlist;
148 #--------------------------------------------------------------------#
154 $id = &AddBookseller($bookseller);
156 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
157 keys are the fields of the aqbooksellers table in the Koha database.
158 All fields must be present.
160 Returns the ID of the newly-created bookseller.
168 my $dbh = C4::Context->dbh;
170 INSERT INTO aqbooksellers
172 name, address1, address2, address3, address4,
173 postal, phone, fax, url, contact,
174 contpos, contphone, contfax, contaltphone, contemail,
175 contnotes, active, listprice, invoiceprice, gstreg,
176 listincgst,invoiceincgst, specialty, discount, invoicedisc,
179 VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
181 my $sth = $dbh->prepare($query);
183 $data->{'name'}, $data->{'address1'},
184 $data->{'address2'}, $data->{'address3'},
185 $data->{'address4'}, $data->{'postal'},
186 $data->{'phone'}, $data->{'fax'},
187 $data->{'url'}, $data->{'contact'},
188 $data->{'contpos'}, $data->{'contphone'},
189 $data->{'contfax'}, $data->{'contaltphone'},
190 $data->{'contemail'}, $data->{'contnotes'},
191 $data->{'active'}, $data->{'listprice'},
192 $data->{'invoiceprice'}, $data->{'gstreg'},
193 $data->{'listincgst'}, $data->{'invoiceincgst'},
194 $data->{'specialty'}, $data->{'discount'},
195 $data->{'invoicedisc'}, $data->{'nocalc'},
199 # return the id of this new supplier
204 my $sth = $dbh->prepare($query);
206 return scalar($sth->fetchrow);
209 #-----------------------------------------------------------------#
215 &ModSupplier($bookseller);
217 Updates the information for a given bookseller. C<$bookseller> is a
218 reference-to-hash whose keys are the fields of the aqbooksellers table
219 in the Koha database. It must contain entries for all of the fields.
220 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
222 The easiest way to get all of the necessary fields is to look up a
223 book seller with C<&booksellers>, modify what's necessary, then call
224 C<&ModSupplier> with the result.
232 my $dbh = C4::Context->dbh;
235 SET name=?,address1=?,address2=?,address3=?,address4=?,
236 postal=?,phone=?,fax=?,url=?,contact=?,contpos=?,
237 contphone=?,contfax=?,contaltphone=?,contemail=?,
238 contnotes=?,active=?,listprice=?, invoiceprice=?,
239 gstreg=?, listincgst=?,invoiceincgst=?,
240 specialty=?,discount=?,invoicedisc=?,nocalc=?, notes=?
243 my $sth = $dbh->prepare($query);
245 $data->{'name'}, $data->{'address1'},
246 $data->{'address2'}, $data->{'address3'},
247 $data->{'address4'}, $data->{'postal'},
248 $data->{'phone'}, $data->{'fax'},
249 $data->{'url'}, $data->{'contact'},
250 $data->{'contpos'}, $data->{'contphone'},
251 $data->{'contfax'}, $data->{'contaltphone'},
252 $data->{'contemail'}, $data->{'contnotes'},
253 $data->{'active'}, $data->{'listprice'},
254 $data->{'invoiceprice'}, $data->{'gstreg'},
255 $data->{'listincgst'}, $data->{'invoiceincgst'},
256 $data->{'specialty'}, $data->{'discount'},
257 $data->{'invoicedisc'}, $data->{'nocalc'},
258 $data->{'notes'}, $data->{'id'}
264 END { } # module clean-up code here (global destructor)
274 Koha Developement team <info@koha.org>