/** * Employee Termination * * @since 0.1 * * @return json */ public function employee_terminate() { $this->verify_nonce('employee_update_terminate'); $employee_id = isset($_POST['employee_id']) ? intval($_POST['employee_id']) : 0; $terminate_date = empty($_POST['terminate_date']) ? current_time('mysql') : $_POST['terminate_date']; $termination_type = isset($_POST['termination_type']) ? $_POST['termination_type'] : ''; $termination_reason = isset($_POST['termination_reason']) ? $_POST['termination_reason'] : ''; $eligible_for_rehire = isset($_POST['eligible_for_rehire']) ? $_POST['eligible_for_rehire'] : ''; $requires = ['terminate_date' => __('Termination Date', 'wp-erp'), 'termination_type' => __('Termination Type', 'wp-erp'), 'termination_reason' => __('Termination Reason', 'wp-erp'), 'eligible_for_rehire' => __('Eligible for Hire', 'wp-erp')]; $fields = ['terminate_date' => $terminate_date, 'termination_type' => $termination_type, 'termination_reason' => $termination_reason, 'eligible_for_rehire' => $eligible_for_rehire]; foreach ($requires as $var_name => $label) { if (!${$var_name}) { $this->send_error(sprintf(__('%s is required', 'wp-erp'), $label)); } } $employee = new \WeDevs\ERP\HRM\Models\Employee(); $employee->where('user_id', $employee_id)->update(['status' => 'terminated', 'termination_date' => $terminate_date]); update_user_meta($employee_id, '_erp_hr_termination', $fields); $this->send_success(); }
/** * Get all employees from a company * * @param int $company_id company id * @param bool $no_object if set true, Employee object will be * returned as array. $wpdb rows otherwise * * @return array the employees */ function erp_hr_count_employees() { $where = array(); $employee = new \WeDevs\ERP\HRM\Models\Employee(); if (isset($args['designation']) && !empty($args['designation'])) { $designation = array('designation' => $args['designation']); $where = array_merge($designation, $where); } if (isset($args['department']) && !empty($args['department'])) { $department = array('department' => $args['department']); $where = array_merge($where, $department); } if (isset($args['location']) && !empty($args['location'])) { $location = array('location' => $args['location']); $where = array_merge($where, $location); } if (isset($args['status']) && !empty($args['status'])) { $status = array('status' => $args['status']); $where = array_merge($where, $status); } $counts = $employee->where($where)->count(); return $counts; }
/** * Create a new employee when a user role is changed to employee * * @param int $user_id * @param string $role * * @return void */ function erp_hr_existing_role_to_employee($user_id, $role) { if ('employee' != $role) { return; } // check if a employee of that ID exists, otherwise create one $employee = new \WeDevs\ERP\HRM\Models\Employee(); $exists = $employee->where('user_id', '=', $user_id)->get()->first(); if (null === $exists) { $employee->create(['user_id' => $user_id, 'designation' => 0, 'department' => 0, 'status' => 'active']); } }