Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1ef9fe2f

Von Udo Spallek vor etwa 19 Jahren hinzugefügt

  • ID 1ef9fe2f5208b9d372cba17d896050f5f3e01bd9
  • Vorgänger 5e3e1260
  • Nachfolger f1e5fd2d

Unbalanced Ledger Workaround... Betr. Bugzilla ID 124

Unterschiede anzeigen:

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;
bin/mozilla/gl.pl
391 391

  
392 392
  $form->{title} = $locale->text('General Ledger');
393 393

  
394
  $ml = ($form->{ml} =~ /(A|E)/) ? -1 : 1;
394
  $ml = ($form->{ml} =~ /(A|E|Q)/) ? -1 : 1;
395 395

  
396 396
  unless ($form->{category} eq 'X') {
397 397
    $form->{title} .= " : " . $locale->text($acctype{ $form->{category} });
......
616 616
        </tr>
617 617
|;
618 618
  }
619

  
619
   $form->{balance} *= $ml;
620 620
  foreach $ref (@{ $form->{GL} }) {
621

  
621
    $form->{balance} *= $ml;
622 622
    # if item ne sort print subtotal
623 623
    if ($form->{l_subtotal} eq 'Y') {
624 624
      if ($sameitem ne $ref->{ $form->{sort} }) {
625 625
        &gl_subtotal;
626 626
      }
627 627
    }
628
    foreach $key (sort keys(%{ $ref->{amount} })) {
629
      $form->{balance} += $ref->{amount}{$key};
630
    }
628
    #foreach $key (sort keys(%{ $ref->{amount} })) {
629
    #  $form->{balance} += $ref->{amount}{$key};
630
    #}
631 631

  
632 632
    $debit = "";
633 633
    foreach $key (sort keys(%{ $ref->{debit} })) {
......
639 639
        $debit .=
640 640
          "<br>" . $form->format_amount(\%myconfig, $ref->{debit}{$key}, 2, 0);
641 641
      }
642
      $form->{balance} = abs($form->{balance}) - abs($ref->{debit}{$key});
642 643
    }
643 644

  
644 645
    $credit = "";
......
651 652
        $credit .= "<br>"
652 653
          . $form->format_amount(\%myconfig, $ref->{credit}{$key}, 2, 0);
653 654
      }
655
      $form->{balance} = abs($form->{balance}) - abs( $ref->{credit}{$key});
654 656
    }
655 657

  
656 658
    $debittax = "";
......
664 666
        $debittax .= "<br>"
665 667
          . $form->format_amount(\%myconfig, $ref->{debit_tax}{$key}, 2, 0);
666 668
      }
669
      $form->{balance} = abs($form->{balance}) - abs($ref->{debit_tax}{$key});
667 670
    }
668 671

  
669 672
    $credittax = "";
......
677 680
        $credittax .= "<br>"
678 681
          . $form->format_amount(\%myconfig, $ref->{credit_tax}{$key}, 2, 0);
679 682
      }
683
      $form->{balance} = abs($form->{balance}) - abs($ref->{credit_tax}{$key});
680 684
    }
681 685

  
682 686
    $debitaccno  = "";
......
769 773
      "<td><a href=$href&gifi_accno=$ref->{gifi_accno}&callback=$callback>$ref->{gifi_accno}</a>&nbsp;</td>";
770 774
    $column_data{balance} =
771 775
        "<td align=right>"
772
      . $form->format_amount(\%myconfig, $form->{balance} * $ml, 2, 0)
776
      . $form->format_amount(\%myconfig, $form->{balance}, 2, 0)
773 777
      . "</td>";
774 778

  
775 779
    $i++;

Auch abrufbar als: Unified diff