forked from frappe/hrms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Preview Salary Slip from Salary Structure Assignment
- Loading branch information
1 parent
63d28f1
commit 6554799
Showing
1 changed file
with
93 additions
and
49 deletions.
There are no files selected for viewing
142 changes: 93 additions & 49 deletions
142
hrms/payroll/doctype/salary_structure_assignment/salary_structure_assignment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,162 @@ | ||
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors | ||
// For license information, please see license.txt | ||
|
||
frappe.ui.form.on('Salary Structure Assignment', { | ||
setup: function(frm) { | ||
frm.set_query("employee", function() { | ||
frappe.ui.form.on("Salary Structure Assignment", { | ||
setup: function (frm) { | ||
frm.set_query("employee", function () { | ||
return { | ||
query: "erpnext.controllers.queries.employee_query", | ||
filters: { company: frm.doc.company }, | ||
} | ||
}; | ||
}); | ||
frm.set_query("salary_structure", function() { | ||
frm.set_query("salary_structure", function () { | ||
return { | ||
filters: { | ||
company: frm.doc.company, | ||
docstatus: 1, | ||
is_active: "Yes" | ||
} | ||
} | ||
is_active: "Yes", | ||
}, | ||
}; | ||
}); | ||
|
||
frm.set_query("income_tax_slab", function() { | ||
frm.set_query("income_tax_slab", function () { | ||
return { | ||
filters: { | ||
company: frm.doc.company, | ||
docstatus: 1, | ||
disabled: 0, | ||
currency: frm.doc.currency | ||
} | ||
currency: frm.doc.currency, | ||
}, | ||
}; | ||
}); | ||
|
||
frm.set_query("payroll_payable_account", function() { | ||
frm.set_query("payroll_payable_account", function () { | ||
var company_currency = erpnext.get_currency(frm.doc.company); | ||
return { | ||
filters: { | ||
"company": frm.doc.company, | ||
"root_type": "Liability", | ||
"is_group": 0, | ||
"account_currency": ["in", [frm.doc.currency, company_currency]], | ||
} | ||
} | ||
company: frm.doc.company, | ||
root_type: "Liability", | ||
is_group: 0, | ||
account_currency: ["in", [frm.doc.currency, company_currency]], | ||
}, | ||
}; | ||
}); | ||
|
||
frm.set_query("cost_center", "payroll_cost_centers", function() { | ||
frm.set_query("cost_center", "payroll_cost_centers", function () { | ||
return { | ||
filters: { | ||
"company": frm.doc.company, | ||
"is_group": 0 | ||
} | ||
company: frm.doc.company, | ||
is_group: 0, | ||
}, | ||
}; | ||
}); | ||
}, | ||
|
||
refresh: function(frm) { | ||
if(frm.doc.__onload){ | ||
frm.unhide_earnings_and_taxation_section = frm.doc.__onload.earning_and_deduction_entries_does_not_exists; | ||
refresh: function (frm) { | ||
if (frm.doc.__onload) { | ||
frm.unhide_earnings_and_taxation_section = | ||
frm.doc.__onload.earning_and_deduction_entries_does_not_exists; | ||
frm.trigger("set_earnings_and_taxation_section_visibility"); | ||
} | ||
|
||
if (frm.doc.docstatus === 1) | ||
frm.add_custom_button(__("Preview Salary Slip"), function () { | ||
frm.trigger("preview_salary_slip"); | ||
}); | ||
}, | ||
|
||
employee: function(frm) { | ||
employee: function (frm) { | ||
if (frm.doc.employee) { | ||
frm.trigger("set_payroll_cost_centers"); | ||
frm.trigger("valiadte_joining_date_and_salary_slips"); | ||
} | ||
else { | ||
} else { | ||
frm.set_value("payroll_cost_centers", []); | ||
} | ||
}, | ||
|
||
company: function(frm) { | ||
company: function (frm) { | ||
if (frm.doc.company) { | ||
frappe.db.get_value("Company", frm.doc.company, "default_payroll_payable_account", (r) => { | ||
frm.set_value("payroll_payable_account", r.default_payroll_payable_account); | ||
}); | ||
frappe.db.get_value( | ||
"Company", | ||
frm.doc.company, | ||
"default_payroll_payable_account", | ||
(r) => { | ||
frm.set_value( | ||
"payroll_payable_account", | ||
r.default_payroll_payable_account | ||
); | ||
} | ||
); | ||
} | ||
}, | ||
|
||
set_payroll_cost_centers: function(frm) { | ||
if (frm.doc.payroll_cost_centers && frm.doc.payroll_cost_centers.length < 1) { | ||
preview_salary_slip: function (frm) { | ||
frappe.db.get_value( | ||
"Salary Structure", | ||
frm.doc.salary_structure, | ||
"salary_slip_based_on_timesheet", | ||
(r) => { | ||
const print_format = r.salary_slip_based_on_timesheet | ||
? "Salary Slip based on Timesheet" | ||
: "Salary Slip Standard"; | ||
frappe.call({ | ||
method: | ||
"hrms.payroll.doctype.salary_structure.salary_structure.make_salary_slip", | ||
args: { | ||
source_name: frm.doc.salary_structure, | ||
employee: frm.doc.employee, | ||
as_print: 1, | ||
print_format: print_format, | ||
for_preview: 1, | ||
}, | ||
callback: function (r) { | ||
const new_window = window.open(); | ||
new_window.document.write(r.message); | ||
}, | ||
}); | ||
} | ||
); | ||
}, | ||
|
||
set_payroll_cost_centers: function (frm) { | ||
if ( | ||
frm.doc.payroll_cost_centers && | ||
frm.doc.payroll_cost_centers.length < 1 | ||
) { | ||
frappe.call({ | ||
method: "set_payroll_cost_centers", | ||
doc: frm.doc, | ||
callback: function(data) { | ||
callback: function (data) { | ||
refresh_field("payroll_cost_centers"); | ||
} | ||
}) | ||
}, | ||
}); | ||
} | ||
}, | ||
|
||
valiadte_joining_date_and_salary_slips: function(frm) { | ||
valiadte_joining_date_and_salary_slips: function (frm) { | ||
frappe.call({ | ||
method: "earning_and_deduction_entries_does_not_exists", | ||
doc: frm.doc, | ||
callback: function(data) { | ||
callback: function (data) { | ||
let earning_and_deduction_entries_does_not_exists = data.message; | ||
frm.unhide_earnings_and_taxation_section = earning_and_deduction_entries_does_not_exists; | ||
frm.unhide_earnings_and_taxation_section = | ||
earning_and_deduction_entries_does_not_exists; | ||
frm.trigger("set_earnings_and_taxation_section_visibility"); | ||
} | ||
}, | ||
}); | ||
}, | ||
|
||
set_earnings_and_taxation_section_visibility: function(frm) { | ||
if(frm.unhide_earnings_and_taxation_section){ | ||
frm.set_df_property('earnings_and_taxation_section', 'hidden', 0); | ||
} | ||
else{ | ||
frm.set_df_property('earnings_and_taxation_section', 'hidden', 1); | ||
set_earnings_and_taxation_section_visibility: function (frm) { | ||
if (frm.unhide_earnings_and_taxation_section) { | ||
frm.set_df_property("earnings_and_taxation_section", "hidden", 0); | ||
} else { | ||
frm.set_df_property("earnings_and_taxation_section", "hidden", 1); | ||
} | ||
}, | ||
|
||
from_date: function(frm) { | ||
from_date: function (frm) { | ||
if (frm.doc.from_date) { | ||
frm.trigger("valiadte_joining_date_and_salary_slips" ); | ||
frm.trigger("valiadte_joining_date_and_salary_slips"); | ||
} | ||
}, | ||
}); |