Salary Slip not updating when adding/removing Timesheet links (#11982)
* timesheet on salary slip * changes * cal total wages * calculate gross_pay and net_pay * codacy fix
This commit is contained in:
parent
de8f6120f3
commit
8cad3f12a2
@ -98,6 +98,15 @@ frappe.ui.form.on('Salary Detail', {
|
||||
}
|
||||
})
|
||||
|
||||
frappe.ui.form.on('Salary Slip Timesheet', {
|
||||
time_sheet: function(frm, dt, dn) {
|
||||
total_work_hours(frm, dt, dn);
|
||||
},
|
||||
timesheets_remove: function(frm, dt, dn) {
|
||||
total_work_hours(frm, dt, dn);
|
||||
}
|
||||
});
|
||||
|
||||
// Get leave details
|
||||
//---------------------------------------------------------------------
|
||||
cur_frm.cscript.start_date = function(doc, dt, dn){
|
||||
@ -154,11 +163,11 @@ cur_frm.cscript.depends_on_lwp = function(doc,dt,dn){
|
||||
// Calculate earning total
|
||||
// ------------------------------------------------------------------------
|
||||
var calculate_earning_total = function(doc, dt, dn, reset_amount) {
|
||||
|
||||
var tbl = doc.earnings || [];
|
||||
var total_earn = 0;
|
||||
for(var i = 0; i < tbl.length; i++){
|
||||
if(cint(tbl[i].depends_on_lwp) == 1) {
|
||||
|
||||
tbl[i].amount = Math.round(tbl[i].default_amount)*(flt(doc.payment_days) /
|
||||
cint(doc.total_working_days)*100)/100;
|
||||
} else if(reset_amount) {
|
||||
@ -166,10 +175,12 @@ var calculate_earning_total = function(doc, dt, dn, reset_amount) {
|
||||
}
|
||||
if(!tbl[i].do_not_include_in_total) {
|
||||
total_earn += flt(tbl[i].amount);
|
||||
|
||||
}
|
||||
}
|
||||
doc.gross_pay = total_earn;
|
||||
refresh_many(['earnings', 'amount','gross_pay']);
|
||||
|
||||
}
|
||||
|
||||
// Calculate deduction total
|
||||
@ -210,3 +221,31 @@ cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) {
|
||||
query: "erpnext.controllers.queries.employee_query"
|
||||
}
|
||||
}
|
||||
|
||||
// calculate total working hours, earnings based on hourly wages and totals
|
||||
// ------------------------------------------------------------------------
|
||||
var total_work_hours = function(frm, dt, dn) {
|
||||
frm.set_value('total_working_hours', 0);
|
||||
|
||||
$.each(frm.doc["timesheets"] || [], function(i, timesheet) {
|
||||
frm.doc.total_working_hours += timesheet.working_hours;
|
||||
});
|
||||
frm.refresh_field('total_working_hours');
|
||||
|
||||
var wages_amount = frm.doc.total_working_hours * frm.doc.hour_rate;
|
||||
|
||||
frappe.db.get_value('Salary Structure', {'name': frm.doc.salary_structure}, 'salary_component', (r) => {
|
||||
frm.set_value('gross_pay', 0);
|
||||
|
||||
$.each(frm.doc["earnings"], function(i, earning) {
|
||||
if (earning.salary_component == r.salary_component) {
|
||||
earning.amount = wages_amount;
|
||||
frm.refresh_fields('earnings');
|
||||
}
|
||||
frm.doc.gross_pay += earning.amount;
|
||||
});
|
||||
|
||||
frm.refresh_field('gross_pay');
|
||||
calculate_net_pay(frm.doc, dt, dn);
|
||||
});
|
||||
}
|
@ -463,4 +463,4 @@ def unlink_ref_doc_from_salary_slip(ref_no):
|
||||
if linked_ss:
|
||||
for ss in linked_ss:
|
||||
ss_doc = frappe.get_doc("Salary Slip", ss)
|
||||
frappe.db.set_value("Salary Slip", ss_doc.name, "journal_entry", "")
|
||||
frappe.db.set_value("Salary Slip", ss_doc.name, "journal_entry", "")
|
Loading…
x
Reference in New Issue
Block a user