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

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



Revision: 1885
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1885&view=rev
Author:   einhverfr
Date:     2007-11-20 21:42:22 -0800 (Tue, 20 Nov 2007)

Log Message:
-----------
More Customer Fixes

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Customer.pm
    trunk/UI/Customer/customer.html
    trunk/scripts/customer.pl
    trunk/sql/modules/Customer.sql
    trunk/sql/modules/Location.sql
    trunk/sql/modules/Roles.sql
    trunk/sql/modules/Vendor.sql

Modified: trunk/LedgerSMB/DBObject/Customer.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Customer.pm	2007-11-20 20:06:22 UTC (rev 1884)
+++ trunk/LedgerSMB/DBObject/Customer.pm	2007-11-21 05:42:22 UTC (rev 1885)
@@ -4,11 +4,13 @@
 use LedgerSMB::DBObject;
 use LedgerSMB::Entity;
 
+my $CUSTOMER_ENTITY_CLASS = 2;
+
 sub save {
     my $self = shift @_;
 
     # This saves both the entity and the credit account. -- CT
-    $self->{entity_class} = 2;
+    $self->{entity_class} = $CUSTOMER_ENTITY_CLASS;
     
     $self->{entity_id} = $self->exec_method(funcname => 'entity_credit_save');
     $self->{dbh}->commit;
@@ -27,6 +29,38 @@
          $self->exec_method(funcname => 'entity_list_contact_class');
 }
 
+sub save_location {
+    $self = shift @_;
+    $self->{entity_class} = $CUSTOMER_ENTITY_CLASS;
+    $self->exec_method(funcname => 'customer_location_save');
+}
+
+sub save_contact {
+}
+
+sub save_bank_acct {
+}
+
+sub get {
+    my $self = shift @_;
+    $self->merge(shift @{$self->exec_method(funcname => 'customer__retrieve')});
+
+    $self->{name} = $self->{legal_name};
+
+    @{$self->{locations}} = $self->exec_method(
+		funcname => 'company__list_locations');
+
+    @{$self->{contacts}} = $self->exec_method(
+		funcname => 'company__list_contacts');
+
+    @{$self->{contacts}} = $self->exec_method(
+		funcname => 'company__list_bank_accounts');
+
+    @{$self->{notes}} = $self->exec_method(
+		funcname => 'company__list_notes');
+}
+
+
 sub search {
     
     

Modified: trunk/UI/Customer/customer.html
===================================================================
--- trunk/UI/Customer/customer.html	2007-11-20 20:06:22 UTC (rev 1884)
+++ trunk/UI/Customer/customer.html	2007-11-21 05:42:22 UTC (rev 1885)
@@ -165,7 +165,7 @@
     <div class="listtop"><?lsmb text('Locations') ?></div>
 	<!-- This entire form should probably be optionaly automated with AJAX
 	in oder to prevent user confusion -->
-    <form id="location_form" action="vendor.pl">
+    <form id="location_form" action="customer.pl">
 	<input type="hidden" name="entity_id" value="<?lsmb entity_id ?>">
 	<input type="hidden" name="location_id" value="<?lsmb location_id ?>">
     <table width="100%">
@@ -234,8 +234,9 @@
 		<?lsmb END ?>
 		</select>
 	</div>
-	<div><button type=submit class="submit" name=submit value="add_location"
-		id="loc_save_location">Save Location</button>
+	<div><button type=submit class="submit" name="action" 
+		value="add_location" id="loc_save_location">
+		<?lsmb text('Save Location') ?></button>
 	</div>
     </form>
 </div>

Modified: trunk/scripts/customer.pl
===================================================================
--- trunk/scripts/customer.pl	2007-11-20 20:06:22 UTC (rev 1884)
+++ trunk/scripts/customer.pl	2007-11-21 05:42:22 UTC (rev 1885)
@@ -56,6 +56,28 @@
         
 }
 
+
+sub add_location {
+    my ($request) = @_;
+    my $customer = LedgerSMB::DBObject::Customer->new({base => $request, copy => 'all'});
+    $customer->set( entity_class=> '2' );
+    $customer->save_location();
+    $customer->get();
+
+    
+    $customer->get_metadata();
+
+    my $template = LedgerSMB::Template->new( 
+	user => $user, 
+	template => 'customer', 
+	path => 'UI/Customer',
+	locale => $request->{_locale}, 
+        format => 'HTML');
+    $request->{script} = 'Customer/customer';
+    $template->render($customer);
+	
+}
+
 =pod
 
 =over

