summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-22 03:31:05 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-22 03:31:05 +0000
commit0190093b09369a6fcf50887620a65b242199478e (patch)
tree4f8b43257fc1703e609345be230d0493ae653860
parent47b7f03901913406bf666fa6dd20b1856d1de7fd (diff)
More customer fixes
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1888 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r--LedgerSMB/DBObject/Customer.pm4
-rw-r--r--sql/modules/Customer.sql8
-rw-r--r--sql/modules/Location.sql7
-rw-r--r--sql/modules/Vendor.sql10
4 files changed, 18 insertions, 11 deletions
diff --git a/LedgerSMB/DBObject/Customer.pm b/LedgerSMB/DBObject/Customer.pm
index 7cd550dc..08296d06 100644
--- a/LedgerSMB/DBObject/Customer.pm
+++ b/LedgerSMB/DBObject/Customer.pm
@@ -12,7 +12,8 @@ sub save {
# This saves both the entity and the credit account. -- CT
$self->{entity_class} = $CUSTOMER_ENTITY_CLASS;
- $self->{entity_id} = $self->exec_method(funcname => 'entity_credit_save');
+ ($ref) = $self->exec_method(funcname => 'entity_credit_save');
+ $self->{entity_id} = $ref->{entity_credit_save};
$self->{dbh}->commit;
}
@@ -32,6 +33,7 @@ sub get_metadata {
sub save_location {
$self = shift @_;
$self->{entity_class} = $CUSTOMER_ENTITY_CLASS;
+ $self->{country_id} = $self->{country};
$self->exec_method(funcname => 'customer_location_save');
}
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;