[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[3016] trunk/sql/modules/Voucher.sql



Revision: 3016
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=3016&view=rev
Author:   einhverfr
Date:     2010-06-28 18:03:37 +0000 (Mon, 28 Jun 2010)

Log Message:
-----------
Correcting inability to delete ar/ap transactions with 1099 info attached

Modified Paths:
--------------
    trunk/sql/modules/Voucher.sql

Modified: trunk/sql/modules/Voucher.sql
===================================================================
--- trunk/sql/modules/Voucher.sql	2010-06-26 23:09:47 UTC (rev 3015)
+++ trunk/sql/modules/Voucher.sql	2010-06-28 18:03:37 UTC (rev 3016)
@@ -274,24 +274,7 @@
 BEGIN
 	FOR out_value IN
 		SELECT b.id, c.class, b.control_code, b.description, u.username,
-			b.created_on, b.default_date,
-			sum(
-				CASE WHEN vc.id = 5 AND al.amount < 0 -- GL
-				     THEN al.amount 
-				     WHEN vc.id  = 1
-				     THEN ap.amount 
-				     WHEN vc.id = 2
-                                     THEN ap.amount
-				     ELSE 0
-                                END) AS transaction_total,
-			sum(
-				CASE WHEN alc.link = 'AR' AND vc.id IN (6, 7)
-				     THEN al.amount
-				     WHEN alc.link = 'AP' AND vc.id IN (3, 4)
-				     THEN al.amount * -1
-				     ELSE 0
-				END
-			   ) AS payment_total
+			b.created_on, b.default_date, 0, 0
 		FROM batch b
 		JOIN batch_class c ON (b.batch_class_id = c.id)
 		LEFT JOIN users u ON (u.entity_id = b.created_by)
@@ -437,6 +420,11 @@
 	where id in (select trans_id from acc_trans where voucher_id IN 
 		(select id from voucher where batch_id = in_batch_id));
 
+        DELETE FROM ac_tax_form WHERE entry_id IN
+               (select entry_id from acc_trans where voucher_id in
+                       (select id from voucher where batch_id = in_batch_id)
+               );
+
 	DELETE FROM acc_trans WHERE voucher_id IN 
 		(select id FROM voucher where batch_id = in_batch_id);
 
@@ -446,6 +434,10 @@
 	SELECT as_array(trans_id) INTO t_transaction_ids
 	FROM voucher WHERE batch_id = in_batch_id AND batch_class IN (1, 2, 5);
 
+        DELETE FROM ac_tax_from WHERE entry_id in
+               (select entry_id from acc_trans 
+                 where trans_id = any(t_transaction_ids));
+
 	DELETE FROM acc_trans WHERE trans_id = ANY(t_transaction_ids);
 	DELETE FROM ap WHERE id = ANY(t_transaction_ids);
 	DELETE FROM gl WHERE id = ANY(t_transaction_ids);
@@ -469,6 +461,11 @@
 BEGIN
 	SELECT * INTO voucher_row FROM voucher WHERE id = in_voucher_id;
 	IF voucher_row.batch_class IN (1, 2, 5) THEN
+                DELETE FROM ac_tax_form WHERE trans_id IN (
+                       SELECT entry_id
+                        from acc_trans
+                       WHERE trans_id = voucher_row.trans_id);
+
 		DELETE from acc_trans WHERE trans_id = voucher_row.trans_id;
 		DELETE FROM ar WHERE id = voucher_row.trans_id;
 		DELETE FROM ap WHERE id = voucher_row.trans_id;
@@ -492,6 +489,9 @@
 				OR voucher_id <> voucher_row.id))
 		where id in (select trans_id from acc_trans 
 				where voucher_id = voucher_row.id);
+                DELETE FROM ac_tax_form WHERE entry_id IN
+                       (select entry_id from acc_trans 
+                         where voucher_id = voucher_row.id);
 
 		DELETE FROM acc_trans where voucher_id = voucher_row.id;
 	END IF;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.