Revision 2a9ed0d5
Von Moritz Bunkus vor mehr als 17 Jahren hinzugefügt
SL/IC.pm | ||
---|---|---|
44 | 44 |
# connect to db |
45 | 45 |
my $dbh = $form->dbconnect($myconfig); |
46 | 46 |
|
47 |
my $query = qq|SELECT p.*,
|
|
48 |
c1.accno AS inventory_accno, |
|
49 |
c2.accno AS income_accno,
|
|
50 |
c3.accno AS expense_accno,
|
|
51 |
pg.partsgroup
|
|
52 |
FROM parts p
|
|
53 |
LEFT JOIN chart c1 ON (p.inventory_accno_id = c1.id)
|
|
54 |
LEFT JOIN chart c2 ON (p.income_accno_id = c2.id)
|
|
55 |
LEFT JOIN chart c3 ON (p.expense_accno_id = c3.id)
|
|
56 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
|
|
57 |
WHERE p.id = ? |;
|
|
58 |
my @vars = ($form->{id});
|
|
59 |
my $sth = $dbh->prepare($query);
|
|
60 |
$sth->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")");
|
|
61 |
my $ref = $sth->fetchrow_hashref(NAME_lc);
|
|
47 |
my $sth;
|
|
48 |
|
|
49 |
my $query =
|
|
50 |
qq|SELECT p.*,
|
|
51 |
c1.accno AS inventory_accno,
|
|
52 |
c2.accno AS income_accno,
|
|
53 |
c3.accno AS expense_accno,
|
|
54 |
pg.partsgroup
|
|
55 |
FROM parts p
|
|
56 |
LEFT JOIN chart c1 ON (p.inventory_accno_id = c1.id)
|
|
57 |
LEFT JOIN chart c2 ON (p.income_accno_id = c2.id)
|
|
58 |
LEFT JOIN chart c3 ON (p.expense_accno_id = c3.id)
|
|
59 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id)
|
|
60 |
WHERE p.id = ? |;
|
|
61 |
my $ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{id}));
|
|
62 | 62 |
|
63 | 63 |
# copy to $form variables |
64 | 64 |
map { $form->{$_} = $ref->{$_} } (keys %{$ref}); |
65 | 65 |
|
66 |
$sth->finish; |
|
67 |
|
|
68 | 66 |
my %oid = ('Pg' => 'a.oid', |
69 | 67 |
'Oracle' => 'a.rowid'); |
70 | 68 |
|
... | ... | |
74 | 72 |
$form->{item} = 'assembly'; |
75 | 73 |
|
76 | 74 |
# retrieve assembly items |
77 |
$query = qq|SELECT p.id, p.partnumber, p.description, |
|
78 |
p.sellprice, p.weight, a.qty, a.bom, p.unit, |
|
79 |
pg.partsgroup |
|
80 |
FROM parts p |
|
81 |
JOIN assembly a ON (a.parts_id = p.id) |
|
82 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
83 |
WHERE a.id = ? |
|
84 |
ORDER BY ?|; |
|
85 |
@vars = ($form->{id}, $oid{$myconfig->{dbdriver}}); |
|
86 |
$sth = $dbh->prepare($query); |
|
87 |
$sth->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")"); |
|
88 |
|
|
75 |
$query = |
|
76 |
qq|SELECT p.id, p.partnumber, p.description, |
|
77 |
p.sellprice, p.weight, a.qty, a.bom, p.unit, |
|
78 |
pg.partsgroup |
|
79 |
FROM parts p |
|
80 |
JOIN assembly a ON (a.parts_id = p.id) |
|
81 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
82 |
WHERE (a.id = ?) |
|
83 |
ORDER BY $oid{$myconfig->{dbdriver}}|; |
|
84 |
$sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); |
|
85 |
|
|
89 | 86 |
$form->{assembly_rows} = 0; |
90 | 87 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
91 | 88 |
$form->{assembly_rows}++; |
... | ... | |
104 | 101 |
$form->{amount}{IC_expense} = $form->{expense_accno}; |
105 | 102 |
$form->{amount}{IC_cogs} = $form->{expense_accno}; |
106 | 103 |
|
104 |
my @pricegroups = (); |
|
105 |
my @pricegroups_not_used = (); |
|
106 |
|
|
107 | 107 |
# get prices |
108 | 108 |
$query = |
109 |
qq|SELECT p.parts_id, p.pricegroup_id, p.price, (SELECT pg.pricegroup FROM pricegroup pg WHERE pg.id=p.pricegroup_id) AS pricegroup FROM prices p |
|
110 |
WHERE parts_id = ? |
|
111 |
ORDER by pricegroup|; |
|
112 |
|
|
113 |
@vars = ($form->{id}); |
|
114 |
$sth = $dbh->prepare($query); |
|
115 |
$sth->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")"); |
|
116 |
|
|
117 |
@pricegroups = (); |
|
118 |
@pricegroups_not_used = (); |
|
109 |
qq|SELECT p.parts_id, p.pricegroup_id, p.price, |
|
110 |
(SELECT pg.pricegroup |
|
111 |
FROM pricegroup pg |
|
112 |
WHERE pg.id = p.pricegroup_id) AS pricegroup |
|
113 |
FROM prices p |
|
114 |
WHERE (parts_id = ?) |
|
115 |
ORDER BY pricegroup|; |
|
116 |
$sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); |
|
119 | 117 |
|
120 | 118 |
#for pricegroups |
121 | 119 |
my $i = 1; |
122 |
while ( |
|
123 |
($form->{"klass_$i"}, $form->{"pricegroup_id_$i"}, |
|
120 |
while (($form->{"klass_$i"}, $form->{"pricegroup_id_$i"}, |
|
124 | 121 |
$form->{"price_$i"}, $form->{"pricegroup_$i"}) |
125 |
= $sth->fetchrow_array |
|
126 |
) { |
|
122 |
= $sth->fetchrow_array()) { |
|
127 | 123 |
$form->{"price_$i"} = $form->round_amount($form->{"price_$i"}, 5); |
128 |
$form->{"price_$i"} = |
|
129 |
$form->format_amount($myconfig, $form->{"price_$i"}, 5); |
|
124 |
$form->{"price_$i"} = $form->format_amount($myconfig, $form->{"price_$i"}, -2); |
|
130 | 125 |
push @pricegroups, $form->{"pricegroup_id_$i"}; |
131 | 126 |
$i++; |
132 | 127 |
} |
... | ... | |
134 | 129 |
$sth->finish; |
135 | 130 |
|
136 | 131 |
# get pricegroups |
137 |
$query = qq|SELECT p.id, p.pricegroup FROM pricegroup p|; |
|
138 |
|
|
139 |
$pkq = $dbh->prepare($query); |
|
140 |
$pkq->execute || $form->dberror($query); |
|
141 |
while ($pkr = $pkq->fetchrow_hashref(NAME_lc)) { |
|
142 |
push @{ $form->{PRICEGROUPS} }, $pkr; |
|
143 |
} |
|
144 |
$pkq->finish; |
|
132 |
$query = qq|SELECT id, pricegroup FROM pricegroup|; |
|
133 |
$form->{PRICEGROUPS} = selectall_hashref_query($form, $dbh, $query); |
|
145 | 134 |
|
146 | 135 |
#find not used pricegroups |
147 |
while ($tmp = pop @{ $form->{PRICEGROUPS} }) {
|
|
148 |
my $insert = 0;
|
|
149 |
foreach $item (@pricegroups) { |
|
136 |
while ($tmp = pop(@{ $form->{PRICEGROUPS} })) {
|
|
137 |
my $in_use = 0;
|
|
138 |
foreach my $item (@pricegroups) {
|
|
150 | 139 |
if ($item eq $tmp->{id}) { |
151 |
|
|
152 |
#drop |
|
153 |
$insert = 1; |
|
140 |
$in_use = 1; |
|
141 |
last; |
|
154 | 142 |
} |
155 | 143 |
} |
156 |
if ($insert == 0) { |
|
157 |
push @pricegroups_not_used, $tmp; |
|
158 |
} |
|
144 |
push(@pricegroups_not_used, $tmp) unless ($in_use); |
|
159 | 145 |
} |
160 | 146 |
|
161 | 147 |
# if not used pricegroups are avaible |
... | ... | |
164 | 150 |
foreach $name (@pricegroups_not_used) { |
165 | 151 |
$form->{"klass_$i"} = "$name->{id}"; |
166 | 152 |
$form->{"price_$i"} = $form->round_amount($form->{sellprice}, 5); |
167 |
$form->{"price_$i"} = |
|
168 |
$form->format_amount($myconfig, $form->{"price_$i"}, 5); |
|
153 |
$form->{"price_$i"} = $form->format_amount($myconfig, $form->{"price_$i"}, -2); |
|
169 | 154 |
$form->{"pricegroup_id_$i"} = "$name->{id}"; |
170 | 155 |
$form->{"pricegroup_$i"} = "$name->{pricegroup}"; |
171 | 156 |
$i++; |
... | ... | |
179 | 164 |
|
180 | 165 |
# get makes |
181 | 166 |
if ($form->{makemodel}) { |
182 |
$query = qq|SELECT m.make, m.model FROM makemodel m |
|
183 |
WHERE m.parts_id = ?|;
|
|
184 |
@vars = ($form->{id});
|
|
167 |
$query = qq|SELECT m.make, m.model FROM makemodel m | .
|
|
168 |
qq|WHERE m.parts_id = ?|;
|
|
169 |
@values = ($form->{id});
|
|
185 | 170 |
$sth = $dbh->prepare($query); |
186 |
$sth->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")");
|
|
171 |
$sth->execute(@values) || $form->dberror("$query (" . join(', ', @values) . ")");
|
|
187 | 172 |
|
188 | 173 |
my $i = 1; |
189 | 174 |
while (($form->{"make_$i"}, $form->{"model_$i"}) = $sth->fetchrow_array) |
... | ... | |
199 | 184 |
# get translations |
200 | 185 |
$form->{language_values} = ""; |
201 | 186 |
$query = qq|SELECT language_id, translation FROM translation WHERE parts_id = ?|; |
202 |
@vars = ($form->{id}); |
|
203 |
$trq = $dbh->prepare($query); |
|
204 |
$trq->execute(@vars) || $form->dberror("$query (" . join(', ', @vars) . ")"); |
|
187 |
my $trq = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); |
|
205 | 188 |
while ($tr = $trq->fetchrow_hashref(NAME_lc)) { |
206 | 189 |
$form->{language_values} .= "---+++---".$tr->{language_id}."--++--".$tr->{translation}; |
207 | 190 |
} |
208 | 191 |
$trq->finish; |
209 | 192 |
|
210 | 193 |
# now get accno for taxes |
211 |
$query = qq|SELECT c.accno |
|
212 |
FROM chart c, partstax pt |
|
213 |
WHERE pt.chart_id = c.id |
|
214 |
AND pt.parts_id = $form->{id}|; |
|
215 |
|
|
216 |
$sth = $dbh->prepare($query); |
|
217 |
$sth->execute || $form->dberror($query); |
|
218 |
|
|
194 |
$query = |
|
195 |
qq|SELECT c.accno |
|
196 |
FROM chart c, partstax pt |
|
197 |
WHERE (pt.chart_id = c.id) AND (pt.parts_id = ?)|; |
|
198 |
$sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); |
|
219 | 199 |
while (($key) = $sth->fetchrow_array) { |
220 | 200 |
$form->{amount}{$key} = $key; |
221 | 201 |
} |
... | ... | |
223 | 203 |
$sth->finish; |
224 | 204 |
|
225 | 205 |
# is it an orphan |
226 |
$query = qq|SELECT i.parts_id |
|
227 |
FROM invoice i |
|
228 |
WHERE i.parts_id = $form->{id} |
|
229 |
UNION |
|
230 |
SELECT o.parts_id |
|
231 |
FROM orderitems o |
|
232 |
WHERE o.parts_id = $form->{id} |
|
233 |
UNION |
|
234 |
SELECT a.parts_id |
|
235 |
FROM assembly a |
|
236 |
WHERE a.parts_id = $form->{id}|; |
|
237 |
$sth = $dbh->prepare($query); |
|
238 |
$sth->execute || $form->dberror($query); |
|
239 |
|
|
240 |
($form->{orphaned}) = $sth->fetchrow_array; |
|
206 |
$query = |
|
207 |
qq|SELECT i.parts_id |
|
208 |
FROM invoice i |
|
209 |
WHERE (i.parts_id = ?) |
|
210 |
|
|
211 |
UNION |
|
212 |
|
|
213 |
SELECT o.parts_id |
|
214 |
FROM orderitems o |
|
215 |
WHERE (o.parts_id = ?) |
|
216 |
|
|
217 |
UNION |
|
218 |
|
|
219 |
SELECT a.parts_id |
|
220 |
FROM assembly a |
|
221 |
WHERE (a.parts_id = ?)|; |
|
222 |
@values = (conv_i($form->{id}), conv_i($form->{id}), conv_i($form->{id})); |
|
223 |
($form->{orphaned}) = selectrow_query($form, $dbh, $query, @values); |
|
241 | 224 |
$form->{orphaned} = !$form->{orphaned}; |
242 |
$sth->finish; |
|
243 | 225 |
|
244 | 226 |
$form->{"unit_changeable"} = 1; |
245 | 227 |
foreach my $table (qw(invoice assembly orderitems inventory license)) { |
246 |
$query = "SELECT COUNT(*) FROM $table WHERE parts_id = ?"; |
|
247 |
my ($count) = $dbh->selectrow_array($query, undef, $form->{"id"}); |
|
248 |
$form->dberror($query . " (" . $form->{"id"} . ")") if ($dbh->err); |
|
228 |
$query = qq|SELECT COUNT(*) FROM $table WHERE parts_id = ?|; |
|
229 |
my ($count) = selectrow_query($form, $dbh, $query, conv_i($form->{"id"})); |
|
249 | 230 |
|
250 | 231 |
if ($count) { |
251 | 232 |
$form->{"unit_changeable"} = 0; |
... | ... | |
262 | 243 |
$main::lxdebug->enter_sub(); |
263 | 244 |
|
264 | 245 |
my ($self, $myconfig, $form) = @_; |
265 |
my $dbh = $form->dbconnect($myconfig); |
|
266 |
my $i = 1; |
|
267 |
my @pricegroups_not_used = (); |
|
268 | 246 |
|
269 |
# get pricegroups |
|
270 |
my $query = qq|SELECT p.id, p.pricegroup FROM pricegroup p|; |
|
271 |
|
|
272 |
my $pkq = $dbh->prepare($query); |
|
273 |
$pkq->execute || $form->dberror($query); |
|
274 |
while ($pkr = $pkq->fetchrow_hashref(NAME_lc)) { |
|
275 |
push @{ $form->{PRICEGROUPS} }, $pkr; |
|
276 |
} |
|
277 |
$pkq->finish; |
|
278 |
|
|
279 |
#find not used pricegroups |
|
280 |
while ($tmp = pop @{ $form->{PRICEGROUPS} }) { |
|
281 |
push @pricegroups_not_used, $tmp; |
|
282 |
} |
|
247 |
my $dbh = $form->dbconnect($myconfig); |
|
283 | 248 |
|
284 |
# if not used pricegroups are avaible |
|
285 |
if (@pricegroups_not_used) { |
|
249 |
# get pricegroups |
|
250 |
my $query = qq|SELECT id, pricegroup FROM pricegroup|; |
|
251 |
my $pricegroups = selectall_hashref_query($form, $dbh, $query); |
|
286 | 252 |
|
287 |
foreach $name (@pricegroups_not_used) { |
|
288 |
$form->{"klass_$i"} = "$name->{id}"; |
|
289 |
$form->{"price_$i"} = $form->round_amount($form->{sellprice}, 5); |
|
290 |
$form->{"price_$i"} = |
|
291 |
$form->format_amount($myconfig, $form->{"price_$i"}, 5); |
|
292 |
$form->{"pricegroup_id_$i"} = "$name->{id}"; |
|
293 |
$form->{"pricegroup_$i"} = "$name->{pricegroup}"; |
|
294 |
$i++; |
|
295 |
} |
|
253 |
my $i = 1; |
|
254 |
foreach $pg (@{ $pricegroups }) { |
|
255 |
$form->{"klass_$i"} = "$pg->{id}"; |
|
256 |
$form->{"price_$i"} = $form->format_amount($myconfig, $form->{"price_$i"}, -2); |
|
257 |
$form->{"pricegroup_id_$i"} = "$pg->{id}"; |
|
258 |
$form->{"pricegroup_$i"} = "$pg->{pricegroup}"; |
|
259 |
$i++; |
|
296 | 260 |
} |
297 | 261 |
|
298 | 262 |
#correct rows |
... | ... | |
313 | 277 |
my $dbh = $form->dbconnect($myconfig); |
314 | 278 |
|
315 | 279 |
# get buchungsgruppen |
316 |
$query = qq|SELECT id, description |
|
317 |
FROM buchungsgruppen |
|
318 |
ORDER BY sortkey|; |
|
319 |
$sth = $dbh->prepare($query); |
|
320 |
$sth->execute || $form->dberror($query); |
|
321 |
|
|
322 |
$form->{BUCHUNGSGRUPPEN} = []; |
|
323 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
|
324 |
push(@{ $form->{BUCHUNGSGRUPPEN} }, $ref); |
|
325 |
} |
|
326 |
$sth->finish; |
|
280 |
$query = qq|SELECT id, description FROM buchungsgruppen ORDER BY sortkey|; |
|
281 |
$form->{BUCHUNGSGRUPPEN} = selectall_hashref_query($form, $dbh, $query); |
|
327 | 282 |
|
328 | 283 |
$main::lxdebug->leave_sub(); |
329 | 284 |
} |
... | ... | |
332 | 287 |
$main::lxdebug->enter_sub(); |
333 | 288 |
|
334 | 289 |
my ($self, $myconfig, $form) = @_; |
335 |
|
|
290 |
my @values; |
|
336 | 291 |
# connect to database, turn off AutoCommit |
337 | 292 |
my $dbh = $form->dbconnect_noauto($myconfig); |
338 | 293 |
|
... | ... | |
345 | 300 |
# if there is a $form->{id} then replace the old entry |
346 | 301 |
# delete all makemodel entries and add the new ones |
347 | 302 |
|
348 |
# escape ' |
|
349 |
map { $form->{$_} =~ s/\'/\'\'/g } qw(partnumber description notes unit); |
|
350 |
|
|
351 | 303 |
# undo amount formatting |
352 | 304 |
map { $form->{$_} = $form->parse_amount($myconfig, $form->{$_}) } |
353 | 305 |
qw(rop weight listprice sellprice gv lastcost stock); |
354 | 306 |
|
355 |
# set date to NULL if nothing entered |
|
356 |
$form->{priceupdate} = |
|
357 |
($form->{priceupdate}) ? qq|'$form->{priceupdate}'| : "NULL"; |
|
358 |
|
|
359 |
$form->{makemodel} = (($form->{make_1}) || ($form->{model_1})) ? 1 : 0; |
|
307 |
my $makemodel = (($form->{make_1}) || ($form->{model_1})) ? 1 : 0; |
|
360 | 308 |
|
361 |
$form->{alternate} = 0; |
|
362 | 309 |
$form->{assembly} = ($form->{item} eq 'assembly') ? 1 : 0; |
363 |
$form->{obsolete} *= 1; |
|
364 |
$form->{shop} *= 1; |
|
365 |
$form->{onhand} *= 1; |
|
366 |
$form->{ve} *= 1; |
|
367 |
$form->{ge} *= 1; |
|
368 |
$form->{buchungsgruppen_id} *= 1; |
|
369 |
$form->{not_discountable} *= 1; |
|
370 |
$form->{payment_id} *= 1; |
|
371 | 310 |
|
372 | 311 |
my ($query, $sth); |
373 | 312 |
|
374 | 313 |
if ($form->{id}) { |
375 | 314 |
|
376 | 315 |
# get old price |
377 |
$query = qq|SELECT p.sellprice, p.weight |
|
378 |
FROM parts p |
|
379 |
WHERE p.id = $form->{id}|; |
|
380 |
$sth = $dbh->prepare($query); |
|
381 |
$sth->execute || $form->dberror($query); |
|
382 |
my ($sellprice, $weight) = $sth->fetchrow_array; |
|
383 |
$sth->finish; |
|
316 |
$query = qq|SELECT sellprice, weight FROM parts WHERE id = ?|; |
|
317 |
my ($sellprice, $weight) = selectrow_query($form, $dbh, $query, conv_i($form->{id})); |
|
384 | 318 |
|
385 | 319 |
# if item is part of an assembly adjust all assemblies |
386 |
$query = qq|SELECT a.id, a.qty |
|
387 |
FROM assembly a |
|
388 |
WHERE a.parts_id = $form->{id}|; |
|
389 |
$sth = $dbh->prepare($query); |
|
390 |
$sth->execute || $form->dberror($query); |
|
320 |
$query = qq|SELECT id, qty FROM assembly WHERE parts_id = ?|; |
|
321 |
$sth = prepare_execute_query($form, $dbh, $query, conv_i($form->{id})); |
|
391 | 322 |
while (my ($id, $qty) = $sth->fetchrow_array) { |
392 | 323 |
&update_assembly($dbh, $form, $id, $qty, $sellprice * 1, $weight * 1); |
393 | 324 |
} |
394 | 325 |
$sth->finish; |
395 | 326 |
|
396 | 327 |
if ($form->{item} ne 'service') { |
397 |
|
|
398 | 328 |
# delete makemodel records |
399 |
$query = qq|DELETE FROM makemodel |
|
400 |
WHERE parts_id = $form->{id}|; |
|
401 |
$dbh->do($query) || $form->dberror($query); |
|
329 |
do_query($form, $dbh, qq|DELETE FROM makemodel WHERE parts_id = ?|, conv_i($form->{id})); |
|
402 | 330 |
} |
403 | 331 |
|
404 | 332 |
if ($form->{item} eq 'assembly') { |
... | ... | |
407 | 335 |
} |
408 | 336 |
|
409 | 337 |
# delete assembly records |
410 |
$query = qq|DELETE FROM assembly |
|
411 |
WHERE id = $form->{id}|; |
|
412 |
$dbh->do($query) || $form->dberror($query); |
|
338 |
do_query($form, $dbh, qq|DELETE FROM assembly WHERE id = ?|, conv_i($form->{id})); |
|
413 | 339 |
|
414 | 340 |
$form->{onhand} += $form->{stock}; |
415 | 341 |
} |
416 | 342 |
|
417 | 343 |
# delete tax records |
418 |
$query = qq|DELETE FROM partstax |
|
419 |
WHERE parts_id = $form->{id}|; |
|
420 |
$dbh->do($query) || $form->dberror($query); |
|
344 |
do_query($form, $dbh, qq|DELETE FROM partstax WHERE parts_id = ?|, conv_i($form->{id})); |
|
421 | 345 |
|
422 | 346 |
# delete translations |
423 |
$query = qq|DELETE FROM translation |
|
424 |
WHERE parts_id = $form->{id}|; |
|
425 |
$dbh->do($query) || $form->dberror($query); |
|
347 |
do_query($form, $dbh, qq|DELETE FROM translation WHERE parts_id = ?|, conv_i($form->{id})); |
|
426 | 348 |
|
427 | 349 |
} else { |
428 |
my $uid = rand() . time; |
|
429 |
$uid .= $form->{login}; |
|
430 |
|
|
431 |
$query = qq|SELECT p.id FROM parts p |
|
432 |
WHERE p.partnumber = '$form->{partnumber}'|; |
|
433 |
$sth = $dbh->prepare($query); |
|
434 |
$sth->execute || $form->dberror($query); |
|
435 |
($form->{id}) = $sth->fetchrow_array; |
|
436 |
$sth->finish; |
|
437 |
|
|
438 |
if ($form->{id} ne "") { |
|
350 |
my ($count) = selectrow_array($form, $dbh, qq|SELECT COUNT(*) FROM parts WHERE partnumber = ?|, $form->{partnumber}); |
|
351 |
if ($count) { |
|
439 | 352 |
$main::lxdebug->leave_sub(); |
440 | 353 |
return 3; |
441 | 354 |
} |
442 |
$query = qq|INSERT INTO parts (partnumber, description) |
|
443 |
VALUES ('$uid', 'dummy')|; |
|
444 |
$dbh->do($query) || $form->dberror($query); |
|
445 |
|
|
446 |
$query = qq|SELECT p.id FROM parts p |
|
447 |
WHERE p.partnumber = '$uid'|; |
|
448 |
$sth = $dbh->prepare($query); |
|
449 |
$sth->execute || $form->dberror($query); |
|
450 | 355 |
|
451 |
($form->{id}) = $sth->fetchrow_array;
|
|
452 |
$sth->finish;
|
|
356 |
($form->{id}) = selectrow_array($form, $dbh, qq|SELECT nextval('id')|);
|
|
357 |
do_query($form, $dbh, qq|INSERT INTO parts (id, partnumber) VALUES (?, '')|, $form->{id});
|
|
453 | 358 |
|
454 | 359 |
$form->{orphaned} = 1; |
455 | 360 |
$form->{onhand} = $form->{stock} if $form->{item} eq 'assembly'; |
... | ... | |
464 | 369 |
my $partsgroup_id = 0; |
465 | 370 |
|
466 | 371 |
if ($form->{partsgroup}) { |
467 |
($partsgroup, $partsgroup_id) = split /--/, $form->{partsgroup};
|
|
372 |
($partsgroup, $partsgroup_id) = split(/--/, $form->{partsgroup});
|
|
468 | 373 |
} |
469 | 374 |
|
470 | 375 |
my ($subq_inventory, $subq_expense, $subq_income); |
471 | 376 |
if ($form->{"item"} eq "part") { |
472 | 377 |
$subq_inventory = |
473 |
qq|(SELECT bg.inventory_accno_id | .
|
|
474 |
qq| FROM buchungsgruppen bg | .
|
|
475 |
qq| WHERE bg.id = | . $dbh->quote($form->{"buchungsgruppen_id"}) . qq|)|;
|
|
378 |
qq|(SELECT bg.inventory_accno_id |
|
379 |
FROM buchungsgruppen bg
|
|
380 |
WHERE bg.id = | . conv_i($form->{"buchungsgruppen_id"}, 'NULL') . qq|)|;
|
|
476 | 381 |
} else { |
477 | 382 |
$subq_inventory = "NULL"; |
478 | 383 |
} |
479 | 384 |
|
480 | 385 |
if ($form->{"item"} ne "assembly") { |
481 | 386 |
$subq_expense = |
482 |
qq|(SELECT bg.expense_accno_id_0 | .
|
|
483 |
qq| FROM buchungsgruppen bg | .
|
|
484 |
qq| WHERE bg.id = | . $dbh->quote($form->{"buchungsgruppen_id"}) . qq|)|;
|
|
387 |
qq|(SELECT bg.expense_accno_id_0 |
|
388 |
FROM buchungsgruppen bg
|
|
389 |
WHERE bg.id = | . conv_i($form->{"buchungsgruppen_id"}, 'NULL') . qq|)|;
|
|
485 | 390 |
} else { |
486 | 391 |
$subq_expense = "NULL"; |
487 | 392 |
} |
488 | 393 |
|
489 |
$subq_income = |
|
490 |
qq|(SELECT bg.income_accno_id_0 | . |
|
491 |
qq| FROM buchungsgruppen bg | . |
|
492 |
qq| WHERE bg.id = | . $dbh->quote($form->{"buchungsgruppen_id"}) . qq|)|; |
|
493 |
|
|
494 |
$query = qq|UPDATE parts SET |
|
495 |
partnumber = '$form->{partnumber}', |
|
496 |
description = '$form->{description}', |
|
497 |
makemodel = '$form->{makemodel}', |
|
498 |
alternate = '$form->{alternate}', |
|
499 |
assembly = '$form->{assembly}', |
|
500 |
listprice = $form->{listprice}, |
|
501 |
sellprice = $form->{sellprice}, |
|
502 |
lastcost = $form->{lastcost}, |
|
503 |
weight = $form->{weight}, |
|
504 |
priceupdate = $form->{priceupdate}, |
|
505 |
unit = '$form->{unit}', |
|
506 |
notes = '$form->{notes}', |
|
507 |
formel = '$form->{formel}', |
|
508 |
rop = $form->{rop}, |
|
509 |
bin = '$form->{bin}', |
|
510 |
buchungsgruppen_id = '$form->{buchungsgruppen_id}', |
|
511 |
payment_id = '$form->{payment_id}', |
|
512 |
inventory_accno_id = $subq_inventory, |
|
513 |
income_accno_id = $subq_income, |
|
514 |
expense_accno_id = $subq_expense, |
|
515 |
obsolete = '$form->{obsolete}', |
|
516 |
image = '$form->{image}', |
|
517 |
drawing = '$form->{drawing}', |
|
518 |
shop = '$form->{shop}', |
|
519 |
ve = '$form->{ve}', |
|
520 |
gv = '$form->{gv}', |
|
521 |
ean = '$form->{ean}', |
|
522 |
not_discountable = '$form->{not_discountable}', |
|
523 |
microfiche = '$form->{microfiche}', |
|
524 |
partsgroup_id = $partsgroup_id |
|
525 |
WHERE id = $form->{id}|; |
|
526 |
$dbh->do($query) || $form->dberror($query); |
|
394 |
$query = |
|
395 |
qq|UPDATE parts SET |
|
396 |
partnumber = ?, |
|
397 |
description = ?, |
|
398 |
makemodel = ?, |
|
399 |
alternate = 'f', |
|
400 |
assembly = ?, |
|
401 |
listprice = ?, |
|
402 |
sellprice = ?, |
|
403 |
lastcost = ?, |
|
404 |
weight = ?, |
|
405 |
priceupdate = ?, |
|
406 |
unit = ?, |
|
407 |
notes = ?, |
|
408 |
formel = ?, |
|
409 |
rop = ?, |
|
410 |
bin = ?, |
|
411 |
buchungsgruppen_id = ?, |
|
412 |
payment_id = ?, |
|
413 |
inventory_accno_id = $subq_inventory, |
|
414 |
income_accno_id = (SELECT bg.income_accno_id_0 FROM buchungsgruppen bg WHERE bg.id = ?), |
|
415 |
expense_accno_id = $subq_expense, |
|
416 |
obsolete = ?, |
|
417 |
image = ?, |
|
418 |
drawing = ?, |
|
419 |
shop = ?, |
|
420 |
ve = ?, |
|
421 |
gv = ?, |
|
422 |
ean = ?, |
|
423 |
not_discountable = ?, |
|
424 |
microfiche = ?, |
|
425 |
partsgroup_id = ? |
|
426 |
WHERE id = ?|; |
|
427 |
@values = ($form->{partnumber}, |
|
428 |
$form->{description}, |
|
429 |
$makemodel ? 't' : 'f', |
|
430 |
$form->{assembly} ? 't' : 'f', |
|
431 |
$form->{listprice}, |
|
432 |
$form->{sellprice}, |
|
433 |
$form->{lastcost}, |
|
434 |
$form->{weight}, |
|
435 |
conv_date($form->{priceupdate}), |
|
436 |
$form->{unit}, |
|
437 |
$form->{notes}, |
|
438 |
$form->{formel}, |
|
439 |
$form->{rop}, |
|
440 |
$form->{bin}, |
|
441 |
conv_i($form->{buchungsgruppen_id}), |
|
442 |
conv_i($form->{payment_id}), |
|
443 |
conv_i($form->{buchungsgruppen_id}), |
|
444 |
$form->{obsolete} ? 't' : 'f', |
|
445 |
$form->{image}, |
|
446 |
$form->{drawing}, |
|
447 |
$form->{shop} ? 't' : 'f', |
|
448 |
conv_i($form->{ve}), |
|
449 |
conv_i($form->{gv}), |
|
450 |
$form->{ean}, |
|
451 |
$form->{not_discountable} ? 't' : 'f', |
|
452 |
$form->{microfiche}, |
|
453 |
conv_i($partsgroup_id), |
|
454 |
conv_i($form->{id}) |
|
455 |
); |
|
456 |
do_query($form, $dbh, $query, @values); |
|
527 | 457 |
|
528 | 458 |
# delete translation records |
529 |
$query = qq|DELETE FROM translation |
|
530 |
WHERE parts_id = $form->{id}|; |
|
531 |
$dbh->do($query) || $form->dberror($query); |
|
459 |
do_query($form, $dbh, qq|DELETE FROM translation WHERE parts_id = ?|, conv_i($form->{id})); |
|
532 | 460 |
|
533 | 461 |
if ($form->{language_values} ne "") { |
534 |
split /---\+\+\+---/,$form->{language_values}; |
|
535 |
foreach $item (@_) { |
|
536 |
my ($language_id, $translation, $longdescription) = split /--\+\+--/, $item; |
|
462 |
foreach $item (split(/---\+\+\+---/, $form->{language_values})) { |
|
463 |
my ($language_id, $translation, $longdescription) = split(/--\+\+--/, $item); |
|
537 | 464 |
if ($translation ne "") { |
538 |
$query = qq|INSERT into translation (parts_id, language_id, translation, longdescription) VALUES |
|
539 |
($form->{id}, $language_id, | . $dbh->quote($translation) . qq|, | . $dbh->quote($longdescription) . qq| )|; |
|
540 |
$dbh->do($query) || $form->dberror($query); |
|
465 |
$query = qq|INSERT into translation (parts_id, language_id, translation, longdescription) |
|
466 |
VALUES ( ?, ?, ?, ? )|; |
|
467 |
@values = (conv_i($form->{id}), conv_i($language_id), $translation, $longdescription); |
|
468 |
do_query($form, $dbh, $query, @values); |
|
541 | 469 |
} |
542 | 470 |
} |
543 | 471 |
} |
472 |
|
|
544 | 473 |
# delete price records |
545 |
$query = qq|DELETE FROM prices |
|
546 |
WHERE parts_id = $form->{id}|; |
|
547 |
$dbh->do($query) || $form->dberror($query); |
|
474 |
do_query($form, $dbh, qq|DELETE FROM prices WHERE parts_id = ?|, conv_i($form->{id})); |
|
475 |
|
|
548 | 476 |
# insert price records only if different to sellprice |
549 | 477 |
for my $i (1 .. $form->{price_rows}) { |
550 | 478 |
if ($form->{"price_$i"} eq "0") { |
... | ... | |
556 | 484 |
|| $form->{"pricegroup_id_$i"}) |
557 | 485 |
and $form->{"price_$i"} != $form->{sellprice} |
558 | 486 |
) { |
559 |
$klass = $form->parse_amount($myconfig, $form->{"klass_$i"}); |
|
487 |
#$klass = $form->parse_amount($myconfig, $form->{"klass_$i"});
|
|
560 | 488 |
$price = $form->parse_amount($myconfig, $form->{"price_$i"}); |
561 | 489 |
$pricegroup_id = |
562 | 490 |
$form->parse_amount($myconfig, $form->{"pricegroup_id_$i"}); |
563 |
$query = qq|INSERT INTO prices (parts_id, pricegroup_id, price) |
|
564 |
VALUES($form->{id},$pricegroup_id,$price)|; |
|
565 |
$dbh->do($query) || $form->dberror($query); |
|
491 |
$query = qq|INSERT INTO prices (parts_id, pricegroup_id, price) | . |
|
492 |
qq|VALUES(?, ?, ?)|; |
|
493 |
@values = (conv_i($form->{id}), conv_i($pricegroup_id), $price); |
|
494 |
do_query($form, $dbh, $query, @values); |
|
566 | 495 |
} |
567 | 496 |
} |
568 | 497 |
|
... | ... | |
572 | 501 |
if (($form->{"make_$i"}) || ($form->{"model_$i"})) { |
573 | 502 |
map { $form->{"${_}_$i"} =~ s/\'/\'\'/g } qw(make model); |
574 | 503 |
|
575 |
$query = qq|INSERT INTO makemodel (parts_id, make, model) |
|
576 |
VALUES ($form->{id},
|
|
577 |
'$form->{"make_$i"}', '$form->{"model_$i"}')|;
|
|
578 |
$dbh->do($query) || $form->dberror($query);
|
|
504 |
$query = qq|INSERT INTO makemodel (parts_id, make, model) | .
|
|
505 |
qq|VALUES (?, ?, ?)|;
|
|
506 |
@values = (conv_i($form->{id}), $form->{"make_$i"}, $form->{"model_$i"});
|
|
507 |
do_query($form, $dbh, $query, @values);
|
|
579 | 508 |
} |
580 | 509 |
} |
581 | 510 |
} |
582 | 511 |
|
583 | 512 |
# insert taxes |
584 |
foreach $item (split / /, $form->{taxaccounts}) {
|
|
513 |
foreach $item (split(/ /, $form->{taxaccounts})) {
|
|
585 | 514 |
if ($form->{"IC_tax_$item"}) { |
586 |
$query = qq|INSERT INTO partstax (parts_id, chart_id) |
|
587 |
VALUES ($form->{id}, |
|
588 |
(SELECT c.id |
|
589 |
FROM chart c |
|
590 |
WHERE c.accno = '$item'))|; |
|
591 |
$dbh->do($query) || $form->dberror($query); |
|
515 |
$query = |
|
516 |
qq|INSERT INTO partstax (parts_id, chart_id) |
|
517 |
VALUES (?, (SELECT id FROM chart WHERE accno = ?))|; |
|
518 |
@values = (conv_i($form->{id}), $item); |
|
519 |
do_query($form, $dbh, $query, @values); |
|
592 | 520 |
} |
593 | 521 |
} |
594 | 522 |
|
... | ... | |
600 | 528 |
|
601 | 529 |
if ($form->{"qty_$i"} != 0) { |
602 | 530 |
$form->{"bom_$i"} *= 1; |
603 |
$query = qq|INSERT INTO assembly (id, parts_id, qty, bom) |
|
604 |
VALUES ($form->{id}, $form->{"id_$i"},
|
|
605 |
$form->{"qty_$i"}, '$form->{"bom_$i"}')|;
|
|
606 |
$dbh->do($query) || $form->dberror($query);
|
|
531 |
$query = qq|INSERT INTO assembly (id, parts_id, qty, bom) | .
|
|
532 |
qq|VALUES (?, ?, ?, ?)|;
|
|
533 |
@values = (conv_i($form->{id}), conv_i($form->{"id_$i"}), conv_i($form->{"qty_$i"}), $form->{"bom_$i"} ? 't' : 'f');
|
|
534 |
do_query($form, $dbh, $query, @values);
|
|
607 | 535 |
} |
608 | 536 |
} |
609 | 537 |
|
... | ... | |
620 | 548 |
$form->get_employee($dbh); |
621 | 549 |
|
622 | 550 |
# add inventory record |
623 |
$query = qq|INSERT INTO inventory (warehouse_id, parts_id, qty,
|
|
624 |
shippingdate, employee_id) VALUES (
|
|
625 |
0, $form->{id}, $form->{stock}, '$shippingdate',
|
|
626 |
$form->{employee_id})|;
|
|
627 |
$dbh->do($query) || $form->dberror($query);
|
|
551 |
$query = |
|
552 |
qq|INSERT INTO inventory (warehouse_id, parts_id, qty, shippingdate, employee_id)
|
|
553 |
VALUES (0, ?, ?, '$shippingdate', ?)|;
|
|
554 |
@values = (conv_i($form->{id}), $form->{stock}, conv_i($form->{employee_id}));
|
|
555 |
do_query($form, $dbh, $query, @values);
|
|
628 | 556 |
|
629 | 557 |
} |
630 | 558 |
|
... | ... | |
637 | 565 |
# get tax rates and description |
638 | 566 |
$accno_id = |
639 | 567 |
($form->{vc} eq "customer") ? $form->{income_accno} : $vendor_accno; |
640 |
$query = qq|SELECT c.accno, c.description, t.rate, t.taxnumber |
|
641 |
FROM chart c, tax t |
|
642 |
WHERE c.id=t.chart_id AND t.taxkey in (SELECT taxkey_id from chart where accno = '$accno_id') |
|
643 |
ORDER BY c.accno|; |
|
644 |
$stw = $dbh->prepare($query); |
|
645 |
|
|
646 |
$stw->execute || $form->dberror($query); |
|
568 |
$query = |
|
569 |
qq|SELECT c.accno, c.description, t.rate, t.taxnumber |
|
570 |
FROM chart c, tax t |
|
571 |
WHERE (c.id = t.chart_id) AND (t.taxkey IN (SELECT taxkey_id FROM chart where accno = ?)) |
|
572 |
ORDER BY c.accno|; |
|
573 |
$stw = prepare_execute_query($form, $dbh, $query, $accno_id); |
|
647 | 574 |
|
648 | 575 |
$form->{taxaccount} = ""; |
649 | 576 |
while ($ptr = $stw->fetchrow_hashref(NAME_lc)) { |
650 |
|
|
651 |
# if ($customertax{$ref->{accno}}) { |
|
652 | 577 |
$form->{taxaccount} .= "$ptr->{accno} "; |
653 | 578 |
if (!($form->{taxaccount2} =~ /$ptr->{accno}/)) { |
654 | 579 |
$form->{"$ptr->{accno}_rate"} = $ptr->{rate}; |
... | ... | |
656 | 581 |
$form->{"$ptr->{accno}_taxnumber"} = $ptr->{taxnumber}; |
657 | 582 |
$form->{taxaccount2} .= " $ptr->{accno} "; |
658 | 583 |
} |
659 |
|
|
660 | 584 |
} |
661 | 585 |
|
662 | 586 |
# commit |
... | ... | |
673 | 597 |
|
674 | 598 |
my ($dbh, $form, $id, $qty, $sellprice, $weight) = @_; |
675 | 599 |
|
676 |
my $query = qq|SELECT a.id, a.qty |
|
677 |
FROM assembly a |
|
678 |
WHERE a.parts_id = $id|; |
|
679 |
my $sth = $dbh->prepare($query); |
|
680 |
$sth->execute || $form->dberror($query); |
|
600 |
my $query = qq|SELECT id, qty FROM assembly WHERE parts_id = ?|; |
|
601 |
my $sth = prepare_execute_query($form, $dbh, $query, conv_i($id)); |
|
681 | 602 |
|
682 | 603 |
while (my ($pid, $aqty) = $sth->fetchrow_array) { |
683 | 604 |
&update_assembly($dbh, $form, $pid, $aqty * $qty, $sellprice, $weight); |
684 | 605 |
} |
685 | 606 |
$sth->finish; |
686 | 607 |
|
687 |
$query = qq|UPDATE parts |
|
688 |
SET sellprice = sellprice + |
|
689 |
$qty * ($form->{sellprice} - $sellprice), |
|
690 |
weight = weight + |
|
691 |
$qty * ($form->{weight} - $weight) |
|
692 |
WHERE id = $id|; |
|
693 |
$dbh->do($query) || $form->dberror($query); |
|
608 |
$query = |
|
609 |
qq|UPDATE parts SET sellprice = sellprice + ?, weight = weight + ? |
|
610 |
WHERE id = ?|; |
|
611 |
@values = ($qty * ($form->{sellprice} - $sellprice), |
|
612 |
$qty * ($form->{weight} - $weight), conv_i($id)); |
|
613 |
do_query($form, $dbh, $query, @values); |
|
694 | 614 |
|
695 | 615 |
$main::lxdebug->leave_sub(); |
696 | 616 |
} |
... | ... | |
703 | 623 |
# connect to database |
704 | 624 |
my $dbh = $form->dbconnect($myconfig); |
705 | 625 |
|
706 |
my $where = '1 = 1'; |
|
626 |
my $where = qq|NOT p.obsolete|; |
|
627 |
my @values; |
|
707 | 628 |
|
708 | 629 |
if ($form->{partnumber}) { |
709 |
my $partnumber = $form->like(lc $form->{partnumber});
|
|
710 |
$where .= " AND lower(p.partnumber) LIKE '$partnumber'";
|
|
630 |
$where .= qq| AND (p.partnumber ILIKE ?)|;
|
|
631 |
push(@values, '%' . $form->{partnumber} . '%');
|
|
711 | 632 |
} |
712 | 633 |
|
713 | 634 |
if ($form->{description}) { |
714 |
my $description = $form->like(lc $form->{description});
|
|
715 |
$where .= " AND lower(p.description) LIKE '$description'";
|
|
635 |
$where .= qq| AND (p.description ILIKE ?)|;
|
|
636 |
push(@values, '%' . $form->{description} . '%');
|
|
716 | 637 |
} |
717 |
$where .= " AND NOT p.obsolete = '1'"; |
|
718 | 638 |
|
719 | 639 |
# retrieve assembly items |
720 |
my $query = qq|SELECT p.id, p.partnumber, p.description, |
|
721 |
p.bin, p.onhand, p.rop, |
|
722 |
(SELECT sum(p2.inventory_accno_id) |
|
723 |
FROM parts p2, assembly a |
|
724 |
WHERE p2.id = a.parts_id |
|
725 |
AND a.id = p.id) AS inventory |
|
726 |
FROM parts p |
|
727 |
WHERE $where |
|
728 |
AND assembly = '1'|; |
|
729 |
|
|
730 |
my $sth = $dbh->prepare($query); |
|
731 |
$sth->execute || $form->dberror($query); |
|
640 |
my $query = |
|
641 |
qq|SELECT p.id, p.partnumber, p.description, |
|
642 |
p.bin, p.onhand, p.rop, |
|
643 |
(SELECT sum(p2.inventory_accno_id) |
|
644 |
FROM parts p2, assembly a |
|
645 |
WHERE (p2.id = a.parts_id) AND (a.id = p.id)) AS inventory |
|
646 |
FROM parts p |
|
647 |
WHERE NOT p.obsolete AND p.assembly $where|; |
|
732 | 648 |
|
733 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
|
734 |
push @{ $form->{assembly_items} }, $ref if $ref->{inventory}; |
|
735 |
} |
|
736 |
$sth->finish; |
|
649 |
$form->{assembly_items} = selectall_hashref_query($form, $dbh, $query, @values); |
|
737 | 650 |
|
738 | 651 |
$dbh->disconnect; |
739 | 652 |
|
... | ... | |
771 | 684 |
|
772 | 685 |
my ($dbh, $form, $id, $qty) = @_; |
773 | 686 |
|
774 |
my $query = qq|SELECT p.id, p.inventory_accno_id, p.assembly, a.qty |
|
775 |
FROM parts p, assembly a |
|
776 |
WHERE a.parts_id = p.id |
|
777 |
AND a.id = $id|; |
|
778 |
my $sth = $dbh->prepare($query); |
|
779 |
$sth->execute || $form->dberror($query); |
|
687 |
my $query = |
|
688 |
qq|SELECT p.id, p.inventory_accno_id, p.assembly, a.qty |
|
689 |
FROM parts p, assembly a |
|
690 |
WHERE (a.parts_id = p.id) AND (a.id = ?)|; |
|
691 |
my $sth = prepare_execute_query($form, $dbh, $query, conv_i($id)); |
|
780 | 692 |
|
781 | 693 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
782 | 694 |
|
... | ... | |
806 | 718 |
$main::lxdebug->enter_sub(); |
807 | 719 |
|
808 | 720 |
my ($self, $myconfig, $form) = @_; |
809 |
|
|
721 |
my @values = (conv_i($form->{id})); |
|
810 | 722 |
# connect to database, turn off AutoCommit |
811 | 723 |
my $dbh = $form->dbconnect_noauto($myconfig); |
812 | 724 |
|
813 |
# first delete prices of pricegroup |
|
814 |
my $query = qq|DELETE FROM prices |
|
815 |
WHERE parts_id = $form->{id}|; |
|
816 |
$dbh->do($query) || $form->dberror($query); |
|
817 |
|
|
818 |
my $query = qq|DELETE FROM parts |
|
819 |
WHERE id = $form->{id}|; |
|
820 |
$dbh->do($query) || $form->dberror($query); |
|
821 |
|
|
822 |
$query = qq|DELETE FROM partstax |
|
823 |
WHERE parts_id = $form->{id}|; |
|
824 |
$dbh->do($query) || $form->dberror($query); |
|
825 |
|
|
826 |
# check if it is a part, assembly or service |
|
827 |
if ($form->{item} ne 'service') { |
|
828 |
$query = qq|DELETE FROM makemodel |
|
829 |
WHERE parts_id = $form->{id}|; |
|
830 |
$dbh->do($query) || $form->dberror($query); |
|
831 |
} |
|
832 |
|
|
833 |
if ($form->{item} eq 'assembly') { |
|
834 |
|
|
835 |
# delete inventory |
|
836 |
$query = qq|DELETE FROM inventory |
|
837 |
WHERE parts_id = $form->{id}|; |
|
838 |
$dbh->do($query) || $form->dberror($query); |
|
725 |
my %columns = ( "assembly" => "id", "alternate" => "id", "parts" => "id" ); |
|
839 | 726 |
|
840 |
$query = qq|DELETE FROM assembly |
|
841 |
WHERE id = $form->{id}|; |
|
842 |
$dbh->do($query) || $form->dberror($query); |
|
843 |
} |
|
844 |
|
|
845 |
if ($form->{item} eq 'alternate') { |
|
846 |
$query = qq|DELETE FROM alternate |
|
847 |
WHERE id = $form->{id}|; |
|
848 |
$dbh->do($query) || $form->dberror($query); |
|
727 |
for my $table (qw(prices partstax makemodel inventory assembly parts)) { |
|
728 |
my $column = defined($columns{$table}) ? $columns{$table} : "parts_id"; |
|
729 |
do_query($form, $dbh, qq|DELETE FROM $table WHERE $column = ?|, @values); |
|
849 | 730 |
} |
850 | 731 |
|
851 | 732 |
# commit |
... | ... | |
864 | 745 |
|
865 | 746 |
my $i = $form->{assembly_rows}; |
866 | 747 |
my $var; |
867 |
my $where = "1 = 1"; |
|
748 |
my $where = qq|1 = 1|; |
|
749 |
my @values; |
|
868 | 750 |
|
869 |
if ($form->{"partnumber_$i"}) { |
|
870 |
$var = $form->like(lc $form->{"partnumber_$i"}); |
|
871 |
$where .= " AND lower(p.partnumber) LIKE '$var'"; |
|
872 |
} |
|
873 |
if ($form->{"description_$i"}) { |
|
874 |
$var = $form->like(lc $form->{"description_$i"}); |
|
875 |
$where .= " AND lower(p.description) LIKE '$var'"; |
|
876 |
} |
|
877 |
if ($form->{"partsgroup_$i"}) { |
|
878 |
$var = $form->like(lc $form->{"partsgroup_$i"}); |
|
879 |
$where .= " AND lower(pg.partsgroup) LIKE '$var'"; |
|
751 |
my %columns = ("partnumber" => "p", "description" => "p", "partsgroup" => "pg"); |
|
752 |
|
|
753 |
while (my ($column, $table) = each(%columns)) { |
|
754 |
next unless ($form->{"${column}_$i"}); |
|
755 |
$where .= qq| AND ${table}.${column} ILIKE ?|; |
|
756 |
push(@values, '%' . $form->{"${column}_$i"} . '%'); |
|
880 | 757 |
} |
881 | 758 |
|
882 | 759 |
if ($form->{id}) { |
883 |
$where .= " AND NOT p.id = $form->{id}"; |
|
760 |
$where .= qq| AND NOT (p.id = ?)|; |
|
761 |
push(@values, conv_i($form->{id})); |
|
884 | 762 |
} |
885 | 763 |
|
886 | 764 |
if ($partnumber) { |
887 |
$where .= " ORDER BY p.partnumber";
|
|
765 |
$where .= qq| ORDER BY p.partnumber|;
|
|
888 | 766 |
} else { |
889 |
$where .= " ORDER BY p.description";
|
|
767 |
$where .= qq| ORDER BY p.description|;
|
|
890 | 768 |
} |
891 | 769 |
|
892 | 770 |
# connect to database |
893 | 771 |
my $dbh = $form->dbconnect($myconfig); |
894 | 772 |
|
895 |
my $query = qq|SELECT p.id, p.partnumber, p.description, p.sellprice, |
|
896 |
p.weight, p.onhand, p.unit, |
|
897 |
pg.partsgroup |
|
898 |
FROM parts p |
|
899 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
900 |
WHERE $where|; |
|
901 |
my $sth = $dbh->prepare($query); |
|
902 |
$sth->execute || $form->dberror($query); |
|
903 |
|
|
904 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
|
905 |
push @{ $form->{item_list} }, $ref; |
|
906 |
} |
|
773 |
my $query = |
|
774 |
qq|SELECT p.id, p.partnumber, p.description, p.sellprice, p.weight, p.onhand, p.unit, pg.partsgroup |
|
775 |
FROM parts p |
|
776 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
777 |
WHERE $where|; |
|
778 |
$form->{item_list} = selectall_hashref_query($form, $dbh, $query, @values); |
|
907 | 779 |
|
908 |
$sth->finish; |
|
909 | 780 |
$dbh->disconnect; |
910 | 781 |
|
911 | 782 |
$main::lxdebug->leave_sub(); |
... | ... | |
916 | 787 |
|
917 | 788 |
my ($self, $myconfig, $form) = @_; |
918 | 789 |
|
919 |
my $where = '1 = 1'; |
|
920 |
my $var; |
|
921 |
|
|
922 |
my $group; |
|
923 |
my $limit; |
|
790 |
my $where = qq|1 = 1|; |
|
791 |
my (@values, $var, $flds, $group, $limit); |
|
924 | 792 |
|
925 |
foreach my $item (qw(partnumber drawing microfiche)) { |
|
926 |
if ($form->{$item}) { |
|
927 |
$var = $form->like(lc $form->{$item}); |
|
928 |
$where .= " AND lower(p.$item) LIKE '$var'"; |
|
793 |
foreach my $item (qw(partnumber drawing microfiche ean pg.partsgroup)) { |
|
794 |
my $column = $item; |
|
795 |
$column =~ s/.*\.//; |
|
796 |
if ($form->{$column}) { |
|
797 |
$where .= qq| AND (${item} ILIKE ?)|; |
|
798 |
push(@values, '%' . $form->{$column} . '%'); |
|
929 | 799 |
} |
930 | 800 |
} |
931 | 801 |
|
932 | 802 |
# special case for description |
933 |
if ($form->{description}) { |
|
934 |
unless ( $form->{bought} |
|
935 |
|| $form->{sold} |
|
936 |
|| $form->{onorder} |
|
937 |
|| $form->{ordered} |
|
938 |
|| $form->{rfq} |
|
939 |
|| $form->{quoted}) { |
|
940 |
$var = $form->like(lc $form->{description}); |
|
941 |
$where .= " AND lower(p.description) LIKE '$var'"; |
|
942 |
} |
|
803 |
if ($form->{description} |
|
804 |
&& !( $form->{bought} || $form->{sold} || $form->{onorder} |
|
805 |
|| $form->{ordered} || $form->{rfq} || $form->{quoted})) { |
|
806 |
$where .= qq| AND (p.description ILIKE ?)|; |
|
807 |
push(@values, '%' . $form->{description} . '%'); |
|
943 | 808 |
} |
944 | 809 |
|
945 | 810 |
# special case for serialnumber |
946 |
if ($form->{l_serialnumber}) { |
|
947 |
if ($form->{serialnumber}) { |
|
948 |
$var = $form->like(lc $form->{serialnumber}); |
|
949 |
$where .= " AND lower(serialnumber) LIKE '$var'"; |
|
950 |
} |
|
811 |
if ($form->{l_serialnumber} && $form->{serialnumber}) { |
|
812 |
$where .= qq| AND (p.serialnumber ILIKE ?)|; |
|
813 |
push(@values, '%' . $form->{serialnumber} . '%'); |
|
951 | 814 |
} |
952 | 815 |
|
953 |
if ($form->{ean}) { |
|
954 |
$var = $form->like(lc $form->{ean}); |
|
955 |
$where .= " AND lower(ean) LIKE '$var'"; |
|
956 |
} |
|
957 |
|
|
958 | 816 |
if ($form->{searchitems} eq 'part') { |
959 |
$where .= " AND p.inventory_accno_id > 0";
|
|
817 |
$where .= qq| AND (p.inventory_accno_id > 0) |;
|
|
960 | 818 |
} |
819 |
|
|
961 | 820 |
if ($form->{searchitems} eq 'assembly') { |
962 | 821 |
$form->{bought} = ""; |
963 |
$where .= " AND p.assembly = '1'";
|
|
822 |
$where .= qq| AND p.assembly|;
|
|
964 | 823 |
} |
824 |
|
|
965 | 825 |
if ($form->{searchitems} eq 'service') { |
966 |
$where .= " AND p.inventory_accno_id IS NULL AND NOT p.assembly = '1'";
|
|
826 |
$where .= qq| AND (p.inventory_accno_id IS NULL) AND NOT (p.assembly = '1')|;
|
|
967 | 827 |
|
968 | 828 |
# irrelevant for services |
969 | 829 |
$form->{make} = $form->{model} = ""; |
... | ... | |
978 | 838 |
|
979 | 839 |
$form->{transdatefrom} = $form->{transdateto} = ""; |
980 | 840 |
|
981 |
$where .= " AND p.onhand = 0 |
|
982 |
AND p.id NOT IN (SELECT p.id FROM parts p, invoice i |
|
983 |
WHERE p.id = i.parts_id) |
|
984 |
AND p.id NOT IN (SELECT p.id FROM parts p, assembly a |
|
985 |
WHERE p.id = a.parts_id) |
|
986 |
AND p.id NOT IN (SELECT p.id FROM parts p, orderitems o |
|
987 |
WHERE p.id = o.parts_id)"; |
|
841 |
$where .= |
|
842 |
qq| AND (p.onhand = 0) |
|
843 |
AND p.id NOT IN |
|
844 |
( |
|
845 |
SELECT DISTINCT parts_id FROM invoice |
|
846 |
UNION |
|
847 |
SELECT DISTINCT parts_id FROM assembly |
|
848 |
UNION |
|
849 |
SELECT DISTINCT parts_id FROM orderitems |
|
850 |
)|; |
|
988 | 851 |
} |
989 | 852 |
|
990 | 853 |
if ($form->{itemstatus} eq 'active') { |
991 |
$where .= " AND p.obsolete = '0'"; |
|
992 |
} |
|
993 |
if ($form->{itemstatus} eq 'obsolete') { |
|
994 |
$where .= " AND p.obsolete = '1'"; |
|
854 |
$where .= qq| AND (p.obsolete = '0')|; |
|
855 |
} elsif ($form->{itemstatus} eq 'obsolete') { |
|
856 |
$where .= qq| AND (p.obsolete = '1')|; |
|
995 | 857 |
$form->{onhand} = $form->{short} = 0; |
858 |
} elsif ($form->{itemstatus} eq 'onhand') { |
|
859 |
$where .= qq| AND (p.onhand > 0)|; |
|
860 |
} elsif ($form->{itemstatus} eq 'short') { |
|
861 |
$where .= qq| AND (p.onhand < p.rop)|; |
|
996 | 862 |
} |
997 |
if ($form->{itemstatus} eq 'onhand') { |
|
998 |
$where .= " AND p.onhand > 0"; |
|
999 |
} |
|
1000 |
if ($form->{itemstatus} eq 'short') { |
|
1001 |
$where .= " AND p.onhand < p.rop"; |
|
1002 |
} |
|
1003 |
if ($form->{make}) { |
|
1004 |
$var = $form->like(lc $form->{make}); |
|
1005 |
$where .= " AND p.id IN (SELECT DISTINCT ON (m.parts_id) m.parts_id |
|
1006 |
FROM makemodel m WHERE lower(m.make) LIKE '$var')"; |
|
1007 |
} |
|
1008 |
if ($form->{model}) { |
|
1009 |
$var = $form->like(lc $form->{model}); |
|
1010 |
$where .= " AND p.id IN (SELECT DISTINCT ON (m.parts_id) m.parts_id |
|
1011 |
FROM makemodel m WHERE lower(m.model) LIKE '$var')"; |
|
1012 |
} |
|
1013 |
if ($form->{partsgroup}) { |
|
1014 |
$var = $form->like(lc $form->{partsgroup}); |
|
1015 |
$where .= " AND lower(pg.partsgroup) LIKE '$var'"; |
|
863 |
|
|
864 |
foreach my $column (qw(make model)) { |
|
865 |
next unless ($form->{$column}); |
|
866 |
$where .= qq| AND p.id IN (SELECT DISTINCT m.parts_id FROM makemodel WHERE $column ILIKE ?)|; |
|
867 |
push(@values, '%' . $form->{$column} . '%'); |
|
1016 | 868 |
} |
869 |
|
|
1017 | 870 |
if ($form->{l_soldtotal}) { |
1018 |
$where .= " AND p.id=i.parts_id AND i.qty >= 0";
|
|
871 |
$where .= qq| AND (p.id = i.parts_id) AND (i.qty >= 0)|;
|
|
1019 | 872 |
$group = |
1020 |
" GROUP BY p.id,p.partnumber,p.description,p.onhand,p.unit,p.bin, p.sellprice,p.listprice,p.lastcost,p.priceupdate,pg.partsgroup"; |
|
1021 |
} |
|
1022 |
if ($form->{top100}) { |
|
1023 |
$limit = " LIMIT 100"; |
|
873 |
qq| GROUP BY p.id, p.partnumber, p.description, p.onhand, p.unit, p.bin, p.sellprice, p.listprice, p.lastcost, p.priceupdate, pg.partsgroup|; |
|
1024 | 874 |
} |
1025 | 875 |
|
1026 |
# tables revers? |
|
1027 |
if ($form->{revers} == 1) { |
|
1028 |
$form->{desc} = " DESC"; |
|
1029 |
} else { |
|
1030 |
$form->{desc} = ""; |
|
1031 |
} |
|
876 |
$limit = qq| LIMIT 100| if ($form->{top100}); |
|
1032 | 877 |
|
1033 | 878 |
# connect to database |
1034 | 879 |
my $dbh = $form->dbconnect($myconfig); |
1035 | 880 |
|
1036 |
my $sortorder = $form->{sort}; |
|
1037 |
$sortorder .= $form->{desc}; |
|
1038 |
$sortorder = $form->{sort} if $form->{sort}; |
|
881 |
my @sort_cols = qw(id partnumber description partsgroup bin priceupdate onhand |
|
882 |
invnumber ordnumber quonumber name drawing microfiche |
|
883 |
serialnumber soldtotal deliverydate); |
|
884 |
|
|
885 |
my $sortorder = "partnumber"; |
|
886 |
$sortorder = $form->{sort} if ($form->{sort} && grep({ $_ eq $form->{sort} } @sort_cols)); |
|
887 |
$sortorder .= " DESC" if ($form->{revers}); |
|
1039 | 888 |
|
1040 | 889 |
my $query = ""; |
1041 | 890 |
|
1042 | 891 |
if ($form->{l_soldtotal}) { |
1043 | 892 |
$form->{soldtotal} = 'soldtotal'; |
1044 | 893 |
$query = |
1045 |
qq|SELECT p.id,p.partnumber,p.description,p.onhand,p.unit,p.bin,p.sellprice,p.listprice,
|
|
1046 |
p.lastcost,p.priceupdate,pg.partsgroup,sum(i.qty) as soldtotal FROM parts
|
|
1047 |
p LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id), invoice i
|
|
1048 |
WHERE $where
|
|
1049 |
$group
|
|
1050 |
ORDER BY $sortorder
|
|
1051 |
$limit|;
|
|
894 |
qq|SELECT p.id, p.partnumber, p.description, p.onhand, p.unit, p.bin, p.sellprice, p.listprice,
|
|
895 |
p.lastcost, p.priceupdate, pg.partsgroup,sum(i.qty) AS soldtotal FROM parts
|
|
896 |
p LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id), invoice i
|
|
897 |
WHERE $where
|
|
898 |
$group
|
|
899 |
ORDER BY $sortorder
|
|
900 |
$limit|;
|
|
1052 | 901 |
} else { |
1053 |
$query = qq|SELECT p.id, p.partnumber, p.description, p.onhand, p.unit, |
|
1054 |
p.bin, p.sellprice, p.listprice, p.lastcost, p.rop, p.weight, |
|
1055 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
1056 |
pg.partsgroup |
|
1057 |
FROM parts p |
|
1058 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
1059 |
WHERE $where |
|
1060 |
$group |
|
1061 |
ORDER BY $sortorder|; |
|
902 |
$query = |
|
903 |
qq|SELECT p.id, p.partnumber, p.description, p.onhand, p.unit, |
|
904 |
p.bin, p.sellprice, p.listprice, p.lastcost, p.rop, p.weight, |
|
905 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
906 |
pg.partsgroup |
|
907 |
FROM parts p |
|
908 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
909 |
WHERE $where |
|
910 |
$group |
|
911 |
ORDER BY $sortorder |
|
912 |
$limit|; |
|
1062 | 913 |
} |
1063 | 914 |
|
915 |
my @all_values = @values; |
|
916 |
|
|
1064 | 917 |
# rebuild query for bought and sold items |
1065 | 918 |
if ( $form->{bought} |
1066 | 919 |
|| $form->{sold} |
... | ... | |
1068 | 921 |
|| $form->{ordered} |
1069 | 922 |
|| $form->{rfq} |
1070 | 923 |
|| $form->{quoted}) { |
1071 |
|
|
1072 |
my @a = qw(partnumber description bin priceupdate name); |
|
1073 |
|
|
1074 |
push @a, qw(invnumber serialnumber) if ($form->{bought} || $form->{sold}); |
|
1075 |
push @a, "ordnumber" if ($form->{onorder} || $form->{ordered}); |
|
1076 |
push @a, "quonumber" if ($form->{rfq} || $form->{quoted}); |
|
1077 |
|
|
1078 | 924 |
my $union = ""; |
1079 | 925 |
$query = ""; |
926 |
@all_values = (); |
|
1080 | 927 |
|
1081 | 928 |
if ($form->{bought} || $form->{sold}) { |
1082 | 929 |
|
930 |
my @invvalues = @values; |
|
1083 | 931 |
my $invwhere = "$where"; |
1084 |
$invwhere .= " AND i.assemblyitem = '0'"; |
|
1085 |
$invwhere .= " AND a.transdate >= '$form->{transdatefrom}'" |
|
1086 |
if $form->{transdatefrom}; |
|
1087 |
$invwhere .= " AND a.transdate <= '$form->{transdateto}'" |
|
1088 |
if $form->{transdateto}; |
|
932 |
$invwhere .= qq| AND i.assemblyitem = '0'|; |
|
933 |
|
|
934 |
if ($form->{transdatefrom}) { |
|
935 |
$invwhere .= qq| AND a.transdate >= ?|; |
|
936 |
push(@invvalues, $form->{transdatefrom}); |
|
937 |
} |
|
938 |
|
|
939 |
if ($form->{transdateto}) { |
|
940 |
$invwhere .= qq| AND a.transdate <= ?|; |
|
941 |
push(@invvalues, $form->{transdateto}); |
|
942 |
} |
|
1089 | 943 |
|
1090 | 944 |
if ($form->{description}) { |
1091 |
$var = $form->like(lc $form->{description});
|
|
1092 |
$invwhere .= " AND lower(i.description) LIKE '$var'";
|
|
945 |
$invwhere .= qq| AND i.description ILIKE ?|;
|
|
946 |
push(@invvalues, '%' . $form->{description} . '%');
|
|
1093 | 947 |
} |
1094 | 948 |
|
1095 |
my $flds = qq|p.id, p.partnumber, i.description, i.serialnumber, |
|
1096 |
i.qty AS onhand, i.unit, p.bin, i.sellprice, |
|
1097 |
p.listprice, p.lastcost, p.rop, p.weight, |
|
1098 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
1099 |
pg.partsgroup, |
|
1100 |
a.invnumber, a.ordnumber, a.quonumber, i.trans_id, |
|
1101 |
ct.name, i.deliverydate|; |
|
949 |
$flds = |
|
950 |
qq|p.id, p.partnumber, i.description, i.serialnumber, |
|
951 |
i.qty AS onhand, i.unit, p.bin, i.sellprice, |
|
952 |
p.listprice, p.lastcost, p.rop, p.weight, |
|
953 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
954 |
pg.partsgroup, |
|
955 |
a.invnumber, a.ordnumber, a.quonumber, i.trans_id, |
|
956 |
ct.name, i.deliverydate|; |
|
1102 | 957 |
|
1103 | 958 |
if ($form->{bought}) { |
1104 |
$query = qq| |
|
1105 |
SELECT $flds, 'ir' AS module, '' AS type, |
|
1106 |
1 AS exchangerate |
|
1107 |
FROM invoice i |
|
1108 |
JOIN parts p ON (p.id = i.parts_id) |
|
1109 |
JOIN ap a ON (a.id = i.trans_id) |
|
1110 |
JOIN vendor ct ON (a.vendor_id = ct.id) |
|
1111 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
1112 |
WHERE $invwhere|; |
|
1113 |
$union = " |
|
1114 |
UNION"; |
|
959 |
$query = |
|
960 |
qq|SELECT $flds, 'ir' AS module, '' AS type, 1 AS exchangerate |
|
961 |
FROM invoice i |
|
962 |
JOIN parts p ON (p.id = i.parts_id) |
|
963 |
JOIN ap a ON (a.id = i.trans_id) |
|
964 |
JOIN vendor ct ON (a.vendor_id = ct.id) |
|
965 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
966 |
WHERE $invwhere|; |
|
967 |
|
|
968 |
$union = qq| UNION |; |
|
969 |
|
|
970 |
push(@all_values, @invvalues); |
|
1115 | 971 |
} |
1116 | 972 |
|
1117 | 973 |
if ($form->{sold}) { |
1118 |
$query .= qq|$union |
|
1119 |
SELECT $flds, 'is' AS module, '' AS type, |
|
1120 |
1 As exchangerate |
|
1121 |
FROM invoice i |
|
1122 |
JOIN parts p ON (p.id = i.parts_id) |
|
1123 |
JOIN ar a ON (a.id = i.trans_id) |
|
1124 |
JOIN customer ct ON (a.customer_id = ct.id) |
|
1125 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
1126 |
WHERE $invwhere|; |
|
1127 |
$union = " |
|
1128 |
UNION"; |
|
974 |
$query .= |
|
975 |
qq|$union |
|
976 |
|
|
977 |
SELECT $flds, 'is' AS module, '' AS type, 1 As exchangerate |
|
978 |
FROM invoice i |
|
979 |
JOIN parts p ON (p.id = i.parts_id) |
|
980 |
JOIN ar a ON (a.id = i.trans_id) |
|
981 |
JOIN customer ct ON (a.customer_id = ct.id) |
|
982 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
983 |
WHERE $invwhere|; |
|
984 |
$union = qq| UNION |; |
|
985 |
|
|
986 |
push(@all_values, @invvalues); |
|
1129 | 987 |
} |
1130 | 988 |
} |
1131 | 989 |
|
1132 | 990 |
if ($form->{onorder} || $form->{ordered}) { |
1133 |
my $ordwhere = "$where |
|
1134 |
AND o.quotation = '0'"; |
|
1135 |
$ordwhere .= " AND o.transdate >= '$form->{transdatefrom}'" |
|
1136 |
if $form->{transdatefrom}; |
|
1137 |
$ordwhere .= " AND o.transdate <= '$form->{transdateto}'" |
|
1138 |
if $form->{transdateto}; |
|
991 |
my @ordvalues = @values; |
|
992 |
my $ordwhere = $where . qq| AND o.quotation = '0'|; |
|
1139 | 993 |
|
1140 |
if ($form->{description}) {
|
|
1141 |
$var = $form->like(lc $form->{description});
|
|
1142 |
$ordwhere .= " AND lower(oi.description) LIKE '$var'";
|
|
994 |
if ($form->{transdatefrom}) {
|
|
995 |
$ordwhere .= qq| AND o.transdate >= ?|;
|
|
996 |
push(@ordvalues, $form->{transdatefrom});
|
|
1143 | 997 |
} |
1144 | 998 |
|
1145 |
$flds = |
|
1146 |
qq|p.id, p.partnumber, oi.description, oi.serialnumber AS serialnumber, |
|
1147 |
oi.qty AS onhand, oi.unit, p.bin, oi.sellprice, |
|
1148 |
p.listprice, p.lastcost, p.rop, p.weight, |
|
1149 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
1150 |
pg.partsgroup, |
|
1151 |
'' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id, |
|
1152 |
ct.name, NULL AS deliverydate|; |
|
999 |
if ($form->{transdateto}) { |
|
1000 |
$ordwhere .= qq| AND o.transdate <= ?|; |
|
1001 |
push(@ordvalues, $form->{transdateto}); |
|
1002 |
} |
|
1003 |
|
|
1004 |
if ($form->{description}) { |
|
1005 |
$ordwhere .= qq| AND oi.description ILIKE ?|; |
|
1006 |
push(@ordvalues, '%' . $form->{description} . '%'); |
|
1007 |
} |
|
1153 | 1008 |
|
1154 | 1009 |
if ($form->{ordered}) { |
1155 |
$query .= qq|$union |
|
1156 |
SELECT $flds, 'oe' AS module, 'sales_order' AS type, |
|
1157 |
(SELECT buy FROM exchangerate ex |
|
1158 |
WHERE ex.curr = o.curr |
|
1159 |
AND ex.transdate = o.transdate) AS exchangerate |
|
1160 |
FROM orderitems oi |
|
1161 |
JOIN parts p ON (oi.parts_id = p.id) |
|
1162 |
JOIN oe o ON (oi.trans_id = o.id) |
|
1163 |
JOIN customer ct ON (o.customer_id = ct.id) |
|
1164 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
1165 |
WHERE $ordwhere |
|
1166 |
AND o.customer_id > 0|; |
|
1167 |
$union = " |
|
1168 |
UNION"; |
|
1010 |
$query .= |
|
1011 |
qq|$union |
|
1012 |
|
|
1013 |
SELECT p.id, p.partnumber, oi.description, oi.serialnumber AS serialnumber, |
|
1014 |
oi.qty AS onhand, oi.unit, p.bin, oi.sellprice, |
|
1015 |
p.listprice, p.lastcost, p.rop, p.weight, |
|
1016 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
1017 |
pg.partsgroup, |
|
1018 |
'' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id, |
|
1019 |
ct.name, NULL AS deliverydate, |
|
1020 |
'oe' AS module, 'sales_order' AS type, |
|
1021 |
(SELECT buy FROM exchangerate ex |
|
1022 |
WHERE ex.curr = o.curr AND ex.transdate = o.transdate) AS exchangerate |
|
1023 |
FROM orderitems oi |
|
1024 |
JOIN parts p ON (oi.parts_id = p.id) |
|
1025 |
JOIN oe o ON (oi.trans_id = o.id) |
|
1026 |
JOIN customer ct ON (o.customer_id = ct.id) |
|
1027 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
1028 |
WHERE $ordwhere AND (o.customer_id > 0)|; |
|
1029 |
$union = qq| UNION |; |
|
1030 |
|
|
1031 |
push(@all_values, @ordvalues); |
|
1169 | 1032 |
} |
1170 | 1033 |
|
1171 | 1034 |
if ($form->{onorder}) { |
1172 |
$flds = |
|
1173 |
qq|p.id, p.partnumber, oi.description, oi.serialnumber AS serialnumber, |
|
1174 |
oi.qty * -1 AS onhand, oi.unit, p.bin, oi.sellprice, |
|
1175 |
p.listprice, p.lastcost, p.rop, p.weight, |
|
1176 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
1177 |
pg.partsgroup, |
|
1178 |
'' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id, |
|
1179 |
ct.name, NULL AS deliverydate|; |
|
1180 |
|
|
1181 |
$query .= qq|$union |
|
1182 |
SELECT $flds, 'oe' AS module, 'purchase_order' AS type, |
|
1183 |
(SELECT sell FROM exchangerate ex |
|
1184 |
WHERE ex.curr = o.curr |
|
1185 |
AND ex.transdate = o.transdate) AS exchangerate |
|
1186 |
FROM orderitems oi |
|
1187 |
JOIN parts p ON (oi.parts_id = p.id) |
|
1188 |
JOIN oe o ON (oi.trans_id = o.id) |
|
1189 |
JOIN vendor ct ON (o.vendor_id = ct.id) |
|
1190 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
1191 |
WHERE $ordwhere |
|
1192 |
AND o.vendor_id > 0|; |
|
1035 |
$query .= |
|
1036 |
qq|$union |
|
1037 |
|
|
1038 |
SELECT p.id, p.partnumber, oi.description, oi.serialnumber AS serialnumber, |
|
1039 |
oi.qty * -1 AS onhand, oi.unit, p.bin, oi.sellprice, |
|
1040 |
p.listprice, p.lastcost, p.rop, p.weight, |
|
1041 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
1042 |
pg.partsgroup, |
|
1043 |
'' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id, |
|
1044 |
ct.name, NULL AS deliverydate, |
|
1045 |
'oe' AS module, 'purchase_order' AS type, |
|
1046 |
(SELECT sell FROM exchangerate ex |
|
1047 |
WHERE ex.curr = o.curr AND (ex.transdate = o.transdate)) AS exchangerate |
|
1048 |
FROM orderitems oi |
|
1049 |
JOIN parts p ON (oi.parts_id = p.id) |
|
1050 |
JOIN oe o ON (oi.trans_id = o.id) |
|
1051 |
JOIN vendor ct ON (o.vendor_id = ct.id) |
|
1052 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
1053 |
WHERE $ordwhere AND (o.vendor_id > 0)|; |
|
1054 |
$union = qq| UNION |; |
|
1055 |
|
|
1056 |
push(@all_values, @ordvalues); |
|
1193 | 1057 |
} |
1194 | 1058 |
|
1195 | 1059 |
} |
1196 | 1060 |
|
1197 | 1061 |
if ($form->{rfq} || $form->{quoted}) { |
1198 |
my $quowhere = "$where |
|
1199 |
AND o.quotation = '1'"; |
|
1200 |
$quowhere .= " AND o.transdate >= '$form->{transdatefrom}'" |
|
1201 |
if $form->{transdatefrom}; |
|
1202 |
$quowhere .= " AND o.transdate <= '$form->{transdateto}'" |
|
1203 |
if $form->{transdateto}; |
|
1062 |
my $quowhere = $where . qq| AND o.quotation = '1'|; |
|
1063 |
my @quovalues = @values; |
|
1204 | 1064 |
|
1205 |
if ($form->{description}) {
|
|
1206 |
$var = $form->like(lc $form->{description});
|
|
1207 |
$quowhere .= " AND lower(oi.description) LIKE '$var'";
|
|
1065 |
if ($form->{transdatefrom}) {
|
|
1066 |
$quowhere .= qq| AND o.transdate >= ?|;
|
|
1067 |
push(@quovalues, $form->{transdatefrom});
|
|
1208 | 1068 |
} |
1209 | 1069 |
|
1210 |
$flds = |
|
1211 |
qq|p.id, p.partnumber, oi.description, oi.serialnumber AS serialnumber, |
|
1212 |
oi.qty AS onhand, oi.unit, p.bin, oi.sellprice, |
|
1213 |
p.listprice, p.lastcost, p.rop, p.weight, |
|
1214 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
1215 |
pg.partsgroup, |
|
1216 |
'' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id, |
|
1217 |
ct.name, NULL AS deliverydate|; |
|
1070 |
if ($form->{transdateto}) { |
|
1071 |
$quowhere .= qq| AND o.transdate <= ?|; |
|
1072 |
push(@quovalues, $form->{transdateto}); |
|
1073 |
} |
|
1074 |
|
|
1075 |
if ($form->{description}) { |
|
1076 |
$quowhere .= qq| AND oi.description ILIKE ?|; |
|
1077 |
push(@quovalues, '%' . $form->{description} . '%'); |
|
1078 |
} |
|
1218 | 1079 |
|
1219 | 1080 |
if ($form->{quoted}) { |
1220 |
$query .= qq|$union |
|
1221 |
SELECT $flds, 'oe' AS module, 'sales_quotation' AS type, |
|
1222 |
(SELECT buy FROM exchangerate ex |
|
1223 |
WHERE ex.curr = o.curr |
|
1224 |
AND ex.transdate = o.transdate) AS exchangerate |
|
1225 |
FROM orderitems oi |
|
1226 |
JOIN parts p ON (oi.parts_id = p.id) |
|
1227 |
JOIN oe o ON (oi.trans_id = o.id) |
|
1228 |
JOIN customer ct ON (o.customer_id = ct.id) |
|
1229 |
LEFT JOIN partsgroup pg ON (p.partsgroup_id = pg.id) |
|
1230 |
WHERE $quowhere |
|
1231 |
AND o.customer_id > 0|; |
|
1232 |
$union = " |
|
1233 |
UNION"; |
|
1081 |
$query .= |
|
1082 |
qq|$union |
|
1083 |
|
|
1084 |
SELECT |
|
1085 |
p.id, p.partnumber, oi.description, oi.serialnumber AS serialnumber, |
|
1086 |
oi.qty AS onhand, oi.unit, p.bin, oi.sellprice, |
|
1087 |
p.listprice, p.lastcost, p.rop, p.weight, |
|
1088 |
p.priceupdate, p.image, p.drawing, p.microfiche, |
|
1089 |
pg.partsgroup, |
|
1090 |
'' AS invnumber, o.ordnumber, o.quonumber, oi.trans_id, |
|
1091 |
ct.name, NULL AS deliverydate, 'oe' AS module, 'sales_quotation' AS type, |
|
1092 |
(SELECT buy FROM exchangerate ex |
|
1093 |
WHERE (ex.curr = o.curr) AND (ex.transdate = o.transdate)) AS exchangerate |
|
1094 |
FROM orderitems oi |
Auch abrufbar als: Unified diff
Umstellung von IC.pm auf die Verwendung von parametrisierten Queries und gequoteter Werte zur Vermeidung von SQL injections.