PTC: Steuern auch nach Steuer-Id zurückgeben
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 24 Jun 2020 14:45:55 +0000 (16:45 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 24 Jun 2020 14:45:55 +0000 (16:45 +0200)
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.

SL/DB/Helper/PriceTaxCalculator.pm
t/db_helper/price_tax_calculator.t

index a3c42d2..79dac7b 100644 (file)
@@ -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<taxes_by_tax_id>
+
+A hash reference with the calculated taxes. The keys are tax IDs,
+the values the calculated taxes.
+
 =item C<amounts>
 
 A hash reference with the calculated amounts. The keys are chart IDs,
index 6caae1d..e5087d0 100644 (file)
@@ -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,