Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6ff01fdb

Von Moritz Bunkus vor mehr als 15 Jahren hinzugefügt

  • ID 6ff01fdb61880344c2826c86955ef4c1e8f47db4
  • Vorgänger 450a0e2f
  • Nachfolger 8beef6f5

Einführung einer ID-Spalte in acc_trans

Die Benutzung der von PostgreSQL zur Verfügung gestellten
Spalte "oid" hat ihre Tücken. Über diese wird in Lx-Office die
Reihenfolge der Einträge in acc_trans geregelt. Wird aber ein
UPDATE-SQL-Query auf acc_trans ausgeführt, so kann es (anscheinend
je nach Datenbankversion) dazu kommen, dass die Zeile eine neue
oid erhält, wodurch die Reihenfolge nicht mehr stimmt.

Unterschiede anzeigen:

SL/AP.pm
509 509

  
510 510
  my ($self, $form, $dbh) = @_;
511 511

  
512
  my @delete_oids;
512
  my @delete_acc_trans_ids;
513 513

  
514 514
  # Delete old payment entries from acc_trans.
515 515
  my $query =
516
    qq|SELECT oid
516
    qq|SELECT acc_trans_id
517 517
       FROM acc_trans
518 518
       WHERE (trans_id = ?) AND fx_transaction
519 519

  
520 520
       UNION
521 521

  
522
       SELECT at.oid
522
       SELECT at.acc_trans_id
523 523
       FROM acc_trans at
524 524
       LEFT JOIN chart c ON (at.chart_id = c.id)
525 525
       WHERE (trans_id = ?) AND (c.link LIKE '%AP_paid%')|;
526
  push @delete_oids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}), conv_i($form->{id}));
526
  push @delete_acc_trans_ids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}), conv_i($form->{id}));
527 527

  
528 528
  $query =
529
    qq|SELECT at.oid
529
    qq|SELECT at.acc_trans_id
530 530
       FROM acc_trans at
531 531
       LEFT JOIN chart c ON (at.chart_id = c.id)
532 532
       WHERE (trans_id = ?)
533 533
         AND ((c.link = 'AP') OR (c.link LIKE '%:AP') OR (c.link LIKE 'AP:%'))
534
       ORDER BY at.oid
534
       ORDER BY at.acc_trans_id
535 535
       OFFSET 1|;
536
  push @delete_oids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}));
536
  push @delete_acc_trans_ids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}));
537 537

  
538
  if (@delete_oids) {
539
    $query = qq|DELETE FROM acc_trans WHERE oid IN (| . join(", ", @delete_oids) . qq|)|;
538
  if (@delete_acc_trans_ids) {
539
    $query = qq|DELETE FROM acc_trans WHERE acc_trans_id IN (| . join(", ", @delete_acc_trans_ids) . qq|)|;
540 540
    do_query($form, $dbh, $query);
541 541
  }
542 542

  
......
589 589
       LEFT JOIN chart c ON (at.chart_id = c.id)
590 590
       WHERE (trans_id = ?)
591 591
         AND ((c.link = 'AP') OR (c.link LIKE '%:AP') OR (c.link LIKE 'AP:%'))
592
       ORDER BY at.oid
592
       ORDER BY at.acc_trans_id
593 593
       LIMIT 1|;
594 594

  
595 595
  ($form->{APselected}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{id}));
......
760 760
  do_query($form, $dbh, $query, $id);
761 761

  
762 762
  # now copy acc_trans entries
763
  $query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ? ORDER BY a.oid|;
763
  $query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ? ORDER BY a.acc_trans_id|;
764 764
  my $rowref = selectall_hashref_query($form, $dbh, $query, $id); 
765 765

  
766 766
  # kill all entries containing payments, which are the last 2n rows, of which the last has link =~ /paid/
SL/AR.pm
279 279

  
280 280
  my ($self, $form, $dbh) = @_;
281 281

  
282
  my @delete_oids;
282
  my @delete_acc_trans_ids;
283 283

  
284 284
  # Delete old payment entries from acc_trans.
285 285
  my $query =
286
    qq|SELECT oid
286
    qq|SELECT acc_trans_id
287 287
       FROM acc_trans
288 288
       WHERE (trans_id = ?) AND fx_transaction
289 289

  
290 290
       UNION
291 291

  
292
       SELECT at.oid
292
       SELECT at.acc_trans_id
293 293
       FROM acc_trans at
294 294
       LEFT JOIN chart c ON (at.chart_id = c.id)
295 295
       WHERE (trans_id = ?) AND (c.link LIKE '%AR_paid%')|;
296
  push @delete_oids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}), conv_i($form->{id}));
296
  push @delete_acc_trans_ids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}), conv_i($form->{id}));
