epic-s6ts
[kivitendo-erp.git] / SL / USTVA.pm
index b01ebac..ee2d21f 100644 (file)
@@ -26,6 +26,7 @@
 
 package USTVA;
 
+use Carp;
 use Data::Dumper;
 use List::Util qw(first);
 
@@ -33,6 +34,7 @@ use SL::DB;
 use SL::DBUtils;
 use SL::DB::Default;
 use SL::DB::Finanzamt;
+use SL::Locale::String qw(t8);
 
 use utf8;
 use strict;
@@ -691,7 +693,7 @@ sub get_accounts_ustva {
          SUM( ac.amount *
             -- Bezahlt / Rechnungssumme
            (
-             SELECT SUM(acc.amount), t.rate, c.accno
+             SELECT SUM(acc.amount)
              FROM acc_trans acc
              INNER JOIN chart c ON (acc.chart_id   =   c.id
                                     AND c.link   like  '%AR_paid%')
@@ -699,13 +701,12 @@ sub get_accounts_ustva {
               1=1
               $ARwhere
               AND acc.trans_id = ac.trans_id
-              )
-           /
+              )           /
            (
             SELECT amount FROM ar WHERE id = ac.trans_id
            )
          ) AS amount,
-         tk.pos_ustva
+         tk.pos_ustva,  t.rate, c.accno
        FROM acc_trans ac
        LEFT JOIN chart c ON (c.id  = ac.chart_id)
        LEFT JOIN ar      ON (ar.id = ac.trans_id)
@@ -875,6 +876,12 @@ sub get_accounts_ustva {
         # Dont rely on dates of taxkeys
         $corr = 1;
         $form->{"81"} += $ref->{amount};
+      }  elsif ($ref->{rate} == 0.07) {
+        # pos_ustva says 5, but rate says 7
+        # see comment above:
+        # Dont rely on dates of taxkeys
+        $corr = 1;
+        $form->{"86"} += $ref->{amount};
       } else {die ("No valid tax rate for pos 35" . Dumper($ref)); }
     }
     # USTVA Pos 36 (Steuerkonten)