Hi all, I was scripting (client-side) to calculate the amount to deduct for Leave without Pay in Salary Slip. I couldn’t use the default calculation method in ERPNext. This is because under the labor law of my country:
-
Salary below $1500: the deduction for Leave without Pay has to be based on the number of days in the month. e.g. 28 days during Feb.
-
Salary above $1500: the deduction for Leave without Pay will be based on the company’s policy i.e. 22 days
So the calculation should for Feb 2019 (28 days)
-
Employee Zack: Took 2 days of Leave without Pay
Basic (earning): $1500
Leave without Pay (deduction): $1500 / 28 * 2 = $107.14
Net Salary: $1500 - $107.14 = $1392.86 -
Employee Cindy: Took 2 days of Leave without Pay
Basic (earning): $3000
Leave without Pay (deduction): $3000 / 22 * 2 = $272.72
Net Salary: $3000 - $272.72 = $2727.28
But during the creation of salary slip, I received an error: “Error in formula or condition: float division by zero”
- This is the formula I put for Leave without Pay salary component (Note that ‘total_days_in_the_month’ is a custom field I inserted in Salary Slip doctype):
(basic / total_days_in_the_month * leave_without_pay) if basic < 1500 else (basic / 22 * leave_without_pay)
- This is the custom script (client-side) for Salary Slip.
frappe.ui.form.on('Salary Slip', "refresh", function(frm, cdt, cdn){ var d = locals[cdt][cdn]; frappe.model.set_value(cdt, cdn, 'total_days_in_the_month', frappe.datetime.get_day_diff( d.end_date , d.start_date)); refresh_field('total_days_in_the_month'); });