diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2008-06-23 17:08:04 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2008-06-23 17:08:04 +0000 |
commit | 675bce61fec48b070d653424867e897cf57b72df (patch) | |
tree | dda657f98145b95c7bf501189ef847f64d37e709 /sql/modules | |
parent | 2ad6191f9e1cd5857138550e5be0df8749ec375e (diff) |
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
Diffstat (limited to 'sql/modules')
-rw-r--r-- | sql/modules/Company.sql | 15 |
1 files changed, 15 insertions, 0 deletions
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,8 +235,23 @@ 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); t_entity_id := currval('entity_id_seq'); |