Topic: Payroll Module Development

I am in the process of migrating away from quickbooks to Frontaccounting. My quickbooks software (Pro 2009) is going to cripple its payroll function as of May 31, so I'm trying to build a simple payroll module for FA and get everything moved over before then. So far, I've combed through the core code and I've gotten as far as building an employee database table with an input/edit form on the front end. Woohoo!

My idea is to make the payroll system fairly agnostic. As I see it, US payroll uses three types of calculations:
Tiered percentage -
percent witheld based on certain income levels with allowances for household members (ie. income tax witholding)

Limited percentage -
percentage taken up a certain yearly limit (ie Unemployment Tax)

Straight percentage -
simple percentage of gross pay (ie Medicare)

So, I'm thinking of having a form to input these different levels and percentages and run the calculations based on that.

I'm looking for ideas, best practices, help in implementation, etc. I'll be submitting this to the community when I get it working.

Re: Payroll Module Development

One specific question I have is how to integrate the payroll into the current bank transaction (check writing) form, and being able to see all the taxes/deductions itemized.

All ideas coveted.

Re: Payroll Module Development

I've started the process payroll form and I'd like to get some feedback.
I'd like to be able to select the employees to pay, but I don't know how to check whether they have been selected and then send only those employees to the calculation page. If there's a better way to do this, I'm open.

Here's what I have so far:

<?php
/*
  Paycheck.php
  Begin to process paychecks
    list employees, enter hours, set pay period
    submit for calculation and review
*/

/////////////////////////////////////////////////////
//Includes
/////////////////////////////////////////////////////
$page_security = 'SA_PAYROLL';
$path_to_root="../..";

include($path_to_root . "/includes/session.inc");
add_access_extensions();

$js = "";
if ($use_popup_windows)
    $js .= get_js_open_window(900, 500);
if ($use_date_picker)
    $js .= get_js_date_picker();

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");


/////////////////////////////////////////////////////
//Functions
/////////////////////////////////////////////////////

function payperiod_settings(){

  start_outer_table(TABLESTYLE2);
  table_section(1);
  date_row("Pay Period Ends:", 'PayPeriodEnd');
  date_row("Check date:", "CheckDate");

  table_section(2);
  bank_accounts_list_row("Bank Account:", "BankAccount");
  end_outer_table(1);
}

//--------------------------------------------------------------------------------------------
function get_employees(){
  //get all active employees
  $sql = "SELECT emp_id, emp_name, emp_paytype FROM ".TB_PREF."employees WHERE inactive = 0";

  $result = db_query($sql, "The employee table is inaccessible");

  return $result;
}

//--------------------------------------------------------------------------------------------
//display the list of employees
function list_employees($list){

    start_table(TABLESTYLE, "width=60%");

    $th = array(("check"),_("Name"), _("Hours"), _("Salary"));//add columns for commission, overtime, etc
    table_header($th);

      $k = 0;
      while ($myrow = db_fetch($list)){
      alt_table_row_color($k);
      check_cells(null, "check".$myrow["emp_id"], '', '', '', "width=15 align=center");//select employees to pay
      label_cell($myrow["emp_name"]);

      if ($myrow['emp_paytype'] == 'hr'){
        text_cells(null, 'hours'.$myrow["emp_id"], "get_last_hours()", 8, 4);//pre-fill this with hours from last paycheck?
      } else {
        echo "<td></td>";//blank cell for non hourly employees
      }

      if ($myrow['emp_paytype'] == 'sal'){
        text_cells(null, 'salary'.$myrow["emp_id"], null, 8, 4);//show something?
      } else {
        echo "<td></td>";//blank cell for non salaried employees
      }

      end_row();
      }

    end_table(1);

    div_start('controls');
    submit_center('submit', _("Proceed"), true, '', 'default');
    div_end();

}

//--------------------------------------------------------------------------------------------
function get_last_hours($id){
  //
}

//--------------------------------------------------------------------------------------------
function can_process(){
  //is at least one employee checked?
  
  //do all the checked hourly employees have positive hours listed?

  return true;
}

