858 lines
41 KiB
PHP
Executable File
858 lines
41 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Date: 11/9/17
|
|
* Time: 5:28 PM
|
|
*/
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
class Employee_model extends CI_Model
|
|
{
|
|
|
|
/*
|
|
* get user login details
|
|
* params:email,password
|
|
* created by kdk
|
|
* */
|
|
|
|
/*
|
|
* get Employee Details, Employee Branch Details
|
|
*/
|
|
|
|
// get login employee profile details
|
|
public function get_emp_prof_detail($empLoginID = null) {
|
|
// echo "hai i am here don't worry be happy";
|
|
|
|
$this->db->select('StaffID');
|
|
$this->db->from(LOGIN);
|
|
$this->db->where('ID', $empLoginID);
|
|
$loginEmpDetail = $this->db->get()->first_row();
|
|
if (!empty($loginEmpDetail)) {
|
|
$EmpId = $loginEmpDetail->StaffID;
|
|
$this->db->select('t1.*');
|
|
$this->db->from('' . STAFF . ' as t1');
|
|
$this->db->where('t1.StaffID', $EmpId);
|
|
// $this->db->join('T_StaffDetails as t2', 't1.StaffID = t2.StaffID', 'LEFT');
|
|
$responseDetails = $this->db->get()->first_row();
|
|
$result['empStatus'] = true;
|
|
print_r($responseDetails);exit();
|
|
|
|
if (!empty($responseDetails) && $responseDetails->ListCode == SUPER_ADMIN) {
|
|
// print_r($result['details']->ListCode);exit();
|
|
// get branch details for super admin
|
|
$responseDetails->BranchCode = 'All';
|
|
$result['details'] = $responseDetails;
|
|
// print_r($result['details']);exit();
|
|
$this->db->select('t3.BranchCode, t3.BranchName');
|
|
$this->db->from('' . STAFF_BRANCH . ' as t2');
|
|
$this->db->where('t2.StaffID', $EmpId);
|
|
$this->db->where('t2.IsActive', 1);
|
|
$this->db->join('' . BRANCH . ' as t3', 't2.BranchCode = t3.BranchCode', 'LEFT');
|
|
$this->db->where('t3.IsActive', 1);
|
|
// $this->db->join('T_StaffDetails as t2', 't1.StaffID = t2.StaffID', 'LEFT');
|
|
$branchDetails = $this->db->get();
|
|
$getArrs = $branchDetails->result();
|
|
$SS['BranchCode'] = 'All';
|
|
$SS['BranchName'] = 'All';
|
|
|
|
array_push($getArrs, $SS);
|
|
// print_r($getArrs);exit();
|
|
$result['branchStatus'] = true;
|
|
$result['branch_details'] = $getArrs;
|
|
$result['work_State'] = 'Super Admin';
|
|
|
|
} else {
|
|
// get branch details for admin & staff
|
|
$result['details'] = $responseDetails;
|
|
$this->db->select('t3.BranchCode, t3.BranchName, ');
|
|
$this->db->from('' . STAFF_BRANCH . ' as t2');
|
|
$this->db->where('t2.StaffID', $EmpId);
|
|
$this->db->where('t2.IsActive', 1);
|
|
$this->db->join('' . BRANCH . ' as t3', 't2.BranchCode = t3.BranchCode', 'LEFT');
|
|
$this->db->where('t3.IsActive', 1);
|
|
// $this->db->join('T_StaffDetails as t2', 't1.StaffID = t2.StaffID', 'LEFT');
|
|
$branchDetails = $this->db->get();
|
|
$result['branchStatus'] = true;
|
|
$result['work_State'] = !empty($responseDetails) && $responseDetails->ListCode == ADMIN ? 'Admin' : 'Staff';
|
|
$result['branch_details'] = $branchDetails->result();
|
|
}
|
|
} else {
|
|
$result['empStatus'] = false;
|
|
$result['message'] = "Something Went Wrong, Please try Again !!";
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
// get single employee details
|
|
public function get_emp_detail($empLoginID = null)
|
|
{
|
|
$this->db->select('StaffID,ListCode');
|
|
$this->db->from(LOGIN);
|
|
$this->db->where('ID', $empLoginID);
|
|
$loginEmpDetail = $this->db->get()->first_row();
|
|
if ($loginEmpDetail) {
|
|
$EmpId = $loginEmpDetail->StaffID;
|
|
if($loginEmpDetail->ListCode != STUDENT){
|
|
$this->db->select('t1.*');
|
|
$this->db->from('' . STAFF . ' as t1');
|
|
$this->db->where('t1.StaffID', $EmpId);
|
|
// $this->db->join('T_StaffDetails as t2', 't1.StaffID = t2.StaffID', 'LEFT');
|
|
$responseDetails = $this->db->get()->first_row();
|
|
$result['empStatus'] = true;
|
|
// print_r($result['details']);exit();
|
|
|
|
if ($responseDetails->ListCode == SUPER_ADMIN) {
|
|
// print_r($result['details']->ListCode);exit();
|
|
// get branch details for super admin
|
|
$responseDetails->BranchCode = 'All';
|
|
$result['details'] = $responseDetails;
|
|
// print_r($result['details']);exit();
|
|
$this->db->select('t1.BranchCode, t1.BranchName, t2.ListCode, t3.ListName');
|
|
// $this->db->from('' . STAFF_BRANCH . ' as t2');
|
|
// $this->db->where('t2.StaffID', $EmpId);
|
|
// $this->db->where('t2.IsActive', 1);
|
|
$this->db->from('' . BRANCH . ' as t1');
|
|
// $this->db->where('t3.IsActive', 1);
|
|
$this->db->join(''.LOGIN.' as t2', 't2.ID = t1.CreatedBy', 'LEFT');
|
|
$this->db->join('' . PICK_LIST_DETAILS . ' as t3', 't3.ListCode = t2.ListCode', 'LEFT');
|
|
$branchDetails = $this->db->get();
|
|
$getArrs = $branchDetails->result();
|
|
$SS['ListCode'] = $responseDetails->ListCode;
|
|
$SS['ListName'] = '';
|
|
// array_push($getArrs, $SS);
|
|
// print_r($getArrs);exit();
|
|
$result['branchStatus'] = true;
|
|
$result['branch_details'] = $getArrs;
|
|
|
|
} else {
|
|
// get branch details for admin & staff
|
|
$result['details'] = $responseDetails;
|
|
$this->db->select('t3.BranchCode, t3.BranchName, t2.ListCode , t4.ListName, t2.FinanceModuleAccess,t2.CallModuleAccess');
|
|
$this->db->from('' . STAFF_BRANCH . ' as t2');
|
|
$this->db->where('t2.StaffID', $EmpId);
|
|
$this->db->where('t2.IsActive', 1);
|
|
$this->db->order_by('t2.CreatedOn', 'ACS');
|
|
$this->db->join('' . BRANCH . ' as t3', 't2.BranchCode = t3.BranchCode', 'LEFT');
|
|
$this->db->join('' . PICK_LIST_DETAILS . ' as t4', 't4.ListCode = t2.ListCode', 'LEFT');
|
|
// $this->db->where('t3.IsActive', 1);STAFF_BRANCH
|
|
// $this->db->join('T_StaffDetails as t2', 't1.StaffID = t2.StaffID', 'LEFT');
|
|
$branchDetails = $this->db->get();
|
|
$result['branchStatus'] = true;
|
|
$result['branch_details'] = $branchDetails->result();
|
|
}
|
|
}
|
|
elseif ($loginEmpDetail->ListCode == STUDENT){
|
|
$this->db->select('ST.*');
|
|
$this->db->from('' . STUDENTS . ' as ST');
|
|
$this->db->where('ST.StudentID', $EmpId);
|
|
// $this->db->join('T_StaffDetails as t2', 't1.StaffID = t2.StaffID', 'LEFT');
|
|
$responseDetails = $this->db->get()->first_row();
|
|
$result['empStatus'] = true;
|
|
$result['details'] = $responseDetails;
|
|
$result['branch_details'] = "";
|
|
|
|
}
|
|
|
|
} else {
|
|
$result['empStatus'] = false;
|
|
$result['message'] = "Something Went Wrong, Please try Again !!";
|
|
}
|
|
return $result;
|
|
|
|
}
|
|
|
|
// get employee list based on login user
|
|
public function get_employee_list($loginUserId, $loginUserBranchId, $loginUserType)
|
|
{
|
|
// echo $loginUserId, $loginUserBranchId, $loginUserType; exit();
|
|
if ($loginUserType == SUPER_ADMIN) {
|
|
// list for super admin
|
|
// echo $loginUserBranchId;exit();
|
|
if ($loginUserBranchId == 'All') {
|
|
// for getting all branch details
|
|
$staffId = $this->selfGetEmpId($loginUserId);
|
|
$this->db->select('t1.*');
|
|
$this->db->order_by('t1.CreatedOn', 'DESC');
|
|
$this->db->from('' . STAFF . ' as t1');
|
|
// $this->db->join('' . STAFF_BRANCH . ' as t3', 't3.StaffID = t1.StaffID', 'LEFT');
|
|
// not for SuperAdmin and Student Role code
|
|
$this->db->where_not_in('t1.StaffID', $staffId);
|
|
// $this->db->group_by('t3.StaffID');
|
|
// $this->db->where('BranchCode', $loginUserBranchId);
|
|
$empDetails = $this->db->get();
|
|
$checkArr = $empDetails->result();
|
|
if (count($checkArr) > 0) {
|
|
$results['employeeList'] = true;
|
|
$results['employees_details'] = $empDetails->result();
|
|
} else {
|
|
$results['employeeList'] = false;
|
|
$results['message'] = 'No record found';
|
|
}
|
|
} else {
|
|
$staffId = $this->selfGetEmpId($loginUserId);
|
|
$this->db->select('t2.*');
|
|
$this->db->from('' . STAFF_BRANCH . ' as t1');
|
|
|
|
$this->db->join('' . STAFF . ' as t2', 't2.StaffID = t1.StaffID', 'LEFT');
|
|
|
|
// not for SuperAdmin and Student Role code
|
|
$this->db->where_not_in('t1.StaffID', $staffId);
|
|
$this->db->group_by('t1.StaffID');
|
|
$this->db->where('t1.BranchCode', $loginUserBranchId);
|
|
// $this->db->where('t1.ListCode', EMPLOYEE);
|
|
$this->db->order_by('t1.CreatedOn', 'DESC');
|
|
$empDetails = $this->db->get();
|
|
$checkArr = $empDetails->result();
|
|
// print_r($this->db->last_query());die();
|
|
if (count($checkArr) > 0) {
|
|
$results['employeeList'] = true;
|
|
$results['employees_details'] = $empDetails->result();
|
|
} else {
|
|
$results['employeeList'] = false;
|
|
$results['message'] = 'No record found';
|
|
}
|
|
|
|
}
|
|
|
|
} else if ($loginUserType == ADMIN) {
|
|
// list for admin
|
|
$staffId = $this->selfGetEmpId($loginUserId);
|
|
$this->db->distinct();
|
|
$this->db->select('t1.*,t2.*');
|
|
$this->db->from('' . STAFF_BRANCH . ' as t1');
|
|
|
|
$this->db->join('' . STAFF . ' as t2', 't2.StaffID = t1.StaffID', 'LEFT');
|
|
|
|
// not for SuperAdmin and Student Role code
|
|
$this->db->where_not_in('t1.StaffID', $staffId);
|
|
// $this->db->group_by('t1.StaffID');
|
|
$this->db->where('t1.BranchCode', $loginUserBranchId);
|
|
// $this->db->where('t2.ListCode', EMPLOYEE)->or_where("t1.ListCode",TRAINEE);
|
|
$this->db->order_by('t1.CreatedOn', 'DESC');
|
|
// print_r($this->db->last_query());die();
|
|
$empDetails = $this->db->get();
|
|
$checkArr = $empDetails->result();
|
|
if (count($checkArr) > 0) {
|
|
$results['employeeList'] = true;
|
|
$results['employees_details'] = $empDetails->result();
|
|
} else {
|
|
$results['employeeList'] = false;
|
|
}
|
|
} else {
|
|
$results['employeeList'] = false;
|
|
}
|
|
return $results;
|
|
}
|
|
|
|
// get role details based on login user
|
|
public function get_req_role_detail($reqRoleId)
|
|
{
|
|
// echo $reqRoleId;exit();
|
|
if ($reqRoleId == SUPER_ADMIN) {
|
|
// res for SuperAdmin
|
|
$this->db->select('ListCode, ListName');
|
|
$this->db->from(PICK_LIST_DETAILS);
|
|
// not for SuperAdmin and Student Role code
|
|
$this->db->where_not_in('ListCode', $reqRoleId);
|
|
$this->db->where_not_in('ListCode', 'R001');
|
|
// end : not for SuperAdmin and Student Role code
|
|
$this->db->where('ListGroup', 0);
|
|
$this->db->where('IsActive', 1);
|
|
$roleDetails = $this->db->get();
|
|
$result['RoleDetailStatus'] = true;
|
|
$result['role_details'] = $roleDetails->result();
|
|
} else {
|
|
// res for Admin
|
|
$this->db->select('ListCode, ListName');
|
|
$this->db->from(PICK_LIST_DETAILS);
|
|
// not for SuperAdmin and Admin and Student Role code
|
|
$this->db->where_not_in('ListCode', $reqRoleId);
|
|
$this->db->where_not_in('ListCode', 'R001');
|
|
$this->db->where_not_in('ListCode', 'R004');
|
|
// end : not for SuperAdmin and Admin and Student Role code
|
|
$this->db->where('ListGroup', 0);
|
|
$this->db->where('IsActive', 1);
|
|
$roleDetails = $this->db->get();
|
|
$result['RoleDetailStatus'] = true;
|
|
$result['role_details'] = $roleDetails->result();
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
// get branch details based on login user
|
|
public function get_req_master_branch_detail($reqRoleId, $reqUserID,$branchId)
|
|
{
|
|
|
|
//$listcode="R002";
|
|
if ($reqRoleId == SUPER_ADMIN ) {
|
|
// res for SuperAdmin
|
|
$this->db->select('BranchCode, BranchName');
|
|
$this->db->from(BRANCH);
|
|
$this->db->where('IsActive', 1);
|
|
$mBranchDetails = $this->db->get();
|
|
$results['MeasterBranchDetailStatus'] = true;
|
|
$results['branch_details'] = $mBranchDetails->result();
|
|
} //else {
|
|
/////// res for Admin//////////////
|
|
// $staffId = $this->selfGetEmpId($reqUserID);
|
|
//$reqRoleId =$this->
|
|
// $subQuery = "SELECT t1.BranchCode, t1.BranchName
|
|
// FROM T_BranchMaster as t1
|
|
// LEFT JOIN T_Staff_BranchAccess as t2 ON t2.StaffID = '$staffId'
|
|
// WHERE t1.BranchCode='$branchId' and t2.ListCode='$listcode'
|
|
|
|
// AND t1.IsActive = 1
|
|
// AND t2.IsActive = 1
|
|
// group by t1.BranchCode";
|
|
|
|
|
|
// $subQuery="SELECT t1.BranchCode, t1.BranchName
|
|
// FROM T_BranchMaster as t1
|
|
// LEFT JOIN T_Staff_BranchAccess as t2 ON t2.BranchCode = t1.BranchCode
|
|
// WHERE t2.StaffID='$staffId' and t2.ListCode='$listcode' AND t1.IsActive = 1 AND t2.IsActive = 1 group by t1.BranchCode";
|
|
|
|
|
|
// $mBranchDetails = $this->db->query($subQuery);
|
|
// $results['MeasterBranchDetailStatus'] = true;
|
|
// $results['branch_details'] = $mBranchDetails->result();
|
|
// }
|
|
if ($reqRoleId == ADMIN ) {
|
|
// res for SuperAdmin
|
|
$this->db->select('BranchCode, BranchName');
|
|
$this->db->from(BRANCH);
|
|
$this->db->where('IsActive', 1);
|
|
$mBranchDetails = $this->db->get();
|
|
$results['MeasterBranchDetailStatus'] = true;
|
|
$results['branch_details'] = $mBranchDetails->result();
|
|
}
|
|
return $results;
|
|
|
|
}
|
|
|
|
// check exist
|
|
public function check_exist($data, $checkData)
|
|
{
|
|
if ($checkData == 'employeeId') {
|
|
// check for employee id
|
|
$this->db->select('*');
|
|
$this->db->from(STAFF);
|
|
$this->db->where('StaffID', $data);
|
|
if ($this->db->get()->first_row()) {
|
|
$result['existEmpId'] = true;
|
|
$result['message'] = "This Employee ID is already exist!";
|
|
} else {
|
|
$result['existEmpId'] = false;
|
|
}
|
|
|
|
} else if ($checkData == 'mobileNumber') {
|
|
// check for mobile number
|
|
$this->db->select('*');
|
|
$this->db->from(LOGIN);
|
|
$this->db->where('MobileNumber', $data);
|
|
if ($this->db->get()->first_row()) {
|
|
$result['existMobile'] = true;
|
|
$result['message'] = "This Mobile Number is already exist!";
|
|
} else {
|
|
$result['existMobile'] = false;
|
|
}
|
|
|
|
} else if ($checkData == 'emailId') {
|
|
// check for email id
|
|
$this->db->select('*');
|
|
$this->db->from(STAFF);
|
|
$this->db->where('EmailID', $data);
|
|
if ($this->db->get()->first_row()) {
|
|
$result['existEmailId'] = true;
|
|
$result['message'] = "This EmailId is already exist!";
|
|
} else {
|
|
$result['existEmailId'] = false;
|
|
}
|
|
} else {
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
// add employee
|
|
public function add_employee($empArr, $createdBy, $imageName, $imageSource, $imageSize)
|
|
{
|
|
//print_r($empArr);exit();
|
|
|
|
$time = date('Y-m-d');
|
|
$dateTime = $time;
|
|
if( $imageSource == '') { // add employee without image
|
|
$imageNameDb = 'default.jpeg';
|
|
$empArr['ProfilePicPath'] = "employee/".$imageNameDb;
|
|
$this->db->insert(STAFF, $empArr);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$branchArr['StaffID'] = $empArr['StaffID'];
|
|
$branchArr['BranchCode'] = $empArr['BranchCode'];
|
|
$branchArr['IsActive'] = $empArr['IsActive'];
|
|
$branchArr['CreatedBy'] = $createdBy;
|
|
$branchArr['ListCode'] = $empArr['ListCode'];
|
|
$branchArr['JobResponsibility'] = $empArr['JobResponsibility'];
|
|
$branchArr['FinanceModuleAccess'] = $empArr['FinanceModuleAccess'];
|
|
$branchArr['CallModuleAccess'] = $empArr['CallModuleAccess'];
|
|
$branchArr['HomeBranch'] = 1;
|
|
$this->db->insert(STAFF_BRANCH, $branchArr);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$loginArr['StaffID'] = $empArr['StaffID'];
|
|
$loginArr['ListCode'] = $empArr['ListCode'];
|
|
// $loginArr['MobileNumber'] = $empArr['MobileNumber'];
|
|
$loginArr['MobileNumber'] = $empArr['StaffID'];
|
|
$loginArr['EmailId'] = $empArr['EmailID'];
|
|
$loginArr['IsActive'] = $empArr['IsActive'];
|
|
$loginArr['CreatedBy'] = $createdBy;
|
|
$loginArr['Password_Date']= $dateTime;
|
|
$loginArr['Password'] = ENCR_PASSWORD;
|
|
$this->db->insert(LOGIN, $loginArr);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$result['addEmpStatus'] = true;
|
|
$result['message'] = "Successfully employee details added";
|
|
} else {
|
|
$result['addEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
} else {
|
|
$result['addEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
} else {
|
|
$result['addEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
} else { // add employee with image
|
|
$target = "../images/employee/";
|
|
$getUploadStatus = $this->upload_image($imageSource, $imageSize, $target);
|
|
$imageNameDb = $getUploadStatus['status'] == true ? $getUploadStatus['imageName'] : $getUploadStatus['imageName'] = 'default.jpeg';
|
|
$empArr['ProfilePicPath'] = "employee/".$imageNameDb;
|
|
$this->db->insert(STAFF, $empArr);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$branchArr['StaffID'] = $empArr['StaffID'];
|
|
$branchArr['BranchCode'] = $empArr['BranchCode'];
|
|
$branchArr['IsActive'] = $empArr['IsActive'];
|
|
$branchArr['CreatedBy'] = $createdBy;
|
|
$branchArr['ListCode'] = $empArr['ListCode'];
|
|
$branchArr['JobResponsibility'] = $empArr['JobResponsibility'];
|
|
$branchArr['FinanceModuleAccess'] = $empArr['FinanceModuleAccess'];
|
|
$branchArr['HomeBranch'] = 1;
|
|
$this->db->insert(STAFF_BRANCH, $branchArr);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$loginArr['StaffID'] = $empArr['StaffID'];
|
|
$loginArr['ListCode'] = $empArr['ListCode'];
|
|
// $loginArr['MobileNumber'] = $empArr['MobileNumber'];
|
|
$loginArr['MobileNumber'] = $empArr['StaffID'];
|
|
$loginArr['EmailId'] = $empArr['EmailID'];
|
|
$loginArr['IsActive'] = $empArr['IsActive'];
|
|
$loginArr['CreatedBy'] = $createdBy;
|
|
$loginArr['Password'] = ENCR_PASSWORD;
|
|
$this->db->insert(LOGIN, $loginArr);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$result['addEmpStatus'] = true;
|
|
$result['message'] = "Successfully employee details added";
|
|
} else {
|
|
$result['addEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
} else {
|
|
$result['addEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
} else {
|
|
$result['addEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
// check existing data while update
|
|
public function check_update_exist($exceptId, $datas, $checkFor)
|
|
{
|
|
if ($checkFor == 'mobileNumber') {
|
|
// check update for mobile number
|
|
$this->db->select('*');
|
|
$this->db->from(LOGIN);
|
|
$this->db->where('MobileNumber', $datas);
|
|
$this->db->where_not_in('StaffID', $exceptId);
|
|
if ($this->db->get()->first_row()) {
|
|
$result['existMobile'] = true;
|
|
$this->db->select('MobileNumber');
|
|
$this->db->from(STAFF);
|
|
$this->db->where('StaffID', $exceptId);
|
|
$result['resetValue'] = $this->db->get()->first_row();
|
|
$result['message'] = "This Mobile Number is already exist!";
|
|
} else {
|
|
$result['existMobile'] = false;
|
|
}
|
|
|
|
} else if ($checkFor == 'emailId') {
|
|
// check update for email
|
|
$this->db->select('*');
|
|
$this->db->from(STAFF);
|
|
$this->db->where('EmailID', $datas);
|
|
$this->db->where_not_in('StaffID', $exceptId);
|
|
if ($this->db->get()->first_row()) {
|
|
$result['existEmailId'] = true;
|
|
$this->db->select('EmailID');
|
|
$this->db->from(STAFF);
|
|
$this->db->where('StaffID', $exceptId);
|
|
$result['resetValue'] = $this->db->get()->first_row();
|
|
$result['message'] = "This EmailId is already exist!";
|
|
} else {
|
|
$result['existEmailId'] = false;
|
|
}
|
|
} else {
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
// update employee personal details
|
|
public function update_employee($empArr, $updateFor, $imageName, $imageSource, $imageSize)
|
|
{
|
|
if( $imageSource == '') { // update Employee without image
|
|
// $this->db->select('*');
|
|
// $this->db->from(STAFF);
|
|
// $this->db->where('MobileNumber', $empArr['MobileNumber']);
|
|
// $this->db->where_not_in('StaffID', $updateFor);
|
|
// if ($this->db->get()->first_row()) {
|
|
// $result['updateEmpStatus'] = false;
|
|
// $result['message'] = "This Mobile Number Already Exist";
|
|
// }else {
|
|
$this->db->select('*');
|
|
$this->db->from(LOGIN);
|
|
$this->db->where('MobileNumber', $updateFor);
|
|
$this->db->where_not_in('StaffID', $updateFor);
|
|
if($this->db->get()->first_row()) {
|
|
$result['updateEmpStatus'] = false;
|
|
$result['message'] = "This Mobile Number Already Exist";
|
|
} else {
|
|
$this->db->where('StaffID', $updateFor);
|
|
$this->db->update(STAFF, $empArr);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$mobile = $empArr['MobileNumber'];
|
|
$email = $empArr['EmailID'];
|
|
$active = $empArr['IsActive'];
|
|
$updatedBy = $empArr['UpdatedBy'];
|
|
$updatedOn = $empArr['UpdatedOn'];
|
|
$sql = "UPDATE ".LOGIN." SET EmailId='$email', IsActive='$active', UpdatedBy='$updatedBy', UpdatedOn='$updatedOn' WHERE StaffID='$updateFor'";
|
|
if($this->db->query($sql) == '1'){
|
|
$result['updateEmpStatus'] = true;
|
|
$result['message'] = "Successfully employee details Updated";
|
|
} else {
|
|
$result['updateEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
} else {
|
|
$result['updateEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
}
|
|
// }
|
|
}
|
|
else { // update employee with image
|
|
|
|
// $this->db->select('*');
|
|
// $this->db->from(STAFF);
|
|
// $this->db->where('MobileNumber', $empArr['MobileNumber']);
|
|
// $this->db->where_not_in('StaffID', $updateFor);
|
|
// if ($this->db->get()->first_row()) {
|
|
// $result['updateEmpStatus'] = false;
|
|
// $result['message'] = "This Mobile Number Already Exist";
|
|
// }else {
|
|
$this->db->select('*');
|
|
$this->db->from(LOGIN);
|
|
$this->db->where('MobileNumber', $empArr['MobileNumber']);
|
|
$this->db->where_not_in('StaffID', $updateFor);
|
|
if($this->db->get()->first_row()) {
|
|
$result['updateEmpStatus'] = false;
|
|
$result['message'] = "This Mobile Number Already Exist";
|
|
} else {
|
|
$target = "../images/employee/";
|
|
$getUploadStatus = $this->upload_image($imageSource, $imageSize, $target);
|
|
$imageNameDb = $getUploadStatus['status'] == true ? $getUploadStatus['imageName'] : $getUploadStatus['imageName'] = 'default.jpeg';
|
|
$empArr['ProfilePicPath'] = "employee/".$imageNameDb;
|
|
$this->db->select('ProfilePicPath');
|
|
$this->db->from(STAFF);
|
|
$this->db->where('StaffID', $updateFor);
|
|
$roleDetails = $this->db->get()->first_row();
|
|
// echo $roleDetails->ProfilePicPath;
|
|
// exit();
|
|
if( $roleDetails->ProfilePicPath != '' && $roleDetails->ProfilePicPath != 'employee/default.jpeg'){
|
|
unlink('../images/'.$roleDetails->ProfilePicPath);
|
|
} else {
|
|
}
|
|
$this->db->where('StaffID', $updateFor);
|
|
$this->db->update(STAFF, $empArr);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$mobile = $empArr['MobileNumber'];
|
|
$email = $empArr['EmailID'];
|
|
$active = $empArr['IsActive'];
|
|
$updatedBy = $empArr['UpdatedBy'];
|
|
$updatedOn = $empArr['UpdatedOn'];
|
|
$sql = "UPDATE ".LOGIN." SET EmailId='$email', IsActive='$active', UpdatedBy='$updatedBy', UpdatedOn='$updatedOn' WHERE StaffID='$updateFor'";
|
|
if($this->db->query($sql) == '1'){
|
|
$result['updateEmpStatus'] = true;
|
|
$result['message'] = "Successfully employee details Updated";
|
|
} else {
|
|
$result['updateEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
} else {
|
|
$result['updateEmpStatus'] = false;
|
|
$result['message'] = "Something went wrong.please try again";
|
|
}
|
|
}
|
|
// }
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
// get employee branch details
|
|
public function get_employee_branch($staffId)
|
|
{
|
|
// $this->db->select('t3.ListCode, t3.ListName, t4.JobResponsibility, t4.FinanceModuleAccess');
|
|
// $this->db->from('' . PICK_LIST_DETAILS . ' as t3');
|
|
// $this->db->join('' . STAFF . ' as t4', 't4.ListCode = t3.ListCode', 'LEFT');
|
|
// $this->db->where('t4.StaffID', $staffId);
|
|
// $roleDetails = $this->db->get();
|
|
// $checkArr = $roleDetails->result();
|
|
// if (count($checkArr) > 0) {
|
|
$this->db->select('t1.*, t2.BranchName, t3.ListName');
|
|
$this->db->from('' . STAFF_BRANCH . ' as t1');
|
|
$this->db->join('' . BRANCH . ' as t2', 't2.BranchCode = t1.BranchCode', 'LEFT');
|
|
$this->db->join('' . PICK_LIST_DETAILS . ' as t3', 't3.ListCode = t1.ListCode', 'LEFT');
|
|
$this->db->where('t1.StaffID', $staffId);
|
|
// $this->db->where('t2.IsActive', 1);
|
|
// $this->db->where('t1.IsActive', 1);
|
|
$branchDetails = $this->db->get();
|
|
$branchArr = $branchDetails->result();
|
|
|
|
//print_r($this->db->last_query());die();
|
|
if( count($branchArr) > 0 ) {
|
|
$result['empBranchDetails'] = true;
|
|
$result['branch_details'] = $branchArr;
|
|
} else {
|
|
$result['empBranchDetails'] = false;
|
|
$result['message'] = "No Employee Branch Details";
|
|
}
|
|
// } else {
|
|
// $result['empBranchDetails'] = false;
|
|
// }
|
|
// print_r($result);exit();
|
|
return $result;
|
|
}
|
|
|
|
public function get_branch_code($name) {
|
|
$this->db->select('BranchCode');
|
|
$this->db->from(BRANCH);
|
|
$this->db->where('BranchName', $name);
|
|
$roleDetails = $this->db->get()->first_row();
|
|
return $roleDetails->BranchCode;
|
|
}
|
|
|
|
|
|
public function add_employee_branch($req) {
|
|
$staffID = $req['StaffID'];
|
|
$BranchCode = $req['BranchCode'];
|
|
$this->db->select('*');
|
|
$this->db->from(STAFF_BRANCH);
|
|
$this->db->where('StaffID', $staffID);
|
|
$this->db->where('BranchCode', $BranchCode);
|
|
$roleDetails = $this->db->get()->first_row();
|
|
if(count($roleDetails) > 0) {
|
|
$result['addEmpbranchStatus'] = false;
|
|
$result['message'] = "Already Employee Exist for this Branch.";
|
|
} else {
|
|
$req['HomeBranch'] = 0;
|
|
$this->db->insert(STAFF_BRANCH, $req);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$result['addEmpbranchStatus'] = true;
|
|
$result['message'] = "Successfully employee branch details Added";
|
|
|
|
} else {
|
|
$result['addEmpbranchStatus'] = false;
|
|
$result['message'] = "Something went wrong.";
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
|
|
// update employee branch details
|
|
public function upate_employee_branch($updateFor, $req)
|
|
{
|
|
// print_r($req);die();
|
|
// echo $updateFor;exit();
|
|
$staffID = $req['StaffID'];
|
|
$BranchCode = $req['BranchCode'];
|
|
$this->db->select('*');
|
|
$this->db->from(STAFF_BRANCH);
|
|
$this->db->where('ID', $updateFor);
|
|
$this->db->where_not_in('BranchCode', $BranchCode);
|
|
$roleDetails = $this->db->get()->first_row();
|
|
// print_r($roleDetails);exit();
|
|
|
|
//print_r($this->db->last_query());die();
|
|
if(count($roleDetails) > 0) {
|
|
$result['updateEmpbranchStatus'] = false;
|
|
$result['message'] = "Already Employee Exist for this Branch.";
|
|
} else {
|
|
if($req['HomeBranch'] == 1) {
|
|
$this->db->where('ID', $updateFor);
|
|
$this->db->update( STAFF_BRANCH , $req);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$listCode = $req['ListCode'];
|
|
$empFor = $req['StaffID'];
|
|
$branchCode = $req['BranchCode'];
|
|
$roleResponsibility = $req['JobResponsibility'];
|
|
$FinanceModuleAccess = $req['FinanceModuleAccess'];
|
|
$sql = "UPDATE ".LOGIN." SET ListCode ='$listCode' WHERE StaffID='$empFor'";
|
|
if ($this->db->query($sql) == '1') {
|
|
// $sql1 = "UPDATE ".STAFF." SET BranchCode='$branchCode', JobResponsibility='$roleResponsibility', FinanceModuleAccess= '$FinanceModuleAccess' WHERE StaffID='$empFor'";
|
|
// if ($this->db->query($sql1) == '1') {
|
|
$result['updateEmpbranchStatus'] = true;
|
|
$result['message'] = "Successfully employee branch details Updated";
|
|
// } else {
|
|
// $result['updateEmpbranchStatus'] = false;
|
|
// $result['message'] = "Something Went Wrong.";
|
|
// }
|
|
} else {
|
|
$result['updateEmpbranchStatus'] = false;
|
|
$result['message'] = "Something Went Wrong.";
|
|
}
|
|
} else {
|
|
$result['updateEmpbranchStatus'] = false;
|
|
$result['message'] = "Something Went Wrong.";
|
|
}
|
|
} else {
|
|
$this->db->where('ID', $updateFor);
|
|
$this->db->update( STAFF_BRANCH , $req);
|
|
if ($this->db->affected_rows() == '1') {
|
|
$result['updateEmpbranchStatus'] = true;
|
|
$result['message'] = "Successfully employee branch details Updated";
|
|
} else {
|
|
$result['updateEmpbranchStatus'] = false;
|
|
$result['message'] = "Something Went Wrong.";
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//print_r($result);die();
|
|
return $result;
|
|
// $this->db->where('StaffID', $empFor);
|
|
// $this->db->update($req['StaffID'] , $req);
|
|
// // update role to staff table
|
|
// if ($this->db->affected_rows() == '1') {
|
|
// $this->db->where('StaffID', $empFor);
|
|
// $this->db->update(LOGIN, $req);
|
|
// // echo $this->db->affected_rows();exit();
|
|
// // update role to login table
|
|
// if ($this->db->affected_rows() == '1') {
|
|
// // $branchCode = $this->get_branch_code($reqBanch['BranchCode'][0]);
|
|
// $branchCode = $reqBanch['BranchCode'][0];
|
|
// $roleResponsibility = $reqJOBRES['JobResponsibility'];
|
|
// $sql = "UPDATE ".STAFF." SET BranchCode='$branchCode', JobResponsibility='$roleResponsibility', FinanceModuleAccess=$FinanceModuleAccess WHERE StaffID='$empFor'";
|
|
// // update branch to staff table
|
|
// if ($this->db->query($sql) == '1') {
|
|
// $this->db->where('StaffID', $empFor);
|
|
// $this->db->delete(STAFF_BRANCH);
|
|
// foreach($reqBanch['BranchCode'] as $something) {
|
|
// // $branchCode = $this->get_branch_code($something);
|
|
// $branchCode = $something;
|
|
// $sql1 = "INSERT INTO ".STAFF_BRANCH." (StaffID, BranchCode, IsActive, CreatedBy, CreatedOn, UpdatedBy, UpdatedOn)
|
|
// VALUES ('$empFor', '$branchCode', '1','$createby', '$createon', '$createby', '$createon')";
|
|
// // update branch to staff_branch table
|
|
// if ($this->db->query($sql1) == '1') {
|
|
// $result['updateEmpbranchStatus'] = true;
|
|
// $result['message'] = "Successfully employee branch details Updated";
|
|
// } else {
|
|
// $result['updateEmpbranchStatus'] = false;
|
|
// $result['message'] = "Something went wrong.please try again";
|
|
// }
|
|
// }
|
|
// } else {
|
|
// $result['updateEmpbranchStatus'] = false;
|
|
// $result['message'] = "Something went wrong.please try again";
|
|
// }
|
|
// } else {
|
|
// $result['updateEmpbranchStatus'] = false;
|
|
// $result['message'] = "Something went wrong.please try again";
|
|
// }
|
|
// } else {
|
|
// $result['updateEmpbranchStatus'] = false;
|
|
// $result['message'] = "Something went wrong.please try again";
|
|
// }
|
|
// return $result;
|
|
|
|
// } else {
|
|
// $this->db->where('StaffID', $empFor);
|
|
// $this->db->update(STAFF, $req);
|
|
// // update role to staff table
|
|
// if ($this->db->affected_rows() == '1') {
|
|
// $this->db->where('StaffID', $empFor);
|
|
// $this->db->update(LOGIN, $req);
|
|
// // echo $this->db->affected_rows();exit();
|
|
// // update role to login table
|
|
// if ($this->db->affected_rows() == '1') {
|
|
// // $branchCode = $this->get_branch_code($reqBanch['BranchCode'][0]);
|
|
// $branchCode = $reqBanch['BranchCode'][0];
|
|
// $roleResponsibility = $reqJOBRES['JobResponsibility'];
|
|
// $sql = "UPDATE ".STAFF." SET BranchCode='$branchCode', JobResponsibility='$roleResponsibility', FinanceModuleAccess=$FinanceModuleAccess WHERE StaffID='$empFor'";
|
|
// // update branch to staff table
|
|
// if ($this->db->query($sql) == '1') {
|
|
// $this->db->where('StaffID', $empFor);
|
|
// $this->db->delete(STAFF_BRANCH);
|
|
// $sql1 = "INSERT INTO ".STAFF_BRANCH." (StaffID, BranchCode, IsActive, CreatedBy, CreatedOn)
|
|
// VALUES ('$empFor', '$branchCode', '1','$createby', '$createon')";
|
|
// // update branch to staff_branch table
|
|
// if ($this->db->query($sql1) == '1') {
|
|
// $result['updateEmpbranchStatus'] = true;
|
|
// $result['message'] = "Successfully employee branch details Updated";
|
|
// } else {
|
|
// $result['updateEmpbranchStatus'] = false;
|
|
// $result['message'] = "Something went wrong.please try again";
|
|
// }
|
|
// } else {
|
|
// $result['updateEmpbranchStatus'] = false;
|
|
// $result['message'] = "Something went wrong.please try again";
|
|
// }
|
|
// } else {
|
|
// $result['updateEmpbranchStatus'] = false;
|
|
// $result['message'] = "Something went wrong.please try again";
|
|
// }
|
|
// } else {
|
|
// $result['updateEmpbranchStatus'] = false;
|
|
// $result['message'] = "Something went wrong.please try again";
|
|
// }
|
|
// return $result;
|
|
// }
|
|
|
|
}
|
|
|
|
public function selfGetEmpId($sID)
|
|
{
|
|
$this->db->select('StaffID');
|
|
$this->db->from(LOGIN);
|
|
$this->db->where('ID', $sID);
|
|
$roleDetails = $this->db->get()->first_row();
|
|
return $roleDetails->StaffID;
|
|
}
|
|
|
|
// image upload in taget path
|
|
public function upload_image( $imageSource, $size, $target ) {
|
|
$key2 = substr(str_shuffle('abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 12);
|
|
$new_regNo = "Dri_" . $key2 . "." . 'jpeg';
|
|
$targetPlace = $target . $new_regNo;
|
|
// echo $targetPlace;exit();
|
|
if(!move_uploaded_file($imageSource , $targetPlace))
|
|
{
|
|
return $result['status'] = false;
|
|
} else {
|
|
$result['status'] = true;
|
|
$result['imageName'] = $new_regNo;
|
|
return $result;
|
|
}
|
|
}
|
|
} |