Revision 0ec7b690
Von Moritz Bunkus vor fast 18 Jahren hinzugefügt
SL/AP.pm | ||
---|---|---|
34 | 34 |
|
35 | 35 |
package AP; |
36 | 36 |
|
37 |
use SL::DBUtils; |
|
38 |
|
|
37 | 39 |
sub post_transaction { |
38 | 40 |
$main::lxdebug->enter_sub(); |
39 | 41 |
|
... | ... | |
90 | 92 |
for $i (1 .. $form->{rowcount}) { |
91 | 93 |
($form->{"tax_id_$i"}, $NULL) = split /--/, $form->{"taxchart_$i"}; |
92 | 94 |
|
93 |
$query = qq|SELECT c.accno, t.taxkey, t.rate |
|
94 |
FROM tax t LEFT JOIN chart c on (c.id=t.chart_id) |
|
95 |
WHERE t.id=$form->{"tax_id_$i"} |
|
96 |
ORDER BY c.accno|; |
|
95 |
$query = |
|
96 |
qq|SELECT c.accno, t.taxkey, t.rate | . |
|
97 |
qq|FROM tax t LEFT JOIN chart c on (c.id=t.chart_id) | . |
|
98 |
qq|WHERE t.id = ? | . |
|
99 |
qq|ORDER BY c.accno|; |
|
97 | 100 |
$sth = $dbh->prepare($query); |
98 |
$sth->execute || $form->dberror($query);
|
|
101 |
$sth->execute($form->{"tax_id_$i"}) || $form->dberror($query . " (" . $form->{"tax_id_$i"} . ")");
|
|
99 | 102 |
($form->{AP_amounts}{"tax_$i"}, $form->{"taxkey_$i"}, $form->{"taxrate_$i"}) = |
100 | 103 |
$sth->fetchrow_array; |
101 | 104 |
$form->{AP_amounts}{"tax_$i"}{taxkey} = $form->{"taxkey_$i"}; |
... | ... | |
160 | 163 |
if ($form->{id}) { |
161 | 164 |
|
162 | 165 |
# delete detail records |
163 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = $form->{id}|; |
|
164 |
|
|
165 |
$dbh->do($query) || $form->dberror($query); |
|
166 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = ?|; |
|
167 |
do_query($form, $dbh, $query, $form->{id}); |
|
166 | 168 |
|
167 | 169 |
} else { |
168 | 170 |
my $uid = rand() . time; |
... | ... | |
171 | 173 |
|
172 | 174 |
$uid = substr($uid, 2, 75); |
173 | 175 |
|
174 |
$query = qq|INSERT INTO ap (invnumber, employee_id)
|
|
175 |
VALUES ('$uid', (SELECT e.id FROM employee e
|
|
176 |
WHERE e.login = '$form->{login}') )|;
|
|
177 |
$dbh->do($query) || $form->dberror($query);
|
|
176 |
$query = |
|
177 |
qq|INSERT INTO ap (invnumber, employee_id) | .
|
|
178 |
qq|VALUES (?, (SELECT e.id FROM employee e WHERE e.login = ?))|;
|
|
179 |
do_query($form, $dbh, $query, $uid, $form->{login});
|
|
178 | 180 |
|
179 | 181 |
$query = qq|SELECT a.id FROM ap a |
180 |
WHERE a.invnumber = '$uid'|; |
|
181 |
$sth = $dbh->prepare($query); |
|
182 |
$sth->execute || $form->dberror($query); |
|
183 |
|
|
184 |
($form->{id}) = $sth->fetchrow_array; |
|
185 |
$sth->finish; |
|
186 |
|
|
182 |
WHERE a.invnumber = ?|; |
|
183 |
($form->{id}) = selectrow_query($form, $dbh, $query, $uid); |
|
187 | 184 |
} |
188 | 185 |
|
189 | 186 |
$form->{invnumber} = $form->{id} unless $form->{invnumber}; |
190 | 187 |
|
191 |
# escape ' |
|
192 |
map { $form->{$_} =~ s/\'/\'\'/g } qw(invnumber ordnumber notes); |
|
193 |
|
|
194 | 188 |
$form->{datepaid} = $form->{transdate} unless ($form->{datepaid}); |
195 |
my $datepaid = ($form->{invpaid} != 0) ? qq|'$form->{datepaid}'| : 'NULL';
|
|
189 |
my $datepaid = ($form->{invpaid} != 0) ? $form->{datepaid} : undef;
|
|
196 | 190 |
|
197 | 191 |
$query = qq|UPDATE ap SET |
198 |
invnumber = '$form->{invnumber}', |
|
199 |
transdate = '$form->{transdate}', |
|
200 |
ordnumber = '$form->{ordnumber}', |
|
201 |
vendor_id = $form->{vendor_id}, |
|
202 |
taxincluded = '$form->{taxincluded}', |
|
203 |
amount = $form->{invtotal}, |
|
204 |
duedate = '$form->{duedate}', |
|
205 |
paid = $form->{invpaid}, |
|
206 |
datepaid = $datepaid, |
|
207 |
netamount = $form->{netamount}, |
|
208 |
curr = '$form->{currency}', |
|
209 |
notes = '$form->{notes}', |
|
210 |
department_id = $form->{department_id} |
|
211 |
WHERE id = $form->{id} |
|
212 |
|; |
|
213 |
$dbh->do($query) || $form->dberror($query); |
|
192 |
invnumber = ?, |
|
193 |
transdate = ?, |
|
194 |
ordnumber = ?, |
|
195 |
vendor_id = ?, |
|
196 |
taxincluded = ?, |
|
197 |
amount = ?, |
|
198 |
duedate = ?, |
|
199 |
paid = ?, |
|
200 |
datepaid = ?, |
|
201 |
netamount = ?, |
|
202 |
curr = ?, |
|
203 |
notes = ?, |
|
204 |
department_id = ? |
|
205 |
WHERE id = ?|; |
|
206 |
my @values = ($form->{invnumber}, conv_date($form->{transdate}), |
|
207 |
$form->{ordnumber}, conv_i($form->{vendor_id}), |
|
208 |
$form->{taxincluded}, $form->{invtotal}, |
|
209 |
conv_date($form->{duedate}), $form->{invpaid}, |
|
210 |
conv_date($datepaid), $form->{netamount}, |
|
211 |
$form->{currency}, $form->{notes}, |
|
212 |
conv_i($form->{department_id}), $form->{id}); |
|
213 |
do_query($form, $dbh, $query, @values); |
|
214 | 214 |
|
215 | 215 |
# update exchangerate |
216 | 216 |
if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) { |
... | ... | |
221 | 221 |
# add individual transactions |
222 | 222 |
for $i (1 .. $form->{rowcount}) { |
223 | 223 |
if ($form->{"amount_$i"} != 0) { |
224 |
$project_id = 'NULL';
|
|
224 |
my $project_id;
|
|
225 | 225 |
if ("amount_$i" =~ /amount_/) { |
226 | 226 |
if ($form->{"project_id_$i"} && $form->{"projectnumber_$i"}) { |
227 | 227 |
$project_id = $form->{"project_id_$i"}; |
... | ... | |
232 | 232 |
} |
233 | 233 |
|
234 | 234 |
# insert detail records in acc_trans |
235 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
236 |
project_id, taxkey) |
|
237 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
238 |
WHERE c.accno = '$form->{AP_amounts}{"amount_$i"}'), |
|
239 |
$form->{"amount_$i"}, '$form->{transdate}', $project_id, '$taxkey')|; |
|
240 |
$dbh->do($query) || $form->dberror($query); |
|
235 |
$query = |
|
236 |
qq|INSERT INTO acc_trans | . |
|
237 |
qq| (trans_id, chart_id, amount, transdate, project_id, taxkey)| . |
|
238 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . |
|
239 |
qq| ?, ?, ?, ?)|; |
|
240 |
@values = ($form->{id}, $form->{AP_amounts}{"amount_$i"}, |
|
241 |
$form->{"amount_$i"}, conv_date($form->{transdate}), |
|
242 |
conv_i($project_id), $taxkey); |
|
243 |
do_query($form, $dbh, $query, @values); |
|
241 | 244 |
|
242 | 245 |
if ($form->{"tax_$i"} != 0) { |
243 |
|
|
244 | 246 |
# insert detail records in acc_trans |
245 | 247 |
$query = |
246 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
247 |
project_id, taxkey) |
|
248 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
249 |
WHERE c.accno = '$form->{AP_amounts}{"tax_$i"}'), |
|
250 |
$form->{"tax_$i"}, '$form->{transdate}', $project_id, '$taxkey')|; |
|
251 |
$dbh->do($query) || $form->dberror($query); |
|
248 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, | . |
|
249 |
qq| project_id, taxkey) | . |
|
250 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . |
|
251 |
qq| ?, ?, ?, ?)|; |
|
252 |
@values = ($form->{id}, $form->{AP_amounts}{"tax_$i"}, |
|
253 |
$form->{"tax_$i"}, conv_date($form->{transdate}), |
|
254 |
conv_date($project_id), $taxkey); |
|
255 |
do_query($form, $dbh, $query, @values); |
|
252 | 256 |
} |
253 | 257 |
|
254 | 258 |
} |
255 | 259 |
} |
256 | 260 |
|
257 | 261 |
# add payables |
258 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
259 |
project_id) |
|
260 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
261 |
WHERE c.accno = '$form->{AP_amounts}{payables}'), |
|
262 |
$form->{payables}, '$form->{transdate}', $project_id)|; |
|
263 |
$dbh->do($query) || $form->dberror($query); |
|
262 |
$query = |
|
263 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id) | . |
|
264 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), | . |
|
265 |
qq| ?, ?, ?)|; |
|
266 |
@values = ($form->{id}, $form->{AP_amounts}{payables}, $form->{payables}, |
|
267 |
conv_date($form->{transdate}), conv_i($project_id)); |
|
268 |
do_query($form, $dbh, $query, @values); |
|
264 | 269 |
|
265 | 270 |
# if there is no amount but a payment record a payable |
266 | 271 |
if ($form->{amount} == 0 && $form->{invtotal} == 0) { |
... | ... | |
301 | 306 |
$form->round_amount($form->{"paid_$i"} * $form->{exchangerate} * -1, |
302 | 307 |
2); |
303 | 308 |
if ($form->{payables}) { |
304 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
305 |
transdate) |
|
306 |
VALUES ($form->{id}, |
|
307 |
(SELECT c.id FROM chart c |
|
308 |
WHERE c.accno = '$form->{AP}{payables}'), |
|
309 |
$amount, '$form->{"datepaid_$i"}')|; |
|
310 |
$dbh->do($query) || $form->dberror($query); |
|
309 |
$query = |
|
310 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate) | . |
|
311 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?)|; |
|
312 |
@values = ($form->{id}, $form->{AP}{payables}, $amount, |
|
313 |
conv_date($form->{"datepaid_$i"})); |
|
314 |
do_query($form, $dbh, $query, @values); |
|
311 | 315 |
} |
312 | 316 |
$form->{payables} = $amount; |
313 | 317 |
|
314 |
$form->{"memo_$i"} =~ s/\'/\'\'/g; |
|
315 |
|
|
316 | 318 |
# add payment |
317 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
318 |
transdate, source, memo) |
|
319 |
VALUES ($form->{id}, |
|
320 |
(SELECT c.id FROM chart c |
|
321 |
WHERE c.accno = '$form->{AP}{"paid_$i"}'), |
|
322 |
$form->{"paid_$i"}, '$form->{"datepaid_$i"}', |
|
323 |
'$form->{"source_$i"}', '$form->{"memo_$i"}')|; |
|
324 |
$dbh->do($query) || $form->dberror($query); |
|
319 |
$query = |
|
320 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo) | . |
|
321 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
322 |
@values = ($form->{id}, $form->{AP}{"paid_$i"}, $form->{"paid_$i"}, |
|
323 |
conv_date($form->{"datepaid_$i"}), $form->{"source_$i"}, |
|
324 |
$form->{"memo_$i"}); |
|
325 |
do_query($form, $dbh, $query, @values); |
|
325 | 326 |
|
326 | 327 |
# add exchange rate difference |
327 | 328 |
$amount = |
328 |
$form->round_amount( |
|
329 |
$form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1), |
|
330 |
2); |
|
329 |
$form->round_amount($form->{"paid_$i"} * |
|
330 |
($form->{"exchangerate_$i"} - 1), 2); |
|
331 | 331 |
if ($amount != 0) { |
332 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
333 |
transdate, fx_transaction, cleared) |
|
334 |
VALUES ($form->{id}, |
|
335 |
(SELECT c.id FROM chart c |
|
336 |
WHERE c.accno = '$form->{AP}{"paid_$i"}'), |
|
337 |
$amount, '$form->{"datepaid_$i"}', '1', '0')|; |
|
338 |
|
|
339 |
$dbh->do($query) || $form->dberror($query); |
|
332 |
$query = |
|
333 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared) | . |
|
334 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, 't', 'f')|; |
|
335 |
@values = ($form->{id}, $form->{AP}{"paid_$i"}, $amount, |
|
336 |
conv_date($form->{"datepaid_$i"})); |
|
337 |
do_query($form, $dbh, $query, @values); |
|
340 | 338 |
} |
341 | 339 |
|
342 | 340 |
# exchangerate gain/loss |
343 | 341 |
$amount = |
344 |
$form->round_amount( |
|
345 |
$form->{"paid_$i"} * |
|
346 |
($form->{exchangerate} - $form->{"exchangerate_$i"}), |
|
347 |
2); |
|
342 |
$form->round_amount($form->{"paid_$i"} * |
|
343 |
($form->{exchangerate} - |
|
344 |
$form->{"exchangerate_$i"}), 2); |
|
348 | 345 |
|
349 | 346 |
if ($amount != 0) { |
350 |
$accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno};
|
|
351 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
|
|
352 |
transdate, fx_transaction, cleared)
|
|
353 |
VALUES ($form->{id}, (SELECT c.id FROM chart c
|
|
354 |
WHERE c.accno = '$accno'),
|
|
355 |
$amount, '$form->{"datepaid_$i"}', '1', '0')|;
|
|
356 |
$dbh->do($query) || $form->dberror($query);
|
|
347 |
$query =
|
|
348 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, fx_transaction, cleared) | .
|
|
349 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, 't', 'f')|;
|
|
350 |
@values = ($form->{id}, ($amount > 0) ?
|
|
351 |
$form->{fxgain_accno} : $form->{fxloss_accno},
|
|
352 |
$amount, conv_date($form->{"datepaid_$i"}));
|
|
353 |
do_query($form, $dbh, $query, @values);
|
|
357 | 354 |
} |
358 | 355 |
|
359 | 356 |
# update exchange rate record |
... | ... | |
381 | 378 |
# connect to database |
382 | 379 |
my $dbh = $form->dbconnect_noauto($myconfig); |
383 | 380 |
|
384 |
my $query = qq|DELETE FROM ap WHERE id = $form->{id}|;
|
|
385 |
$dbh->do($query) || $form->dberror($query);
|
|
381 |
my $query = qq|DELETE FROM ap WHERE id = ?|;
|
|
382 |
do_query($form, $dbh, $query, $form->{id});
|
|
386 | 383 |
|
387 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = $form->{id}|;
|
|
388 |
$dbh->do($query) || $form->dberror($query);
|
|
384 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = ?|;
|
|
385 |
do_query($form, $dbh, $query, $form->{id});
|
|
389 | 386 |
|
390 | 387 |
# commit and redirect |
391 | 388 |
my $rc = $dbh->commit; |
... | ... | |
404 | 401 |
# connect to database |
405 | 402 |
my $dbh = $form->dbconnect($myconfig); |
406 | 403 |
|
407 |
my $query = qq|SELECT a.id, a.invnumber, a.transdate, a.duedate, |
|
408 |
a.amount, a.paid, a.ordnumber, v.name, a.invoice, |
|
409 |
a.netamount, a.datepaid, a.notes, e.name AS employee |
|
410 |
FROM ap a |
|
411 |
JOIN vendor v ON (a.vendor_id = v.id) |
|
412 |
LEFT JOIN employee e ON (a.employee_id = e.id)|; |
|
404 |
my $query = |
|
405 |
qq|SELECT a.id, a.invnumber, a.transdate, a.duedate, a.amount, a.paid, | . |
|
406 |
qq| a.ordnumber, v.name, a.invoice, a.netamount, a.datepaid, a.notes, | . |
|
407 |
qq| e.name AS employee | . |
|
408 |
qq|FROM ap a | . |
|
409 |
qq|JOIN vendor v ON (a.vendor_id = v.id) | . |
|
410 |
qq|LEFT JOIN employee e ON (a.employee_id = e.id)|; |
|
413 | 411 |
|
414 |
my $where = "1 = 1"; |
|
412 |
my $where; |
|
413 |
my @values; |
|
415 | 414 |
|
416 | 415 |
if ($form->{vendor_id}) { |
417 |
$where .= " AND a.vendor_id = $form->{vendor_id}"; |
|
418 |
} else { |
|
419 |
if ($form->{vendor}) { |
|
420 |
my $vendor = $form->like(lc $form->{vendor}); |
|
421 |
$where .= " AND lower(v.name) LIKE '$vendor'"; |
|
422 |
} |
|
416 |
$where .= " AND a.vendor_id = ?"; |
|
417 |
push(@values, $form->{vendor_id}); |
|
418 |
} elsif ($form->{vendor}) { |
|
419 |
$where .= " AND v.name ILIKE ?"; |
|
420 |
push(@values, $form->like($form->{vendor})); |
|
423 | 421 |
} |
424 | 422 |
if ($form->{department}) { |
425 | 423 |
my ($null, $department_id) = split /--/, $form->{department}; |
426 |
$where .= " AND a.department_id = $department_id"; |
|
424 |
$where .= " AND a.department_id = ?"; |
|
425 |
push(@values, $department_id); |
|
427 | 426 |
} |
428 | 427 |
if ($form->{invnumber}) { |
429 |
my $invnumber = $form->like(lc $form->{invnumber});
|
|
430 |
$where .= " AND lower(a.invnumber) LIKE '$invnumber'";
|
|
428 |
$where .= " AND a.invnumber ILIKE ?";
|
|
429 |
push(@values, $form->like($form->{invnumber}));
|
|
431 | 430 |
} |
432 | 431 |
if ($form->{ordnumber}) { |
433 |
my $ordnumber = $form->like(lc $form->{ordnumber});
|
|
434 |
$where .= " AND lower(a.ordnumber) LIKE '$ordnumber'";
|
|
432 |
$where .= " AND a.ordnumber ILIKE ?";
|
|
433 |
push(@values, $form->like($form->{ordnumber}));
|
|
435 | 434 |
} |
436 | 435 |
if ($form->{notes}) { |
437 |
my $notes = $form->like(lc $form->{notes});
|
|
438 |
$where .= " AND lower(a.notes) LIKE '$notes'";
|
|
436 |
$where .= " AND lower(a.notes) LIKE ?";
|
|
437 |
push(@values, $form->like($form->{notes}));
|
|
439 | 438 |
} |
440 | 439 |
|
441 |
$where .= " AND a.transdate >= '$form->{transdatefrom}'" |
|
442 |
if $form->{transdatefrom}; |
|
443 |
$where .= " AND a.transdate <= '$form->{transdateto}'" |
|
444 |
if $form->{transdateto}; |
|
440 |
if ($form->{transdatefrom}) { |
|
441 |
$where .= " AND a.transdate >= ?"; |
|
442 |
push(@values, $form->{transdatefrom}); |
|
443 |
} |
|
444 |
if ($form->{transdateto}) { |
|
445 |
$where .= " AND a.transdate <= ?"; |
|
446 |
push(@values, $form->{transdateto}); |
|
447 |
} |
|
445 | 448 |
if ($form->{open} || $form->{closed}) { |
446 | 449 |
unless ($form->{open} && $form->{closed}) { |
447 | 450 |
$where .= " AND a.amount <> a.paid" if ($form->{open}); |
... | ... | |
449 | 452 |
} |
450 | 453 |
} |
451 | 454 |
|
455 |
if ($where) { |
|
456 |
substr($where, 0, 4) = "WHERE"; |
|
457 |
$query .= $where; |
|
458 |
} |
|
459 |
|
|
452 | 460 |
my @a = (transdate, invnumber, name); |
453 | 461 |
push @a, "employee" if $self->{l_employee}; |
454 |
my $sortorder = join ', ', $form->sort_columns(@a); |
|
455 |
$sortorder = $form->{sort} if $form->{sort}; |
|
462 |
my $sortorder = join(', ', @a); |
|
463 |
|
|
464 |
if (grep({ $_ eq $form->{sort} } |
|
465 |
qw(transdate id invnumber ordnumber name netamount tax amount |
|
466 |
paid datepaid due duedate notes employee))) { |
|
467 |
$sortorder = $form->{sort}; |
|
468 |
} |
|
456 | 469 |
|
457 |
$query .= "WHERE $where |
|
458 |
ORDER by $sortorder"; |
|
470 |
$query .= " ORDER by $sortorder"; |
|
459 | 471 |
|
460 | 472 |
my $sth = $dbh->prepare($query); |
461 |
$sth->execute || $form->dberror($query); |
|
473 |
$sth->execute(@values) || |
|
474 |
$form->dberror($query . " (" . join(", ", @values) . ")"); |
|
462 | 475 |
|
476 |
$form->{AP} = []; |
|
463 | 477 |
while (my $ap = $sth->fetchrow_hashref(NAME_lc)) { |
464 | 478 |
push @{ $form->{AP} }, $ap; |
465 | 479 |
} |
... | ... | |
512 | 526 |
$form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, |
513 | 527 |
"buy"); |
514 | 528 |
|
529 |
my (@values, $query); |
|
530 |
|
|
515 | 531 |
# record payments and offsetting AP |
516 | 532 |
for my $i (1 .. $form->{paidaccounts}) { |
517 | 533 |
|
... | ... | |
541 | 557 |
2) * -1; |
542 | 558 |
|
543 | 559 |
|
544 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
545 |
WHERE c.accno = '$form->{AP}') AND amount=$amount AND transdate='$form->{"datepaid_$i"}'|; |
|
546 |
$dbh->do($query) || $form->dberror($query); |
|
547 |
|
|
548 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
549 |
transdate) |
|
550 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
551 |
WHERE c.accno = '$form->{AP}'), |
|
552 |
$amount, '$form->{"datepaid_$i"}')|; |
|
553 |
$dbh->do($query) || $form->dberror($query); |
|
554 |
|
|
555 |
|
|
556 |
|
|
557 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
558 |
WHERE c.accno = '$accno') AND amount=$form->{"paid_$i"} AND transdate='$form->{"datepaid_$i"}' AND source='$form->{"source_$i"}' AND memo='$form->{"memo_$i"}'|; |
|
559 |
$dbh->do($query) || $form->dberror($query); |
|
560 |
|
|
561 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
562 |
source, memo) |
|
563 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
564 |
WHERE c.accno = '$accno'), |
|
565 |
$form->{"paid_$i"}, '$form->{"datepaid_$i"}', |
|
566 |
'$form->{"source_$i"}', '$form->{"memo_$i"}')|; |
|
567 |
$dbh->do($query) || $form->dberror($query); |
|
568 |
|
|
560 |
$query = |
|
561 |
qq|DELETE FROM acc_trans | . |
|
562 |
qq|WHERE trans_id = ? | . |
|
563 |
qq| AND chart_id = (SELECT c.id FROM chart c WHERE c.accno = ?) | . |
|
564 |
qq| AND amount = ? AND transdate = ?|; |
|
565 |
@values = ($form->{id}, $form->{AP}, $amount, |
|
566 |
conv_date($form->{"datepaid_$i"})); |
|
567 |
do_query($form, $dbh, $query, @values); |
|
568 |
|
|
569 |
$query = |
|
570 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate) | . |
|
571 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?)|; |
|
572 |
@values = ($form->{id}, $form->{AP}, $amount, |
|
573 |
conv_date($form->{"datepaid_$i"})); |
|
574 |
do_query($form, $dbh, $query, @values); |
|
575 |
|
|
576 |
$query = |
|
577 |
qq|DELETE FROM acc_trans | . |
|
578 |
qq|WHERE trans_id = ? | . |
|
579 |
qq| AND chart_id = (SELECT c.id FROM chart c WHERE c.accno = ?) | . |
|
580 |
qq| AND amount = ? AND transdate = ? AND source = ? AND memo = ?|; |
|
581 |
@values = ($form->{id}, $accno, $form->{"paid_$i"}, |
|
582 |
conv_date($form->{"datepaid_$i"}), $form->{"source_$i"}, |
|
583 |
$form->{"memo_$i"}); |
|
584 |
do_query($form, $dbh, $query, @values); |
|
585 |
|
|
586 |
$query = |
|
587 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo) | . |
|
588 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?)|; |
|
589 |
@values = ($form->{id}, $accno, $form->{"paid_$i"}, |
|
590 |
$form->{"datepaid_$i"}, |
|
591 |
$form->{"source_$i"}, $form->{"memo_$i"}); |
|
592 |
do_query($form, $dbh, $query, @values); |
|
569 | 593 |
|
570 | 594 |
# gain/loss |
571 | 595 |
$amount = |
... | ... | |
598 | 622 |
$form->round_amount($form->{fx}{$accno}{$transdate}, 2) |
599 | 623 |
) != 0 |
600 | 624 |
) { |
601 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
602 |
WHERE c.accno = '$accno') AND amount=$form->{fx}{$accno}{$transdate} AND transdate='$transdate' AND cleared='0' AND fx_transaction='1'|; |
|
603 |
$dbh->do($query) || $form->dberror($query); |
|
604 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
605 |
transdate, cleared, fx_transaction) |
|
606 |
VALUES ($form->{id}, |
|
607 |
(SELECT c.id FROM chart c |
|
608 |
WHERE c.accno = '$accno'), |
|
609 |
$form->{fx}{$accno}{$transdate}, '$transdate', '0', '1')|; |
|
610 |
$dbh->do($query) || $form->dberror($query); |
|
625 |
$query = |
|
626 |
qq|DELETE FROM acc_trans | . |
|
627 |
qq|WHERE trans_id = ? AND chart_id = | . |
|
628 |
qq| (SELECT c.id FROM chart c WHERE c.accno = ?) AND amount = ? | . |
|
629 |
qq| AND transdate = ? AND cleared = 'f' AND fx_transaction = 't'|; |
|
630 |
@values = ($form->{id}, $accno, $form->{fx}{$accno}{$transdate}, |
|
631 |
conv_date($transdate),); |
|
632 |
do_query($form, $dbh, $query, @values); |
|
633 |
|
|
634 |
$query = |
|
635 |
qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction) | . |
|
636 |
qq|VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, 'f', 't')|; |
|
637 |
@values = ($form->{id}, $accno, $form->{fx}{$accno}{$transdate}, |
|
638 |
conv_date($transdate)); |
|
639 |
do_query($form, $dbh, $query, @values); |
|
611 | 640 |
} |
612 | 641 |
} |
613 | 642 |
} |
614 |
my $datepaid = ($form->{paid}) ? qq|'$form->{datepaid}'| : "NULL"; |
|
615 | 643 |
|
616 | 644 |
# save AP record |
617 |
my $query = qq|UPDATE ap set |
|
618 |
paid = $form->{paid}, |
|
619 |
datepaid = $datepaid |
|
620 |
WHERE id=$form->{id}|; |
|
621 |
|
|
622 |
$dbh->do($query) || $form->dberror($query); |
|
645 |
my $query = qq|UPDATE ap SET paid = ?, datepaid = ? WHERE id = ?|; |
|
646 |
@values = ($form->{paid}, $form->{paid} ? $form->{datepaid} : undef, |
|
647 |
$form->{id}); |
|
648 |
do_query($form, $dbh, $query, @values); |
|
623 | 649 |
|
624 | 650 |
my $rc = $dbh->commit; |
625 | 651 |
$dbh->disconnect; |
Auch abrufbar als: Unified diff
Verhinderung von SQL injection durch Verwendung von parametrisierten Abfragen.