From e4a0d2ab0b155bc655821da4fde41ca1e6d579ae Mon Sep 17 00:00:00 2001 From: Krishna Shirsath Date: Wed, 11 Mar 2026 17:48:12 +0530 Subject: [PATCH] feat(employee): Enhance milestone indicators for birthdays and work anniversaries --- erpnext/setup/doctype/employee/employee.js | 100 ++++++++++++++------- 1 file changed, 66 insertions(+), 34 deletions(-) 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(` +
+ + ${frappe.utils.icon("cake", "sm")} + ${__("Birthday")} + +
`); + } + 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(` +
+ + ${frappe.utils.icon("briefcase", "sm")} + ${label} + +
`); + } + 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 += `
${__( - "Today is their Birthday!" - )}
`; - } - } - - if (frm.doc.date_of_joining) { - let doj = moment(frm.doc.date_of_joining); - if (doj.date() === today.date() && doj.month() === today.month()) { - let years = today.year() - doj.year(); - if (years > 0) { - content += `
${__( - "Today is their {0} Work Anniversary!", - [years === 1 ? __("{0} Year", [years]) : __("{0} Years", [years])] - )}
`; - } - } - } + let $indicator_section = frm.events.create_milestone_section($sidebar); + let content = frm.events.build_anniversary_content(frm); if (content) { $indicator_section.find(".anniversary-content").html(content);