Modified: trunk/sql/modules/Customer.sql
===================================================================
--- trunk/sql/modules/Customer.sql	2007-11-20 20:06:22 UTC (rev 1884)
+++ trunk/sql/modules/Customer.sql	2007-11-21 05:42:22 UTC (rev 1885)
@@ -23,19 +23,33 @@
         creditlimit numeric,
         terms int2,
         customernumber int,
-        cc text,
-        bcc text,
         business_id int,
         language_code text,
         pricegroup_id int,
-        curr char,
+        curr char(3),
         startdate date,
-        enddate date,
-        bic varchar, 
-        iban varchar, 
-        note text
+        enddate date
 );
 
+CREATE OR REPLACE FUNCTION customer__retrieve(in_entity_id int) RETURNS
+customer_search_return AS
+$$
+DECLARE out_row customer_search_return;
+BEGIN
+	SELECT c.legal_name, c.id, e.id, ec.entity_class, ec.discount,
+		ec.taxincluded, ec.creditlimit, ec.terms, ec.meta_number,
+		ec.business_id, ec.language_code, ec.pricegroup_id, 
+		ec.curr::char(3), ec.startdate, ec.enddate
+	INTO out_row
+	FROM company c
+	JOIN entity e ON (c.entity_id = e.id)
+	JOIN entity_credit_account ec ON (c.entity_id = ec.entity_id)
+	WHERE e.id = in_entity_id
+		AND ec.entity_class = 2;
+
+	RETURN out_row;
+END;
+$$ LANGUAGE PLPGSQL;
 -- COMMENT ON TYPE customer_search_result IS
 -- $$ This structure will change greatly in 1.4.  
 -- If you want to reply on it heavily, be prepared for breakage later.  $$;
@@ -145,6 +159,96 @@
     
 $$ language 'plpgsql';
 
+CREATE TYPE location_result AS (
+	id int,
+	line_one text,
+	line_two text,
+	line_three text,
+	city text,
+	state text,
+	country text,
+	class text
+);
+
+
+CREATE OR REPLACE FUNCTION company__list_locations(in_entity_id int)
+RETURNS SETOF location_result AS
+$$
+DECLARE out_row RECORD;
+BEGIN
+	FOR out_row IN
+		SELECT l.id, l.line_one, l.line_two, l.line_three, l.city, 
+			l.state, c.name, lc.class
+		FROM location l
+		JOIN company_to_location ctl ON (ctl.location_id = l.id)
+		JOIN company cp ON (ctl.company_id = cp.id)
+		JOIN location_class lc ON (ctl.location_class = lc.id)
+		JOIN country c ON (c.id = l.country_id)
+		WHERE cp.entity_id = in_entity_id
+		ORDER BY lc.id, l.id, c.name
+	LOOP
+		RETURN NEXT out_row;
+	END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TYPE contact_list AS (
+	class text,
+	contact text
+);
+
+CREATE OR REPLACE FUNCTION company__list_contacts(in_entity_id int)
+RETURNS SETOF contact_list AS 
+$$
+DECLARE out_row RECORD;
+BEGIN
+	FOR out_row IN 
+		SELECT cc.class, c.contact
+		FROM company_to_contact c
+		JOIN contact_class cc ON (c.contact_class_id = cc.id)
+		JOIN company cp ON (c.company_id = cp.id)
+		WHERE cp.entity_id = in_entity_id
+	LOOP
+		RETURN NEXT out_row;
+	END LOOP;
+END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION company__list_bank_account(in_entity_id int)
+RETURNS SETOF entity_bank_account AS
+$$
+DECLARE out_row entity_bank_account%ROWTYPE;
+BEGIN
+	FOR out_row IN
+		SELECT * from entity_bank_account where entity_id = in_entity_id
+	LOOP
+		RETURN NEXT;
+	END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+
+CREATE TYPE entity_note_list AS (
+	id int,
+	note text
+);
+
+CREATE OR REPLACE FUNCTION company__list_notes(in_entity_id int) 
+RETURNS SETOF entity_note_list AS 
+$$
+DECLARE out_row record;
+BEGIN
+	FOR out_row IN
+		SELECT id, note
+		FROM entity_note
+		WHERE ref_key = in_entity_id
+	LOOP
+		RETURN NEXT out_row;
+	END LOOP;
+END;
+$$ LANGUAGE PLPGSQL;
+		
+
+
 CREATE OR REPLACE FUNCTION customer_location_save (
     in_company_id int,
     in_location_class int, in_line_one text, in_line_two text, 
@@ -153,7 +257,7 @@
 ) returns int AS $$
     BEGIN
     return _entity_location_save(
-        in_company_id,
+        in_company_id, NULL,
         in_location_class, in_line_one, in_line_two, in_line_three,
         in_city, in_state, in_mail_code, in_country_code);
     END;

