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

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



Revision: 4487
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4487&view=rev
Author:   einhverfr
Date:     2012-03-16 11:56:39 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
Company info now loads from new Moose-based classes

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Company.pm
    trunk/LedgerSMB/DBObject/Entity/Company.pm
    trunk/LedgerSMB/DBObject_Moose.pm
    trunk/LedgerSMB/ScriptLib/Company.pm
    trunk/UI/Contact/contact.html
    trunk/sql/modules/Company.sql

Modified: trunk/LedgerSMB/DBObject/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Company.pm	2012-03-16 11:14:36 UTC (rev 4486)
+++ trunk/LedgerSMB/DBObject/Company.pm	2012-03-16 11:56:39 UTC (rev 4487)
@@ -522,105 +522,6 @@
     }
 }
 
-=item get
-
-Retrieves a company record and all info.
-
-taxform_list is set to a list of tax forms for the entity's country
-credit_list is set to a list of credit accounts
-locations is set to a list of locations
-contacts to a list of contacts
-notes to a list of notes
-bank_account to a list of bank accounts
-
-=cut
-
-sub get {
-    my $self = shift @_;
-
-    $self->set_entity_class();
-
-    if($self->{entity_id})
-    {
-        @{$self->{taxform_list}} = $self->exec_method(funcname => 'list_taxforms');
-    }
-
-    my ($ref) = $self->exec_method(funcname => 'company_retrieve');
-    $self->merge($ref);
-    $self->{threshold} = $self->format_amount(amount => $self->{threshold});
-
-    @{$self->{credit_list}} = 
-         $self->exec_method(funcname => 'entity__list_credit');
-    $self->{eca_tax} = [];
-    for (@{$self->{credit_list}}){
-	if (($_->{credit_id} eq $self->{credit_id}) 
-                   or ($_->{meta_number} eq $self->{meta_number})
-                   or ($_->{id} eq $self->{credit_id})){
-            $self->merge($_);
-            if ($_->{entity_class} == 1 || $_->{entity_class} == 2){
-                my @taxes = $self->exec_method(funcname => 'eca__get_taxes');
-                
-                for my $tax (@taxes){
-                    push @{$self->{eca_tax}}, $tax->{chart_id};
-                }
-            }
-            last;
-        }
-    }
-    $self->{name} = $self->{legal_name};
-    if ($self->{credit_id} and $self->{meta_number}){
-        $self->get_credit_id;
-    }
-
-    if ($self->{credit_id}){
-        @{$self->{locations}} = $self->exec_method(
-		funcname => 'eca__list_locations');
-        @{$self->{contacts}} = $self->exec_method(
-		funcname => 'eca__list_contacts');
-        @{$self->{notes}} = $self->exec_method(
-		funcname => 'eca__list_notes');
-        
-    }
-    else {
-        @{$self->{locations}} = $self->exec_method(
-		funcname => 'company__list_locations');
-        @{$self->{contacts}} = $self->exec_method(
-		funcname => 'company__list_contacts');
-        @{$self->{notes}} = $self->exec_method(
-		funcname => 'company__list_notes');
-
-    }
-
-    if ($self->{location_id}){
-        for (@{$self->{locations}}){
-            if ($_->{id} == $self->{location_id}){
-                my $old_id = $self->{id};
-                $self->merge($_);
-                for my $c (@{$self->{country_list}}){
-                     if ($c->{name} eq $self->{country}){
-                         $self->{country_code} = $c->{id};
-                     }
-                }
-                last;
-            }
-        }
-    }
-
-    if ($self->{contact_id}){
-        for (@{$self->{contacts}}){
-            if ($_->{id} = $self->{contact_id}){
-                my $old_id = $self->{id};
-                $self->merge($_);
-                $self->{id} = $old_id;
-                last;
-            }
-        }
-    }
-
-    @{$self->{bank_account}} = $self->exec_method(
-		funcname => 'company__list_bank_account');
-};
-
 =item get_pricematrix
 
 This routine gets the price matrix for the customer or vendor.  The pricematrix

Modified: trunk/LedgerSMB/DBObject/Entity/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Company.pm	2012-03-16 11:14:36 UTC (rev 4486)
+++ trunk/LedgerSMB/DBObject/Entity/Company.pm	2012-03-16 11:56:39 UTC (rev 4487)
@@ -87,7 +87,8 @@
 
 sub get {
     my ($self, $id) = @_;
-    my ($ref) = $self->exec_method({funcname => 'company__get'});
+    my ($ref) = $self->call_procedure(procname => 'company__get',
+                                          args => [$id]);
     $self->prepare_dbhash($ref);
     return $self->new(%$ref);
 }

Modified: trunk/LedgerSMB/DBObject_Moose.pm
===================================================================
--- trunk/LedgerSMB/DBObject_Moose.pm	2012-03-16 11:14:36 UTC (rev 4486)
+++ trunk/LedgerSMB/DBObject_Moose.pm	2012-03-16 11:56:39 UTC (rev 4487)
@@ -145,7 +145,7 @@
         $self->{call_args} = ..hidden..;
         $logger->debug("exec_method: \$self = " . Data::Dumper::Dumper($self));
         for my $arg(@call_args){
-            if (eval {$arg->can('to_db')}){
+            if (defined $arg && eval {$arg->can('to_db')}){
                $arg = $arg->to_db;
             }
         }

Modified: trunk/LedgerSMB/ScriptLib/Company.pm
===================================================================
--- trunk/LedgerSMB/ScriptLib/Company.pm	2012-03-16 11:14:36 UTC (rev 4486)
+++ trunk/LedgerSMB/ScriptLib/Company.pm	2012-03-16 11:56:39 UTC (rev 4487)
@@ -61,7 +61,8 @@
    my ($request) = @_;
    my $company = new_company($request);
    $company->get_by_cc();   
-   _render_main_screen($company);
+   $request->{company} = $company;
+   _render_main_screen($request);
 }
 
 =item dispatch_legacy
