Tekki/sql-ledger

Payroll Deduction Amount Confusion

gopokyo-colinn opened this issue · 11 comments

Hey there - been searching through the code to figure out how things work.

I have a payroll deduction table with rates per pay. First X dollars are taxed at %1, next Y dollars are taxes at %2 etc.

I've noted that the deduction calculator sorts and stops when pay is between above and below.

To add the previous amounts I have put their values in the amount column - the problem is that it does not take pay frequency into account like the rest of the table.

Here is my change

gopokyo-colinn@2059714

Tekki commented

Hello,
The idea with deductions is the following: Deductions are either absolute (fixed amount) or relative (percentage). These two types of deductions cannot be mixed (fixed and percentage at the same time).
Fixed amounts are subtracted from each payroll, for a maximum limited by the pay periods. If you pay per month and at the end of the year you give your employees an additional bonus, then this deduction shouldn't be made a 13th time. The fixed amount is defined as amount per period, not per year, because of that your change breaks the existing code.
The deductions by percent are directly related to the actual salary. They can be defined as x1 % if the salary s is above y1 and below y2, x2 % if the salary is above y2. Such deductions are calculated as x1 % of s or x2 % of s. They are not related to the pay frequency.
As far as I see it's not possible to apply different rates to different parts of the salary. Here in Switzerland we have such deduction tables for tax deduced at source for non-resident employees, with 12 different patterns. They are a nightmare.
Is this a bit clearer now?

Be warned, this module has some real issues.

Hey there Tekki,

I think its clearer now. So in Switzerland its basically if you are rich all of your income (from 0 to a million) is taxed at a higher rate whereas if you are in Canada and rich only a portion of your income (100,000 to a million) is taxed at a higher rate. Sql-ledger HR payroll is built around the Switzerland model.

Does that sounds right?

If so, I could make a deduction for each salary range I think. Does that sound like it would work?

Also, thanks for the module warning - seems to be working ok so far aside from document storage which I put an issue in for but the report it isn't of high quality

Tekki commented

Does that sounds right?

No it doesn't. In Switzerland social insurances are deduced from the salary, taxes are payed by the individuals. Only for non-residents taxes are deduced from the salary too, and here the calculation may be as complicated as in your country.
I think the module fits the Swiss system because a Swiss customer financed the development, but I'm not sure about that.

Tekki commented

Also, thanks for the module warning - seems to be working ok so far...

'No' number 2: Create a payroll transaction, change the rate, create a new one, re-open the first and you will see.

Tekki commented

