Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d5488529

Von Moritz Bunkus vor fast 18 Jahren hinzugefügt

  • ID d5488529f5b1ce09a4e728f21764010b0cd4c379
  • Vorgänger f58a783a
  • Nachfolger 5bfd9281

Recommit von r1014 von udo_spallek: Solved Bug 246: Buchungsjournal stellt Stornobuchungen verwirrend dar. + Kommentare Bitte Testen...

Unterschiede anzeigen:

SL/GL.pm
362 362
  }
363 363

  
364 364
  my $query =
365
    qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, t.taxkey AS sorttax,
365
    qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, c.link,
366 366
                 g.description, ac.transdate, ac.source, ac.trans_id,
367 367
		 ac.amount, c.accno, c.gifi_accno, g.notes, t.chart_id, ac.oid
368 368
                 FROM gl g, acc_trans ac, chart c LEFT JOIN tax t ON
......
371 371
		 AND ac.chart_id = c.id
372 372
		 AND g.id = ac.trans_id
373 373
	UNION
374
	         SELECT a.id, 'ar' AS type, a.invoice, a.invnumber, ac.taxkey, t.taxkey AS sorttax,
374
	         SELECT a.id, 'ar' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
375 375
		 ct.name, ac.transdate, ac.source, ac.trans_id,
376 376
		 ac.amount, c.accno, c.gifi_accno, a.notes, t.chart_id, ac.oid
377 377
		 FROM ar a, acc_trans ac, customer ct, chart c LEFT JOIN tax t ON
......
381 381
		 AND a.customer_id = ct.id
382 382
		 AND a.id = ac.trans_id
383 383
	UNION
384
	         SELECT a.id, 'ap' AS type, a.invoice, a.invnumber, ac.taxkey, t.taxkey AS sorttax,
384
	         SELECT a.id, 'ap' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
385 385
		 ct.name, ac.transdate, ac.source, ac.trans_id,
386 386
		 ac.amount, c.accno, c.gifi_accno, a.notes, t.chart_id, ac.oid
387 387
		 FROM ap a, acc_trans ac, vendor ct, chart c LEFT JOIN tax t ON
......
390 390
		 AND ac.chart_id = c.id
391 391
		 AND a.vendor_id = ct.id
392 392
		 AND a.id = ac.trans_id
393
	         ORDER BY $sortorder transdate, trans_id, taxkey DESC, sorttax DESC,oid|;
393
	         ORDER BY $sortorder transdate, trans_id, taxkey DESC, oid|;
394

  
395
  # Show all $query in Debuglevel LXDebug::QUERY
396
  $callingdetails = (caller (0))[3];
397
  $main::lxdebug->message(LXDebug::QUERY, "$callingdetails \$query=\n $query");
398
      
394 399
  my $sth = $dbh->prepare($query);
395 400
  $sth->execute || $form->dberror($query);
396 401
  my $trans_id  = "";
397 402
  my $trans_id2 = "";
