Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 45d6fc38

Von Bernd Bleßmann vor fast 4 Jahren hinzugefügt

  • ID 45d6fc385606d960c57d9bf1ec79bbc256f9a5a2
  • Vorgänger b3089c09
  • Nachfolger 517ed14d

PTC: Rückgabehash taxes in taxes_by_chart_id umbenannt

Damit ist klarer, was zu erwarten ist

Unterschiede anzeigen:

SL/DB/Helper/PriceTaxCalculator.pm
29 29
               last_incex_chart_id => undef,
30 30
               units_by_name       => \%units_by_name,
31 31
               price_factors_by_id => \%price_factors_by_id,
32
               taxes               => { },
32
               taxes_by_chart_id   => { },
33 33
               taxes_by_tax_id     => { },
34 34
               amounts             => { },
35 35
               amounts_cogs        => { },
......
66 66

  
67 67
  return $self unless wantarray;
68 68

  
69
  return map { ($_ => $data{$_}) } qw(taxes taxes_by_tax_id amounts amounts_cogs allocated exchangerate assembly_items items rounding);
69
  return map { ($_ => $data{$_}) } qw(taxes_by_chart_id taxes_by_tax_id amounts amounts_cogs allocated exchangerate assembly_items items rounding);
70 70
}
71 71

  
72 72
sub _get_exchangerate {
......
123 123
  }
124 124

  
125 125
  if ($taxkey->tax->chart_id) {
126
    $data->{taxes}->{ $taxkey->tax->chart_id } ||= 0;
127
    $data->{taxes}->{ $taxkey->tax->chart_id }  += $tax_amount;
128
    $data->{taxes_by_tax_id}->{ $taxkey->tax_id } ||= 0;
129
    $data->{taxes_by_tax_id}->{ $taxkey->tax_id }  += $tax_amount;
126
    $data->{taxes_by_chart_id}->{ $taxkey->tax->chart_id } ||= 0;
127
    $data->{taxes_by_chart_id}->{ $taxkey->tax->chart_id }  += $tax_amount;
128
    $data->{taxes_by_tax_id}->{ $taxkey->tax_id }          ||= 0;
129
    $data->{taxes_by_tax_id}->{ $taxkey->tax_id }           += $tax_amount;
130 130
  } elsif ($tax_amount) {
131 131
    die "tax_amount != 0 but no chart_id for taxkey " . $taxkey->id . " tax " . $taxkey->tax->id;
132 132
  }
......
183 183
  my ($self, $data, %params) = @_;
184 184

  
185 185
  my $tax_diff = 0;
186
  foreach my $chart_id (keys %{ $data->{taxes} }) {
187
    my $rounded                  = _round($data->{taxes}->{$chart_id} * $data->{exchangerate}, 2);
188
    $tax_diff                   += $data->{taxes}->{$chart_id} * $data->{exchangerate} - $rounded if $self->taxincluded;
189
    $data->{taxes}->{$chart_id}  = $rounded;
186
  foreach my $chart_id (keys %{ $data->{taxes_by_chart_id} }) {
187
    my $rounded                              = _round($data->{taxes_by_chart_id}->{$chart_id} * $data->{exchangerate}, 2);
188
    $tax_diff                               += $data->{taxes_by_chart_id}->{$chart_id} * $data->{exchangerate} - $rounded if $self->taxincluded;
189
    $data->{taxes_by_chart_id}->{$chart_id}  = $rounded;
190 190
  }
191 191

  
192 192
  $self->netamount(sum map { $_->{amount} } values %{ $data->{amounts} });
......
202 202

  
203 203
  _dbg("Sna " . $self->netamount . " idiff " . $data->{invoicediff} . " tdiff ${tax_diff}");
204 204

  
205
  my $tax              = sum values %{ $data->{taxes} };
205
  my $tax              = sum values %{ $data->{taxes_by_chart_id} };
206 206
  $amount              = $netamount + $tax;
207 207
  my $grossamount      = _round($amount, 2, 1);
208 208
  $data->{rounding}    = _round($grossamount - $amount, 2);
......
338 338

  
339 339
=over 2
340 340

  
341
=item C<taxes>
341
=item C<taxes_by_chart_id>
342 342

  
343 343
A hash reference with the calculated taxes. The keys are chart IDs,
344
the values the calculated taxes.
344
the values the rounded calculated taxes.
345 345

  
346 346
=item C<taxes_by_tax_id>
347 347

  
SL/DB/Invoice.pm
275 275

  
276 276
    $self->_post_add_acctrans($data{amounts_cogs});
277 277
    $self->_post_add_acctrans($data{amounts});
278
    $self->_post_add_acctrans($data{taxes});
278
    $self->_post_add_acctrans($data{taxes_by_chart_id});
279 279

  
280 280
    $self->_post_add_acctrans({ $params{ar_id} => $self->amount * -1 });
281 281

  
t/db_helper/price_tax_calculator.t
153 153
      [],
154 154
    ],
155 155
    exchangerate                                 => 1,
156
    taxes                                        => {
156
    taxes_by_chart_id                            => {
157 157
      $tax->chart_id                             => 1.11,
158 158
    },
159 159
    taxes_by_tax_id                              => {
......
238 238
      [], [],
239 239
    ],
240 240
    exchangerate                                  => 1,
241
    taxes                                         => {
241
    taxes_by_chart_id                             => {
242 242
      $tax->chart_id                              => 1.11,
243 243
      $tax7->chart_id                             => 0.82,
244 244
    },
......
346 346
      [], [], [],
347 347
    ],
348 348
    exchangerate                                 => 1,
349
    taxes                                        => {
349
    taxes_by_chart_id                            => {
350 350
      $tax->chart_id                             => 2.9,
351 351
    },
352 352
    taxes_by_tax_id                              => {
......
417 417
      [],
418 418
    ],
419 419
    exchangerate                                 => 1,
420
    taxes                                        => {
420
    taxes_by_chart_id                            => {
421 421
      $tax->chart_id                             => 0.66,
422 422
    },
423 423
    taxes_by_tax_id                              => {
......
470 470
      [],
471 471
    ],
472 472
    exchangerate                                 => 1,
473
    taxes                                        => {
473
    taxes_by_chart_id                            => {
474 474
      $tax->chart_id                             => 1843,
475 475
    },
476 476
    taxes_by_tax_id                              => {
......
534 534
      [],
535 535
    ],
536 536
    exchangerate                                 => 1,
537
    taxes                                        => {
537
    taxes_by_chart_id                            => {
538 538
      $tax->chart_id                             => 12.84,
539 539
    },
540 540
    taxes_by_tax_id                              => {

Auch abrufbar als: Unified diff