297 297

  
298 298
  $query =
299
    qq|SELECT at.oid
299
    qq|SELECT at.acc_trans_id
300 300
       FROM acc_trans at
301 301
       LEFT JOIN chart c ON (at.chart_id = c.id)
302 302
       WHERE (trans_id = ?)
303 303
         AND ((c.link = 'AR') OR (c.link LIKE '%:AR') OR (c.link LIKE 'AR:%'))
304
       ORDER BY at.oid
304
       ORDER BY at.acc_trans_id
305 305
       OFFSET 1|;
306
  push @delete_oids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}));
306
  push @delete_acc_trans_ids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}));
307 307

  
308
  if (@delete_oids) {
309
    $query = qq|DELETE FROM acc_trans WHERE oid IN (| . join(", ", @delete_oids) . qq|)|;
308
  if (@delete_acc_trans_ids) {
309
    $query = qq|DELETE FROM acc_trans WHERE acc_trans_id IN (| . join(", ", @delete_acc_trans_ids) . qq|)|;
310 310
    do_query($form, $dbh, $query);
311 311
  }
312 312

  
......
359 359
       LEFT JOIN chart c ON (at.chart_id = c.id)
360 360
       WHERE (trans_id = ?)
361 361
         AND ((c.link = 'AR') OR (c.link LIKE '%:AR') OR (c.link LIKE 'AR:%'))
362
       ORDER BY at.oid
362
       ORDER BY at.acc_trans_id
363 363
       LIMIT 1|;
364 364

  
365 365
  ($form->{ARselected}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{id}));
......
650 650
  do_query($form, $dbh, $query, $id);
651 651

  
652 652
  # now copy acc_trans entries
653
  $query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ? ORDER BY a.oid|;
653
  $query = qq|SELECT a.*, c.link FROM acc_trans a LEFT JOIN chart c ON a.chart_id = c.id WHERE a.trans_id = ? ORDER BY a.acc_trans_id|;
654 654
  my $rowref = selectall_hashref_query($form, $dbh, $query, $id); 
655 655

  
656 656
  # kill all entries containing payments, which are the last 2n rows, of which the last has link =~ /paid/
SL/AccTransCorrections.pm
53 53
  }
54 54

  
55 55
  my $query = qq!
56
    SELECT at.oid, at.*,
56
    SELECT at.*,
57 57
      c.accno, c.description AS chartdescription, c.charttype, c.category AS chartcategory, c.link AS chartlink,
58 58
      COALESCE(gl.reference, COALESCE(ap.invnumber, ar.invnumber)) AS reference,
59 59
      COALESCE(ap.invoice, COALESCE(ar.invoice, FALSE)) AS invoice,
......
74 74
    LEFT JOIN ap      ON (at.trans_id = ap.id)
75 75
    LEFT JOIN ar      ON (at.trans_id = ar.id)
76 76
    $where
77
    ORDER BY at.trans_id, at.oid
77
    ORDER BY at.trans_id, at.acc_trans_id
78 78
!;
79 79

  
80 80
  my @transactions = ();
......
410 410
      }
