Bug in Advanced Percent (Tax Bracket Alternate)?

Discussion for TimeTrex open source community developers.
Locked
allanregistos
Posts: 41
Joined: Wed Oct 21, 2009 11:56 pm
Location: Philippines
Contact:

Bug in Advanced Percent (Tax Bracket Alternate)?

Post by allanregistos »

I have a tax calculation of 8 brackets for each employee based on Advanced Percent (Tax Bracket Alternate) calculation type.
The problem is if the amount(gross) is equal to the minimum wage, it results in wrong value and doubles the deduction. If the amount is not equal to min. wage, the result is accurate.

Example:
Amount(gross) = 7,500
Percent: 15%
Min. wage = 7,500
Max. wage = 9,167
Annual Fixed Amount: 104.17
Results doubles:
Withholding Tax: 104.13
Withholding Tax: 104.17

That totals to 208.3 for a YTD amount in a single payperiod!

The result should be 104.17 by this calculation if I understood correctly the Advanced Percent (Tax Bracket Alt.):
Tax = ((Amount - min. wage) * Percent) + Annual Fixed Amount.
Tax = ((0)*15%)+104.17
Tax = ( zero ) + 104.17
Tax = 104.17

Am I doing something wrong here, or there is a problem in the calculation "Advanced Percent (Tax Bracket Alt.)?

Thank you...
Allan E. Registos
shaunw
Posts: 7839
Joined: Tue Sep 19, 2006 2:22 pm

Re: Bug in Advanced Percent (Tax Bracket Alternate)?

Post by shaunw »

What version of TimeTrex are you using?

How many pay periods do you have in a year?
allanregistos
Posts: 41
Joined: Wed Oct 21, 2009 11:56 pm
Location: Philippines
Contact:

Re: Bug in Advanced Percent (Tax Bracket Alternate)?

Post by allanregistos »

shaunw wrote:What version of TimeTrex are you using?

How many pay periods do you have in a year?
I am using TimeTrex Standard version 3.0.5.
I have semi-monthly pay periods, i.e., 24 pay periods per year.

I look at the code, and it seems it is this file: classes/modules/users/UserDeductionFactory.class.php.

The exact code I think is this:

Code: Select all

if ( $amount >= $min_wage AND $amount <= $max_wage ) {
           $retval = bcadd( bcmul( bcsub( $amount, $min_wage ) , bcdiv($percent, 100) ), $annual_fixed_amount);
}
The problem occurs if the amount is exactly equal to min_wage. The expected return value must be the value of annual_fixed_amount only, since multiplying numbers by zero is equal to zero and then add annual_fixed_amount of the result and it ends there.
shaunw
Posts: 7839
Joined: Tue Sep 19, 2006 2:22 pm

Re: Bug in Advanced Percent (Tax Bracket Alternate)?

Post by shaunw »

I'm not sure I follow, the code you quoted looks pretty much identical to the formula you specified. Where do you think the error in the formula is?
allanregistos
Posts: 41
Joined: Wed Oct 21, 2009 11:56 pm
Location: Philippines
Contact:

Re: Bug in Advanced Percent (Tax Bracket Alternate)?

Post by allanregistos »

shaunw wrote:I'm not sure I follow, the code you quoted looks pretty much identical to the formula you specified. Where do you think the error in the formula is?
Yes, it is the same, and I really don't know where in the code, even if I modified the code to look this way, to make sure that if this condition is true -> ($amount = $min_wage) then
return value must be set to $retval = $annual_fixed_amount,

Code: Select all

if ( $amount >= $min_wage AND $amount <= $max_wage ) {
       $retval = bcadd( bcmul( bcsub( $amount, $min_wage ) , bcdiv($percent, 100) ), $annual_fixed_amount);
}
if ($amount == $min_wage){
       $retval = $annual_fixed_amount;
}
still the same wrong result occurs. The weird thing is if I have 8958 as total gross, and it is the same as the min_wage in the bracket, i've got this tax result = 1112.50. While if total gross is 7500 and this same value was the same min_wage in the bracket, i've got two taxes one is 104.13 and 104.17 to which the latter is the correct one, to the total YTD amount of 208.30 of the same pay period. The rest of the calculation as long as $amount is not equal to $min_wage, are all accurate.

