diff --git a/erpnext/setup/doctype/employee/employee.js b/erpnext/setup/doctype/employee/employee.js index 55dedea167b..bb69adc8827 100755 --- a/erpnext/setup/doctype/employee/employee.js +++ b/erpnext/setup/doctype/employee/employee.js @@ -57,44 +57,76 @@ frappe.ui.form.on("Employee", { frm.trigger("add_anniversary_indicator"); }, + is_employee_birthday: function (frm) { + if (!frm.doc.date_of_birth) return false; + let today = moment().startOf("day"); + let dob = moment(frm.doc.date_of_birth); + return dob.date() === today.date() && dob.month() === today.month(); + }, + + is_work_anniversary: function (frm) { + if (!frm.doc.date_of_joining) return false; + let today = moment().startOf("day"); + let doj = moment(frm.doc.date_of_joining); + let years = today.year() - doj.year(); + return doj.date() === today.date() && doj.month() === today.month() && years > 0; + }, + + get_work_anniversary_years: function (frm) { + let today = moment().startOf("day"); + let doj = moment(frm.doc.date_of_joining); + return today.year() - doj.year(); + }, + + create_milestone_section: function ($sidebar) { + let $indicator_section = $sidebar.find(".anniversary-indicator-section"); + if (!$indicator_section.length) { + $indicator_section = $(` +
+ `).insertAfter($sidebar.find(".sidebar-meta-details")); + } + return $indicator_section; + }, + + build_anniversary_content: function (frm) { + let items = []; + if (frm.events.is_employee_birthday(frm)) { + items.push(` + `); + } + if (frm.events.is_work_anniversary(frm)) { + let years = frm.events.get_work_anniversary_years(frm); + let label = + years === 1 + ? __("{0} Year Work Anniversary", [years]) + : __("{0} Years Work Anniversary", [years]); + items.push(` + `); + } + return items.join(""); + }, + add_anniversary_indicator: function (frm) { if (!frm.sidebar || !frm.sidebar.sidebar) return; let $sidebar = frm.sidebar.sidebar; - let $indicator_section = $sidebar.find(".anniversary-indicator-section"); - - if (!$indicator_section.length) { - $indicator_section = $(` - - `).insertAfter($sidebar.find(".sidebar-meta-details")); - } - - let content = ""; - let today = moment().startOf("day"); - - if (frm.doc.date_of_birth) { - let dob = moment(frm.doc.date_of_birth); - if (dob.date() === today.date() && dob.month() === today.month()) { - content += `