[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4856] trunk/LedgerSMB
- Subject: SF.net SVN: ledger-smb:[4856] trunk/LedgerSMB
- From: ..hidden..
- Date: Thu, 07 Jun 2012 08:06:52 +0000
Revision: 4856
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4856&view=rev
Author: einhverfr
Date: 2012-06-07 08:06:52 +0000 (Thu, 07 Jun 2012)
Log Message:
-----------
Employee initial port, still broken (not any more working but on 1.4 codebase so this should not take much longer.
Modified Paths:
--------------
trunk/LedgerSMB/Scripts/employee.pm
Added Paths:
-----------
trunk/LedgerSMB/DBObject/Entity/Person/
trunk/LedgerSMB/DBObject/Entity/Person/Employee.pm
Removed Paths:
-------------
trunk/LedgerSMB/DBObject/Employee.pm
Deleted: trunk/LedgerSMB/DBObject/Employee.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Employee.pm 2012-06-07 02:31:00 UTC (rev 4855)
+++ trunk/LedgerSMB/DBObject/Employee.pm 2012-06-07 08:06:52 UTC (rev 4856)
@@ -1,380 +0,0 @@
-package LedgerSMB::DBObject::Employee;
-
-=head1 NAME
-
-LedgerSMB::DBObject::Employee - LedgerSMB class for managing Employees
-
-=head1 SYOPSIS
-
-This module creates object instances based on LedgerSMB's in-database ORM.
-
-=head1 METHODS
-
-The following method is static:
-
-=over
-
-=item new ($LedgerSMB object);
-
-
-=item save
-
-Saves an employee. Inputs required
-
-=over
-
-=item entity_id
-
-May not be undef
-
-=item start_date
-
-=item end_date
-
-=item dob date
-
-may not be undef
-
-=item role
-
-Not the database role. Either manager or user
-
-=item ssn
-
-=item sales
-
-=item manager_id
-
-=item employee_number
-
-=back
-
-=item search
-
-Returns a list of employees matching set criteria:
-
-=over
-
-=item employeenumber (exact match)
-
-=item startdate_from (start of date range)
-
-=item startdate_to (end of date range)
-
-=item first_name (partial match)
-
-=item middle_name (partial match)
-
-=item last_name (partial match)
-
-=item notes (partial match)
-
-=back
-
-Undef values match all values.
-
-=cut
-
-use base qw(LedgerSMB::DBObject);
-use strict;
-
-my $ENTITY_CLASS = 3;
-
-my $logger = Log::Log4perl->get_logger('LedgerSMB::DBObject::Employee');
-
-=item set_entity_class
-
-Sets the entity class to 3.
-
-=cut
-
-sub set_entity_class {
- my $self = shift @_;
- $self->{entity_class} = $ENTITY_CLASS;
-}
-
-sub save {
- my ($self) = @_;
- $self->set_entity_class();
- if ($self->{is_manager}) {
- $self->{role} = 'manager';
- } else {
- $self->{role} = 'user';
- }
- my ($ref) = $self->exec_method(funcname => 'person__save');
- $self->{entity_id} = $ref->{'person__save'};
- $self->exec_method(funcname => 'employee__save');
- $self->{dbh}->commit;
-}
-
-
-=item get_managers
-
-Retrieves a set of managers and attaches to $self->{all_managers}
-
-=cut
-
-sub get_managers {
- my ($self) = @_;
- my @results = $self->exec_method(funcname => 'employee__all_managers');
- for my $ref (@results) {
- $ref->{label} = $ref->{employeenumber} . '--' . $ref->{last_name};
- }
- $self->{all_managers} = ..hidden..;
- return @results;
-}
-
-=item save_location
-
-Saves the location data for the contact.
-
-Inputs are standard location inputs (line_one, line_two, etc)
-
-=cut
-
-sub save_location {
- my $self = shift @_;
-
- $self->{country_id} = $self->{country_code};
-
- my ($ref) = $self->exec_method(funcname => 'person__save_location');
- my @vals = values %$ref;
- $self->{location_id} = $vals[0];
-
- $self->{dbh}->commit;
-}
-
-=item save_contact
-
-Saves contact information. Inputs are standard contact inputs:
-
-=over
-
-=item entity_id
-
-=item contact_class
-
-=item contact
-
-=item description
-
-=cut
-
-sub save_contact {
- my ($self) = @_;
- $self->{contact_new} = $self->{contact};
- $self->exec_method(funcname => 'person__save_contact');
- $self->{dbh}->commit;
-}
-
-=item save_bank_account
-
-Saves a bank account to an employee.
-
-Standard inputs (entity_id, iban, bic)
-
-=cut
-
-sub save_bank_account {
- my $self = shift @_;
- $self->exec_method(funcname => 'entity__save_bank_account');
- $self->{dbh}->commit;
-}
-
-=item get_metadata()
-
-This retrieves various information vor building the user interface. Among other
-things, it sets the following properties:
-$self->{ar_ap_acc_list} = qw(list of ar or ap accounts)
-$self->{cash_acc_list} = qw(list of cash accounts)
-
-=cut
-
-sub get_metadata {
- my $self = shift @_;
- $self->get_managers;
- @{$self->{entity_classes}} =
- $self->exec_method(funcname => 'entity__list_classes');
-
- @{$self->{location_class_list}} =
- $self->exec_method(funcname => 'location_list_class');
-
- @{$self->{country_list}} =
- $self->exec_method(funcname => 'location_list_country');
-
- @{$self->{contact_class_list}} =
- $self->exec_method(funcname => 'contact_class__list');
- my $country_setting = LedgerSMB::Setting->new({base => $self, copy => 'base'});
- $country_setting->{key} = 'default_country';
- $country_setting->get;
- $self->{default_country} = $country_setting->{value};
- $self->get_user_info();
-}
-
-=item get
-
-Returns the employee record with all the inputs required for "save" populated.
-
-Also populates:
-
-=over
-
-=item locations
-
-List of location info
-
-=item contacts
-
-List of contact info
-
-=item notes
-
-List of notes
-
-=item bank account
-
-List of bank accounts
-
-=back
-
-=cut
-
-sub get {
- my $self = shift @_;
- my ($ref) = $self->exec_method(funcname => 'employee__get');
- if ($ref->{role} eq 'manager'){
- $ref->{is_manager} = 1;
- }
- $self->merge($ref);
- @{$self->{locations}} = $self->exec_method(
- funcname => 'person__list_locations');
- @{$self->{contacts}} = $self->exec_method(
- funcname => 'person__list_contacts');
- @{$self->{notes}} = $self->exec_method(
- funcname => 'person__list_notes');
- @{$self->{bank_account}} = $self->exec_method(
- funcname => 'person__list_bank_account');
-
-
-
-}
-
-=item save_notes
-
-Saves a note to an employee entity.
-
-Standard inputs (note, subject, entity_id)
-
-=cut
-
-sub save_notes {
- my $self = shift @_;
- $self->exec_method(funcname => 'entity__save_notes');
- $self->{dbh}->commit;
-}
-
-sub search {
- my $self = shift @_;
- my @results = $self->exec_method(funcname => 'employee__search');
- @{$self->{search_results}} = @results;
- return @results;
-}
-
-=item delete_contact
-
-required request variables:
-
-contact_class_id: int id of contact class
-contact: text of contact information
-person_id: int of entity_credit_account.id, preferred value
-
-
-=cut
-
-sub delete_contact {
- my ($self) = @_;
- $self->exec_method(funcname => 'person__delete_contact');
- $self->{dbh}->commit;
-}
-
-=item delete_location
-
-Deletes a record from the location side.
-
-Required request variables:
-
-location_id
-location_class_id
-person_id
-
-Returns true if a record was deleted. False otherwise.
-
-=cut
-
-sub delete_location {
- my ($self) = @_;
- my $rv;
- ($rv) = $self->exec_method(funcname => 'person__delete_location');
- $self->{dbh}->commit;
- return $rv;
-}
-
-=item delete_bank_account
-
-Deletes a bank account
-
-Requires:
-
-entity_id
-bank_account_id
-
-Returns true if a record was deleted, false otherwise.
-
-=back
-
-=cut
-
-sub delete_bank_account {
- my ($self) = @_;
- my $rv;
- ($rv) = $self->exec_method(funcname => 'entity__delete_bank_account',
- args => [$self->{entity_id},
- $self->{bank_account_id}]);
- $self->{dbh}->commit;
- return $rv;
-}
-
-=item get_user_info
-
-Attaches the user_id and username to the employee object.
-
-If the user does not have manage_users powers, this will simply return false
-
-=cut
-
-sub get_user_info {
- my $self = shift @_;
- if (!$self->is_allowed_role({allowed_roles => [
- "lsmb_$self->{company}__users_manage"]
- }
- )){
- return 0;
- }
- my ($ref) = $self->exec_method(funcname => 'employee__get_user');
- $self->{user_id} = $ref->{id};
- $self->{username} = $ref->{username};
- return 1;
-}
-
-=back
-
-=head1 Copyright (C) 2007, The LedgerSMB core team.
-
-This file is licensed under the Gnu General Public License version 2, or at your
-option any later version. A copy of the license should have been included with
-your software.
-
-=cut
-
-
-1;
Added: trunk/LedgerSMB/DBObject/Entity/Person/Employee.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Person/Employee.pm (rev 0)
+++ trunk/LedgerSMB/DBObject/Entity/Person/Employee.pm 2012-06-07 08:06:52 UTC (rev 4856)
@@ -0,0 +1,168 @@
+=head1 NAME
+
+LedgerSMB::DBObject::Entity::Person::Employee -- Employee handling for LedgerSMB
+
+=head1 SYNOPSIS
+
+To save:
+
+ my $emp = LedgerSMB::DBObject::Entity::Person::Employee(\%$request);
+ $emp->save;
+
+To get by entity id:
+
+ my $emp = LedgerSMB::DBObject::Entity::Person::Employee->get($entity_id);
+
+To get by control code:
+
+ my $emp
+ = LedgerSMB::DBObject::Entity::Person::Employee->get_by_cc($control_code);
+
+=head1 INHERITS
+
+=over
+
+=item LedgerSMB::DBObject::Entity::Person
+
+=back
+
+=cut
+
+package LedgerSMB::DBObject::Entity::Person::Employee;
+use Moose;
+extends 'LedgerSMB::DBObject::Entity::Person';
+
+use LedgerSMB::App_State;
+my $locale = $LedgerSMB::App_State::Locale;
+
+=head1 PROPERTIES
+
+=over
+
+=item start_date
+
+Start date for employee.
+
+=cut
+
+has start_date => (is => 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item end_date
+
+End date for employee
+
+=cut
+
+has end_date => (is => 'rw', isa => 'Maybe[LedgerSMB::PGDate]');
+
+=item dob
+
+Date of Birth. Required.
+
+=cut
+
+has dob => (is => 'rw', isa => 'LedgerSMB::PGDate');
+
+=item role
+
+Organizational role. Is manager, user, or administrator
+
+=cut
+
+has role => (is => 'rw', isa => 'Maybe[Str]');
+
+=item ssn
+
+Social security number, tax number, or the like for the employee. Required
+
+=cut
+
+has ssn => (is => 'rw', isa => 'Str');
+
+=item sales
+
+Bool, whether the individual is a salesperson or not
+
+=cut
+
+has sales => (is => 'rw', isa => 'Bool');
+
+=item manager_id
+
+Entity id of manager
+
+=cut
+
+has manager_id => (is => 'rw', isa => 'Maybe[Int]');
+
+=item employee_number
+
+Employee number, required, for employee.
+
+=cut
+
+has employee_number => (is => 'rw', isa => 'Str');
+
+=back
+
+=head1 METHODS
+
+=over
+
+=item get($entity_id)
+
+This does not need to be a blessed reference. It does return a reference
+blessed if the employee is found or undef otherwise.
+
+=cut
+
+sub get {
+ my ($self, $id) = @_;
+ my ($ref) = $self->call_procedure(procname => 'employee__get',
+ args => [$id]);
+ return undef unless $ref->{control_code};
+ $self->prepare_dbhash($ref);
+ return $self->new(%$ref);
+}
+
+=item get_by_cc($control_code);
+
+Similar to get above but accepts as input the control code rather than the
+entity_id.
+
+=cut
+
+sub get_by_cc {
+ my ($self, $cc) = @_;
+ my ($ref) = $self->call_procedure(procname => 'person__get_by_cc',
+ args => [$cc]);
+ return undef unless $ref->{control_code};
+ return get($ref->{id});
+}
+
+=item save()
+
+Saves the employee. Must be a blessed reference.
+
+=cut
+
+sub save {
+ my ($self) = @_;
+ my ($ref) = $self->exec_method({funcname => 'employee__save'});
+ my ($id) = values(%$ref);
+ $self->entity_id($id);
+}
+
+=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;
+
+1;
Modified: trunk/LedgerSMB/Scripts/employee.pm
===================================================================
--- trunk/LedgerSMB/Scripts/employee.pm 2012-06-07 02:31:00 UTC (rev 4855)
+++ trunk/LedgerSMB/Scripts/employee.pm 2012-06-07 08:06:52 UTC (rev 4856)
@@ -3,424 +3,407 @@
=head1 NAME
-LedgerSMB::Scripts::employee - LedgerSMB class defining the Controller
-functions, template instantiation and rendering for employee editing and display.
+LedgerSMB::Scripts::contact - LedgerSMB class defining the Controller
+functions, template instantiation and rendering for customer editing and display.
=head1 SYOPSIS
-This module is the UI controller for the employee DB access; it provides the
-View interface, as well as defines the Save employee.
-Save employee will update or create as needed.
+This module is the UI controller for the customer, vendor, etc functions; it
-
=head1 METHODS
-=over
-
=cut
package LedgerSMB::Scripts::employee;
+use LedgerSMB::DBObject::Entity::Person::Employee;
+use LedgerSMB::DBObject::Entity::Location;
+use LedgerSMB::DBObject::Entity::Contact;
+use LedgerSMB::DBObject::Entity::Bank;
+use LedgerSMB::DBObject::Entity::Note;
+use LedgerSMB::App_State;
use LedgerSMB::Template;
-use LedgerSMB::DBObject::Employee;
-#require 'lsmb-request.pl';
+use strict;
+use warnings;
-=item get($self, $request, $user)
+my $locale = $LedgerSMB::App_State::Locale;
-Requires form var: id
+=head1 COPYRIGHT
-Extracts a single employee from the database, using its company ID as the primary
-point of uniqueness. Shows (appropriate to user privileges) and allows editing
-of the employee informations.
+Copyright (c) 2012, the LedgerSMB Core Team. This is licensed under the GNU
+General Public License, version 2, or at your option any later version. Please
+see the accompanying License.txt for more information.
=cut
+=head1 METHODS
-sub get {
-
- my ($request) = @_;
- my $employee = LedgerSMB::DBObject::Employee->new(base => $request, copy => 'all');
-
- $employee->get_metadata();
- $employee->set( entity_class=> '3' );
- $employee->{target_div} = 'hr_div';
- my $result = $employee->get();
-
- my $template = LedgerSMB::Template->new( user => $user,
- template => 'contact', language => $user->{language},
- path => 'UI/Contact',
- format => 'HTML');
- $template->render($results);
-
-}
+=over
-=item add_location
+=item get_by_cc
-Adds a location to an employee and returns to the edit employee screen.
-Standard location inputs apply.
+Retrieves the employee based on control code.
=cut
-sub add_location {
+sub get_by_cc {
my ($request) = @_;
- my $employee= LedgerSMB::DBObject::Employee->new({base => $request, copy => 'all'});
- $employee->set( entity_class=> '3' );
- $employee->save_location();
- $employee->get();
+ my $emp = LedgerSMB::DBObject::Entity::Person::Employee->get_by_cc(
+ $request->{control_code}
+ );
+ _main_screen($request, $emp);
+}
-
- _render_main_screen($employee);
-
-}
+=item get
-=item add
+Requires form var: id
-This method creates a blank screen for entering a employee's information.
+Retrieves the employee by id.
-=cut
+=cut
-sub add {
+sub get {
my ($request) = @_;
- my $employee= LedgerSMB::DBObject::Employee->new(base => $request, copy => 'all');
- $employee->set( entity_class=> '3' );
- $employee->{target_div} = 'hr_div';
- _render_main_screen($employee);
+ my $emp = LedgerSMB::DBObject::Entity::Person::Employee->get(
+ $request->{entity_id}
+ );
+ _main_screen($request, $emp);
}
-=item delete_contact
-Deletes the selected contact info record
+# private method _main_screen
+#
+# this attaches everything other than employee and displays.
-Must include company_id or credit_id (credit_id used if both are provided) plus:
+sub _main_screen {
+ my ($request, $employee) = @_;
-=over
-=item contact_class_id
+ # DIVS logic
+ my @DIVS;
+ if ($employee->{entity_id}){
+ @DIVS = qw(employee address contact_info bank_act notes);
+ } else {
+ @DIVS = qw(employee);
+ }
+ $request->{target_div} ||= 'employee_div';
-=item contact
+ my %DIV_LABEL = (
+ company => $locale->text('Employee'),
+ address => $locale->text('Addresses'),
+ contact_info => $locale->text('Contact Info'),
+ bank_act => $locale->text('Bank Accounts'),
+ notes => $locale->text('Notes'),
+ );
-=item form_id
+ # DIVS contents
+ my $entity_id = $employee->{entity_id};
-=back
+ my $entity_class = 3;
-=cut
+ my @locations = LedgerSMB::DBObject::Entity::Location->get_active(
+ {entity_id => $entity_id,
+ credit_id => undef}
+ );
-sub delete_contact {
- my ($request) = @_;
- my $employee= LedgerSMB::DBObject::Employee->new(base => $request, copy => 'all');
- if (_close_form($employee)){
- $employee->delete_contact();
- }
- $employee->get;
- _render_main_screen( $employee);
-}
+ my @contact_class_list =
+ LedgerSMB::DBObject::Entity::Contact->list_classes;
-=item save_contact_new($request)
+ my @contacts = LedgerSMB::DBObject::Entity::Contact->list(
+ {entity_id => $entity_id,
+ credit_id => undef}
+ );
+ my @bank_account =
+ LedgerSMB::DBObject::Entity::Bank->list($entity_id);
+ my @notes =
+ LedgerSMB::DBObject::Entity::Note->list($entity_id,
+ undef);
-Saves contact info as a new line as per save_contact above.
+ # Globals for the template
+ my @salutations = $request->call_procedure(
+ procname => 'person__list_salutations'
+ );
+ my @managers = $request->call_procedure(
+ procname => 'employee__all_managers'
+ );
-=cut
+ my @language_code_list =
+ $request->call_procedure(procname=> 'person__list_languages');
-sub save_contact_new{
- my ($request) = @_;
- delete $request->{old_contact};
- delete $request->{old_contact_class};
- save_contact($request);
-}
+ for my $ref (@language_code_list){
+ $ref->{text} = "$ref->{code}--$ref->{description}";
+ }
+
+ my @location_class_list =
+ $request->call_procedure(procname => 'location_list_class');
-=item delete_location
+ my ($curr_list) =
+ $request->call_procedure(procname => 'setting__get_currencies');
-Deletes the selected contact info record
+ my @all_currencies;
+ for my $curr (@{$curr_list->{'setting__get_currencies'}}){
+ push @all_currencies, { text => $curr};
+ }
-Must include company_id or credit_id (credit_id used if both are provided) plus:
+ my ($default_country) = $request->call_procedure(
+ procname => 'setting_get',
+ args => ['default_country']);
+ $default_country = $default_country->{value};
-* location_class_id
-* location_id
-* form_id
+ my ($default_language) = $request->call_procedure(
+ procname => 'setting_get',
+ args => ['default_language']);
+ $default_language = $default_language->{value};
-=cut
+ my $attach_level_options = [
+ {text => $locale->text('Entity'), value => 1} ];
-sub delete_location {
- my ($request) = @_;
- my $employee= LedgerSMB::DBObject::Employee->new(base => $request, copy => 'all');
- if (_close_form($employee)){
- $employee->delete_location();
- }
- $employee->get;
- _render_main_screen( $employee);
+ $request->close_form();
+ $request->open_form();
+
+ # Template info and rendering
+ my $template = LedgerSMB::Template->new(
+ user => $request->{_user},
+ template => 'contact',
+ locale => $request->{_locale},
+ path => 'UI/Contact',
+ format => 'HTML'
+ );
+
+ use Data::Dumper;
+ $Data::Dumper::Sortkeys = 1;
+ #die '<pre>' . Dumper($request) . '</pre>';
+ my @country_list = $request->call_procedure(
+ procname => 'location_list_country'
+ );
+ my @entity_classes = $request->call_procedure(
+ procname => 'entity__list_classes'
+ );
+
+ $template->render({
+ DIVS => ..hidden..,
+ DIV_LABEL => \%DIV_LABEL,
+ request => $request,
+ employee => $employee,
+ country_list => ..hidden..,
+ locations => ..hidden..,
+ contacts => ..hidden..,
+ bank_account => ..hidden..,
+ notes => ..hidden..,
+ managers => ..hidden..,
+ # globals
+ form_id => $request->{form_id},
+ salutations => ..hidden..,
+ language_code_list => ..hidden..,
+ all_currencies => ..hidden..,
+ attach_level_options => $attach_level_options,
+ entity_id => $entity_id,
+ entity_class => $entity_class,
+ location_class_list => ..hidden..,
+ contact_class_list => ..hidden..,
+ });
}
-=item edit_bank_account($request)
+=item generate_control_code
-displays screen to a bank account
+Generates a control code and hands off execution to other routines
-Required data:
+=cut
-=over
+sub generate_control_code {
+ my ($request) = @_;
+ my ($ref) = $request->call_procedure(
+ procname => 'setting_increment',
+ args => ['entity_control']
+ );
+ ($request->{control_code}) = values %$ref;
+ _main_screen($request, $request);
+}
-=item bank_account_id
-=item bic
+=item add
-=item iban
+This method creates a blank screen for entering a company's information.
=back
-=cut
+=cut
-sub edit_bank_acct {
+sub add {
my ($request) = @_;
- my $employee= LedgerSMB::DBObject::Employee->new(base => $request, copy => 'all');
- $employee->get;
- _render_main_screen( $employee);
+ $request->{target_div} = 'employee_div';
+ _main_screen($request, $request);
}
-=item delete_bank_acct
+=item save_employee
-Deletes the selected bank account record
+Saves a company and moves on to the next screen
-Required request variables:
+=cut
-=over
+sub save_employee {
+ my ($request) = @_;
+ my $employee = LedgerSMB::DBObject::Entity::Person::Employee->new(%$request);
+ $request->{target_div} = 'credit_div';
+ $employee->save;
+ _main_screen($request, $employee);
+}
-=item bank_account_id
+=item save_location
-=item entity_id
+Adds a location to the company as defined in the inherited object
-=item form_id
-
-=back
-
=cut
-sub delete_bank_acct{
+sub save_location {
my ($request) = @_;
- my $employee= LedgerSMB::DBObject::Employee->new(base => $request, copy => 'all');
- if (_close_form($employee)){
- $employee->delete_bank_account();
- }
- $employee->get;
- _render_main_screen( $employee);
-}
-# Private method. Sets notice if form could not be closed.
-sub _close_form {
- my ($employee) = @_;
- if (!$employee->close_form()){
- $employee->{notice} =
- $employee->{_locale}->text('Changes not saved. Please try again.');
- return 0;
+ my $location = LedgerSMB::DBObject::Entity::Location->new(%$request);
+ if ($request->{attach_to} eq '1'){
+ $location->credit_id(undef);
}
- return 1;
+ $location->id($request->{location_id});
+ $location->save;
+ $request->{target_div} = 'address_div';
+ get($request);
+
}
-=item save($self, $request, $user)
+=item save_new_location
-Saves a employee to the database. The function will update or insert a new
-employee as needed, and will generate a new Company ID for the employee if needed.
+Adds a location to the company as defined in the inherited object, not
+overwriting existing locations.
=cut
-sub save {
-
+sub save_new_location {
my ($request) = @_;
-
- my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
- if (!$employee->{employeenumber}){
- my ($ref) = $employee->call_procedure(
- procname => 'setting_increment',
- args => ['employeenumber']
- );
- ($employee->{employeenumber}) = values %$ref;
- }
- $employee->{employee_number}=$employee->{employeenumber};
- $employee->save();
- _render_main_screen($employee);
+ delete $request->{location_id};
+ save_location($request);
}
-=item search
+=item edit
-Displays the search criteria screen
+This is a synonym of get() which is preferred to use for editing operations.
=cut
-sub search {
- my $request = shift @_;
- my $template = LedgerSMB::Template->new(
- user => $request->{_user},
- template => 'filter',
- locale => $request->{_locale},
- path => 'UI/employee',
- format => 'HTML'
- );
- $template->render($request);
+sub edit {
+ get (@_);
}
-=item search_results
+=item delete_location
-Displays search results.
+Deletes the specified location
=cut
-sub search_results {
- my $request = shift @_;
- my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
- my @rows = $employee->search();
- my $template = LedgerSMB::Template->new(
- user => $employee->{_user},
- template => 'form-dynatable',
- locale => $employee->{_locale},
- path => 'UI',
- format => 'HTML'
- );
- my @columns;
- my $locale = $request->{_locale};
- $request->{title} = $locale->text('Search Results');
- for my $col (qw(l_position l_id l_employeenumber l_salutation
- l_first_name l_middle_name l_last_name l_dob
- l_startdate l_enddate l_role l_ssn l_sales l_manager_id
- l_manager_first_name l_manager_last_name)){
- if ($request->{$col}){
- my $pcol = $col;
- $pcol =~ s/^l_//;
- push @columns, $pcol;
- }
+sub delete_location {
+ my ($request) = @_;
+ my $location = LedgerSMB::DBObject::Entity::Location->new(%$request);
+ $location->id($request->{location_id});
+ if (!$request->{is_for_credit}){
+ $location->credit_id(undef);
}
- # Omitting headers for the running number and salutation fields --CT
- my $header = {
- id => $locale->text('ID'),
-employeenumber=> $locale->text('Employee Number'),
- first_name => $locale->text('First Name'),
- middle_name => $locale->text('Middle Name'),
- last_name => $locale->text('Last Name'),
- dob => $locale->text('DOB'),
- startdate => $locale->text('Start Date'),
- enddate => $locale->text('End Date'),
- role => $locale->text('Role'),
- ssn => $locale->text('SSN'),
- sales => $locale->text('Sales'),
- manager_id => $locale->text('Manager ID'),
+ $location->delete;
+ $request->{target_div} = 'address_div';
+ get($request);
+}
+=item save_contact
- manager_first_name => $locale->text('Manager First Name'),
- manager_last_name => $locale->text('Manager Last Name'),
- };
+Saves the specified contact info
- my $pos = 1;
- for my $ref(@rows){
- $ref->{position} = $pos;
- my $href = "employee.pl?action=edit&entity_id=$ref->{entity_id}";
- $ref->{id} = {href => $href,
- text => $ref->{entity_id}};
- $ref->{employeenumber} = { href => $href,
- text => $ref->{employeenumber} };
- ++$pos;
- }
- $template->render({
- form => $request,
- columns => ..hidden..,
- heading => $header,
- rows => ..hidden..,
- });
-}
+=cut
-=item edit
+sub save_contact {
+ my ($request) = @_;
+ my $contact = LedgerSMB::DBObject::Entity::Contact->new(%$request);
+ if ($request->{attach_to} == 1){
+ $contact->credit_id(undef);
+ }
+ $contact->save;
+ $request->{target_div} = 'address_div';
+ $request->{target_div} = 'contact_info_div';
+ get($request);
+}
-displays the edit employee screen. Requires id field to be set.
+=item delete_contact
+Deletes the specified contact info. Note that for_credit is used to pass the
+credit id over in this case.
+
=cut
-sub edit{
- my $request = shift @_;
- my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
- $employee->get();
- _render_main_screen($employee);
+sub delete_contact {
+ my ($request) = @_;
+ my $contact = LedgerSMB::DBObject::Entity::Contact->new(%$request);
+ $contact->credit_id($request->{for_credit});
+ $contact->delete;
+ $request->{target_div} = 'contact_info_div';
+ get($request);
}
-sub _render_main_screen{
- my $employee = shift @_;
- $employee->get_metadata();
- $employee->close_form;
- $employee->open_form;
- $employee->{dbh}->commit;
- $employee->{entity_class} = 3;
- $employee->{creditlimit} = "$employee->{creditlimit}";
- $employee->{discount} = "$employee->{discount}";
- $employee->{script} = "employee.pl";
- if ($employee->is_allowed_role({allowed_roles => [
- "lsmb_$employee->{company}__users_manage"]
- }
- )){
- $employee->{manage_users} = 1;
- }
- $employee->debug({file => '/tmp/emp'});
- my $template = LedgerSMB::Template->new(
- user => $employee->{_user},
- template => 'contact',
- locale => $employee->{_locale},
- path => 'UI/Contact',
- format => 'HTML'
- );
- $template->render($employee);
-}
+=item delete_bank_acct
-=item save_contact
+Deletes the selected bank account record
-Saves contact info and returns to edit employee screen
+Required request variables:
+* bank_account_id
+* entity_id
+* form_id
=cut
-sub save_contact {
+sub delete_bank_account{
my ($request) = @_;
- my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
- $employee->save_contact();
- $employee->get;
- _render_main_screen($employee );
+ my $account = LedgerSMB::DBObject::Entity::Bank->new(%$request);
+ $account->delete;
+ $request->{target_div} = 'bank_act_div';
+ get($request);
}
-=item save_bank_account
+=sub save_bank_account
-Saves bank account information (bic, iban, id required) and returns to the
-edit employee screen
+Adds a bank account to a company and, if defined, an entity credit account.
=cut
sub save_bank_account {
my ($request) = @_;
- my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
- $employee->save_bank_account();
- $employee->get;
- _render_main_screen($employee);
+ my $bank = LedgerSMB::DBObject::Entity::Bank->new(%$request);
+ $bank->save;
+ $request->{target_div} = 'bank_act_div';
+ get($request);
}
-=item save_notes
+=item save_notes($request)
-Attaches note (subject, note, id required) and returns to the edit employee
-screen.
+Saves notes. entity_id or credit_id must be set, as must note_class, note, and
+subject.
=cut
sub save_notes {
my ($request) = @_;
- my $employee = LedgerSMB::DBObject::Employee->new({base => $request});
- $employee->save_notes();
- $employee->get();
- _render_main_screen($employee);
+ my $note = LedgerSMB::DBObject::Entity::Note->new(%$request);
+ if ($request->{note_class} == 1){
+ $note->credit_id(undef);
+ }
+ $note->save;
+ get($request);
}
-
-eval { do "scripts/custom/employee.pl"};
=back
=head1 COPYRIGHT
-Copyright (C) 2009 LedgerSMB Core Team. This file is licensed under the GNU
-General Public License version 2, or at your option any later version. Please
-see the included License.txt for details.
+Copyright (c) 2012, the LedgerSMB Core Team. This is licensed under the GNU
+General Public License, version 2, or at your option any later version. Please
+see the accompanying License.txt for more information.
=cut
-
1;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.