From bd5f5dabbd72764b2ad860fd5266019d48863eff Mon Sep 17 00:00:00 2001 From: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Date: Mon, 23 Dec 2019 18:01:41 +0530 Subject: [PATCH] fix: Salary Structure Fixes (#19923) --- .../salary_structure/salary_structure.js | 87 ++++++++++--------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.js b/erpnext/hr/doctype/salary_structure/salary_structure.js index dd34ef2ae2..9f42c917a4 100755 --- a/erpnext/hr/doctype/salary_structure/salary_structure.js +++ b/erpnext/hr/doctype/salary_structure/salary_structure.js @@ -46,7 +46,7 @@ frappe.ui.form.on('Salary Structure', { frm.trigger("toggle_fields"); frm.fields_dict['earnings'].grid.set_column_disp("default_amount", false); frm.fields_dict['deductions'].grid.set_column_disp("default_amount", false); - + if(frm.doc.docstatus === 1) { frm.add_custom_button(__("Preview Salary Slip"), function() { frm.trigger('preview_salary_slip'); @@ -119,47 +119,52 @@ frappe.ui.form.on('Salary Structure', { }, callback: function(r) { var employees = r.message; - var d = new frappe.ui.Dialog({ - title: __("Preview Salary Slip"), - fields: [ - { - "label":__("Employee"), - "fieldname":"employee", - "fieldtype":"Select", - "reqd": true, - options: employees - }, { - fieldname:"fetch", - "label":__("Show Salary Slip"), - "fieldtype":"Button" - } - ] - }); - d.get_input("fetch").on("click", function() { - var values = d.get_values(); - if(!values) return; - var print_format; - frm.doc.salary_slip_based_on_timesheet ? - print_format="Salary Slip based on Timesheet" : - print_format="Salary Slip Standard"; - - frappe.call({ - method: "erpnext.hr.doctype.salary_structure.salary_structure.make_salary_slip", - args: { - source_name: frm.doc.name, - employee: values.employee, - as_print: 1, - print_format: print_format, - for_preview: 1 - }, - callback: function(r) { - var new_window = window.open(); - new_window.document.write(r.message); - // frappe.msgprint(r.message); - } + if(!employees) return; + if (employees.length == 1){ + frm.events.open_salary_slip(frm, employees[0]); + } else { + var d = new frappe.ui.Dialog({ + title: __("Preview Salary Slip"), + fields: [ + { + "label":__("Employee"), + "fieldname":"employee", + "fieldtype":"Select", + "reqd": true, + options: employees + }, { + fieldname:"fetch", + "label":__("Show Salary Slip"), + "fieldtype":"Button" + } + ] }); - }); - d.show(); + d.get_input("fetch").on("click", function() { + var values = d.get_values(); + if(!values) return; + frm.events.open_salary_slip(frm, values.employee) + + }); + d.show(); + } + } + }); + }, + + open_salary_slip: function(frm, employee){ + var print_format = frm.doc.salary_slip_based_on_timesheet ? "Salary Slip based on Timesheet" : "Salary Slip Standard"; + frappe.call({ + method: "erpnext.hr.doctype.salary_structure.salary_structure.make_salary_slip", + args: { + source_name: frm.doc.name, + employee: employee, + as_print: 1, + print_format: print_format, + for_preview: 1 + }, + callback: function(r) { + var new_window = window.open(); + new_window.document.write(r.message); } }); },