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

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



Revision: 4488
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4488&view=rev
Author:   einhverfr
Date:     2012-03-16 14:02:19 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
Basic company/credit account stuff now works on new Moose-based classes

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Company.pm
    trunk/LedgerSMB/DBObject/Entity/Company.pm
    trunk/LedgerSMB/DBObject/Entity/Credit_Account.pm
    trunk/LedgerSMB/DBObject_Moose.pm
    trunk/LedgerSMB/ScriptLib/Company.pm
    trunk/LedgerSMB.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:56:39 UTC (rev 4487)
+++ trunk/LedgerSMB/DBObject/Company.pm	2012-03-16 14:02:19 UTC (rev 4488)
@@ -46,30 +46,6 @@
     }
 }
 
-=over
-
-=item get_by_cc
-
-This retrieves the company header information by control code.  Leaves the 
-overall account class untouched.
-
-=back
-
-=cut
-
-sub get_by_cc {
-    my $self = shift @_;
-    my $entity_class = $self->{entity_class};
-    my ($ref) = $self->exec_method({funcname => 'entity__get_by_cc'});
-    $self->merge($ref);
-    $self->{entity_id} = $self->{id};
-    delete $self->{id};
-    $self->get;
-    $self->get_metadata;
-    $self->{entity_class} = $entity_class;
-}
-
-
 =over 
 
 =item delete_contact
@@ -267,26 +243,6 @@
 
 =over
 
-=item get_credit_id 
-
-This method returns the current credit id from the screen.
-
-Requires entity_id, meta_number, and entity_class be set.
-
-=back
-
-=cut
-
-sub get_credit_id {
-    my $self = shift @_;
-    my ($ref) = $self->exec_method(
-           funcname => 'entity_credit_get_id'
-    );
-    $self->{credit_id} = $ref->{'entity_credit_get_id'};
-}
-
-=over
-
 =item get_metadata()
 
 This retrieves various information vor building the user interface.  Among other
@@ -485,10 +441,6 @@
 
 
 
-# I don't believe account() is used.  At any rate the stored proc called 
-# doesn't exist and therefore it can't work.  Therefore deleting the account() 
-# function. Not the same as the accounts() function which is used. --CT 
-
 =item accounts
 
 Returns all accounts, and sets these to $self->{accounts}.

Modified: trunk/LedgerSMB/DBObject/Entity/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Company.pm	2012-03-16 11:56:39 UTC (rev 4487)
+++ trunk/LedgerSMB/DBObject/Entity/Company.pm	2012-03-16 14:02:19 UTC (rev 4488)
@@ -25,6 +25,14 @@
 
 =over
 
+=item entity_id
+
+ID of entity attached.  This is also an interal reference to this company.
+
+=cut
+
+has 'entity_id' => (is => 'rw', isa => 'Maybe[Int]');
+
 =item legal_name
 
 Legal name of the company.  Will also map back to the entity's name field.
@@ -89,10 +97,32 @@
     my ($self, $id) = @_;
     my ($ref) = $self->call_procedure(procname => 'company__get',
                                           args => [$id]);
+    if (!$ref){
+        die $self->{_locale}->text('No company found.');
+    }
     $self->prepare_dbhash($ref);
     return $self->new(%$ref);
 }
 
+=item get_by_cc($cc)
+
+This retrieves a company associated with a control code.  Dies with error if 
+company does not exist.
+
+=cut
+
+sub get_by_cc {
+    my ($self, $cc) = @_;
+    my ($ref) = $self->call_procedure(procname => 'company__get_by_cc',
+                                          args => [$cc]);
+    if (!$ref){
+        die $self->{_locale}->text('No company found.');
+    }
+    $self->prepare_dbhash($ref);
+    return $self->new(%$ref);
+}
+
+
 =item save()
 
 Saves the item and populates db defaults in id and created.

Modified: trunk/LedgerSMB/DBObject/Entity/Credit_Account.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Credit_Account.pm	2012-03-16 11:56:39 UTC (rev 4487)
+++ trunk/LedgerSMB/DBObject/Entity/Credit_Account.pm	2012-03-16 14:02:19 UTC (rev 4488)
@@ -111,7 +111,7 @@
 
 =cut
 
-has 'creditlimit' => (is => 'rw', isa => 'Maybe[Num]');
+has 'creditlimit' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGNumber]');
 
 =item current_debt
 
@@ -121,7 +121,7 @@
 
 =cut
 
-has 'current_debt' => (is => 'rw', isa => 'Maybe[Num]');
+has 'current_debt' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGNumber]');
 
 =item terms
 
@@ -258,6 +258,32 @@
 
 =over
 
