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

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



Revision: 4767
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4767&view=rev
Author:   einhverfr
Date:     2012-05-24 03:53:22 +0000 (Thu, 24 May 2012)
Log Message:
-----------
Contact info handling moved from 1.3 codebase to something more modular

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Company.pm
    trunk/LedgerSMB/DBObject/Employee.pm
    trunk/LedgerSMB/DBObject/Entity/Location.pm
    trunk/LedgerSMB/ScriptLib/Company.pm
    trunk/UI/Contact/divs/contact_info.html
    trunk/sql/Pg-database.sql
    trunk/sql/modules/Company.sql

Modified: trunk/LedgerSMB/DBObject/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Company.pm	2012-05-24 01:05:20 UTC (rev 4766)
+++ trunk/LedgerSMB/DBObject/Company.pm	2012-05-24 03:53:22 UTC (rev 4767)
@@ -48,43 +48,6 @@
 
 =over 
 
-=item delete_contact
-
-required request variables:
-
-contact_class_id:  int id of contact class
-contact: text of contact information
-
-Must include at least one of:
-
-credit_id: int of entity_credit_account.id, preferred value
-company_id:  int of company.id, only used if credit_id not set.
-
-returns true of a record was deleted.
-
-=back
-
-=cut
-
-sub delete_contact {
-    my ($self) = @_;
-    my $rv;
-    if ($self->{credit_id}){
-        ($rv) = $self->exec_method(funcname => 'eca__delete_contact');
-    } elsif ($self->{company_id}){
-        ($rv) = $self->exec_method(funcname => 'company__delete_contact');
-    } else {
-       $self->error($self->{_locale}->text(
-          'No company or credit id in LedgerSMB::DBObject::delete_contact'
-       ));
-    }
-    $self->{dbh}->commit;
-    return $rv;
-}
-
-
-=over 
-
 =item delete_bank_account
 
 Deletes a bank account
@@ -232,8 +195,6 @@
         $curr = { text => $curr };
     }
 
-    @{$self->{contact_class_list}} = 
-         $self->exec_method(funcname => 'entity_list_contact_class');
     #HV was $country_setting , given it a more general name, not only for country
     my $setting_module = LedgerSMB::Setting->new({base => $self, copy => 'base'});
     $setting_module->{key} = 'default_country';
@@ -244,31 +205,6 @@
     $self->{default_language} = $setting_module->{value};
 }
 
-=item save_contact
-
-Saves a contact.  Requires credit_id, contact_class, description, and contact to 
-be set.
-
-Requires the following be set:
-credit_id or entity_id
-contact_class
-description
-contact
-old_contact
-old_contact_class
-
-=cut
-
-sub save_contact {
-    my ($self) = @_;
-    if ($self->{credit_id}){
-        $self->exec_method(funcname => 'eca__save_contact');
-    } else {
-        $self->exec_method(funcname => 'company__save_contact');
-    }
-    $self->{dbh}->commit;
-}
-
 =item save_bank_account
 
 Saves a bank account.  Requires the following be set:

Modified: trunk/LedgerSMB/DBObject/Employee.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Employee.pm	2012-05-24 01:05:20 UTC (rev 4766)
+++ trunk/LedgerSMB/DBObject/Employee.pm	2012-05-24 03:53:22 UTC (rev 4767)
@@ -203,7 +203,7 @@
          $self->exec_method(funcname => 'location_list_country');
 
     @{$self->{contact_class_list}} = 
-         $self->exec_method(funcname => 'entity_list_contact_class');
+         $self->exec_method(funcname => 'contact_class__list');
     my $country_setting = LedgerSMB::Setting->new({base => $self, copy => 'base'});
     $country_setting->{key} = 'default_country';
     $country_setting->get;

Modified: trunk/LedgerSMB/DBObject/Entity/Location.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Location.pm	2012-05-24 01:05:20 UTC (rev 4766)
+++ trunk/LedgerSMB/DBObject/Entity/Location.pm	2012-05-24 03:53:22 UTC (rev 4767)
@@ -258,4 +258,6 @@
 
 =cut
 
+__PACKAGE__->meta->make_immutable;
+
 return 1;

Modified: trunk/LedgerSMB/ScriptLib/Company.pm
===================================================================
--- trunk/LedgerSMB/ScriptLib/Company.pm	2012-05-24 01:05:20 UTC (rev 4766)
+++ trunk/LedgerSMB/ScriptLib/Company.pm	2012-05-24 03:53:22 UTC (rev 4767)
@@ -4,6 +4,7 @@
 use LedgerSMB::DBObject::Entity::Company;
 use LedgerSMB::DBObject::Entity::Credit_Account;
 use LedgerSMB::DBObject::Entity::Location;
