| 1 |
<?php |
| 2 |
|
| 3 |
/** Callbacks *****************************/ |
| 4 |
|
| 5 |
function erp_hr_dashboard_widget_birthday_callback() { |
| 6 |
erp_admin_dash_metabox( __( '<i class="fa fa-birthday-cake"></i> Birthday Buddies', 'erp' ), 'erp_hr_dashboard_widget_birthday' ); |
| 7 |
erp_admin_dash_metabox( __( '<i class="fa fa-paper-plane"></i> Who is out', 'erp' ), 'erp_hr_dashboard_widget_whoisout' ); |
| 8 |
} |
| 9 |
|
| 10 |
function erp_hr_dashboard_widget_announcement_callback() { |
| 11 |
erp_admin_dash_metabox( __( '<i class="fa fa-microphone"></i> Latest Announcement', 'erp' ), 'erp_hr_dashboard_widget_latest_announcement' ); |
| 12 |
erp_admin_dash_metabox( __( '<i class="fa fa-calendar-o"></i> My Leave Calendar', 'erp' ), 'erp_hr_dashboard_widget_leave_calendar' ); |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
add_action( 'erp_hr_dashboard_widgets_right', 'erp_hr_dashboard_widget_birthday_callback' ); |
| 17 |
add_action( 'erp_hr_dashboard_widgets_left', 'erp_hr_dashboard_widget_announcement_callback' ); |
| 18 |
|
| 19 |
/** Widgets *****************************/ |
| 20 |
|
| 21 |
/** |
| 22 |
* Birthday widget |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
function erp_hr_dashboard_widget_birthday() { |
| 27 |
$todays_birthday = erp_hr_get_todays_birthday(); |
| 28 |
$upcoming_birtday = erp_hr_get_next_seven_days_birthday(); |
| 29 |
|
| 30 |
if ( $todays_birthday ) { ?> |
| 31 |
|
| 32 |
<h4><?php _e( 'Today\'s Birthday', 'erp' ); ?></h4> |
| 33 |
<span class="wait"><?php _e( 'please wait ...', 'erp' ); ?></span> |
| 34 |
|
| 35 |
<ul class="erp-list list-inline"> |
| 36 |
<?php |
| 37 |
|
| 38 |
foreach ( $todays_birthday as $user ) { |
| 39 |
$employee = new \WeDevs\ERP\HRM\Employee( intval( $user->user_id ) ); |
| 40 |
?> |
| 41 |
<li> |
| 42 |
<a href="<?php echo $employee->get_details_url(); ?>" class="erp-tips" title="<?php echo $employee->get_full_name(); ?>"> |
| 43 |
<?php echo $employee->get_avatar( 32 ); ?></a> |
| 44 |
<?php if ( !isset($_COOKIE[ $employee->get_user_id() ] ) ) : ?> |
| 45 |
<a href="#" title="Send birthday wish email to <?php echo $employee->get_full_name(); ?>" |
| 46 |
class="send-wish" data-user_id="<?php echo intval( $employee->get_user_id() ); ?>"> |
| 47 |
<i class="fa fa-envelope-o" aria-hidden="true"></i> |
| 48 |
</a> |
| 49 |
<?php endif; ?> |
| 50 |
</li> |
| 51 |
<?php } ?> |
| 52 |
</ul> |
| 53 |
|
| 54 |
<?php |
| 55 |
} |
| 56 |
?> |
| 57 |
|
| 58 |
<?php if ( $upcoming_birtday ) { ?> |
| 59 |
|
| 60 |
<h4><?php _e( 'Upcoming Birthdays', 'erp' ); ?></h4> |
| 61 |
|
| 62 |
<ul class="erp-list list-two-side list-sep"> |
| 63 |
|
| 64 |
<?php foreach ( $upcoming_birtday as $key => $user ): ?> |
| 65 |
|
| 66 |
<?php $employee = new \WeDevs\ERP\HRM\Employee( intval( $user->user_id ) ); ?> |
| 67 |
|
| 68 |
<li> |
| 69 |
<a href="<?php echo $employee->get_details_url(); ?>"><?php echo $employee->get_full_name(); ?></a> |
| 70 |
<span><?php echo erp_format_date( $user->date_of_birth, 'M, d' ); ?></span> |
| 71 |
</li> |
| 72 |
|
| 73 |
<?php endforeach; ?> |
| 74 |
|
| 75 |
</ul> |
| 76 |
<?php |
| 77 |
} |
| 78 |
|
| 79 |
if ( ! $todays_birthday && ! $upcoming_birtday ) { |
| 80 |
_e( 'No one has birthdays this week!', 'erp' ); |
| 81 |
} |
| 82 |
?> |
| 83 |
<style> |
| 84 |
span.wait { |
| 85 |
display: none; |
| 86 |
float: right; |
| 87 |
} |
| 88 |
.erp-list .send-wish { |
| 89 |
box-shadow: none; |
| 90 |
} |
| 91 |
.erp-list .send-wish i { |
| 92 |
color: #fbc02d; |
| 93 |
} |
| 94 |
</style> |
| 95 |
<?php |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Latest Announcement Widget |
| 100 |
* |
| 101 |
* @since 0.1 |
| 102 |
* |
| 103 |
* @return void |
| 104 |
*/ |
| 105 |
function erp_hr_dashboard_widget_latest_announcement() { |
| 106 |
|
| 107 |
//if user is admin then show latest 5 announcements |
| 108 |
if ( current_user_can( erp_hr_get_manager_role() ) ) { |
| 109 |
$query = new WP_Query( array( |
| 110 |
'post_type' => 'erp_hr_announcement', |
| 111 |
'posts_per_page' => '5', |
| 112 |
'order' => 'DESC' |
| 113 |
) ); |
| 114 |
$announcements = $query->get_posts(); |
| 115 |
} else { |
| 116 |
$announcements = erp_hr_employee_dashboard_announcement( get_current_user_id() ); |
| 117 |
} |
| 118 |
|
| 119 |
if ( $announcements ) { |
| 120 |
?> |
| 121 |
<ul class="erp-list erp-dashboard-announcement"> |
| 122 |
<?php |
| 123 |
$i = 0; |
| 124 |
foreach ( $announcements as $key => $announcement ): ?> |
| 125 |
<li class="<?php echo ($announcement->status !== 'read') ? 'unread' : 'read'; ?>"> |
| 126 |
<div class="announcement-title"> |
| 127 |
<a href="#" <?php echo ( $announcement->status == 'read' ) ? 'class="read"' : ''; ?>> |
| 128 |
<?php echo $announcement->post_title; ?> |
| 129 |
</a> | <span class="announcement-date"><?php echo erp_format_date( $announcement->post_date ); ?></span> |
| 130 |
</div > |
| 131 |
|
| 132 |
<?php echo ( 0 == $i ) ? '<p>' . wp_trim_words( $announcement->post_content, 50 ) . '</p>' : ''; ?> |
| 133 |
|
| 134 |
<div class="announcement-row-actions"> |
| 135 |
<?php if ( ! current_user_can( erp_hr_get_manager_role() ) ): ?> |
| 136 |
<a href="#" class="mark-read erp-tips <?php echo ( $announcement->status == 'read' ) ? 'erp-hide' : ''; ?>" title="<?php _e( 'Mark as Read', 'erp' ); ?>" data-row_id="<?php echo $announcement->id; ?>"><i class="dashicons dashicons-yes"></i></a> |
| 137 |
<?php endif; ?> |
| 138 |
<a href="#" class="view-full erp-tips" title="<?php _e( 'View full announcement', 'erp' ); ?>" data-row_id="<?php echo $announcement->ID; ?>"><i class="dashicons dashicons-editor-expand"></i></a> |
| 139 |
</div> |
| 140 |
</li> |
| 141 |
<?php $i++; |
| 142 |
endforeach ?> |
| 143 |
</ul> |
| 144 |
<?php |
| 145 |
} else { |
| 146 |
_e( 'No announcement found', 'erp' ); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Erp dashboard who is out widget |
| 152 |
* |
| 153 |
* @since 0.1 |
| 154 |
* |
| 155 |
* @return void |
| 156 |
*/ |
| 157 |
function erp_hr_dashboard_widget_whoisout() { |
| 158 |
$leave_requests = erp_hr_get_current_month_leave_list(); |
| 159 |
$leave_requests_nextmonth = erp_hr_get_next_month_leave_list(); |
| 160 |
?> |
| 161 |
<?php if ( $leave_requests ) { ?> |
| 162 |
|
| 163 |
<h4><?php _e( 'This Month', 'erp' ); ?></h4> |
| 164 |
|
| 165 |
<ul class="erp-list list-two-side list-sep"> |
| 166 |
<?php foreach ( $leave_requests as $key => $leave ): ?> |
| 167 |
<?php $employee = new \WeDevs\ERP\HRM\Employee( intval( $leave->user_id ) ); ?> |
| 168 |
<li> |
| 169 |
<a href="<?php echo $employee->get_details_url(); ?>"><?php echo $employee->get_full_name(); ?></a> |
| 170 |
<span><i class="fa fa-calendar"></i> <?php echo erp_format_date( $leave->start_date, 'M d' ) . ' - '. erp_format_date( $leave->end_date, 'M d' ); ?></span> |
| 171 |
</li> |
| 172 |
<?php endforeach ?> |
| 173 |
</ul> |
| 174 |
<?php } ?> |
| 175 |
|
| 176 |
<?php if ( $leave_requests_nextmonth ) { ?> |
| 177 |
<h4><?php _e( 'Next Month', 'erp' ); ?></h4> |
| 178 |
|
| 179 |
<ul class="erp-list list-two-side list-sep"> |
| 180 |
<?php foreach ( $leave_requests_nextmonth as $key => $leave ): ?> |
| 181 |
<?php $employee = new \WeDevs\ERP\HRM\Employee( intval( $leave->user_id ) ); ?> |
| 182 |
<li> |
| 183 |
<a href="<?php echo $employee->get_details_url(); ?>"><?php echo $employee->get_full_name(); ?></a> |
| 184 |
<span><i class="fa fa-calendar"></i> <?php echo erp_format_date( $leave->start_date, 'M d' ) . ' - '. erp_format_date( $leave->end_date, 'M d' ); ?></span> |
| 185 |
</li> |
| 186 |
<?php endforeach ?> |
| 187 |
</ul> |
| 188 |
|
| 189 |
<?php } ?> |
| 190 |
|
| 191 |
<?php if ( ! $leave_requests && ! $leave_requests_nextmonth ) { ?> |
| 192 |
|
| 193 |
<?php _e( 'No one is on vacation on this or next month', 'erp' ); ?> |
| 194 |
|
| 195 |
<?php } ?> |
| 196 |
|
| 197 |
<?php |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* ERP dashboard leave calendar widget |
| 202 |
* |
| 203 |
* @since 0.1 |
| 204 |
* |
| 205 |
* @return void |
| 206 |
*/ |
| 207 |
function erp_hr_dashboard_widget_leave_calendar() { |
| 208 |
|
| 209 |
$user_id = get_current_user_id(); |
| 210 |
$leave_requests = erp_hr_get_calendar_leave_events( false, $user_id, false ); |
| 211 |
$holidays = erp_array_to_object( \WeDevs\ERP\HRM\Models\Leave_Holiday::all()->toArray() ); |
| 212 |
$events = []; |
| 213 |
$holiday_events = []; |
| 214 |
$event_data = []; |
| 215 |
|
| 216 |
foreach ( $leave_requests as $key => $leave_request ) { |
| 217 |
//if status pending |
| 218 |
$policy = erp_hr_leave_get_policy( $leave_request->policy_id ); |
| 219 |
$event_label = $policy->name; |
| 220 |
if ( 2 == $leave_request->status ) { |
| 221 |
$policy = erp_hr_leave_get_policy( $leave_request->policy_id ); |
| 222 |
$event_label .= sprintf( ' ( %s ) ', __( 'Pending', 'erp' ) ); |
| 223 |
} |
| 224 |
$events[] = array( |
| 225 |
'id' => $leave_request->id, |
| 226 |
'title' => $event_label, |
| 227 |
'start' => $leave_request->start_date, |
| 228 |
'end' => $leave_request->end_date, |
| 229 |
'url' => erp_hr_url_single_employee( $leave_request->user_id, 'leave' ), |
| 230 |
'color' => $leave_request->color, |
| 231 |
); |
| 232 |
} |
| 233 |
|
| 234 |
foreach ( $holidays as $key => $holiday ) { |
| 235 |
$holiday_events[] = [ |
| 236 |
'id' => $holiday->id, |
| 237 |
'title' => $holiday->title, |
| 238 |
'start' => $holiday->start, |
| 239 |
'end' => $holiday->end, |
| 240 |
'color' => '#FF5354', |
| 241 |
'img' => '', |
| 242 |
'holiday' => true |
| 243 |
]; |
| 244 |
} |
| 245 |
|
| 246 |
$event_data = array_merge( $events, $holiday_events ); |
| 247 |
|
| 248 |
?> |
| 249 |
<style> |
| 250 |
.fc-time { |
| 251 |
display:none; |
| 252 |
} |
| 253 |
.erp-leave-avatar img { |
| 254 |
border-radius: 50%; |
| 255 |
margin: 3px 7px 0 0; |
| 256 |
|
| 257 |
} |
| 258 |
.erp-calendar-filter { |
| 259 |
margin: 15px 0px; |
| 260 |
} |
| 261 |
.fc-title { |
| 262 |
position: relative; |
| 263 |
} |
| 264 |
</style> |
| 265 |
|
| 266 |
<?php if ( erp_hr_get_assign_policy_from_entitlement( $user_id ) ): ?> |
| 267 |
<div class="erp-hr-new-leave-request-wrap"> |
| 268 |
<a href="#" class="button button-primary" id="erp-hr-new-leave-req"><?php _e( 'Take a Leave', 'erp' ); ?></a> |
| 269 |
</div> |
| 270 |
<?php endif ?> |
| 271 |
|
| 272 |
<div id="erp-hr-calendar"></div> |
| 273 |
|
| 274 |
<script> |
| 275 |
;jQuery(document).ready(function($) { |
| 276 |
|
| 277 |
$('#erp-hr-calendar').fullCalendar({ |
| 278 |
header: { |
| 279 |
left: 'prev,next today', |
| 280 |
center: 'title', |
| 281 |
right: 'month,agendaWeek,agendaDay' |
| 282 |
}, |
| 283 |
editable: false, |
| 284 |
eventLimit: true, |
| 285 |
events: <?php echo json_encode( $event_data ); ?>, |
| 286 |
eventRender: function(event, element, calEvent) { |
| 287 |
if ( event.holiday ) { |
| 288 |
element.find('.fc-content').find('.fc-title').css({ 'top':'0px', 'left' : '3px', 'fontSize' : '13px', 'padding':'2px' }); |
| 289 |
}; |
| 290 |
}, |
| 291 |
}); |
| 292 |
}); |
| 293 |
|
| 294 |
</script> |
| 295 |
<?php |
| 296 |
} |
| 297 |
|
| 298 |
/** |
| 299 |
* Employee list url |
| 300 |
* |
| 301 |
* @since 1.1.10 |
| 302 |
* |
| 303 |
* @return string |
| 304 |
*/ |
| 305 |
function erp_hr_employee_list_url() { |
| 306 |
$args = [ |
| 307 |
'page' => 'erp-hr-employee' |
| 308 |
]; |
| 309 |
|
| 310 |
$url = add_query_arg( $args, admin_url( 'admin.php' ) ); |
| 311 |
$url = apply_filters( 'erp_hr_employee_list_url', $url, $args ); |
| 312 |
|
| 313 |
return $url; |
| 314 |
} |
| 315 |
|