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

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



Revision: 4823
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4823&view=rev
Author:   einhverfr
Date:     2012-06-03 08:25:16 +0000 (Sun, 03 Jun 2012)
Log Message:
-----------
It is now possible to save a natural person as customer or vendor.  Not all functionality working yet, needs further work

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Entity/Company.pm
    trunk/LedgerSMB/DBObject/Entity/Person.pm
    trunk/LedgerSMB/DBObject/Entity.pm
    trunk/LedgerSMB/Scripts/contact.pm
    trunk/UI/Contact/divs/person.html

Modified: trunk/LedgerSMB/DBObject/Entity/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Company.pm	2012-06-02 15:15:20 UTC (rev 4822)
+++ trunk/LedgerSMB/DBObject/Entity/Company.pm	2012-06-03 08:25:16 UTC (rev 4823)
@@ -98,7 +98,7 @@
     my ($ref) = $self->call_procedure(procname => 'company__get',
                                           args => [$id]);
     if (!$ref){
-        die $self->{_locale}->text('No company found.');
+        return undef;
     }
     $self->prepare_dbhash($ref);
     return $self->new(%$ref);
@@ -116,7 +116,7 @@
     my ($ref) = $self->call_procedure(procname => 'company__get_by_cc',
                                           args => [$cc]);
     if (!$ref){
-        die $self->{_locale}->text('No company found.');
+        return undef;
     }
     $self->prepare_dbhash($ref);
     return $self->new(%$ref);

Modified: trunk/LedgerSMB/DBObject/Entity/Person.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Person.pm	2012-06-02 15:15:20 UTC (rev 4822)
+++ trunk/LedgerSMB/DBObject/Entity/Person.pm	2012-06-03 08:25:16 UTC (rev 4823)
@@ -32,7 +32,6 @@
 extends 'LedgerSMB::DBObject::Entity';
 
 use LedgerSMB::App_State;
-
 my $locale = $LedgerSMB::App_State::Locale;
 
 =head1 PROPERTIES
@@ -148,10 +147,7 @@
 sub get_by_cc {
     my ($self, $cc) = @_;
     my ($ref) = $self->call_procedure(procname => 'person__get_by_cc',
-                                          args => [$cc]);
-    if (!$ref){
-        die $self->{_locale}->text('No person found.');
-    }
+                                          args => [$cc]) || return undef;
     $self->prepare_dbhash($ref);
     return $self->new(%$ref);
 }
@@ -166,11 +162,7 @@
 sub save {
     my ($self) = @_;
     my ($ref) = $self->exec_method({funcname => 'person__save'});
-    $self->prepare_dbhash($ref);
-    $ref->{control_code} = $self->{control_code};
-    $ref->{entity_class} = $self->{entity_class};
-    $ref->{country_id} = $self->{country_id};
-    $self = $self->new(%$ref);
+    $self->entity_id(values %$ref);
 }
 
 =back
@@ -183,6 +175,9 @@
 
 =cut
 
-__PACKAGE__->meta->make_immutable;
+# Not sure why but making the class immutable causes parent attributes to be 
+# lost.  Is this a bug in Class::MOP?
+#
+#__PACKAGE__->meta->make_immutable;
 
-return 1;
+1;

Modified: trunk/LedgerSMB/DBObject/Entity.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity.pm	2012-06-02 15:15:20 UTC (rev 4822)
+++ trunk/LedgerSMB/DBObject/Entity.pm	2012-06-03 08:25:16 UTC (rev 4823)
@@ -6,6 +6,9 @@
 
 package LedgerSMB::DBObject::Entity;
 use Moose;
+extends 'LedgerSMB::DBObject_Moose';
+use LedgerSMB::DBObject::Entity::Company;
+use LedgerSMB::DBObject::Entity::Person;
 
 =head1 SYNOPSYS
 
@@ -22,7 +25,6 @@
 
 =cut
 
-extends 'LedgerSMB::DBObject_Moose';
 
 =head1 PROPERTIES
 
@@ -63,7 +65,7 @@
 
 =cut
 
-has 'country_id' => (is => 'rw', isa => 'Int', required => '1');
+has 'country_id' => (is => 'rw', isa => 'Int');
 
 =item country_name
 
@@ -89,39 +91,28 @@
 
 =over
 
-=item get_locations
+=item get($id)
 
-Returns a list of locations for that entity
+This retrieves the entity or person by id
 
-=cut
+Please note, that the return value will always be either undef (not found), or
+an object of type of either LedgerSMB::DBObject::Entity::Company or
+LedgerSMB::DBObject::Entity::Person
 
-sub get_locations {
-    my ($self) = @_;
-    return $self->exec_method({funcname => 'entity__list_locations'}, add_dbo=> 1);
-}
-
-=item get_contacts
-
-Returns a list of contacts tied to the entity.
-
 =cut
 