411 411

  
412 412
      foreach my $entry (@{ $data{$side}->{entries} }) {
413
        $entry->{actual_tax}     = $form->round_amount(abs($entry->{tax_entry} ? $entry->{tax_entry}->{amount} : 0), 2);
414
        $entry->{expected_tax}   = $form->round_amount(abs($entry->{expected_tax}), 2);
415
        $entry->{taxkey_error}   =    ( $entry->{taxkey} && !$entry->{tax_entry})
416
                                   || (!$entry->{taxkey} &&  $entry->{tax_entry})
417
                                   || (abs($entry->{expected_tax} - $entry->{actual_tax}) >= 0.02);
418
        $entry->{tax_entry_oid}  = $entry->{tax_entry}->{oid};
413
        $entry->{actual_tax}              = $form->round_amount(abs($entry->{tax_entry} ? $entry->{tax_entry}->{amount} : 0), 2);
414
        $entry->{expected_tax}            = $form->round_amount(abs($entry->{expected_tax}), 2);
415
        $entry->{taxkey_error}            =    ( $entry->{taxkey} && !$entry->{tax_entry})
416
                                            || (!$entry->{taxkey} &&  $entry->{tax_entry})
417
                                            || (abs($entry->{expected_tax} - $entry->{actual_tax}) >= 0.02);
418
        $entry->{tax_entry_acc_trans_id}  = $entry->{tax_entry}->{acc_trans_id};
419 419
        delete $entry->{tax_entry};
420 420

  
421 421
        $entry->{display_amount}       = $form->round_amount(abs($entry->{amount}) * $storno_mult, 2);
......
438 438

  
439 439
            my $tax_info = $all_taxes{taxkeys}->{$taxkey};
440 440

  
441
            next if ((!$tax_info || (0 == $tax_info->{taxrate} * 1)) && $entry->{tax_entry_oid});
441
            next if ((!$tax_info || (0 == $tax_info->{taxrate} * 1)) && $entry->{tax_entry_acc_trans_id});
442 442

  
443 443
            push @{ $entry->{correct_taxkeys} }, {
444 444
              'taxkey'      => $taxkey,
......
552 552
#             $solution->{rows}->[$i]->{taxdescription} .= ' ' . $form->format_amount(\%myconfig, $tax_entry->{taxrate} * 100) . ' %';
553 553

  
554 554
#             push @{ $solution->{changes} }, {
555
#               'oid'    => $entry->{oid},
555
#               'acc_trans_id'    => $entry->{acc_trans_id},
556 556
#               'taxkey' => $solution->{taxkeys}->[$i],
557 557
#             };
558 558
#           }
......
641 641
  my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
642 642

  
643 643
  my $query    = qq|SELECT 'ap' AS module,
644
                      at.oid, at.trans_id, at.chart_id, at.amount, at.taxkey, at.transdate,
644
                      at.acc_trans_id, at.trans_id, at.chart_id, at.amount, at.taxkey, at.transdate,
645 645
                      c.link
646 646
                    FROM acc_trans at
647 647
                    LEFT JOIN chart c ON (at.chart_id = c.id)
......
651 651
                    UNION
652 652

  
653 653
                    SELECT 'ar' AS module,
654
                      at.oid, at.trans_id, at.chart_id, at.amount, at.taxkey, at.transdate,
654
                      at.acc_trans_id, at.trans_id, at.chart_id, at.amount, at.taxkey, at.transdate,
655 655
                      c.link
656 656
                    FROM acc_trans at
657 657
                    LEFT JOIN chart c ON (at.chart_id = c.id)
658 658
                    WHERE (trans_id IN (SELECT id FROM ar WHERE NOT invoice))
659 659
                      AND (taxkey IN (8, 9, 18, 19))
660 660

  
661
                    ORDER BY trans_id, oid|;
661
                    ORDER BY trans_id, acc_trans_id|;
662 662

  
663 663
  my $sth      = prepare_execute_query($form, $dbh, $query);
664 664
  my @transactions;
......
706 706

  
707 707
      my %all_taxes = $self->{taxkeys}->get_full_tax_info('transdate' => $non_tax->{transdate});
708 708

  
709
      push @corrections, ({ 'oid'      => $non_tax->{oid},
710
                            'taxkey'   => $taxkey_replacements{$non_tax->{taxkey}},
709
      push @corrections, ({ 'acc_trans_id' => $non_tax->{acc_trans_id},
710
                            'taxkey'       => $taxkey_replacements{$non_tax->{taxkey}},
711 711
                          },
712 712
                          {
713
                            'oid'      => $tax->{oid},
714
                            'taxkey'   => $taxkey_replacements{$non_tax->{taxkey}},
715
                            'chart_id' => $all_taxes{taxkeys}->{ $taxkey_replacements{$non_tax->{taxkey}} }->{taxchart_id},
713
                            'acc_trans_id' => $tax->{acc_trans_id},
714
                            'taxkey'       => $taxkey_replacements{$non_tax->{taxkey}},
715
                            'chart_id'     => $all_taxes{taxkeys}->{ $taxkey_replacements{$non_tax->{taxkey}} }->{taxchart_id},
716 716
                          });
717 717
    }
718 718
  }
719 719

  
720 720
  if (scalar @corrections) {
721
    my $q_taxkey_only     = qq|UPDATE acc_trans SET taxkey = ? WHERE oid = ?|;
721
    my $q_taxkey_only     = qq|UPDATE acc_trans SET taxkey = ? WHERE acc_trans_id = ?|;
722 722
    my $h_taxkey_only     = prepare_query($form, $dbh, $q_taxkey_only);
723 723

  
724
    my $q_taxkey_chart_id = qq|UPDATE acc_trans SET taxkey = ?, chart_id = ? WHERE oid = ?|;
724
    my $q_taxkey_chart_id = qq|UPDATE acc_trans SET taxkey = ?, chart_id = ? WHERE acc_trans_id = ?|;
725 725
    my $h_taxkey_chart_id = prepare_query($form, $dbh, $q_taxkey_chart_id);
726 726

  
727 727
    foreach my $entry (@corrections) {
728 728
      if ($entry->{chart_id}) {
729
        do_statement($form, $h_taxkey_chart_id, $q_taxkey_chart_id, $entry->{taxkey}, $entry->{chart_id}, $entry->{oid});
729
        do_statement($form, $h_taxkey_chart_id, $q_taxkey_chart_id, $entry->{taxkey}, $entry->{chart_id}, $entry->{acc_trans_id});
730 730
      } else {
731
        do_statement($form, $h_taxkey_only, $q_taxkey_only, $entry->{taxkey}, $entry->{oid});
731
        do_statement($form, $h_taxkey_only, $q_taxkey_only, $entry->{taxkey}, $entry->{acc_trans_id});
732 732
      }
733 733
    }
734 734

  
......
752 752

  
753 753
  my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
754 754

  
755
  my $query    = qq|SELECT at.oid, at.*, c.link
755
  my $query    = qq|SELECT at.*, c.link
756 756
                    FROM acc_trans at
757 757
                    LEFT JOIN ar      ON (at.trans_id = ar.id)
758 758
                    LEFT JOIN chart c ON (at.chart_id = c.id)
......
760 760

  
761 761
                    UNION
762 762

  
763
                    SELECT at.oid, at.*, c.link
763
                    SELECT at.*, c.link
764 764
                    FROM acc_trans at
765 765
                    LEFT JOIN ap      ON (at.trans_id = ap.id)
766 766
                    LEFT JOIN chart c ON (at.chart_id = c.id)
767 767
                    WHERE (ap.invoice)
768 768

  
769
                    ORDER BY trans_id, oid|;
769
                    ORDER BY trans_id, acc_trans_id|;
770 770

  
771 771
  my $sth      = prepare_execute_query($form, $dbh, $query);
772 772
  my @transactions;
......
792 792

  
793 793
      foreach my $entry (@{ $sub_transaction }) {
794 794
        next if ($entry->{taxkey} == 0);
795
        push @corrections, $entry->{oid};
795
        push @corrections, $entry->{acc_trans_id};
796 796
      }
797 797
    }
798 798
  }
799 799

  
800 800
  if (@corrections) {
801
    $query = qq|UPDATE acc_trans SET taxkey = 0 WHERE oid = ?|;
801
    $query = qq|UPDATE acc_trans SET taxkey = 0 WHERE acc_trans_id = ?|;
802 802
    $sth   = prepare_query($form, $dbh, $query);
803 803

  
804
    foreach my $oid (@corrections) {
805
      do_statement($form, $sth, $query, $oid);
804
    foreach my $acc_trans_id (@corrections) {
805
      do_statement($form, $sth, $query, $acc_trans_id);
806 806
    }
807 807

  
808 808
    $sth->finish();
......
827 827

  
828 828
  my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
829 829

  
830
  my $q_taxkey_only  = qq|UPDATE acc_trans SET taxkey = ? WHERE oid = ?|;
830
  my $q_taxkey_only  = qq|UPDATE acc_trans SET taxkey = ? WHERE acc_trans_id = ?|;
831 831
  my $h_taxkey_only  = prepare_query($form, $dbh, $q_taxkey_only);
832 832

  
833
  my $q_taxkey_chart = qq|UPDATE acc_trans SET taxkey = ?, chart_id = ? WHERE oid = ?|;
833
  my $q_taxkey_chart = qq|UPDATE acc_trans SET taxkey = ?, chart_id = ? WHERE acc_trans_id = ?|;
834 834
  my $h_taxkey_chart = prepare_query($form, $dbh, $q_taxkey_chart);
835 835

  
836
  my $q_transdate    = qq|SELECT transdate FROM acc_trans WHERE oid = ?|;
836
  my $q_transdate    = qq|SELECT transdate FROM acc_trans WHERE acc_trans_id = ?|;
837 837
  my $h_transdate    = prepare_query($form, $dbh, $q_transdate);
838 838

  
839 839
  foreach my $fix (@{ $params{fixes} }) {
840
    next unless ($fix->{oid});
840
    next unless ($fix->{acc_trans_id});
841 841

  
842
    do_statement($form, $h_taxkey_only, $q_taxkey_only, conv_i($fix->{taxkey}), conv_i($fix->{oid}));
842
    do_statement($form, $h_taxkey_only, $q_taxkey_only, conv_i($fix->{taxkey}), conv_i($fix->{acc_trans_id}));
843 843

  
844
    next unless ($fix->{tax_entry_oid});
844
    next unless ($fix->{tax_entry_acc_trans_id});
845 845

  
846
    do_statement($form, $h_transdate, $q_transdate, conv_i($fix->{tax_entry_oid}));
846
    do_statement($form, $h_transdate, $q_transdate, conv_i($fix->{tax_entry_acc_trans_id}));
847 847
    my ($transdate) = $h_transdate->fetchrow_array();
848 848

  
849 849
    my %all_taxes = $self->{taxkeys}->get_full_tax_info('transdate' => $transdate);
......
851 851

  
852 852
    next unless ($tax_info);
853 853

  
854
    do_statement($form, $h_taxkey_chart, $q_taxkey_chart, conv_i($fix->{taxkey}), conv_i($tax_info->{taxchart_id}), conv_i($fix->{tax_entry_oid}));
854
    do_statement($form, $h_taxkey_chart, $q_taxkey_chart, conv_i($fix->{taxkey}), conv_i($tax_info->{taxchart_id}), conv_i($fix->{tax_entry_acc_trans_id}));
855 855
  }
856 856

  
857 857
  $h_taxkey_only->finish();
SL/DATEV.pm
332 332
  my %all_taxchart_ids = selectall_as_map($form, $dbh, qq|SELECT DISTINCT chart_id, TRUE AS is_set FROM tax|, 'chart_id', 'is_set');
333 333

  
334 334
  my $query    =
335
    qq|SELECT ac.oid, ac.transdate, ac.trans_id,ar.id, ac.amount, ac.taxkey,
335
    qq|SELECT ac.acc_trans_id, ac.transdate, ac.trans_id,ar.id, ac.amount, ac.taxkey,
336 336
         ar.invnumber, ar.duedate, ar.amount as umsatz,
337 337
         ct.name,
338 338
         c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, c.link,
......
347 347

  
348 348
       UNION ALL
349 349

  
350
       SELECT ac.oid, ac.transdate, ac.trans_id,ap.id, ac.amount, ac.taxkey,
350
       SELECT ac.acc_trans_id, ac.transdate, ac.trans_id,ap.id, ac.amount, ac.taxkey,
351 351
         ap.invnumber, ap.duedate, ap.amount as umsatz,
352 352
         ct.name,
353 353
         c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, c.link,
......
362 362

  
363 363
       UNION ALL
364 364

  
365
       SELECT ac.oid, ac.transdate, ac.trans_id,gl.id, ac.amount, ac.taxkey,
365
       SELECT ac.acc_trans_id, ac.transdate, ac.trans_id,gl.id, ac.amount, ac.taxkey,
366 366
         gl.reference AS invnumber, gl.transdate AS duedate, ac.amount as umsatz,
367 367
         gl.description AS name,
368 368
         c.accno, c.taxkey_id as charttax, c.datevautomatik, c.id, c.link,
......
374 374
         AND $fromto
375 375
         $filter
376 376

  
377
       ORDER BY trans_id, oid|;
377
       ORDER BY trans_id, acc_trans_id|;
378 378

  
379 379
  my $sth = prepare_execute_query($form, $dbh, $query);
380 380

  
SL/DN.pm
838 838
  $ref = selectfirst_hashref_query($form, $dbh, $query, $form->{login});
839 839
  map { $form->{"employee_${_}"} = $ref->{$_} } keys %{ $ref };
840 840

  
841
  $query = qq|SELECT * FROM acc_trans WHERE trans_id = ? ORDER BY oid ASC|;
841
  $query = qq|SELECT * FROM acc_trans WHERE trans_id = ? ORDER BY acc_trans_id ASC|;
842 842
  $sth   = prepare_execute_query($form, $dbh, $query, $ar_id);
843 843

  
844 844
  my ($row, $fee, $interest) = (0, 0, 0);
SL/Form.pm
2829 2829
                                      (startdate <= a.transdate) ORDER BY startdate DESC LIMIT 1))
2830 2830
         WHERE a.trans_id = ?
2831 2831
         AND a.fx_transaction = '0'
2832
         ORDER BY a.oid, a.transdate|;
2832
         ORDER BY a.acc_trans_id, a.transdate|;
2833 2833
    $sth = $dbh->prepare($query);
2834 2834
    do_statement($self, $sth, $query, $self->{id});
2835 2835

  
SL/GL.pm
344 344

  
345 345
  my $query =
346 346
    qq|SELECT
347
        ac.oid AS acoid, g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, c.link,
347
        ac.acc_trans_id, g.id, 'gl' AS type, $false AS invoice, g.reference, ac.taxkey, c.link,
348 348
        g.description, ac.transdate, ac.source, ac.trans_id,
349
        ac.amount, c.accno, g.notes, t.chart_id, ac.oid
349
        ac.amount, c.accno, g.notes, t.chart_id,
350
        CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
350 351
        $project_columns
351 352
        $columns_for_sorting{gl}
352 353
      FROM gl g, acc_trans ac $project_join, chart c
......
357 358

  
358 359
      UNION
359 360

  
360
      SELECT ac.oid AS acoid, a.id, 'ar' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
361
      SELECT ac.acc_trans_id, a.id, 'ar' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
361 362
        ct.name, ac.transdate, ac.source, ac.trans_id,
362
        ac.amount, c.accno, a.notes, t.chart_id, ac.oid
363
        ac.amount, c.accno, a.notes, t.chart_id,
364
        CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
363 365
        $project_columns
364 366
        $columns_for_sorting{arap}
365 367
      FROM ar a, acc_trans ac $project_join, customer ct, chart c
......
371 373

  
372 374
      UNION
373 375

  
374
      SELECT ac.oid AS acoid, a.id, 'ap' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
376
      SELECT ac.acc_trans_id, a.id, 'ap' AS type, a.invoice, a.invnumber, ac.taxkey, c.link,
375 377
        ct.name, ac.transdate, ac.source, ac.trans_id,
376
        ac.amount, c.accno, a.notes, t.chart_id, ac.oid
378
        ac.amount, c.accno, a.notes, t.chart_id,
379
        CASE WHEN (COALESCE(e.name, '') = '') THEN e.login ELSE e.name END AS employee
377 380
        $project_columns
378 381
        $columns_for_sorting{arap}
379 382
      FROM ap a, acc_trans ac $project_join, vendor ct, chart c
......
383 386
        AND (a.vendor_id = ct.id)
384 387
        AND (a.id = ac.trans_id)
385 388

  
386
      ORDER BY $sortorder, acoid $sortdir|;
389
      ORDER BY $sortorder, acc_trans_id $sortdir|;
387 390

  
388 391
  my @values = (@glvalues, @arvalues, @apvalues);
389 392

  
......
635 638
              ORDER BY startdate DESC LIMIT 1))
