Lines 1-6
Link Here
|
1 |
package C4::Bookseller; |
1 |
package C4::Bookseller; |
2 |
|
2 |
|
3 |
# Copyright 2000-2002 Katipo Communications |
3 |
# Copyright 2000-2002 Katipo Communications |
|
|
4 |
# Copyright 2010 PTFS Europe |
4 |
# |
5 |
# |
5 |
# This file is part of Koha. |
6 |
# This file is part of Koha. |
6 |
# |
7 |
# |
Lines 18-40
package C4::Bookseller;
Link Here
|
18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
19 |
|
20 |
|
20 |
use strict; |
21 |
use strict; |
21 |
#use warnings; FIXME - Bug 2505 |
22 |
use warnings; |
22 |
|
23 |
|
23 |
use vars qw($VERSION @ISA @EXPORT); |
24 |
use base qw( Exporter ); |
24 |
|
|
|
25 |
BEGIN { |
26 |
# set the version for version checking |
27 |
$VERSION = 3.01; |
28 |
require Exporter; |
29 |
@ISA = qw(Exporter); |
30 |
@EXPORT = qw( |
31 |
&GetBookSeller &GetBooksellersWithLateOrders &GetBookSellerFromId |
32 |
&ModBookseller |
33 |
&DelBookseller |
34 |
&AddBookseller |
35 |
); |
36 |
} |
37 |
|
25 |
|
|
|
26 |
# set the version for version checking |
27 |
our $VERSION = 4.01; |
28 |
our @EXPORT_OK = qw( |
29 |
GetBookSeller GetBooksellersWithLateOrders GetBookSellerFromId |
30 |
ModBookseller |
31 |
DelBookseller |
32 |
AddBookseller |
33 |
); |
38 |
|
34 |
|
39 |
=head1 NAME |
35 |
=head1 NAME |
40 |
|
36 |
|
Lines 54-145
a bookseller.
Link Here
|
54 |
|
50 |
|
55 |
=head2 GetBookSeller |
51 |
=head2 GetBookSeller |
56 |
|
52 |
|
57 |
@results = &GetBookSeller($searchstring); |
53 |
@results = GetBookSeller($searchstring); |
58 |
|
54 |
|
59 |
Looks up a book seller. C<$searchstring> may be either a book seller |
55 |
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. |
56 |
ID, or a string to look for in the book seller's name. |
61 |
|
57 |
|
62 |
C<@results> is an array of references-to-hash, whose keys are the fields of of the |
58 |
C<@results> is an array of hash_refs whose keys are the fields of of the |
63 |
aqbooksellers table in the Koha database. |
59 |
aqbooksellers table in the Koha database. |
64 |
|
60 |
|
65 |
=cut |
61 |
=cut |
66 |
|
62 |
|
67 |
# FIXME: This function is badly named. It should be something like |
63 |
sub GetBookSeller { |
68 |
# SearchBookSellersByName. It is NOT a singular return value. |
64 |
my $searchstring = shift; |
|
|
65 |
$searchstring = q{%} . $searchstring . q{%}; |
66 |
my $query = |
67 |
'select aqbooksellers.*, count(*) as basketcount from aqbooksellers left join aqbasket ' |
68 |
. 'on aqbasket.booksellerid = aqbooksellers.id where name lIke ? group by aqbooksellers.id order by name'; |
69 |
|
70 |
my $dbh = C4::Context->dbh; |
71 |
my $sth = $dbh->prepare($query); |
72 |
$sth->execute($searchstring); |
73 |
my $resultset_ref = $sth->fetchall_arrayref( {} ); |
74 |
return @{$resultset_ref}; |
75 |
} |
69 |
|
76 |
|
70 |
sub GetBookSeller($) { |
77 |
sub GetBookSellerFromId { |
71 |
my ($searchstring) = @_; |
78 |
my $id = shift or return; |
72 |
my $dbh = C4::Context->dbh; |
79 |
my $dbh = C4::Context->dbh; |
73 |
my $query = "SELECT * FROM aqbooksellers WHERE name LIKE ?"; |
80 |
my $vendor = |
74 |
my $sth =$dbh->prepare($query); |
81 |
$dbh->selectrow_hashref( 'SELECT * FROM aqbooksellers WHERE id = ?', |
75 |
$sth->execute( "%$searchstring%" ); |
82 |
{}, $id ); |
76 |
my @results; |
83 |
if ($vendor) { |
77 |
# count how many baskets this bookseller has. |
84 |
( $vendor->{basketcount} ) = $dbh->selectrow_array( |
78 |
# if it has none, the bookseller can be deleted |
85 |
'SELECT count(*) FROM aqbasket where booksellerid = ?', |
79 |
my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?"); |
86 |
{}, $id ); |
80 |
while ( my $data = $sth->fetchrow_hashref ) { |
|
|
81 |
$sth2->execute($data->{id}); |
82 |
$data->{basketcount} = $sth2->fetchrow(); |
83 |
push( @results, $data ); |
84 |
} |
87 |
} |
85 |
$sth->finish; |
88 |
return $vendor; |
86 |
return @results ; |
|
|
87 |
} |
89 |
} |
88 |
|
90 |
|
89 |
|
|
|
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); |
95 |
$sth->execute( $id ); |
96 |
if (my $data = $sth->fetchrow_hashref()){ |
97 |
my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?"); |
98 |
$sth2->execute($id); |
99 |
$data->{basketcount}=$sth2->fetchrow(); |
100 |
return $data; |
101 |
} |
102 |
return; |
103 |
} |
104 |
#-----------------------------------------------------------------# |
91 |
#-----------------------------------------------------------------# |
105 |
|
92 |
|
106 |
=head2 GetBooksellersWithLateOrders |
93 |
=head2 GetBooksellersWithLateOrders |
107 |
|
94 |
|
108 |
%results = &GetBooksellersWithLateOrders; |
95 |
%results = GetBooksellersWithLateOrders($delay); |
109 |
|
96 |
|
110 |
Searches for suppliers with late orders. |
97 |
Searches for suppliers with late orders. |
111 |
|
98 |
|
112 |
=cut |
99 |
=cut |
113 |
|
100 |
|
114 |
sub GetBooksellersWithLateOrders { |
101 |
sub GetBooksellersWithLateOrders { |
115 |
my ($delay,$branch) = @_; # FIXME: Branch argument unused. |
102 |
my $delay = shift; |
116 |
my $dbh = C4::Context->dbh; |
103 |
my $dbh = C4::Context->dbh; |
117 |
|
104 |
|
118 |
# FIXME NOT quite sure that this operation is valid for DBMs different from Mysql, HOPING so |
105 |
# TODO delay should be verified |
119 |
# should be tested with other DBMs |
106 |
my $query_string = |
120 |
|
107 |
"SELECT DISTINCT aqbasket.booksellerid, aqbooksellers.name |
121 |
my $strsth; |
108 |
FROM aqorders LEFT JOIN aqbasket ON aqorders.basketno=aqbasket.basketno |
122 |
my $dbdriver = C4::Context->config("db_scheme") || "mysql"; |
109 |
LEFT JOIN aqbooksellers ON aqbasket.booksellerid = aqbooksellers.id |
123 |
if ( $dbdriver eq "mysql" ) { |
110 |
WHERE (closedate < DATE_SUB(CURDATE( ),INTERVAL $delay DAY) |
124 |
$strsth = " |
111 |
AND (datereceived = '' OR datereceived IS NULL))"; |
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)) |
130 |
"; |
131 |
} |
132 |
else { |
133 |
$strsth = " |
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)) |
139 |
"; |
140 |
} |
141 |
|
112 |
|
142 |
my $sth = $dbh->prepare($strsth); |
113 |
my $sth = $dbh->prepare($query_string); |
143 |
$sth->execute; |
114 |
$sth->execute; |
144 |
my %supplierlist; |
115 |
my %supplierlist; |
145 |
while ( my ( $id, $name ) = $sth->fetchrow ) { |
116 |
while ( my ( $id, $name ) = $sth->fetchrow ) { |
Lines 165-172
Returns the ID of the newly-created bookseller.
Link Here
|
165 |
|
136 |
|
166 |
sub AddBookseller { |
137 |
sub AddBookseller { |
167 |
my ($data) = @_; |
138 |
my ($data) = @_; |
168 |
my $dbh = C4::Context->dbh; |
139 |
my $dbh = C4::Context->dbh; |
169 |
my $query = " |
140 |
my $query = q| |
170 |
INSERT INTO aqbooksellers |
141 |
INSERT INTO aqbooksellers |
171 |
( |
142 |
( |
172 |
name, address1, address2, address3, address4, |
143 |
name, address1, address2, address3, address4, |
Lines 176-183
sub AddBookseller {
Link Here
|
176 |
listincgst,invoiceincgst, gstrate, discount, |
147 |
listincgst,invoiceincgst, gstrate, discount, |
177 |
notes |
148 |
notes |
178 |
) |
149 |
) |
179 |
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |
150 |
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) | |
180 |
"; |
151 |
; |
181 |
my $sth = $dbh->prepare($query); |
152 |
my $sth = $dbh->prepare($query); |
182 |
$sth->execute( |
153 |
$sth->execute( |
183 |
$data->{'name'}, $data->{'address1'}, |
154 |
$data->{'name'}, $data->{'address1'}, |
Lines 196-216
sub AddBookseller {
Link Here
|
196 |
); |
167 |
); |
197 |
|
168 |
|
198 |
# return the id of this new supplier |
169 |
# return the id of this new supplier |
199 |
# FIXME: no protection against simultaneous addition: max(id) might be wrong! |
170 |
return $dbh->{'mysql_insertid'}; |
200 |
$query = " |
|
|
201 |
SELECT max(id) |
202 |
FROM aqbooksellers |
203 |
"; |
204 |
$sth = $dbh->prepare($query); |
205 |
$sth->execute; |
206 |
return scalar($sth->fetchrow); |
207 |
} |
171 |
} |
208 |
|
172 |
|
209 |
#-----------------------------------------------------------------# |
173 |
#-----------------------------------------------------------------# |
210 |
|
174 |
|
211 |
=head2 ModBookseller |
175 |
=head2 ModBookseller |
212 |
|
176 |
|
213 |
&ModBookseller($bookseller); |
177 |
ModBookseller($bookseller); |
214 |
|
178 |
|
215 |
Updates the information for a given bookseller. C<$bookseller> is a |
179 |
Updates the information for a given bookseller. C<$bookseller> is a |
216 |
reference-to-hash whose keys are the fields of the aqbooksellers table |
180 |
reference-to-hash whose keys are the fields of the aqbooksellers table |
Lines 226-242
C<&ModBookseller> with the result.
Link Here
|
226 |
sub ModBookseller { |
190 |
sub ModBookseller { |
227 |
my ($data) = @_; |
191 |
my ($data) = @_; |
228 |
my $dbh = C4::Context->dbh; |
192 |
my $dbh = C4::Context->dbh; |
229 |
my $query = " |
193 |
my $query = 'UPDATE aqbooksellers |
230 |
UPDATE aqbooksellers |
|
|
231 |
SET name=?,address1=?,address2=?,address3=?,address4=?, |
194 |
SET name=?,address1=?,address2=?,address3=?,address4=?, |
232 |
postal=?,phone=?,fax=?,url=?,contact=?,contpos=?, |
195 |
postal=?,phone=?,fax=?,url=?,contact=?,contpos=?, |
233 |
contphone=?,contfax=?,contaltphone=?,contemail=?, |
196 |
contphone=?,contfax=?,contaltphone=?,contemail=?, |
234 |
contnotes=?,active=?,listprice=?, invoiceprice=?, |
197 |
contnotes=?,active=?,listprice=?, invoiceprice=?, |
235 |
gstreg=?,listincgst=?,invoiceincgst=?, |
198 |
gstreg=?,listincgst=?,invoiceincgst=?, |
236 |
discount=?, notes=?, gstrate=? |
199 |
discount=?,notes=?,gstrate=? |
237 |
WHERE id=? |
200 |
WHERE id=?'; |
238 |
"; |
201 |
my $sth = $dbh->prepare($query); |
239 |
my $sth = $dbh->prepare($query); |
|
|
240 |
$sth->execute( |
202 |
$sth->execute( |
241 |
$data->{'name'}, $data->{'address1'}, |
203 |
$data->{'name'}, $data->{'address1'}, |
242 |
$data->{'address2'}, $data->{'address3'}, |
204 |
$data->{'address2'}, $data->{'address3'}, |
Lines 249-275
sub ModBookseller {
Link Here
|
249 |
$data->{'active'}, $data->{'listprice'}, |
211 |
$data->{'active'}, $data->{'listprice'}, |
250 |
$data->{'invoiceprice'}, $data->{'gstreg'}, |
212 |
$data->{'invoiceprice'}, $data->{'gstreg'}, |
251 |
$data->{'listincgst'}, $data->{'invoiceincgst'}, |
213 |
$data->{'listincgst'}, $data->{'invoiceincgst'}, |
252 |
$data->{'discount'}, |
214 |
$data->{'discount'}, $data->{'notes'}, |
253 |
$data->{'notes'}, $data->{'gstrate'}, |
215 |
$data->{'gstrate'}, $data->{'id'} |
254 |
$data->{'id'} |
|
|
255 |
); |
216 |
); |
256 |
$sth->finish; |
217 |
return; |
257 |
} |
218 |
} |
258 |
|
219 |
|
259 |
=head2 DelBookseller |
220 |
=head2 DelBookseller |
260 |
|
221 |
|
261 |
&DelBookseller($booksellerid); |
222 |
DelBookseller($booksellerid); |
262 |
|
223 |
|
263 |
delete the supplier identified by $booksellerid |
224 |
delete the supplier record identified by $booksellerid |
264 |
This sub can be called only if the supplier has no order. |
225 |
This sub assumes it is called only if the supplier has no order. |
265 |
|
226 |
|
266 |
=cut |
227 |
=cut |
267 |
|
228 |
|
268 |
sub DelBookseller { |
229 |
sub DelBookseller { |
269 |
my ($id) = @_; |
230 |
my $id = shift; |
270 |
my $dbh=C4::Context->dbh; |
231 |
my $dbh = C4::Context->dbh; |
271 |
my $sth=$dbh->prepare("DELETE FROM aqbooksellers WHERE id=?"); |
232 |
my $sth = $dbh->prepare('DELETE FROM aqbooksellers WHERE id=?'); |
272 |
$sth->execute($id); |
233 |
$sth->execute($id); |
|
|
234 |
return; |
273 |
} |
235 |
} |
274 |
|
236 |
|
275 |
1; |
237 |
1; |