+use LedgerSMB::DBObject::Entity::Contact;
 use LedgerSMB::DBObject::Vendor;
 use Log::Log4perl;
 
@@ -761,7 +762,14 @@
     for my $ref (@{$request->{credit_list}}){
         $company->{credit_act} = $ref; 
     }
-    my $err =  $company->{credit_act}->{id};
+    @{$company->{contacts}} = 
+          LedgerSMB::DBObject::Entity::Contact->list(
+              {entity_id => $company->{entity_id},
+                        credit_id => $company->{credit_act}->{id}},
+              $request
+          );
+    @{$company->{contact_class_list}} = 
+          LedgerSMB::DBObject::Entity::Contact->list_classes;
     @{$company->{locations}} = 
           LedgerSMB::DBObject::Entity::Location->get_active(
                        $request,
@@ -834,12 +842,11 @@
 
 sub save_contact {
    my ($request) = @_;
-    my $company = new_company($request);
-    if (_close_form($company)){
-        $company->save_contact();
-    }
-    $company->get;
-    _render_main_screen( $company );
+   my $contact = LedgerSMB::DBObject::Entity::Contact->new(%$request);   
+   if (_close_form($request)){
+       $contact->save();
+   }
+   get( $request );
 }
 
 =pod

Modified: trunk/UI/Contact/divs/contact_info.html
===================================================================
--- trunk/UI/Contact/divs/contact_info.html	2012-05-24 01:05:20 UTC (rev 4766)
+++ trunk/UI/Contact/divs/contact_info.html	2012-05-24 03:53:22 UTC (rev 4767)
@@ -1,42 +1,33 @@
 <div class="container" id="contact_div">
-	<div class="listtop"><?lsmb text('Contact Information') ?></div>
-	<table width="100%">
-	<tr class="listheading">
-		<th class="contact_class"><?lsmb text('Type') ?></th>
-		<th class="description"><?lsmb text('Description') ?></th>
-		<th class="contact"><?lsmb text('Contact Info') ?></th>
-		<th class="contact_actions"><?lsmb text('Actions') ?></th>
-	</tr>
-	<?lsmb FOREACH ct = contacts ?>
-	<tr>
-		<td class="contact_class"><?lsmb ct.class ?></td>
-		<td class="description"><?lsmb ct.description ?></td>
-		<td class="contact"><?lsmb ct.contact ?></td>
-		<td class="contact_actions">
-			<a href="<?lsmb tt_url(script) 
-				?>?entity_id=<?lsmb tt_url(entity_id)
-				?>&contact=<?lsmb tt_url(ct.contact)
-				?>&contact_class=<?lsmb tt_url(ct.class_id)
-				?>&description=<?lsmb tt_url(ct.description)
-				?>&action=edit&credit_id=<?lsmb 
-				tt_url(credit_id) 
-                                ?>&person_id=<?lsmb tt_url(person_id)
-                                ?>&target_div=contact_div"
-			>[<?lsmb text('Edit'); ?>]</a>&nbsp;&nbsp;
-			<a href="<?lsmb tt_url(script) 
-				?>?entity_id=<?lsmb tt_url(entity_id) 
-				?>&contact_class_id=<?lsmb 
-                                tt_url(ct.class_id)
-				?>&action=delete_contact&credit_id=<?lsmb 
-				tt_url(credit_id) ?>&form_id=<?lsmb form_id 
-                                ?>&contact=<?lsmb tt_url(ct.contact)
-                                ?>&person_id=<?lsmb tt_url(person_id)
-                                ?>&target_div=contact_div"
-			>[<?lsmb text('Delete'); ?>]</a>
-		</td>
-	</tr>
-	<?lsmb END ?>
-	</table>
+<div class="listtop"><?lsmb text('Contact Information') ?></div>
+<?lsmb 
+
+FOREACH row IN contacts;
+    row.edit = '[' _ text('Edit') _ ']';
+    row.delete = '[' _ text('Delete') _ ']';
+    row.edit_href_suffix = 
+               tt_url(script) _ '?entity_id=' _ entity_id _ '&contact=' _
+               tt_url(row.contact) _ '&contact_class=' _ row.contact _
+               '&contact_class=' _ row.class_id _ '&description=' _
+               tt_url(row.description) _ '&credit_id=' _ credit_id _
+               '&action=edit&target_div=contact_div';
+    row.delete_href_suffix = 
+               tt_url(script) _ '?entity_id=' _ entity_id _ '&contact=' _
+               tt_url(row.contact) _ '&contact_class=' _ row.contact _
+               '&contact_class=' _ row.class_id _ '&description=' _
+               tt_url(row.description) _ '&credit_id=' _ credit_id _
+               '&action=delete_contact&target_div=contact_div';
+END;
+PROCESS dynatable 
+        attributes = {id = 'contact-list' }
+        tbody = {rows = contacts}
+        columns = [
+         {col_id='class_name', type='text' name=text('Type') },
+         {col_id='description', type='text', name=text('Description') },
+         {col_id='contact', type='text', name=text('Contact Info') } #'
+         {col_id='edit', type='href', href_base='', name='' }
+         {col_id='delete', type='href', href_base='', name='' }
+        ] ?>
 	<form action="<?lsmb script ?>">
 <?lsmb PROCESS input element_data = {
 		type = "hidden"
@@ -75,7 +66,7 @@
 	} ?>
 	<div>
 		<?lsmb PROCESS select element_data = {
-			name = "contact_class"
+			name = "class_id"
 			label = "Type"
 			text_attr = "class"
 			value_attr = "id"

Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql	2012-05-24 01:05:20 UTC (rev 4766)
+++ trunk/sql/Pg-database.sql	2012-05-24 03:53:22 UTC (rev 4767)
@@ -776,7 +776,7 @@
 SELECT SETVAL('contact_class_id_seq',17);
 
 CREATE TABLE entity_to_contact (
-  entity_id integer not null references person(entity_id) ON DELETE CASCADE,
+  entity_id integer not null references entity(id) ON DELETE CASCADE,
   contact_class_id integer references contact_class(id) not null,
   contact text check(contact ~ '[[:alnum:]_]') not null,
   description text,

Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql	2012-05-24 01:05:20 UTC (rev 4766)
+++ trunk/sql/modules/Company.sql	2012-05-24 03:53:22 UTC (rev 4767)
@@ -429,7 +429,7 @@
 COMMENT ON FUNCTION entity_credit__get(in_id int) IS
 $$ Returns the entity credit account info.$$;
 
-CREATE OR REPLACE FUNCTION entity_list_contact_class() 
+CREATE OR REPLACE FUNCTION contact_class__list() 
 RETURNS SETOF contact_class AS
 $$
 DECLARE out_row RECORD;
@@ -442,7 +442,7 @@
 END;
 $$ language plpgsql;
 
-COMMENT ON FUNCTION entity_list_contact_class() IS
+COMMENT ON FUNCTION contact_class__list() IS
 $$ Returns a list of contact classes ordered by ID.$$;
 
 DROP TYPE IF EXISTS entity_credit_search_return CASCADE;
@@ -917,7 +917,7 @@
 	contact text
 );
 
-CREATE OR REPLACE FUNCTION company__list_contacts(in_entity_id int) 
+CREATE OR REPLACE FUNCTION entity__list_contacts(in_entity_id int) 
 RETURNS SETOF contact_list AS $$
 DECLARE out_row contact_list;
 BEGIN
@@ -932,7 +932,7 @@
 END;
 $$ language plpgsql;
 
-COMMENT ON FUNCTION company__list_contacts(in_entity_id int) IS
+COMMENT ON FUNCTION entity__list_contacts(in_entity_id int) IS
 $$ Lists all contact info for the entity.$$;
 
 CREATE OR REPLACE FUNCTION company__list_bank_account(in_entity_id int)
@@ -1051,22 +1051,28 @@
 $$ Returns true if at least one record was deleted.  False if no records were
 affected.$$;
 
-CREATE OR REPLACE FUNCTION company__save_contact
-(in_entity_id int, in_contact_class int, in_description text, in_contact text)
+CREATE OR REPLACE FUNCTION entity__save_contact
+(in_entity_id int, in_class_id int, in_description text, in_contact text,
+ in_old_contact text, in_old_class_id int)
 RETURNS INT AS
 $$
 DECLARE out_id int;
 BEGIN
+        DELETE FROM entity_to_contact 
+         WHERE entity_id = in_entity_id AND contact = in_old_contact 
+               AND contact_class_id = in_old_class_id;
+
 	INSERT INTO entity_to_contact 
                (entity_id, contact_class_id, description, contact)
-	VALUES (entity_id, in_contact_class, in_description, in_contact);
+	VALUES (in_entity_id, in_class_id, in_description, in_contact);
 
 	RETURN 1;
 END;
 $$ LANGUAGE PLPGSQL;
 
-COMMENT ON FUNCTION company__save_contact
-(in_entity_id int, in_contact_class int, in_description text, in_contact text) IS
+COMMENT ON FUNCTION entity__save_contact
+(in_entity_id int, in_contact_class int, in_description text, in_contact text,
+in_old_contact text, in_old_class_id int) IS
 $$ Saves company contact information.  The return value is meaningless. $$;
 
 DROP TYPE IF EXISTS entity_note_list CASCADE;

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