summaryrefslogtreecommitdiff
path: root/LedgerSMB/DBObject
diff options
context:
space:
mode:
authoraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-15 23:10:31 +0000
committeraurynn_cmd <aurynn_cmd@4979c152-3d1c-0410-bac9-87ea11338e46>2007-11-15 23:10:31 +0000
commitd340ccd5ecbb731c273a07876ad0dfc0a9b33379 (patch)
tree15acb5cc66a14c787ef49a6bab8910cdca0f82c9 /LedgerSMB/DBObject
parentc366b783a65dfdd7dadb105962ae0807cddaa6b9 (diff)
Significant work on the Entity and Administrative code. It's buggy, so please test, etc. thoroughly.
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1869 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/DBObject')
-rw-r--r--LedgerSMB/DBObject/Admin.pm24
-rw-r--r--LedgerSMB/DBObject/Customer.pm54
-rw-r--r--LedgerSMB/DBObject/User.pm38
3 files changed, 83 insertions, 33 deletions
diff --git a/LedgerSMB/DBObject/Admin.pm b/LedgerSMB/DBObject/Admin.pm
index 51620c47..6b54a7d4 100644
--- a/LedgerSMB/DBObject/Admin.pm
+++ b/LedgerSMB/DBObject/Admin.pm
@@ -5,6 +5,7 @@ use base LedgerSMB::DBObject;
use LedgerSMB::Location;
use LedgerSMB::DBObject::Employee;
use LedgerSMB::Contact;
+use LedgerSMB::Entity;
#[18:00:31] <aurynn> I'd like to split them employee/user and roles/prefs
#[18:00:44] <aurynn> edit/create employee and add user features if needed.
@@ -18,19 +19,27 @@ sub save_employee {
my $self = shift @_;
- my $entity_id = shift @{ $self->exec_method( procname => "save_user" ) };
- $self->merge($entity_id);
+ my $entity = LedgerSMB::DBObject::Entity->new(base=>$self, copy=>'none');
- my $person = LedgerSMB::DBObject::Person->new(base=>$self, copy=>'list',
+ $entity->set(name=>$self->{first_name}." ".$self->{last_name});
+ $entity->save();
+
+ $self->{entity_id} = $entity->{id};
+
+
+ my $user_id = shift @{ $self->exec_method( procname => "admin_save_user" ) };
+ $self->merge($user_id);
+
+ my $person = LedgerSMB::DBObject::Person->new( base=>$self, copy=>'list',
merge=>[
'salutation',
'first_name',
'last_name',
]
);
- my $employee = LedgerSMB::DBObject::Employee->new(base=>$self, copy=>'list',
+ my $employee = LedgerSMB::DBObject::Employee->new( base=>$self, copy=>'list',
merge=>[
- '',
+ 'salutation',
'first_name',
'last_name',
'employeenumber',
@@ -76,16 +85,15 @@ sub save_employee {
'is_a_user'
]
);
-
$user->get();
$user->save();
}
-sub save_roles {
+sub save_roles_preferences {
my $self = shift @_;
- my $user = LedgerSMB::DBObject::User->new(base=>$self, copy=>'all');
+ my $user = LedgerSMB::DBObject::User->new( base=>$self, copy=>'all' );
my $roles = $self->exec_method( procname => "admin_all_roles" );
my $user_roles = $self->exec_method(procname => "admin_get_user_roles", args=>[ $self->{ username } ] );
diff --git a/LedgerSMB/DBObject/Customer.pm b/LedgerSMB/DBObject/Customer.pm
index ef25c4a1..36b4ed62 100644
--- a/LedgerSMB/DBObject/Customer.pm
+++ b/LedgerSMB/DBObject/Customer.pm
@@ -1,33 +1,47 @@
package LedgerSMB::DBObject::Customer;
-use base qw(LedgerSMB);
+use base qw(LedgerSMB::DBObject::Company);
use LedgerSMB::DBObject;
+use LedgerSMB::Entity;
-sub save_to_db {
+sub save {
+
+ # this is doing way too much.
my $self = shift @_;
- my $id;
- if ($self->{id} >= 1) {
- $id = $self->{id};
+ my $entity;
+
+ # this is a fairly effective way of telling if we need to create a new
+ # entity or not.
+
+ if (!$self->{entity_id}) {
+
+ $entity = LedgerSMB::Entity->new(base=>$request);
}
else {
- $id = $self->next_customer_id();
+
+ $entity = LedgerSMB::Entity->get(id=>$self->{entity_id});
}
- $id = $self->save($id, $self->{discount}, $self->{tax_included},
- $self->{creditlimit}, $self->{terms}, $self->{customernumber},
- $self->{cc}, $self->{bcc}, $self->{business_id}, $self->{language},
- $self->{pricegroup}, $self->{currency}, $self->{startdate},
- $self->{enddate}
- );
-
- # Undef in the created field causes the system to use now() as the current
- # creation date.
- $self->location_save(
- $id, 1, $self->{line_one}, $self->{line_two}, $self->{line_three},
- $self->{city_province}, $self->{mailing_code}, $self->{country}, undef
+
+ $entity->set(name=> $reqeust->{first_name}." ".$request->{last_name} );
+ $entity->set(entity_class=>2);
+
+ $self->set(entity_id=>$entity->{id});
+ $self->set(entity_class=> 2);
+
+ $entity->save();
+ if (!self->{entity_id}) {
- );
- return $id;
+ $self->{entity_id} = $entity->{id};
+ }
+ $self->SUPER::save();
+
+ return $self->{id};
+}
+
+sub search {
+
+
}
1; \ No newline at end of file
diff --git a/LedgerSMB/DBObject/User.pm b/LedgerSMB/DBObject/User.pm
index 62ae4e0b..3486fbd6 100644
--- a/LedgerSMB/DBObject/User.pm
+++ b/LedgerSMB/DBObject/User.pm
@@ -8,13 +8,13 @@ sub save {
my $user = $self->get();
- if ($user->{id} && $self->{is_a_user}) {
+ if ( $user->{id} && $self->{is_a_user} ) {
# doesn't check for the password - that's done in the sproc.
- $self->{id} = @{ $self->exec_method(procname=>'admin_save_user',
- args=>[$user->{id}, $self->{username}, $self->{password}] ) }[0];
- else {
-
+ $self->{id} = shift @{ $self->exec_method(procname=>'admin_save_user',
+ args=>[$user->{id}, $self->{username}, $self->{password}] ) };
+ if (!$self->{id}) {
+
return 0;
}
}
@@ -26,6 +26,12 @@ sub save {
return $self->remove();
}
+ elsif ($self->{is_a_user}) {
+
+ # No user ID, meaning, creating a new one.
+ $self->{id} = shift @{ $self->exec_method(procname=>'admin_save_user',
+ args=>[undef, $self->{username}, $self->{password}] ) };
+ }
return 1;
}
@@ -49,4 +55,26 @@ sub remove {
return $code->[0];
}
+sub save_prefs {
+
+ my $self = shift @_;
+
+ my $pref_id = $self->exec_method(procname=>"admin_save_preferences",
+ args=>[
+ 'language',
+ 'stylesheet',
+ 'printer',
+ 'dateformat',
+ 'numberformat'
+ ]
+ );
+}
+
+sub get_all_users {
+
+ my $self = shift @_;
+
+ $self->{users} = $self->exec_method( procname=>"user_get_all_users" );
+}
+
1; \ No newline at end of file