From: Bernd Bleßmann Date: Wed, 24 Jun 2020 14:45:55 +0000 (+0200) Subject: PTC: Steuern auch nach Steuer-Id zurückgeben X-Git-Tag: release-3.5.6.1~180 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=46547316aaf51a45a52deabacafa5ea3c637d048;p=kivitendo-erp.git PTC: Steuern auch nach Steuer-Id zurückgeben Bisher kann der PTC die berechntete Steuer pro Steuerkonto zurückgeben. Allerdings kann kivi so konfiguriert sein, dass verschiedene Steuern auf ein Konto gebucht werden. Diese lassen sich dann durch die Rückgabe des PTC nicht unterscheiden. Jetzt werden die Steuern zusätzlich auch pro Steuereintrag (also per tax.id) zurückgegeben. --- diff --git a/SL/DB/Helper/PriceTaxCalculator.pm b/SL/DB/Helper/PriceTaxCalculator.pm index a3c42d2e9..79dac7b4f 100644 --- a/SL/DB/Helper/PriceTaxCalculator.pm +++ b/SL/DB/Helper/PriceTaxCalculator.pm @@ -30,6 +30,7 @@ sub calculate_prices_and_taxes { units_by_name => \%units_by_name, price_factors_by_id => \%price_factors_by_id, taxes => { }, + taxes_by_tax_id => { }, amounts => { }, amounts_cogs => { }, allocated => { }, @@ -65,7 +66,7 @@ sub calculate_prices_and_taxes { return $self unless wantarray; - return map { ($_ => $data{$_}) } qw(taxes amounts amounts_cogs allocated exchangerate assembly_items items rounding); + return map { ($_ => $data{$_}) } qw(taxes taxes_by_tax_id amounts amounts_cogs allocated exchangerate assembly_items items rounding); } sub _get_exchangerate { @@ -124,6 +125,8 @@ 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; } elsif ($tax_amount) { die "tax_amount != 0 but no chart_id for taxkey " . $taxkey->id . " tax " . $taxkey->tax->id; } @@ -340,6 +343,11 @@ In array context a hash with the following keys is returned: A hash reference with the calculated taxes. The keys are chart IDs, the values the calculated taxes. +=item C + +A hash reference with the calculated taxes. The keys are tax IDs, +the values the calculated taxes. + =item C A hash reference with the calculated amounts. The keys are chart IDs, diff --git a/t/db_helper/price_tax_calculator.t b/t/db_helper/price_tax_calculator.t index 6caae1d7c..e5087d051 100644 --- a/t/db_helper/price_tax_calculator.t +++ b/t/db_helper/price_tax_calculator.t @@ -156,6 +156,9 @@ sub test_default_invoice_one_item_19_tax_not_included() { taxes => { $tax->chart_id => 1.11, }, + taxes_by_tax_id => { + $tax->id => 1.1115, + }, items => [ { linetotal => 5.85, linetotal_cost => 4.83, @@ -193,6 +196,7 @@ sub test_default_invoice_two_items_19_7_tax_not_included() { # item 2: # sellprice 9.714 * qty 1.2 = 11.6568 rounded 11.66 # 7%(11.6568) = 0.815976; rounded = 0.82 + # 7%(11.66) = 0.8162 # total rounded = 12.48 # lastcost 5.473 * qty 1.2 = 6.5676; rounded 6.57 @@ -238,6 +242,10 @@ sub test_default_invoice_two_items_19_7_tax_not_included() { $tax->chart_id => 1.11, $tax7->chart_id => 0.82, }, + taxes_by_tax_id => { + $tax->id => 1.1115, + $tax7->id => 0.8162, + }, items => [ { linetotal => 5.85, linetotal_cost => 4.83, @@ -341,6 +349,9 @@ sub test_default_invoice_three_items_sellprice_rounding_discount() { taxes => { $tax->chart_id => 2.9, }, + taxes_by_tax_id => { + $tax->id => 2.89750, + }, items => [ { linetotal => 5.27, linetotal_cost => 1.93, @@ -409,6 +420,9 @@ sub test_default_invoice_one_item_19_tax_not_included_rounding_discount() { taxes => { $tax->chart_id => 0.66, }, + taxes_by_tax_id => { + $tax->id => 0.66310, + }, items => [ { linetotal => 3.49, linetotal_cost => 0, @@ -459,6 +473,9 @@ sub test_default_invoice_one_item_19_tax_not_included_rounding_discount_huge_qty taxes => { $tax->chart_id => 1843, }, + taxes_by_tax_id => { + $tax->id => 1843, + }, items => [ { linetotal => 9700, linetotal_cost => 0, @@ -520,6 +537,9 @@ sub test_default_invoice_one_item_19_tax_not_included_rounding_discount_big_qty_ taxes => { $tax->chart_id => 12.84, }, + taxes_by_tax_id => { + $tax->id => 12.8364, + }, items => [ { linetotal => 67.56, linetotal_cost => 19301.93,