403

  
398 404
  while (my $ref0 = $sth->fetchrow_hashref(NAME_lc)) {
405
    
399 406
    $trans_id = $ref0->{id};
400
    if ($trans_id != $trans_id2) {
407
    
408
    if ($trans_id != $trans_id2) { # first line of a booking
409
    
401 410
      if ($trans_id2) {
402 411
        push @{ $form->{GL} }, $ref;
403 412
        $balance = 0;
404 413
      }
414
    
405 415
      $ref       = $ref0;
406 416
      $trans_id2 = $ref->{id};
407 417

  
......
427 437
          $ref->{module} = "ar";
428 438
        }
429 439
      }
440
    
430 441
      $balance = $ref->{amount};
431
      $i       = 0;
432
      $j       = 0;
433
      $k       = 0;
434
      $l       = 0;
435
      if ($ref->{amount} < 0) {
436
        if ($ref->{chart_id} > 0) {
437
          $ref->{debit_tax}{$i}       = $ref->{amount} * -1;
438
          $ref->{debit_tax_accno}{$i} = $ref->{accno};
442
    
443
      # Linenumbers of General Ledger  
444
      $k       = 0; # Debit      # AP      # Soll
445
      $l       = 0; # Credit     # AR      # Haben
446
      $i       = 0; # Debit Tax  # AP_tax  # VSt
447
      $j       = 0; # Credit Tax # AR_tax  # USt
448
      
449

  
450
      if ($ref->{chart_id} > 0) { # all tax accounts first line, no line increasing
451
        if ($ref->{amount} < 0) {
452
          if ($ref->{link} =~ /AR_tax/) {
453
            $ref->{credit_tax}{$j}       = $ref->{amount};
454
            $ref->{credit_tax_accno}{$j} = $ref->{accno};              
455
          }
456
          if ($ref->{link} =~ /AP_tax/) {
457
            $ref->{debit_tax}{$i}       = $ref->{amount} * -1;
458
            $ref->{debit_tax_accno}{$i} = $ref->{accno};   
459
          }
439 460
        } else {
461
          if ($ref->{link} =~ /AR_tax/) {
462
            $ref->{credit_tax}{$j}       = $ref->{amount};
463
            $ref->{credit_tax_accno}{$j} = $ref->{accno};              
464
          }
465
          if ($ref->{link} =~ /AP_tax/) {
466
            $ref->{debit_tax}{$i}       = $ref->{amount} * -1;
467
            $ref->{debit_tax_accno}{$i} = $ref->{accno};   
468
          }
469
        }
470
      } else { #all other accounts first line
471
        if ($ref->{amount} < 0) {
440 472
          $ref->{debit}{$k}        = $ref->{amount} * -1;
441 473
          $ref->{debit_accno}{$k}  = $ref->{accno};
442 474
          $ref->{debit_taxkey}{$k} = $ref->{taxkey};
443
        }
444
      } else {
445
        if ($ref->{chart_id} > 0) {
446
          $ref->{credit_tax}{$j}       = $ref->{amount};
447
          $ref->{credit_tax_accno}{$j} = $ref->{accno};
475

  
448 476
        } else {
449
          $ref->{credit}{$l}        = $ref->{amount};
477
          $ref->{credit}{$l}        = $ref->{amount} * 1;
450 478
          $ref->{credit_accno}{$l}  = $ref->{accno};
451 479
          $ref->{credit_taxkey}{$l} = $ref->{taxkey};
480

  
481

  
452 482
        }
453 483
      }
454
    } else {
484

  
485
    } else { # following lines of a booking, line increasing
486

  
455 487
      $ref2      = $ref0;
488
      $trans_old  =$trans_id2;
456 489
      $trans_id2 = $ref2->{id};
457

  
458
      #      if ($form->{accno} eq ''){ # flo & udo: if general report,
459
      # then check balance
460
      #         while (abs($balance) >= 0.015) {
461
      #           my $ref2 = $sth->fetchrow_hashref(NAME_lc)
462
      #             || $form->error("Unbalanced ledger!");
463
      #
490
  
464 491
      $balance =
465 492
        (int($balance * 100000) + int(100000 * $ref2->{amount})) / 100000;
466
      if ($ref2->{amount} < 0) {
467
        if ($ref2->{chart_id} > 0) {
468
          if ($ref->{debit_tax_accno}{$i} ne "") {
469
            $i++;
493

  
494

  
495
      if ($ref2->{chart_id} > 0) { # all tax accounts, following lines
496
        if ($ref2->{amount} < 0) {
497
          if ($ref2->{link} =~ /AR_tax/) {
498
            if ($ref->{credit_tax_accno}{$j} ne "") {
499
              $j++;
500
            }
501
            $ref->{credit_tax}{$j}       = $ref2->{amount};
502
            $ref->{credit_tax_accno}{$j} = $ref2->{accno};              
503
          }
504
          if ($ref2->{link} =~ /AP_tax/) {
505
            if ($ref->{debit_tax_accno}{$i} ne "") {
506
              $i++;
507
            }
508
            $ref->{debit_tax}{$i}       = $ref2->{amount} * -1;
509
            $ref->{debit_tax_accno}{$i} = $ref2->{accno};   
470 510
          }
471
          $ref->{debit_tax}{$i}       = $ref2->{amount} * -1;
472
          $ref->{debit_tax_accno}{$i} = $ref2->{accno};
473 511
        } else {
512
          if ($ref2->{link} =~ /AR_tax/) {
513
            if ($ref->{credit_tax_accno}{$j} ne "") {
514
              $j++;
515
            }
516
            $ref->{credit_tax}{$j}       = $ref2->{amount};
517
            $ref->{credit_tax_accno}{$j} = $ref2->{accno};              
518
          }
519
          if ($ref2->{link} =~ /AP_tax/) {
520
            if ($ref->{debit_tax_accno}{$i} ne "") {
521
              $i++;
522
            }
523
            $ref->{debit_tax}{$i}       = $ref2->{amount} * -1;
524
            $ref->{debit_tax_accno}{$i} = $ref2->{accno};   
525
          }
526
        }
527
      } else { # all other accounts, following lines
528
        if ($ref2->{amount} < 0) {
474 529
          if ($ref->{debit_accno}{$k} ne "") {
475 530
            $k++;
476 531
          }
477
          $ref->{debit}{$k}        = $ref2->{amount} * -1;
532
          $ref->{debit}{$k}        = $ref2->{amount} * - 1;
478 533
          $ref->{debit_accno}{$k}  = $ref2->{accno};
479 534
          $ref->{debit_taxkey}{$k} = $ref2->{taxkey};
480
        }
481
      } else {
482
        if ($ref2->{chart_id} > 0) {
483
          if ($ref->{credit_tax_accno}{$j} ne "") {
484
            $j++;
485
          }
486
          $ref->{credit_tax}{$j}       = $ref2->{amount};
487
          $ref->{credit_tax_accno}{$j} = $ref2->{accno};
488 535
        } else {
489 536
          if ($ref->{credit_accno}{$l} ne "") {
490 537
            $l++;
......
494 541
          $ref->{credit_taxkey}{$l} = $ref2->{taxkey};
495 542
        }
496 543
      }
497

  
498
      #         }
499
      #       } else {
500
      #         # if account-report, then calculate the Balance?!
501
      #         # ToDo: Calculate the Balance
502
      #         1;
503
      #       }
504 544
    }
505

  
506 545
  }
507 546
  push @{ $form->{GL} }, $ref;
508 547
  $sth->finish;

Auch abrufbar als: Unified diff