From 675bce61fec48b070d653424867e897cf57b72df Mon Sep 17 00:00:00 2001 From: einhverfr Date: Mon, 23 Jun 2008 17:08:04 +0000 Subject: Updating customer/vendor saving to be more safe for multiple account entities. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2169 4979c152-3d1c-0410-bac9-87ea11338e46 --- sql/modules/Company.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'sql/modules') diff --git a/sql/modules/Company.sql b/sql/modules/Company.sql index f493586f..b7f5e640 100644 --- a/sql/modules/Company.sql +++ b/sql/modules/Company.sql @@ -235,7 +235,22 @@ CREATE OR REPLACE FUNCTION company_save ( in_entity_id int, in_sic_code text ) RETURNS INT AS $$ DECLARE t_entity_id INT; + t_company_id INT; BEGIN + IF in_entity_id IS NULL THEN + IF in_id IS NULL THEN + SELECT id INTO t_company_id FROM company + WHERE legal_name = in_name AND + (tax_id = in_tax_id OR + (tax_id IS NULL AND in_tax_id IS NULL)); + END IF; + IF t_company_id IS NOT NULL THEN + SELECT entity_id INTO t_entity_id FROM company + WHERE id = t_company_id; + END IF; + ELSE + t_entity_id := in_entity_id; + END IF; IF in_entity_id IS NULL THEN INSERT INTO entity (name, entity_class) VALUES (in_name, in_entity_class); -- cgit v1.2.3