@@ -94,6 +94,8 @@ frappe.ui.form.on("Employee", {
9494 dialog . show ( ) ;
9595 } ) ;
9696 }
97+
98+ frm . trigger ( "add_anniversary_indicator" ) ;
9799 } ,
98100
99101 create_user_automatically : function ( frm ) {
@@ -105,6 +107,88 @@ frappe.ui.form.on("Employee", {
105107 }
106108 } ,
107109
110+ date_of_birth : function ( frm ) {
111+ frm . trigger ( "add_anniversary_indicator" ) ;
112+ } ,
113+
114+ date_of_joining : function ( frm ) {
115+ frm . trigger ( "add_anniversary_indicator" ) ;
116+ } ,
117+
118+ is_employee_birthday : function ( frm , today ) {
119+ if ( ! frm . doc . date_of_birth ) return false ;
120+ let dob = moment ( frm . doc . date_of_birth ) ;
121+ return dob . date ( ) === today . date ( ) && dob . month ( ) === today . month ( ) ;
122+ } ,
123+
124+ is_work_anniversary : function ( frm , today ) {
125+ if ( ! frm . doc . date_of_joining ) return false ;
126+ let doj = moment ( frm . doc . date_of_joining ) ;
127+ let years = today . year ( ) - doj . year ( ) ;
128+ return doj . date ( ) === today . date ( ) && doj . month ( ) === today . month ( ) && years > 0 ;
129+ } ,
130+
131+ get_work_anniversary_years : function ( frm , today ) {
132+ let doj = moment ( frm . doc . date_of_joining ) ;
133+ return today . year ( ) - doj . year ( ) ;
134+ } ,
135+
136+ create_milestone_section : function ( $sidebar ) {
137+ let $indicator_section = $sidebar . find ( ".anniversary-indicator-section" ) ;
138+ if ( ! $indicator_section . length ) {
139+ $indicator_section = $ ( `
140+ <div class="sidebar-section anniversary-indicator-section border-bottom">
141+ <div class="anniversary-content d-flex flex-column" style="gap: 0.5rem;"></div>
142+ </div>
143+ ` ) . insertAfter ( $sidebar . find ( ".sidebar-meta-details" ) ) ;
144+ }
145+ return $indicator_section ;
146+ } ,
147+
148+ build_anniversary_content : function ( frm ) {
149+ let today = moment ( ) ;
150+ let items = [ ] ;
151+ if ( frm . events . is_employee_birthday ( frm , today ) ) {
152+ items . push ( `
153+ <div class="form-sidebar-items milestone-item">
154+ <span class="form-sidebar-label">
155+ ${ frappe . utils . icon ( "cake" , "sm" ) }
156+ <span class="ellipsis">${ __ ( "Birthday" ) } </span>
157+ </span>
158+ </div>` ) ;
159+ }
160+ if ( frm . events . is_work_anniversary ( frm , today ) ) {
161+ let years = frm . events . get_work_anniversary_years ( frm , today ) ;
162+ let label =
163+ years === 1
164+ ? __ ( "{0} Year Work Anniversary" , [ years ] )
165+ : __ ( "{0} Years Work Anniversary" , [ years ] ) ;
166+ items . push ( `
167+ <div class="form-sidebar-items milestone-item">
168+ <span class="form-sidebar-label">
169+ ${ frappe . utils . icon ( "briefcase" , "sm" ) }
170+ <span class="ellipsis">${ label } </span>
171+ </span>
172+ </div>` ) ;
173+ }
174+ return items . join ( "" ) ;
175+ } ,
176+
177+ add_anniversary_indicator : function ( frm ) {
178+ if ( ! frm . sidebar ?. sidebar ) return ;
179+
180+ let $sidebar = frm . sidebar . sidebar ;
181+ let $indicator_section = frm . events . create_milestone_section ( $sidebar ) ;
182+ let content = frm . events . build_anniversary_content ( frm ) ;
183+
184+ if ( content ) {
185+ $indicator_section . find ( ".anniversary-content" ) . html ( content ) ;
186+ $indicator_section . show ( ) ;
187+ } else {
188+ $indicator_section . hide ( ) ;
189+ }
190+ } ,
191+
108192 prefered_contact_email : function ( frm ) {
109193 frm . events . update_contact ( frm ) ;
110194 } ,
0 commit comments