Modified: trunk/sql/modules/Location.sql
===================================================================
--- trunk/sql/modules/Location.sql	2007-11-20 20:06:22 UTC (rev 1884)
+++ trunk/sql/modules/Location.sql	2007-11-21 05:42:22 UTC (rev 1885)
@@ -28,7 +28,7 @@
 
 CREATE OR REPLACE FUNCTION location_save
 (in_address1 text, in_address2 text, in_address3 text,
-	in_city text, in_state text, in_zipcode text, in_country text) 
+	in_city text, in_state text, in_zipcode text, in_country int) 
 returns integer AS
 $$
 DECLARE
@@ -42,16 +42,16 @@
 		line_three = in_address3 AND
 		city = in_city AND
 		state = in_state AND
-		zipcode = in_zipcode AND
+		mail_code = in_zipcode AND
 		country_id = in_country
 	LIMIT 1;
 	IF FOUND THEN
 		return location_row.id;
 	END IF;
 	INSERT INTO location 
-	(companyname, address1, address2, city, state, zipcode, country_id)
+	(line_one, line_two, line_three, city, state, mail_code, country_id)
 	VALUES
-	(in_companyname, in_address1, in_address2, in_city, in_state,
+	(in_address1, in_address2, in_address3, in_city, in_state,
 		in_zipcode, in_country);
 	SELECT lastval('location_id_seq') INTO location_id;
 	return location_id;

Modified: trunk/sql/modules/Roles.sql
===================================================================
--- trunk/sql/modules/Roles.sql	2007-11-20 20:06:22 UTC (rev 1884)
+++ trunk/sql/modules/Roles.sql	2007-11-21 05:42:22 UTC (rev 1885)
@@ -23,6 +23,7 @@
 GRANT SELECT ON person_to_contact TO lsmb_<?lsmb dbname ?>__read_contact;
 GRANT SELECT ON person_to_location TO lsmb_<?lsmb dbname ?>__read_contact;
 GRANT SELECT ON person_to_location TO lsmb_<?lsmb dbname ?>__read_contact;
+GRANT SELECT ON company_to_location TO lsmb_<?lsmb dbname ?>__read_contact;
 GRANT SELECT ON vendortax TO lsmb_<?lsmb dbname ?>__read_contact;
 
 INSERT INTO menu_acl (node_id, acl_type, role_name) 
@@ -67,6 +68,8 @@
 GRANT INSERT ON person_to_contact TO lsmb_<?lsmb dbname ?>__create_contact;
 GRANT INSERT ON person_to_location TO lsmb_<?lsmb dbname ?>__create_contact;
 GRANT INSERT ON person_to_location TO lsmb_<?lsmb dbname ?>__create_contact;
+GRANT INSERT ON company_to_location TO lsmb_<?lsmb dbname ?>__create_contact;
+GRANT DELETE ON company_to_location TO lsmb_<?lsmb dbname ?>__create_contact;
 GRANT INSERT ON vendortax TO lsmb_<?lsmb dbname ?>__create_contact;
 
 INSERT INTO menu_acl (node_id, acl_type, role_name) 

Modified: trunk/sql/modules/Vendor.sql
===================================================================
--- trunk/sql/modules/Vendor.sql	2007-11-20 20:06:22 UTC (rev 1884)
+++ trunk/sql/modules/Vendor.sql	2007-11-21 05:42:22 UTC (rev 1885)
@@ -186,7 +186,7 @@
 		AND location_id = in_location_id;
 
 	SELECT location_save(in_line_one, in_line_two, in_line_three, in_city,
-		in_state, in_mail_code, in_mail_code, in_country_code) 
+		in_state, in_mail_code, in_country_code) 
 	INTO l_id;
 
 	INSERT INTO company_to_location 


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