diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-11-21 05:42:22 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-11-21 05:42:22 +0000 |
commit | eb7e5f65f488f890c1d9fb6d56bed8a40fe8a595 (patch) | |
tree | ca581deabbbae5cc59c7df22b9ed77c095e8fccb | |
parent | ff6f935be468458483306b06a827ccc82564c496 (diff) |
More Customer Fixes
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1885 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r-- | LedgerSMB/DBObject/Customer.pm | 36 | ||||
-rw-r--r-- | UI/Customer/customer.html | 7 | ||||
-rw-r--r-- | scripts/customer.pl | 22 | ||||
-rw-r--r-- | sql/modules/Customer.sql | 120 | ||||
-rw-r--r-- | sql/modules/Location.sql | 8 | ||||
-rw-r--r-- | sql/modules/Roles.sql | 3 | ||||
-rw-r--r-- | sql/modules/Vendor.sql | 2 |
7 files changed, 181 insertions, 17 deletions
diff --git a/LedgerSMB/DBObject/Customer.pm b/LedgerSMB/DBObject/Customer.pm index aa4404ce..7cd550dc 100644 --- a/LedgerSMB/DBObject/Customer.pm +++ b/LedgerSMB/DBObject/Customer.pm @@ -4,11 +4,13 @@ use base qw(LedgerSMB::DBObject); 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 @@ sub get_metadata { $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 { diff --git a/UI/Customer/customer.html b/UI/Customer/customer.html index 4bd9ae8d..ef0b79e1 100644 --- a/UI/Customer/customer.html +++ b/UI/Customer/customer.html @@ -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> diff --git a/scripts/customer.pl b/scripts/customer.pl index 27e3d4d0..bef642ec 100644 --- a/scripts/customer.pl +++ b/scripts/customer.pl @@ -56,6 +56,28 @@ sub get { } + +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 diff --git a/sql/modules/Customer.sql b/sql/modules/Customer.sql index 7f2a8da0..40625cbf 100644 --- a/sql/modules/Customer.sql +++ b/sql/modules/Customer.sql @@ -23,19 +23,33 @@ CREATE TYPE customer_search_return AS ( 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 @@ CREATE OR REPLACE FUNCTION entity_credit_save ( $$ 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 @@ CREATE OR REPLACE FUNCTION customer_location_save ( ) 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; diff --git a/sql/modules/Location.sql b/sql/modules/Location.sql index 51fb1d02..3986c24f 100644 --- a/sql/modules/Location.sql +++ b/sql/modules/Location.sql @@ -28,7 +28,7 @@ $$ language plpgsql; 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 @@ BEGIN 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; diff --git a/sql/modules/Roles.sql b/sql/modules/Roles.sql index 864fb4e7..cce8ca0d 100644 --- a/sql/modules/Roles.sql +++ b/sql/modules/Roles.sql @@ -23,6 +23,7 @@ GRANT SELECT ON person_to_contact TO lsmb_<?lsmb dbname ?>__read_contact; 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_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) diff --git a/sql/modules/Vendor.sql b/sql/modules/Vendor.sql index d2f6c3c3..8e9e12a9 100644 --- a/sql/modules/Vendor.sql +++ b/sql/modules/Vendor.sql @@ -186,7 +186,7 @@ create or replace function _entity_location_save( 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 |