[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4920] trunk
- Subject: SF.net SVN: ledger-smb:[4920] trunk
- From: ..hidden..
- Date: Tue, 19 Jun 2012 09:21:20 +0000
Revision: 4920
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4920&view=rev
Author: einhverfr
Date: 2012-06-19 09:21:20 +0000 (Tue, 19 Jun 2012)
Log Message:
-----------
Basic payroll info tab for employee screen
A few fixes to ar/ap transaction search
Modified Paths:
--------------
trunk/LedgerSMB/Scripts/employee.pm
trunk/sql/Pg-database.sql
trunk/sql/modules/arap.sql
Added Paths:
-----------
trunk/LedgerSMB/DBObject/Entity/Payroll/
trunk/LedgerSMB/DBObject/Entity/Payroll/Deduction.pm
trunk/LedgerSMB/DBObject/Entity/Payroll/Wage.pm
trunk/UI/Contact/divs/wage.html
trunk/sql/modules/Payroll.sql
Added: trunk/LedgerSMB/DBObject/Entity/Payroll/Deduction.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Payroll/Deduction.pm (rev 0)
+++ trunk/LedgerSMB/DBObject/Entity/Payroll/Deduction.pm 2012-06-19 09:21:20 UTC (rev 4920)
@@ -0,0 +1,110 @@
+=head1 NAME
+
+LedgerSMB::DBObject::Entity::Payroll::Deduction - Payroll Deduction handling for
+LedgerSMB
+
+=head1 SYNPOSIS
+
+To retrieve a list of deductions for an entity:
+
+ my @deducts = LedgerSMB::DBObject::Entity::Person::Deductions->list(
+ $entity_id
+ );
+
+To retrieve a list of deduction categories for selection:
+ my @types = LedgerSMB::DBObject::Entity::Person::Deduction->types(
+ $country_id
+ );
+
+To save a new deduction:
+
+ my $deduct= LedgerSMB::DBObject::Entity::Person::Deduction->new(%$request);
+ $deduct->save;
+
+=cut
+
+package LedgerSMB::DBObject::Entity::Payroll::Deduction;
+use Moose;
+extends 'LedgerSMB::DBObject_Moose';
+
+=head1 PROPERTIES
+
+=over
+
+=item entry_id
+
+This is the entry id (when set) of the deduction.
+
+=cut
+
+has entry_id => (is => 'rw', isa => 'Maybe[Int]');
+
+=item type_id
+
+This is the class id of the deduction
+
+=cut
+
+has type_id => (is => 'rw', isa => 'Int');
+
+=item rate
+
+The rate handling here is deduction class specific. Some deductions may be
+percentages of income, they may be fixed amounts, or they may be calculated on
+some other basis. Therefore.....
+
+=cut
+
+has rate => (is => 'rw', isa => 'Num');
+
+=back
+
+=head1 METHODS
+
+=over
+
+=item list($entity_id)
+
+Retrns a list of deduction objects for entity
+
+=cut
+
+sub list {
+ my ($self, $entity_id) = @_;
+ return $self->call_procedure(procname => 'deduction__list_for_entity',
+ args => [$entity_id]);
+}
+
+=item classes($country_id)
+
+Returns a list of deduction classes
+
+=cut
+
+sub types{
+ my ($self, $country_id) = @_;
+ return $self->call_procedure(procname => 'deduction__list_types',
+ args => [$country_id]);
+}
+
+=item save
+
+Saves the deduction and attaches to the entity record
+
+=cut
+
+sub save {
+ my ($self) = @_;
+ my ($ref) = $self->exec_method({funcname => 'deduction__save'});
+ $self->entry_id($ref->{entry_id});
+}
+
+=back
+
+=head1 COPYRIGHT
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
Added: trunk/LedgerSMB/DBObject/Entity/Payroll/Wage.pm
===================================================================
--- trunk/LedgerSMB/DBObject/Entity/Payroll/Wage.pm (rev 0)
+++ trunk/LedgerSMB/DBObject/Entity/Payroll/Wage.pm 2012-06-19 09:21:20 UTC (rev 4920)
@@ -0,0 +1,105 @@
+=head1 NAME
+
+LedgerSMB::DBObject::Entity::Payroll::Wage - Wages and Salary Handling
+for LedgerSMB
+
+=head1 SYNPOSIS
+
+To retrieve a list of wages for an entity:
+
+ my @wages = LedgerSMB::DBObject::Entity::Person::Wage->list($entity_id);
+
+To retrieve a list of wage categories for selection:
+ my @classes = LedgerSMB::DBObject::Entity::Person::Wage->classes($entity_id);
+
+To save a new wage:
+
+ my $wage = LedgerSMB::DBObject::Entity::Person::Wage->new(%$request);
+ $wage->save;
+
+=cut
+
+package LedgerSMB::DBObject::Entity::Payroll::Wage;
+use Moose;
+extends 'LedgerSMB::DBObject_Moose';
+
+=head1 PROPERTIES
+
+=over
+
+=item entry_id
+
+This is the entry id (when set) of the wage.
+
+=cut
+
+has entry_id => (is => 'rw', isa => 'Maybe[Int]');
+
+=item type_id
+
+This is the class id of the wage (when set)
+
+=cut
+
+has type_id => (is => 'rw', isa => 'Int');
+
+=item rate
+
+This is the rate that one is paid. Depending on class could be hourly, per
+month, or per unit produced.
+
+=cut
+
+has rate => (is => 'rw', isa => 'Num');
+
+=back
+
+=head1 METHODS
+
+=over
+
+=item list($entity_id)
+
+Retrns a list of wage objects for entity
+
+=cut
+
+sub list {
+ my ($self, $entity_id) = @_;
+ return $self->call_procedure(procname => 'wage__list_for_entity',
+ args => [$entity_id]);
+}
+
+=item classes($country_id)
+
+Returns a list of wage classes
+
+=cut
+
+sub types{
+ my ($self, $country_id) = @_;
+ return $self->call_procedure(procname => 'wage__list_types',
+ args => [$country_id]);
+}
+
+=item save
+
+Saves the wage and attaches to the entity record
+
+=cut
+
+sub save {
+ my ($self) = @_;
+ my ($ref) = $self->exec_method({funcname => 'wage__save'});
+ $self->entry_id($ref->{entry_id});
+}
+
+=back
+
+=head1 COPYRIGHT
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
+
+1;
Modified: trunk/LedgerSMB/Scripts/employee.pm
===================================================================
--- trunk/LedgerSMB/Scripts/employee.pm 2012-06-19 02:42:31 UTC (rev 4919)
+++ trunk/LedgerSMB/Scripts/employee.pm 2012-06-19 09:21:20 UTC (rev 4920)
@@ -17,6 +17,8 @@
package LedgerSMB::Scripts::employee;
use LedgerSMB::DBObject::Entity::Person::Employee;
+use LedgerSMB::DBObject::Entity::Payroll::Wage;
+use LedgerSMB::DBObject::Entity::Payroll::Deduction;
use LedgerSMB::DBObject::Entity::Location;
use LedgerSMB::DBObject::Entity::Contact;
use LedgerSMB::DBObject::Entity::Bank;
@@ -87,7 +89,7 @@
# DIVS logic
my @DIVS;
if ($employee->{entity_id}){
- @DIVS = qw(employee user address contact_info bank_act notes);
+ @DIVS = qw(employee user wage address contact_info bank_act notes);
} else {
@DIVS = qw(employee);
}
@@ -96,6 +98,7 @@
my %DIV_LABEL = (
employee => $locale->text('Employee'),
user => $locale->text('User'),
+ wage => $locale->text('Wages/Deductions'),
address => $locale->text('Addresses'),
contact_info => $locale->text('Contact Info'),
bank_act => $locale->text('Bank Accounts'),
@@ -176,9 +179,6 @@
format => 'HTML'
);
- use Data::Dumper;
- $Data::Dumper::Sortkeys = 1;
- #die '<pre>' . Dumper($request) . '</pre>';
my @country_list = $request->call_procedure(
procname => 'location_list_country'
);
@@ -187,6 +187,23 @@
);
my @roles = LedgerSMB::DBObject::Entity::User->list_roles;
+ my @wage_types = LedgerSMB::DBObject::Entity::Payroll::Wage->types(
+ $employee->country_id
+ ) if $employee->can('country_id');
+
+ my @deduction_types =
+ LedgerSMB::DBObject::Entity::Payroll::Deduction->types(
+ $employee->country_id
+ ) if $employee->can('country_id');
+
+ my @wages = LedgerSMB::DBObject::Entity::Payroll::Wage->list(
+ $employee->entity_id
+ ) if $employee->can('entity_id');
+
+ my @deductions = LedgerSMB::DBObject::Entity::Payroll::Deduction->list(
+ $employee->entity_id
+ ) if $employee->can('entity_id');
+
$template->render({
DIVS => ..hidden..,
DIV_LABEL => \%DIV_LABEL,
@@ -194,6 +211,10 @@
employee => $employee,
user => $user,
roles => ..hidden..,
+ wages => ..hidden..,
+ deductions => ..hidden..,
+ wage_types => ..hidden..,
+ deduction_types => ..hidden..,
country_list => ..hidden..,
locations => ..hidden..,
contacts => ..hidden..,
Added: trunk/UI/Contact/divs/wage.html
===================================================================
--- trunk/UI/Contact/divs/wage.html (rev 0)
+++ trunk/UI/Contact/divs/wage.html 2012-06-19 09:21:20 UTC (rev 4920)
@@ -0,0 +1,72 @@
+<div class="container" id="wage_div">
+<?lsmb
+columns = [{ col_id = 'type', name = text('Type'), type = 'text' },
+ { col_id = 'rate', name = text('Amount/Rate'), type = 'text' }];
+
+PROCESS dynatable
+ columns = columns
+ attributes = {id = 'wage-table', width='100%' }
+ t_body = {rows = wages};
+
+PROCESS dynatable
+ columns = columns
+ attributes = {id = 'deduction-table', width='100%' }
+ t_body = {rows = deductions}; ?>
+
+<table>
+<tr>
+<form action="<?lsmb script ?>" method="post" name="wage">
+<td><?lsmb PROCESS select element_data = {
+ options = wage_types
+ value_attr = 'id'
+ text_attr = 'label'
+ name = 'type_id'
+} ?></td>
+<td><?lsmb PROCESS input element_data = {
+ name = 'rate'
+ value = rate
+ class = 'number'
+ type = 'text'
+} ?></td>
+<?lsmb PROCESS input element_data = {
+ name = 'entity_id'
+ type = 'hidden'
+ value = entity_id
+} ?>
+<td><?lsmb PROCESS button element_data = {
+ text = text('Add/Change Wage') #'
+ name = 'action'
+ type = 'submit'
+ class = 'submit'
+} ?></td>
+</form>
+</tr>
+<tr>
+<form action="<?lsmb script ?>" method="post" name="deduction">
+<td><?lsmb PROCESS select element_data = {
+ options = deduction_types
+ value_attr = 'id'
+ text_attr = 'label'
+ name = 'type_id'
+} ?></td>
+<td><?lsmb PROCESS input element_data = {
+ name = 'rate'
+ value = rate
+ class = 'number'
+ type = 'text'
+} ?></td>
+<?lsmb PROCESS input element_data = {
+ name = 'entity_id'
+ type = 'hidden'
+ value = entity_id
+} ?>
+<td><?lsmb PROCESS button element_data = {
+ text = text('Add/Change Deductions') #'
+ name = 'action'
+ type = 'submit'
+ class = 'submit'
+} ?></td>
+</form>
+</tr>
+</table>
+</div>
Modified: trunk/sql/Pg-database.sql
===================================================================
--- trunk/sql/Pg-database.sql 2012-06-19 02:42:31 UTC (rev 4919)
+++ trunk/sql/Pg-database.sql 2012-06-19 09:21:20 UTC (rev 4920)
@@ -931,6 +931,14 @@
references payroll_income_class(id, country_id)
);
+CREATE TABLE payroll_wage (
+ entry_id serial not null unique,
+ entity_id int references entity(id),
+ type_id int references payroll_income_type(id),
+ rate numeric not null,
+ PRIMARY KEY(entity_id, type_id)
+);
+
CREATE TABLE payroll_employee_class (
id serial not null unique,
label text primary key
@@ -951,7 +959,7 @@
);
CREATE TABLE payroll_deduction_type (
- itype_id serial not null unique,
+ id serial not null unique,
account_id int not null references account(id),
pic_id int not null,
country_id int not null,
@@ -963,6 +971,14 @@
references payroll_income_class(id, country_id)
);
+CREATE TABLE payroll_deduction (
+ entry_id serial not null unique,
+ entity_id int references entity(id),
+ type_id int references payroll_deduction_type(id),
+ rate numeric not null,
+ PRIMARY KEY(entity_id, type_id)
+);
+
CREATE TABLE payroll_report (
id serial not null primary key,
ec_id int not null references payroll_employee_class(id),
Added: trunk/sql/modules/Payroll.sql
===================================================================
--- trunk/sql/modules/Payroll.sql (rev 0)
+++ trunk/sql/modules/Payroll.sql 2012-06-19 09:21:20 UTC (rev 4920)
@@ -0,0 +1,73 @@
+BEGIN;
+-- WAGE FUNCTIONS
+CREATE OR REPLACE FUNCTION wage__list_for_entity(in_entity_id int)
+RETURNS SETOF payroll_wage AS
+$$
+SELECT * FROM payroll_wage WHERE entity_id = $1;
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION wage__list_types(in_country_id int)
+RETURNS SETOF payroll_income_type AS
+$$
+SELECT * FROM payroll_income_type where country_id = $1
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION wage__save
+(in_rate numeric, in_entity_id int, in_type_id int)
+RETURNS SETOF payroll_wage
+AS
+$$
+BEGIN
+
+UPDATE payroll_wage
+ SET rate = in_rate
+ WHERE entity_id = in_entity_id and in_type_id;
+
+
+IF NOT FOUND THEN
+ INSERT INTO payroll_wage (entity_id, type_id, rate)
+ VALUES (in_entity_id, in_type_id, in_rate);
+END IF;
+
+RETURN QUERY SELECT * FROM payroll_wage
+ WHERE entity_id = in_entity_id and in_type_id;
+END;
+$$ language plpgsql;
+
+-- DEDUCTION FUNCTINS
+CREATE OR REPLACE FUNCTION deduction__list_for_entity(in_entity_id int)
+RETURNS SETOF payroll_deduction AS
+$$
+SELECT * FROM payroll_deduction WHERE entity_id = $1;
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION deduction__list_types(in_country_id int)
+RETURNS SETOF payroll_deduction_type AS
+$$
+SELECT * FROM payroll_deduction_type where country_id = $1
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION deductin__save
+(in_rate numeric, in_entity_id int, in_type_id int)
+RETURNS SETOF payroll_deduction
+AS
+$$
+BEGIN
+
+UPDATE payroll_deduction
+ SET rate = in_rate
+ WHERE entity_id = in_entity_id and in_type_id;
+
+
+IF NOT FOUND THEN
+ INSERT INTO payroll_deduction (entity_id, type_id, rate)
+ VALUES (in_entity_id, in_type_id, in_rate);
+END IF;
+
+RETURN QUERY SELECT * FROM payroll_deduction
+ WHERE entity_id = in_entity_id and in_type_id;
+END;
+$$ language plpgsql;
+
+
+COMMIT;
Modified: trunk/sql/modules/arap.sql
===================================================================
--- trunk/sql/modules/arap.sql 2012-06-19 02:42:31 UTC (rev 4919)
+++ trunk/sql/modules/arap.sql 2012-06-19 09:21:20 UTC (rev 4920)
@@ -112,17 +112,17 @@
$$
BEGIN
RETURN QUERY
- SELECT null::int, null::text, null::text, null::text, null::date
- entity_name, meta_number, entity_id, sum(amount),
+ SELECT null::int, null::bool, null::text, null::text, null::text,
+ null::date, entity_name, meta_number, entity_id, sum(amount),
sum(amount_paid), sum(tax), currency, null::date, null::date,
- tull::text, null::text, null::text, null::text[]
+ null::text, null::text, null::text, null::text[]
FROM ar_ap__transaction_search
(in_account_id, in_name_part, in_meta_number, in_invnumber,
in_ordnumber, in_ponumber, in_source, in_description,
in_notes, in_shipvia, in_from_date, in_to_date,
in_on_hold, in_inc_open, in_inc_closed, in_as_of,
in_entity_class)
- GROUP BY entity_name, meta_number, entity_id;
+ GROUP BY entity_name, meta_number, entity_id, currency;
END;
$$ language plpgsql;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.