636 639
         WHERE (a.trans_id = ?)
637 640
           AND (a.fx_transaction = '0')
638
         ORDER BY a.oid, a.transdate|;
641
         ORDER BY a.acc_trans_id, a.transdate|;
639 642
    $form->{GL} = selectall_hashref_query($form, $dbh, $query, conv_i($form->{id}));
640 643

  
641 644
  } else {
SL/IR.pm
1187 1187

  
1188 1188
  my ($self, $form, $dbh) = @_;
1189 1189

  
1190
  my @delete_oids;
1190
  my @delete_acc_trans_ids;
1191 1191

  
1192 1192
  # Delete old payment entries from acc_trans.
1193 1193
  my $query =
1194
    qq|SELECT oid
1194
    qq|SELECT acc_trans_id
1195 1195
       FROM acc_trans
1196 1196
       WHERE (trans_id = ?) AND fx_transaction
1197 1197

  
1198 1198
       UNION
1199 1199

  
1200
       SELECT at.oid
1200
       SELECT at.acc_trans_id
1201 1201
       FROM acc_trans at
1202 1202
       LEFT JOIN chart c ON (at.chart_id = c.id)
1203 1203
       WHERE (trans_id = ?) AND (c.link LIKE '%AP_paid%')|;
1204
  push @delete_oids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}), conv_i($form->{id}));
