Beim Speichern eines Kontos chart.taxkey_id aus taxkeys aktualisieren/setzen
authorMoritz Bunkus <moritz@bunkus.org>
Wed, 27 Apr 2011 08:47:44 +0000 (10:47 +0200)
committerMoritz Bunkus <moritz@bunkus.org>
Wed, 27 Apr 2011 08:47:44 +0000 (10:47 +0200)
Fix für Bug 1627.

SL/AM.pm
sql/Pg-upgrade2/chart_taxkey_id_from_taxkeys.sql [new file with mode: 0644]

index bf5c97d..a4db439 100644 (file)
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -378,6 +378,21 @@ sub save_account {
 
   }
 
+  # Update chart.taxkey_id to the latest from taxkeys for this chart.
+  $query = <<SQL;
+    UPDATE chart
+    SET taxkey_id = (
+      SELECT taxkey_id
+      FROM taxkeys
+      WHERE taxkeys.chart_id = chart.id
+      ORDER BY startdate DESC
+      LIMIT 1
+    )
+    WHERE id = ?
+SQL
+
+  do_query($form, $dbh, $query, $form->{id});
+
   # commit
   my $rc = $dbh->commit;
   $dbh->disconnect;
diff --git a/sql/Pg-upgrade2/chart_taxkey_id_from_taxkeys.sql b/sql/Pg-upgrade2/chart_taxkey_id_from_taxkeys.sql
new file mode 100644 (file)
index 0000000..5301735
--- /dev/null
@@ -0,0 +1,12 @@
+-- @tag: chart_taxkey_id_from_taxkeys
+-- @description: chart.taxkey_id aus taxkeys aktualisieren
+-- @depends: release_2_6_2
+-- @charset: utf-8
+UPDATE chart
+SET taxkey_id = (
+  SELECT taxkey_id
+  FROM taxkeys
+  WHERE taxkeys.chart_id = chart.id
+  ORDER BY startdate DESC
+  LIMIT 1
+);