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

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



Revision: 4822
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4822&view=rev
Author:   einhverfr
Date:     2012-06-02 15:15:20 +0000 (Sat, 02 Jun 2012)
Log Message:
-----------
Persons as customers/vendors partially working.  More work needs to be done tomorrow on this though

Modified Paths:
--------------
    trunk/LedgerSMB/DBObject/Entity/Company.pm
    trunk/LedgerSMB/Scripts/contact.pm

Added Paths:
-----------
    trunk/LedgerSMB/DBObject/Entity/Person.pm
    trunk/UI/Contact/divs/person.html

Modified: trunk/LedgerSMB/DBObject/Entity/Company.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Company.pm	2012-06-02 11:46:33 UTC (rev 4821)
+++ trunk/LedgerSMB/DBObject/Entity/Company.pm	2012-06-02 15:15:20 UTC (rev 4822)
@@ -139,34 +139,6 @@
     $self = $self->new(%$ref);
 }
 
-=item search({account_class => int, contact => string, contact_info => arrayref(string),
-              meta_number => string, address => string, city => string, state => string,
-              mail_code => string, country => string, date_from => date, 
-              date_to => date, business_id => int, legal_name => string, 
-              control_code string})
-
-Retrieves a list of companies matching search criteria.
-
-account_class is required and is an exact match.
-control_code and business_id are exact matches.
-All other criteria are partial matches.
-
-Except with account_class, undef matches all values.
-
-=cut
-
-sub search {
-    my ($self, $criteria) = @_;
-    my @results = $self->exec_method({funcname => 'company__search', 
-                                       arghash => $criteria}
-    );
-    for my $ref (@results){
-        $self->prepare_dbhash($ref);
-        $ref = $self->new(%$ref);
-    }
-    return @results;
-}
-
 =back
 
 =head1 COPYRIGHT

Added: trunk/LedgerSMB/DBObject/Entity/Person.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Person.pm	                        (rev 0)
+++ trunk/LedgerSMB/DBObject/Entity/Person.pm	2012-06-02 15:15:20 UTC (rev 4822)
@@ -0,0 +1,188 @@
+=head1 NAME
+
+LedgerSMB::DBObject::Entity::Person -- Natural Person handling for LedgerSMB
+
+=head1 SYNOPSIS
+
+To save:
+
+ my $person = LedgerSMB::DBObject::Entity::Person(\%$request);
+ $person->save;
+
+To get by entity id:
+
+ my $person = LedgerSMB::DBObject::Entity::Person->get($entity_id);
+
+To get by control code:
+
+ my $person = LedgerSMB::DBObject::Entity::Person->get_by_cc($control_code);
+
+=head1 INHERITS
+
+=over 
+
+=item LedgerSMB::DBObject::Entity
+
+=back
+
+=cut
+
+package LedgerSMB::DBObject::Entity::Person;
+use Moose;
+extends 'LedgerSMB::DBObject::Entity';
+
+use LedgerSMB::App_State;
+
+my $locale = $LedgerSMB::App_State::Locale;
+
+=head1 PROPERTIES
+
+=over
+
+=item entity_id
+
+ID of entity attached.  This is also an interal reference to this person.
+
+=cut
+
+has 'entity_id' => (is => 'rw', isa => 'Maybe[Int]');
+
+=item first_name
+
+Given name of the individual.
+
+=cut
+
+has 'first_name' => (is => 'rw', isa => 'Str');
+
+=item middle_name
+
+Middle name of individual
+
+=cut
+
+has 'middle_name' => (is => 'rw', isa => 'Maybe[Str]');
+
+=item last_name
+
+Surname of individual
+
+=cut
+
+has 'last_name' => (is => 'rw', isa => 'Maybe[Str]');
+
+=item salutation_id
+
+Salutation id.  These are fixed as:
+
+  id | salutation 
+ ----+------------
+   1 | Dr.
+   2 | Miss.
+   3 | Mr.
+   4 | Mrs.
+   5 | Ms.
+   6 | Sir.
+ (6 rows)
+
+
+=cut
+
+has 'salutation_id' => (is => 'rw', isa => 'Int');
+
+=item salutations
+
+Constant hashref of above salutations, key is id.
+
+=cut
+
+sub salutations {
+    return { 
+       '1' => $locale->text('Dr.'),
+       '2' => $locale->text('Miss.'),
+       '3' => $locale->text('Mr.'),
+       '4' => $locale->text('Mrs.'),
+       '5' => $locale->text('Ms.'),
+       '6' => $locale->text('Sir.'),
+    };
+}
+
+=item created 
+
+Date when the  person was entered into LedgerSMB
+
+=back
+
+=cut
+
+has 'created' => (is => 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=head1 METHODS
+
+=over
+
+=item get($id)
+
+This retrieves and returns the item as a blessed reference
+
+=cut
+
+sub get {
+    my ($self, $id) = @_;
+    my ($ref) = $self->call_procedure(procname => 'person__get',
+                                          args => [$id]);
+    if (!$ref){
+        die $locale->text('No person found.');
+    }
+    $self->prepare_dbhash($ref);
+    return $self->new(%$ref);
+}
+
+=item get_by_cc($cc)
+
+This retrieves a person associated with a control code.  Dies with error if 
+person does not exist.
+
+=cut
+
+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.');
+    }
+    $self->prepare_dbhash($ref);
+    return $self->new(%$ref);
+}
+
+
+=item save()
+
+Saves the item and populates db defaults in id and created.
+
+=cut
+
+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);
+}
+
+=back
+
+=head1 COPYRIGHT
+
+Copyright (C) 2012, the LedgerSMB Core Team.  This file may be re-used under the GNU GPL
+version 2 or at your option any future version.  Please see the accompanying LICENSE 
+file for details.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+return 1;

