Revision 41592331
Von Moritz Bunkus vor fast 18 Jahren hinzugefügt
SL/AR.pm | ||
---|---|---|
96 | 96 |
for $i (1 .. $form->{rowcount}) { |
97 | 97 |
($form->{"tax_id_$i"}, $NULL) = split /--/, $form->{"taxchart_$i"}; |
98 | 98 |
|
99 |
$query = qq|SELECT c.accno, t.taxkey, t.rate |
|
100 |
FROM tax t LEFT JOIN chart c on (c.id=t.chart_id) |
|
101 |
WHERE t.id=$form->{"tax_id_$i"} |
|
102 |
ORDER BY c.accno|; |
|
99 |
$query = |
|
100 |
qq|SELECT c.accno, t.taxkey, t.rate | . |
|
101 |
qq|FROM tax t LEFT JOIN chart c on (c.id = t.chart_id) | . |
|
102 |
qq|WHERE t.id = ? | . |
|
103 |
qq|ORDER BY c.accno|; |
|
103 | 104 |
|
104 |
$sth = $dbh->prepare($query); |
|
105 |
$sth->execute || $form->dberror($query); |
|
106 | 105 |
($form->{AR_amounts}{"tax_$i"}, $form->{"taxkey_$i"}, $form->{"taxrate_$i"}) = |
107 |
$sth->fetchrow_array;
|
|
106 |
selectrow_query($form, $dbh, $query, $form->{"tax_id_$i"});
|
|
108 | 107 |
$form->{AR_amounts}{"tax_$i"}{taxkey} = $form->{"taxkey_$i"}; |
109 | 108 |
$form->{AR_amounts}{"amount_$i"}{taxkey} = $form->{"taxkey_$i"}; |
110 | 109 |
|
111 |
$sth->finish; |
|
112 | 110 |
if ($form->{taxincluded} *= 1) { |
113 | 111 |
if (!$form->{"korrektur_$i"}) { |
114 | 112 |
$tax = |
... | ... | |
162 | 160 |
|
163 | 161 |
# if we have an id delete old records |
164 | 162 |
if ($form->{id}) { |
165 |
|
|
166 | 163 |
# delete detail records |
167 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = $form->{id}|;
|
|
168 |
$dbh->do($query) || $form->dberror($query);
|
|
164 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
|
|
165 |
do_query($form, $dbh, $query, $form->{id});
|
|
169 | 166 |
|
170 | 167 |
} else { |
171 |
my $uid = rand() . time; |
|
172 |
|
|
173 |
$uid .= $form->{login}; |
|
174 |
|
|
175 |
$uid = substr($uid, 2, 75); |
|
176 |
|
|
177 |
$query = qq|INSERT INTO ar (invnumber, employee_id) |
|
178 |
VALUES ('$uid', $form->{employee_id})|; |
|
179 |
$dbh->do($query) || $form->dberror($query); |
|
180 |
|
|
181 |
$query = qq|SELECT a.id FROM ar a |
|
182 |
WHERE a.invnumber = '$uid'|; |
|
183 |
$sth = $dbh->prepare($query); |
|
184 |
$sth->execute || $form->dberror($query); |
|
185 |
|
|
186 |
($form->{id}) = $sth->fetchrow_array; |
|
187 |
$sth->finish; |
|
168 |
$query = qq|SELECT nextval('glid')|; |
|
169 |
($form->{id}) = selectrow_query($form, $dbh, $query); |
|
188 | 170 |
|
171 |
$query = qq|INSERT INTO ar (id, invnumber, employee_id) VALUES (?, 'dummy', ?)|; |
|
172 |
do_query($form, $dbh, $query, $form->{id}, $form->{employee_id}); |
|
189 | 173 |
} |
190 | 174 |
|
191 | 175 |
# update department |
192 | 176 |
($null, $form->{department_id}) = split(/--/, $form->{department}); |
193 | 177 |
$form->{department_id} *= 1; |
194 | 178 |
|
195 |
# escape ' |
|
196 |
map { $form->{$_} =~ s/\'/\'\'/g } qw(invnumber ordnumber notes); |
|
197 |
|
|
198 | 179 |
# record last payment date in ar table |
199 | 180 |
$form->{datepaid} = $form->{transdate} unless $form->{datepaid}; |
200 |
my $datepaid = ($form->{paid} != 0) ? qq|'$form->{datepaid}'| : 'NULL';
|
|
201 |
|
|
202 |
$query = qq|UPDATE ar set
|
|
203 |
invnumber = '$form->{invnumber}',
|
|
204 |
ordnumber = '$form->{ordnumber}',
|
|
205 |
transdate = '$form->{transdate}',
|
|
206 |
customer_id = $form->{customer_id},
|
|
207 |
taxincluded = '$form->{taxincluded}',
|
|
208 |
amount = $form->{amount},
|
|
209 |
duedate = '$form->{duedate}',
|
|
210 |
paid = $form->{paid},
|
|
211 |
datepaid = $datepaid,
|
|
212 |
netamount = $form->{netamount},
|
|
213 |
curr = '$form->{currency}',
|
|
214 |
notes = '$form->{notes}',
|
|
215 |
department_id = $form->{department_id},
|
|
216 |
employee_id = $form->{employee_id}
|
|
217 |
WHERE id = $form->{id}|;
|
|
218 |
$dbh->do($query) || $form->dberror($query);
|
|
181 |
my $datepaid = ($form->{paid} != 0) ? $form->{datepaid} : undef;
|
|
182 |
|
|
183 |
$query = |
|
184 |
qq|UPDATE ar set | .
|
|
185 |
qq| invnumber = ?, ordnumber = ?, transdate = ?, customer_id = ?, | .
|
|
186 |
qq| taxincluded = ?, amount = ?, duedate = ?, paid = ?, datepaid = ?, | .
|
|
187 |
qq| netamount = ?, curr = ?, notes = ?, department_id = ?, | .
|
|
188 |
qq| employee_id = ? | .
|
|
189 |
qq|WHERE id = ?|;
|
|
190 |
my @values = ($form->{invnumber}, $form->{ordnumber},
|
|
191 |
conv_date($form->{transdate}), conv_i($form->{customer_id}),
|
|
192 |
$form->{taxincluded} ? 't' : 'f', $form->{amount},
|
|
193 |
conv_date($form->{duedate}), $form->{paid},
|
|
194 |
conv_date($datepaid), $form->{netamount},
|
|
195 |
$form->{currency}, $form->{notes},
|
|
196 |
conv_i($form->{department_id}),
|
|
197 |
conv_i($form->{employee_id}),
|
|
198 |
conv_i($form->{id}));
|
|
199 |
do_query($form, $dbh, $query, @values);
|
|
219 | 200 |
|
220 | 201 |
# amount for AR account |
221 | 202 |
$form->{receivables} = $form->round_amount($form->{amount}, 2) * -1; |
... | ... | |
229 | 210 |
# add individual transactions for AR, amount and taxes |
230 | 211 |
for $i (1 .. $form->{rowcount}) { |
231 | 212 |
if ($form->{"amount_$i"} != 0) { |
232 |
my $project_id = undef; |
|
233 |
$project_id = conv_i($form->{"project_id_$i"}); |
|
213 |
my $project_id = conv_i($form->{"project_id_$i"}); |
|
234 | 214 |
$taxkey = $form->{AR_amounts}{"amount_$i"}{taxkey}; |
235 | 215 |
|
236 |
@values = ($project_id); |
|
237 | 216 |
# insert detail records in acc_trans |
238 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
239 |
project_id, taxkey) |
|
240 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
241 |
WHERE c.accno = '$form->{AR_amounts}{"amount_$i"}'), |
|
242 |
$form->{"amount_$i"}, '$form->{transdate}', ?, '$taxkey')|; |
|
217 |
$query = |
|
218 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | . |
|
219 |
qq| project_id, taxkey) | . |
|
220 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
221 |
@values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"amount_$i"}), |
|
222 |
conv_i($form->{"amount_$i"}), conv_date($form->{transdate}), |
|
223 |
$project_id, conv_i($taxkey)); |
|
243 | 224 |
do_query($form, $dbh, $query, @values); |
244 |
if ($form->{"tax_$i"} != 0) { |
|
245 | 225 |
|
246 |
@values = ($project_id);
|
|
226 |
if ($form->{"tax_$i"} != 0) {
|
|
247 | 227 |
# insert detail records in acc_trans |
248 | 228 |
$query = |
249 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
250 |
project_id, taxkey) |
|
251 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
252 |
WHERE c.accno = '$form->{AR_amounts}{"tax_$i"}'), |
|
253 |
$form->{"tax_$i"}, '$form->{transdate}', ?, '$taxkey')|; |
|
229 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | . |
|
230 |
qq| project_id, taxkey) | . |
|
231 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . |
|
232 |
qq| ?, ?, ?, ?)|; |
|
233 |
@values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{"tax_$i"}), |
|
234 |
conv_i($form->{"tax_$i"}), conv_date($form->{transdate}), |
|
235 |
$project_id, conv_i($taxkey)); |
|
254 | 236 |
do_query($form, $dbh, $query, @values); |
255 | 237 |
} |
256 | 238 |
} |
257 | 239 |
} |
258 | 240 |
|
259 | 241 |
# add recievables |
260 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate) |
|
261 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
262 |
WHERE c.accno = '$form->{AR_amounts}{receivables}'), |
|
263 |
$form->{receivables}, '$form->{transdate}')|; |
|
264 |
$dbh->do($query) || $form->dberror($query); |
|
242 |
$query = |
|
243 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate) | . |
|
244 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?)|; |
|
245 |
@values = (conv_i($form->{id}), conv_i($form->{AR_amounts}{receivables}), |
|
246 |
conv_i($form->{receivables}), conv_date($form->{transdate})); |
|
247 |
do_query($form, $dbh, $query, @values); |
|
265 | 248 |
|
266 | 249 |
# add paid transactions |
267 | 250 |
for my $i (1 .. $form->{paidaccounts}) { |
268 | 251 |
if ($form->{"paid_$i"} != 0) { |
252 |
my $project_id = conv_i($form->{"paid_project_id_$i"}); |
|
269 | 253 |
|
270 | 254 |
$form->{"AR_paid_$i"} =~ s/\"//g; |
271 | 255 |
($form->{AR}{"paid_$i"}) = split(/--/, $form->{"AR_paid_$i"}); |
... | ... | |
296 | 280 |
$form->round_amount($form->{"paid_$i"} * $form->{exchangerate}, 2); |
297 | 281 |
|
298 | 282 |
if ($form->{receivables} != 0) { |
299 |
|
|
300 | 283 |
# add receivable |
301 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
302 |
transdate, project_id) |
|
303 |
VALUES ($form->{id}, |
|
304 |
(SELECT c.id FROM chart c |
|
305 |
WHERE c.accno = '$form->{AR}{receivables}'), |
|
306 |
$amount, '$form->{"datepaid_$i"}', ?)|; |
|
307 |
do_query($form, $dbh, $query, $project_id); |
|
284 |
$query = |
|
285 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id) | . |
|
286 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?)|; |
|
287 |
@values = (conv_i($form->{id}), conv_i($form->{AR}{receivables}), |
|
288 |
$amount, conv_date($form->{"datepaid_$i"}), $project_id); |
|
289 |
do_query($form, $dbh, $query, @values); |
|
308 | 290 |
} |
309 | 291 |
$form->{receivables} = $amount; |
310 | 292 |
|
311 |
$form->{"memo_$i"} =~ s/\'/\'\'/g; |
|
312 |
|
|
313 | 293 |
if ($form->{"paid_$i"} != 0) { |
314 | 294 |
my $project_id = conv_i($form->{"paid_project_id_$i"}); |
315 | 295 |
# add payment |
316 | 296 |
$amount = $form->{"paid_$i"} * -1; |
317 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
318 |
transdate, source, memo, project_id) |
|
319 |
VALUES ($form->{id}, |
|
320 |
(SELECT c.id FROM chart c |
|
321 |
WHERE c.accno = '$form->{AR}{"paid_$i"}'), |
|
322 |
$amount, '$form->{"datepaid_$i"}', |
|
323 |
'$form->{"source_$i"}', '$form->{"memo_$i"}', ?)|; |
|
324 |
do_query($form, $dbh, $query, $project_id); |
|
297 |
$query = |
|
298 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo, project_id) | . |
|
299 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|; |
|
300 |
@values = (conv_i($form->{id}), conv_i($form->{AR}{"paid_$i"}), $amount, |
|
301 |
conv_date($form->{"datepaid_$i"}), $form->{"source_$i"}, |
|
302 |
$form->{"memo_$i"}, $project_id); |
|
303 |
do_query($form, $dbh, $query, @values); |
|
325 | 304 |
|
326 | 305 |
# exchangerate difference for payment |
327 | 306 |
$amount = |
... | ... | |
330 | 309 |
2); |
331 | 310 |
|
332 | 311 |
if ($amount != 0) { |
333 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
334 |
transdate, fx_transaction, cleared, project_id) |
|
335 |
VALUES ($form->{id}, |
|
336 |
(SELECT c.id FROM chart c |
|
337 |
WHERE c.accno = '$form->{AR}{"paid_$i"}'), |
|
338 |
$amount, '$form->{"datepaid_$i"}', '1', '0', ?)|; |
|
339 |
do_query($form, $dbh, $query, $project_id); |
|
312 |
$query = |
|
313 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id) | . |
|
314 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, 't', 'f', ?)|; |
|
315 |
@values = (conv_i($form->{id}), conv_i($form->{AR}{"paid_$i"}), |
|
316 |
$amount, conv_date($form->{"datepaid_$i"}), $project_id); |
|
317 |
do_query($form, $dbh, $query, @values); |
|
340 | 318 |
} |
341 | 319 |
|
342 | 320 |
# exchangerate gain/loss |
... | ... | |
349 | 327 |
if ($amount != 0) { |
350 | 328 |
$accno = |
351 | 329 |
($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno}; |
352 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
|
|
353 |
transdate, fx_transaction, cleared, project_id)
|
|
354 |
VALUES ($form->{id}, (SELECT c.id FROM chart c
|
|
355 |
WHERE c.accno = '$accno'),
|
|
356 |
$amount, '$form->{"datepaid_$i"}', '1', '0', ?)|;
|
|
357 |
do_query($form, $dbh, $query, $project_id);
|
|
330 |
$query = |
|
331 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared, project_id) | .
|
|
332 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, 't', 'f', ?)|;
|
|
333 |
@values = (conv_i($form->{id}), $accno, $amount,
|
|
334 |
conv_date($form->{"datepaid_$i"}), $project_id);
|
|
335 |
do_query($form, $dbh, $query, @values);
|
|
358 | 336 |
} |
359 | 337 |
} |
360 | 338 |
|
... | ... | |
433 | 411 |
2); |
434 | 412 |
|
435 | 413 |
|
436 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
437 |
WHERE c.accno = '$accno_ar') AND amount=$amount AND transdate='$form->{"datepaid_$i"}'|; |
|
438 |
$dbh->do($query) || $form->dberror($query); |
|
439 |
|
|
440 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
441 |
transdate, project_id) |
|
442 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
443 |
WHERE c.accno = '$accno_ar'), |
|
444 |
$amount, '$form->{"datepaid_$i"}', ?)|; |
|
445 |
do_query($form, $dbh, $query, $project_id); |
|
414 |
$query = |
|
415 |
qq|DELETE FROM acc_trans | . |
|
416 |
qq|WHERE trans_id = ? AND amount = ? AND transdate = ? AND | . |
|
417 |
qq| chart_id = (SELECT c.id FROM chart c WHERE c.accno = ?)|; |
|
418 |
@values = (conv_i($form->{id}), $amount, |
|
419 |
conv_date($form->{"datepaid_$i"}), $accno_ar); |
|
420 |
do_query($form, $dbh, $query, @values); |
|
446 | 421 |
|
422 |
$query = |
|
423 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id) | . |
|
424 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?)|; |
|
425 |
@values = (conv_i($form->{id}), $accno_ar, conv_i($amount), |
|
426 |
conv_date($form->{"datepaid_$i"}), $project_id); |
|
427 |
do_query($form, $dbh, $query, @values); |
|
447 | 428 |
|
448 | 429 |
# record payment |
449 | 430 |
$form->{"paid_$i"} *= -1; |
450 | 431 |
|
451 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
452 |
WHERE c.accno = '$accno') AND amount=$form->{"paid_$i"} AND transdate='$form->{"datepaid_$i"}' AND source='$form->{"source_$i"}' AND memo='$form->{"memo_$i"}'|; |
|
453 |
$dbh->do($query) || $form->dberror($query); |
|
454 |
|
|
455 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
456 |
source, memo, project_id) |
|
457 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
458 |
WHERE c.accno = '$accno'), |
|
459 |
$form->{"paid_$i"}, '$form->{"datepaid_$i"}', |
|
460 |
'$form->{"source_$i"}', '$form->{"memo_$i"}', ?)|; |
|
461 |
do_query($form, $dbh, $query, $project_id); |
|
432 |
$query = |
|
433 |
qq|DELETE FROM acc_trans | . |
|
434 |
qq|WHERE trans_id = ? AND | . |
|
435 |
qq| chart_id = (SELECT c.id FROM chart c WHERE c.accno = ?) AND | . |
|
436 |
qq| amount = ? AND transdate = ? AND source = ? AND memo = ?|; |
|
437 |
@values = (conv_i($form->{id}), $accno, conv_i($form->{"paid_$i"}), |
|
438 |
conv_date($form->{"datepaid_$i"}), |
|
439 |
$form->{"source_$i"}, $form->{"memo_$i"}); |
|
440 |
do_query($form, $dbh, $query, @values); |
|
462 | 441 |
|
442 |
$query = |
|
443 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo, project_id) | . |
|
444 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|; |
|
445 |
@values = (conv_i($form->{id}), $accno, conv_i($form->{"paid_$i"}), |
|
446 |
conv_date($form->{"datepaid_$i"}), |
|
447 |
$form->{"source_$i"}, $form->{"memo_$i"}, $project_id); |
|
448 |
do_query($form, $dbh, $query, @values); |
|
463 | 449 |
|
464 | 450 |
# gain/loss |
465 | 451 |
$amount = |
... | ... | |
492 | 478 |
$form->round_amount($form->{fx}{$accno}{$transdate}, 2) |
493 | 479 |
) != 0 |
494 | 480 |
) { |
495 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
496 |
WHERE c.accno = '$accno') AND amount=$form->{fx}{$accno}{$transdate} AND transdate='$transdate' AND cleared='0' AND fx_transaction='1'|; |
|
497 |
$dbh->do($query) || $form->dberror($query); |
|
498 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
499 |
transdate, cleared, fx_transaction, project_id) |
|
500 |
VALUES ($form->{id}, |
|
501 |
(SELECT c.id FROM chart c |
|
502 |
WHERE c.accno = '$accno'), |
|
503 |
$form->{fx}{$accno}{$transdate}, '$transdate', '0', '1', ?)|; |
|
504 |
do_query($form, $dbh, $query, $project_id); |
|
481 |
$query = |
|
482 |
qq|DELETE FROM acc_trans | . |
|
483 |
qq|WHERE trans_id = ? AND | . |
|
484 |
qq| chart_id = (SELECT c.id FROM chart c WHERE c.accno = ?) AND | . |
|
485 |
qq| amount = ? AND transdate = ? AND cleared = 'f' AND fx_transaction = 't'|; |
|
486 |
@values = (conv_i($form->{id}), $accno, |
|
487 |
conv_i($form->{fx}{$accno}{$transdate}), |
|
488 |
conv_date($transdate)); |
|
489 |
do_query($form, $dbh, $query, @values); |
|
490 |
|
|
491 |
$query = |
|
492 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, project_id) | . |
|
493 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, 'f', 't', ?)|; |
|
494 |
@values = (conv_i($form->{id}), $accno, |
|
495 |
conv_i($form->{fx}{$accno}{$transdate}), |
|
496 |
conv_date($transdate), $project_id); |
|
497 |
do_query($form, $dbh, $query, @values); |
|
505 | 498 |
} |
506 | 499 |
} |
507 | 500 |
} |
508 |
my $datepaid = ($form->{paid}) ? qq|'$form->{datepaid}'| : "NULL";
|
|
501 |
my $datepaid = ($form->{paid}) ? $form->{datepaid} : "NULL";
|
|
509 | 502 |
|
510 | 503 |
# save AR record |
511 |
my $query = qq|UPDATE ar set |
|
512 |
paid = $form->{paid}, |
|
513 |
datepaid = $datepaid |
|
514 |
WHERE id=$form->{id}|; |
|
515 |
|
|
516 |
$dbh->do($query) || $form->dberror($query); |
|
504 |
my $query = |
|
505 |
qq|UPDATE ar set paid = ?, datepaid = ? WHERE id = ?|; |
|
506 |
@values = (conv_i($form->{paid}), conv_date($datepaid), conv_i($form->{id})); |
|
507 |
do_query($form, $dbh, $query, @values); |
|
517 | 508 |
|
518 | 509 |
my $rc = $dbh->commit; |
519 | 510 |
$dbh->disconnect; |
... | ... | |
531 | 522 |
# connect to database, turn AutoCommit off |
532 | 523 |
my $dbh = $form->dbconnect_noauto($myconfig); |
533 | 524 |
|
534 |
my $query = qq|DELETE FROM ar WHERE id = $form->{id}|;
|
|
535 |
$dbh->do($query) || $form->dberror($query);
|
|
525 |
my $query = qq|DELETE FROM ar WHERE id = ?|;
|
|
526 |
do_query($form, $dbh, $query, $form->{id});
|
|
536 | 527 |
|
537 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = $form->{id}|;
|
|
538 |
$dbh->do($query) || $form->dberror($query);
|
|
528 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
|
|
529 |
do_query($form, $dbh, $query, $form->{id});
|
|
539 | 530 |
|
540 | 531 |
# commit |
541 | 532 |
my $rc = $dbh->commit; |
... | ... | |
556 | 547 |
|
557 | 548 |
my @values; |
558 | 549 |
|
559 |
my $query = qq|SELECT a.id, a.invnumber, a.ordnumber, a.transdate, |
|
560 |
a.duedate, a.netamount, a.amount, a.paid, c.name, |
|
561 |
a.invoice, a.datepaid, a.terms, a.notes, a.shipvia, |
|
562 |
a.shippingpoint, a.storno, a.globalproject_id, |
|
563 |
pr.projectnumber AS globalprojectnumber, |
|
564 |
e.name AS employee |
|
565 |
FROM ar a |
|
566 |
JOIN customer c ON (a.customer_id = c.id) |
|
567 |
LEFT JOIN employee e ON (a.employee_id = e.id) |
|
568 |
LEFT JOIN project pr ON a.globalproject_id = pr.id|; |
|
550 |
my $query = |
|
551 |
qq|SELECT a.id, a.invnumber, a.ordnumber, a.transdate, | . |
|
552 |
qq| a.duedate, a.netamount, a.amount, a.paid, | . |
|
553 |
qq| a.invoice, a.datepaid, a.terms, a.notes, a.shipvia, | . |
|
554 |
qq| a.shippingpoint, a.storno, a.globalproject_id, | . |
|
555 |
qq| pr.projectnumber AS globalprojectnumber, | . |
|
556 |
qq| c.name, | . |
|
557 |
qq| e.name AS employee | . |
|
558 |
qq|FROM ar a | . |
|
559 |
qq|JOIN customer c ON (a.customer_id = c.id) | . |
|
560 |
qq|LEFT JOIN employee e ON (a.employee_id = e.id) | . |
|
561 |
qq|LEFT JOIN project pr ON (a.globalproject_id = pr.id)|; |
|
569 | 562 |
|
570 | 563 |
my $where = "1 = 1"; |
571 | 564 |
if ($form->{customer_id}) { |
572 |
$where .= " AND a.customer_id = $form->{customer_id}"; |
|
573 |
} else { |
|
574 |
if ($form->{customer}) { |
|
575 |
my $customer = $form->like(lc $form->{customer}); |
|
576 |
$where .= " AND lower(c.name) LIKE '$customer'"; |
|
577 |
} |
|
565 |
$where .= " AND a.customer_id = ?"; |
|
566 |
push(@values, $form->{customer_id}); |
|
567 |
} elsif ($form->{customer}) { |
|
568 |
$where .= " AND c.name ILIKE ?"; |
|
569 |
push(@values, $form->like($form->{customer})); |
|
578 | 570 |
} |
579 | 571 |
if ($form->{department}) { |
580 | 572 |
my ($null, $department_id) = split /--/, $form->{department}; |
581 |
$where .= " AND a.department_id = $department_id"; |
|
582 |
} |
|
583 |
if ($form->{invnumber}) { |
|
584 |
my $invnumber = $form->like(lc $form->{invnumber}); |
|
585 |
$where .= " AND lower(a.invnumber) LIKE '$invnumber'"; |
|
573 |
$where .= " AND a.department_id = ?"; |
|
574 |
push(@values, $department_id); |
|
586 | 575 |
} |
587 |
if ($form->{ordnumber}) { |
|
588 |
my $ordnumber = $form->like(lc $form->{ordnumber}); |
|
589 |
$where .= " AND lower(a.ordnumber) LIKE '$ordnumber'"; |
|
590 |
} |
|
591 |
if ($form->{notes}) { |
|
592 |
my $notes = $form->like(lc $form->{notes}); |
|
593 |
$where .= " AND lower(a.notes) LIKE '$notes'"; |
|
576 |
foreach my $column (qw(invnumber ordnumber notes)) { |
|
577 |
if ($form->{$column}) { |
|
578 |
$where .= " AND a.$column ILIKE ?"; |
|
579 |
push(@values, $form->like($form->{$column})); |
|
580 |
} |
|
594 | 581 |
} |
595 | 582 |
if ($form->{"project_id"}) { |
596 | 583 |
$where .= |
... | ... | |
600 | 587 |
push(@values, $form->{"project_id"}, $form->{"project_id"}); |
601 | 588 |
} |
602 | 589 |
|
603 |
$where .= " AND a.transdate >= '$form->{transdatefrom}'" |
|
604 |
if $form->{transdatefrom}; |
|
605 |
$where .= " AND a.transdate <= '$form->{transdateto}'" |
|
606 |
if $form->{transdateto}; |
|
590 |
if ($form->{transdatefrom}) { |
|
591 |
$where .= " AND a.transdate >= ?"; |
|
592 |
push(@values, $form->{transdatefrom}); |
|
593 |
} |
|
594 |
if ($form->{transdateto}) { |
|
595 |
$where .= " AND a.transdate <= ?"; |
|
596 |
push(@values, $form->{transdateto}); |
|
597 |
} |
|
607 | 598 |
if ($form->{open} || $form->{closed}) { |
608 | 599 |
unless ($form->{open} && $form->{closed}) { |
609 | 600 |
$where .= " AND a.amount <> a.paid" if ($form->{open}); |
... | ... | |
613 | 604 |
|
614 | 605 |
my @a = (transdate, invnumber, name); |
615 | 606 |
push @a, "employee" if $form->{l_employee}; |
616 |
my $sortorder = join ', ', $form->sort_columns(@a);
|
|
617 |
$sortorder = $form->{sort} if $form->{sort};
|
|
607 |
my $sortorder = join(', ', @a);
|
|
608 |
$sortorder = $form->{sort} if ($form->{sort} && grep({ $_ eq $form->{sort} } @a));
|
|
618 | 609 |
|
619 |
$query .= " WHERE $where |
|
620 |
ORDER by $sortorder"; |
|
610 |
$query .= " WHERE $where ORDER by $sortorder"; |
|
621 | 611 |
|
622 | 612 |
my $sth = $dbh->prepare($query); |
623 | 613 |
$sth->execute(@values) || |
624 | 614 |
$form->dberror($query . " (" . join(", ", @values) . ")"); |
625 | 615 |
|
616 |
$form->{AR} = []; |
|
626 | 617 |
while (my $ar = $sth->fetchrow_hashref(NAME_lc)) { |
627 | 618 |
push @{ $form->{AR} }, $ar; |
628 | 619 |
} |
Auch abrufbar als: Unified diff
Umformatieren der Abfragen und Vermeidung von SQL injection durch Verwendung von parametrisierten Abfragen.