Client script to calculate OT and shortfall

Hello Community,

I am writing Client Script to calculate OT and shortfall hours.

To calculate “Total Working Hours” and “Total Holidays” I already applied Server Script Type : API

Now, to calculate OT and shortfall hours I am writing below client script which is not working.

May I know what I am missing?

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 = 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);
        }
    } 
});
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);
        }
    } 
});

@umarless Try this

1 Like

Thanks for reply Hardik.

This is the same code I am trying.

@umarless

There is a difference

Your code has var pd = doc.payment_days - th; and mine once has var pd = frm.doc.payment_days - th;

1 Like

Thanks Hardik.

1 Like