//--------------------------------------------------------------------------------------------
function handle_submit(){

  if (!can_process())
    return;

  //hand off to calculation/review page

}


/////////////////////////////////////////////////////
//Page Flow
/////////////////////////////////////////////////////
page("Enter Paycheck Information");

//display top table with date, check, and account info
payperiod_settings();


//display bottom table with employee info
$result = get_employees();
if (!$result)
  display_notification("There are no employees to pay.");
else
  list_employees($result);


end_page();

?>  
 

Re: Payroll Module Development

I've created some simple calculation functions and I've been able to figure the various payroll amounts correctly. I could use some help in posting the values to the GL. It looks like the Bank Account Payment Entry is using a cart to handle entries, but I'm not seeing how they are posted. Any help is appreciated.

Thank you,
-Joshua

Re: Payroll Module Development

Hello,
I have no programming knowledge but I know that when you get this module up and running it will be well recieved by all users. Has anybody from FrontAccounting been assisting you?
Bill

Re: Payroll Module Development

I hope it is helpful. So far, you have been the only person to respond.

Joshua

Re: Payroll Module Development

Joshua,

The project I am working on for which I am studying FrontAccounting has me a bit confused. I believe you could shed some light on the subject. Would you please contact me off this forum at whtemple1959@gmail.com?

Thanks,
Bill

Re: Payroll Module Development

You will need to allow for different groups of employees being paid on different days on different pay cycles.

In general you should avoid data entry columns specific to any type of pay such as salary or commission. Your database structure should support the user definition of pay items similar to inventory items, and have a pay cart built using those pay items.

When defining your database structures avoid including any columns that are specific to any one country.  Instead, you could create attribute tables linked to the core common data tables. The basic calculated payslip items should only need a quantity column, a rate and a calculated cash amount.

Avoid holding any accumulated totals in any tables. Always output totals by accumulating the core calculated payslip items. Using attributes linked to the pay items to define report categories it makes it relatively easy to create reports for different countries requirements.

I hope I have not been too discouraging.

Re: Payroll Module Development

Asro,
So far, we're on the same page.
I haven't implemented a scheduling system, but I have allowed for different pay frequencies per employee.

I have not set up the pay types yet. I just have salary/hourly options to test this as I build. There has to be some basis for the calculations, right? The system has to know that hourly rates (including overtime, etc) and piecework are calculated as pay per unit. Salary is a yearly figure. Commission, tips, bonus, etc are lump sum payments. Given these basic types of calculations (pay per unit, yearly sum, lump sum), the user could set up different pay types and rates. I was planning to eventually connect the salesperson commission tracking to this payroll setup.

I have avoided as much as possible any set tax definitions. There shouldn't be anything in here that is country specific. I have different functions to handle different types of calculations (as I mentioned in the first post). Here they are:

//complex tiered percentage calculation
//--------------------------------------------------------------------------------------------
function calculate_tiered($gross, $tiered_array, $allowances, $per_allowance, $payfreq){
  //$tiered_array is an array of thresholds => percentages as annual figures
  //returns the amount of tax owed
  
  //get the allowance for this pay period
  $allowance = ($allowances * $per_allowance)/$payfreq;

  $net = $gross - $allowance;

  $tax = 0;
  $last_threshold = 0;
  foreach($tiered_array as $threshold => $percent){
    //convert the annual figures to pay period figures
    $period_threshold = round($threshold/$payfreq, 0);//round to whole dollars (per IRS tables)
    //compare pay to each threshold and calculate tax accordingly
    if ($net <= $period_threshold){
      $tax += round(($net-$last_threshold)*$percent/100, 2);
      break;
    } else {
      $tax += round(($period_threshold-$last_threshold)*$percent/100, 2);
    }
    $last_threshold = $period_threshold;
  }

  return $tax;
}