-sub get_contacts{
-    my ($self) = @_;
-    return $self->exec_method({funcname => 'entity__list_contacts'}, add_dbo => 1);
+sub get{
+    my ($id) = @_;
+    my $entity = 
+       LedgerSMB::DBObject::Entity::Company->get($id) ||
+        LedgerSMB::DBObject::Entity::Person->get($id);
+    return $entity; 
 }
 
-=item get_notes
+=item get_by_cc($control_code)
 
-Returns a list of notes tied to the entity.
+This retrieves the entity or person by control code
 
-=cut
-
-sub get_notes{
-    my ($self) = @_;
-    return $self->exec_method({funcname => 'entity__list_notes'}, add_dbo => 1);
-}
-
 =head1 COPYRIGHT
 
 Copyright (C) 2012 The LedgerSMB Core Team.  This file may be reused under the

Modified: trunk/LedgerSMB/Scripts/contact.pm
===================================================================
--- trunk/LedgerSMB/Scripts/contact.pm	2012-06-02 15:15:20 UTC (rev 4822)
+++ trunk/LedgerSMB/Scripts/contact.pm	2012-06-03 08:25:16 UTC (rev 4823)
@@ -50,13 +50,15 @@
 
 sub get_by_cc {
     my ($request) = @_;
-    $request->{entity_class} ||= $request->{account_class};
-    $request->{legal_name} ||= 'test';
-    $request->{country_id} = 0;
-    $request->{target_div} = 'credit_div';
-    my $company = LedgerSMB::DBObject::Entity::Company->new(%$request);
-    $company = $company->get_by_cc($request->{control_code});
-    _main_screen($request, $company);
+    my $entity = 
+              LedgerSMB::DBObject::Entity->get_by_cc($request->{control_code});
+    my ($company, $person) = (undef, undef);
+    if ($entity->isa('LedgerSMB::DBObject::Entity::Company')){
+       $company = $entity;
+    } elsif ($entity->isa('LedgerSMB::DBObject::Entity::Person')){
+       $person = $entity;
+    }
+    _main_screen($request, $company, $person);
 }
 
 
@@ -72,10 +74,14 @@
 
 sub get {
     my ($request) = @_;
-    $request->{entity_class} ||= $request->{account_class};
-    $request->{legal_name} ||= 'test';
-    my $company = LedgerSMB::DBObject::Entity::Company->get($request->{entity_id});
-    _main_screen($request, $company);
+    my $entity = LedgerSMB::DBObject::Entity->get($request->{entity_id});
+    my ($company, $person) = (undef, undef);
+    if ($entity->isa('LedgerSMB::DBObject::Entity::Company')){
+       $company = $entity;
+    } elsif ($entity->isa('LedgerSMB::DBObject::Entity::Person')){
+       $person = $entity;
+    }
+    _main_screen($request, $company, $person);
 }
 
 
@@ -86,15 +92,17 @@
 sub _main_screen {
     my ($request, $company, $person) = @_;
 
+
     # DIVS logic
     my @DIVS;
     if ($company->{entity_id} or $person->{entity_id}){
-       @DIVS = qw(address contact_info bank_act notes);
+       @DIVS = qw(credit address contact_info bank_act notes);
        unshift @DIVS, 'company' if $company->{entity_id};
        unshift @DIVS, 'person' if $person->{entity_id};
     } else {
        @DIVS = qw(company person);
     }
+    $request->{company_div} ||= 'company';
 
     my %DIV_LABEL = (
              company => $locale->text('Company'),
@@ -107,9 +115,11 @@
     );
 
     # DIVS contents
+    my $entity_id = $company->{entity_id};
+    $entity_id ||= $person->{entity_id};
     my @credit_list = 
        LedgerSMB::DBObject::Entity::Credit_Account->list_for_entity(
-                          $company->{entity_id},
+                          $entity_id,
                           $request->{entity_class}
         );
     my $credit_act;
@@ -124,7 +134,7 @@
     $entity_class ||= $request->{entity_class};
     $entity_class ||= $request->{account_class};
     my @locations = LedgerSMB::DBObject::Entity::Location->get_active(
-                       {entity_id => $request->{entity_id},
+                       {entity_id => $entity_id,
                         credit_id => $credit_act->{id}}
           );
 
@@ -132,16 +142,19 @@
           LedgerSMB::DBObject::Entity::Contact->list_classes;
 
     my @contacts = LedgerSMB::DBObject::Entity::Contact->list(
-              {entity_id => $request->{entity_id},
+              {entity_id => $entity_id,
                credit_id => $credit_act->{id}}
     );
     my @bank_account = 
-         LedgerSMB::DBObject::Entity::Bank->list($request->{entity_id});
+         LedgerSMB::DBObject::Entity::Bank->list($entity_id);
     my @notes =
-         LedgerSMB::DBObject::Entity::Note->list($request->{entity_id},
+         LedgerSMB::DBObject::Entity::Note->list($entity_id,
                                                  $credit_act->{id});
 
     # Globals for the template
+    my @salutations = $request->call_procedure(
+                procname => 'person__list_salutations'
+    );
     my @all_taxes = $request->call_procedure(procname => 'account__get_taxes');
 
     my @ar_ap_acc_list = $request->call_procedure(procname => 'chart_get_ar_ap',
@@ -220,7 +233,6 @@
     my @entity_classes = $request->call_procedure(
                       procname => 'entity__list_classes'
     );
-    my $entity_id = $company->{entity_id};
 
     $template->render({
                      DIVS => ..hidden..,
@@ -238,6 +250,7 @@
                     notes => ..hidden..,
           # globals
                   form_id => $request->{form_id},
+              salutations => ..hidden..,
            ar_ap_acc_list => ..hidden..,
             cash_acc_list => ..hidden..,
         discount_acc_list => ..hidden..,
@@ -264,7 +277,6 @@
                              args     => ['entity_control']
                            );
     ($request->{control_code}) = values %$ref;
-    $request->{target_div} = 'company_div';
     _main_screen($request, $request, $request);
 }
 
@@ -413,11 +425,26 @@
 sub save_company {
     my ($request) = @_;
     my $company = LedgerSMB::DBObject::Entity::Company->new(%$request);
+    $request->{target_div} = 'credit_div';
+    _main_screen($request, $company->save);
+}
+
+=item save_person
+
+Saves a person and moves on to the next screen
+
+=cut
+
+sub save_person {
+    my ($request) = @_;
+    my $person = LedgerSMB::DBObject::Entity::Person->new(
+              %$request
+    );
     use Data::Dumper;
-    $Data::Dumper::Sortkeys => 1;
+    $Data::Dumper::Sortkeys = 1;
     $request->{target_div} = 'credit_div';
-    $company = $company->save;
-    _main_screen($request, $company);
+    $person->save;
+    _main_screen($request, undef, $person);
 }
 
 =item save_credit($request)
@@ -547,7 +574,7 @@
     get($request);
 } 
 
-=item selete_contact
+=item delete_contact
 
 Deletes the specified contact info.  Note that for_credit is used to pass the 
 credit id over in this case.

Modified: trunk/UI/Contact/divs/person.html
===================================================================
--- trunk/UI/Contact/divs/person.html	2012-06-02 15:15:20 UTC (rev 4822)
+++ trunk/UI/Contact/divs/person.html	2012-06-03 08:25:16 UTC (rev 4823)
@@ -74,6 +74,20 @@
 </div>
 <div class="input_line">
 <div class="input_group1">
+     <?lsmb 
+        PROCESS select element_data = {
+                  label = text('Salutation')
+                   name = 'salutation_id'
+         default_values = [salutation_id]
+                options = salutations
+                  class = 'salutations'
+              text_attr = 'salutation'
+             value_attr = 'id'
+    } ?>
+</div>
+</div>
+<div class="input_line">
+<div class="input_group1">
 	<?lsmb PROCESS input element_data = {
 		label = text('Given Name') #'
 		type= "text"
@@ -82,7 +96,9 @@
 		size = "20"
 	} ?>
 </div>
-<div class="input_group2">
+</div>
+<div class="input_line">
+<div class="input_group1">
         <?lsmb PROCESS input element_data = {
                 label = text('Middle Name') #'
                 type= "text"
@@ -91,17 +107,36 @@
                 size = "20"
         } ?>
 </div>
-<div class="input_group2">
+</div>
+<div class="input_line">
+<div class="input_group1">
         <?lsmb PROCESS input element_data = {
                 label = text('Surname') 
                 type= "text"
-                name = "surname"
-                value = person.surname
+                name = "last_name"
+                value = person.last_name
                 size = "20"
         } ?>
 </div>
 </div>
 <div class="input_line">
+<div class="input_group1">
+       <?lsmb 
+                person_country_id = person.country_id;
+                IF !person_country_id; 
+                          person_country_id = default_country_id;
+                END;
+		INCLUDE select element_data = {
+			text_attr = "name"
+			value_attr = "id"
+			default_values = [company_country_id]
+			options = country_list
+			name = "country_id"
+			label = text('Country') 
+	} ?> 
+</div>
+</div>
+<div class="input_line">
             <hr/>
 <div class="input_group1">
 		<?lsmb INCLUDE button element_data = {

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