+=item prepare_input($hashref)
+
+Takes all PGNumber and PGDate inputs and constructs appropriate classes.
+
+=cut
+
+sub prepare_input {
+    my ($self, $request) = @_;
+
+    $request->{startdate} =
+       LedgerSMB::PGDate->from_input($request->{startdate}) 
+            if defined $request->{startdate};
+    $request->{enddate} =
+       LedgerSMB::PGDate->from_input($request->{enddate}) 
+            if defined $request->{enddate};
+    $request->{discount} = 
+       LedgerSMB::PGNumber->from_input($request->{discount})
+            if defined $request->{discount};
+    $request->{threshold} = 
+       LedgerSMB::PGNumber->from_input($request->{threshold})
+            if defined $request->{threshold};
+    $request->{creditlimit} = 
+       LedgerSMB::PGNumber->from_input($request->{creditlimit})
+            if defined $request->{creditlimit};
+}
+
 =item get_by_id($id int);
 
 Retrieves and returns the entity credit account corresponding with the id 

Modified: trunk/LedgerSMB/DBObject_Moose.pm
===================================================================
--- trunk/LedgerSMB/DBObject_Moose.pm	2012-03-16 11:56:39 UTC (rev 4487)
+++ trunk/LedgerSMB/DBObject_Moose.pm	2012-03-16 14:02:19 UTC (rev 4488)
@@ -364,7 +364,7 @@
 	for (0 .. $#names){
             #   numeric            float4/real
             if ($types[$_] == 3 or $types[$_] == 2) {
-                $ref->{$names[$_]} = Math::BigFloat->new($ref->{$names[$_]});
+                $ref->{$names[$_]} = LedgerSMB::PGNumber->from_db($ref->{$names[$_]});
             }
             #    DATE 
             elsif ($types[$_] == 91){

Modified: trunk/LedgerSMB/ScriptLib/Company.pm
===================================================================
--- trunk/LedgerSMB/ScriptLib/Company.pm	2012-03-16 11:56:39 UTC (rev 4487)
+++ trunk/LedgerSMB/ScriptLib/Company.pm	2012-03-16 14:02:19 UTC (rev 4488)
@@ -58,11 +58,13 @@
 =cut
 
 sub get_by_cc {
-   my ($request) = @_;
-   my $company = new_company($request);
-   $company->get_by_cc();   
-   $request->{company} = $company;
-   _render_main_screen($request);
+    my ($request) = @_;
+    $request->{legal_name} ||= 'test';
+    $request->{country_id} = 0;
+    my $company = LedgerSMB::DBObject::Entity::Company->new(%$request);
+    $company = $company->get_by_cc($request->{control_code});
+    $request->{company} = $company;
+    _render_main_screen($request);
 }
 
 =item dispatch_legacy
@@ -220,7 +222,6 @@
 =cut
 
 sub get {
-    
     my ($request) = @_;
     $request->{legal_name} ||= 'test';
     my $company = LedgerSMB::DBObject::Entity::Company->new(%$request);
@@ -681,10 +682,11 @@
         }  
     }
     if (_close_form($request)){
+        LedgerSMB::DBObject::Entity::Credit_Account->prepare_input($request);
         $credit = LedgerSMB::DBObject::Entity::Credit_Account->new(%$request);    
         $credit->save();
     }
-    _render_main_screen($request);
+    get($request);
 }
 
 =pod
