/** * Get assign policies according to employee entitlement * * @since 0.1 * * @param integer $employee_id * * @return boolean|array */ function erp_hr_get_assign_policy_from_entitlement($employee_id) { global $wpdb; $data = []; $dropdown = []; $policy = new \WeDevs\ERP\HRM\Models\Leave_Policies(); $en = new \WeDevs\ERP\HRM\Models\Leave_Entitlement(); $policy_tb = $wpdb->prefix . 'erp_hr_leave_policies'; $en_tb = $wpdb->prefix . 'erp_hr_leave_entitlements'; $financial_start_date = erp_financial_start_date(); $financial_end_date = erp_financial_end_date(); $policies = \WeDevs\ERP\HRM\Models\Leave_Policies::select($policy_tb . '.name', $policy_tb . '.id')->leftjoin($en_tb, $en_tb . '.policy_id', '=', $policy_tb . '.id')->where($en_tb . '.user_id', $employee_id)->where('from_date', '>=', $financial_start_date)->where('to_date', '<=', $financial_end_date)->distinct()->get()->toArray(); if (!empty($policies)) { foreach ($policies as $policy) { $dropdown[$policy['id']] = stripslashes($policy['name']); } return $dropdown; } return false; }
/** * 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); }