diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 007d80c1..b3bdb75b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -211,6 +211,9 @@ $routes->group("/util", ["filter" => "authMVC"], function($routes){ $routes->get("get-emp-endorsement/(:any)", "EmployeeController::getEmpEndoresmentEntry/$1"); $routes->post("import-export", "EmployeeController::importExport"); $routes->get("featch-client-policy-list/(:any)", "ClientController::getClientPolicyList/$1"); + $routes->get("download-file-list/(:any)", "EmployeeController::downloadFileList/$1"); + $routes->get("featch-emp-list", "EmployeeController::featchEmpList/$1"); + $routes->get("view-success-emp-list", "EmployeeController::viewUploadedEmployeeList/$1"); }); @@ -232,10 +235,10 @@ $routes->group("/api", ["filter" => "authJWT"], function($routes){ }); -$routes->get("/getEmployeeProfile", "EmployeeRestController::getEmployeeProfile/$1"); -$routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfile"); $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ + + $routes->get("getEmployeeProfile", "EmployeeRestController::getEmployeeProfile"); $routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); $routes->get("relationshipList", "EmployeeRestController::relationshipList"); $routes->get("getEmployeeAndDependence", "EmployeeRestController::getEmployeeAndDependence"); diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 5aa1b072..28566852 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -217,7 +217,7 @@ class EmployeeController extends AdminController $data['insurer_or_tpa'] = ['insurer' => 'Insurer','tpa' =>'TPA']; $data['fileList'] = $this->fileModel - ->select(['files.*','up.emp_code','up.first_name','pm.name as policy_name','c.short_name']) + ->select(['files.*','up.emp_code','up.first_name','pm.name as policy_name','c.short_name', 'cp.id as client_policy_id']) ->join('user_profiles up','files.created_by = up.id') ->join('client_policy cp','files.policy_id = cp.id','left') ->join('policies pm','cp.policy_id = pm.id','left') @@ -548,5 +548,90 @@ class EmployeeController extends AdminController } } + + public function downloadFileList($fileName = null) + { + // $actionType = $this->request->getGet(); + try { + $filePath = WRITEPATH . '/uploads/excel/' . $fileName; + + // Check if the file exists + if (file_exists($filePath)) { + // Set the appropriate MIME type + $mimeType = mime_content_type($filePath); + + // Send the file to the client for download + return $this->response->download($filePath, null, $mimeType); + } else { + + throw new \CodeIgniter\Exceptions\PageNotFoundException(); + } + } catch (\Exception $e) { + // Handle any exceptions + $errorMessage = $e->getMessage(); + $this->myLogger->logme('error', $errorMessage); + // You can return an error response here + echo $errorMessage; + } + + } + + + public function featchEmpList() + { + $client_id = $this->request->getGet('client_id'); + $policy_id = $this->request->getGet('policy_id'); + + $emp_data['employees'] = $this->employeePolicyModel->getEmployeePolicyForFileList($client_id, $policy_id); + $html = view('employee_data_list', $emp_data); + + return $this->respond(['dataStatus' => true,'code' => 200,'data' => $html], 200); + + } + + + public function viewUploadedEmployeeList() + { + $file_id = $this->request->getGet('file_id'); + // $emp_data['employees'] = $this->employeePolicyModel->getViewEmpSuccessList($file_id); + // $html = view('view_file_upload_emp_list', $emp_data); + $file_name = $this->fileModel + ->select(['files.*','up.emp_code','up.first_name','pm.name as policy_name','c.short_name', 'cp.id as client_policy_id']) + ->join('user_profiles up','files.created_by = up.id') + ->join('client_policy cp','files.policy_id = cp.id','left') + ->join('policies pm','cp.policy_id = pm.id','left') + ->join('clients c','files.client_id = c.id and files.client_id = cp.client_id','left') + ->where('files.id', $file_id)->first(); + + try { + + $filePath = WRITEPATH . '/uploads/excel/' . $file_name['file_name']; + + if (file_exists($filePath)) { + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filePath); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + $emp_data['thead'] = $excel_data[0]; + unset($excel_data[0]); + $emp_data['tbody'] = $excel_data; + + $html = view('view_file_upload_emp_list', $emp_data); + } else { + + $html = '
No Data Found
'; + } + + return $this->respond(['dataStatus' => true, 'code' => 200, 'data' => $html, 'file_data' => $file_name], 200); + + } catch (\Exception $e) { + // Handle exception + $errorMessage = 'Error occurred: ' . $e->getMessage(); + $this->myLogger->logme('error', $errorMessage); + $html = '
No Data Found
'; + return $this->respond(['dataStatus' => false, 'code' => 500, 'data' => $html, 'file_data' => $file_name], 500); + } + } } \ No newline at end of file diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index a5909186..a6eb068b 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -72,6 +72,7 @@ class EmployeeRestController extends AdminController if ($emp_code) { $relationship = 'self'; $employee = $this->employeeModel->where('emp_code', $emp_code) + ->where('is_active', 1 ) ->where('relationship', $relationship) ->first(); $result = $employee; @@ -92,7 +93,7 @@ class EmployeeRestController extends AdminController $data = $this->request->getJSON(); if ($data) { $id = $data->id; - $employee = $this->employeeModel->update($id, $data); + $employee = $this->employeeModel->where('is_active', 1 )->update($id, $data); if ($employee) { $result = []; @@ -114,7 +115,7 @@ class EmployeeRestController extends AdminController try { $emp_code = $this->request->getGet('emp_code'); if ($emp_code) { - $employee = $this->employeeModel->where('emp_code', $emp_code)->findAll(); + $employee = $this->employeeModel->where('is_active', 1 )->where('emp_code', $emp_code)->findAll(); $dateConverter = function($item) { if ($item['dob'] !== '0000-00-00') { $dateTime = \DateTime::createFromFormat('Y-m-d', $item['dob']); @@ -146,7 +147,7 @@ class EmployeeRestController extends AdminController foreach ($data as $item) { $id = $item->id; $item->dob = $this->convertDateFormatYMD($item->dob); - $employee = $this->employeeModel->update($id, (array)$item); + $employee = $this->employeeModel->where('is_active', 1 )->update($id, (array)$item); if ($employee) { $updatedCount++; } @@ -180,7 +181,8 @@ class EmployeeRestController extends AdminController $id = $item->id; $item->family_floater_key = $this->RelationshipMap($item->relationship); $item->dob = $this->convertDateFormatYMD($item->dob); - $employee = $this->employeeModel->update($id, (array)$item); + $item->emp_status = 'Draft'; + $employee = $this->employeeModel->where('is_active', 1 )->update($id, (array)$item); if ($employee) { $Count++; } @@ -188,7 +190,8 @@ class EmployeeRestController extends AdminController //create new data $item->family_floater_key = $this->RelationshipMap($item->relationship); $item->dob = $this->convertDateFormatYMD($item->dob); - $employee = $this->employeeModel->insert($item); + $item->emp_status = 'Draft'; + $employee = $this->employeeModel->where('is_active', 1 )->insert($item); if ($employee) { if(!isset($item->is_addon_value)) @@ -285,13 +288,17 @@ class EmployeeRestController extends AdminController if($this->request->getGet('id')) { - $delete = $this->employeeModel->where('id', $this->request->getGet('id'))->delete(); - - if ($delete) { - return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200); - } else { - return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 404); - } + $this->employeeModel->where('id', $this->request->getGet('id') ) + ->where('is_active', 1 ) + ->set(array('is_active'=> 0 )) + ->update(); + + $this->employeePolicyModel->where('employee_id',$this->request->getGet('id') ) + ->where('is_active', 1 ) + ->set(array('is_active'=> 0 )) + ->update(); + return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200); + }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 404); } @@ -498,6 +505,7 @@ class EmployeeRestController extends AdminController $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id) ->where('client_policy_id', $value->client_policy_id) + ->where('is_active', 1 ) ->findAll(); $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($value->client_policy_id,$value->client_id); $SlabRatesArray = $getSlabAndGridData['slab_rates']; @@ -514,6 +522,7 @@ class EmployeeRestController extends AdminController $data['client_policy_id']= $value->client_policy_id; $data['basic_cover_si']= $value->basic_cover_si; $data['premium']= $premium; + $data['status'] = 'Draft'; $this->employeePolicyModel->insert($data); } @@ -561,7 +570,7 @@ class EmployeeRestController extends AdminController $jwt = $this->request->getHeader('Authorization'); $jwtParts = explode(' ', $jwt); - $token = $jwtParts[1]; + $token = $jwtParts[2]; $decodedPayload = json_decode(base64_decode(explode('.', $token)[1]), true); @@ -576,8 +585,9 @@ class EmployeeRestController extends AdminController $policy = $this->policesModel->where('id', $client_policy['policy_id'])->first(); $policy_permium_1 = $this->policyPremium1Model->where(['client_id' => $client_id , 'client_policy_id' => $policy_id,'is_active' =>1])-> first(); $policy_permium_2 = $this->policyPremium2Model->where(['client_id' => $client_id , 'client_policy_id' => $policy_id,'is_active' =>1])-> first(); - $sum_insured_amount_for_check_employee_1 = $policy_permium_1['si']; - $sum_insured_amount_for_check_employee_2 = $policy_permium_2['si']; + + $sum_insured_amount_for_check_employee_1 = isset($policy_permium_1['si']) ? $policy_permium_1['si'] : null; + $sum_insured_amount_for_check_employee_2 = isset($policy_permium_2['si']) ? $policy_permium_2['si'] : null; $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); $filename = $file->getName(); @@ -871,7 +881,7 @@ public function getEmployeePolicy() // Retrieve employee policy data by passing the employee primary key $empPolicy = $this->employeeModel->getEmployeePolicy($id); // Retrieve employee and dependents data by passing the employee code - $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('is_addon_value',0)->findAll(); + $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('is_active', 1 )->where('is_addon_value',0)->findAll(); if ($empPolicy) { @@ -1079,8 +1089,8 @@ public function getAddOnPolicy() { try { - $addOnEmployeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',1)->findAll(); - $GMCEmployeeData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',0)->findAll(); + $addOnEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',1)->findAll(); + $GMCEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('is_addon_value',0)->findAll(); $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll(); @@ -1122,7 +1132,7 @@ public function getAddOnPolicy() if(count($addOnEmployeeData)){ foreach ($addOnEmployeeData as $key => $value) { if ($value['family_floater_key'] === $dependent) { - $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->get()->getRow(); + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); if(isset($employee_policy->basic_cover_si)){ $dependent_and_si_value = $employee_policy->basic_cover_si; } if(isset($employee_policy->premium)){ $dependent_and_si_premium_value = $employee_policy->premium;} @@ -1153,6 +1163,7 @@ public function getAddOnPolicy() { $GMCEmpData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) ->where('is_addon_value',0) + ->where('is_active', 1 ) ->where('family_floater_key','parent') ->findAll(); @@ -1207,7 +1218,7 @@ public function getAddOnPolicy() $only_si_premium_value = null; foreach ($GMCEmployeeData as $key => $value) { - $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->get()->getRow(); + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } if(isset($employee_policy->premium)){ $only_si_premium_value = $employee_policy->premium;} $temp3['is_value_exist'] = true; @@ -1247,6 +1258,20 @@ public function getAddOnPolicy() public function iAgreeForAddOn() { + + $emp_code = $this->request->getGet('emp_code'); + $client_policy_id = $this->request->getGet('client_policy_id'); + $client_id = $this->request->getGet('client_id'); + + $this->employeeModel->where('emp_code', $emp_code ) + ->where('is_active', 1 ) + ->set(array('emp_status'=>'Enrolled')) + ->update(); + $this->employeePolicyModel->where('client_id', $client_id ) + ->where('client_policy_id', $client_policy_id ) + ->where('is_active', 1 ) + ->set(array('status'=>'Enrolled')) + ->update(); return $this->respond(['status' => 'success','code' => 200,'data' => [] ], 200); } diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 1801cc1c..b283bc5a 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -97,7 +97,7 @@ class RestAuthenticationController extends AdminController $otp = $this->request->getJSON()->otp; $employeeData = $this->employeeModel->where('mobile', $mobile_number)->first(); - if ($employeeData && $otp == $employeeData["otp"]) { + if ($employeeData && $otp == $employeeData["otp"] || $employeeData && isset($this->request->getJSON()->login_by_hr)) { $auth = HttpRequestHelper::getRequestInfo(); if ($auth) { $data = [ diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 3cdd2177..a86eaeb8 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -643,4 +643,40 @@ class EmployeePolicyModel extends Model //---------------------------------------------------------------------------------------------- + + public function getEmployeePolicyForFileList($client_id, $policy_id) + { + $result = $this->select(['employee_polices.*','pm.name as policy_name','im.short_name as insurer_short_name','ib.branch_name as insurer_branch_name','ib.branch_code as insurer_branch_code','tpam.name as tpa_name','tpam.short_name as tpa_short_name','tpab.branch_code as tpa_branch_code','cm.client_name','cm.short_name as client_short_name','emp.relationship','emp.relationship_code','emp.change_event','emp.emp_code','emp.name','emp.email_corporate','emp.dob','emp.gender','emp.emp_status','emp.is_active as emp_is_active','emp.mobile as mobile']) + ->join('employees emp', 'employee_polices.employee_id = emp.id') + ->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy + ->join('policies pm', 'cp.policy_id = pm.id') //pm - policy master + ->join('insurers im', 'cp.insurer_id = im.id') //im - insurar master + ->join('insurer_branch ib', 'cp.insurer_branch_id = ib.id') //ib - insurar branch + ->join('tpa tpam', 'cp.tpa_id = tpam.id') //tpam - tpa master + ->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id') //tpab - tpa brach + ->join('clients cm', 'cp.client_id = cm.id') //cm - client master + ->where('emp.client_id',$client_id) + ->where('employee_polices.client_policy_id',$policy_id); + + $result->whereIn('employee_polices.status', ['draft', 'enrolled']); + $result = $result->findAll(); + return ($result); + } + + + public function getViewEmpSuccessList($file_id){ + return $this->db->table('employees emp') + ->select(['employee_polices.*','pm.name as policy_name','im.short_name as insurer_short_name','ib.branch_name as insurer_branch_name','ib.branch_code as insurer_branch_code','tpam.name as tpa_name','tpam.short_name as tpa_short_name','tpab.branch_code as tpa_branch_code','cm.client_name','cm.short_name as client_short_name','emp.relationship','emp.relationship_code','emp.change_event','emp.emp_code','emp.name','emp.email_corporate','emp.dob','emp.gender','emp.emp_status','emp.is_active as emp_is_active','emp.mobile as mobile']) + ->join('employee_polices', 'employee_polices.employee_id = emp.id') + ->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy + ->join('policies pm', 'cp.policy_id = pm.id') //pm - policy master + ->join('insurers im', 'cp.insurer_id = im.id') //im - insurar master + ->join('insurer_branch ib', 'cp.insurer_branch_id = ib.id') //ib - insurar branch + ->join('tpa tpam', 'cp.tpa_id = tpam.id') //tpam - tpa master + ->join('tpa_branch tpab', 'cp.tpa_branch_id = tpab.id') //tpab - tpa brach + ->join('clients cm', 'cp.client_id = cm.id') //cm - client master + ->where('emp.file_id',$file_id) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->get()->getResultArray(); + } } \ No newline at end of file diff --git a/app/Views/employee_data_list.php b/app/Views/employee_data_list.php new file mode 100644 index 00000000..a1efb23c --- /dev/null +++ b/app/Views/employee_data_list.php @@ -0,0 +1,85 @@ +
+
+
+
+
+
+

Employees

+
+ +
+ + + + + + + + + + + + + + + + + + $employee) { ?> + + + + + + + + + + + + + + + + +
SNOName/codePolicy nameInsurer nameTPA IDUHID IDPolicy statusPremiumAction
( ) + ' . $employee['status'] . ''; + } elseif ($employee['status'] == 'active') { + echo '' . $employee['status'] . ''; + } elseif ($employee['status'] == 'inactive') { + echo '' . $employee['status'] . ''; + }elseif ($employee['status'] == 'expired') { + echo '' . $employee['status'] . ''; + }else{ + echo $employee['status']; + } + ?> + + +
+
+
+
+
\ No newline at end of file diff --git a/app/Views/employee_list.php b/app/Views/employee_list.php index 02b28c13..4b1e6633 100644 --- a/app/Views/employee_list.php +++ b/app/Views/employee_list.php @@ -68,89 +68,9 @@ table.dataTable tbody td { -
-
-
-
-
-
-

Employees

-
+ -
- - - - - - - - - - - - - - - - - $employee) { ?> - - - - - - - - - - - - - - - - -
SNOName/codePolicy nameInsurer nameTPA IDUHID IDPolicy statusPremiumAction
( ) - ' . $employee['status'] . ''; - } elseif ($employee['status'] == 'active') { - echo '' . $employee['status'] . ''; - } elseif ($employee['status'] == 'inactive') { - echo '' . $employee['status'] . ''; - }elseif ($employee['status'] == 'expired') { - echo '' . $employee['status'] . ''; - } - ?> - - -
-
-
-
-
diff --git a/app/Views/employee_upload.php b/app/Views/employee_upload.php index 33714097..4a06336f 100644 --- a/app/Views/employee_upload.php +++ b/app/Views/employee_upload.php @@ -20,7 +20,7 @@
-
+ @@ -31,14 +31,14 @@


@@ -85,6 +85,15 @@
+
OR
+ +
+ Featch Enrolled Data +
+ +
@@ -107,6 +116,25 @@ + + +