@@ -46,6 +46,8 @@ frappe.ui.form.on("Employee", {
4646 refresh : function ( frm ) {
4747 frm . fields_dict . date_of_birth . datepicker . update ( { maxDate : new Date ( ) } ) ;
4848
49+ frm . trigger ( "add_anniversary_indicator" ) ;
50+
4951 if ( ! frm . is_new ( ) && ! frm . doc . user_id ) {
5052 frm . add_custom_button ( __ ( "Create User" ) , ( ) => {
5153 const dialog = new frappe . ui . Dialog ( {
@@ -95,6 +97,61 @@ frappe.ui.form.on("Employee", {
9597 }
9698 } ,
9799
100+ date_of_birth : function ( frm ) {
101+ frm . trigger ( "add_anniversary_indicator" ) ;
102+ } ,
103+
104+ date_of_joining : function ( frm ) {
105+ frm . trigger ( "add_anniversary_indicator" ) ;
106+ } ,
107+
108+ add_anniversary_indicator : function ( frm ) {
109+ if ( ! frm . sidebar || ! frm . sidebar . sidebar ) return ;
110+
111+ let $sidebar = frm . sidebar . sidebar ;
112+ let $indicator_section = $sidebar . find ( ".anniversary-indicator-section" ) ;
113+
114+ if ( ! $indicator_section . length ) {
115+ $indicator_section = $ ( `
116+ <div class="sidebar-section anniversary-indicator-section border-bottom">
117+ <div class="anniversary-content"></div>
118+ </div>
119+ ` ) . insertAfter ( $sidebar . find ( ".sidebar-meta-details" ) ) ;
120+ }
121+
122+ let content = "" ;
123+ let today = moment ( ) . startOf ( "day" ) ;
124+
125+ if ( frm . doc . date_of_birth ) {
126+ let dob = moment ( frm . doc . date_of_birth ) ;
127+ if ( dob . date ( ) === today . date ( ) && dob . month ( ) === today . month ( ) ) {
128+ content += `<div class="mb-1"><span class="indicator green"></span> ${ __ (
129+ "Today is their Birthday!"
130+ ) } </div>`;
131+ }
132+ }
133+
134+ if ( frm . doc . date_of_joining ) {
135+ let doj = moment ( frm . doc . date_of_joining ) ;
136+ if ( doj . date ( ) === today . date ( ) && doj . month ( ) === today . month ( ) ) {
137+ let years = today . year ( ) - doj . year ( ) ;
138+ if ( years > 0 ) {
139+ content += `<div class="mb-1"><span class="indicator green"></span> ${ __ (
140+ "Today is their {0} Year Work Anniversary!" ,
141+ [ years ]
142+ ) } </div>`;
143+ }
144+ }
145+ }
146+
147+ if ( content ) {
148+ $indicator_section . find ( ".anniversary-content" ) . html ( content ) ;
149+ $indicator_section . show ( ) ;
150+ } else {
151+ $indicator_section . hide ( ) ;
152+ }
153+ } ,
154+
98155 prefered_contact_email : function ( frm ) {
99156 frm . events . update_contact ( frm ) ;
100157 } ,
0 commit comments