diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/modules/Customer.sql | 8 | ||||
-rw-r--r-- | sql/modules/Location.sql | 7 | ||||
-rw-r--r-- | sql/modules/Vendor.sql | 10 |
3 files changed, 15 insertions, 10 deletions
diff --git a/sql/modules/Customer.sql b/sql/modules/Customer.sql index 40625cbf..c368906b 100644 --- a/sql/modules/Customer.sql +++ b/sql/modules/Customer.sql @@ -250,16 +250,16 @@ $$ LANGUAGE PLPGSQL; CREATE OR REPLACE FUNCTION customer_location_save ( - in_company_id int, + in_entity_id int, in_location_class int, in_line_one text, in_line_two text, in_line_three text, - in_city TEXT, in_state text, in_mail_code text, in_country_code int + in_city TEXT, in_state text, in_mail_code text, in_country_id int ) returns int AS $$ BEGIN return _entity_location_save( - in_company_id, NULL, + in_entity_id, NULL, in_location_class, in_line_one, in_line_two, in_line_three, - in_city, in_state, in_mail_code, in_country_code); + in_city, in_state, in_mail_code, in_country_id); END; $$ language 'plpgsql'; diff --git a/sql/modules/Location.sql b/sql/modules/Location.sql index 3986c24f..c0d57b51 100644 --- a/sql/modules/Location.sql +++ b/sql/modules/Location.sql @@ -49,11 +49,12 @@ BEGIN return location_row.id; END IF; INSERT INTO location - (line_one, line_two, line_three, city, state, mail_code, country_id) + (line_one, line_two, line_three, city, state, mail_code, country_id, + created) VALUES (in_address1, in_address2, in_address3, in_city, in_state, - in_zipcode, in_country); - SELECT lastval('location_id_seq') INTO location_id; + in_zipcode, in_country, now()); + SELECT currval('location_id_seq') INTO location_id; return location_id; END; $$ LANGUAGE PLPGSQL; diff --git a/sql/modules/Vendor.sql b/sql/modules/Vendor.sql index 8e9e12a9..1e3b640b 100644 --- a/sql/modules/Vendor.sql +++ b/sql/modules/Vendor.sql @@ -170,7 +170,7 @@ $$ language 'plpgsql'; create or replace function _entity_location_save( - in_company_id int, in_location_id int, + in_entity_id int, in_location_id int, in_location_class int, in_line_one text, in_line_two text, in_line_three text, in_city TEXT, in_state TEXT, in_mail_code text, in_country_code int @@ -179,9 +179,13 @@ create or replace function _entity_location_save( DECLARE l_row location; l_id INT; + t_company_id int; BEGIN + SELECT id INTO t_company_id + FROM company WHERE entity_id = in_entity_id; + DELETE FROM company_to_location - WHERE company_id = in_company_id + WHERE company_id = t_company_id AND location_class = in_location_class AND location_id = in_location_id; @@ -191,7 +195,7 @@ create or replace function _entity_location_save( INSERT INTO company_to_location (company_id, location_class, location_id) - VALUES (in_company_id, in_location_class, l_id); + VALUES (t_company_id, in_location_class, l_id); RETURN l_id; END; |