feat(employee): Add birthdays and work anniversaries indicator in form ,list view enhancements and new empty state.

(cherry picked from commit 4f43f655cf)
This commit is contained in:
Krishna Shirsath
2026-02-25 13:21:06 +05:30
committed by Mergify
parent b0145512ed
commit 0b3c9120c3
3 changed files with 84 additions and 2 deletions

View File

@@ -46,6 +46,8 @@ frappe.ui.form.on("Employee", {
refresh: function (frm) {
frm.fields_dict.date_of_birth.datepicker.update({ maxDate: new Date() });
frm.trigger("add_anniversary_indicator");
if (!frm.is_new() && !frm.doc.user_id) {
frm.add_custom_button(__("Create User"), () => {
const dialog = new frappe.ui.Dialog({
@@ -95,6 +97,61 @@ frappe.ui.form.on("Employee", {
}
},
date_of_birth: function (frm) {
frm.trigger("add_anniversary_indicator");
},
date_of_joining: function (frm) {
frm.trigger("add_anniversary_indicator");
},
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 = $(`
<div class="sidebar-section anniversary-indicator-section border-bottom">
<div class="anniversary-content"></div>
</div>
`).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 += `<div class="mb-1"><span class="indicator green"></span> ${__(
"Today is their Birthday!"
)}</div>`;
}
}
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 += `<div class="mb-1"><span class="indicator green"></span> ${__(
"Today is their {0} Year Work Anniversary!",
[years]
)}</div>`;
}
}
}
if (content) {
$indicator_section.find(".anniversary-content").html(content);
$indicator_section.show();
} else {
$indicator_section.hide();
}
},
prefered_contact_email: function (frm) {
frm.events.update_contact(frm);
},

View File

@@ -351,6 +351,7 @@
{
"fieldname": "department",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Department",
"oldfieldname": "department",
@@ -380,6 +381,7 @@
{
"fieldname": "branch",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Branch",
"oldfieldname": "branch",
"oldfieldtype": "Link",
@@ -831,7 +833,7 @@
"image_field": "image",
"is_tree": 1,
"links": [],
"modified": "2026-02-19 17:07:42.691107",
"modified": "2026-02-25 11:23:10.689232",
"modified_by": "Administrator",
"module": "Setup",
"name": "Employee",

View File

@@ -1,11 +1,34 @@
frappe.listview_settings["Employee"] = {
add_fields: ["status", "branch", "department", "designation", "image"],
filters: [["status", "=", "Active"]],
get_indicator: function (doc) {
get_indicator(doc) {
return [
__(doc.status, null, "Employee"),
{ Active: "green", Inactive: "red", Left: "gray", Suspended: "orange" }[doc.status],
"status,=," + doc.status,
];
},
onload(listview) {
listview.get_no_result_message = () => {
return `
<div class="msg-box no-border">
<div class="mb-4">
<svg class="icon icon-xl" style="stroke: var(--text-light);">
<use href="#icon-small-file"></use>
</svg>
</div>
<p>${__("No Active Employees Found. Prefer importing if you have many records.")}</p>
<p>
<button class="btn btn-primary btn-sm btn-new-doc">
${__("Create New")}
</button>
<button class="btn btn-default btn-sm" onclick="frappe.set_route('List', 'Data Import', {reference_doctype: 'Employee'})">
${__("Import Employees")}
</button>
</p>
</div>
`;
};
},
};