It's Sunday, formula 1 was last week end and I had time to look at the Canadian tax system, so I decided to reopen this issue.
A yearly income of $ 120,000 results in a federal tax of 21,531. Do you agree with that?
Now if we add the complete tax table to one deduction, this means ignore what I said above and fill out all the rate, amount, above and below fields, leave aside for the moment the question of the pay periods and the changing rates, set the employee to 1 pay period and add a transaction of 120,000, we actually get this result.
If next we add your change, set the employee to 12 periods and add a transaction of 10,000, the tax is 1794.21, and that's correct.
So what are we going to do now? As I said before, your code breaks the functionality for those who created a deduction with a fixed monthly amount. Instead of 100 they will get 8.33, for example. But if on the other hand I look at the code at line 1886:

            $m = $form->round_amount($amount * $form->{payperiod}, $form->{precision});
            if ($m > $ref->{above}) {
              if ($m < $ref->{below}) {

I have the impression that the intention was to work with yearly, not with monthly amounts.
What do you think?

Hi Tekki

Canadian tax makes my mind spin. The following calculator gives 20797 in federal tax. https://www.taxtips.ca/calculators/canadian-tax/canadian-tax-calculator.htm

The difference comes from some tax breaks that aren't presented clearly on the CRA website. That said, I think assuming 21,531 is fine for this exercise.

The code you referenced does seem like it intends to take the number of payperiods into account. I find the deductions function in general a bit confusing though as I am not sure what "basedon" means etc.

To me, it would be more logical for amount to be per pay period ... otherwise you would need different deduction tables for different employees or projects that have different pay periods.

If you wanted to support both use cases there could be a checkbox named "split" or something defaulted to off that would split the amount per payperiod?

Tekki commented

There is a new version 3.2.8 from DWS with changes in this code block. We have to be careful with our own updates.

I think your tax calculator isn't used for what we are speaking about. But correct me if I'm mistaken. What I think is that the tax deduced by the employer is an approximative tax, calculated using the rates from this link. Then at the end of the year the employee makes the exact calculation and inserts the tax already paid by his employer under 'Total income tax deducted'.

'To me, it would be more logical for amount to be per pay period': You mean per year?

Here is what I use for payroll deductions in Canada

https://www.canada.ca/en/revenue-agency/services/e-services/e-services-businesses/payroll-deductions-online-calculator.html

It does not show any detail, but that linked tax calculator I had seemed to have the same resulting figure with details on how it came about.

What I meant was that it would be more logical for the figure in "amount" to be spit per pay period (per year). Sorry for the confusion

Tekki commented

There are two things we have to do:
First to find out how to calculate the tax. Because these calculators and a manual calculation all give different results. Calculated with the rates from the government website I get:

Salary Rate Deduction
47,630.00 15.0 % 7,144.50
47,629.00 20.5 % 9,763.95
24,741.00 26.0 % 6,432.66
120,000.00 23,341.11

I think it's your job to find this out. Maybe you have to ask the tax office directly.
Second we have to take care that the program calculates the amount we expect from it. I have no problems with a breaking change here if it makes sense.
This will need a bit more time, so next I'll publish version 3.2.8 (3.2.8.12) without any changes to the HR module.

Sorry for the late reply.

I use this online calculator to get tax deductions. It is correct and easier to use then the CRA website

https://www.hrclub.ca/wintaxcalculator/

This one gives a bit more insight into what is going on as its a very long form, also accurate

https://www.taxtips.ca/calculators/canadian-tax/canadian-tax-calculator.htm

Here is how Canadian tax works:

  1. CPP -> There is an exemption amount for low income persons. There is a maximum contribution amount for the year. A % is deducted from each pay period
  2. EI -> There is no exemption amount. There is a maximum amount. A % is deducted from each pay period
  3. Federal Tax -> There is an exemption amount that varies per individual. There is no maximum. The first n dollars are taxed at p %, the next n2 dollars are taxed at p2 % and so on. Computed after CPP and EI are deducted
  4. Provincial Tax -> There is an exemption amount that varies per individual. There is no maximum. The first n dollars are taxed at p %, the next n2 dollars are taxed at p2 % and so on. Computed after CPP and EI are deducted

Additionally, there are some hidden tax credits if you look at the taxtips.ca site for Federal tax:

  • Canada employment credit amount (Fed/YT) / 1,222
    This contributes to the basic exemption amount for federal tax. I set this up in the employee setup page, but more in that later.

Here is how I set up the system and how I expect it to work

  1. Tax Deductions for CPP and EI
  • I just set the rate to what is needs to be (CPP is 5.1% for both employee and employer, EI is 1.62% for employee and 1.4x that for employer). This works fine.
  • In the employee setup I set a CPP exempt amount of 178.49 and max amount to 2,748.90. I set no exempt amount for EI and a max amount of 860.22. This works fine
    NOTE: EI and CPP see to compute properly for now, no one has reach maximum contribution levels yet so I do not know if it will work properly for the entire year.
  1. Tax Deductions for federal and provincial tax - this isn't working
  • I set up the tax table as previously discussed, here is my provincial table

| Rate | Amount (I have a code edit that splits this evenly across total pay periods) | Above | Below |
| 8.79 | 0 | | 29,590.00 |
| 14.95 | 2,755.32 | 29,590.00 | 59,180.00 |
| 16.67 | 7,487.40 | 59,180.00 | 93,000.00 |

and so on.

  • CPP and EI are set as deductions for this deduction. I expect the software to tax the employees gross pay, deduct the current CPP/EI contributions, and then compute tax
  • In the employee setup I set an exemption amount for each employee. This is based on what they tell me about their financial situation. There is a complex form, but the summary of it is that its basically the following: 1,222 + (their computed exemption amount) * first tax rate which is 15% for federal and 8.79% for Nova Scotia. You can see this on line 338 of the tax tips site.

So this kind of works with the code change to spread the "Amount" from tax deductions over each all pay periods instead of being treated as a flat amount. It works up until I get into tax deduction entries that have an "Amount" set. I think there is an issue with the exemption amounts and the "Amount" value in the deduction?

Tekki commented

Closing this, no activity since nearly a year.