/** * Default column values if no callback found * * @param object $item * @param string $column_name * * @return string */ function column_default($entitlement, $column_name) { $balance = erp_hr_leave_get_balance($entitlement->user_id); if (isset($balance[$entitlement->policy_id])) { $scheduled = $balance[$entitlement->policy_id]['scheduled']; $available = $balance[$entitlement->policy_id]['entitlement'] - $balance[$entitlement->policy_id]['total']; } else { $scheduled = ''; $available = ''; } switch ($column_name) { case 'name': return sprintf('<strong><a href="%s">%s</a></strong>', erp_hr_url_single_employee($entitlement->user_id), esc_html($entitlement->employee_name)); case 'leave_policy': return esc_html($entitlement->policy_name); case 'valid_from': return erp_format_date($entitlement->from_date); case 'valid_to': return erp_format_date($entitlement->to_date); case 'days': return number_format_i18n($entitlement->days); case 'scheduled': return $scheduled ? sprintf(__('%d days', 'wp-erp'), number_format_i18n($scheduled)) : '-'; case 'available': if ($available < 0) { return sprintf('<span class="red">%d %s</span>', number_format_i18n($available), __('days', 'wp-erp')); } elseif ($available > 0) { return sprintf('<span class="green">%d %s</span>', number_format_i18n($available), __('days', 'wp-erp')); } else { return '-'; } default: return isset($entitlement->{$column_name}) ? $entitlement->{$column_name} : ''; } }
/** * Get available day for users leave policy * * @since 0.1 * * @return json */ public function leave_available_days() { $this->verify_nonce('wp-erp-hr-nonce'); $employee_id = isset($_POST['employee_id']) && $_POST['employee_id'] ? intval($_POST['employee_id']) : false; $policy_id = isset($_POST['policy_id']) && $_POST['policy_id'] ? intval($_POST['policy_id']) : false; $available = 0; if (!$employee_id) { $this->send_error('Please select an employee', 'wp-erp'); } if (!$policy_id) { $this->send_error('Please select a policy', 'wp-erp'); } $balance = erp_hr_leave_get_balance($employee_id); if (array_key_exists($policy_id, $balance)) { $available = $balance[$policy_id]['entitlement'] - $balance[$policy_id]['total']; } if ($available < 0) { $content = sprintf('<span class="description red">%d %s</span>', number_format_i18n($available), __('days are available', 'wp-erp')); } elseif ($available > 0) { $content = sprintf('<span class="description green">%d %s</span>', number_format_i18n($available), __('days are available', 'wp-erp')); } else { $leave_policy_day = \WeDevs\ERP\HRM\Models\Leave_Policies::select('value')->where('id', $policy_id)->pluck('value'); $content = sprintf('<span class="description">%d %s</span>', number_format_i18n($leave_policy_day), __('days are available', 'wp-erp')); } $this->send_success($content); }
<h3><?php _e('Balances', 'wp-erp'); ?> </h3> <?php $policies = erp_hr_leave_get_policies(); $entitlements = erp_hr_leave_get_entitlements(array('employee_id' => $employee->id)); $entitlements_pol = wp_list_pluck($entitlements, 'policy_id'); $balance = erp_hr_leave_get_balance($employee->id); if ($policies) { ?> <table class="widefat"> <thead> <tr> <th><?php _e('Leave', 'wp-erp'); ?> </th> <th><?php _e('Current', 'wp-erp'); ?> </th> <th><?php _e('Scheduled', 'wp-erp'); ?> </th> <th><?php _e('Available', 'wp-erp'); ?>