@@ -221,11 +222,11 @@
 sub get {
     
     my ($request) = @_;
-    my $company = new_company($request);
-    $company->get();
-    $company->get_credit_id();
-#    $company->get_metadata(); It will be called from _render_main_screen
-    _render_main_screen($company);
+    $request->{legal_name} ||= 'test';
+    my $company = LedgerSMB::DBObject::Entity::Company->new(%$request);
+    $company = $company->get($request->{entity_id});
+    $request->{company} = $company;
+    _render_main_screen($request);
 }
 
 =pod

Modified: trunk/UI/Contact/contact.html
===================================================================
--- trunk/UI/Contact/contact.html	2012-03-16 11:14:36 UTC (rev 4486)
+++ trunk/UI/Contact/contact.html	2012-03-16 11:56:39 UTC (rev 4487)
@@ -274,7 +274,7 @@
 	<?lsmb PROCESS input element_data = {
 		type = "hidden"
 		name = "id"
-		value = id
+		value = company.id
 	} ?>	
 <?lsmb PROCESS input element_data = {
 		type = "hidden"
@@ -292,7 +292,7 @@
 		label = text('Control Code') #'
 		type= "text"
 		name = "control_code"
-		value = control_code
+		value = company.control_code
 		size = "20"
 	} ?>
 	<?lsmb IF !created_as_class;
@@ -300,10 +300,14 @@
 	END; # IF !created_as_class ?> 
 </div>
 <div class="input_group2">
-	<?lsmb PROCESS select element_data = {
+        <?lsmb company_entity_class = company.entity_class;
+        IF !company_entity_class;
+              company_entity_class = entity_class;
+        END;
+        PROCESS select element_data = {
 		name = "created_as_class"
 		options = entity_classes
-		default_values = [created_as_class]
+		default_values = [company_entity_class]
 		text_attr = 'class'
 		value_attr = 'id'
 		label = text('Class')
@@ -329,17 +333,21 @@
 	<?lsmb PROCESS input element_data = {
 		label = text('Name')
 		type= "text"
-		name = "name"
-		value = name
+		name = "legal_name"
+		value = company.legal_name
 		size = "20"
 	} ?>
 </div>
 <div class="input_group2">
-       <?lsmb country_list.unshift({}) ?>
-		<?lsmb INCLUDE select element_data = {
+       <?lsmb country_list.unshift({});
+                company_country_id = company.country_id;
+                IF !company_country_id; 
+                          company_country_id = default_country_id;
+                END;
+		INCLUDE select element_data = {
 			text_attr = "name"
 			value_attr = "id"
-			default_values = [country_id]
+			default_values = [company_country_id]
 			options = country_list
 			name = "country_id"
 			label = text('Country') 
@@ -351,7 +359,7 @@
 		<?lsmb INCLUDE input element_data = {
 			label = text('Tax Number/SSN'),
 			name = "tax_id",
-			value = tax_id,
+			value = company.tax_id,
 			type = "text",
 			size = "19"
 		} #' ?>
@@ -360,7 +368,7 @@
 		<?lsmb INCLUDE input element_data = {
 			label = text('SIC'),
 			name = "sic_code",
-			value = sic_code,
+			value = company.sic_code,
 			type = "text",
 			size = "19",
 			class = 'sic'
@@ -375,7 +383,7 @@
           type = 'text'
          class = 'taxnumber'
           size = '19'
-         value = sales_tax_id
+         value = company.sales_tax_id
      } ?>
 </div>
 <div class="input_group2">
@@ -385,7 +393,7 @@
           type = 'text'
          class = 'taxnumber'
           size = '19'
-         value = license_number
+         value = company.license_number
      } ?>
 </div>
 </div>

Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql	2012-03-16 11:14:36 UTC (rev 4486)
+++ trunk/sql/modules/Company.sql	2012-03-16 11:56:39 UTC (rev 4487)
@@ -6,6 +6,19 @@
 
 BEGIN;
 
+DROP TYPE IF EXISTS company_entity CASCADE;
+
+CREATE TYPE company_entity AS(
+  entity_id int,
+  legal_name text,
+  tax_id text,
+  sales_tax_id text,
+  license_number text,
+  sic_code varchar,
+  control_code text,
+  country_id int
+);
+
 DROP TYPE IF EXISTS eca__pricematrix CASCADE;
 
 CREATE TYPE eca__pricematrix AS (
@@ -543,16 +556,16 @@
 IS $$ Returns a list of entity credit account entries for the entity and of the
 entity class.$$;
 
-CREATE OR REPLACE FUNCTION company_retrieve (in_entity_id int) RETURNS company AS
+CREATE OR REPLACE FUNCTION company__get (in_entity_id int) RETURNS company_entity AS
 $$
-DECLARE t_company company;
-BEGIN
-	SELECT * INTO t_company FROM company WHERE entity_id = in_entity_id;
-	RETURN t_company;
-END;
-$$ language plpgsql;
+	SELECT c.entity_id, c.legal_name, c.tax_id, c.sales_tax_id,
+               c.license_number, c.sic_code, e.control_code, e.country_id 
+          FROM company c
+          JOIN entity e ON e.id = c.entity_id
+         WHERE entity_id = $1;
+$$ language sql;
 
-COMMENT ON FUNCTION company_retrieve (in_entity_id int) IS
+COMMENT ON FUNCTION company__get (in_entity_id int) IS
 $$ Returns all attributes for the company attached to the entity.$$;
 
 CREATE OR REPLACE FUNCTION entity__get_by_cc (in_control_code text)

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