Adding a Payroll calculator

Jay Scherrer jay at scherrer.com
Wed Nov 2 17:11:53 EST 2005


On Wed, 2005-11-02 at 09:33 -0800, Andrew Sackville-West wrote:
> This is in response to several above.... and my own thoughts on it last 
> night.
> 
> Derek Atkins wrote:
> >
> >>Example: scheduleY1()
> >>
> >>This example is used for calculating the income tax for someone who is
> >>married, filing jointly, and earns more then $100,000 according to the
> >>IRS 1040 2001 rates. 
> >>
> >>variables: 
> >>[$line41 = wages, $line42 = Tax, scheduleY1 = member function]
> >>## Status = married filing joint ##
> >>sub scheduleY1(){
> >>    my $line41 = shift;
> >>    if ($line41 >= 0 && $line41 <= 12000){
> >>	$line42 = $line41 * .10;
> >>    }elsif ($line41 >= 12000 && $line41 <= 46700) {
> >>	$line42 = ((($line41 - 12000)* .15) + 12000);
> >>    }elsif ($line41 >= 46700 && $line41 <= 112850) {
> >>	$line42 = ((($line41 - 46700)* .27) + 6405);
> >>    }elsif ($line41 >= 112850 && $line41 <= 171950) {
> >>	$line42 = ((($line41 - 112850)* .30) + 24265.50);
> >>    }elsif ($line41 >= 171950 && $line41 <= 307050) {
> >>	$line42 = ((($line41 - 171950)* .35) + 41995.50);
> >>    }elsif ($line41 > 307050) {
> >>	$line42 = ((($line41 - 307050)* .38.6) + 89280.50);
> >>    }
> >>    return $line42;
> > 
> > 
> > Um, this seems particular hard-coded and not very flexible.  It's even
> > WORSE if it's in C, because then the numbers aren't user-settable.
> > You /need/ to support this kind of configuration in a user-settable
> > method.  How do you propose to do that?
> > 
> > This is why I'm suggesting scheme, because then you can configure this
> > kind of "function" in scheme and users can change the values without
> > having to rebuild gnucash.  I'm open to other suggestions, too.  We
> > can certainly try to create a generalized "graduated tax" in C, but
> > you'd need to figure out some way to allow the user to configure that.
> > 
> 
Actually, this example was pulled right off of my head perhaps I had
jumped to far ahead. This example has to be hard coded because that is
the way the IRS stipulates this calculation according to pub 17. The
standard deductions of earnings above $100,000. But what I was trying to
show is that, If we have classes with user defined entries (wages,
hours, rates) then we would define functions as prototypes attached to
the particular calculation of mixed members and classes.   
> WHy not do something like this:
> 
> struct _gncTax
> {
>    char *          id;
>    char *          taxName;   /* Medicare, SSI, Sales,..etc */
>    char *          taxType;   /* Payroll, Payroll, Sales  */
>    char *          taxCatagory;/* Employee, Salary, Sale */
>    gnc_numeric     taxRate;   /* .0145, .062, .893 */
>    gnc_numeric     taxFrequency; /* hourly, monthly, unit */
> 	gnc_numeric	taxFloor; /* minimum value below which tax is NOT applied */
> 	gnc_numeric	tax Ceiling; /* max value above which tax is NOT applied */
>    gnc_commodity * currency;
>    gboolean        active;
>    char *          language;
>    Account *       tax_acc;
> };
> 
> This allows you to set tax brackets which would work for US graduated 
> taxes by setting a different instance for each bracket with min and max 
> values set by the user. But it could also apply to "Wage base" taxes 
> like Social Security or Unemployment Tax which both only apply to the 
> first $x of wage per year. by setting the taxFloor to 0, and taxCeiling 
> to $x then you only tax the first $x wages. etc. you couuld hard code a 
> default so that if tax Ceiling is $0 then the tax always applies (i.e. 
> medicare).
> 
> I think we might need something like this as well:
> 
> struct _gncPayrollItem
> {
>    char *          id;
>    char *          PIName;   /* name of the item */
>    char *          PIType;   /* addition or deduction  */
>    Account *          PIAccount;/* account linked to this Item (can be 
> blank, can we do that with Account?) */
>    gboolean	  taxable; /* some items are taxable */
> /* some method of determining which taxes apply??? */
>    gnc_numeric     PIAmount;   /* the amount */
>    gnc_commodity * currency;
>    gboolean        active;
>    char *          language;
> 
> };
> 
> I really don't know what I'm doing here as far as gnc code goes, but it 
> works like this. Everything that is part of a paycheck has to be 
> associated with an _gncPayrollItem. Each of these items is previsouly 
> set-up by the user and linked to the employee. you can have one for 
> wages, one for employee mileage reimbursements, one for reported tips 
> (and then another one to deduct the employee tips back out), one for 
> reclaiming employee advances etc. etc. etc. This idean is stolen right 
> out of QB by  the way.... The point is there are lots of other things 
> that go on in payroll besides taxes and any reasonable solution, in my 
> mind, needs to include these things. So you can have an employee with a 
> variety of _gncTax applied and a variety of _gncPayrollItem applied to 
> build up the whole transaction.
> 
> For those that question the tips portion above it works like this: If 
> you have tipped employees (/me) then you have to tax them on their tips 
> so their tips are included in the Total Wages before taxes are 
> calculated. Then those tips are deducted back out (because the employee 
> already has them) out of the final paycheck.
> 
> A
Interesting. 
new variables: employeeHours, employeeTipIncome, businessCombinedTips,
businessNumberEmployees businessAllocatedTips, businessIncome.

employeeType = tipped
employeeWage = (employeeHours * employeeRate);
employeeTipIncome = (combinedTips / businessNumberEmployees); 
/* for Medicare and SSI wages and tips */   

businessAllocatedTips = ((businessIncome *.20) /
businessNumberEmployees);
Because of the allocated tip section on the W-2 we should also offer for
businesses a function for calculating this:
Allocated tip income = (Business Gross Income * .20) / (number of
employees);

I think now that we/I am starting to understand payroll. It's do-able as
long as we have some sort of user definitions that can be updated by the
payroll admin. Plus, I am in the midst of an Income tax course, so the
requirements are fresh in mind. Let me try to compile a simple payroll
program using c over the weekend.    

Some items for thought: based on 2004
Social security is withheld at 6.2% on all employees up to $87,900.
Employees are taxed 1.45% on all wages and tip for Medicare.

Jay Scherrer



More information about the gnucash-devel mailing list