Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4e8e33e9

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

  • ID 4e8e33e9c0a98f10551a4ae18597dc724e621a13
  • Vorgänger a05cda74
  • Nachfolger c4cea463

AR/IR/OE - Steuerbeschreibung an Oberfläche / Druck aus tax_id holen

siehe Kommentare in SL/IS.pm

Wenn ein Steuerautomatikkonto mehrmals bei den Steuern auftaucht kann
man die Steuerbeschreibung nicht mehr eindeutig anhand der Kontonummer
(hier als taxnumber verwendet) bestimmen, von daher wird jetzt immer
auch die tax_id mit ausgelesen.

Hier gibt es noch ganz viel Refactoringpotential...

Unterschiede anzeigen:

SL/IC.pm
806 806
SQL
807 807

  
808 808
  my $query_tax = <<SQL;
809
    SELECT c.accno, t.taxdescription AS description, t.rate,
809
    SELECT c.accno, t.taxdescription AS description, t.id as tax_id, t.rate,
810 810
           c.accno as taxnumber
811 811
    FROM tax t
812 812
    LEFT JOIN chart c ON c.id = t.chart_id
......
838 838
    $form->{"taxaccounts_$index"} = $ref->{"accno"};
839 839
    $form->{"taxaccounts"} .= "$ref->{accno} "if $form->{"taxaccounts"} !~ /$ref->{accno}/;
840 840

  
841
    $form->{"$ref->{accno}_${_}"} = $ref->{$_} for qw(rate description taxnumber);
841
    $form->{"$ref->{accno}_${_}"} = $ref->{$_} for qw(rate description taxnumber tax_id);
842 842
  }
843 843

  
844 844
  $sth_tax->finish;
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,
1074
      qq|SELECT c.accno, t.taxdescription, t.rate, t.id as tax_id,
1075 1075
                c.accno as taxnumber   -- taxnumber is same as accno, but still accessed as taxnumber in code
1076 1076
         FROM tax t
1077 1077
         LEFT JOIN chart c ON (c.id = t.chart_id)
......
1098 1098
        $form->{"$ptr->{accno}_rate"}         = $ptr->{rate};
1099 1099
        $form->{"$ptr->{accno}_description"}  = $ptr->{taxdescription};
1100 1100
        $form->{"$ptr->{accno}_taxnumber"}    = $ptr->{taxnumber};
1101
        $form->{"$ptr->{accno}_tax_id"}       = $ptr->{tax_id};
1101 1102
        $form->{taxaccounts}                 .= "$ptr->{accno} ";
1102 1103
      }
1103 1104

  
......
1341 1342
    # get tax rates and description
1342 1343
    my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
1343 1344
    $query =
1344
      qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber
1345
      qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber, t.id as tax_id
1345 1346
         FROM tax t
1346 1347
         LEFT JOIN chart c on (c.id = t.chart_id)
1347 1348
         WHERE t.id IN
......
1372 1373
        $form->{"$ptr->{accno}_rate"}         = $ptr->{rate};
1373 1374
        $form->{"$ptr->{accno}_description"}  = $ptr->{taxdescription};
1374 1375
        $form->{"$ptr->{accno}_taxnumber"}    = $ptr->{taxnumber};
1376
        $form->{"$ptr->{accno}_tax_id"}       = $ptr->{tax_id};
1375 1377
        $form->{taxaccounts}                 .= "$ptr->{accno} ";
1376 1378
      }
1377 1379

  
SL/IS.pm
171 171
  push @arrays, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs };
172 172
  push @arrays, map { "project_cvar_$_->{name}" } @{ $project_cvar_configs };
173 173

  
174
  my @tax_arrays = qw(taxbase tax taxdescription taxrate taxnumber);
174
  my @tax_arrays = qw(taxbase tax taxdescription taxrate taxnumber tax_id);
175 175

  
176 176
  my @payment_arrays = qw(payment paymentaccount paymentdate paymentsource paymentmemo);
177 177

  
......
505 505
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate} },        $form->format_amount($myconfig, $form->{"${item}_rate"} * 100));
506 506
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate_nofmt} },  $form->{"${item}_rate"} * 100);
507 507
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxnumber} },      $form->{"${item}_taxnumber"});
508
    push(@{ $form->{TEMPLATE_ARRAYS}->{tax_id} },         $form->{"${item}_tax_id"});
