Payroll Submit Salary Slip not working

Hello Community Members,

I have three client script, all for Salary Slip as below.

  1. 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];
					}
				});
});
  1. 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];
					}
				});
});
  1. 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

  1. 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

Hi,

If you want to use the script from Payroll Entry, you need to create as server script and not as client script.

Client script only works when you are on the transaction screen in GUI. It will not work with API and other method of creation where you are not in the GUI of transaction screen. Server script will work in all the scenario.

Thanks,

Divyesh Mangroliya

1 Like

Ok. Understand.

But May I know how can we apply a server script on Payroll Entry Which should apply on Salary Slip creation.

Any hint or documentation link ? please suggest.

Hi,

Apply the Server Script on Salary Slip on Save Event. It will work from Payroll Entry.

Thanks,

Divyesh Mangroliya

1 Like

Only this calculation script should be server script, right?

Hi,

All three-client script, you need to convert to server script.

Regards,

Divyesh M.

1 Like

Thanks a lot.