Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a07e0f1a

Von Moritz Bunkus vor fast 18 Jahren hinzugefügt

  • ID a07e0f1ae8c1a44b4ad20de602b9bdbb805450f3
  • Vorgänger 1aee716d
  • Nachfolger c722e644

Recommit von r1005 von udo_spallek: Solved Bug 246: Buchungsjournal stellt Stornobuchungen verwirrend dar.

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, t.type AS taxtype,
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, t.type AS taxtype,
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, t.type AS taxtype,
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, taxtype 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 = "";
398 403
  while (my $ref0 = $sth->fetchrow_hashref(NAME_lc)) {
404
    
399 405
    $trans_id = $ref0->{id};
406
    
400 407
    if ($trans_id != $trans_id2) {
408
    
401 409
      if ($trans_id2) {
402 410
        push @{ $form->{GL} }, $ref;
403 411
        $balance = 0;
404 412
      }
413
    
405 414
      $ref       = $ref0;
406 415
      $trans_id2 = $ref->{id};
407 416

  
......
427 436
          $ref->{module} = "ar";
428 437
        }
429 438
      }
439
    
430 440
      $balance = $ref->{amount};
441
    
431 442
      $i       = 0;
432 443
      $j       = 0;
433 444
      $k       = 0;
434 445
      $l       = 0;
446

  
435 447
      if ($ref->{amount} < 0) {
436 448
        if ($ref->{chart_id} > 0) {
437 449
          $ref->{debit_tax}{$i}       = $ref->{amount} * -1;
......
441 453
          $ref->{debit_accno}{$k}  = $ref->{accno};
442 454
          $ref->{debit_taxkey}{$k} = $ref->{taxkey};
443 455
        }
456

  
444 457
      } else {
458

  
445 459
        if ($ref->{chart_id} > 0) {
446 460
          $ref->{credit_tax}{$j}       = $ref->{amount};
447 461
          $ref->{credit_tax_accno}{$j} = $ref->{accno};
......
450 464
          $ref->{credit_accno}{$l}  = $ref->{accno};
451 465
          $ref->{credit_taxkey}{$l} = $ref->{taxkey};
452 466
        }
467

  
453 468
      }
469

  
454 470
    } else {
471

  
455 472
      $ref2      = $ref0;
473
      $trans_old  =$trans_id2;
456 474
      $trans_id2 = $ref2->{id};
457 475

  
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
      #
464 476
      $balance =
465 477
        (int($balance * 100000) + int(100000 * $ref2->{amount})) / 100000;
478

  
466 479
      if ($ref2->{amount} < 0) {
480

  
467 481
        if ($ref2->{chart_id} > 0) {
482

  
468 483
          if ($ref->{debit_tax_accno}{$i} ne "") {
469 484
            $i++;
470 485
          }
471
          $ref->{debit_tax}{$i}       = $ref2->{amount} * -1;
472
          $ref->{debit_tax_accno}{$i} = $ref2->{accno};
486
          if ($ref2->{taxtype} eq 'U') {
487
            $ref->{credit_tax}{$j}       = $ref2->{amount};
488
            $ref->{credit_tax_accno}{$j} = $ref2->{accno};              
489
          }
490
          if ($ref2->{taxtype} eq 'V') {
491
            $ref->{debit_tax}{$j}       = $ref2->{amount} * -1;
492
            $ref->{debit_tax_accno}{$j} = $ref2->{accno};              
493
          }
494

  
473 495
        } else {
496

  
474 497
          if ($ref->{debit_accno}{$k} ne "") {
475 498
            $k++;
476 499
          }
......
478 501
          $ref->{debit_accno}{$k}  = $ref2->{accno};
479 502
          $ref->{debit_taxkey}{$k} = $ref2->{taxkey};
480 503
        }
504

  
481 505
      } else {
506

  
482 507
        if ($ref2->{chart_id} > 0) {
508

  
483 509
          if ($ref->{credit_tax_accno}{$j} ne "") {
484 510
            $j++;
485 511
          }
486
          $ref->{credit_tax}{$j}       = $ref2->{amount};
487
          $ref->{credit_tax_accno}{$j} = $ref2->{accno};
512
          if ($ref2->{taxtype} eq 'U') {
513
            $ref->{credit_tax}{$j}       = $ref2->{amount};
514
            $ref->{credit_tax_accno}{$j} = $ref2->{accno};              
515
          }
516
          if ($ref2->{taxtype} eq 'V') {
517
            $ref->{debit_tax}{$j}       = $ref2->{amount} * -1;
518
            $ref->{debit_tax_accno}{$j} = $ref2->{accno};              
519
          }
520

  
488 521
        } else {
522

  
489 523
          if ($ref->{credit_accno}{$l} ne "") {
490 524
            $l++;
491 525
          }
......
494 528
          $ref->{credit_taxkey}{$l} = $ref2->{taxkey};
495 529
        }
496 530
      }
497

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

  
506 532
  }
507 533
  push @{ $form->{GL} }, $ref;
508 534
  $sth->finish;

Auch abrufbar als: Unified diff