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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #use warnings; FIXME - Bug 2505
23 use vars
qw($VERSION @ISA @EXPORT);
26 # set the version for version checking
31 &GetBookSeller &GetBooksellersWithLateOrders &GetBookSellerFromId
41 C4::Bookseller - Koha functions for dealing with booksellers.
49 The functions in this module deal with booksellers. They allow to
50 add a new bookseller, to modify it or to get some informations around
57 @results = &GetBookSeller($searchstring);
59 Looks up a book seller. C<$searchstring> may be either a book seller
60 ID, or a string to look for in the book seller's name.
62 C<@results> is an array of references-to-hash, whose keys are the fields of of the
63 aqbooksellers table in the Koha database.
67 # FIXME: This function is badly named. It should be something like
68 # SearchBookSellersByName. It is NOT a singular return value.
70 sub GetBookSeller
($) {
71 my ($searchstring) = @_;
72 my $dbh = C4
::Context
->dbh;
73 my $query = "SELECT * FROM aqbooksellers WHERE name LIKE ?";
74 my $sth =$dbh->prepare($query);
75 $sth->execute( "%$searchstring%" );
77 # count how many baskets this bookseller has.
78 # if it has none, the bookseller can be deleted
79 my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?");
80 while ( my $data = $sth->fetchrow_hashref ) {
81 $sth2->execute($data->{id
});
82 $data->{basketcount
} = $sth2->fetchrow();
83 push( @results, $data );
90 sub GetBookSellerFromId
($) {
91 my $id = shift or return;
92 my $dbh = C4
::Context
->dbh();
93 my $query = "SELECT * FROM aqbooksellers WHERE id = ?";
94 my $sth =$dbh->prepare($query);
96 if (my $data = $sth->fetchrow_hashref()){
97 my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?");
99 $data->{basketcount
}=$sth2->fetchrow();
104 #-----------------------------------------------------------------#
106 =head2 GetBooksellersWithLateOrders
108 %results = &GetBooksellersWithLateOrders;
110 Searches for suppliers with late orders.
114 sub GetBooksellersWithLateOrders
{
115 my ($delay,$branch) = @_; # FIXME: Branch argument unused.
116 my $dbh = C4
::Context
->dbh;
118 # FIXME NOT quite sure that this operation is valid for DBMs different from Mysql, HOPING so
119 # should be tested with other DBMs
122 my $dbdriver = C4
::Context
->config("db_scheme") || "mysql";
123 if ( $dbdriver eq "mysql" ) {
125 SELECT DISTINCT aqbasket.booksellerid, aqbooksellers.name
126 FROM aqorders LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
127 LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id
128 WHERE (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY)
129 AND (datereceived = '' OR datereceived IS NULL))
134 SELECT DISTINCT aqbasket.booksellerid, aqbooksellers.name
135 FROM aqorders LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno
136 LEFT JOIN aqbooksellers ON aqbasket.aqbooksellerid = aqbooksellers.id
137 WHERE (closedate < (CURDATE( )-(INTERVAL $delay DAY)))
138 AND (datereceived = '' OR datereceived IS NULL))
142 my $sth = $dbh->prepare($strsth);
145 while ( my ( $id, $name ) = $sth->fetchrow ) {
146 $supplierlist{$id} = $name;
149 return %supplierlist;
152 #--------------------------------------------------------------------#
156 $id = &AddBookseller($bookseller);
158 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
159 keys are the fields of the aqbooksellers table in the Koha database.
160 All fields must be present.
162 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, discount,
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->{'discount'}, $data->{'notes'}
197 # return the id of this new supplier
198 # FIXME: no protection against simultaneous addition: max(id) might be wrong!
203 $sth = $dbh->prepare($query);
205 return scalar($sth->fetchrow);
208 #-----------------------------------------------------------------#
212 &ModBookseller($bookseller);
214 Updates the information for a given bookseller. C<$bookseller> is a
215 reference-to-hash whose keys are the fields of the aqbooksellers table
216 in the Koha database. It must contain entries for all of the fields.
217 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
219 The easiest way to get all of the necessary fields is to look up a
220 book seller with C<&GetBookseller>, modify what's necessary, then call
221 C<&ModBookseller> with the result.
227 my $dbh = C4
::Context
->dbh;
230 SET name=?,address1=?,address2=?,address3=?,address4=?,
231 postal=?,phone=?,fax=?,url=?,contact=?,contpos=?,
232 contphone=?,contfax=?,contaltphone=?,contemail=?,
233 contnotes=?,active=?,listprice=?, invoiceprice=?,
234 gstreg=?,listincgst=?,invoiceincgst=?,
235 discount=?, notes=?, gstrate=?
238 my $sth = $dbh->prepare($query);
240 $data->{'name'}, $data->{'address1'},
241 $data->{'address2'}, $data->{'address3'},
242 $data->{'address4'}, $data->{'postal'},
243 $data->{'phone'}, $data->{'fax'},
244 $data->{'url'}, $data->{'contact'},
245 $data->{'contpos'}, $data->{'contphone'},
246 $data->{'contfax'}, $data->{'contaltphone'},
247 $data->{'contemail'}, $data->{'contnotes'},
248 $data->{'active'}, $data->{'listprice'},
249 $data->{'invoiceprice'}, $data->{'gstreg'},
250 $data->{'listincgst'}, $data->{'invoiceincgst'},
252 $data->{'notes'}, $data->{'gstrate'},
260 &DelBookseller($booksellerid);
262 delete the supplier identified by $booksellerid
263 This sub can be called only if the supplier has no order.
269 my $dbh=C4
::Context
->dbh;
270 my $sth=$dbh->prepare("DELETE FROM aqbooksellers WHERE id=?");
280 Koha Development Team <http://koha-community.org/>