diff --git a/Apollo/api/application/config/routes.php b/Apollo/api/application/config/routes.php index cc0f415c..bb3b650f 100755 --- a/Apollo/api/application/config/routes.php +++ b/Apollo/api/application/config/routes.php @@ -80,7 +80,7 @@ $route['updateEmpBranchDetail'] = 'Employee_Controller/updateEmpBranchDetail'; $route['updateEmpImgExistDetail'] = 'Employee_Controller/updateEmployeeImage'; $route['insertEmployeeImage'] = 'Employee_Controller/addEmployeeImage'; $route['employeeGetProf'] = 'Employee_Controller/employeeGetProf'; - +$route['addEmpBranchDetail'] = 'Employee_Controller/addEmpBranchDetail'; // call tracking $route['getTrackingLeadDetails'] = 'Call_Tracking_Controller/getTrackingLeadDetails'; $route['addLeadTrackingDetails'] = 'Call_Tracking_Controller/addLeadTrackingDetails'; diff --git a/Apollo/api/application/controllers/Employee_Controller.php b/Apollo/api/application/controllers/Employee_Controller.php index cc59b078..cc6b0ffb 100755 --- a/Apollo/api/application/controllers/Employee_Controller.php +++ b/Apollo/api/application/controllers/Employee_Controller.php @@ -437,19 +437,53 @@ class Employee_Controller extends REST_Controller { } } + public function addEmpBranchDetail_post() { + $req['StaffID'] = $this->post('empFor'); + $req['BranchCode'] = $this->post('updateBranch'); + $req['ListCode'] = $this->post('updateRole'); + $req['JobResponsibility'] = $this->post('JobResponsibility'); + + $req['FinanceModuleAccess'] = $this->post('FinanceModuleAccess') == 1 ? '1' : '0'; + $req['CreatedBy'] = $this->post('updateBy'); + $date = date('Y-m-d H:i:s'); + $req['IsActive'] = '1'; + $req['UpdatedOn'] = $date; + + $addEmpBranch = $this->employee_model->add_employee_branch( $req );// Check if the employee exist + if ($addEmpBranch) + { + $addEmpBranch['status'] = REST_Controller::HTTP_OK; + // Set the response and exit + $this->response($addEmpBranch, REST_Controller::HTTP_OK); // OK (200) being the HTTP response code + } + else + { + // Set the response and exit + $this->response([ + 'message' => 'No users were found', + 'status' => REST_Controller::HTTP_NOT_FOUND + ], REST_Controller::HTTP_NOT_FOUND); // NOT_FOUND (404) being the HTTP response code + } + } + // update employee branch public function updateEmpBranchDetail_post() { // exit(); - $empFor = $this->post('empFor'); - $reqBanch['BranchCode'] = $this->post('updateBranch'); + $req['StaffID'] = $this->post('empFor'); + $req['BranchCode'] = $this->post('updateBranch'); $req['ListCode'] = $this->post('updateRole'); - $reqJOBRES['JobResponsibility'] = $this->post('JobResponsibility'); - $FinanceModuleAccess = $this->post('FinanceModuleAccess') == 1 ? 1 : 0; + $req['JobResponsibility'] = $this->post('JobResponsibility'); + $req['HomeBranch'] = $this->post('HomeBranch'); + + $req['FinanceModuleAccess'] = $this->post('FinanceModuleAccess') == 1 ? '1' : '0'; + // echo $req['FinanceModuleAccess'];exit(); $req['UpdatedBy'] = $this->post('updateBy'); $date = date('Y-m-d H:i:s'); $req['UpdatedOn'] = $date; + + $updateFor = $this->post('ID'); - $updateBranch = $this->employee_model->upate_employee_branch( $empFor, $reqBanch, $req, $req['UpdatedBy'], $req['UpdatedOn'], $reqJOBRES, $FinanceModuleAccess);// Check if the employee exist + $updateBranch = $this->employee_model->upate_employee_branch( $updateFor, $req );// Check if the employee exist if ($updateBranch) { $updateBranch['status'] = REST_Controller::HTTP_OK; diff --git a/Apollo/api/application/models/Employee_model.php b/Apollo/api/application/models/Employee_model.php index 9ec0e013..73b4bb1e 100755 --- a/Apollo/api/application/models/Employee_model.php +++ b/Apollo/api/application/models/Employee_model.php @@ -61,7 +61,7 @@ class Employee_model extends CI_Model } else { // get branch details for admin & staff $result['details'] = $responseDetails; - $this->db->select('t3.BranchCode, t3.BranchName'); + $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); @@ -123,11 +123,13 @@ class Employee_model extends CI_Model } else { // get branch details for admin & staff $result['details'] = $responseDetails; - $this->db->select('t3.BranchCode, t3.BranchName'); + $this->db->select('t3.BranchCode, t3.BranchName, t2.ListCode , t4.ListName, t2.FinanceModuleAccess'); $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(); @@ -183,12 +185,17 @@ class Employee_model extends CI_Model } } 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); + $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(); if (count($checkArr) > 0) { @@ -204,13 +211,17 @@ class Employee_model extends CI_Model } else if ($loginUserType == ADMIN) { // list for admin $staffId = $this->selfGetEmpId($loginUserId); - $this->db->select('*'); - $this->db->from(STAFF); - $this->db->order_by('CreatedOn', 'DESC'); + $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('StaffID', $staffId); - $this->db->where('BranchCode', $loginUserBranchId); - $this->db->where('ListCode', EMPLOYEE); + $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(); if (count($checkArr) > 0) { @@ -344,11 +355,16 @@ class Employee_model extends CI_Model $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['MobileNumber']; + $loginArr['MobileNumber'] = $empArr['StaffID']; $loginArr['EmailId'] = $empArr['EmailID']; $loginArr['IsActive'] = $empArr['IsActive']; $loginArr['CreatedBy'] = $createdBy; @@ -380,11 +396,16 @@ class Employee_model extends CI_Model $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['MobileNumber']; + $loginArr['MobileNumber'] = $empArr['StaffID']; $loginArr['EmailId'] = $empArr['EmailID']; $loginArr['IsActive'] = $empArr['IsActive']; $loginArr['CreatedBy'] = $createdBy; @@ -454,17 +475,17 @@ class Employee_model extends CI_Model 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(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('MobileNumber', $updateFor); $this->db->where_not_in('StaffID', $updateFor); if($this->db->get()->first_row()) { $result['updateEmpStatus'] = false; @@ -478,7 +499,7 @@ class Employee_model extends CI_Model $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'"; + $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"; @@ -490,23 +511,19 @@ class Employee_model extends CI_Model $result['updateEmpStatus'] = false; $result['message'] = "Something went wrong.please try again"; } - - - } } + // } + } + else { // update employee with image - - - } 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(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']); @@ -537,7 +554,7 @@ class Employee_model extends CI_Model $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'"; + $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"; @@ -550,7 +567,7 @@ class Employee_model extends CI_Model $result['message'] = "Something went wrong.please try again"; } } - } + // } } return $result; } @@ -558,33 +575,33 @@ class Employee_model extends CI_Model // 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.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->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(); if( count($branchArr) > 0 ) { $result['empBranchDetails'] = true; - $result['role_details'] = $roleDetails->result(); - $result['branch_details'] = $branchDetails->result(); + $result['branch_details'] = $branchArr; } else { - $result['empBranchDetails'] = true; - $result['role_details'] = $roleDetails->result(); - $result['branch_details'] = $branchDetails->result(); + $result['empBranchDetails'] = false; + $result['message'] = "No Employee Branch Details"; } - } else { - $result['empBranchDetails'] = false; - } + // } else { + // $result['empBranchDetails'] = false; + // } + // print_r($result);exit(); return $result; } @@ -596,98 +613,178 @@ class Employee_model extends CI_Model return $roleDetails->BranchCode; } - // update employee branch details - public function upate_employee_branch($empFor, $reqBanch, $req, $createby, $createon, $reqJOBRES, $FinanceModuleAccess) - { - // 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]); - $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; + 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 { - $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 + $req['HomeBranch'] = 0; + $this->db->insert(STAFF_BRANCH, $req); 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"; + $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); + // 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(); + 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.please try again"; + $result['message'] = "Something Went Wrong."; } } else { $result['updateEmpbranchStatus'] = false; - $result['message'] = "Something went wrong.please try again"; + $result['message'] = "Something Went Wrong."; } } else { - $result['updateEmpbranchStatus'] = false; - $result['message'] = "Something went wrong.please try again"; + $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."; + } } - } else { - $result['updateEmpbranchStatus'] = false; - $result['message'] = "Something went wrong.please try again"; } 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; + // } } diff --git a/Apollo/api/application/models/Login_model.php b/Apollo/api/application/models/Login_model.php index 79ecab7e..9a11cd5f 100755 --- a/Apollo/api/application/models/Login_model.php +++ b/Apollo/api/application/models/Login_model.php @@ -29,6 +29,7 @@ class Login_model extends CI_Model $this->db->where('t1.IsActive', 1); //$this->db->where('t2.IsActive', 1); $loginDetails = $this->db->get(LOGIN)->first_row(); + // print_r($loginDetails);exit(); if ($loginDetails) { if ($mobile == $loginDetails->MobileNumber) { diff --git a/Apollo/assets/js/controllers/employeeCtrl.js b/Apollo/assets/js/controllers/employeeCtrl.js index 2bbc6929..81ee37f9 100755 --- a/Apollo/assets/js/controllers/employeeCtrl.js +++ b/Apollo/assets/js/controllers/employeeCtrl.js @@ -68,6 +68,8 @@ app.controller('staffCtrl', ["$scope", "toaster", "$filter", "ngTableParams", "$ $scope.init = function () { if (localDetail != null) { $scope.currentDate = new Date(); + $scope.localUserListCode = localDetail.localType; + // $scope.currentPage = 1; $scope.getEmployeeList(); $scope.getRoleList(); @@ -173,8 +175,21 @@ app.controller('staffCtrl', ["$scope", "toaster", "$filter", "ngTableParams", "$ $scope.empBranchDetails = ''; $scope.empRoleDetail = ''; + $scope.branchListView = false; + $scope.empEditBranchView = false; + $scope.empAddNewBranchView = false; + $scope.getEmpBranchDetails = function (id) { // alert(id); + $scope.empEditBranchDetails = { + 'ID': '', + 'StaffID': '', + 'ListCode': '', + 'BranchCode': '', + 'JobResponsibility': '', + 'IsActive': '' + } + var req = { method: 'POST', url: apiPoint.url + 'getEmpBranchDetails/', @@ -189,24 +204,226 @@ app.controller('staffCtrl', ["$scope", "toaster", "$filter", "ngTableParams", "$ if (response.data.empBranchDetails) { // $scope.editBranchId = id; $scope.branchEditLoading = false; + $scope.branchListView = true; + $scope.empEditBranchView = false; + $scope.empAddNewBranchView = false; $scope.empBranchs = response.data.branch_details; - $scope.branchArr = []; - $scope.BranchName = ''; - angular.forEach($scope.empBranchs, function (item, index) { - // alert(item.BranchName); - $scope.BranchName = item.BranchName + '-' + item.BranchCode; - $scope.branchArr.push($scope.BranchName); - }); - $scope.empBranchDetails = { - arr: $scope.branchArr, - } - response.data.role_details[0].FinanceModuleAccess = response.data.role_details[0].FinanceModuleAccess == 1 ? true : false; - $scope.empRoleDetail = response.data.role_details[0]; + // $scope.branchArr = []; + // $scope.BranchName = ''; + // angular.forEach($scope.empBranchs, function (item, index) { + // // alert(item.BranchName); + // $scope.BranchName = item.BranchName + '-' + item.BranchCode; + // $scope.branchArr.push($scope.BranchName); + // }); + // $scope.empBranchDetails = { + // arr: $scope.branchArr, + // } + // response.data.role_details[0].FinanceModuleAccess = response.data.role_details[0].FinanceModuleAccess == 1 ? true : false; + // $scope.empRoleDetail = response.data.role_details[0]; } else { + $scope.NoBranchDetailsFound = response.data.message ; } }); } + $scope.empEditBranchDetails = { + 'ID': '', + 'StaffID': '', + 'ListCode': '', + 'BranchCode': '', + 'JobResponsibility': '', + 'IsActive': '', + 'FinanceModuleAccess': '', + 'HomeBranch': '' + } + + $scope.getEmpEditBranchDetails = function(p) { + $scope.branchListView = false; + $scope.empEditBranchView = true; + $scope.empAddNewBranchView = false; + + $scope.empEditBranchDetails.ID = p.ID; + $scope.empEditBranchDetails.StaffID = p.StaffID; + $scope.empEditBranchDetails.ListCode = p.ListCode; + $scope.empEditBranchDetails.BranchCode = p.BranchCode; + $scope.empEditBranchDetails.JobResponsibility = p.JobResponsibility; + $scope.empEditBranchDetails.FinanceModuleAccess = p.FinanceModuleAccess == 1 ? true : false; + $scope.empEditBranchDetails.HomeBranch = p.HomeBranch; + } + + $scope.getEmpEditBranchDetailsCancel = function() { + $scope.branchListView = true; + $scope.empEditBranchView = false; + $scope.empAddNewBranchView = false; + + $scope.empEditBranchDetails = { + 'ID': '', + 'StaffID': '', + 'ListCode': '', + 'BranchCode': '', + 'JobResponsibility': '', + 'IsActive': '', + 'FinanceModuleAccess': '', + 'HomeBranch': '' + } + } + + + $scope.updateEmpBranchDetails = function (form) { + + if (form.$invalid) { + var field = null, firstError = null; + for (field in form) { + if (field[0] != '$') { + if (firstError === null && !form[field].$valid) { + firstError = form[field].$name; + } + if (form[field].$pristine) { + form[field].$dirty = true; + } + } + } + angular.element('.ng-invalid[name=' + firstError + ']').focus(); + // swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error"); + } else { + + // angular.forEach(empBranchs.arr, function (item) { + // var newString = item.split("-").pop(); + // $scope.arr1.push(newString); + // }); + // alert(JSON.stringify($scope.arr1)); + $scope.sendBranchData = { + 'ID': $scope.empEditBranchDetails.ID, + 'empFor': $scope.empEditBranchDetails.StaffID , + 'updateRole': $scope.empEditBranchDetails.ListCode, + 'JobResponsibility': $scope.empEditBranchDetails.JobResponsibility, + 'updateBranch': $scope.empEditBranchDetails.BranchCode, + 'updateBy': localDetails.localUserID, + 'FinanceModuleAccess': $scope.empEditBranchDetails.FinanceModuleAccess == true ? 1 : 0, + 'HomeBranch': $scope.empEditBranchDetails.HomeBranch + } + // p.IsActive = p.IsActive === true ? 1 : 0; + var req = { + method: 'POST', + url: apiPoint.url + 'updateEmpBranchDetail/', + headers: { + 'Content-Type': 'application/json' + }, + data: $scope.sendBranchData + }; + $http(req).then(function (response) { + if (response.data.updateEmpbranchStatus == true) { + swal("", "Updated Successfully.", "success"); + $scope.getEmployeeList(); + $scope.getEmpBranchDetails($scope.empEditBranchDetails.StaffID); + $scope.branchListView = true; + $scope.empEditBranchView = false; + $scope.empAddNewBranchView = false; + $scope.empEditBranchDetails = { + 'ID': '', + 'StaffID': '', + 'ListCode': '', + 'BranchCode': '', + 'JobResponsibility': '', + 'IsActive': '', + 'FinanceModuleAccess': '', + 'HomeBranch': '' + }; + } else { + // $scope.ldloading1[loading.replace('-', '_')] = false; + swal("", response.data.message, "error"); + } + }); + } + } + + $scope.addNewBranch = function () { + $scope.branchListView = false; + $scope.empEditBranchView = false; + $scope.empAddNewBranchView = true; + } + + $scope.addNewBranchcancel = function() { + $scope.branchListView = true; + $scope.empEditBranchView = false; + $scope.empAddNewBranchView = false; + $scope.empAddBranchDetails = { + 'StaffID': '', + 'ListCode': '', + 'BranchCode': '', + 'JobResponsibility': '', + 'IsActive': '', + 'FinanceModuleAccess': '' + } + } + + $scope.empAddBranchDetails = { + 'StaffID': '', + 'ListCode': '', + 'BranchCode': '', + 'JobResponsibility': '', + 'IsActive': '', + 'FinanceModuleAccess': '' + } + + $scope.addEmpBranchDetails = function(emp, form) { + if (form.$invalid) { + var field = null, firstError = null; + for (field in form) { + if (field[0] != '$') { + if (firstError === null && !form[field].$valid) { + firstError = form[field].$name; + } + if (form[field].$pristine) { + form[field].$dirty = true; + } + } + } + angular.element('.ng-invalid[name=' + firstError + ']').focus(); + // swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error"); + } else { + + $scope.addEmpNewBranch = { + 'empFor': emp, + 'updateRole': $scope.empAddBranchDetails.ListCode, + 'JobResponsibility': $scope.empAddBranchDetails.JobResponsibility, + 'updateBranch': $scope.empAddBranchDetails.BranchCode, + 'updateBy': localDetails.localUserID, + 'FinanceModuleAccess': $scope.empAddBranchDetails.FinanceModuleAccess == true ? 1 : 0, + } + + var req = { + method: 'POST', + url: apiPoint.url + 'addEmpBranchDetail/', + headers: { + 'Content-Type': 'application/json' + }, + data: $scope.addEmpNewBranch + }; + $http(req).then(function (response) { + if (response.data.addEmpbranchStatus == true) { + swal("", "Added Successfully.", "success"); + $scope.getEmployeeList(); + $scope.getEmpBranchDetails(emp); + $scope.branchListView = true; + $scope.empEditBranchView = false; + $scope.empAddNewBranchView = false; + $scope.empAddBranchDetails = { + 'empFor': emp, + 'updateRole': $scope.empAddBranchDetails.ListCode, + 'JobResponsibility': $scope.empAddBranchDetails.JobResponsibility, + 'updateBranch': $scope.empAddBranchDetails.BranchCode, + 'updateBy': localDetails.localUserID, + 'FinanceModuleAccess': $scope.empAddBranchDetails.FinanceModuleAccess + } + } else { + // $scope.ldloading1[loading.replace('-', '_')] = false; + swal("", response.data.message, "error"); + } + }); + } + } + $scope.getRoleList = function () { var req = { method: 'POST', @@ -243,13 +460,14 @@ app.controller('staffCtrl', ["$scope", "toaster", "$filter", "ngTableParams", "$ if (response.data.MeasterBranchDetailStatus == true) { $scope.branchDetails = response.data.branch_details; - $scope.branchDetailsName = []; - $scope.BranchName = ''; - angular.forEach($scope.branchDetails, function (item, index) { - // alert(item.BranchName); - $scope.BranchName = item.BranchName + '-' + item.BranchCode; - $scope.branchDetailsName.push($scope.BranchName); - }); + // alert(JSON.stringify($scope.branchDetails)); + // $scope.branchDetailsName = []; + // $scope.BranchName = ''; + // angular.forEach($scope.branchDetails, function (item, index) { + // // alert(item.BranchName); + // $scope.BranchName = item.BranchName + '-' + item.BranchCode; + // $scope.branchDetailsName.push($scope.BranchName); + // }); } else { } @@ -603,69 +821,6 @@ app.controller('staffCtrl', ["$scope", "toaster", "$filter", "ngTableParams", "$ } } - $scope.updateEmpBranchDetails = function (form, empRole, empBranchs, p) { - // alert(empBranchs.arr.length); - // alert(JSON.stringify(empRole)); - if (empBranchs.arr.length >= 1) { - var firstError = null; - if (form.$invalid) { - var field = null, firstError = null; - for (field in form) { - if (field[0] != '$') { - if (firstError === null && !form[field].$valid) { - firstError = form[field].$name; - } - if (form[field].$pristine) { - form[field].$dirty = true; - } - } - } - angular.element('.ng-invalid[name=' + firstError + ']').focus(); - // swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error"); - } else { - // alert(JSON.stringify(p)); - // alert(JSON.stringify(empRole)); - - $scope.arr1 = []; - - angular.forEach(empBranchs.arr, function (item) { - var newString = item.split("-").pop(); - $scope.arr1.push(newString); - }); - // alert(JSON.stringify($scope.arr1)); - $scope.sendBranchData = { - 'empFor': p.StaffID, - 'updateRole': empRole.ListCode, - 'JobResponsibility': empRole.JobResponsibility, - 'updateBranch': $scope.arr1, - 'updateBy': localDetails.localUserID, - 'FinanceModuleAccess': empRole.FinanceModuleAccess - } - // p.IsActive = p.IsActive === true ? 1 : 0; - var req = { - method: 'POST', - url: apiPoint.url + 'updateEmpBranchDetail/', - headers: { - 'Content-Type': 'application/json' - }, - data: $scope.sendBranchData - }; - $http(req).then(function (response) { - if (response.data.updateEmpbranchStatus = true) { - swal("", "Updated Successfully.", "success"); - $scope.getEmployeeList(); - $scope.editBranchId = -1; - } else { - // $scope.ldloading1[loading.replace('-', '_')] = false; - swal("", response.data.message, "error"); - } - }); - } - } else { - swal("Warning!", "should select atleast branch!!", "warning"); - } - } - }]); // file upload directive diff --git a/Apollo/assets/js/controllers/sessionCtrl.js b/Apollo/assets/js/controllers/sessionCtrl.js index e32c475f..95e3ea95 100755 --- a/Apollo/assets/js/controllers/sessionCtrl.js +++ b/Apollo/assets/js/controllers/sessionCtrl.js @@ -188,10 +188,14 @@ app.controller('topnavCtrl', ["$scope", "$http", "API_POINTS", "$localStorage", }; - $scope.upDateLocalBran = function (Id) { + $scope.upDateLocalBran = function (Id, listCode, financeAccess) { localDetail.localBranchID = Id; localDetails.localBranchID = Id; + localDetail.localType = listCode; + localDetails.localType = listCode; + localDetail.is_DayBookApproval_Access = financeAccess; + localDetails.is_DayBookApproval_Access = financeAccess; ipCookie('cookiechk', localDetails, { expires: 21 }); localStorage.setItem('localObj', JSON.stringify(localDetail)); $window.location.reload(); diff --git a/Apollo/assets/views/editEmployeeBranchDetails.html b/Apollo/assets/views/editEmployeeBranchDetails.html index d1771aa3..b0031499 100755 --- a/Apollo/assets/views/editEmployeeBranchDetails.html +++ b/Apollo/assets/views/editEmployeeBranchDetails.html @@ -1,410 +1,208 @@ -
- \ No newline at end of file + + \ No newline at end of file diff --git a/Apollo/assets/views/editEmployeeDetails.html b/Apollo/assets/views/editEmployeeDetails.html index 0c86d804..3d269575 100755 --- a/Apollo/assets/views/editEmployeeDetails.html +++ b/Apollo/assets/views/editEmployeeDetails.html @@ -236,7 +236,7 @@ class="symbol required"> Mobile Number is required. Enter a Valid Phone Number diff --git a/Apollo/assets/views/employeeDetails.html b/Apollo/assets/views/employeeDetails.html index 86f14aeb..5cb4b910 100755 --- a/Apollo/assets/views/employeeDetails.html +++ b/Apollo/assets/views/employeeDetails.html @@ -172,9 +172,10 @@ + ng-minlength="4" ng-maxlength="12" ng-pattern="/^[a-zA-Z0-9.\s]*$/" ng-blur='checkEmpIdExist()' required/> + Employee Id is required - Invalid Employee Id + Employee ID length Should be (4-12) @@ -261,7 +262,7 @@ class="symbol required"> Mobile Number is required. Enter a Valid Phone Number diff --git a/Apollo/assets/views/login_login.html b/Apollo/assets/views/login_login.html index bb18cc1d..dbcefb19 100755 --- a/Apollo/assets/views/login_login.html +++ b/Apollo/assets/views/login_login.html @@ -28,12 +28,12 @@