From 6dd6719d91cf5a48acb6fb3731f9e143d7a7d83b Mon Sep 17 00:00:00 2001
From: =?utf8?q?Jan=20B=C3=BCren?= <jan@kivitendo-premium.de>
Date: Thu, 30 Jan 2014 10:28:09 +0100
Subject: [PATCH] =?utf8?q?Bugfix=202443:=20L=C3=B6schen=20von=20neu=20ange?=
 =?utf8?q?legten=20Konten,=20aufgrund=20von=20Constraint=20taxkeys=20nicht?=
 =?utf8?q?=20m=C3=B6glich?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

fixt #2443
---
 SL/AM.pm | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/SL/AM.pm b/SL/AM.pm
index ed896e1ad..29be070a6 100644
--- a/SL/AM.pm
+++ b/SL/AM.pm
@@ -482,16 +482,18 @@ sub delete_account {
               WHERE chart_id = ?|;
   do_query($form, $dbh, $query, $form->{id});
 
-  # delete chart of account record
-  $query = qq|DELETE FROM chart
-              WHERE id = ?|;
-  do_query($form, $dbh, $query, $form->{id});
-
   # delete account taxkeys
   $query = qq|DELETE FROM taxkeys
               WHERE chart_id = ?|;
   do_query($form, $dbh, $query, $form->{id});
 
+  # delete chart of account record
+  # last step delete chart, because we have a constraint
+  # to taxkeys
+  $query = qq|DELETE FROM chart
+              WHERE id = ?|;
+  do_query($form, $dbh, $query, $form->{id});
+
   # commit and redirect
   my $rc = $dbh->commit;
   $dbh->disconnect;
-- 
2.20.1