From 484f4f00ff319bf97c5ca911313738aa05a63a2c Mon Sep 17 00:00:00 2001
From: einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>
Date: Mon, 7 Jul 2008 17:37:20 +0000
Subject: Correcting all check printing issues on my secondary testing instance

git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2190 4979c152-3d1c-0410-bac9-87ea11338e46
---
 sql/modules/Company.sql | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

(limited to 'sql')

diff --git a/sql/modules/Company.sql b/sql/modules/Company.sql
index d653d9f7..45fd89dd 100644
--- a/sql/modules/Company.sql
+++ b/sql/modules/Company.sql
@@ -229,6 +229,39 @@ BEGIN
 END;
 $$ language plpgsql;
 
+CREATE TYPE company_billing_info AS (
+legal_name text,
+tax_id text,
+street1 text,
+street2 text,
+street3 text,
+city text,
+state text,
+mail_code text,
+country text
+);
+
+CREATE OR REPLACE FUNCTION company_get_billing_info (in_id int) 
+returns company_billing_info as
+$$
+DECLARE out_var company_billing_info;
+	t_id INT;
+BEGIN
+	select c.legal_name, c.tax_id, a.line_one, a.line_two, a.line_three, 
+		a.city, a.state, a.mail_code, cc.name
+	into out_var
+	FROM company c
+	JOIN company_to_location cl ON (c.id = cl.company_id)
+	JOIN location a ON (a.id = cl.location_id)
+	JOIN country cc ON (cc.id = a.country_id)
+	WHERE c.entity_id = (select entity_id 
+			from entity_credit_account where id = in_id)
+		AND a.id = (SELECT min(location_id) from company_to_location
+			where company_id = c.id and location_class = 1);
+	RETURN out_var;
+END;
+$$ language plpgsql;
+
 CREATE OR REPLACE FUNCTION company_save (
     in_id int, in_entity_class int,
     in_name text, in_tax_id TEXT,
-- 
cgit v1.2.3