1204
  push @delete_acc_trans_ids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}), conv_i($form->{id}));
1205 1205

  
1206 1206
  $query =
1207
    qq|SELECT at.oid
1207
    qq|SELECT at.acc_trans_id
1208 1208
       FROM acc_trans at
1209 1209
       LEFT JOIN chart c ON (at.chart_id = c.id)
1210 1210
       WHERE (trans_id = ?)
1211 1211
         AND ((c.link = 'AP') OR (c.link LIKE '%:AP') OR (c.link LIKE 'AP:%'))
1212
       ORDER BY at.oid
1212
       ORDER BY at.acc_trans_id
1213 1213
       OFFSET 1|;
1214
  push @delete_oids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}));
1214
  push @delete_acc_trans_ids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}));
1215 1215

  
1216
  if (@delete_oids) {
1217
    $query = qq|DELETE FROM acc_trans WHERE oid IN (| . join(", ", @delete_oids) . qq|)|;
1216
  if (@delete_acc_trans_ids) {
1217
    $query = qq|DELETE FROM acc_trans WHERE acc_trans_id IN (| . join(", ", @delete_acc_trans_ids) . qq|)|;
1218 1218
    do_query($form, $dbh, $query);
1219 1219
  }
1220 1220

  
......
1271 1271
       LEFT JOIN chart c ON (at.chart_id = c.id)
1272 1272
       WHERE (trans_id = ?)
1273 1273
         AND ((c.link = 'AP') OR (c.link LIKE '%:AP') OR (c.link LIKE 'AP:%'))
1274
       ORDER BY at.oid
1274
       ORDER BY at.acc_trans_id
1275 1275
       LIMIT 1|;
1276 1276

  
1277 1277
  ($form->{AP}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{id}));