508 509

  
509
    # taxnumber is used for grouping the amount of the various taxes
510
    # taxnumber (= accno) is used for grouping the amounts of the various taxes and as a prefix in form
510 511

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

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

  
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
518
    # As we now also store the tax_id we can use that to look up the tax
519
    # instead, this is only done here to get the (translated) taxdescription.
519 520

  
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];
521
    if ( $form->{"${item}_tax_id"} ) {
522
      my $tax_obj = SL::DB::Manager::Tax->find_by(id => $form->{"${item}_tax_id"}) or die "Can't find tax with id " . $form->{"${item}_tax_id"};
523
      my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription',  $form->{language_id}, 0) : '';
524
      push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%});
527 525
    }
528
    my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription',  $form->{language_id}, 0) : '';
529
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%});
526

  
530 527
  }
531 528

  
532 529
  for my $i (1 .. $form->{paidaccounts}) {
......
2087 2084
      # get tax rates and description
2088 2085
      my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
2089 2086
      $query =
2090
        qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber
2087
        qq|SELECT c.accno, t.taxdescription, t.rate, t.id as tax_id, c.accno as taxnumber
2091 2088
           FROM tax t
2092 2089
           LEFT JOIN chart c ON (c.id = t.chart_id)
2093 2090
           WHERE t.id IN
......
2110 2107
        if (!($form->{taxaccounts} =~ /\Q$ptr->{accno}\E/)) {
2111 2108
          $form->{"$ptr->{accno}_rate"}        = $ptr->{rate};
2112 2109
          $form->{"$ptr->{accno}_description"} = $ptr->{taxdescription};
2113
          $form->{"$ptr->{accno}_taxnumber"}   = $ptr->{taxnumber};
2110
          $form->{"$ptr->{accno}_taxnumber"}   = $ptr->{taxnumber}; # don't use this anymore
2111
          $form->{"$ptr->{accno}_tax_id"}      = $ptr->{tax_id};
2114 2112
          $form->{taxaccounts} .= "$ptr->{accno} ";
2115 2113
        }
2116 2114

  
......
2412 2410
    # get tax rates and description
2413 2411
    my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
2414 2412
    $query =
2415
      qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber
2413
      qq|SELECT c.accno, t.taxdescription, t.id as tax_id, t.rate, c.accno as taxnumber
2416 2414
         FROM tax t
2417 2415
         LEFT JOIN chart c ON (c.id = t.chart_id)
2418 2416
         WHERE t.id in
......
2441 2439
        $form->{"$ptr->{accno}_rate"}        = $ptr->{rate};
2442 2440
        $form->{"$ptr->{accno}_description"} = $ptr->{taxdescription};
2443 2441
        $form->{"$ptr->{accno}_taxnumber"}   = $ptr->{taxnumber};
2442
        $form->{"$ptr->{accno}_tax_id"}      = $ptr->{tax_id};
2444 2443
        $form->{taxaccounts} .= "$ptr->{accno} ";
2445 2444
      }
2446 2445

  
SL/OE.pm
1195 1195
      # get tax rates and description
1196 1196
      my $accno_id = ($form->{vc} eq "customer") ? $ref->{income_accno} : $ref->{expense_accno};
1197 1197
      $query =
1198
        qq|SELECT c.accno, t.taxdescription, t.rate, c.accno as taxnumber | .
1198
        qq|SELECT c.accno, t.taxdescription, t.rate, t.id as tax_id, c.accno as taxnumber | .
1199 1199
        qq|FROM tax t | .
1200 1200
        qq|LEFT JOIN chart c on (c.id = t.chart_id) | .
1201 1201
        qq|WHERE t.id IN (SELECT tk.tax_id FROM taxkeys tk | .
......
1215 1215
          $form->{"$ptr->{accno}_rate"}        = $ptr->{rate};
1216 1216
          $form->{"$ptr->{accno}_description"} = $ptr->{taxdescription};
1217 1217
          $form->{"$ptr->{accno}_taxnumber"}   = $ptr->{taxnumber};
1218
          $form->{"$ptr->{accno}_tax_id"}      = $ptr->{tax_id};
1218 1219
          $form->{taxaccounts} .= "$ptr->{accno} ";
1219 1220
        }