Modified: trunk/LedgerSMB/Scripts/contact.pm
===================================================================
--- trunk/LedgerSMB/Scripts/contact.pm	2012-06-02 11:46:33 UTC (rev 4821)
+++ trunk/LedgerSMB/Scripts/contact.pm	2012-06-02 15:15:20 UTC (rev 4822)
@@ -17,6 +17,7 @@
 package LedgerSMB::Scripts::contact;
 
 use LedgerSMB::DBObject::Entity::Company;
+use LedgerSMB::DBObject::Entity::Person;
 use LedgerSMB::DBObject::Entity::Credit_Account;
 use LedgerSMB::DBObject::Entity::Location;
 use LedgerSMB::DBObject::Entity::Contact;
@@ -83,18 +84,21 @@
 # this attaches everything other than {company} to $request and displays it.
 
 sub _main_screen {
-    my ($request, $company) = @_;
+    my ($request, $company, $person) = @_;
 
     # DIVS logic
     my @DIVS;
-    if ($company->{entity_id}){
-       @DIVS = qw(company credit address contact_info bank_act notes);
+    if ($company->{entity_id} or $person->{entity_id}){
+       @DIVS = qw(address contact_info bank_act notes);
+       unshift @DIVS, 'company' if $company->{entity_id};
+       unshift @DIVS, 'person' if $person->{entity_id};
     } else {
-       @DIVS = qw(company);
+       @DIVS = qw(company person);
     }
 
     my %DIV_LABEL = (
              company => $locale->text('Company'),
+              person => $locale->text('Person'),
               credit => $locale->text('Credit Accounts'),
              address => $locale->text('Addresses'),
         contact_info => $locale->text('Contact Info'),
@@ -223,6 +227,7 @@
                 DIV_LABEL => \%DIV_LABEL,
                   request => $request,
                   company => $company,
+                   person => $person,
              country_list => ..hidden..,
                credit_act => $credit_act,
               credit_list => ..hidden..,
@@ -260,7 +265,7 @@
                            );
     ($request->{control_code}) = values %$ref;
     $request->{target_div} = 'company_div';
-    _main_screen($request, $request);
+    _main_screen($request, $request, $request);
 }
 
 =item dispatch_legacy

Added: trunk/UI/Contact/divs/person.html
===================================================================
--- trunk/UI/Contact/divs/person.html	                        (rev 0)
+++ trunk/UI/Contact/divs/person.html	2012-06-02 15:15:20 UTC (rev 4822)
@@ -0,0 +1,124 @@
+<div class="container" id="person_div">
+<?lsmb SWITCH entity_class
+	?><?lsmb CASE 1 ?><?lsmb entity_classname = "Vendor" 
+	?><?lsmb CASE 2 ?><?lsmb entity_classname = "Customer" 
+	?><?lsmb END ?>
+	<div class="listtop"><strong><?lsmb text("$operation $entity_classname") ?></strong></div>
+<form name="customer" method="post" action="<?lsmb script ?>">
+<?lsmb PROCESS input element_data = { # Only for generate_control_code
+		type = "hidden"
+		name = "target_div"
+		value = 'person_div'
+	} ?>
+	<?lsmb PROCESS input element_data = {
+		type = "hidden"
+		name = "entity_id"
+		value = entity_id
+	} ?>	
+	<?lsmb PROCESS input element_data = {
+		type = "hidden"
+		name = "id"
+		value = person.id
+	} ?>	
+<?lsmb PROCESS input element_data = {
+		type = "hidden"
+		name = "form_id"
+		value = form_id
+	} ?>
+	<?lsmb PROCESS input element_data = {
+		type = "hidden"
+		name = "account_class"
+		value = account_class
+	} ?>	
+<div class="input_line">
+<div class="input_group1">
+	<?lsmb PROCESS input element_data = {
+		label = text('Control Code') #'
+		type= "text"
+		name = "control_code"
+		value = person.control_code
+		size = "20"
+	} ?>
+	<?lsmb IF !created_as_class;
+		created_as_class = entity_class;
+	END; # IF !created_as_class ?> 
+</div>
+<div class="input_group2">
+        <?lsmb company_entity_class =persony.entity_class;
+        IF !company_entity_class;
+              company_entity_class = request.entity_class;
+        END;
+        PROCESS select element_data = {
+		name = "entity_class"
+		options = entity_classes
+		default_values = [person_entity_class]
+		text_attr = 'class'
+		value_attr = 'id'
+		label = text('Class')
+	} ?>
+	<?lsmb PROCESS button element_data = {
+		text = text('Generate Control Code') #'
+		type = "submit"
+		name = "action"
+		value = "generate_control_code"
+		class = "submit"
+        } ?>
+        <?lsmb PROCESS button element_data = {
+                text = text('Retrieve')
+                type = 'submit'
+                name = 'action'
+               value = 'get_by_cc'
+               class = 'submit'
+        } ?>
+</div>
+</div>
+<div class="input_line">
+<div class="input_group1">
+	<?lsmb PROCESS input element_data = {
+		label = text('Given Name') #'
+		type= "text"
+		name = "first_name"
+		value = person.first_name
+		size = "20"
+	} ?>
+</div>
+<div class="input_group2">
+        <?lsmb PROCESS input element_data = {
+                label = text('Middle Name') #'
+                type= "text"
+                name = "middle_name"
+                value = person.middle_name
+                size = "20"
+        } ?>
+</div>
+<div class="input_group2">
+        <?lsmb PROCESS input element_data = {
+                label = text('Surname') 
+                type= "text"
+                name = "surname"
+                value = person.surname
+                size = "20"
+        } ?>
+</div>
+</div>
+<div class="input_line">
+            <hr/>
+<div class="input_group1">
+		<?lsmb INCLUDE button element_data = {
+			text = text('Save'),
+			class="submit" 
+			type="submit" 
+			name="action" 
+			value="save_person" 
+			accesskey="S" 
+			title="Save [Alt-S]"
+		} ?>
+</div>
+</div>
+</form>
+<?lsmb FOREACH n = notes ?>
+<div class="note">
+<div class="note_contents"><?lsmb n.note ?></div>
+</div>
+<?lsmb END ?>
+</div>

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