SL/IS.pm
1063 1063

  
1064 1064
  my ($self, $form, $dbh) = @_;
1065 1065

  
1066
  my @delete_oids;
1066
  my @delete_acc_trans_ids;
1067 1067

  
1068 1068
  # Delete old payment entries from acc_trans.
1069 1069
  my $query =
1070
    qq|SELECT oid
1070
    qq|SELECT acc_trans_id
1071 1071
       FROM acc_trans
1072 1072
       WHERE (trans_id = ?) AND fx_transaction
1073 1073

  
1074 1074
       UNION
1075 1075

  
1076
       SELECT at.oid
1076
       SELECT at.acc_trans_id
1077 1077
       FROM acc_trans at
1078 1078
       LEFT JOIN chart c ON (at.chart_id = c.id)
1079 1079
       WHERE (trans_id = ?) AND (c.link LIKE '%AR_paid%')|;
1080
  push @delete_oids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}), conv_i($form->{id}));
1080
  push @delete_acc_trans_ids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}), conv_i($form->{id}));
1081 1081

  
1082 1082
  $query =
1083
    qq|SELECT at.oid
1083
    qq|SELECT at.acc_trans_id
1084 1084
       FROM acc_trans at
1085 1085
       LEFT JOIN chart c ON (at.chart_id = c.id)
