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

SF.net SVN: ledger-smb:[2768] addons/1.3/assets/trunk/sql/modules/Assets. sql



Revision: 2768
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2768&view=rev
Author:   einhverfr
Date:     2009-09-15 16:00:17 +0000 (Tue, 15 Sep 2009)

Log Message:
-----------

Refactoring some asset stuff
Fixing some CSS issues
Other misc bug fixes:

Modified Paths:
--------------
    addons/1.3/assets/trunk/sql/modules/Assets.sql

Modified: addons/1.3/assets/trunk/sql/modules/Assets.sql
===================================================================
--- addons/1.3/assets/trunk/sql/modules/Assets.sql	2009-09-15 15:59:34 UTC (rev 2767)
+++ addons/1.3/assets/trunk/sql/modules/Assets.sql	2009-09-15 16:00:17 UTC (rev 2768)
@@ -40,10 +40,60 @@
 
 	INSERT INTO asset_report_line (asset_id, report_id, amount)
 	VALUES (in_asst_id, in_report_id, depreciation_amount);
+
+	PERFORM asset_report__generate_gl(in_report_id);
 	RETURN NULL;
 end;	
 $$ language plpgsql;
 
+CREATE OR REPLACE FUNCTION asset_report__generate_gl(in_report_id int)
+RETURNS INT AS
+$$
+DECLARE 
+	t_report_dept record;
+	t_line RECORD;
+	t_dept_id INT;
+	t_dep_amount numeric;
+
+Begin
+	INSERT INTO gl (reference, description, transdate, approved, 
+		department_id)
+	SELECT setting_increment('glnumber'), 'Asset Report' || report_id, 
+		report_date, false, department_id
+	FROM asset_report 
+	JOIN asset_report_line 
+		ON (asset_report.id = asset_report_line.report_id)
+	JOIN asset_item 
+		ON (asset_report_line.asset_item_id = asset_item.id)
+	WHERE asset_report.id = in_report_id
+	GROUP BY asset_report.report_id, asset_item.department_id;
+
+	INSERT INTO acc_trans (trans_id, chart_id, transdate, approved, amount)
+	SELECT gl.id, c.asset_account_id, r.report_date, true, sum(amount)
+	FROM asset_report r
+	JOIN asset_report_line l ON (r.id = l.report_id)
+	JOIN asset_item a ON (l.asset_item_id = a.id)
+	JOIN gl ON (gl.description = 'Asset Report' || l.report_id AND
+		a.department_id = gl.department_id)
+	JOIN asset_class c ON (a.class_id = c.id)
+	WHERE r.id = in_report_id
+	GROUP BY gl.id, c.asset_account_id, r.report_date;
+
+	INSERT INTO acc_trans (trans_id, chart_id, transdate, approved, amount)
+	SELECT gl.id, c.dep_account_id, r.report_date, true, sum(amount) * -1
+	FROM asset_report r
+	JOIN asset_report_line l ON (r.id = l.report_id)
+	JOIN asset_item a ON (l.asset_item_id = a.id)
+	JOIN gl ON (gl.description = 'Asset Report' || l.report_id AND
+		a.department_id = gl.department_id)
+	JOIN asset_class c ON (a.class_id = c.id)
+	WHERE r.id = in_report_id
+	GROUP BY gl.id, c.asset_account_id, r.report_date;
+
+	RETURN in_report_id;
+END;
+$$ language plpgsql;
+
 CREATE OR REPLACE FUNCTION asset_class__get (in_id int) RETURNS asset_class AS
 $$
 DECLARE ret_val asset_class;


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