From: Bernd Bleßmann Date: Wed, 24 Jun 2020 14:58:05 +0000 (+0200) Subject: PTC: Rückgabehash taxes in taxes_by_chart_id umbenannt X-Git-Tag: release-3.5.6.1~177 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=45d6fc385606d960c57d9bf1ec79bbc256f9a5a2;p=kivitendo-erp.git PTC: Rückgabehash taxes in taxes_by_chart_id umbenannt Damit ist klarer, was zu erwarten ist --- diff --git a/SL/DB/Helper/PriceTaxCalculator.pm b/SL/DB/Helper/PriceTaxCalculator.pm index 79dac7b4f..b0876da23 100644 --- a/SL/DB/Helper/PriceTaxCalculator.pm +++ b/SL/DB/Helper/PriceTaxCalculator.pm @@ -29,7 +29,7 @@ sub calculate_prices_and_taxes { last_incex_chart_id => undef, units_by_name => \%units_by_name, price_factors_by_id => \%price_factors_by_id, - taxes => { }, + taxes_by_chart_id => { }, taxes_by_tax_id => { }, amounts => { }, amounts_cogs => { }, @@ -66,7 +66,7 @@ sub calculate_prices_and_taxes { return $self unless wantarray; - return map { ($_ => $data{$_}) } qw(taxes taxes_by_tax_id amounts amounts_cogs allocated exchangerate assembly_items items rounding); + return map { ($_ => $data{$_}) } qw(taxes_by_chart_id taxes_by_tax_id amounts amounts_cogs allocated exchangerate assembly_items items rounding); } sub _get_exchangerate { @@ -123,10 +123,10 @@ sub _calculate_item { } if ($taxkey->tax->chart_id) { - $data->{taxes}->{ $taxkey->tax->chart_id } ||= 0; - $data->{taxes}->{ $taxkey->tax->chart_id } += $tax_amount; - $data->{taxes_by_tax_id}->{ $taxkey->tax_id } ||= 0; - $data->{taxes_by_tax_id}->{ $taxkey->tax_id } += $tax_amount; + $data->{taxes_by_chart_id}->{ $taxkey->tax->chart_id } ||= 0; + $data->{taxes_by_chart_id}->{ $taxkey->tax->chart_id } += $tax_amount; + $data->{taxes_by_tax_id}->{ $taxkey->tax_id } ||= 0; + $data->{taxes_by_tax_id}->{ $taxkey->tax_id } += $tax_amount; } elsif ($tax_amount) { die "tax_amount != 0 but no chart_id for taxkey " . $taxkey->id . " tax " . $taxkey->tax->id; } @@ -183,10 +183,10 @@ sub _calculate_amounts { my ($self, $data, %params) = @_; my $tax_diff = 0; - foreach my $chart_id (keys %{ $data->{taxes} }) { - my $rounded = _round($data->{taxes}->{$chart_id} * $data->{exchangerate}, 2); - $tax_diff += $data->{taxes}->{$chart_id} * $data->{exchangerate} - $rounded if $self->taxincluded; - $data->{taxes}->{$chart_id} = $rounded; + foreach my $chart_id (keys %{ $data->{taxes_by_chart_id} }) { + my $rounded = _round($data->{taxes_by_chart_id}->{$chart_id} * $data->{exchangerate}, 2); + $tax_diff += $data->{taxes_by_chart_id}->{$chart_id} * $data->{exchangerate} - $rounded if $self->taxincluded; + $data->{taxes_by_chart_id}->{$chart_id} = $rounded; } $self->netamount(sum map { $_->{amount} } values %{ $data->{amounts} }); @@ -202,7 +202,7 @@ sub _calculate_amounts { _dbg("Sna " . $self->netamount . " idiff " . $data->{invoicediff} . " tdiff ${tax_diff}"); - my $tax = sum values %{ $data->{taxes} }; + my $tax = sum values %{ $data->{taxes_by_chart_id} }; $amount = $netamount + $tax; my $grossamount = _round($amount, 2, 1); $data->{rounding} = _round($grossamount - $amount, 2); @@ -338,10 +338,10 @@ In array context a hash with the following keys is returned: =over 2 -=item C +=item C A hash reference with the calculated taxes. The keys are chart IDs, -the values the calculated taxes. +the values the rounded calculated taxes. =item C diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index f33d75dca..d428d08cb 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -275,7 +275,7 @@ sub post { $self->_post_add_acctrans($data{amounts_cogs}); $self->_post_add_acctrans($data{amounts}); - $self->_post_add_acctrans($data{taxes}); + $self->_post_add_acctrans($data{taxes_by_chart_id}); $self->_post_add_acctrans({ $params{ar_id} => $self->amount * -1 }); diff --git a/t/db_helper/price_tax_calculator.t b/t/db_helper/price_tax_calculator.t index e5087d051..057cd0d63 100644 --- a/t/db_helper/price_tax_calculator.t +++ b/t/db_helper/price_tax_calculator.t @@ -153,7 +153,7 @@ sub test_default_invoice_one_item_19_tax_not_included() { [], ], exchangerate => 1, - taxes => { + taxes_by_chart_id => { $tax->chart_id => 1.11, }, taxes_by_tax_id => { @@ -238,7 +238,7 @@ sub test_default_invoice_two_items_19_7_tax_not_included() { [], [], ], exchangerate => 1, - taxes => { + taxes_by_chart_id => { $tax->chart_id => 1.11, $tax7->chart_id => 0.82, }, @@ -346,7 +346,7 @@ sub test_default_invoice_three_items_sellprice_rounding_discount() { [], [], [], ], exchangerate => 1, - taxes => { + taxes_by_chart_id => { $tax->chart_id => 2.9, }, taxes_by_tax_id => { @@ -417,7 +417,7 @@ sub test_default_invoice_one_item_19_tax_not_included_rounding_discount() { [], ], exchangerate => 1, - taxes => { + taxes_by_chart_id => { $tax->chart_id => 0.66, }, taxes_by_tax_id => { @@ -470,7 +470,7 @@ sub test_default_invoice_one_item_19_tax_not_included_rounding_discount_huge_qty [], ], exchangerate => 1, - taxes => { + taxes_by_chart_id => { $tax->chart_id => 1843, }, taxes_by_tax_id => { @@ -534,7 +534,7 @@ sub test_default_invoice_one_item_19_tax_not_included_rounding_discount_big_qty_ [], ], exchangerate => 1, - taxes => { + taxes_by_chart_id => { $tax->chart_id => 12.84, }, taxes_by_tax_id => {