//advanced percentage calculation with a threshold
//--------------------------------------------------------------------------------------------
function calculate_adv_percent($gross, $rate_array, $ytd){
  //$rate_array is an array of 1 threshold => percentage
  $threshold = key($rate_array);
  $percent = current($rate_array);

  //have we met the threshold?
  if ($ytd < $threshold){
    //will this paycheck push us over the threshold?
    if ($ytd + $gross >= $threshold){
      //yes, only calculate tax on the remaining amount
      $tax = round(($threshold - $ytd)*$percent/100, 2);
    } else {
      //no, calculate tax on the entire amount
      $tax = round($gross*$percent/100, 2);
    }
  } else {
    //threshold met, no more tax owed
    $tax = 0;
  }
  return $tax;
}

//simple percentage calculation
//--------------------------------------------------------------------------------------------
function calculate_percent($gross, $percent){
  $percent = current($percent);//$percent comes in as an array as with the other calculators
  $tax = round($gross*$percent/100, 2);
  return $tax;
}

I don't quite understand what you mean by attribute tables. Please explain this more.

As for holding totals, I would like to insert paychecks as journal entries. Should there be a separate table just for paycheck journal entries?

You've not been discouraging at all. I really appreciate the feedback.

Re: Payroll Module Development

For the attribute table, I meant something similar to the sys_prefs table in FA, but linked to each of the main entities in the payroll. If you have a pay items table similar in purpose to the FA items table, the pay item table itself would not have any columns specific to any one country but have a table linked to it to contain all the values of what would be country specific columns in the pay item table. I don't think you'd include the type and length of each attribute in the attribute table, unlike the FA sys_prefs table, but should probably have a separate attributes index table that defined all the possible attributes, their types and lengths and scope.

The payroll pay item attribute table would then just have the pay item id, the attribute index id, and the value specific to this pay item.

For example, the pay item table would have a code, description, a link to an FA expense account and fields to declare how the pay item is to be calculated. A pay item record for a salary would have a calculation method field that linked the pay item to the salary calculation function, and a separate tax pay item would link the item to the tax calculation function. But there are other attributes linked to a pay item that would have to be associated with specific countries, such as a tax category to indicate how that pay item is to be reported for tax, or perhaps how that pay item might be included in the total from which another pay item is calculated. Those types of attributes should not be columns within the pay item table, but perhaps each value stored as a separate record in a 'pay item attributes' table, linked to the pay item.

It then becomes possible to easily add processing for new countries whilst not upsetting the processing for countries already defined. You'd need attributes tables linked to each of the main entities in the payroll: the company, employees, pay items and payslip (pay check) records.

Adding a new country to the framework then means simply adding the new attributes, calculation functions and country specific reports. Hopefully the core tables would not need changing, but you might need to add country specific reference tables: the UK needs tiered National Insurance rate tables as well as tiered tax tables, and different countries quite often have different fields for each tax tier. For Australia there are two percentage rates involved in the tax calculation. For UK, you have to flag which tier is the basic rate tax, and so on.

I think you do need a separate table for payslips and payslip items, just as FA has sales order and sales order details, and the GL entries are generated from them. The payslip and payslip items tables also need their own attribute tables as some countries require values to be carried forward from pay to pay.

I have followed this design for a PC payroll system that is sold in Australia, New Zealand, United Kingdom, and several Pacific islands. It's worked quite well so far and it's relatively easy for me to extend the software for new countries. I had considered adding a payroll module to FA myself based on the same design, but I am a bit tied up with support and enhancements for that other payroll and don't have much time left.

Re: Payroll Module Development

I'm sure that is a great explanation - it looks quite thorough - but it went right over my head. I probably should not be the person making this module, but I want to get away from quickbooks. I'll do my best.

12 (edited by serbanc 04/14/2012 08:00:27 pm)

Re: Payroll Module Development

Hello gents,

i was considering writing a module for payroll, but maybe we can join forces.

As I am living in Romania, I am mostly interested in a payroll module for Romania.

