Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 543d7822

Von G. Richardson vor mehr als 5 Jahren hinzugefügt

  • ID 543d78225ec609e9f67ecb1544e135ca88149234
  • Vorgänger c3500451
  • Nachfolger cdd986ac

Spalte taxnumber aus Tabelle tax entfernt

tax.taxnumber war ein redundanter Eintrag, und entsprach dem Wert von
chart.accno aus tax.chart_id.

Z.B. in SKR04 hatte Steuerschlüssel 3 (Umsatzsteuer 19%) die taxnumber
1776 und die chart_id 775 (chart mit id 775 ist das Konto 1776).

Ein Problem dabei ist, daß wenn man in den Konteneinstellungen die
Kontonummer von 1776 ändert, dies nicht automatisch in tax.taxnumber mit
aktualisiert wurde.

Im Code wurde taxnumber v.A. verwendet, um bei Belegen die Steuern zu
gruppieren, mit der taxnumber als Schlüssel.

taxnumber wurde nun also entfernt, und obwohl zum Gruppieren der Steuern
immer noch diese Kontonummer verwendet wird, wird diese Kontonummer
nicht mehr zum Suchen des entsprechenden Taxeintrags verwendet, sondern
die Suche passiert indirekt über die chart_id.

Das ganze System basiert derzeit darauf, daß es für jeden tax-Eintrag ein
eindeutiges Automatikkonto gibt, in der Praxis muß dies aber nicht der
Fall sein!

Unterschiede anzeigen:

SL/AM.pm
1181 1181
                  taxdescription           = ?,
1182 1182
                  rate                     = ?,
1183 1183
                  chart_id                 = ?,
1184
                  taxnumber                = (SELECT accno FROM chart WHERE id = ? ),
1185 1184
                  skonto_sales_chart_id    = ?,
1186 1185
                  skonto_purchase_chart_id = ?,
1187 1186
                  chart_categories         = ?
......
1195 1194
                  taxdescription,
1196 1195
                  rate,
1197 1196
                  chart_id,
1198
                  taxnumber,
1199 1197
                  skonto_sales_chart_id,
1200 1198
                  skonto_purchase_chart_id,
1201 1199
                  chart_categories,
SL/CA.pm
104 104
      comma(tk.startdate::text) AS startdate,
105 105
      comma(tk.taxkey_id::text) AS taxkey,
106 106
      comma(tx.taxdescription || to_char (tx.rate, '99V99' ) || '%') AS taxdescription,
107
      comma(tx.taxnumber::text) AS taxaccount,
107
      comma(taxchart.accno::text) AS taxaccount,
108 108
      comma(tk.pos_ustva::text) AS tk_ustva,
109 109
      ( SELECT accno
110 110
      FROM chart c2
......
113 113
    FROM chart c
114 114
    LEFT JOIN taxkeys tk ON (c.id = tk.chart_id)
115 115
    LEFT JOIN tax tx ON (tk.tax_id = tx.id)
116
    LEFT JOIN chart taxchart ON (taxchart.id = tx.chart_id)
116 117
    WHERE 1=1
117 118
    $where
118 119
    GROUP BY c.accno, c.id, c.description, c.charttype,
SL/DB/MetaSetup/Tax.pm
19 19
  skonto_sales_chart_id    => { type => 'integer' },
20 20
  taxdescription           => { type => 'text', not_null => 1 },
21 21
  taxkey                   => { type => 'integer', not_null => 1 },
22
  taxnumber                => { type => 'text' },
23 22
);
24 23

  
25 24
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
SL/IC.pm
790 790
SQL
791 791

  
792 792
  my $query_tax = <<SQL;
793
    SELECT c.accno, t.taxdescription AS description, t.rate, t.taxnumber
793
    SELECT c.accno, t.taxdescription AS description, t.rate,
794
           c.accno as taxnumber
794 795
    FROM tax t
795 796
    LEFT JOIN chart c ON c.id = t.chart_id
796 797
    WHERE t.id IN
SL/IR.pm
1071 1071
    # get tax rates and description
1072 1072
    my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
1073 1073
    $query =
1074
      qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber FROM tax t
1074
      qq|SELECT c.accno, t.taxdescription, t.rate,
1075
                c.accno as taxnumber   -- taxnumber is same as accno, but still accessed as taxnumber in code
1076
         FROM tax t
1075 1077
         LEFT JOIN chart c ON (c.id = t.chart_id)
1076 1078
         WHERE t.id in
