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.