1086 1086
       WHERE (trans_id = ?)
1087 1087
         AND ((c.link = 'AR') OR (c.link LIKE '%:AR') OR (c.link LIKE 'AR:%'))
1088
       ORDER BY at.oid
1088
       ORDER BY at.acc_trans_id
1089 1089
       OFFSET 1|;
1090
  push @delete_oids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}));
1090
  push @delete_acc_trans_ids, selectall_array_query($form, $dbh, $query, conv_i($form->{id}));
1091 1091

  
1092
  if (@delete_oids) {
1093
    $query = qq|DELETE FROM acc_trans WHERE oid IN (| . join(", ", @delete_oids) . qq|)|;
1092
  if (@delete_acc_trans_ids) {
1093
    $query = qq|DELETE FROM acc_trans WHERE acc_trans_id IN (| . join(", ", @delete_acc_trans_ids) . qq|)|;
1094 1094
    do_query($form, $dbh, $query);
1095 1095
  }
1096 1096

  
......
1147 1147
       LEFT JOIN chart c ON (at.chart_id = c.id)
1148 1148
       WHERE (trans_id = ?)
1149 1149
         AND ((c.link = 'AR') OR (c.link LIKE '%:AR') OR (c.link LIKE 'AR:%'))
1150
       ORDER BY at.oid
1150
       ORDER BY at.acc_trans_id
1151 1151
       LIMIT 1|;
1152 1152

  
1153 1153
  ($form->{AR}) = selectfirst_array_query($form, $dbh, $query, conv_i($form->{id}));
SL/RC.pm
91 91
  ($form->{beginningbalance}, $form->{category}) =
92 92
    selectrow_query($form, $dbh, $query, @values);
93 93

  
94
  my %oid = ('Pg'     => 'ac.oid',
94
  my %oid = ('Pg'     => 'ac.acc_trans_id',
95 95
             'Oracle' => 'ac.rowid');
96 96
  @values = ();
97 97
  $query =
......
184 184
  my $dbh = $form->dbconnect($myconfig);
185 185

  
186 186
  my ($query, $i);
187
  my %oid = ('Pg'     => 'oid',
187
  my %oid = ('Pg'     => 'acc_trans_id',
188 188
             'Oracle' => 'rowid');
189 189

  
190 190
  # clear flags
sql/Pg-upgrade2/acc_trans_without_oid.sql
1
-- @tag: acc_trans_without_oid
2
-- @description: Einf?hren einer ID-Spalte in acc_trans
3
-- @depends: release_2_4_3 cb_ob_transaction
4

  
5
CREATE SEQUENCE acc_trans_id_seq;
6

  
7
CREATE TABLE new_acc_trans (
8
    acc_trans_id integer DEFAULT nextval('acc_trans_id_seq'),
9
    trans_id integer,
10
    chart_id integer,
11
    amount numeric(15,5),
12
    transdate date DEFAULT date('now'::text),
13
    gldate date DEFAULT date('now'::text),
14
    source text,
15
    cleared boolean DEFAULT false,
16
    fx_transaction boolean DEFAULT false,
17
    ob_transaction boolean DEFAULT false,
18
    cb_transaction boolean DEFAULT false,
19
    project_id integer,
20
    memo text,
21
    taxkey integer,
22
    itime timestamp without time zone DEFAULT now(),
23
    mtime timestamp without time zone
24
);
25

  
26
INSERT INTO new_acc_trans (acc_trans_id, trans_id, chart_id, amount, transdate, gldate, source, cleared,
27
                           fx_transaction, ob_transaction, cb_transaction, project_id, memo, taxkey, itime, mtime)
28
  SELECT oid, trans_id, chart_id, amount, transdate, gldate, source, cleared,
29
    fx_transaction, ob_transaction, cb_transaction, project_id, memo, taxkey, itime, mtime
30
  FROM acc_trans;
31

  
32
SELECT setval('acc_trans_id_seq', (SELECT COALESCE((SELECT MAX(oid::integer) FROM acc_trans), 0) + 1));
33

  
34
DROP TABLE acc_trans;
35
ALTER TABLE new_acc_trans RENAME TO acc_trans;
36

  
37
CREATE INDEX acc_trans_trans_id_key ON acc_trans USING btree (trans_id);
38
CREATE INDEX acc_trans_chart_id_key ON acc_trans USING btree (chart_id);
39
CREATE INDEX acc_trans_transdate_key ON acc_trans USING btree (transdate);
40
CREATE INDEX acc_trans_source_key ON acc_trans USING btree (lower(source));
41

  
42
ALTER TABLE ONLY acc_trans
43
    ADD CONSTRAINT "$1" FOREIGN KEY (chart_id) REFERENCES chart(id);
44

  
45
CREATE TRIGGER mtime_acc_trans
46
    BEFORE UPDATE ON acc_trans
47
    FOR EACH ROW
48
    EXECUTE PROCEDURE set_mtime();
templates/webpages/acctranscorrections/assistant_for_wrong_taxkeys_de.html
58 58
    </tr>
59 59

  
60 60
    [%- SET curr_row = 0 %]
61
    [%- IF (problem.data.module == 'ar') || ((problem.data.module == 'gl') && (problem.acc_trans.credit.entries.first.oid < problem.acc_trans.debit.entries.first.oid)) %]
61
    [%- IF (problem.data.module == 'ar') || ((problem.data.module == 'gl') && (problem.acc_trans.credit.entries.first.acc_trans_id < problem.acc_trans.debit.entries.first.acc_trans_id)) %]
62 62
     [%- SET order = [ 'credit', 'debit' ] %]
63 63
     [%- SET other_side = 'debit' %]
64 64
    [%- ELSE %]
......
94 94

  
95 95
       <td>
96 96
        [%- IF row.taxkey_error %]
97
         <input type="hidden" name="fixes[+].oid" value="[% HTML.escape(row.oid) %]">
98
         <input type="hidden" name="fixes[].tax_entry_oid" value="[% HTML.escape(row.tax_entry_oid) %]">
97
         <input type="hidden" name="fixes[+].acc_trans_id" value="[% HTML.escape(row.acc_trans_id) %]">
98
         <input type="hidden" name="fixes[].tax_entry_acc_trans_id" value="[% HTML.escape(row.tax_entry_acc_trans_id) %]">
99 99
         <select name="fixes[].taxkey" style="width: 250px" onchange="enable_fix_button_maybe()">
100 100
          <option value="">---bitte ausw?hlen---</option>
101 101
          [%- FOREACH taxkey = row.correct_taxkeys %]
templates/webpages/acctranscorrections/assistant_for_wrong_taxkeys_master.html
71 71
    </tr>
72 72

  
73 73
    [%- SET curr_row = 0 %]
74
    [%- IF (problem.data.module == 'ar') || ((problem.data.module == 'gl') && (problem.acc_trans.credit.entries.first.oid < problem.acc_trans.debit.entries.first.oid)) %]
74
    [%- IF (problem.data.module == 'ar') || ((problem.data.module == 'gl') && (problem.acc_trans.credit.entries.first.acc_trans_id < problem.acc_trans.debit.entries.first.acc_trans_id)) %]
75 75
     [%- SET order = [ 'credit', 'debit' ] %]
76 76
     [%- SET other_side = 'debit' %]
77 77
    [%- ELSE %]
......
107 107

  
108 108
       <td>
109 109
        [%- IF row.taxkey_error %]
110
         <input type="hidden" name="fixes[+].oid" value="[% HTML.escape(row.oid) %]">
111
         <input type="hidden" name="fixes[].tax_entry_oid" value="[% HTML.escape(row.tax_entry_oid) %]">
110
         <input type="hidden" name="fixes[+].acc_trans_id" value="[% HTML.escape(row.acc_trans_id) %]">
111
         <input type="hidden" name="fixes[].tax_entry_acc_trans_id" value="[% HTML.escape(row.tax_entry_acc_trans_id) %]">
112 112
         <select name="fixes[].taxkey" style="width: 250px" onchange="enable_fix_button_maybe()">
113 113
          <option value=""><translate>---please select---</translate></option>
114 114
          [%- FOREACH taxkey = row.correct_taxkeys %]

Auch abrufbar als: Unified diff