Payroll Deductions Are Being Added Instead of Subtracted

m facing a puzzling issue with payroll calculation in my ERPNext system. The deductions are being added to the Gross Pay instead of being subtracted, resulting in an incorrect Net Pay.

Here’s the data from the payslip:

  • Gross Pay: 500,000,000
  • Total Deductions: 37,000,000 (from two components: ter-22 and ter-33)
  • Expected Net Pay (Manual Calculation): 500,000,000 - 37,000,000 = 463,000,000
  • Actual Net Pay (from the System): ** 537,000,000**

The system’s calculation seems to be Gross Pay + Total Deductions.

Has anyone encountered this problem before? Could this be a configuration error in the Salary Component setup (e.g., a component incorrectly set as an “Earning” instead of “Deduction” or a formula issue)? Any advice on how to debug this would be a great help.

Thank you!


Hi there,

On quick glance, it looks like you’ve got this set up with the signs reversed. The deductions should be positive numbers. Deducting a negative number is addition.

Any guidance on how to make it Positive? Should I tweak that on Salary Component or??

Yep! I assume the negative number is coming from a salary component definition. If so, that’s where you should fix it.

i make it abs((base - 250000000) * 0.25) so it wouldnot be negative, but it gets error

Error while evaluating the Salary Structure <a href="http://127.0.0.1:8000/app/salary-structure/new%20one">new one</a> at row 1. <br><br> <b>Error:</b> name 'abs' is not defined <br><br> <b>Hint:</b> This error can be due to missing or deleted field.
Check Error Log <a href="http://127.0.0.1:8000/app/error-log/ogca29mit7">ogca29mit7</a> for more details.

is there any alternative besides abs?

I don’t really understand what you’re describing here. If base is 500.000.000, how are you getting 6.000.000 or 31.000.000 from the formula ((base - 250000000) * 0.25)?

Is it okay if I use this code snippet?

gross_salary = gross_pay
ptkp_status = employee.status_ptkp

tax_tables = {
    'A': [
        (5400000, 0.00), (5650000, 0.0025), (5950000, 0.0050),
        (6300000, 0.0075), (6750000, 0.01), (7500000, 0.0125),
        (8550000, 0.015), (9650000, 0.0175), (10050000, 0.02),
        (10350000, 0.0225), (10700000, 0.025), (11050000, 0.03),
        (11600000, 0.035), (12500000, 0.04), (13750000, 0.05),
        (15100000, 0.06), (16950000, 0.07), (19750000, 0.08),
        (24150000, 0.09), (26450000, 0.10), (28000000, 0.11),
        (30050000, 0.12), (32400000, 0.13), (35400000, 0.14),
        (39100000, 0.15), (43850000, 0.16), (47800000, 0.17),
        (51400000, 0.18), (56300000, 0.19), (62200000, 0.20),
        (68600000, 0.21), (77500000, 0.22), (89000000, 0.23),
        (103000000, 0.24), (125000000, 0.25), (157000000, 0.26),
        (206000000, 0.27), (337000000, 0.28), (454000000, 0.29),
        (550000000, 0.30), (695000000, 0.31), (910000000, 0.32),
        (1400000000, 0.33), (float('inf'), 0.34)
    ],
    'B': [
        (6200000, 0.00), (6500000, 0.0025), (6850000, 0.0050),
        (7300000, 0.0075), (9200000, 0.01), (10750000, 0.015),
        (11250000, 0.02), (11600000, 0.025), (12600000, 0.03),
        (13600000, 0.04), (14950000, 0.05), (16400000, 0.06),
        (18450000, 0.07), (21850000, 0.08), (26000000, 0.09),
        (27700000, 0.10), (29350000, 0.11), (31450000, 0.12),
        (33950000, 0.13), (37100000, 0.14), (41100000, 0.15),
        (45800000, 0.16), (49500000, 0.17), (53800000, 0.18),
        (58500000, 0.19), (64000000, 0.20), (71000000, 0.21),
        (80000000, 0.22), (93000000, 0.23), (109000000, 0.24),
        (129000000, 0.25), (163000000, 0.26), (211000000, 0.27),
        (374000000, 0.28), (459000000, 0.29), (555000000, 0.30),
        (704000000, 0.31), (957000000, 0.32), (1405000000, 0.33),
        (float('inf'), 0.34)
    ],
    'C': [
        (6600000, 0.00), (6950000, 0.0025), (7350000, 0.0050),
        (7800000, 0.0075), (8850000, 0.01), (9800000, 0.0125),
        (10950000, 0.015), (11200000, 0.0175), (12050000, 0.02),
        (12950000, 0.03), (14150000, 0.04), (15550000, 0.05),
        (17050000, 0.06), (19500000, 0.07), (22700000, 0.08),
        (26600000, 0.09), (28100000, 0.10), (30100000, 0.11),
        (32600000, 0.12), (35400000, 0.13), (38900000, 0.14),
        (43000000, 0.15), (47400000, 0.16), (51200000, 0.17),
        (55800000, 0.18), (60400000, 0.19), (66700000, 0.20),
        (74500000, 0.21), (83200000, 0.22), (95600000, 0.23),
        (110000000, 0.24), (134000000, 0.25), (169000000, 0.26),
        (221000000, 0.27), (390000000, 0.28), (463000000, 0.29),
        (561000000, 0.30), (709000000, 0.31), (965000000, 0.32),
        (1419000000, 0.33), (float('inf'), 0.34)
    ]
}

ter_rate = 0.0

if ptkp_status in ['TK/0', 'TK/1', 'K/0']:
    category = 'A'
elif ptkp_status in ['TK/2', 'TK/3', 'K/1', 'K/2']:
    category = 'B'
elif ptkp_status == 'K/3':
    category = 'C'
else:
    return 0.0

for upper_bound, rate in tax_tables[category]:
    if gross_salary <= upper_bound:
        ter_rate = rate
        break

return (gross_salary * ter_rate) * -1

On formula in Salary Component. This formula for my tax calculation has me quite confused in frappe

Without testing myself, I have no idea. This is vastly more complex than salary component formulas generally should be. If you need to do something this elaborate, you’d probably be much better off leaving a zero-value entry and then using a server script to alter the value manually.

If deductions are not correctly calculated, it is the user error. Do not attempt to cover your mistakes with coding. Get some help to look through the system or do as many samples on a test system as you can.