@@ -742,10 +744,22 @@
 
 sub _render_main_screen{
     my ($request, $company) = @_;
+    delete $request->{creditlimit};
+    delete $request->{discount};
+    delete $request->{threshold};
+    delete $request->{startdate};
+    delete $request->{enddate};
+    my $credit = LedgerSMB::DBObject::Entity::Credit_Account->new(%$request);
     $request->close_form;
     $request->open_form;
     $request->{dbh}->commit;
-    set_entity_class($request);
+    if ($request->{company}){
+        my @credit_list = 
+           $credit->list_for_entity($request->{company}->entity_id);
+        $request->{credit_list} = ..hidden..;
+        $request->{entity_id} = $request->{company}->entity_id;
+    }
+    set_entity_class($request) unless $request->{entity_class};
     if (!$company){
         $company = new_company($request);
         $company->get_metadata();

Modified: trunk/LedgerSMB.pm
===================================================================
--- trunk/LedgerSMB.pm	2012-03-16 11:56:39 UTC (rev 4487)
+++ trunk/LedgerSMB.pm	2012-03-16 14:02:19 UTC (rev 4488)
@@ -710,7 +710,7 @@
 	for (0 .. $#names){
             #   numeric            float4/real
             if ($types[$_] == 3 or $types[$_] == 2) {
-                $ref->{$names[$_]} = Math::BigFloat->new($ref->{$names[$_]}, 'datetime') if defined $ref->{$names[$_]};
+                $ref->{$names[$_]} = LedgerSMB::PGNumber->from_db($ref->{$names[$_]}, 'datetime') if defined $ref->{$names[$_]};
             }
             #    DATE                TIMESTAMP
             if ($types[$_] == 91 or $types[$_] == 11){

Modified: trunk/UI/Contact/contact.html
===================================================================
--- trunk/UI/Contact/contact.html	2012-03-16 11:56:39 UTC (rev 4487)
+++ trunk/UI/Contact/contact.html	2012-03-16 14:02:19 UTC (rev 4488)
@@ -418,7 +418,7 @@
 </div>
 <?lsmb END ?>
 </div>
-<?lsmb IF entity_id ?>
+<?lsmb IF credit_list ?>
 <div id="credit_div" class="container">
 <div class="listtop"><strong>Accounts</strong></div>
     <table width="100%">
@@ -430,8 +430,9 @@
         <th class="start_date"><?lsmb text('Start Date') ?></th>
         <th class="end_date"><?lsmb text('End Date') ?></th>
     </tr>
-    <?lsmb FOREACH cl_item = credit_list ?>
-    <tr <?lsmb IF meta_number == cl_item.meta_number  ?> class="active"<?lsmb END ?>>
+    <?lsmb FOREACH cl_item IN credit_list ?>
+    <tr <?lsmb IF meta_number == cl_item.meta_number ;
+                   credit_act = cl_item;  ?> class="active"<?lsmb END ?>>
         <td><?lsmb IF cl_item.entity_class == 1 ?><?lsmb text('Vendor') ?>
             <?lsmb ELSIF cl_item.entity_class == 2 ?><?lsmb text('Customer') ?>
             <?lsmb END ?>
@@ -456,17 +457,17 @@
 	<?lsmb PROCESS input element_data = {
 		type = "hidden"
 		name = "entity_id"
-		value = entity_id
+		value = credit_act.entity_id
 	} ?>	
 	<?lsmb PROCESS input element_data = {
 		type = "hidden"
 		name = "credit_id"
-		value = credit_id
+		value = credit_act.id
 	} ?>	
 	<?lsmb PROCESS input element_data = {
 		type = "hidden"
 		name = "account_class"
-		value = account_class
+		value = credit_act.entity_class
 	} ?>	
         <table>
 	<tr class="eca_row">
@@ -475,14 +476,14 @@
 		label = text("$entity_classname Number"),
 		type= "text",
 		name = "meta_number",
-		value = meta_number,
+		value = credit_act.meta_number,
 		size = "10"
 	}  # " ?></td>
 	<td><?lsmb PROCESS input element_data = {
 		label = text("Description"),
 		type= "text",
 		name = "description",
-		value = description,
+		value = credit_act.description,
 		size = "20"
 	} ?></td>
 	</tr>
@@ -493,7 +494,7 @@
 		type = "text"
 		size = "50"
 		name = "pay_to_name"
-		value = pay_to_name
+		value = credit_act.pay_to_name
 		class = "name"
 	} ?>
 	</td>
@@ -504,7 +505,7 @@
 			label = text('Starting Date'),
 			name = "startdate",
 			class = "date",
-			value = startdate,
+			value = credit_act.startdate,
 			type = "text",
 			size = "12",
 			maxlength = "10"
@@ -515,7 +516,7 @@
 			label = text('End Date'),
 			name = "enddate",
 			class = "date",
-			value = enddate,
+			value = credit.enddate,
 			type = "text",
 			size = "12",
 			maxlength = "10"
@@ -527,7 +528,7 @@
 		<?lsmb INCLUDE input element_data = {
 			label = text('Credit Limit'),
 			name = "creditlimit",
-			value = creditlimit,
+			value = credit_act.creditlimit,
 			type = "text",
 			size = "20"
 		} #' ?>
@@ -536,7 +537,7 @@
 		<?lsmb INCLUDE input element_data = {
 			label = text('Terms'),
 			name = "terms",
-			value = terms,
+			value = credit_act.terms,
 			type = "text",
 			size = "5"
 		} ?> <?lsmb text('days') ?></span>
@@ -547,14 +548,14 @@
 		<?lsmb INCLUDE input element_data = {
 			label = text('Discount'),
 			name = "discount",
-			value = discount,
+			value = credit_act.discount,
 			type = "text",
 			size = "3",
 			maxlength = 3
 		} ?>% / 
 		<?lsmb INCLUDE input element_data = {
 			name = "discount_terms",
-			value = discount_terms,
+			value = credit_act.discount_terms,
 			type = "text",
 			size = "3",
 			maxlength = 3
@@ -564,7 +565,7 @@
 		<?lsmb INCLUDE input element_data = {
 			label = text('Subcontract GIFI'),
 			name = "gifi_accno",
-			value = gifi_accno,
+			value = credit_act.gifi_accno,
 			type = "text",
 			size = "19"
 		} #' ?>
@@ -573,7 +574,7 @@
         <tr id="account-link-row">
            <td> <?lsmb INCLUDE select element_data = {
 			name = "ar_ap_account_id"
-			default_values = [ar_ap_account_id]
+			default_values = [credit_act.ar_ap_account_id]
 			options = ar_ap_acc_list
 			label = text((account_class == 1) ? 'AP' : 'AR')
 			text_attr = "text"
@@ -582,7 +583,7 @@
            </td>
            <td> <?lsmb INCLUDE select element_data = {
 			name = "cash_account_id"
-			default_values = [cash_account_id]
+			default_values = [credit_act.cash_account_id]
 			options = cash_acc_list
 			label = text('Payment')
 			text_attr = "text"
@@ -591,7 +592,7 @@
            </td>
            <td> <?lsmb INCLUDE select element_data = {
                         name = "discount_account_id"
-                        default_values = [discount_account_id]
+                        default_values = [credit_act.discount_account_id]
                         options = discount_acc_list
                         label = text('Discount')
                         text_attr = "text"
@@ -604,7 +605,7 @@
                        INCLUDE select element_data = {
 			name = "business_id"
 			options = business_types
-			default_values = [business_id]
+			default_values = [credit_act.business_id]
 			text_attr = "description"
 			value_attr = "id"
 			label = text('Business Type') #'
@@ -612,7 +613,7 @@
 	  </td>
           <td> <?lsmb INCLUDE input element_data = {
 			name = "threshold"
-			value = threshold
+			value = credit_act.threshold
 			type = "text"
 			size = "20"
 			label = text('Threshold')
@@ -626,7 +627,7 @@
 	 <td> <?lsmb INCLUDE select element_data = {
 			name = "taxform_id"
 			options = taxform_list
-			default_values = [taxform_id]
+			default_values = [credit_act.taxform_id]
 			text_attr = "form_name"
 			value_attr = "id"
 			label = text('Taxforms') 
@@ -635,7 +636,7 @@
         <td> <?lsmb INCLUDE select element_data = {
 		label = text("Language")
 		name = "language_code"
-                default_values = [language_code],
+                default_values = [credit_act.language_code],
                 options = language_code_list
 		text_attr = "text"
 		value_attr = "code"
@@ -646,7 +647,7 @@
                         options = all_currencies
                         text_attr = 'text'
                         value_attr = 'text'
-                        default_values = [curr]
+                        default_values = [credit_act.curr]
                         label = text('Currency')
                } ?>
            </td>
@@ -673,7 +674,7 @@
                    } ?><span></div>
         <?lsmb END # FOR tx ?>
          </div>
-		<?lsmb IF credit_id;
+		<?lsmb IF credit_act.id;
 		INCLUDE button element_data = {
 			text = text('Save Changes'),
 			class="submit" 

Modified: trunk/sql/modules/Company.sql
===================================================================
--- trunk/sql/modules/Company.sql	2012-03-16 11:56:39 UTC (rev 4487)
+++ trunk/sql/modules/Company.sql	2012-03-16 14:02:19 UTC (rev 4488)
@@ -556,7 +556,8 @@
 IS $$ Returns a list of entity credit account entries for the entity and of the
 entity class.$$;
 
-CREATE OR REPLACE FUNCTION company__get (in_entity_id int) RETURNS company_entity AS
+CREATE OR REPLACE FUNCTION company__get (in_entity_id int) 
+RETURNS company_entity AS
 $$
 	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 
@@ -568,12 +569,18 @@
 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)
-RETURNS SETOF entity AS $$
-SELECT * FROM entity WHERE control_code = $1 $$ language sql;
+CREATE OR REPLACE FUNCTION company__get_by_cc (in_control_code text)
+RETURNS company_entity AS
+$$
+        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 e.control_code = $1;
+$$ language sql;
 
-COMMENT ON FUNCTION entity__get_by_cc (in_control_code text) IS
-$$ Returns the entity row attached to the control code. $$;
+COMMENT ON FUNCTION company__get_by_cc (in_control_code text) IS
+$$ Returns the entity/company row attached to the control code. $$;
 
 create or replace function save_taxform 
 (in_country_code int, in_taxform_name text)

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