It is easy to reproduce this same scenario in a fresh installation that I will try later.
allanregistos
Posts: 41
Joined: Wed Oct 21, 2009 11:56 pm
Location: Philippines
Contact:

Re: Bug in Advanced Percent (Tax Bracket Alternate)?

Post by allanregistos »

I installed a fresh 3.0.6 version, setup tax brackets:

Code: Select all

Exemption      0.00   0.00  	        20.83  	104.17  	354.17  	937.50  	2083.33  	5208.33  	
status 	      0%    5% 	           10% 	   15% 	    20% 	    25% 	    30% 	   32% 	=( + percent over) 	
1. ME1/S1 	  1 	    3,125 	    3,542 	  4,375 	 6,042 	8,958         13,542 	23,958 	 

Just for ME1/S1 this time. I created two sample employees, then put a gross amount of 8958 and 13542.
This doubles the result:

Code: Select all

Total Gross         13,542.00
Deductions          Amount     YTD Amount      |         Deductions          Amount      YTD Amount
Withholding Tax    2,083.33    4,166.83           |      Withholding Tax    2,083.50    0.00
Total Deductions                                                            4,166.83    4,166.83
Note that I have two tax deductions, which is supposedly one only. For more information, please see attached PDF paystub.
Attachments
PayStubList.pdf
(1.1 MiB) Downloaded 545 times
shaunw
Posts: 7839
Joined: Tue Sep 19, 2006 2:22 pm

Re: Bug in Advanced Percent (Tax Bracket Alternate)?

Post by shaunw »

I don't follow you at all, in your first post the bracket was 7500-9500, now you are talking 8,958 and 13,542.

In order to figure out whats going on, you should disable/delete all brackets except one and start there. You will also need to provide a screenshot of your one bracket (Edit Tax/Deduction page), and a screenshot of the resulting pay stub, and what you feel the result should be. Only then can we begin to make progress.

Just a note, you do realize the Tax/Deduction values are annual amounts correct? When you create a single pay stub with a gross of 8958, this is multiplied by the number of pay periods in a year before its compared to the tax brackets. So if you want to test a tax bracket of 7500-9500 you need to take 7500/<total pay payperiods/year> = Total Gross for one pay period.
7500/26PPs (bi-weekly) = $288.46 Gross Pay in a single pay period. This also makes it extremely difficult to have an employee actually earn the exact amount necessary to match the bracket exactly due to rounding (288.46*26 = 7499.96, so this amount would actually not have any taxes taken off). The last thing is that since the brackets all compare with >= and <=, you're brackets must have not matching values, ie:

Incorrect Way:
7500-9500
9500-12000
12000-15000

Correct Way:
7500-9500
9501-12000
12001-15000
allanregistos
Posts: 41
Joined: Wed Oct 21, 2009 11:56 pm
Location: Philippines
Contact:

Re: Bug in Advanced Percent (Tax Bracket Alternate)?

Post by allanregistos »

shaunw wrote:I don't follow you at all, in your first post the bracket was 7500-9500, now you are talking 8,958 and 13,542.
The 7500-9500 range is one example. I have just tested a different value with the same $amount=$min_wage.
shaunw wrote: In order to figure out whats going on, you should disable/delete all brackets except one and start there. You will also need to provide a screenshot of your one bracket (Edit Tax/Deduction page), and a screenshot of the resulting pay stub, and what you feel the result should be. Only then can we begin to make progress.
Yes, I did this, except the screenshot.
shaunw wrote: Just a note, you do realize the Tax/Deduction values are annual amounts correct? When you create a single pay stub with a gross of 8958, this is multiplied by the number of pay periods in a year before its compared to the tax brackets. So if you want to test a tax bracket of 7500-9500 you need to take 7500/<total pay payperiods/year> = Total Gross for one pay period.
7500/26PPs (bi-weekly) = $288.46 Gross Pay in a single pay period. This also makes it extremely difficult to have an employee actually earn the exact amount necessary to match the bracket exactly due to rounding (288.46*26 = 7499.96, so this amount would actually not have any taxes taken off). The last thing is that since the brackets all compare with >= and <=, you're brackets must have not matching values, ie:

Incorrect Way:
7500-9500
9500-12000
12000-15000

Correct Way:
7500-9500
9501-12000
12001-15000
Shaunw, I think you just have found my problem, I am making the brackets in the incorrect way! My bad! Thanks a lot for helping us out!
Locked