1220 1221

  
......
1592 1593
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate} },        $form->format_amount($myconfig, $form->{"${item}_rate"} * 100));
1593 1594
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxrate_nofmt} },  $form->{"${item}_rate"} * 100);
1594 1595
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxnumber} },      $form->{"${item}_taxnumber"});
1596
    push(@{ $form->{TEMPLATE_ARRAYS}->{tax_id} },         $form->{"${item}_tax_id"});
1595 1597

  
1596
    my $tax_objs     = SL::DB::Manager::Tax->get_objects_from_sql(
1597
      sql  => 'SELECT * from tax where chart_id = (SELECT id FROM chart WHERE accno = ?)',
1598
      args => [ $form->{"${item}_taxnumber"} ]
1599
    );
1600
    my $tax_obj;
1601
    if ( $tax_objs ) {
1602
      $tax_obj     = $tax_objs->[0];
1598
    if ( $form->{"${item}_tax_id"} ) {
1599
      my $tax_obj = SL::DB::Manager::Tax->find_by(id => $form->{"${item}_tax_id"}) or die "Can't find tax with id " . $form->{"${item}_tax_id"};
1600
      my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription',  $form->{language_id}, 0) : '';
1601
      push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%});
1603 1602
    }
1604
    my $description = $tax_obj ? $tax_obj->translated_attribute('taxdescription',  $form->{language_id}, 0) : '';
1605
    push(@{ $form->{TEMPLATE_ARRAYS}->{taxdescription} }, $description . q{ } . 100 * $form->{"${item}_rate"} . q{%});
1606 1603
  }
1607 1604

  
1608 1605
  $form->{nodiscount_subtotal} = $form->format_amount($myconfig, $form->{nodiscount_total}, 2);
bin/mozilla/io.pl
1660 1660
  $form->{"taxaccounts"} =~ s/\s*$//;
1661 1661
  $form->{"taxaccounts"} =~ s/^\s*//;
1662 1662
  foreach my $accno (split(/\s*/, $form->{"taxaccounts"})) {
1663
    map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber));
1663
    map({ delete($form->{"${accno}_${_}"}); } qw(rate description taxnumber tax_id)); # add tax_id ?
1664 1664
  }
1665 1665
  $form->{"taxaccounts"} = "";
1666 1666

  
bin/mozilla/ir.pl
451 451
    shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
452 452
    convert_from_do_ids convert_from_oe_ids convert_from_ap_ids show_details gldate useasnew
453 453
  ), @custom_hiddens,
454
  map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
454
  map { $_.'_rate', $_.'_description', $_.'_taxnumber', $_.'_tax_id' } split / /, $form->{taxaccounts}];
455 455

  
456 456
  $TMPL_VAR{payment_terms_obj} = get_payment_terms_for_invoice();
457 457
  $form->{duedate}             = $TMPL_VAR{payment_terms_obj}->calc_date(reference_date => $form->{invdate}, due_date => $form->{duedate})->to_kivitendo if $TMPL_VAR{payment_terms_obj};
bin/mozilla/is.pl
536 536
    invoice_id
537 537
    show_details
538 538
  ), @custom_hiddens,
539
  map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
539
  map { $_.'_rate', $_.'_description', $_.'_taxnumber', $_.'_tax_id' } split / /, $form->{taxaccounts}];
540 540

  
541 541
  $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase kivi.Part kivi.CustomerVendor kivi.Validator ckeditor/ckeditor ckeditor/adapters/jquery kivi.io client_js));
542 542

  
bin/mozilla/oe.pl
652 652
        taxpart taxservice taxaccounts cursor_fokus
653 653
        show_details useasnew),
654 654
        @custom_hiddens,
655
        map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts} ];  # deleted: discount
655
        map { $_.'_rate', $_.'_description', $_.'_taxnumber', $_.'_tax_id' } split / /, $form->{taxaccounts} ];  # deleted: discount
656 656

  
657 657
  $TMPL_VAR->{$_} = $type_check_vars{$_} for keys %type_check_vars;
658 658

  

Auch abrufbar als: Unified diff