From 18e15b44b4dda09f5d5a8a416e3f6524fb8b2a64 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Sun, 18 Nov 2007 20:35:31 +0000 Subject: More customer/vendor screen/stored proc fixes. Note that since locations are mapped many<->many with companies and persons, I have moved the location class foreign key into the mapping tables. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1879 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/DBObject/Customer.pm | 4 +- LedgerSMB/Template/HTML.pm | 2 +- UI/Customer/customer.html | 127 +++++++++++++++++++---------------------- UI/lib/ui-header.html | 9 +++ scripts/customer.pl | 39 +++++++------ scripts/payment.pl | 4 +- sql/Pg-database.sql | 3 +- sql/modules/Location.sql | 8 +-- sql/modules/Roles.sql | 1 + sql/modules/Vendor.sql | 60 ++++++------------- 10 files changed, 121 insertions(+), 136 deletions(-) diff --git a/LedgerSMB/DBObject/Customer.pm b/LedgerSMB/DBObject/Customer.pm index 36b4ed62..09f8e3dd 100644 --- a/LedgerSMB/DBObject/Customer.pm +++ b/LedgerSMB/DBObject/Customer.pm @@ -1,6 +1,6 @@ package LedgerSMB::DBObject::Customer; -use base qw(LedgerSMB::DBObject::Company); +use base qw(LedgerSMB::DBObject); use LedgerSMB::DBObject; use LedgerSMB::Entity; @@ -44,4 +44,4 @@ sub search { } -1; \ No newline at end of file +1; diff --git a/LedgerSMB/Template/HTML.pm b/LedgerSMB/Template/HTML.pm index 9159098e..ca748dd3 100755 --- a/LedgerSMB/Template/HTML.pm +++ b/LedgerSMB/Template/HTML.pm @@ -97,7 +97,7 @@ sub process { $source = get_template($parent->{template}); } $template = Template->new({ - INCLUDE_PATH => $parent->{include_path}, + INCLUDE_PATH => [$parent->{include_path}, 'UI/lib'], START_TAG => quotemeta(' quotemeta('?>'), DELIMITER => ';', diff --git a/UI/Customer/customer.html b/UI/Customer/customer.html index 23bb064b..88020d1d 100644 --- a/UI/Customer/customer.html +++ b/UI/Customer/customer.html @@ -1,109 +1,102 @@ - - - - <?lsmb form.titlebar ?> - - - - - - - - - + + +
- - - + + +
+ +
- + + -
- + - + + + - - @@ -111,21 +104,22 @@ +

- + value=""> - +
- + - +
- + - days - - - + days
- + - + +
+ + / + - +
- + - +

-
-
- - - - + - - - - - - - - - - -
+
+
+ +
+ +
+
+ + diff --git a/UI/lib/ui-header.html b/UI/lib/ui-header.html index 5a429866..af703b32 100644 --- a/UI/lib/ui-header.html +++ b/UI/lib/ui-header.html @@ -6,7 +6,16 @@ + + + + + + + + + diff --git a/scripts/customer.pl b/scripts/customer.pl index 7fc238da..76fa8a56 100644 --- a/scripts/customer.pl +++ b/scripts/customer.pl @@ -44,14 +44,14 @@ of the customer informations. sub get { my ($request) = @_; - my $customer = LedgerSMB::DBObject::Company->new(base => $request, copy => 'all'); + my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all'); $customer->set( entity_class=> '2' ); my $result = $customer->get(); my $template = LedgerSMB::Template->new( user => $user, - template => 'Customer/customer.html', language => $user->{language}, - format => 'html'); + template => 'Customer/customer', language => $user->{language}, + format => 'HTML'); $template->render($results); } @@ -70,12 +70,16 @@ This method creates a blank screen for entering a customer's information. sub add { my ($request) = @_; - my $customer = LedgerSMB::DBObject::Company->new(base => $request, copy => 'all'); + my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all'); $customer->set(entity_class=>2); - my $template = LedgerSMB::Template->new( user => $user, - template => 'Customer/customer.html', language => $user->{language}, - format => 'html'); - $template->render($results); + my $template = LedgerSMB::Template->new( + user => $user, + template => 'customer', + path => 'UI/Customer', + locale => $request->{_locale}, + format => 'HTML'); + $request->{script} = 'Customer/customer'; + $template->render($request); } =pod @@ -100,13 +104,13 @@ sub search { if ($request->type() eq 'POST') { # assume it's asking us to do the search, now - my $customer = LedgerSMB::DBObject::Company->new(base => $request, copy => 'all'); + my $customer = LedgerSMB::DBObject::Customer->new(base => $request, copy => 'all'); $customer->set(entity_class=>2); my $results = $customer->search($customer->{search_pattern}); my $template = LedgerSMB::Template->new( user => $user, - template => 'Customer/customer.html', language => $user->{language}, - format => 'html'); + template => 'Customer/customer', language => $user->{language}, + format => 'HTML'); $template->render($results); } @@ -114,9 +118,12 @@ sub search { # grab the happy search page out. - my $template = LedgerSMB::Template->new( user => $user, - template => 'Customer/customer_search.html', language => $user->{language}, - format => 'html'); + my $template = LedgerSMB::Template->new( + user => $user, + path => 'UI/Customer' , + template => 'customer_search', + locale => $request->{_locale}, + format => 'HTML'); $template->render(); } @@ -151,8 +158,8 @@ sub save { my $result = $customer->save(); my $template = LedgerSMB::Template->new( user => $user, - template => 'Customer/customer.html', language => $user->{language}, - format => 'html'); + template => 'Customer/customer', language => $user->{language}, + format => 'HTML'); $template->render($result); } else { diff --git a/scripts/payment.pl b/scripts/payment.pl index 01e32fc7..b6dd87d4 100644 --- a/scripts/payment.pl +++ b/scripts/payment.pl @@ -157,8 +157,8 @@ my $template; $template = LedgerSMB::Template->new( user => $request->{_user}, locale => $request->{_locale}, -# path => 'UI/payments', - path => 'UI', + path => 'UI/payments', +# path => 'UI', template => 'payment1', format => 'HTML', ); $template->render($select);# And finally, Lets print the screen :) diff --git a/sql/Pg-database.sql b/sql/Pg-database.sql index 67dc0a5a..9737b474 100644 --- a/sql/Pg-database.sql +++ b/sql/Pg-database.sql @@ -130,7 +130,6 @@ SELECT SETVAL('location_class_id_seq',4); CREATE TABLE location ( id serial PRIMARY KEY, - location_class integer not null references location_class(id), line_one text check (line_one ~ '[[:alnum:]_]') NOT NULL, line_two text, line_three text, @@ -156,6 +155,7 @@ COMMENT ON COLUMN company.tax_id IS $$ In the US this would be a EIN. $$; CREATE TABLE company_to_location ( location_id integer references location(id) not null, + location_class integer not null references location_class(id), company_id integer not null references company(id) ON DELETE CASCADE, PRIMARY KEY(location_id,company_id)); @@ -201,6 +201,7 @@ create table entity_employee ( CREATE TABLE person_to_location ( location_id integer not null references location(id), + location_class integer not null references location_class(id), person_id integer not null references person(id) ON DELETE CASCADE, PRIMARY KEY (location_id,person_id)); diff --git a/sql/modules/Location.sql b/sql/modules/Location.sql index fb93cf82..d4f8f9f5 100644 --- a/sql/modules/Location.sql +++ b/sql/modules/Location.sql @@ -1,6 +1,6 @@ -- VERSION 1.3.0 CREATE OR REPLACE FUNCTION location_save -(in_companyname text, in_address1 text, in_address2 text, +(in_address1 text, in_address2 text, in_address3 text, in_city text, in_state text, in_zipcode text, in_country text) returns integer AS $$ @@ -10,9 +10,9 @@ DECLARE BEGIN SELECT * INTO location_row FROM location - WHERE companyname = in_companyname AND - address1 = in_address1 AND - address2 = in_address2 AND + WHERE line_one = in_address1 AND + line_two = in_address2 AND + line_three = in_address3 AND city = in_city AND state = in_state AND zipcode = in_zipcode AND diff --git a/sql/modules/Roles.sql b/sql/modules/Roles.sql index a44ebcf4..864fb4e7 100644 --- a/sql/modules/Roles.sql +++ b/sql/modules/Roles.sql @@ -1376,3 +1376,4 @@ GRANT SELECT ON user_preference TO public; GRANT SELECT ON custom_table_catalog TO PUBLIC; GRANT SELECT ON custom_field_catalog TO PUBLIC; grant select on menu_node, menu_attribute, menu_acl to public; +GRANT select on chart, gifi to public; diff --git a/sql/modules/Vendor.sql b/sql/modules/Vendor.sql index d075b62e..e18f88a5 100644 --- a/sql/modules/Vendor.sql +++ b/sql/modules/Vendor.sql @@ -170,9 +170,9 @@ $$ language 'plpgsql'; create or replace function _entity_location_save( - in_company_id int, - in_location_class int, in_line_one text, in_line_two text, - in_city_province TEXT, in_mail_code text, in_country_code int, + in_company_id int, in_location_id int, + in_location_class int, in_line_one text, in_line_two text, + in_city TEXT, in_state TEXT, in_mail_code text, in_country_code int, in_created date ) returns int AS $$ @@ -180,46 +180,20 @@ create or replace function _entity_location_save( l_row location; l_id INT; BEGIN - - SELECT l.* INTO l_row FROM location l - JOIN company_to_location ctl ON ctl.location_id = l.id - JOIN company c on ctl.company_id = c.id - where c.id = in_company_id; - - IF NOT FOUND THEN - - l_id := nextval('location_id_seq'); - - INSERT INTO location (id, location_class, line_one, line_two, - city_province, country_id, mail_code, created) - VALUES ( - l_id, - in_location_class, - in_line_one, - in_line_two, - in_city_province, - in_country_code, - in_mail_code, - in_created - ); - - INSERT INTO company_to_location (location_id, company_id) - VALUES (l_id, in_company_id); - - ELSIF FOUND THEN - - l_id := l.id; - update location SET - location_class = in_location_class, - line_one = in_line_one, - line_two = in_line_two, - city_province = in_city_province, - country_id = in_country_code, - mail_code = in_mail_code - WHERE id = l_id; - - END IF; - return l_id; + DELETE FROM company_to_location + WHERE company_id = in_company_id + AND location_class = in_location_class + AND location_id = in_location_id; + + SELECT location_save(in_line_one, in_line_two, NULL, in_city, + in_state, in_mail_code, in_mail_code, in_country_code) + INTO l_id; + + INSERT INTO company_to_location + (company_id, location_class, location_id) + VALUES (in_company_id, in_location_class, l_id); + + RETURN l_id; END; $$ language 'plpgsql'; -- cgit v1.2.3