@Past_Papers I think that I found a solution.
- Customize the
Salary Slip
doctype and add a new int read only field callednumber_of_late_days
- Create a
Client Script
forSalary Slip
form and use the below code - Create a
Salary Component
and in the condition putnumber_of_late_days > 2
and in the formula put(number_of_late_days - 2) * 100
- In the
Salary Slip
add theSalary Component
you created for deduction.
frappe.ui.form.on('Salary Slip', {
employee: function(frm) {
frm.trigger('update_number_of_late_days');
},
start_date: function(frm) {
frm.trigger('update_number_of_late_days');
},
end_date: function(frm) {
frm.trigger('update_number_of_late_days');
},
update_number_of_late_days: function(frm) {
if (!frm.is_new() && !frm.is_dirty()) return;
if (!frm.doc.employee || !frm.doc.start_date || !frm.doc.end_date) return;
frappe.db.get_list('Attendance', {
fields: ['name'],
filters: {
employee: frm.doc.employee,
late_entry: 1,
attendance_date: ['between', [frm.doc.start_date, frm.doc.end_date]]
}
}).then(ret => {
let count = ret.length, late_days = cint(frm.doc.number_of_late_days);
if (count === late_days) return;
frm.set_value('number_of_late_days', count);
if (!frm.is_new()) {
frm.dirty();
frm.save();
}
});
}
});
The following code will set the number of late days between the start and end dates of the Salary Slip
.