From 27b2c2caf5ea455663253189c797bbbf4ab0807f Mon Sep 17 00:00:00 2001
From: einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>
Date: Wed, 22 Oct 2008 20:29:16 +0000
Subject: Corrected missing commit on draft deletion Corrected inadequate
 cleanup on draft deletion

git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2377 4979c152-3d1c-0410-bac9-87ea11338e46
---
 sql/modules/Drafts.sql | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

(limited to 'sql/modules/Drafts.sql')

diff --git a/sql/modules/Drafts.sql b/sql/modules/Drafts.sql
index e5a7b940..850fae4e 100644
--- a/sql/modules/Drafts.sql
+++ b/sql/modules/Drafts.sql
@@ -91,7 +91,9 @@ $$
 declare 
 	t_table text;
 begin
-	SELECT table_name into t_table FROM transactions where id = in_id;
+        DELETE FROM acc_trans WHERE trans_id = in_id;
+	SELECT lower(table_name) into t_table FROM transactions where id = in_id;
+
         IF t_table = 'ar' THEN
 		DELETE FROM ar WHERE id = in_id AND approved IS FALSE;
 	ELSIF t_table = 'ap' THEN
@@ -101,7 +103,10 @@ begin
 	ELSE
 		raise exception 'Invalid table % in draft_delete for transaction %', t_table, in_id;
 	END IF;
-	RETURN FOUND;
+	IF NOT FOUND THEN
+		RAISE EXCEPTION 'Invalid transaction id %', in_id;
+	END IF;
+	RETURN TRUE;
 END;
 $$ LANGUAGE PLPGSQL SECURITY DEFINER;
 
-- 
cgit v1.2.3

