Revision 1ef9fe2f
Von Udo Spallek vor etwa 19 Jahren hinzugefügt
SL/GL.pm | ||
---|---|---|
298 | 298 |
($form->{ml}) = $sth->fetchrow_array; |
299 | 299 |
$sth->finish; |
300 | 300 |
|
301 |
if ($form->{datefrom}) { |
|
301 |
#if ($form->{datefrom}) {
|
|
302 | 302 |
$query = qq|SELECT SUM(ac.amount) |
303 | 303 |
FROM acc_trans ac, chart c |
304 | 304 |
WHERE ac.chart_id = c.id |
305 |
AND c.accno = '$form->{accno}' |
|
306 |
AND ac.transdate < date '$form->{datefrom}' |
|
307 |
|; |
|
305 |
AND c.accno = '$form->{accno}'|; |
|
306 |
$query .= qq|AND ac.transdate > date '$form->{datefrom}' |
|
307 |
| if ($form->{datefrom});; |
|
308 |
$query .= qq|AND ac.transdate < date '$form->{dateto}' |
|
309 |
| if ($form->{dateto}); |
|
310 |
|
|
308 | 311 |
$sth = $dbh->prepare($query); |
309 | 312 |
$sth->execute || $form->dberror($query); |
310 | 313 |
|
311 | 314 |
($form->{balance}) = $sth->fetchrow_array; |
312 | 315 |
$sth->finish; |
313 |
} |
|
316 |
#}
|
|
314 | 317 |
} |
315 | 318 |
|
316 | 319 |
if ($form->{gifi_accno}) { |
... | ... | |
345 | 348 |
my $query = |
346 | 349 |
qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, t.taxkey AS sorttax, |
347 | 350 |
g.description, ac.transdate, ac.source, ac.trans_id, |
348 |
ac.amount, c.accno, c.gifi_accno, g.notes, t.chart_id, ac.oid |
|
351 |
ac.amount*100 AS amount, c.accno, c.gifi_accno, g.notes, t.chart_id, ac.oid
|
|
349 | 352 |
FROM gl g, acc_trans ac, chart c LEFT JOIN tax t ON |
350 | 353 |
(t.chart_id=c.id) |
351 | 354 |
WHERE $glwhere |
... | ... | |
354 | 357 |
UNION |
355 | 358 |
SELECT a.id, 'ar' AS type, a.invoice, a.invnumber, ac.taxkey, t.taxkey AS sorttax, |
356 | 359 |
ct.name, ac.transdate, ac.source, ac.trans_id, |
357 |
ac.amount, c.accno, c.gifi_accno, a.notes, t.chart_id, ac.oid |
|
360 |
ac.amount*100 AS amount, c.accno, c.gifi_accno, a.notes, t.chart_id, ac.oid
|
|
358 | 361 |
FROM ar a, acc_trans ac, customer ct, chart c LEFT JOIN tax t ON |
359 | 362 |
(t.chart_id=c.id) |
360 | 363 |
WHERE $arwhere |
... | ... | |
364 | 367 |
UNION |
365 | 368 |
SELECT a.id, 'ap' AS type, a.invoice, a.invnumber, ac.taxkey, t.taxkey AS sorttax, |
366 | 369 |
ct.name, ac.transdate, ac.source, ac.trans_id, |
367 |
ac.amount, c.accno, c.gifi_accno, a.notes, t.chart_id, ac.oid |
|
370 |
ac.amount*100 AS amount, c.accno, c.gifi_accno, a.notes, t.chart_id, ac.oid
|
|
368 | 371 |
FROM ap a, acc_trans ac, vendor ct, chart c LEFT JOIN tax t ON |
369 | 372 |
(t.chart_id=c.id) |
370 | 373 |
WHERE $apwhere |
... | ... | |
401 | 404 |
} |
402 | 405 |
} |
403 | 406 |
$balance = $ref->{amount}; |
407 |
$ref->{amount} = $ref->{amount} * 1.0; |
|
404 | 408 |
$i = 0; |
405 | 409 |
$j = 0; |
406 | 410 |
$k = 0; |
407 | 411 |
$l = 0; |
408 | 412 |
if ($ref->{amount} < 0) { |
409 | 413 |
if ($ref->{chart_id} > 0) { |
410 |
$ref->{debit_tax}{$i} = $ref->{amount} * -1;
|
|
414 |
$ref->{debit_tax}{$i} = ($ref->{amount} / 100.0) * -1;
|
|
411 | 415 |
$ref->{debit_tax_accno}{$i} = $ref->{accno}; |
412 | 416 |
} else { |
413 |
$ref->{debit}{$k} = $ref->{amount} * -1;
|
|
417 |
$ref->{debit}{$k} = ($ref->{amount} / 100.0) * -1;
|
|
414 | 418 |
$ref->{debit_accno}{$k} = $ref->{accno}; |
415 | 419 |
$ref->{debit_taxkey}{$k} = $ref->{taxkey}; |
416 | 420 |
} |
417 | 421 |
} else { |
418 | 422 |
if ($ref->{chart_id} > 0) { |
419 |
$ref->{credit_tax}{$j} = $ref->{amount}; |
|
423 |
$ref->{credit_tax}{$j} = $ref->{amount} / 100.0;
|
|
420 | 424 |
$ref->{credit_tax_accno}{$j} = $ref->{accno}; |
421 | 425 |
} else { |
422 |
$ref->{credit}{$l} = $ref->{amount}; |
|
426 |
$ref->{credit}{$l} = $ref->{amount} / 100.0;
|
|
423 | 427 |
$ref->{credit_accno}{$l} = $ref->{accno}; |
424 | 428 |
$ref->{credit_taxkey}{$l} = $ref->{taxkey}; |
425 | 429 |
} |
426 | 430 |
} |
427 |
|
|
428 |
while (abs($balance) >= 0.015) { |
|
429 |
my $ref2 = $sth->fetchrow_hashref(NAME_lc) |
|
430 |
|| $form->error("Unbalanced ledger!"); |
|
431 |
|
|
432 |
$balance = |
|
433 |
(int($balance * 100000) + int(100000 * $ref2->{amount})) / 100000; |
|
434 |
print(STDERR $balance, " BAlance\n"); |
|
435 |
if ($ref2->{amount} < 0) { |
|
436 |
if ($ref2->{chart_id} > 0) { |
|
437 |
if ($ref->{debit_tax_accno}{$i} ne "") { |
|
438 |
$i++; |
|
439 |
} |
|
440 |
$ref->{debit_tax}{$i} = $ref2->{amount} * -1; |
|
441 |
$ref->{debit_tax_accno}{$i} = $ref2->{accno}; |
|
442 |
} else { |
|
443 |
if ($ref->{debit_accno}{$k} ne "") { |
|
444 |
$k++; |
|
445 |
} |
|
446 |
$ref->{debit}{$k} = $ref2->{amount} * -1; |
|
447 |
$ref->{debit_accno}{$k} = $ref2->{accno}; |
|
448 |
$ref->{debit_taxkey}{$k} = $ref2->{taxkey}; |
|
449 |
} |
|
450 |
} else { |
|
451 |
if ($ref2->{chart_id} > 0) { |
|
452 |
if ($ref->{credit_tax_accno}{$j} ne "") { |
|
453 |
$j++; |
|
454 |
} |
|
455 |
$ref->{credit_tax}{$j} = $ref2->{amount}; |
|
456 |
$ref->{credit_tax_accno}{$j} = $ref2->{accno}; |
|
457 |
} else { |
|
458 |
if ($ref->{credit_accno}{$l} ne "") { |
|
459 |
$l++; |
|
460 |
} |
|
461 |
$ref->{credit}{$l} = $ref2->{amount}; |
|
462 |
$ref->{credit_accno}{$l} = $ref2->{accno}; |
|
463 |
$ref->{credit_taxkey}{$l} = $ref2->{taxkey}; |
|
464 |
} |
|
465 |
} |
|
466 |
} |
|
467 |
|
|
431 |
# if ($form->{accno} eq ''){ # flo & udo: if general report, |
|
432 |
# then check balance |
|
433 |
|
|
434 |
# while ($balance != 0) { |
|
435 |
# my $ref2 = $sth->fetchrow_hashref(NAME_lc) |
|
436 |
# || $form->error(sprintf("Unbalanced ledger! trans-id: %i", $ref->{trans_id})); |
|
437 |
# |
|
438 |
# $balance = |
|
439 |
# (int($balance * 100000) + int(100000 * $ref2->{amount})) / 100000; |
|
440 |
# $balance += $ref2->{amount}; |
|
441 |
|
|
442 |
#print(STDERR $balance, " BAlance\n"); |
|
443 |
#print(STDERR $ref2->{amount}, " Ref2->amount\n"); |
|
444 |
# if ($ref2->{amount} < 0) { |
|
445 |
# if ($ref2->{chart_id} > 0) { |
|
446 |
# if ($ref->{debit_tax_accno}{$i} ne "") { |
|
447 |
# $i++; |
|
448 |
# } |
|
449 |
# $ref->{debit_tax}{$i} = ($ref2->{amount} / 100.0) * -1; |
|
450 |
# $ref->{debit_tax_accno}{$i} = $ref2->{accno}; |
|
451 |
# } else { |
|
452 |
# if ($ref->{debit_accno}{$k} ne "") { |
|
453 |
# $k++; |
|
454 |
# } |
|
455 |
# $ref->{debit}{$k} = ($ref2->{amount} / 100.0) * -1; |
|
456 |
# $ref->{debit_accno}{$k} = $ref2->{accno}; |
|
457 |
# $ref->{debit_taxkey}{$k} = $ref2->{taxkey}; |
|
458 |
# } |
|
459 |
# } else { |
|
460 |
# if ($ref2->{chart_id} > 0) { |
|
461 |
# if ($ref->{credit_tax_accno}{$j} ne "") { |
|
462 |
# $j++; |
|
463 |
# } |
|
464 |
# $ref->{credit_tax}{$j} = $ref2->{amount} / 100.0; |
|
465 |
# $ref->{credit_tax_accno}{$j} = $ref2->{accno}; |
|
466 |
# } else { |
|
467 |
# if ($ref->{credit_accno}{$l} ne "") { |
|
468 |
# $l++; |
|
469 |
# } |
|
470 |
# $ref->{credit}{$l} = $ref2->{amount} / 100.0; |
|
471 |
# $ref->{credit_accno}{$l} = $ref2->{accno}; |
|
472 |
# $ref->{credit_taxkey}{$l} = $ref2->{taxkey}; |
|
473 |
# } |
|
474 |
# } |
|
475 |
# } |
|
476 |
# } else { |
|
477 |
# 1; |
|
478 |
# } |
|
468 | 479 |
# print(STDERR Dumper($ref)); |
469 | 480 |
push @{ $form->{GL} }, $ref; |
470 | 481 |
$balance = 0; |
Auch abrufbar als: Unified diff
Unbalanced Ledger Workaround... Betr. Bugzilla ID 124