db->table('t_employee_details EMP') ->select('user.isDeleted,user.createdDtm,EMP.EmpID,EMP.FirstName, EMP.LastName,EMP.Designation,user.email as EmailId,EMP.ContactNumber, DEPT.DEPCode,DEPT.DepartmentName,role.role,user.userId') ->join('t_departmentdetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode','left') ->join('tbl_users user', 'user.EmpID = EMP.EmpID','left') ->join('tbl_roles role', 'user.roleId = role.roleId','left') ->where('user.isDeleted',$isDeleted) ->orderBy('user.createdDtm', 'desc'); $query = $builder->get(); $result = $query->getResult(); 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->getResult(); } /** * This function is used to get the user roles information * @return array $result : This is result of the query */ function getUserRoles() { $builder = $this->db->table('tbl_roles') ->select('roleId, role'); $query = $builder->get(); return $query->getResult(); } /** * This function is used to check whether email id is already exist or not * @param {string} $email : This is email id * @param {number} $userId : This is user id * @return {mixed} $result : This is searched result */ function checkEmailExists($email, $userId = 0) { $builder = $this->db->table("tbl_users") ->select("email") ->where("email", $email) ->where("isDeleted", 0); if ($userId != 0) { $builder->where("userId !=", $userId); } $query = $builder->get(); return $query->getResult(); } /** * This function is used to add new user to system * @return number $insert_id : This is last inserted id */ function addNewUser($userInfo) { $this->db->transStart(); $builder = $this->db->table('tbl_users'); $builder->insert($userInfo); $insert_id = $this->db->affectedRows(); $this->db->transComplete(); return $insert_id; } /** * This function used to get user information by id * @param number $userId : This is user id * @return array $result : This is user information */ function getUserInfo($userId) { $builder = $this->db->table('tbl_users') ->select('userId, name, email, mobile, roleId,isDeleted') ->where('isDeleted', 0) ->where('roleId !=', 1) ->where('userId', $userId); $query = $builder->get(); return $query->getResult(); } /** * This function is used to update the user information * @param array $userInfo : This is users updated information * @param number $userId : This is user id */ function editUser($userInfo, $userId) { $this->db->table('tbl_users') ->where('EmpID', $userId) ->update($userInfo); return TRUE; } /** * This function is used to delete the user information * @param number $userId : This is user id * @return boolean $result : TRUE / FALSE */ function userActivation($Uid, $updateInfo) { // Delete the user record $this->db->table('tbl_users') ->where('userId', $Uid) ->update($updateInfo); // Return the number of affected rows to confirm the deletion return $this->db->affectedRows(); } /** * This function is used to match users password for change password * @param number $userId : This is user id */ function matchOldPassword($userId, $oldPassword) { $builder = $this->db->table('tbl_users') ->select('userId, password') ->where('userId', $userId) ->where('isDeleted', 0); $query = $builder->get(); $user = $query->getResult(); if (!empty($user)) { if (password_verify($oldPassword, $user[0]->password)) { return $user; } else { return array(); } } else { return array(); } } /** * This function is used to change users password * @param number $userId : This is user id * @param array $userInfo : This is user updation info */ function changePassword($userId, $userInfo) { $this->db->table('tbl_users') ->where('userId', $userId) ->where('isDeleted', 0) ->update($userInfo); return $this->db->affectedRows(); } /** * 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,user.email as EmailId,EMP.ContactNumber,DEPT.DEPCode,DEPT.DepartmentName from t_employee_details EMP join t_departmentdetails DEPT on EMP.Departmentcode = DEPT.DEPCode join tbl_users user on EMP.EmpID = user.EmpID where EMP.EmpID= (select EmpID from tbl_users where userId=?)'; $query = $this->db->query($subQuery, array($UserId)); return $query->getResult(); } /** * This function is used to get the All employees * @return array $result : This is result of the query */ function getAllEmployees() { /*->select('EmpID,FirstName,LastName'); $builder = $this->db->table('t_employee_details'); $query = $builder->get(); return $query->getResult(); */ $builder = $this->db->table('t_employee_details EMP') ->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber,DEPT.DEPCode,DEPT.DepartmentName') ->join('t_departmentdetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode') ->join('tbl_users U', 'EMP.EmpID = U.EmpID', 'left') ->where('EMP.IsActive ', 1) ->where('U.EmpID IS NULL'); $query = $builder->get(); return $query->getResult(); } function rolesNotAllotedEmployees(){ { $builder = $this->db->table('t_employee_details EMP') ->select('EMP.EmpID, EMP.FirstName, EMP.LastName, EMP.Designation, EMP.EmailId, EMP.ContactNumber, DEPT.DEPCode, DEPT.DepartmentName') ->join('t_departmentdetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode') ->join('tbl_users U', 'EMP.EmpID = U.EmpID', 'left') ->where('EMP.IsActive', 1) ->where('U.EmpID IS NULL'); $query = $builder->get(); return $query->getResult(); } } function addAccess($userdept) { $this->db->transStart(); $builder = $this->db->table('t_accessdepartments'); $builder->insert($userdept); $insert_id = $this->db->affectedRows(); $this->db->transComplete(); return $insert_id; } function DeleteAccess($empid, $Depcode) { $query = $this->db->table('t_accessdepartments')->delete(['Departmentcode' => $Depcode, 'EmpID' => $empid]); return TRUE; } //this function used to delivery performances function deliver_perform($fa, $aa, $m) { $sql = "select ip_invoices.*,ip_invoice_items.item_quantity as qty, ip_clients.* from ip_invoices join ip_clients on ip_clients.client_id=ip_invoices.client_id join ip_invoice_items on ip_invoice_items .invoice_id =ip_invoices.invoice_id join ip_invoice_custom icf on icf.invoice_id = ip_invoices.invoice_id where icf.invoice_custom_fieldid = 8 and ip_invoices.invoice_status_id != 1"; if ($fa and $aa != '') { $sql .= " and (ip_invoices.invoice_date_created >= '" . $fa . "-04-01' and ip_invoices.invoice_date_created <= '" . $aa . "-03-31')"; } if ($m != '') { $sql .= " and monthname(ip_invoices.invoice_date_created) = '" . $m . "'"; } $sql .= " ORDER BY ip_invoices.invoice_date_created DESC"; $query = $this->db->query($sql); return $query->getResult(); } function fincalYear() { $sql = "SELECT CASE WHEN MONTH(invoice_date_created)>=4 THEN concat(YEAR(invoice_date_created), '-',YEAR(invoice_date_created)+1) ELSE concat(YEAR(invoice_date_created)-1,'-', YEAR(invoice_date_created)) END AS financial_year FROM ip_invoices GROUP BY financial_year "; $query = $this->db->query($sql); //print_r($query-getResult()); return $query->getResult(); } /* *fav model */ function favouriteadd($favourite) { if ($favourite['Menu_ID'] != '') { $query = $this->db->table('t_fav_add')->delete(['Menu_ID' => $favourite['Menu_ID']]); } else { //echo "else"; $builder = $this->db->table('t_fav_add'); $builder->insert($favourite); $r = $this->db->affectedRows(); return $r; } } function findEmp($EmpId) { $builder = $this->db->table('t_employee_details') ->select('t_employee_details.*') ->where('t_employee_details.EmpID', $EmpId); $query = $builder->get(); return $query->getResult(); } public function isEmailExists($email, $excludeEmpID = null) { $builder = $this->db->table('tbl_users'); $builder->select('email'); $builder->where('email', $email); if (!empty($excludeEmpID)) { $builder->where('EmpID !=', $excludeEmpID); } $query = $builder->get(); return $query->getNumRows() > 0; } }