Penalty for Late Entry or Early Exit

Hi,

I have implemented the biometric auto attendance system and it is working well. I am wondering if we can somehow punish those that have Late Entry or Early Exit with something like a partial leave. I.E.

1 Late Entry = 1/6 Day cut.

Currently the system only mentions Late Entry or Early exit but having an automatic counter would be a great addition. I am a novice coder so some guidance on where to do what would be appreciated.

2 Likes

Hi

I had achieved something similar using a custom app approach to make use of custom hook for salary slip to perform a count of all the late entry and early exit and add the total deduction for that employee in the salary slip.

@bibinqcs It would be a great help if you could share it(GitHub or something else).

I had done the work on a clients system, I couldn’t get to keep a copy of it.

I built a custom python function using

frappe.db.count(doctype, filters)

it was something like this

frappe.db.count('Attendance', { 
               'employee': employee, 
               'status': 'Present', 
               'late_entry': 1
})

https://frappeframework.com/docs/user/en/api/database#frappedbcount

@bibinqcs Thanks, that’s really helpful, but I am much more lost in setting up the web hooks, how does it add a parameter to the salary slip. If you could shed some more light in that part of logic, it would be a lot of help.

You can look at the hook file in erpnext for reference

Document Events
---------------
Hook on document methods and events

doc_events = {
	"*": {
		"on_update": "method",
		"on_cancel": "method",
		"on_trash": "method"
    }
}

You can add one pointing to your custom function for eg

"Salary Slip": {
		"validate": "custom_app.custom.penalty_function"
	}

This will trigger on every save.

You could trigger to make an Additional Salary document which creates the new deduction for an employee with the penalty for Late Entry

https://frappeframework.com/docs/user/en/api/document#frappenew_doc

@bibinqcs thanks a lot, that info really helped.

I have implemented most of the required components, but whenever I try to update the slip, it triggers the validate function which bypasses all my changes. How did you bypass this? Thanks.

@niteya Are you using the additional salary doctype to add the deductions or are you trying to insert the deductions directly into the salary slip

Thank you so much, that fixed it. I was trying to work with salary components instead of additional salary.

1 Like

Hello @niteya, I read all replies to this post but was wondering if there is any chance I could achieve the following workflow through hooks and existing attendance features provided by ERPNext.

Suppose an employee has worked 6 hours last day and 7 hours today. Daily work hours for this employee are 8. With current support from ERPNext features, I can deduct salary based on payment days, which do not take into account the working hours of employees.

In this scenario, the employee has not completed his working hours but is marked “present” for both days. How can I deduct the salary in the salary slip, if the employee has worked less than 8 hours a day? Also, if the employee compensates his working hours some other day, how can I take that into account and tell the system not to deduct the salary then?

Please note that Timesheets is not an option for me. I would really appreciate your help on this. Thank you.

Stay blessed and safe.

1 Like

@Aamir_Khan, based on the scenario you mentioned, You could add a custom field to capture the total working hours in the salary slip. Trigger the calculation of total working hours for the salary period using hooks (before_insert) when a salary slip is created.
While configuring the salary structure set a deduction salary component with a condition to trigger the component only if the total working hours are not met and formula based on the total working hours.
When payroll entry generates salary slips the salary component would get added based on the condition and formula.

I hope this helps

1 Like

Hey @bibinqcs, thanks for taking out time to respond.

As you have mentioned:

I doubt if it’s possible to access total_working_hours in the salary component or salary structure formulas. How can I get past this problem first. Also, how can I deal with compensation? I guess that would be based on total monthly working hours and total monthly hours of employee.

You can add custom fields in Salary Slip, and use it in the formula of Salary Components and created a Salary Structure with it. I have done it
In the use case you mentioned,
You can calculate the deduction using the Payment Days field in salary slip to get working days for the salary period and find out the total monthly working hour and compare it with Total Working Hours for the employee from Attendance