ria/application/models/employeedetails_model.php
2018-04-11 12:44:50 +05:30

271 lines
8.3 KiB
PHP

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
class employeedetails_model extends CI_Model
{
/**
* To get the employee listing
* @return array $result : result of the query(returns as employee details)
*/
function employeeListing()
{
$this->db->select(' Emp.*,Dep.DepartmentName as DepartmentName');
$this->db->from('T_Employee_Details Emp');
$this->db->join('T_DepartmentDetails Dep', 'Emp.Departmentcode = Dep.DEPCode','left');
$this->db->order_by("Emp.EmpID", "asc");
$query = $this->db->get();
$result = $query->result();
return $result;
}
/**
* To get the role data for employee
* @return array $query->result() : result of the query (returns as roles information)
*/
function getUserRoles()
{
$this->db->select('roleId, role');
$this->db->from('tbl_roles');
$this->db->where('roleId !=', 1);
$query = $this->db->get();
return $query->result();
}
/**
* To get the Config value from configuration table
* @return array $query->result() : result of the query (returns as config information)
*/
function getConfigValue($ConfigID )
{
$this->db->select('ConfigValue');
$this->db->from('T_ConfigDetails');
$this->db->where('Config_id ',$ConfigID );
$query = $this->db->get();
return $query->result();
}
/**
* To get the Department details from T_DepartmentDetails
* @return array $query->result() : result of the query
*/
function getDepartment()
{
$this->db->select('DEPCode, DepartmentName');
$this->db->from('T_DepartmentDetails');
$this->db->where('IsActive =', 1);
$query = $this->db->get();
return $query->result();
}
/**
* To store employee details
* @param array $Employee : This will have all the employee datas
* @return number $EmpID : This will return how many value are inserted (return as count in number)
*/
function addNewemployee($Employee)
{
$this->db->insert('T_Employee_Details', $Employee);
$EmpID = $this->db->affected_rows();
return $EmpID;
}
/**
* To store the edited employee details
* @param array $Emp : This will have all the edited employee datas
* @param number $EmpID : This is employee id
*/
function UpdateEmployee($Emp, $EmpID)
{
$this->db->where('EmpID', $EmpID);
$this->db->update('T_Employee_Details', $Emp);
return TRUE;
}
/**
* To get employee details
* @param number $EmpID : This is employee id
* @return array $result : result of the query(returns employee information with department name)
*/
function viewemployee( $EmpID)
{
$this->db->select('Emp.*,Dep.DepartmentName as DepartmentName');
$this->db->from('T_Employee_Details AS Emp');
$this->db->join('T_DepartmentDetails Dep', 'Emp.Departmentcode = Dep.DEPCode','left');
$this->db->where('Emp.EmpID', $EmpID);
$query = $this->db->get();
$result = $query->result();
return $result;
}
/**
* To get the Employee department on respective Employee
* @param number $EmployeeID : this is employee Id
* @return array $query->result_array() : result of the query (return department name)
**/
function GetEmployeeDepartment($EmployeeID)
{
$this->db->select('DepartmentName');
$this->db->from('T_EmployeeDetails');
$this->db->where($EmployeeID);
$query = $this->db->get();
return $query->result_array();
}
/**
* To check respective Employee emailid already exists or not
* @param number $empid : Optional :this is employee Id
* @param number $email : Optional :this is employee's emailid
* @return array $query->result_array() : result of the query (returns employee email id)
**/
function checkMailExists($email='',$Empid='')
{
$this->db->select('EmailId');
$this->db->from('T_Employee_Details');
$this->db->where('EmailId',$email);
if ($Empid != '')
{
$this->db->where('EmpID !=',$Empid);
}
$query = $this->db->get();
if ($query->num_rows > 0) {
return $query->result_array();
}
}
/**
* To get respective Employee aadhar no
* @param number $Empid : Optional : this is employee Id
* @param number $AadharNo : this is employee's aadhar no
* @return array $query->result_array() : result of the query (returns employee aadhar no)
**/
function checkAadharExists($AadharNo,$Empid='')
{
$this->db->select('AadharNo');
$this->db->from('T_Employee_Details');
$this->db->where('AadharNo',$AadharNo);
if ($Empid != '')
{
$this->db->where('EmpID !=',$Empid);
}
$query = $this->db->get();
if ($query->num_rows > 0) {
return $query->result_array();
}
}
/**
* To get respective Employee's panno
* @param number $Empid : Optional : this is employee Id
* @param number $PANNo : this is employee's pan no
* @return array $query->result_array() : result of the query (returns employee pan no)
**/
function checkPANExists($PANNo,$Empid='')
{
$this->db->select('PANNo');
$this->db->from('T_Employee_Details');
$this->db->where('PANNo',$PANNo);
if ($Empid != '')
{
$this->db->where('EmpID !=',$Empid);
}
$query = $this->db->get();
if ($query->num_rows > 0) {
return $query->result_array();
}
}
/**
* To get respective Employee's profile pic name
* @param number $pic : this is employee profile pic (pic name)
* @return array $query->result_array() : result of the query (returns profilepic name)
**/
function checkPhotoExists($Pic)
{
$this->db->select('ProfilePic');
$this->db->from('T_Employee_Details');
$this->db->where($Pic);
$query = $this->db->get();
if ($query->num_rows > 0) {
return $query->result_array();
}
}
/**
* To get employee's count
* @return array $query->result_array() : result of the query (returns employees count)
**/
function getEmployeeCount( )
{
$this->db->select('count(*) as EmpCount');
$this->db->from('T_Employee_Details');
$this->db->where('IsActive ',1 );
$query = $this->db->get();
return $query->result();
}
/**
* To get bank details
* @return array $result : result of the query (returns bank details)
**/
function getBankDetails()
{
$this->db->select('*');
$this->db->from('T_Bank_Details');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function removefiles($value,$Empid){
$str = explode("/",$value);
if($str[0] == 'pan'){ $this->db->set('PANFile', null); }
else if( $str[0] == 'aadhar'){ $this->db->set('AadharFile', null); }
else if( $str[0] == 'voter'){ $this->db->set('VoterFile', null); }
unlink("uploads/images/".$str[1]);
$this->db->where('EmpID =',$Empid);
$this->db->update('T_Employee_Details');
$aff = $this->db->affected_rows();
return $aff;
// $this->db->set('PANNo', null);
// $this->db->where('EmpID =',$Empid);
// $this->db->update('T_Employee_Details');
// $aff = $this->db->affected_rows();
// return $aff;
}
/**
* To get Asset's information for export xl
*/
function export_excel(){
$this->db->select(' det.*,Dep.DepartmentName as DepartmentName,det.firstname,emp1.firstname as UpdatedByName,emp1.firstname as CreatedByName');
$this->db->join('T_DepartmentDetails Dep', 'det.Departmentcode = Dep.DEPCode','left');
$this->db->join('tbl_users as tbl',' det.createdby = tbl.userid','left');
$this->db->join('T_Employee_Details as emp', 'emp.empid=tbl.empid','left');
$this->db->join('tbl_users as tbl1',' det.UpdatedBy = tbl1.userid','left');
$this->db->join('T_Employee_Details as emp1', 'emp1.empid=tbl1.empid','left');
return $this->db->get('T_Employee_Details as det')->result_array();
}
}
?>