siddharth_application/application/models/Employeedetails_model.php
saravanakumar_kandasami 9a4c13b92a updated code for demo
2017-03-28 11:30:22 +05:30

165 lines
6.5 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class Employeedetails_model extends CI_Model
{
/**
* This function is used to get the user listing count
* @param string $searchText : This is optional search text
* @return number $count : This is row count
*/
function employeeListingCount($searchText = ''){
$this->db->select('BaseT.EmpID, BaseT.FirstName, BaseT.LastName, BaseT.DateofBirth,BaseT.ContactNumber, BaseT.EmailId,BaseT.DateofJoining,BaseT.Address1,BaseT.Address2,BaseT.Place,BaseT.City,BaseT.State,BaseT.Pin
,BaseT.DepartmentName,BaseT.User_Comments,role.role');
$this->db->from('T_EmpDetails as BaseT');
$this->db->join('tbl_roles as role', 'role.Role = BaseT.role','left');
if(!empty($searchText)) {
$likeCriteria = "(BaseT.EmpID LIKE '%".$searchText."%'
OR BaseT.FirstName LIKE '%".$searchText."%'
OR BaseT.LastName LIKE '%".$searchText."%'
OR BaseT.DateofBirth LIKE '%".$searchText."%'
OR BaseT.ContactNumber LIKE '%".$searchText."%'
OR BaseT.EmailId LIKE '%".$searchText."%'
OR BaseT.DateofJoining LIKE '%".$searchText."%'
OR BaseT.Role LIKE '%".$searchText."%'
OR BaseT.Address1 LIKE '%".$searchText."%'
OR BaseT.Address2 LIKE '%".$searchText."%'
OR BaseT.Place LIKE '%".$searchText."%'
OR BaseT.City LIKE '%".$searchText."%'
OR BaseT.State LIKE '%".$searchText."%'
OR BaseT.DepartmentName LIKE '%".$searchText."%'
OR BaseT.User_Comments LIKE '%".$searchText."%'
OR BaseT.Pin LIKE '%".$searchText."%'
)";
$this->db->where($likeCriteria);
}
//$this->db->where('BaseT.userId !=', 1);
$query = $this->db->get();
return count($query->result());
}
/**
* This function is used to get the user listing count
* @param string $searchText : This is optional search text
* @param number $page : This is pagination offset
* @param number $segment : This is pagination limit
* @return array $result : This is result
*/
function employeeListing($searchText = '', $page, $segment)
{
$this->db->select('BaseT.EmpID, BaseT.FirstName, BaseT.LastName, BaseT.DateofBirth,BaseT.ContactNumber, BaseT.EmailId,BaseT.DateofJoining,BaseT.Address1,BaseT.Address2,BaseT.Place,BaseT.City,BaseT.State,BaseT.Pin,BaseT.DepartmentName,BaseT.User_Comments,role.role');
$this->db->from('T_EmpDetails as BaseT');
$this->db->join('tbl_roles as role', 'role.Role = BaseT.Role','left');
if(!empty($searchText)) {
$likeCriteria = "(BaseT.EmpID LIKE '%".$searchText."%'
OR BaseT.FirstName LIKE '%".$searchText."%'
OR BaseT.LastName LIKE '%".$searchText."%'
OR BaseT.DateofBirth LIKE '%".$searchText."%'
OR BaseT.ContactNumber LIKE '%".$searchText."%'
OR BaseT.EmailId LIKE '%".$searchText."%'
OR BaseT.DateofJoining LIKE '%".$searchText."%'
OR BaseT.Role LIKE '%".$searchText."%'
OR BaseT.Address1 LIKE '%".$searchText."%'
OR BaseT.Address2 LIKE '%".$searchText."%'
OR BaseT.Place LIKE '%".$searchText."%'
OR BaseT.City LIKE '%".$searchText."%'
OR BaseT.State LIKE '%".$searchText."%'
OR BaseT.DepartmentName LIKE '%".$searchText."%'
OR BaseT.User_Comments LIKE '%".$searchText."%'
OR BaseT.Pin LIKE '%".$searchText."%'
)";
$this->db->where($likeCriteria);
}
//$this->db->where('BaseT.isDeleted', 0);
//$this->db->where('BaseT.userId !=', 1);
$this->db->limit($page, $segment);
$query = $this->db->get();
$result = $query->result();
return $result;
}
function getUserRoles()
{
$this->db->select('roleId, role');
$this->db->from('tbl_roles');
$this->db->where('roleId !=', 1);
$query = $this->db->get();
return $query->result();
}
/**
* This function used to get user information by id
* @param number $userId : This is user id
* @return array $result : This is user information
*/
function addNewemployee($Employee)
{
$this->db->trans_start();
$this->db->insert('T_EmpDetails', $Employee);
$Asset_Code = $this->db->insert_id();
$this->db->trans_complete();
return $EmpID;
}
/**
* 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($EmpID)
{
$this->db->select('EmpID,FirstName,LastName,DateofBirth,ContactNumber,EmailId,DateofJoining,Role,Address1,Address2,
Place,City,State,Pin,DepartmentName,User_Comments,Created_date');
$this->db->from('T_EmpDetails');
//$this->db->where('isDeleted', 0);
//$this->db->where('roleId !=', 1);
$this->db->where('EmpID', $EmpID);
$query = $this->db->get();
return $query->result();
}
function editemployee($Emp, $EmpID)
{
echo $EmpID;
$this->db->where('EmpID', $EmpID);
$this->db->update('T_EmpDetails', $Emp);
return TRUE;
}
function viewemployee($Emp, $EmpID)
{
echo $EmpID;
$this->db->where('EmpID', $EmpID);
$this->db->update('T_EmpDetails', $Emp);
return TRUE;
}
/* This function to get the Employee department on respective Employee */
function GetEmployeeDepartment($EmployeeID)
{
$this->db->select('DepartmentName');
$this->db->from('T_EmployeeDetails');
$this->db->where('EmpID', $EmployeeID);
$query = $this->db->get();
return $query->result_array();
}
}
?>