1077 1079
           (SELECT tk.tax_id FROM taxkeys tk
......
1339 1341
    # get tax rates and description
1340 1342
    my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
1341 1343
    $query =
1342
      qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber
1344
      qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber
1343 1345
         FROM tax t
1344 1346
         LEFT JOIN chart c on (c.id = t.chart_id)
1345 1347
         WHERE t.id IN
SL/IS.pm
506 506
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate_nofmt} },  $form->{"${item}_rate"} * 100);
507 507
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxnumber} },      $form->{"${item}_taxnumber"});
508 508

  
509
    my $tax_obj     = SL::DB::Manager::Tax->find_by(taxnumber => $form->{"${item}_taxnumber"});
509
    # taxnumber is used for grouping the amount of the various taxes
510

  
511
    # this code assumes that at most one tax entry can point to the same
512
    # chart_id, even though chart_id does not have a unique constraint!
513

  
514
    # this chart_id is then looked up via its accno, which is the key that is
515
    # used to group the different taxes by for a record
516

  
517
    # not every tax has a taxnumber (e.g. tax-free), but that is ok, because
518
    # then there would be no tax amount to assign it to
519

  
520
    my $tax_objs = SL::DB::Manager::Tax->get_objects_from_sql(
521
      sql  => 'SELECT * FROM tax WHERE chart_id = (SELECT id FROM chart WHERE accno = ?)',
522
      args => [ $form->{"${item}_taxnumber"} ]
523
    );
524
    my $tax_obj;
525
    if ( $tax_objs ) {
526
      $tax_obj     = $tax_objs->[0];
527
    }
510 528
    my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription',  $form->{language_id}, 0) : '';
511 529
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%});
512 530
  }
......
2069 2087
      # get tax rates and description
2070 2088
      my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
2071 2089
      $query =
2072
        qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber FROM tax t
2090
        qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber
2091
           FROM tax t
2073 2092
           LEFT JOIN chart c ON (c.id = t.chart_id)
2074 2093
           WHERE t.id IN
2075 2094
             (SELECT tk.tax_id FROM taxkeys tk
......
2393 2412
    # get tax rates and description
2394 2413
    my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
2395 2414
    $query =
2396
      qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber
2415
      qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber
2397 2416
         FROM tax t
2398 2417
         LEFT JOIN chart c ON (c.id = t.chart_id)
2399 2418
         WHERE t.id in
SL/OE.pm
1177 1177
      # get tax rates and description
1178 1178
      my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
1179 1179
      $query =
1180
        qq|SELECT c.accno, t.taxdescription, t.rate, t.taxnumber | .
1181
        qq|FROM tax t LEFT JOIN chart c on (c.id = t.chart_id) | .
1180
        qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber | .
1181
        qq|FROM tax t | .
1182
        qq|LEFT JOIN chart c on (c.id = t.chart_id) | .
1182 1183
        qq|WHERE t.id IN (SELECT tk.tax_id FROM taxkeys tk | .
1183 1184
        qq|               WHERE tk.chart_id = (SELECT id FROM chart WHERE accno = ?) | .
1184 1185
        qq|                 AND startdate <= $transdate ORDER BY startdate DESC LIMIT 1) | .
......
1574 1575
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate_nofmt} },  $form->{"${item}_rate"} * 100);
1575 1576
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxnumber} },      $form->{"${item}_taxnumber"});
1576 1577

  
1577
    my $tax_obj     = SL::DB::Manager::Tax->find_by(taxnumber => $form->{"${item}_taxnumber"});
1578
    my $tax_objs     = SL::DB::Manager::Tax->get_objects_from_sql(
1579
      sql  => 'SELECT * from tax where chart_id = (SELECT id FROM chart WHERE accno = ?)',
1580
      args => [ $form->{"${item}_taxnumber"} ]
1581
    );
1582
    my $tax_obj;
1583
    if ( $tax_objs ) {
1584
      $tax_obj     = $tax_objs->[0];
1585
    }
1578 1586
    my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription',  $form->{language_id}, 0) : '';
1579 1587
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%});
1580 1588
  }
SL/Taxkeys.pm
60 60

  
61 61
  if (!$self->{handles}->{get_tax_info}) {
62 62
    $self->{queries}->{get_tax_info} = qq|
63
      SELECT t.rate AS taxrate, t.taxnumber, t.taxdescription, t.chart_id AS taxchart_id,
63
      SELECT t.rate AS taxrate, c.accno as taxnumber, t.taxdescription, t.chart_id AS taxchart_id,
64 64
        c.accno AS taxaccno, c.description AS taxaccount
65 65
      FROM taxkeys tk
66 66
      LEFT JOIN tax t   ON (tk.tax_id  = t.id)

Auch abrufbar als: Unified diff