commit 072919154edb34f4afed6bf93fdbdae5b0969385
Author: Niclas Zimmermann <niclas@kivitendo-premium.de>
Date:   Tue Dec 18 11:26:49 2012 +0100

    Probleme bei Mwst-Wechsel
    
    Durch einen Mwst-Wechsel kam es bisher zu einigen Problemen, folgende
    behebt dieser Commit:
    
    1.Korrektes Öffnen von Dialogbuchung bei inkl Steuern
    
    2.Korrekte Anzeige Steuersatz in
      Berichte-Kontenübersicht-...-Konto auswählen
    
    3.Korrektes Öffnen von Kreditorenbuchungen

diff --git a/SL/CA.pm b/SL/CA.pm
index 577d6b98a..aa9f4fe0e 100644
--- a/SL/CA.pm
+++ b/SL/CA.pm
@@ -273,7 +273,7 @@ sub all_transactions {
     $query =
       qq|SELECT a.id, a.reference, a.description, ac.transdate, ac.chart_id, | .
       qq|  $false AS invoice, ac.amount, 'gl' as module, | .
-      qq§(SELECT accno||'--'||rate FROM tax LEFT JOIN chart ON (tax.chart_id=chart.id) WHERE tax.id = (SELECT tax_id FROM taxkeys WHERE taxkey_id = ac.taxkey AND taxkeys.startdate <= ac.transdate ORDER BY taxkeys.startdate DESC LIMIT 1)) AS taxinfo, ac.source || ' ' || ac.memo AS memo § .
+      qq§(SELECT accno||'--'||rate FROM tax LEFT JOIN chart ON (tax.chart_id=chart.id) WHERE tax.id = ac.tax_id) AS taxinfo, ac.source || ' ' || ac.memo AS memo § .
       qq|FROM acc_trans ac, gl a | .
       $dpt_join .
       qq|WHERE | . $where . $dpt_where . $project .
@@ -285,7 +285,7 @@ sub all_transactions {
 
       qq|SELECT a.id, a.invnumber, c.name, ac.transdate, ac.chart_id, | .
       qq|  a.invoice, ac.amount, 'ar' as module, | .
-      qq§(SELECT accno||'--'||rate FROM tax LEFT JOIN chart ON (tax.chart_id=chart.id) WHERE tax.id = (SELECT tax_id FROM taxkeys WHERE taxkey_id = ac.taxkey AND taxkeys.startdate <= ac.transdate ORDER BY taxkeys.startdate DESC LIMIT 1)) AS taxinfo, ac.source || ' ' || ac.memo AS memo  § .
+      qq§(SELECT accno||'--'||rate FROM tax LEFT JOIN chart ON (tax.chart_id=chart.id) WHERE tax.id = ac.tax_id) AS taxinfo, ac.source || ' ' || ac.memo AS memo § .
       qq|FROM acc_trans ac, customer c, ar a | .
       $dpt_join .
       qq|WHERE | . $where . $dpt_where . $project .
@@ -298,7 +298,7 @@ sub all_transactions {
 
       qq|SELECT a.id, a.invnumber, v.name, ac.transdate, ac.chart_id, | .
       qq|  a.invoice, ac.amount, 'ap' as module, | .
-      qq§(SELECT accno||'--'||rate FROM tax LEFT JOIN chart ON (tax.chart_id=chart.id) WHERE tax.id = (SELECT tax_id FROM taxkeys WHERE taxkey_id = ac.taxkey AND taxkeys.startdate <= ac.transdate ORDER BY taxkeys.startdate DESC LIMIT 1)) AS taxinfo, ac.source || ' ' || ac.memo AS memo  § .
+      qq§(SELECT accno||'--'||rate FROM tax LEFT JOIN chart ON (tax.chart_id=chart.id) WHERE tax.id = ac.tax_id) AS taxinfo, ac.source || ' ' || ac.memo AS memo § .
       qq|FROM acc_trans ac, vendor v, ap a | .
       $dpt_join .
       qq|WHERE | . $where . $dpt_where . $project .
diff --git a/SL/Form.pm b/SL/Form.pm
index 19f2b5cf5..b34458ef6 100644
--- a/SL/Form.pm
+++ b/SL/Form.pm
@@ -2809,14 +2809,7 @@ sub create_links {
          FROM acc_trans a
          LEFT JOIN chart c ON (c.id = a.chart_id)
          LEFT JOIN project p ON (p.id = a.project_id)
-         LEFT JOIN tax t ON (t.id= (SELECT tk.tax_id FROM taxkeys tk
-                                    WHERE (tk.taxkey_id=a.taxkey) AND
-                                      ((CASE WHEN a.chart_id IN (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
-                                        THEN tk.chart_id = a.chart_id
-                                        ELSE 1 = 1
-                                        END)
-                                       OR (c.link='%tax%')) AND
-                                      (startdate <= a.transdate) ORDER BY startdate DESC LIMIT 1))
+         LEFT JOIN tax t ON (t.id= a.tax_id)
          WHERE a.trans_id = ?
          AND a.fx_transaction = '0'
          ORDER BY a.acc_trans_id, a.transdate|;
diff --git a/SL/GL.pm b/SL/GL.pm
index 80c5fda6e..315406345 100644
--- a/SL/GL.pm
+++ b/SL/GL.pm
@@ -664,26 +664,12 @@ sub transaction {
            (SELECT c1.accno
             FROM chart c1, tax t1
             WHERE (t1.id = t.id) AND (c1.id = t.chart_id)) AS taxaccno,
-           (SELECT tk.tax_id
-            FROM taxkeys tk
-            WHERE (tk.chart_id = a.chart_id) AND (tk.startdate <= a.transdate)
-            ORDER BY tk.startdate desc LIMIT 1) AS tax_id
+            a.tax_id AS tax_id
          FROM acc_trans a
          JOIN chart c ON (c.id = a.chart_id)
          LEFT JOIN project p ON (p.id = a.project_id)
          LEFT JOIN tax t ON
-           (t.id =
-             (SELECT tk.tax_id
-              FROM taxkeys tk
-              WHERE (tk.taxkey_id = a.taxkey) AND
-                ((CASE WHEN a.chart_id IN
-                    (SELECT chart_id FROM taxkeys WHERE taxkey_id = a.taxkey)
-                  THEN tk.chart_id = a.chart_id
-                  ELSE 1 = 1
-                  END)
-                 OR (c.link LIKE '%tax%'))
-                AND (startdate <= a.transdate)
-              ORDER BY startdate DESC LIMIT 1))
+           (t.id = a.tax_id)
          WHERE (a.trans_id = ?)
            AND (a.fx_transaction = '0')
          ORDER BY a.acc_trans_id, a.transdate|;
