[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1888] trunk



Revision: 1888
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1888&view=rev
Author:   einhverfr
Date:     2007-11-21 19:31:05 -0800 (Wed, 21 Nov 2007)

Log Message:
-----------
More customer fixes

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Customer.pm
    trunk/sql/modules/Customer.sql
    trunk/sql/modules/Location.sql
    trunk/sql/modules/Vendor.sql

Modified: trunk/LedgerSMB/DBObject/Customer.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Customer.pm	2007-11-21 23:49:19 UTC (rev 1887)
+++ trunk/LedgerSMB/DBObject/Customer.pm	2007-11-22 03:31:05 UTC (rev 1888)
@@ -12,7 +12,8 @@
     # 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 save_location {
     $self = shift @_;
     $self->{entity_class} = $CUSTOMER_ENTITY_CLASS;
+    $self->{country_id} = $self->{country};
     $self->exec_method(funcname => 'customer_location_save');
 }
 

Modified: trunk/sql/modules/Customer.sql
===================================================================
--- trunk/sql/modules/Customer.sql	2007-11-21 23:49:19 UTC (rev 1887)
+++ trunk/sql/modules/Customer.sql	2007-11-22 03:31:05 UTC (rev 1888)
@@ -250,16 +250,16 @@
 
 
 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';

Modified: trunk/sql/modules/Location.sql
===================================================================
--- trunk/sql/modules/Location.sql	2007-11-21 23:49:19 UTC (rev 1887)
+++ trunk/sql/modules/Location.sql	2007-11-22 03:31:05 UTC (rev 1888)
@@ -49,11 +49,12 @@
 		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;

Modified: trunk/sql/modules/Vendor.sql
===================================================================
--- trunk/sql/modules/Vendor.sql	2007-11-21 23:49:19 UTC (rev 1887)
+++ trunk/sql/modules/Vendor.sql	2007-11-22 03:31:05 UTC (rev 1888)
@@ -170,7 +170,7 @@
 
 
 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 @@
     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 @@
 
 	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;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.