Hello Community Members,
I have three client script, all for Salary Slip as below.
- Client Script for fetching total working hours in a particular month for an employee as per working hours in attendance
frappe.ui.form.on("Salary Slip", "refresh", function(frm) {
const totalHours = frappe.call({
method: "attendance_total_working_hours",
args: {
init_date: frm.doc.start_date,
end_date: frm.doc.end_date,
employee: frm.doc.employee
},
callback: function(r) {
frm.doc.custom_total_working_hours = totalHours.responseJSON.total_hours[0][0];
}
});
});
- Client Script for fetching all holidays in particular month for respective employee
frappe.ui.form.on("Salary Slip", "refresh", function(frm) {
const totalHoliday = frappe.call({
method: "holiday_count",
args: {
init_date: frm.doc.start_date,
end_date: frm.doc.end_date,
custom_holiday_list: frm.doc.custom_holiday_list
},
callback: function(r) {
frm.doc.custom_total_holidays = totalHoliday.responseJSON.holiday_count[0][0];
}
});
});
- Client Script for calculating Overtime and Shortfall hours while creating salary slip.
frappe.ui.form.on('Salary Slip', {
refresh: function(frm) {
var twh = frm.doc.custom_total_working_hours;
var th = frm.doc.custom_total_holidays;
var pd = frm.doc.payment_days - th;
var awh = pd * 9;
if(twh > awh) {
frm.set_value("custom_ot_hours", twh - awh);
} else if (awh > twh) {
frm.set_value("custom_shortfall_hours", awh - twh);
} else {
frm.set_value("custom_ot_hours", 0);
frm.set_value("custom_shortfall_hours", 0);
}
}
});
These all working fine when I am creating individual salary slip but when I am trying to create via payroll entry, its not working as desired.
I tried different events for each client script as below but its not working.
I also tried to merge all client script as below.
frappe.ui.form.on("Salary Slip", "refresh", function(frm) {
const totalHours = frappe.call({
method: "attendance_total_working_hours",
args: {
init_date: frm.doc.start_date,
end_date: frm.doc.end_date,
employee: frm.doc.employee
},
callback: function(r) {
frm.doc.custom_total_working_hours = totalHours.responseJSON.total_hours[0][0];
}
});
const totalHoliday = frappe.call({
method: "holiday_count",
args: {
init_date: frm.doc.start_date,
end_date: frm.doc.end_date,
custom_holiday_list: frm.doc.custom_holiday_list
},
callback: function(r) {
frm.doc.custom_total_holidays = totalHoliday.responseJSON.holiday_count[0][0];
}
});
var twh = frm.doc.custom_total_working_hours;
var th = frm.doc.custom_total_holidays;
var pd = frm.doc.payment_days - th;
var awh = pd * 9;
if(twh > awh) {
frm.set_value("custom_ot_hours", twh - awh);
} else if (awh > twh) {
frm.set_value("custom_shortfall_hours", awh - twh);
} else {
frm.set_value("custom_ot_hours", 0);
frm.set_value("custom_shortfall_hours", 0);
}
});
Issues
- While creating individual Salary Slip it is working fine.
But When I am creating payroll entry and creating Salary Slip it is getting submitted before fetching values.
Please suggest how to achieve this.
Thanks