db->select('StaffID'); $this->db->from(LOGIN); $this->db->where('ID', $empLoginID); $loginEmpDetail = $this->db->get()->first_row(); if ($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($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('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; } 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['branch_details'] = $branchDetails->result(); } } 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 if ($loginUserBranchId == 'All') { // for getting all branch details $staffId = $this->selfGetEmpId($loginUserId); $this->db->select('*'); $this->db->order_by('CreatedOn', 'DESC'); $this->db->from(STAFF); // not for SuperAdmin and Student Role code $this->db->where_not_in('StaffID', $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('*'); $this->db->order_by('CreatedOn', 'DESC'); $this->db->from(STAFF); // not for SuperAdmin and Student Role code $this->db->where_not_in('StaffID', $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 if ($loginUserType == ADMIN) { // list for admin $staffId = $this->selfGetEmpId($loginUserId); $this->db->select('*'); $this->db->from(STAFF); $this->db->order_by('CreatedOn', 'DESC'); // not for SuperAdmin and Student Role code $this->db->where_not_in('StaffID', $staffId); $this->db->where('BranchCode', $loginUserBranchId); $this->db->where('ListCode', EMPLOYEE); $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) { 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); $subQuery = "SELECT t1.BranchCode, t1.BranchName FROM T_BranchMaster as t1 LEFT JOIN T_Staff_BranchAccess as t2 ON t2.StaffID = '$staffId' WHERE t2.BranchCode = t1.BranchCode AND t1.IsActive = 1 AND t2.IsActive = 1"; $mBranchDetails = $this->db->query($subQuery); $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(STAFF); $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) { $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; $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['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(STAFF); $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) { $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 MobileNumber='$mobile', EmailId='$email', IsActive='$active', UpdatedBy='$updatedBy', UpdatedOn='$updatedOn' WHERE StaffID='$updateFor'"; if($this->db->query($sql) == '1'){ $result['addEmpStatus'] = true; $result['message'] = "Successfully employee details Updated"; } else { $result['addEmpStatus'] = 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'); $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.BranchCode, t1.BranchName'); $this->db->from('' . BRANCH . ' as t1'); $this->db->join('' . STAFF_BRANCH . ' as t2', 't2.BranchCode = t1.BranchCode', 'LEFT'); $this->db->where('t2.StaffID', $staffId); $this->db->where('t2.IsActive', 1); $this->db->where('t1.IsActive', 1); $branchDetails = $this->db->get(); $branchArr = $branchDetails->result(); if( count($branchArr) > 0 ) { $result['empBranchDetails'] = true; $result['role_details'] = $roleDetails->result(); $result['branch_details'] = $branchDetails->result(); } else { $result['empBranchDetails'] = true; $result['role_details'] = $roleDetails->result(); $result['branch_details'] = $branchDetails->result(); } } else { $result['empBranchDetails'] = false; } 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; } // update employee branch details public function upate_employee_branch($empFor, $reqBanch, $req, $createby, $createon) { // print_r( count($reqBanch['BranchCode']));exit(); if( count($reqBanch['BranchCode']) > 1) { $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]); $sql = "UPDATE ".STAFF." SET BranchCode='$branchCode' 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); $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]); $sql = "UPDATE ".STAFF." SET BranchCode='$branchCode' 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; } }