Aside from various country specifics you mentioned, in RO we have a deduction - aka an amount that is subtracted from base amount - for tax income calculation.
The amount itself is calculated based on a table(gross income, # of persons, formula)=>deduction amount.

LE: and of course, I would like to create an user for each employee, so that they can see/check their payslip and submit their vacation requirements (approval/etc).
and to generate MT100 files for bulk bank payment
and (localized and country specific) to be able to generate electronic statements for authorities.

Whether I can help, otherwise than making specs, please say.

Regards,
S

Re: Payroll Module Development

It should not be terribly difficult to add a new calculation type to what I already have set up. Check out the post above where I listed the calculation functions I have made. If the tiered rate function will work, that would be great. Otherwise, perhaps you could write a new function using these as a model. I'll put it in there.

I am making progress on this, but I'm a slow coder so it's still going to be a little while.

Re: Payroll Module Development

It sounds like most of the stuff in your edit could be handled by generating reports. I haven't done any reports yet, but from what I've read, it should be easier than creating a module. Fa already has the ability to create users with different limited permissions,  so you could generate payslip and bank reports based on who is logged in.
I haven't really done any projects quite like this before, so I don't know how to break this up for distributed development, except for the kind of things you're talking about with the reports and whatnot.

Re: Payroll Module Development

yes, creating reports is generally easier.

ref. distributed development.
I can setup a dev environment on a server, but I would ask the admins the consider a "community" repository on SF.

Re: Payroll Module Development

dear sticmann, I have one question:
have you considered this: Anahaw Open Payroll System ? https:/sourceforge.net/projects/openpayroll/

it seems that it is integrated with weberp - the ancestor of FA....
Perhaps it is easier to use and integrate.

Re: Payroll Module Development

serbanc,
I looked at several other open source payroll solutions, but I had not seen Anahaw. I am far enough into this that I'd rather not start over with something else if possible. I also noticed it has a 29% user approval rating...

I've progressed to the point of having a paycheck processed and ready to insert as a journal entry. I'm very open to pushing the code up for public perusal. If anyone wants to help, this would be a fantastic point to jump in. smile

Re: Payroll Module Development

sticmann,
it was just an ideea, I did not knew how advanced are you.

If you can share the code, I would jump in smile

Re: Payroll Module Development

Progress is being made and the code is available here http://code.google.com/p/fa-payroll-module/ to look at. Serbanc is a more accomplished coder than I am so I have high hopes for this project. It is currently not anywhere close to functional, but you are free to browse the code and the wiki to see where it's going.

20 (edited by Farhaj 07/11/2012 05:35:08 am)

Re: Payroll Module Development

after completion of Fixed asset module we are working on payroll and HR module.

following are list of features.


Payroll Module   
   
S. No    Options
1    Location Setup
2    Department Setup
3    Bank Setup
4    Designation Setup
5    Grade Setup
6    Gazetted Holidays Setup
7    Qualification Setup
8    Employee Information
9    Leave Setup
10    Leave Inquiry and Approved Setup
11    Loan Setup
12    Loan Inquiry and Approved
13    Breakup Salary Inquiry
14    Process Month
15    JV posting
16    Pay Slip  (Report)
17    Bank Draft (Report)
   
   
HR Module   
   
S.No    Options
1    Advertisement
2    Applicant
3    Upload CV
4    Inquiry Applicant Form View/Edit/CV/Approved
5    Interview Inquiry Interview Date/Final Interview
6    Applicant  Appointent Letter
7    Applicant Extended Letter
8    Applicant Termination
9    Applicant  Confirmation
10    Evaluation Form
11    Increment and Promotion Form
12    Increment and Promotion Form Approved
13    Increment and Promotion Letter

Re: Payroll Module Development

Farhaj,
You should join the developers list and discuss this with Janusz. He already has a proposed DB structure in place. You could talk with him about moving forward.

Re: Payroll Module Development

Hello,
I have zero development knowledge but I know that when you acquire this component up and also flowing it ought to be well recieved by every one of the people. Has any person from FrontAccounting been assisting you?
Bill

Re: Payroll Module Development

Yes, several guys here have gotten onboard to help, including Janusz. The module now has multi-national aspirations that reach far beyond the simple little thing I originally had in mind. If it is realized, it will be a very helpful add-on.

Re: Payroll Module Development

I have developed HR and payroll module,you all can test it from this url below.

http://bahriatravels.com/erp/ie3/

user id= admin
pass word= 123456

please give me suggestions.

Regards,
Farhaj

Re: Payroll Module Development

I hope it is helpful. So far, you have been the particular individual to respond.