diff --git a/application/models/login_model.php b/application/models/login_model.php index 51177edd..b7afc93f 100644 --- a/application/models/login_model.php +++ b/application/models/login_model.php @@ -10,15 +10,18 @@ class Login_model extends CI_Model */ function loginMe($email, $password) { - $this->db->select('BaseTbl.userId, BaseTbl.password, BaseTbl.name, BaseTbl.roleId, Roles.role'); + $this->db->select('BaseTbl.userId, BaseTbl.password, Emp.FirstName,Emp.Designation, BaseTbl.roleId, Roles.role,DEPT.DEPCode,DEPT.DepartmentName,DEPT.HeadDept'); $this->db->from('tbl_users as BaseTbl'); $this->db->join('tbl_roles as Roles','Roles.roleId = BaseTbl.roleId'); + $this->db->join('T_Employee_Details as Emp','BaseTbl.EmpID = Emp.EmpID'); + $this->db->join('T_DepartmentDetails as DEPT','Emp.Departmentcode = DEPT.DEPCode'); $this->db->where('BaseTbl.email', $email); $this->db->where('BaseTbl.isDeleted', 0); $query = $this->db->get(); - - $user = $query->result(); - + print_r( $this->db->last_query()); + + $user = $query->result(); + if(!empty($user)){ if(verifyHashedPassword($password, $user[0]->password)){ return $user; diff --git a/application/models/user_model.php b/application/models/user_model.php index 8b8a1b2d..caca933c 100644 --- a/application/models/user_model.php +++ b/application/models/user_model.php @@ -9,17 +9,25 @@ class User_model extends CI_Model */ function userListingCount($searchText = '') { - $this->db->select('BaseTbl.userId, BaseTbl.email, BaseTbl.name, BaseTbl.mobile, Role.role,BaseTbl.isDeleted'); - $this->db->from('tbl_users as BaseTbl'); - $this->db->join('tbl_roles as Role', 'Role.roleId = BaseTbl.roleId','left'); + $this->db->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber, + DEPT.DEPCode,DEPT.DepartmentName,role.role,user.userId'); + $this->db->from('T_Employee_Details EMP'); + $this->db->join('T_DepartmentDetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode'); + $this->db->join('tbl_users user', 'user.EmpID = EMP.EmpID'); + $this->db->join('tbl_roles role', 'user.roleId = role.roleId'); if(!empty($searchText)) { - $likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%' - OR BaseTbl.name LIKE '%".$searchText."%' - OR BaseTbl.mobile LIKE '%".$searchText."%')"; + $likeCriteria = "(EMP.FirstName LIKE '%".$searchText."%' + OR EMP.LastName LIKE '%".$searchText."%' + OR EMP.EmailId LIKE '%".$searchText."%' + OR EMP.ContactNumber LIKE '%".$searchText."%' + OR EMP.Designation LIKE '%".$searchText."%' + OR DEPT.DepartmentName LIKE '%".$searchText."%' + OR role.role LIKE '%".$searchText."%' + OR EMP.Designation LIKE '%".$searchText."%')"; $this->db->where($likeCriteria); } - //$this->db->where('BaseTbl.isDeleted', 0); - $this->db->where('BaseTbl.roleId !=', 1); + $this->db->where('user.isDeleted !=', 1); + $query = $this->db->get(); return count($query->result()); @@ -34,25 +42,44 @@ class User_model extends CI_Model */ function userListing($searchText = '', $page, $segment) { - $this->db->select('BaseTbl.userId, BaseTbl.email, BaseTbl.name, BaseTbl.mobile, Role.role, BaseTbl.isDeleted'); - $this->db->from('tbl_users as BaseTbl'); - $this->db->join('tbl_roles as Role', 'Role.roleId = BaseTbl.roleId','left'); + $this->db->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber, + DEPT.DEPCode,DEPT.DepartmentName,role.role,user.userId'); + $this->db->from('T_Employee_Details EMP'); + $this->db->join('T_DepartmentDetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode'); + $this->db->join('tbl_users user', 'user.EmpID = EMP.EmpID'); + $this->db->join('tbl_roles role', 'user.roleId = role.roleId'); if(!empty($searchText)) { - $likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%' - OR BaseTbl.name LIKE '%".$searchText."%' - OR BaseTbl.mobile LIKE '%".$searchText."%')"; + $likeCriteria = "(EMP.FirstName LIKE '%".$searchText."%' + OR EMP.LastName LIKE '%".$searchText."%' + OR EMP.EmailId LIKE '%".$searchText."%' + OR EMP.ContactNumber LIKE '%".$searchText."%' + OR EMP.Designation LIKE '%".$searchText."%' + OR DEPT.DepartmentName LIKE '%".$searchText."%' + OR role.role LIKE '%".$searchText."%' + OR EMP.Designation LIKE '%".$searchText."%')"; $this->db->where($likeCriteria); } - //$this->db->where('BaseTbl.isDeleted', 0); - $this->db->where('BaseTbl.roleId !=', 1); + + $this->db->where('user.isDeleted !=', 1); $this->db->limit($page, $segment); $query = $this->db->get(); $result = $query->result(); return $result; } - + + function GetRoleNameByUserID($UserId) + { + $subQuery = 'select roleId, role from tbl_roles + where roleId = (select roleId from tbl_users where userId=?)'; + + $query = $this->db->query($subQuery, array($UserId)); + + + return $query->result(); + + } /** * This function is used to get the user roles information * @return array $result : This is result of the query @@ -61,7 +88,7 @@ class User_model extends CI_Model { $this->db->select('roleId, role'); $this->db->from('tbl_roles'); - //$this->db->where('roleId !=', 1); + $this->db->where("roleid <", 4); $query = $this->db->get(); return $query->result(); @@ -97,7 +124,7 @@ class User_model extends CI_Model $this->db->trans_start(); $this->db->insert('tbl_users', $userInfo); - $insert_id = $this->db->insert_id(); + $insert_id = $this->db->affected_rows(); $this->db->trans_complete(); @@ -188,6 +215,41 @@ class User_model extends CI_Model return $this->db->affected_rows(); } + /** + * This function is used to get Employee details based on Employee ID Selection + * @return array $result : This is result of the query + */ + function GetEmployeeDetails($UserId) + { + //echo $UserId; + $subQuery = 'select EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber,DEPT.DEPCode,DEPT.DepartmentName from + T_Employee_Details EMP join T_DepartmentDetails DEPT on + EMP.Departmentcode = DEPT.DEPCode where EMP.EmpID= (select EmpID from tbl_users where userId=?)'; + + $query = $this->db->query($subQuery, array($UserId)); + + + + return $query->result(); + } + /** + * This function is used to get the All employees + * @return array $result : This is result of the query + */ + function getAllEmployees() + { + /*$this->db->select('EmpID,FirstName,LastName'); + $this->db->from('T_Employee_Details'); + $query = $this->db->get(); + + return $query->result(); */ + $this->db->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber,DEPT.DEPCode,DEPT.DepartmentName'); + $this->db->from('T_Employee_Details EMP'); + $this->db->join('T_DepartmentDetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode'); + $this->db->where('EMP.IsActive ',1 ); + $query = $this->db->get(); + return $query->result(); + } } \ No newline at end of file