[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[5107] trunk
- Subject: SF.net SVN: ledger-smb:[5107] trunk
- From: ..hidden..
- Date: Tue, 07 Aug 2012 15:03:42 +0000
Revision: 5107
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=5107&view=rev
Author: einhverfr
Date: 2012-08-07 15:03:42 +0000 (Tue, 07 Aug 2012)
Log Message:
-----------
Initial commit of payroll income type perl and SQL code. Still need workflow scripts, templates, and search routines
Modified Paths:
--------------
trunk/sql/modules/Payroll.sql
Added Paths:
-----------
trunk/LedgerSMB/Payroll/
trunk/LedgerSMB/Payroll/Income_Type.pm
Added: trunk/LedgerSMB/Payroll/Income_Type.pm
===================================================================
--- trunk/LedgerSMB/Payroll/Income_Type.pm (rev 0)
+++ trunk/LedgerSMB/Payroll/Income_Type.pm 2012-08-07 15:03:42 UTC (rev 5107)
@@ -0,0 +1,144 @@
+=head1 NAME
+
+LedgerSMB::Payroll::Income_Type - Income Types for LedgerSMB's Payroll Engine
+
+=head1 SYNOPSIS
+
+To get a type
+
+ my $itype = LedgerSMB::Payroll::Income_Type->get($id)
+
+To save a type
+
+ $itype->save()
+
+=cut
+
+package LedgerSMB::Payroll::Income_Type;
+use Moose;
+with 'LedgerSMB::DBObject_Moose';
+
+=head1 DESCRIPTION
+
+Income types are one of two of the main building blocks of the LedgerSMB's
+payroll engine. These represent the building blocks of gross income before
+deductions and taxes.
+
+Income types are categorized into tax-jurisdiction-dependent classes. In the
+US, for example, we might see Pay-for-production, hourly, salary, and salary
+exempt. Income types are organization-specific manifestations of these. For
+example, an organization may employ some hourly workers, some salary workers,
+and some salary exempt workers but may want to split up expense reporting on
+the income statement. Similearly different classes might be used to indicate
+different default amounts, or to track efforts worked for profit sharing and
+other purposes. Employees are attached to income types and deduction type,
+allowing organizations to set up payroll flexibly for their own businesses.
+
+=head1 PROPERTIES
+
+=over
+
+=item id int
+
+The id. Saving returns a new id with this set.
+
+=cut
+
+has id => (is => 'ro', isa => 'Int', required => 0);
+
+=item account_id int
+
+This is the account to report the income in. It is required.
+
+=cut
+
+has account_id => (is => 'ro', isa => 'Int', required => 1);
+
+=item pic_id int
+
+This is the payroll income class. These are not defined through the user
+interface but rather defined country-wise. It is required.
+
+=cut
+
+has pic_id => (is => 'ro', isa => 'Int', required => 1);
+
+=item country_id int
+
+This is the id of the country. It is required.
+
+=cut
+
+has country_id => (is => 'ro', isa => 'Int', required => 1);
+
+=item label text
+
+This is the human-readable designation for the income type.
+
+=cut
+
+has label => (is => 'ro', isa => 'Str', required => 1);
+
+=item unit text
+
+This is a human-readable label for unit of work. Perhaps "hour" or "month' for
+US would be the most common values.
+
+=cut
+
+has unit => (is => 'ro', isa => 'Str', required => 1);
+
+=item default_amount numeric
+
+This is the default amount for each unit of work. It can be overridden for each
+employee.
+
+=cut
+
+has default_amount => (is => 'ro', isa => 'Num', required => 1);
+
+=back
+
+=head1 METHODS
+
+=over
+
+=item get($id)
+
+Retrieves an income type by id from the database and returns it to the
+application.
+
+=cut
+
+sub get {
+ my ($self, $id) = @_;
+ my ($ref) = __PACKAGE__->call_procedure(
+ procname => 'payroll_income_type__get', args => [$id]
+ );
+ return __PACKAGE__->new(%$ref);
+}
+
+=item save()
+
+This saves the entry to the database and returns a new object with ID and other
+defaults set as applicable.
+
+=cut
+
+sub save {
+ my ($self, $id) = @_;
+ my ($ref) = $self->exec_method({funcname => 'payroll_income_type__save'});
+ return $self->new($ref);
+}
+
+=back
+
+=head1 COPYRIGHT
+
+COPYRIGHT (C) 2012 The LedgerSMB Core Team. This file may be re-used under the
+terms of the LedgerSMB General Public License version 2 or at your option any
+later version. Please see enclosed LICENSE file for details.
+
+=cut
+
+__PACKAGE__->meta->make_immutable;
Modified: trunk/sql/modules/Payroll.sql
===================================================================
--- trunk/sql/modules/Payroll.sql 2012-08-07 03:09:43 UTC (rev 5106)
+++ trunk/sql/modules/Payroll.sql 2012-08-07 15:03:42 UTC (rev 5107)
@@ -47,7 +47,7 @@
SELECT * FROM payroll_deduction_type where country_id = $1
$$ language sql;
-CREATE OR REPLACE FUNCTION deductin__save
+CREATE OR REPLACE FUNCTION deduction__save
(in_rate numeric, in_entity_id int, in_type_id int)
RETURNS SETOF payroll_deduction
AS
@@ -69,5 +69,50 @@
END;
$$ language plpgsql;
+CREATE OR REPLACE FUNCTION payroll_income_type__get(in_id int)
+RETURNS payroll_income_type AS $$
+SELECT * FROM payroll_income_class WHERE id = $1;
+$$ LANGUAGE SQL;
+CREATE OR REPLACE FUNCTION payroll_income_category__list()
+RETURNS SETOF payroll_income_category AS $$
+SELECT * FROM payroll_income_category order by id;
+$$ LANGUAGE SQL;
+
+CREATE OR REPLACE FUNCTION payroll_income_class__for_country(in_country_id int)
+RETURNS SETOF payroll_income_class AS
+$$
+SELECT * FROM payroll_income_class where country_id = $1
+ORDER BY label;
+$$ language sql;
+
+CREATE OR REPLACE FUNCTION payroll_income_type__save(
+in_id int, in_account_id int, in_pic_id int, in_country_id int,
+in_label text, in_unit text, in_default_amount numeric
+) RETURNS payroll_income_type AS $$
+BEGIN
+
+ UPDATE payroll_income_type
+ SET account_id = in_account_id,
+ pic_id = in_pic_id,
+ country_id = in_country_id,
+ label = in_label,
+ unit = in_unit,
+ default_amount = in_default_amount
+ WHERE id = in_id;
+
+ IF FOUND THEN
+ RETURN payroll_income_type__get(in_id);
+ END IF;
+
+ INSERT INTO payroll_income_type
+ (account_id, pic_id, country_id, label, unit, default_amount)
+ VALUES (in_account_id, in_pic_id, in_country_id, in_label, in_unit,
+ in_default_amount);
+
+ RETURN payroll_income_type__get(currval('payroll_income_type_id_seq')::int);
+
+END;
+$$ LANGUAGE PLPGSQL;
+
COMMIT;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.