Gratuity Current Work Experience just for years only
I want includes years, months and days.
Join from 09/06/2019
Relieving Date to 31/04/2024
days : 22
Month : 10
Years : 4
Gratuity Current Work Experience just for years only
I want includes years, months and days.
Join from 09/06/2019
Relieving Date to 31/04/2024
days : 22
Month : 10
Years : 4
but where? Please share the screenshot
Hi @Maged_Bajandooh,
Please apply the client script for the employee doctype.
frappe.ui.form.on('Employee', {
relieving_date: function(frm) {
calculate_service_duration(frm);
},
date_of_joining: function(frm) {
calculate_service_duration(frm);
}
});
function calculate_service_duration(frm) {
if (frm.doc.date_of_joining && frm.doc.relieving_date) {
let joining_date = new Date(frm.doc.date_of_joining);
let relieving_date = new Date(frm.doc.relieving_date);
let years = relieving_date.getFullYear() - joining_date.getFullYear();
let months = relieving_date.getMonth() - joining_date.getMonth();
let days = relieving_date.getDate() - joining_date.getDate();
if (days < 0) {
months -= 1;
days += new Date(relieving_date.getFullYear(), relieving_date.getMonth(), 0).getDate();
}
if (months < 0) {
years -= 1;
months += 12;
}
let output = `Years: ${years}, Months: ${months}, Days: ${days}`;
frm.set_value('custom_current_work_experience', output);
} else {
frm.set_value('custom_current_work_experience', '');
}
}
Output:
current work experience must be Data field.
Years: 24, Months: 7, Days: 18
please also check the current work experience fieldname and set in the script.
Then reload Ctrl+Shift+R and check it.
I need script for Gratuity doctype.
I just provide the sample script. The script will be the same for your scenario. You just need to apply for the Gratuity doctype and also check your field name.
You have to get the joining_date and relieving_date from the employee doctype. so you have to use the frappe.db.get_value
. and also you have to some learn the concept of client script and server script.