diff --git a/.gitignore b/.gitignore index 3d6e6ab3..1f8cb67a 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,7 @@ writable/**/*.sqlite vendor/ +build/ composer.lock .env +.phpunit* diff --git a/app/Config/Routes.php b/app/Config/Routes.php index b14c375b..8bbe79e1 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -2,9 +2,14 @@ use CodeIgniter\Router\RouteCollection; + /** * @var RouteCollection $routes */ + + $routes->get('/swagger', 'SwaggerController::index', ['filter' => 'authMVC']); + + // $routes->get('/', 'LoginController::index'); $routes->get('/test', 'Home::index'); $routes->get('/login', 'LoginController::index');///auth/google @@ -214,7 +219,6 @@ $routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfi -$routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){ $routes->post("employeeUpload", "EmployeeRestController::employeeUpload"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index b83853fc..dc1688f5 100644 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -230,7 +230,8 @@ class ClientController extends AdminController { $this->myLogger->logme('error','Client general info function called'); - $file_name = file_Upload($this->request->getFile('client_logo')); + $uploadFilePath = ROOTPATH . 'public/uploads/logo/'; + $file_name = file_Upload($this->request->getFile('client_logo'), $uploadFilePath); $data = $this->request->getPost(); $data['created_by'] = get_session_userid(); $data['client_logo'] = $file_name; @@ -248,7 +249,8 @@ class ClientController extends AdminController public function editClientGeneralInfo() { $this->myLogger->logme('error','edit client general info function called'); - $file_name = file_Upload($this->request->getFile('client_logo')); + $uploadFilePath = ROOTPATH . 'public/uploads/logo/'; + $file_name = file_Upload($this->request->getFile('client_logo'), $uploadFilePath); $id = $this->request->getPost('PrimaryKey'); $data = $this->request->getPost(); $data['updated_by'] = get_session_userid(); @@ -268,7 +270,8 @@ class ClientController extends AdminController $this->myLogger->logme('error','create Client kyc function called'); $data = $this->request->getPost(); unset($data['file_name']); - $File = file_Upload($this->request->getFile('file_name')); + $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; + $File = file_Upload($this->request->getFile('file_name'), $uploadFilePath); if(!empty($File)){ $data['file_name'] = $File; } @@ -288,7 +291,8 @@ class ClientController extends AdminController { $this->myLogger->logme('error','edit client kyc function called'); - $File = file_Upload($this->request->getFile('file_name')); + $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; + $File = file_Upload($this->request->getFile('file_name'), $uploadFilePath); if(!empty($File)){ $data['file_name'] = $File; } @@ -452,7 +456,7 @@ class ClientController extends AdminController { $this->myLogger->logme('error','Client branch EDIT function called'); - $id = $this->request->getPost('PrimaryKey'); + $id = $this->request->getPost('branch_id_primarykey'); $client_id = $this->request->getPost('client_id'); $data = $this->request->getPost(); $data['updated_by'] = get_session_userid(); @@ -937,23 +941,85 @@ class ClientController extends AdminController public function policyGMCTerms() { - try { - + // print_r($this->request->getPost('family_floaters'));die; $this->myLogger->logme('error','Terms CREATE function called'); - /*** Client Policy Table Primary Key(ID) ***/ $client_policy_id = $this->request->getPost("client_policy_id"); $data['sum_insured'] =str_replace(',', '',$this->request->getPost("sum_insured")); $data['family_floater'] =$this->request->getPost("family_floater"); - $data['corporatebuffer'] = $this->request->getPost("corporatebuffer"); - $data['family_floaters'] = $this->request->getPost("family_floaters") ?? []; + $data['corporatebuffer'] = $this->request->getPost("corporatebuffer"); + $data['family_floaters'] = $this->request->getPost("family_floaters") ?? []; + + // if (!in_array("self", $data['family_floaters'])) { + // array_unshift($data['family_floaters'], "self"); + // } + $temp_family_floaters = $data['family_floaters']; + $data['family_floaters'] =[]; + if (in_array("self",$temp_family_floaters) == 1) { + $data['family_floaters']['self'] =1; + }else{ + $data['family_floaters']['self'] =0; + } + + if (in_array("spouse",$temp_family_floaters) == 1) { + $data['family_floaters']['spouse'] =1; + }else{ + $data['family_floaters']['spouse'] =0; + } + + // $data['family_floaters']['either-parents-pil'] =0; + + if (count($temp_family_floaters)) { + $children_value = 0; + $value = 0; + + if(count($temp_family_floaters) == 2){ + $children_value = 0; + $value = 1; + }else if(count($temp_family_floaters) == 3){ + $children_value = 1; + $value = 2; + }else{ + $children_value = 2; + $value = 3; + } + $data['family_floaters']['childrens'] =(int)$temp_family_floaters[$children_value]; + + if ($temp_family_floaters[$value] == '1P') { + $data['family_floaters']['parents'] =1; + $data['family_floaters']['parents-in-law'] =0; + $data['family_floaters']['either-parents-pil'] =0; + }else if($temp_family_floaters[$value] == '2P'){ + $data['family_floaters']['parents'] =2; + $data['family_floaters']['parents-in-law'] =0; + $data['family_floaters']['either-parents-pil'] =0; + }else if($temp_family_floaters[$value] == '1PIL'){ + $data['family_floaters']['parents'] =0; + $data['family_floaters']['parents-in-law'] =1; + $data['family_floaters']['either-parents-pil'] =0; + }else if($temp_family_floaters[$value] == '2PIL'){ + $data['family_floaters']['parents'] =0; + $data['family_floaters']['parents-in-law'] =2; + $data['family_floaters']['either-parents-pil'] =0; + }else if($temp_family_floaters[$value] == '2EPORPIL'){ + $data['family_floaters']['parents'] =1; + $data['family_floaters']['parents-in-law'] =1; + $data['family_floaters']['either-parents-pil'] =0; + }else if($temp_family_floaters[$value] == 'EPORPIL'){ + $data['family_floaters']['parents'] =0; + $data['family_floaters']['parents-in-law'] =0; + $data['family_floaters']['either-parents-pil'] =1; + }else if($temp_family_floaters[$value] == '4EPORPIL'){ + $data['family_floaters']['parents'] =2; + $data['family_floaters']['parents-in-law'] =2; + $data['family_floaters']['either-parents-pil'] =0; + } + } + - if (!in_array("self", $data['family_floaters'])) { - array_unshift($data['family_floaters'], "self"); - } $data['waiverofpreexistingdiseases'] =$this->request->getPost("waiverofpreexistingdiseases"); if ($data['waiverofpreexistingdiseases'] == 1) { $data['maternitycoverage'] =str_replace(',', '',$this->request->getPost("maternitycoverage")); @@ -1000,7 +1066,6 @@ class ClientController extends AdminController $data['special_condition_label'] = str_replace(',', '',$this->request->getPost("special_condition_label")) ?? []; $data['special_condition_input'] = str_replace(',', '',$this->request->getPost("special_condition_input")) ?? []; - $jsonData = json_encode($data); $dataa = array( 'policy_terms' => $jsonData, @@ -1008,6 +1073,7 @@ class ClientController extends AdminController $record = $this->clientPolicyModel->where('id', $client_policy_id)->first(); + // print_r($data);die; if ($record) { $update = $this->clientPolicyModel->update($client_policy_id, $dataa); if ($update) { diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index 09493bbf..aca39351 100644 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -7,6 +7,8 @@ use CodeIgniter\HTTP\RequestInterface; use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; +use App\Helpers\DepositHelper; + use App\Models\EmployeeModel; use App\Models\EmployeePolicyModel; @@ -52,27 +54,38 @@ class EmpDataServiceController extends BaseController } - public function batchFilesAndBatchListEntry($data, $objects){ + /** + * The below function are Inserts batch files and corresponding batch list entries into the database. + * + * @param array $data An array containing data for batch file insertion. + * @param array $objects An array of objects containing information for batch list entries. + * @return bool Returns true on successful insertion. + */ - $random_number_count = 4; - $data['batch_code'] = generate_random_string($random_number_count); - $data['created_by'] = get_session_userid(); - // $data['file_name'] = $filename; - $insert = $this->batchFileModel->insert($data); - $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); - if($insert){ - foreach($objects as $value){ - $batch_list_data['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_list_data['emp_policy_id'] = $value->primaryKey ?? $value->employee_policy_id ?? ''; - $batch_list_data['created_by'] = get_session_userid(); - $this->batchListModel->insert($batch_list_data); - } - } - return true; + public function batchFilesAndBatchListEntry($data, $objects) + { + + $random_number_count = 4; + $data['batch_code'] = generate_random_string($random_number_count); + $data['created_by'] = get_session_userid(); + + $insert = $this->batchFileModel->insert($data); + $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + + if($insert){ + foreach($objects as $value){ + $batch_list_data['batch_code'] = $batch_file_batch_code['batch_code']; + $batch_list_data['emp_policy_id'] = $value->primaryKey ?? $value->employee_policy_id ?? ''; + $batch_list_data['created_by'] = get_session_userid(); + $this->batchListModel->insert($batch_list_data); + } + } + + return true; + + } - } - /** * Generates an Excel file for Inception_Addititon_DependentAddititon, Correction, SI_Enhancement and Deletion events based on given export data. @@ -86,322 +99,908 @@ class EmpDataServiceController extends BaseController * @return bool True if the Excel file is successfully generated and exported, otherwise false. */ - public function generateExcelForAdditionandInception($export_data) - { - // Fetch employee data for export from the database - $objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data['client_policy_id'], $export_data['insurer_or_tpa'], $export_data['event_type'], $export_data['actions']); + public function generateExcelForAdditionandInception($export_data) + { + // Fetch employee data for export from the database + $objects = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($export_data); + + // Log the count of exported data + $count = count($objects); + $export_data['count'] = $count; + $this->myLogger->logme('error', 'Inception export data count : {data}', ['data'=> $count ]); + + // If no data is found for export, return false + if($count == 0){ + return false; + } + + // Log the export file name + $this->myLogger->logme('error', 'Inception export file name : {data}', ['data'=> $export_data['file_name'] ]); + + // Transform retrieved objects to an array suitable for export + $data = transform_objects_to_array_for_inception($objects); + + // Define headers for the Excel file + $headers = [ + 'S.No', 'NAME OF EMP/DEP', 'EMP ID', 'EMP/DEP TYPE', 'RELATION', 'DOB', 'GENDER', 'PRE EXISTING AILMENTS', + 'BASIC COVER SI', 'DATE OF COVERAGE', 'AGE', 'RELATIONSHIP', 'REMARKS', 'POLICY END DATE', 'NO OF DAYS', 'TPA ID', 'UHID', + 'PREMIUM', 'PR0 RATA PREMIUM', 'GST', 'TOTAL' + ]; + + // Generate Excel file + $tempFile = tmpfile(); + $success = generate_excel($headers, $data, $tempFile, 1); + + // If Excel generation is successful + if ($success) { + // Batch files and list entry + $return = $this->batchFilesAndBatchListEntry($export_data, $objects); + + // If batch operation is successful + if ($return) { + // Set headers for Excel file download + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); + header('Cache-Control: max-age=0'); + + // Output file contents + rewind($tempFile); + fpassthru($tempFile); + + // Close and remove temporary file + fclose($tempFile); + + return true; // Excel file successfully generated and exported + } else { + return false; // Batch operation failed + } + } + + return false; // Excel generation failed + } + - // Log the count of exported data - $count = count($objects); - $export_data['count'] = $count; - $this->myLogger->logme('error', 'Inception export data count : {data}', ['data'=> $count ]); + public function generateExcelForCorrection($export_data) + { - // If no data is found for export, return false - if($count == 0){ - return false; - } + $objects = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($export_data); + // dd($objects); + $count = count($objects); + $export_data['count'] = $count; + $this->myLogger->logme('error','Correction export data count : {data}', ['data'=> $count ]); - // Log the export file name - $this->myLogger->logme('error', 'Inception export file name : {data}', ['data'=> $export_data['file_name'] ]); + if($count == 0){ + return false; + } - // Transform retrieved objects to an array suitable for export - $data = transform_objects_to_array_for_inception($objects); + $this->myLogger->logme('error','Correction export file name : {data}', ['data'=> $export_data['file_name'] ]); - // Define headers for the Excel file - $headers = [ - 'S.No', 'NAME OF EMP/DEP', 'EMP ID', 'EMP/DEP TYPE', 'RELATION', 'DOB', 'GENDER', 'PRE EXISTING AILMENTS', - 'BASIC COVER SI', 'DATE OF COVERAGE', 'AGE', 'RELATIONSHIP', 'REMARKS', 'POLICY END DATE', 'NO OF DAYS', 'TPA ID', 'UHID', - 'PREMIUM', 'PR0 RATA PREMIUM', 'GST', 'TOTAL' - ]; + $correction_data = transform_objects_to_array_for_correction($objects); - // Generate Excel file - $tempFile = tmpfile(); - $success = generate_excel($headers, $data, $tempFile, 1); + $headers = [ + 'Emp Code', + 'RISK ID', + 'NAME OF EMP/DEP', + 'EMP/DEP TYPE', + 'RELATION', + 'DOB', + 'GENDER', + 'Wrong Data', + 'Correct Data', + 'Remarks', + 'Endorsement_Id' + ]; - // If Excel generation is successful - if ($success) { - // Batch files and list entry - $return = $this->batchFilesAndBatchListEntry($export_data, $objects); + // Create a temporary file in memory + $tempFile = tmpfile(); - // If batch operation is successful - if ($return) { - // Set headers for Excel file download - header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); - header('Cache-Control: max-age=0'); + // Generate Excel file with the temporary file + $value = generate_excel($headers, $correction_data, $tempFile); + + if($value){ + $return = $this->batchFilesAndBatchListEntry($export_data, $objects); + if($return){ + + // Set the appropriate headers for Excel file download + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); + header('Cache-Control: max-age=0'); + + // Rewind the temporary file pointer + rewind($tempFile); + + // Output the contents of the temporary file to the browser + fpassthru($tempFile); + + // Close and remove the temporary file + fclose($tempFile); - // Output file contents - rewind($tempFile); - fpassthru($tempFile); + return true; + + }else{ - // Close and remove temporary file - fclose($tempFile); + return false; + } + } + + } + + + public function generateExcelForSIEnhancement($export_data) + { + + $objects = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($export_data); + + // dd($objects); + + $count = count($objects); + $export_data['count'] = $count; + + $this->myLogger->logme('error','SI_Enhancement export data count : {data}', ['data'=> $count ]); + + if($count == 0){ + return false; + } + + $this->myLogger->logme('error','SI_Enhancement export file name : {data}', ['data'=> $export_data['file_name'] ]); + + $si_data = transform_objects_to_array_for_si_enhancement($objects); + + $headers = [ + 'S.No', + 'NAME OF EMP/DEP', + 'EMP ID', + 'EMP/DEP TYPE', + 'RELATION', + 'DOB', + 'GENDER', + 'PRE EXISTING AILMENTS', + 'BASIC COVER SI', + 'Old Sum Insured', + 'Date of Coverage', + 'Policy End Date', + 'No Of Days', + 'Old SI Premium', + 'New SI premium', + 'Difference premium', + 'Pro Rata Premium', + 'GST', + 'Total', + 'ENDORSEMENT_ID' + ]; + + + // Create a temporary file in memory + $tempFile = tmpfile(); + + // Generate Excel file with the temporary file + $value = generate_excel($headers, $si_data, $tempFile); + + if($value){ + $return = $this->batchFilesAndBatchListEntry($export_data, $objects); + if($return){ + + // Set the appropriate headers for Excel file download + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); + header('Cache-Control: max-age=0'); + + // Rewind the temporary file pointer + rewind($tempFile); + + // Output the contents of the temporary file to the browser + fpassthru($tempFile); + + // Close and remove the temporary file + fclose($tempFile); + + return true; + + }else{ + return false; + } + } + + } + + + public function generateExcelForDeletion($export_data) + { + // dd($export_data['client_id']); + $objects = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($export_data); + $count = count($objects); + $export_data['count'] = $count; + + $this->myLogger->logme('error','Deletion export data count : {data}', ['data'=> $count ]); + + if($count == 0){ + return false; + } + + $this->myLogger->logme('error','Deletion export file name : {data}', ['data'=> $export_data['file_name'] ]); + + $si_data = transform_objects_to_array_for_deletion($objects); + // dd($si_data); + $headers = [ + 'S.No', + 'EMP ID', + 'EMP NAME', + 'DOB', + 'GENDER', + 'RELATIONSHIP', + 'SUM INSURED', + 'Date of Leaving', + 'Policy End Date', + 'No Of Days', + 'Premium', + 'Pro Rata Premium', + 'GST', + 'Total', + 'Claim Status', + 'ENDORSEMENT_ID' + ]; + + + // Create a temporary file in memory + $tempFile = tmpfile(); + + // Generate Excel file with the temporary file + $value = generate_excel($headers, $si_data, $tempFile, 2); + + if($value){ + $return = $this->batchFilesAndBatchListEntry($export_data, $objects); + if( $return){ + + // Set the appropriate headers for Excel file download + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); + header('Cache-Control: max-age=0'); + + // Rewind the temporary file pointer + rewind($tempFile); + + // Output the contents of the temporary file to the browser + fpassthru($tempFile); + + // Close and remove the temporary file + fclose($tempFile); + + return true; + + }else{ + return false; + } + } + + + } + + + + /** + * The below functions are Imports data from an Excel file for : + * - Inception + * - Deletion + * - Correction + * - SI_Enhancement + * + * This functions are processes the uploaded Excel file, extracts relevant information, + * and updates employee policies and employees table accordingly. + * + * @param array $import_data An associative array containing : + * - client_id, + * - client_policy_id, + * - the uploaded file. + * @return int Returns: + * - 1 if data import is successful. + * - 2 if the file does not exist. + * - 0 if the provided data is incomplete or incorrect. + */ + + public function importExcelDataForInception($import_data) + { + + $client_id = $import_data['client_id']; + $client_policy_id = $import_data['client_policy_id']; + $file = $import_data['file']; + + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); + $filename = $file->getName(); + + $this->myLogger->logme('error','Inception Import file name : {data}', ['data'=> $filename ]); + $random_number_count = 4; + $batch_code = generate_random_string($random_number_count); + + $this->myLogger->logme('error','Inception Import BATCH CODE : {data}', ['data'=> $batch_code ]); + + $import_data['batch_code'] = $batch_code; + $import_data['created_by'] = get_session_userid(); + $import_data['file_name'] = $filename; + $insert = $this->batchFileModel->insert($import_data); + $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + + $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; + $batch_code_for_batch_list['created_by'] = get_session_userid(); + + $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; + + //check the file exist or not + if(!file_exists($file_name_with_path)) + { + return 2; + } + + $data = read_excel_file_to_array($file_name_with_path); + unset($data[0]); + array_pop($data); + $count = count($data); + $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); + // dd($data ); + $employeeIds = []; + foreach ($data as $key => $value) { + // Check if the array is not empty and has the necessary data + if (!empty($value) && (isset($value[15]) || isset($value[16]))) { + + // Extract the client_policy_id and tpa_id from the array + $tpa_id = $value[15] != null ? $value[15] : ''; + $uhid = $value[16] != null ? $value[16] : ''; + $emp_code = $value[2]; + $name = $value[1]; + + $val = $this->employeePolicyModel + ->select('employee_polices.id') + ->join('employees', 'employees.id = employee_polices.employee_id') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employees.client_id', $client_id) + ->where('employees.name', $name) + ->where('employees.emp_code', $emp_code) + ->where('employee_polices.is_active', 1) + ->first(); + + if ($val !== null) { + $id = $val['id']; + $batch_code_for_batch_list['emp_policy_id'] = $id; + $this->batchListModel->insert($batch_code_for_batch_list); + array_push($employeeIds, $id); + } + + $updateData = [ + 'client_policy_id' => $client_policy_id, + 'client_id' => $client_id, + 'name' => $name, + 'emp_code' => $emp_code, + 'uhid' => $uhid, + 'tpa_id' => $tpa_id + ]; + + $this->employeePolicyModel->updateTPAIDorUHID($updateData); + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; + + }else{ + + return 0; + } + + } + + + $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); + $depositeData = [ + 'employeeIds'=>$employeeIds, + 'client_id'=>$client_id, + 'client_policy_id'=>$client_policy_id, + 'count'=>$count, + 'event'=>$import_data['event_type'], + 'policy_name'=>$policy_name['policy_name'], + ]; + + $this->cashDepositCalculationForInception($depositeData); + return 1; + + } + + + public function importExcelDataForCorrection($import_data) + { + + $client_id = $import_data['client_id']; + $client_policy_id = $import_data['client_policy_id']; + $file = $import_data['file']; + + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); + $filename = $file->getName(); + + $this->myLogger->logme('error','Correction Import file name : {data}', ['data'=> $filename ]); + $random_number_count = 4; + $batch_code = generate_random_string($random_number_count); + $this->myLogger->logme('error','Correction Import BATCH CODE : {data}', ['data'=> $batch_code ]); + + + $import_data['batch_code'] = $batch_code; + $import_data['created_by'] = get_session_userid(); + $import_data['file_name'] = $filename; + $insert = $this->batchFileModel->insert($import_data); + $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + + $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; + $batch_code_for_batch_list['created_by'] = get_session_userid(); + + $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; + + if(!file_exists($file_name_with_path)) + { + return 2; + } + + $data = read_excel_file_to_array($file_name_with_path); + unset($data[0]); + $count = count($data); + $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); + // dd($data); + foreach ($data as $key => $value) { + + if (!empty($value) && isset($value[10])) { + + $emp_code = $value[0]; + $uhid = $value[1]; + $endorsement_id = $value[10] != null ? $value[10] : ''; + + $val = $this->employeePolicyModel + ->select('employees.id') + ->join('employees', 'employees.id = employee_polices.employee_id') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employees.client_id', $client_id) + ->where('employee_polices.uhid', $uhid) + ->where('employees.emp_code', $emp_code) + ->where('employees.is_active', 1) + ->first(); + $batch_code_for_batch_list['emp_policy_id'] = $val['id']; + $this->batchListModel->insert($batch_code_for_batch_list); + + // $this->employeePolicyModel->updateCorrectionData($emp_code, $uhid, $endorsement_id); + + $queryData = $this->empEndorsementModel->select('emp_endorsement.*') + ->join('employees', 'employees.id = emp_endorsement.pk') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code', $emp_code) + ->where('employees.client_id', $client_id) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.uhid', $uhid) + ->get() + ->getResultArray(); + + // dd($queryData); + + foreach ($queryData as $endorsementData) { + + $emp_endoresment_id = $endorsementData['id']; + $emp_id = $endorsementData['emp_id']; + $field_name = $endorsementData['field_name']; + $new_value = $endorsementData['new_value']; + $this->empEndorsementModel->where('id', $emp_endoresment_id)->set('endorsement_id', $endorsement_id)->update(); + $this->employeeModel->where('id', $emp_id)->set($field_name, $new_value)->update(); + } + + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; + }else{ + + return 0; + } + + } + + + return 1; + + } + + + public function importExcelDataForSIEnhancement($import_data) + { + + $client_id = $import_data['client_id']; + $client_policy_id = $import_data['client_policy_id']; + $file = $import_data['file']; + + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); + $filename = $file->getName(); + + $this->myLogger->logme('error','SI_Enhancement Import file name : {data}', ['data'=> $filename ]); + $random_number_count = 4; + $batch_code = generate_random_string($random_number_count); + $this->myLogger->logme('error','SI_Enhancement Import BATCH CODE : {data}', ['data'=> $batch_code ]); + + + $import_data['batch_code'] = $batch_code; + $import_data['created_by'] = get_session_userid(); + $import_data['file_name'] = $filename; + $insert = $this->batchFileModel->insert($import_data); + $batch_file_batch_code = $this->batchFileModel->where('id', 2)->first(); + + $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; + $batch_code_for_batch_list['created_by'] = get_session_userid(); + + $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; + + if(!file_exists($file_name_with_path)) + { + return 2; + } + + $data = read_excel_file_to_array($file_name_with_path); + unset($data[0]); + $count = count($data); + $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); + // dd($data); + $employeeIds = []; + foreach ($data as $key => $value) { + + if (!empty($value) && isset($value[19])) { + + $emp_name = $value[1]; + $emp_code = $value[2]; + // echo $emp_name .'-'. $emp_code; die; + $endorsement_id = $value[19] != null ? $value[19] : ''; + + $updateData = [ + 'emp_code' =>$emp_code, + 'client_id' =>$client_id, + 'client_policy_id' =>$client_policy_id, + 'emp_name' =>$emp_name, + 'endorsement_id' =>$endorsement_id, + ]; + + $this->employeePolicyModel->updateEndoresmentIdForSIEnhancement($updateData); + + $queryData = $this->employeePolicyModel + ->select('employee_polices.*') + ->join('employees', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code', $emp_code) + ->where('employees.name', $emp_name) + ->where('employees.client_id', $client_id) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.is_active', 1) + ->first(); + + $queryData['is_active'] = 0; + $this->employeePolicyModel->save($queryData); + + unset($queryData['id']); + unset($queryData['created_by']); + unset($queryData['created_at']); + unset($queryData['updated_by']); + unset($queryData['updated_at']); + unset($queryData['is_active']); + + $queryData['basic_cover_si'] = $value[8]; + $queryData['premium'] = $value[14]; + $queryData['si_enhancement_date'] = $value[10]; + $queryData['rata_premimum'] = $value[16]; + $queryData['gst'] = $value[17]; + $queryData['created_by'] = get_session_userid(); + + //new insert + $this->employeePolicyModel->save($queryData); + + $val = $this->employeePolicyModel + ->select('employee_polices.id') + ->join('employees', 'employees.id = employee_polices.employee_id') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employees.client_id', $client_id) + ->where('employees.name', $emp_name) + ->where('employees.emp_code', $emp_code) + ->where('employee_polices.is_active', 1) + ->first(); + + if ($val !== null) { + $id = $val['id']; + $batch_code_for_batch_list['emp_policy_id'] = $id; + $this->batchListModel->insert($batch_code_for_batch_list); + array_push($employeeIds, $id); + } + + + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; + }else{ + + return 0; + } + + } + + $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); + $depositeData = [ + 'employeeIds'=>$employeeIds, + 'client_id'=>$client_id, + 'client_policy_id'=>$client_policy_id, + 'count'=>$count, + 'event'=>$import_data['event_type'], + 'policy_name'=>$policy_name['policy_name'], + ]; + + // dd($depositeData); + $this->cashDepositCalculationForSIEnhancement($depositeData); + + return 1; + + + } + + + public function importExcelDataForDeletion($import_data) + { + + $client_id = $import_data['client_id']; + $client_policy_id = $import_data['client_policy_id']; + $file = $import_data['file']; + + + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); + $filename = $file->getName(); + + $this->myLogger->logme('error','Deletion Import file name : {data}', ['data'=> $filename ]); + $random_number_count = 4; + $batch_code = generate_random_string($random_number_count); + $this->myLogger->logme('error','Deletion Import BATCH CODE : {data}', ['data'=> $batch_code ]); + + + $import_data['batch_code'] = $batch_code; + $import_data['created_by'] = get_session_userid(); + $import_data['file_name'] = $filename; + $insert = $this->batchFileModel->insert($import_data); + $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); + + $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; + $batch_code_for_batch_list['created_by'] = get_session_userid(); + + $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; + + if(!file_exists($file_name_with_path)) + { + return 2; + } + + $data = read_excel_file_to_array($file_name_with_path); + unset($data[0]); + array_pop($data); + + $count = count($data); + $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); + + $employeeIds = []; + foreach ($data as $key => $value) { + + if (!empty($value) && isset($value[15])) { + + $emp_name = $value[2]; //employee name + $emp_code = $value[1]; //employee code + $date_of_exit = $value[7]; // date of releving + + // echo $emp_name .'-'. $emp_code .'-'. $date_of_exit; die; + $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id + + $val = $this->employeePolicyModel + ->select('employee_polices.id') + ->join('employees', 'employees.id = employee_polices.employee_id') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employees.client_id', $client_id) + ->where('employees.name', $emp_name) + ->where('employees.emp_code', $emp_code) + ->where('employee_polices.is_active', 1) + ->first(); + + + if ($val !== null) { + + $id = $val['id']; + $batch_code_for_batch_list['emp_policy_id'] = $id; + $this->batchListModel->insert($batch_code_for_batch_list); + array_push($employeeIds, $id); + } + + $updateData = [ + 'emp_code' =>$emp_code, + 'client_id' =>$client_id, + 'client_policy_id' =>$client_policy_id, + 'emp_name' =>$emp_name, + 'endorsement_id' =>$endorsement_id, + ]; + + $this->employeePolicyModel->updateEndoresmentIdForDeletion($updateData); + + $deletionDataForEmployee = $this->empEndorsementModel + ->select('emp_endorsement.new_value, employees.id') + ->join('employees', 'emp_endorsement.emp_code = employees.emp_code') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('emp_endorsement.emp_code', $emp_code) + ->where('employees.client_id', $client_id) + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('emp_endorsement.name', $emp_name) + ->where('emp_endorsement.field_name', 'emp_status') + ->first(); + + $deletionDataForEmployee['updated_by'] = get_session_userid(); + $this->employeeModel->save($deletionDataForEmployee); + + $fetchData = [ + 'emp_code'=> $emp_code, + 'client_policy_id'=> $client_policy_id, + 'emp_name'=> $emp_name, + ]; + + $deletionDataForEmployeePolicy = $this->employeePolicyModel->fetchEmpEndorsementData($fetchData); + $deletionDataForEmployeePolicy['updated_by'] = get_session_userid(); + $this->employeePolicyModel->save($deletionDataForEmployeePolicy); + + // echo '
';
+                        // print_r($deletionDataForEmployeePolicy); die;
+                        
+                        $this->employeePolicyModel->save($deletionDataForEmployeePolicy);
+                        
+                        // $query = $this->employeePolicyModel->getLastQuery();
+                        // echo $query . "
"; + + }else{ + + return 0; + } + + } + + $policy_name = $this->getPolicyNameUsingClientPolicyId($client_policy_id); + $depositeData = [ + 'employeeIds'=>$employeeIds, + 'client_id'=>$client_id, + 'client_policy_id'=>$client_policy_id, + 'count'=>$count, + 'event'=>$import_data['event_type'], + 'policy_name'=>$policy_name['policy_name'], + ]; + + $this->cashDepositCalculationForDeletion($depositeData); + return 1; + + + } + + + + /** + * The below functions are Calculates and records cash deposits for employee policies at inception. + * + * @param array $arrayData An array containing necessary data including : + * - employee IDs, + * - client policy ID, + * - client ID, + * - count of employees, + * - policy_name, and + * - event type. + * + * @return bool Returns true if the operation is successful, otherwise returns 0. + */ + + public function cashDepositCalculationForInception($arrayData) + { + if (!empty($arrayData)) { + + $amount = $this->employeePolicyModel->query(" + SELECT SUM(rata_premimum + gst) AS total_sum + FROM employee_polices + WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ") + ")->getRow(); + + $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first(); + $description = 'The following amount of Rs. ' . $amount->total_sum . '/- has been debited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.'; + + $data = [ + 'amount' => $amount->total_sum, + 'sub_type_id' => 1, + 'client_id' => $arrayData['client_id'], + 'insurer_id' => $insurer_id['insurer_id'], + 'description' => $description, + 'transaction_type' => 'Debit', + 'updated_by' => get_session_userid(), + 'is_active' => 1, + ]; + $response = DepositHelper::saveDeposit($data, get_session_userid()); + return true; + // print_r($response); + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; - return true; // Excel file successfully generated and exported } else { - return false; // Batch operation failed + return 0; } + + } - return false; // Excel generation failed - } - - - public function generateExcelForCorrection($export_data) - { - - $objects = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($export_data['client_id'], $export_data['client_policy_id'], $export_data['insurer_or_tpa']); - // dd($objects); - $count = count($objects); - $export_data['count'] = $count; - $this->myLogger->logme('error','Correction export data count : {data}', ['data'=> $count ]); - - if($count == 0){ - return false; - } - - $this->myLogger->logme('error','Correction export file name : {data}', ['data'=> $export_data['file_name'] ]); - - $correction_data = transform_objects_to_array_for_correction($objects); - - $headers = [ - 'Emp Code', - 'RISK ID', - 'NAME OF EMP/DEP', - 'EMP/DEP TYPE', - 'RELATION', - 'DOB', - 'GENDER', - 'Wrong Data', - 'Correct Data', - 'Remarks', - 'Endorsement_Id' - ]; - - - // Create a temporary file in memory - $tempFile = tmpfile(); - - // Generate Excel file with the temporary file - $value = generate_excel($headers, $correction_data, $tempFile); - - if($value){ - $return = $this->batchFilesAndBatchListEntry($export_data, $objects); - if($return){ - - // Set the appropriate headers for Excel file download - header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); - header('Cache-Control: max-age=0'); - - // Rewind the temporary file pointer - rewind($tempFile); - - // Output the contents of the temporary file to the browser - fpassthru($tempFile); - - // Close and remove the temporary file - fclose($tempFile); - - return true; - - }else{ - - return false; - } - } - - } - - - public function generateExcelForSIEnhancement($export_data) - { - - $objects = $this->employeePolicyModel->getSIEnhancementEmployeesDataForExportExcel($export_data['client_id'], $export_data['client_policy_id'], $export_data['insurer_or_tpa']); - - // dd($objects); - - $count = count($objects); - $export_data['count'] = $count; - - $this->myLogger->logme('error','SI_Enhancement export data count : {data}', ['data'=> $count ]); - - if($count == 0){ - return false; - } - - $this->myLogger->logme('error','SI_Enhancement export file name : {data}', ['data'=> $export_data['file_name'] ]); - - $si_data = transform_objects_to_array_for_si_enhancement($objects); - - $headers = [ - 'S.No', - 'NAME OF EMP/DEP', - 'EMP ID', - 'EMP/DEP TYPE', - 'RELATION', - 'DOB', - 'GENDER', - 'PRE EXISTING AILMENTS', - 'BASIC COVER SI', - 'Old Sum Insured', - 'Date of Coverage', - 'Policy End Date', - 'No Of Days', - 'Old SI Premium', - 'New SI premium', - 'Difference premium', - 'Pro Rata Premium', - 'GST', - 'Total', - 'ENDORSEMENT_ID' - ]; - - - // Create a temporary file in memory - $tempFile = tmpfile(); - - // Generate Excel file with the temporary file - $value = generate_excel($headers, $si_data, $tempFile); - - if($value){ - $return = $this->batchFilesAndBatchListEntry($export_data, $objects); - if($return){ - - // Set the appropriate headers for Excel file download - header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); - header('Cache-Control: max-age=0'); - - // Rewind the temporary file pointer - rewind($tempFile); - - // Output the contents of the temporary file to the browser - fpassthru($tempFile); - - // Close and remove the temporary file - fclose($tempFile); - - return true; - - }else{ - return false; - } - } - - - } - - - public function generateExcelForDeletion($export_data) - { - - $objects = $this->employeePolicyModel->getDeletionEmployeeDataForExportExcel($export_data['client_id'], $$export_data['client_policy_id'], $$export_data['insurer_or_tpa']); - $count = count($objects); - $export_data['count'] = $count; - - $this->myLogger->logme('error','Deletion export data count : {data}', ['data'=> $count ]); - - if($count == 0){ - return false; - } - - $this->myLogger->logme('error','Deletion export file name : {data}', ['data'=> $export_data['file_name'] ]); - - $si_data = transform_objects_to_array_for_deletion($objects); - - // dd($si_data); - - $headers = [ - 'S.No', - 'EMP ID', - 'EMP NAME', - 'DOB', - 'GENDER', - 'RELATIONSHIP', - 'SUM INSURED', - 'Date of Leaving', - 'Policy End Date', - 'No Of Days', - 'Premium', - 'Pro Rata Premium', - 'GST', - 'Total', - 'Claim Status', - 'ENDORSEMENT_ID' - ]; - - - // Create a temporary file in memory - $tempFile = tmpfile(); - - // Generate Excel file with the temporary file - $value = generate_excel($headers, $si_data, $tempFile, 2); - - if($value){ - $return = $this->batchFilesAndBatchListEntry($export_data, $objects); - if( $return){ - - // Set the appropriate headers for Excel file download - header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); - header('Content-Disposition: attachment;filename="' . $export_data['file_name'] . '"'); - header('Cache-Control: max-age=0'); - - // Rewind the temporary file pointer - rewind($tempFile); - - // Output the contents of the temporary file to the browser - fpassthru($tempFile); - - // Close and remove the temporary file - fclose($tempFile); - - return true; - - }else{ - return false; - } - } - - - } - - - public function cashDepositCalculationForInception($arrayData = []) - { - if (!empty($arrayData)) { - $query = $this->employeePolicyModel->query(" - SELECT SUM(rata_premimum + gst) AS total_sum + public function cashDepositCalculationForSIEnhancement($arrayData) + { + if (!empty($arrayData)) { + + $amount = $this->employeePolicyModel->query(" + SELECT + SUM(ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.si_enhancement_date)) / 365, 2) + + ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.si_enhancement_date)) / 365) * 0.18, 2)) AS total_sum FROM employee_polices - WHERE id IN (" . implode(',', $arrayData) . ") - "); - $row = $query->getRow(); - $ - $insert = $this->clientDepositModel->insert(); - $query = $this->clientDepositModel->orderBy('id', 'DESC')->limit(1)->get(); - $cashDepositLastEntry = $query->getRow(); + WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ") + ")->getRow(); + $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first(); + $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.'; - print_r($cashDepositLastEntry); die; + $data = [ - - return $row ? $row->total_sum : 0; + 'amount' => $amount->total_sum, + 'sub_type_id' => 1, + 'client_id' => $arrayData['client_id'], + 'insurer_id' => $insurer_id['insurer_id'], + 'description' => $description, + 'transaction_type' => 'Debit', + 'updated_by' => get_session_userid(), + 'is_active' => 1, + ]; + $response = DepositHelper::saveDeposit($data, get_session_userid()); + return true; + // print_r($response); + // $query = $this->employeePolicyModel->getLastQuery(); + // echo $query . "
"; - } else { - return 0; + } else { + return 0; + } } - - } + public function cashDepositCalculationForDeletion($arrayData) + { + // print_r($arrayData); + if (!empty($arrayData)) { + + echo '
';
+                print_r($arrayData); die;
+                $amount = $this->employeePolicyModel->query("
+                SELECT
+                    SUM(ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.date_of_exit)) / 365, 2) +
+                        ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, employee_polices.date_of_exit)) / 365) * 0.18, 2)) AS total_sum
+                FROM employee_polices
+                WHERE id IN (" . implode(',', $arrayData['employeeIds']) . ")
+                ")->getRow();
+                print_r($amount);die;
+                $insurer_id = $this->clientPolicyModel->where('id', $arrayData['client_policy_id'])->first();       
+                $description = 'The following amount of ' . $amount->total_sum . ' has been credited for the ' . $arrayData['count'] . ' employees at ' . remove_underscore_capitalize_first_letter($arrayData['event']) . ' to ' . remove_underscore_capitalize_first_letter($arrayData['policy_name']) . '.';
 
-    public function cashDepositCalculationForSIEnhancement($arrayData = [])
-    {
+                $data = [
 
-    }
+                    'amount' => $amount->total_sum,
+                    'sub_type_id' => 1,
+                    'client_id' => $arrayData['client_id'],
+                    'insurer_id' => $insurer_id['insurer_id'],
+                    'description' => $description,
+                    'transaction_type' => 'Credit',
+                    'updated_by' => get_session_userid(),
+                    'is_active' => 1,
+                ];
+                $response = DepositHelper::saveDeposit($data, get_session_userid());
+                return true;
+                // print_r($response);
+                // $query = $this->employeePolicyModel->getLastQuery();
+                // echo $query . "
"; - public function cashDepositCalculationForDeletion($arrayData) - { + } else { + return 0; + } - } + } + + public function getPolicyNameUsingClientPolicyId($client_policy_id){ + return $this->clientPolicyModel->select('policies.name as policy_name') + ->join('policies', 'policies.id = client_policy.policy_id') + ->where('client_policy.id', $client_policy_id) + ->first(); + } // ----------------------------------------------------------------------------------- } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 67e5f6b5..5c76efe6 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -125,11 +125,27 @@ class EmployeeController extends AdminController // print_r($this->request->getPost('upload-action-type')); // die(); // $empServiceController = new EmployeeServiceController(); - // $res = $empServiceController->excelFileFormatValidation(['file_id' => '34']); + // $res = $empServiceController->excelFileFormatValidation(['file_id' => '38']); // dd($res); // $empServiceController = new EmployeeServiceController(); - // $res = $empServiceController->excelFileDataValidation(['file_id' => '12']); + // $res = $empServiceController->excelFileDataValidation(['file_id' => '38']); + // dd($res); + // $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_policy_id: '2'); + // dd($existing_famility_details); + // $empServiceController = new EmployeeServiceController(); + // $res = $empServiceController->employeesSIEnhanceProcess(['file_id' => '38']); + // dd($res); + + // $empServiceController = new EmployeeServiceController(); + // $res = $empServiceController->employeesCorrectionProcess(['file_id' => '37']); + // // dd($res); + // $empServiceController = new EmployeeServiceController(); + // $res = $empServiceController->employeesOnboardPreprocess(['client_policy_id' => '3']); + // dd($res); + + // $empServiceController = new EmployeeServiceController(); + // $res = $empServiceController->employeeDisembark(['file_id' => '36']); // dd($res); // if(isset($res['error_summary']) && count($res['error_summary'])) @@ -173,7 +189,7 @@ class EmployeeController extends AdminController $action = $this->request->getPost('upload-action-type'); $status = 'inprogress'; - $file_id = $this->fileModel->insert(['file_name' => $filename,'client_id' => $client_id,'policy_id' => $policy_id,'created_by' => $loggedInUserID,'status' => $status,'action' => $action]); + $file_id = $this->fileModel->insert(['file_name' => $filename,'client_id' => $client_id,'policy_id' => $policy_id,'created_by' => $loggedInUserID,'status' => $status,'action' => $action]);//here field policy_id have client_policy_id and not policy id from policy master $this->myLogger->logme("error",'{file_id} uploaded success',['file_id' => $file_id]); //start validation process @@ -190,16 +206,30 @@ class EmployeeController extends AdminController } - $data['actions'] = ['inception' => 'Inception + Addition + Deletion','correction' =>'Correction','si_enhancement' =>'SI Enhancement']; - $data['events'] = ['inception' => 'Inception + Addition','correction' =>'Correction', 'deletion'=>'Deletion' ,'si_enhancement' =>'SI Enhancement']; + + + $data['events'] = ['inception' => 'Inception (Employee + Dependents)','addition' => 'Addition (Employee + Dependents)','dependent_addition' => 'Dependent Addition (Only Dependents)','deletion' => 'Deletion','correction' =>'Correction','si_enhancement' =>'SI Enhancement']; + $data['actions'] = ['inception' => 'Inception (Employee + Dependents)','addition' => 'Addition (Employee + Dependents)','dependent_addtion' => 'Dependent Addition (Only Dependents)','deletion' => 'Deletion','correction' =>'Correction','si_enhancement' =>'SI Enhancement']; + $data['import_or_export'] = ['import' => 'Import','export' =>'Export']; $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']) ->join('user_profiles up','files.created_by = up.id') - ->join('policies pm','files.policy_id = pm.id') - ->join('clients c','files.client_id = c.id') - ->where('files.created_by',8)->orderBy('files.created_at','desc')->findAll(); + ->join('client_policy cp','files.policy_id = cp.id') + ->join('policies pm','cp.policy_id = pm.id') + ->join('clients c','files.client_id = c.id and files.client_id = cp.client_id') + ->where('files.created_by',get_session_userid())->orderBy('files.created_at','desc')->findAll(); + + $data['batch_list'] = $this->batchFileModel->select('batch_files.*, policies.name as policy_name, clients.short_name as client_short_name') + ->join('client_policy', 'client_policy.id = batch_files.client_policy_id') + ->join('policies', 'policies.id = client_policy.policy_id') + ->join('clients', 'clients.id = client_policy.client_id') + ->orderBy('batch_files.id','desc') + ->findAll(); + + // dd($data['fileList']);die(); if($this->request->getMethod() == "get") { @@ -222,8 +252,18 @@ class EmployeeController extends AdminController } - /**This downloadSampleExcelFile() function facilitates downloading various sample Excel files - ** based on user-selected actions, handling file retrieval and download processes. **/ + /** + * The below function Downloads a sample Excel file based on the provided action type. + * + * @param string|null $actionType The type of action : + * + * - inception + * - correction + * - si_enhancement for selecting the appropriate sample Excel file. + * + * @return redirect back with an error message if the file is not found, otherwise sends the file to the user for download. + */ + public function downloadSampleExcelFile($actionType = null) { // $actionType = $this->request->getGet(); @@ -254,6 +294,16 @@ class EmployeeController extends AdminController } + /** + * The below function are Handles import and export operations based on the provided parameters. + * + * This function logs the call, retrieves necessary data, generates a filename, + * and then either exports data to an Excel file or imports data from an Excel file + * depending on the provided action type and event type. + * + * @return void Redirects the user to the appropriate page with flash messages indicating success or failure. + */ + public function importExport() { @@ -279,16 +329,18 @@ class EmployeeController extends AdminController 'file_name' => $file_name, ]; + // $event_type = 'si_enhancement'; + if($actions == 'export'){ - if($event_type == 'inception'){ + if($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition' ){ $return = $empDataServiceController->generateExcelForAdditionandInception($batch_data); if(!$return){ session()->setFlashdata('error', 'No data found about this action'); return redirect()->to(base_url('employee/upload')); } else{ - $this->myLogger->logme('error','Successfully exported Excel file in Inception/Addition/DependentAddition.'); + $this->myLogger->logme('error','Successfully exported Excel file in {data}.', ['data' => $event_type]); } } else if($event_type == 'correction'){ @@ -325,379 +377,72 @@ class EmployeeController extends AdminController }else if($actions == 'import'){ - if($event_type == 'inception'){ + $batch_data['file'] = $this->request->getFile('import_file_data'); - $file = $this->request->getFile('import_file_data'); - $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); - $filename = $file->getName(); + if($event_type == 'inception' || $event_type == 'addition' || $event_type == 'dependent_addition'){ - $this->myLogger->logme('error','Inception Import file name : {data}', ['data'=> $filename ]); - $random_number_count = 4; - $batch_code = generate_random_string($random_number_count); - - $this->myLogger->logme('error','Inception Import BATCH CODE : {data}', ['data'=> $batch_code ]); + $return = $empDataServiceController->importExcelDataForInception($batch_data); + if($return == 1){ + session()->setFlashdata('success', 'Data updated successfully'); + return redirect()->to(base_url('employee/upload')); - $batch_data['batch_code'] = $batch_code; - $batch_data['created_by'] = get_session_userid(); - $batch_data['file_name'] = $filename; - // $insert = $this->batchFileModel->insert($batch_data); - $batch_file_batch_code = $this->batchFileModel->where('id', 2)->first(); + }else if($return == 2){ + session()->setFlashdata('error', 'File not found'); + return redirect()->to(base_url('employee/upload')); - $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_code_for_batch_list['created_by'] = get_session_userid(); - - $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; - - //check the file exist or not - if(!file_exists($file_name_with_path)) - { - // session()->setFlashdata('error', 'File not found'); - // return redirect()->to(base_url('employee/upload')); + }else if($return == 0){ + session()->setFlashdata('error', 'Something went wrong'); + return redirect()->to(base_url('employee/upload')); } - $data = read_excel_file_to_array($file_name_with_path); - unset($data[0]); - array_pop($data); - $count = count($data); - // $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); - // dd($data ); - $employeeIds = []; - foreach ($data as $key => $value) { - // Check if the array is not empty and has the necessary data - if (!empty($value) && (isset($value[15]) || isset($value[16]))) { - - // Extract the client_policy_id and tpa_id from the array - $tpa_id = $value[15] != null ? $value[15] : ''; - $uhid = $value[16] != null ? $value[16] : ''; - $emp_code = $value[2]; - $name = $value[1]; - - $val = $this->employeePolicyModel - ->select('employee_polices.id') - ->join('employees', 'employees.id = employee_polices.employee_id') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employees.client_id', $client_id) - ->where('employees.name', $name) - ->where('employees.emp_code', $emp_code) - ->where('employee_polices.is_active', 1) - ->first(); - $batch_code_for_batch_list['emp_policy_id'] = $val['id']; - $this->batchListModel->insert($batch_code_for_batch_list); - array_push($employeeIds, $val['id']); - - $this->employeePolicyModel->updateTPAIDorUHID( $client_policy_id, $client_id, $name, $emp_code, $uhid, $tpa_id); - - // $query = $this->employeePolicyModel->getLastQuery(); - // echo $query . "
"; - - }else{ - - // session()->setFlashdata('error', 'Something went wrong'); - // return redirect()->to(base_url('employee/upload')); - } - - } - $action = ['action' => 'inception']; - - // $depositeData = [ - // $employeeIds, - // ]; - // print_r($employeeIds); die; - $empDataServiceController->cashDepositCalculationForInception($employeeIds); - // echo '
';
-                // print_r($depositeData); die;
-                
-                // session()->setFlashdata('success', 'Data updated successfully');
-                // return redirect()->to(base_url('employee/upload'));
-
             }else if($event_type == 'correction'){
 
-                $file = $this->request->getFile('import_file_data');
-                $is_moved = $file->move(WRITEPATH . 'uploads/import_excel');
-                $filename = $file->getName();
+                $return = $empDataServiceController->importExcelDataForCorrection($batch_data);
+                if($return == 1){
+                    session()->setFlashdata('success', 'Data updated successfully');
+                    return redirect()->to(base_url('employee/upload'));
 
-                $this->myLogger->logme('error','Correction Import file name : {data}', ['data'=> $filename ]);
-                $random_number_count = 4;
-                $batch_code = generate_random_string($random_number_count);
-                $this->myLogger->logme('error','Correction Import BATCH CODE : {data}', ['data'=> $batch_code ]);
-
-
-                $batch_data['batch_code'] = $batch_code;
-                $batch_data['created_by'] = get_session_userid();
-                $batch_data['file_name'] = $filename;
-                $insert = $this->batchFileModel->insert($batch_data);
-                $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first();
-
-                $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code'];
-                $batch_code_for_batch_list['created_by'] = get_session_userid();
-
-                $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name'];
-
-                if(!file_exists($file_name_with_path))
-                {
+                }else if($return == 2){
                     session()->setFlashdata('error', 'File not found');
                     return redirect()->to(base_url('employee/upload'));
+
+                }else if($return == 0){
+                    session()->setFlashdata('error', 'Something went wrong');
+                    return redirect()->to(base_url('employee/upload'));
                 }
 
-                $data = read_excel_file_to_array($file_name_with_path);
-                unset($data[0]);
-                $count = count($data);
-                $this->batchFileModel->where('id', $insert)->set('count', $count)->update();
-                // dd($data);
-                foreach ($data as $key => $value) {
-
-                    if (!empty($value) && isset($value[10])) {
-
-                        $emp_code = $value[0];
-                        $uhid = $value[1];
-                        $endorsement_id = $value[10] != null ? $value[10] : '';
-
-                        $val = $this->employeePolicyModel
-                        ->select('employees.id')
-                        ->join('employees', 'employees.id = employee_polices.employee_id')
-                        ->where('employee_polices.client_policy_id', $client_policy_id)
-                        ->where('employees.client_id', $client_id)
-                        ->where('employee_polices.uhid', $uhid)
-                        ->where('employees.emp_code', $emp_code)
-                        ->where('employees.is_active', 1)
-                        ->first();
-                        $batch_code_for_batch_list['emp_policy_id'] = $val['id'];
-                        $this->batchListModel->insert($batch_code_for_batch_list);
-
-                        // $this->employeePolicyModel->updateCorrectionData($emp_code, $uhid, $endorsement_id);
-
-                       $queryData =  $this->empEndorsementModel->select('emp_endorsement.*')
-                                ->join('employees', 'employees.id = emp_endorsement.pk')
-                                ->join('employee_polices', 'employee_polices.employee_id = employees.id')
-                                ->where('employees.emp_code', $emp_code)
-                                ->where('employees.client_id', $client_id)
-                                ->where('employee_polices.client_policy_id', $client_policy_id)
-                                ->where('employee_polices.uhid', $uhid)
-                                ->get()
-                                ->getResultArray();
-
-                                // dd($queryData);
-
-                        foreach ($queryData as $endorsementData) {
-
-                            $emp_endoresment_id = $endorsementData['id'];
-                            $emp_id = $endorsementData['emp_id'];
-                            $field_name = $endorsementData['field_name'];
-                            $new_value = $endorsementData['new_value'];
-                            $this->empEndorsementModel->where('id', $emp_endoresment_id)->set('endorsement_id', $endorsement_id)->update();
-                            $this->employeeModel->where('id', $emp_id)->set($field_name, $new_value)->update();
-                        }
-
-                        // $query = $this->employeePolicyModel->getLastQuery();
-                        // echo $query . "
"; - }else{ - session()->setFlashdata('error', 'Something went wrong'); - return redirect()->to(base_url('employee/upload')); - } - - } - - session()->setFlashdata('success', 'Data updated successfully'); - return redirect()->to(base_url('employee/upload')); - }else if($event_type == 'si_enhancement'){ - $file = $this->request->getFile('import_file_data'); - $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); - $filename = $file->getName(); + $return = $empDataServiceController->importExcelDataForSIEnhancement($batch_data); + if($return == 1){ + session()->setFlashdata('success', 'Data updated successfully'); + return redirect()->to(base_url('employee/upload')); - $this->myLogger->logme('error','SI_Enhancement Import file name : {data}', ['data'=> $filename ]); - $random_number_count = 4; - $batch_code = generate_random_string($random_number_count); - $this->myLogger->logme('error','SI_Enhancement Import BATCH CODE : {data}', ['data'=> $batch_code ]); - - - $batch_data['batch_code'] = $batch_code; - $batch_data['created_by'] = get_session_userid(); - $batch_data['file_name'] = $filename; - $insert = $this->batchFileModel->insert($batch_data); - $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); - - $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_code_for_batch_list['created_by'] = get_session_userid(); - - $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; - - if(!file_exists($file_name_with_path)) - { + }else if($return == 2){ session()->setFlashdata('error', 'File not found'); return redirect()->to(base_url('employee/upload')); + + }else if($return == 0){ + session()->setFlashdata('error', 'Something went wrong'); + return redirect()->to(base_url('employee/upload')); } - $data = read_excel_file_to_array($file_name_with_path); - unset($data[0]); - $count = count($data); - $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); - // dd($data); - foreach ($data as $key => $value) { - - if (!empty($value) && isset($value[19])) { - - $emp_name = $value[1]; - $emp_code = $value[2]; - // echo $emp_name .'-'. $emp_code; die; - $endorsement_id = $value[19] != null ? $value[19] : ''; - - $val = $this->employeePolicyModel - ->select('employee_polices.id') - ->join('employees', 'employees.id = employee_polices.employee_id') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employees.client_id', $client_id) - ->where('employees.name', $emp_name) - ->where('employees.emp_code', $emp_code) - ->where('employee_polices.is_active', 1) - ->first(); - $batch_code_for_batch_list['emp_policy_id'] = $val['id']; - $this->batchListModel->insert($batch_code_for_batch_list); - - - $this->employeePolicyModel->updateEndoresmentIdForSIEnhancement($emp_code, $client_id, $client_policy_id, $emp_name, $endorsement_id); - - $queryData = $this->employeePolicyModel - ->select('employee_polices.*') - ->join('employees', 'employee_polices.employee_id = employees.id') - ->where('employees.emp_code', $emp_code) - ->where('employees.name', $emp_name) - ->where('employees.client_id', $client_id) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employee_polices.is_active', 1) - ->first(); - - $queryData['is_active'] = 0; - $this->employeePolicyModel->save($queryData); - - unset($queryData['id']); - unset($queryData['created_by']); - unset($queryData['created_at']); - unset($queryData['updated_by']); - unset($queryData['updated_at']); - unset($queryData['is_active']); - - $queryData['basic_cover_si'] = $value[8]; - $queryData['premium'] = $value[14]; - $queryData['si_enhancement_date'] = $value[10]; - $queryData['rata_premimum'] = $value[16]; - $queryData['gst'] = $value[17]; - $queryData['created_by'] = get_session_userid(); - - //new insert - $this->employeePolicyModel->save($queryData); - - - // $query = $this->employeePolicyModel->getLastQuery(); - // echo $query . "
"; - }else{ - session()->setFlashdata('error', 'Something went wrong'); - return redirect()->to(base_url('employee/upload')); - } - - } - - session()->setFlashdata('success', 'Data updated successfully'); - return redirect()->to(base_url('employee/upload')); - }else if($event_type == 'deletion'){ - $file = $this->request->getFile('import_file_data'); - $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); - $filename = $file->getName(); + $return = $empDataServiceController->importExcelDataForDeletion($batch_data); + if($return == 1){ + session()->setFlashdata('success', 'Data updated successfully'); + return redirect()->to(base_url('employee/upload')); - $this->myLogger->logme('error','Deletion Import file name : {data}', ['data'=> $filename ]); - $random_number_count = 4; - $batch_code = generate_random_string($random_number_count); - $this->myLogger->logme('error','Deletion Import BATCH CODE : {data}', ['data'=> $batch_code ]); - - - $batch_data['batch_code'] = $batch_code; - $batch_data['created_by'] = get_session_userid(); - $batch_data['file_name'] = $filename; - $insert = $this->batchFileModel->insert($batch_data); - $batch_file_batch_code = $this->batchFileModel->where('id', $insert)->first(); - - $batch_code_for_batch_list['batch_code'] = $batch_file_batch_code['batch_code']; - $batch_code_for_batch_list['created_by'] = get_session_userid(); - - $file_name_with_path = WRITEPATH."/uploads/import_excel/".$batch_file_batch_code['file_name']; - - if(!file_exists($file_name_with_path)) - { + }else if($return == 2){ session()->setFlashdata('error', 'File not found'); return redirect()->to(base_url('employee/upload')); + + }else if($return == 0){ + session()->setFlashdata('error', 'Something went wrong'); + return redirect()->to(base_url('employee/upload')); } - $data = read_excel_file_to_array($file_name_with_path); - unset($data[0]); - array_pop($data); - - $count = count($data); - $this->batchFileModel->where('id', $insert)->set('count', $count)->update(); - - foreach ($data as $key => $value) { - - if (!empty($value) && isset($value[15])) { - - $emp_name = $value[2]; //employee name - $emp_code = $value[1]; //employee code - $date_of_exit = $value[7]; // date of releving - - // echo $emp_name .'-'. $emp_code .'-'. $date_of_exit; die; - $endorsement_id = $value[15] != null ? $value[15] : ''; //endorsement id - - $val = $this->employeePolicyModel - ->select('employee_polices.id') - ->join('employees', 'employees.id = employee_polices.employee_id') - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employees.client_id', $client_id) - ->where('employees.name', $emp_name) - ->where('employees.emp_code', $emp_code) - ->where('employee_polices.is_active', 1) - ->first(); - $batch_code_for_batch_list['emp_policy_id'] = $val['id']; - $this->batchListModel->insert($batch_code_for_batch_list); - - $this->employeePolicyModel->updateEndoresmentIdForDeletion($emp_code, $client_id, $client_policy_id, $emp_name, $endorsement_id); - - $deletionDataForEmployee = $this->empEndorsementModel - ->select('emp_endorsement.new_value, employees.id') - ->join('employees', 'emp_endorsement.emp_code = employees.emp_code') - ->join('employee_polices', 'employee_polices.employee_id = employees.id') - ->where('emp_endorsement.emp_code', $emp_code) - ->where('employees.client_id', $client_id) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('emp_endorsement.name', $emp_name) - ->where('emp_endorsement.field_name', 'emp_status') - ->first(); - - $deletionDataForEmployee['updated_by'] = get_session_userid(); - $this->employeeModel->save($deletionDataForEmployee); - - - $deletionDataForEmployeePolicy = $this->employeePolicyModel->fetchEmpEndorsementData($emp_code, $client_policy_id, $emp_name); - $deletionDataForEmployeePolicy['updated_by'] = get_session_userid(); - $this->employeePolicyModel->save($deletionDataForEmployeePolicy); - - // echo '
';
-                        // print_r($deletionDataForEmployeePolicy); die;
-                        
-                        $this->employeePolicyModel->save($deletionDataForEmployeePolicy);
-                        
-                        // $query = $this->employeePolicyModel->getLastQuery();
-                        // echo $query . "
"; - }else{ - session()->setFlashdata('error', 'Something went wrong'); - return redirect()->to(base_url('employee/upload')); - } - - } - - session()->setFlashdata('success', 'Data updated successfully'); - return redirect()->to(base_url('employee/upload')); - } } diff --git a/app/Controllers/EmployeeModel.php b/app/Controllers/EmployeeModel.php deleted file mode 100644 index 52382dc1..00000000 --- a/app/Controllers/EmployeeModel.php +++ /dev/null @@ -1,57 +0,0 @@ -db->table('employee_polices') - ->select(' policies.name as Policy_Name , client_policy.policy_terms as Policy_Terms, client_policy.client_id as ClientId, client_policy.policy_id as PolicyId,client_policy.id as ClientPolicyId, client_policy.open_for_enrollment as OpenForEnrollment') // Select all columns from both tables - ->join('client_policy', 'client_policy.id = employee_polices.client_policy_id') - ->join('policies', 'policies.id = client_policy.policy_id') - ->where('employee_polices.employee_id', $id) - ->get() - ->getResult(); - } - - - - - // for EMP rest API process do not change - public function checkExistingEmpEntrollment($arr) - { - return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->first(); - } - -} diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 1f26e4b9..33222923 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -17,6 +17,7 @@ use App\Models\PolicesModel; use App\Models\RelationshipModel; use App\Models\FileModel; use App\Models\ClientPolicyModel; +use App\Models\PolicyPremium1Model; use App\Models\PolicyPremium2Model; use App\Controllers\Jobs ; @@ -44,6 +45,7 @@ class EmployeeRestController extends AdminController protected $policesModel; protected $relationshipModel; protected $clientPolicyModel; + protected $policyPremium1Model; protected $policyPremium2Model; public function __construct() @@ -58,6 +60,7 @@ class EmployeeRestController extends AdminController $this->relationshipModel = new RelationshipModel(); $this->fileModel= new FileModel(); $this->clientPolicyModel = new ClientPolicyModel(); + $this->policyPremium1Model = new PolicyPremium1Model(); $this->policyPremium2Model = new PolicyPremium2Model(); } @@ -139,6 +142,7 @@ class EmployeeRestController extends AdminController $data = $this->request->getJSON(); if ($data) { $updatedCount = 0; + foreach ($data as $item) { $id = $item->id; $item->dob = $this->convertDateFormat($item->dob); @@ -156,8 +160,8 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => $result], 404); } } - } catch (\Throwable $th) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $th], 500); + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e], 500); } } @@ -237,6 +241,7 @@ class EmployeeRestController extends AdminController public function deleteDependence() { try { + print_r($this->rquest);die; if($this->request->getGet('id')) { $delete = $this->employeeModel->where('id', $this->request->getGet('id'))->delete(); @@ -489,273 +494,281 @@ class EmployeeRestController extends AdminController // Upload the Employee Detail in DB by Sheet Data public function employeeUpload() { - $file = $this->request->getFile('file'); - $client_id = $this->request->getPost('client_id'); - $policy_id = $this->request->getPost('policy_id'); + try { + $file = $this->request->getFile('file'); + $client_id = $this->request->getPost('client_id'); + // $client_id = $this->request->getJSON('client_id'); + $policy_id = $this->request->getPost('policy_id'); + // $policy_id = $this->request->getJSON('policy_id'); - $client_policy = $this->clientPolicyModel->where('id', $policy_id)->first(); - $policy = $this->policesModel->where('id', $client_policy['policy_id'])->first(); + $client_policy = $this->clientPolicyModel->where('id', $policy_id)->where('client_id', $client_id)->first(); - $policy_permium = $this->policyPremium2Model->where(['client_id' => $client_id , 'client_policy_id' => $policy_id,'is_active' =>1])-> first(); + if ($client_policy) { + $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']; - $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); - $filename = $file->getName(); - $file_name_with_path = WRITEPATH."/uploads/import_excel/".$filename; + $is_moved = $file->move(WRITEPATH . 'uploads/import_excel'); + $filename = $file->getName(); + $file_name_with_path = WRITEPATH."/uploads/import_excel/".$filename; - //check the file exist or not - if(!file_exists($file_name_with_path)) - { - session()->setFlashdata('error', 'File not found'); - return redirect()->to(base_url('employee/upload')); - } - // Load the Excel file - $spreadsheet = IOFactory::load($file_name_with_path); - - // Get the active sheet - $sheet = $spreadsheet->getActiveSheet(); - - // Get the highest row and column numbers - $highestRow = $sheet->getHighestRow(); - $highestColumn = $sheet->getHighestColumn(); - - $highestRowAndColumn = $sheet->getHighestRowAndColumn(); - $data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); - // print_r($excel_data);die(); - // $data = []; - // $data[] =$excel_data; - - // print_r($data);die; - // Iterate through each row - // for ($row = 1; $row <= $highestRow; $row++) { - // // Initialize the row data array - // $rowData = []; - - // // Iterate through each column in the row - // for ($col = 'A'; $col <= $highestColumn; $col++) { - // // Get the cell value - // $value = $sheet->getCell($col . $row)->getValue(); - // // print_r($value); - // // Add the cell value to the row data array - // $rowData[] = $value; - // } - - // // Add the row data to the main data array - // $data[] = $rowData; - // } - // print_r($data);die; - - $extractData['file_name']= $filename; - $extractData['client_id']= $client_id; - $extractData['status']= 'success'; - $extractData['policy_id']= $policy_id; - $extractData['action']= 'enrollment'; - // $extractData['created_by']=set_session_context('Employee'); - - $file_data =$this->fileModel->insert($extractData); - - $extra = []; - //this change the column name into index number - for ($i = 0; $i < count($data[0]); $i++) { - $data[0][$i] = $i; - } - for ($i = 0; $i < count($data); $i++) { - if ($i == 0) { - // Loop through the first row to extract keys - for ($j = 0; $j < count($data[$i]); $j++) { - $extra[$data[$i][$j]] = []; // Initialize keys with empty array + //check the file exist or not + if(!file_exists($file_name_with_path)) + { + session()->setFlashdata('error', 'File not found'); + return redirect()->to(base_url('employee/upload')); } - } else { - // Loop through subsequent rows - for ($j = 0; $j < count($data[$i]); $j++) { - // Append values to corresponding keys in $extra - if (isset($extra[$data[0][$j]])) { - // Make sure the key exists in the $extra array - $extra[$data[0][$j]][] = $data[$i][$j]; + // Load the Excel file + $spreadsheet = IOFactory::load($file_name_with_path); + + // Get the active sheet + $sheet = $spreadsheet->getActiveSheet(); + + // Get the highest row and column numbers + $highestRow = $sheet->getHighestRow(); + $highestColumn = $sheet->getHighestColumn(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + $data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + + $extractData['file_name']= $filename; + $extractData['client_id']= $client_id; + $extractData['status']= 'success'; + $extractData['policy_id']= $policy_id; + $extractData['action']= 'enrollment'; + // $extractData['created_by']=set_session_context('Employee'); + + $file_data =$this->fileModel->insert($extractData); + + $extra = []; + if (count($data[0]) == 10) { + $value = ['S.No','Emp Code','Name','DOJ','Gender','Relation','DOB','Mail','Mobile','SI']; + $check_miss_match = []; + for ($i=0; $i 0) { + return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Column Name's are miss Match's!", 'data'=> $check_miss_match], 404); } } - } - } - $dataToInsert = []; - $basic_cover_si= []; - foreach ($extra['0'] as $index => $id) { - $relation =''; - if ($extra['5'][$index] === 'Mother' || $extra['5'][$index] === 'Father') { - $relation = 'parent'; - } else if($extra['5'][$index] === 'Son' || $extra['5'][$index] === 'Daughter'){ - $relation = 'child'; - }else if($extra['5'][$index] === 'Father in Law' || $extra['5'][$index] === 'Mother in Law'){ - $relation = 'parent_in_law'; - }else if($extra['5'][$index] === 'Spouse'){ - $relation = 'spouse'; - }else{ - $relation = 'self'; - } - - // Simplified formatDate function + if(count($data[0]) != 10){ + return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Uploaded file row count is Not Match!" ], 404); + } - // Assigning formatted dates - // print_r($extra['3']);die; - $doj = $extra['3'][$index] ; - $dob = $extra['6'][$index] ; - - - // Change date format for $doj - $doj_new_format = date('Y-m-d', strtotime($doj)); // $doj_new_format will be "2001-02-12" - - // Change date format for $dob - $dob_new_format = date('Y-m-d', strtotime($dob)); - - // Your existing code here - - $emp_code =isset($extra['1'][$index]) ? $extra['1'][$index] : 0; - $name = $extra['2'][$index]; - - // print_r("--" . $emp_code. "---"); - // print_r( $emp_code != 0 ); - if($emp_code != 0 && $name != '' || $name != null){ - $record = [ - // 'id' => $id, - 'emp_code' => $emp_code, - 'name' => $name, - // Check if the 'doj' key exists before accessing it - 'doj' => $doj_new_format, - 'gender' => $extra['4'][$index], - 'relationship' => ucfirst($extra['5'][$index]), - 'family_floater_key' => $relation, - 'dob' => $dob_new_format, - 'email_corporate' => $extra['7'][$index], - 'mobile'=> $extra['8'][$index], - 'client_id' => $client_id, - 'emp_status'=>'draft' - - ]; - - $basic_cover_si_value = null; - - //Grid id is 10 and 11 sum insure value add only for self other grid type self sum insure is for the dependence - // if ($policy['policy_type_id'] != 1) { - if ($policy_permium['policy_grid_id'] == 10 || $policy_permium['policy_grid_id'] == 11) { - if (strtolower($extra['5'][$index]) == 'self') { - $basic_cover_si_value = $extra['9'][$index]; - }else{ - $basic_cover_si_value = null; + //this change the column name into index number + for ($i = 0; $i < count($data[0]); $i++) { + $data[0][$i] = $i; + } + for ($i = 0; $i < count($data); $i++) { + if ($i == 0) { + // Loop through the first row to extract keys + for ($j = 0; $j < count($data[$i]); $j++) { + $extra[$data[$i][$j]] = []; // Initialize keys with empty array } + } else { + // Loop through subsequent rows + for ($j = 0; $j < count($data[$i]); $j++) { + // Append values to corresponding keys in $extra + if (isset($extra[$data[0][$j]])) { + // Make sure the key exists in the $extra array + $extra[$data[0][$j]][] = $data[$i][$j]; + } + } + } + } + $dataToInsert = []; + $basic_cover_si= []; + if ($extra[9]) { + $new_array = []; + for ($i=0; $i < count($extra[9]); $i++) { + if ($sum_insured_amount_for_check_employee_2 != $extra[9][$i] || $sum_insured_amount_for_check_employee_1 != $extra[9][$i]) { + $new_array[] = $i+1; + } + } + if (count($new_array) > 0) { + $count =count($new_array); + return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "$count Employee Sum Insured is Not Match.. " , 'data' => $new_array], 404); + } + } + foreach ($extra['0'] as $index => $id) { + $relation =''; + if ($extra['5'][$index] === 'Mother' || $extra['5'][$index] === 'Father') { + $relation = 'parent'; + } else if($extra['5'][$index] === 'Son' || $extra['5'][$index] === 'Daughter'){ + $relation = 'child'; + }else if($extra['5'][$index] === 'Father in Law' || $extra['5'][$index] === 'Mother in Law'){ + $relation = 'parent_in_law'; + }else if($extra['5'][$index] === 'Spouse'){ + $relation = 'spouse'; }else{ - if (strtolower($extra['5'][$index]) == 'self') { - $basic_cover_si_value = $extra['9'][$index]; - }else{ - for ($i=0; $i < count($extra['1']) ; $i++) { - - if ($extra['1'][$i] == $extra['1'][$index]) { - if (strtolower($extra['5'][$i]) == 'self') { - $basic_cover_si_value = $extra['9'][$i]; + $relation = 'self'; + } + // Simplified formatDate function + + // Assigning formatted dates + $doj = $extra['3'][$index] ; + $dob = $extra['6'][$index] ; + + // Change date format for $doj + $doj_new_format = date('Y-m-d', strtotime($doj)); // $doj_new_format will be "2001-02-12" + + // Change date format for $dob + $dob_new_format = date('Y-m-d', strtotime($dob)); + + // Your existing code here + $emp_code =isset($extra['1'][$index]) ? $extra['1'][$index] : 0; + $name = $extra['2'][$index]; + + if($emp_code != 0 && $name != '' || $name != null){ + $record = [ + // 'id' => $id, + 'emp_code' => $emp_code, + 'name' => $name, + // Check if the 'doj' key exists before accessing it + 'doj' => $doj_new_format, + 'gender' => $extra['4'][$index], + 'relationship' => ucfirst($extra['5'][$index]), + 'family_floater_key' => $relation, + 'dob' => $dob_new_format, + 'email_corporate' => $extra['7'][$index], + 'mobile'=> $extra['8'][$index], + 'client_id' => $client_id, + 'emp_status'=>'draft' + + ]; + $basic_cover_si_value = null; + + //Grid id is 10 and 11 sum insure value add only for self other grid type self sum insure is for the dependence + if ($policy_permium_2['policy_grid_id'] == 10 || $policy_permium_2['policy_grid_id'] == 11) { + if (strtolower($extra['5'][$index]) == 'self') { + $basic_cover_si_value = $extra['9'][$index]; + }else{ + $basic_cover_si_value = null; + } + }else{ + if (strtolower($extra['5'][$index]) == 'self') { + $basic_cover_si_value = $extra['9'][$index]; + }else{ + for ($i=0; $i < count($extra['1']) ; $i++) { + + if ($extra['1'][$i] == $extra['1'][$index]) { + if (strtolower($extra['5'][$i]) == 'self') { + $basic_cover_si_value = $extra['9'][$i]; + } + } } } } - } - } - // } - - $record2 = [ - 'basic_cover_si' => $basic_cover_si_value, - ]; - // print_r($basic_cover_si);die; - $dataToInsert[] = $record; - $basic_cover_si[]= $basic_cover_si_value; - } - } - for ($a=0; $a employeeModel->checkExistingEmployee($dataToInsert[$a]); - $emp_id =0; - - $data_after_gpa_or_gmc =[]; - // print_r($policy);die; - if ($policy['policy_type_id'] == 1) { - if (strtolower($dataToInsert[$a]['relationship']) == 'self') { - $data_after_gpa_or_gmc = $dataToInsert[$a]; - } - }else{ - $data_after_gpa_or_gmc = $dataToInsert[$a]; - } - - - date_default_timezone_set('Asia/Kolkata'); - $current_timestamp = time(); - $formatted_date_time = date('Y-m-d H:i:s', $current_timestamp); - - if ($employee) { - - $emp_id =$employee['id']; - $id =$emp_id; - $data_after_gpa_or_gmc['id'] = $id; - $data_after_gpa_or_gmc['updated_at'] = $formatted_date_time; - $result = $this->employeeModel->save($data_after_gpa_or_gmc); - if ($result) { - $log_message = 'Update Employee - '.$employee['name'].'('.$employee['emp_code'].') with PK '.$employee['id']; - $this->myLogger->logme('error',('Update - ' . $employee['id'].' - '. $employee['emp_code'] .' - '.$employee['name'])); - } - }else{ - if ($dataToInsert[$a]['emp_code'] != 0) { - $result =false; - if (count($data_after_gpa_or_gmc) != 0) { - $result = $this->employeeModel->insert($data_after_gpa_or_gmc); - } - $emp_id =$result; - if ($result) { - $emp = $this->employeeModel->where('id', $result)->get()->getResult(); - - $policy_name = $this->employeePolicyModel->where('employee_id', $result)->get()->getResult();; - - - $log_message = 'Insert Employee- '.$dataToInsert[$a]['name'] .'('.$dataToInsert[$a]['emp_code'] .') with PK '; - $this->myLogger->logme('error',('Insert - ' . $dataToInsert[$a]['emp_code'] .' - '. $dataToInsert[$a]['name'])); - } - } + $record2 = [ + 'basic_cover_si' => $basic_cover_si_value, + ]; + $dataToInsert[] = $record; + $basic_cover_si[]= $basic_cover_si_value; } - $emp_policy_data =[ - 'employee_id'=>$emp_id, - 'client_policy_id'=>$policy_id, - 'status'=> 'draft', - 'basic_cover_si'=>isset($basic_cover_si[$a]) ? $basic_cover_si[$a] : null - ]; + } + for ($a=0; $a employeeModel->checkExistingEmployee($dataToInsert[$a]); + $emp_id =0; + + $data_after_gpa_or_gmc =[]; + if ($policy['policy_type_id'] == 1) { + if (strtolower($dataToInsert[$a]['relationship']) == 'self') { + $data_after_gpa_or_gmc = $dataToInsert[$a]; + } + }else{ + $data_after_gpa_or_gmc = $dataToInsert[$a]; + } + date_default_timezone_set('Asia/Kolkata'); + $current_timestamp = time(); + $formatted_date_time = date('Y-m-d H:i:s', $current_timestamp); - $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $policy_id]); - if ($employee_policy) { - foreach ($employee_policy as $existing_policy) { - $emp_policy_data['id']= $existing_policy['id']; - $emp_policy_data['updated_at'] = $formatted_date_time; - $this->employeePolicyModel->save($emp_policy_data); - } - } else { - $emp_policy = $this->employeePolicyModel->insert($emp_policy_data); - } + if ($employee) { + + + $emp_id =$employee['id']; + $id =$emp_id; + $data_after_gpa_or_gmc['id'] = $id; + $data_after_gpa_or_gmc['updated_at'] = $formatted_date_time; + $result = $this->employeeModel->save($data_after_gpa_or_gmc); + if ($result) { + $log_message = 'Update Employee - '.$employee['name'].'('.$employee['emp_code'].') with PK '.$employee['id']; + $this->myLogger->logme('error',('Update - ' . $employee['id'].' - '. $employee['emp_code'] .' - '.$employee['name'])); + } + }else{ + if ($dataToInsert[$a]['emp_code'] != 0) { + $result =false; + if (count($data_after_gpa_or_gmc) != 0) { + $result = $this->employeeModel->insert($data_after_gpa_or_gmc); + } + $emp_id =$result; + if ($result) { + $emp = $this->employeeModel->where('id', $result)->get()->getResult(); + + $policy_name = $this->employeePolicyModel->where('employee_id', $result)->get()->getResult();; + + + $log_message = 'Insert Employee- '.$dataToInsert[$a]['name'] .'('.$dataToInsert[$a]['emp_code'] .') with PK '; + $this->myLogger->logme('error',('Insert - ' . $dataToInsert[$a]['emp_code'] .' - '. $dataToInsert[$a]['name'])); + } + } + } + $emp_policy_data =[ + 'employee_id'=>$emp_id, + 'client_policy_id'=>$policy_id, + 'status'=> 'draft', + 'basic_cover_si'=>isset($basic_cover_si[$a]) ? $basic_cover_si[$a] : null + ]; + + $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $policy_id]); + if ($employee_policy) { + foreach ($employee_policy as $existing_policy) { + $emp_policy_data['id']= $existing_policy['id']; + $emp_policy_data['updated_at'] = $formatted_date_time; + $this->employeePolicyModel->save($emp_policy_data); + } + } else { + $emp_policy = $this->employeePolicyModel->insert($emp_policy_data); + } - //trigger - // print_r($dataToInsert[$a]['email_personal']);die; - - $mail = $dataToInsert[$a]['email_corporate']; - $subject = 'Welcome, Employee Benefit Program Enrolment'; - // $message = 'Dear ' . $dataToInsert[$a]['name'] . ",
We are glad to welcome you to the employee benefit program ," .$policy_name['name'] ."offered by your employer,


Click on the link below to review your personal and family details:
Review Details" ; - $data['employee_name']=$dataToInsert[$a]['name']; - $data['policy_name']=$policy['name']; - - $message = view('mail_welcome', $data); - // if ($dataToInsert[$a]['email_corporate'] != null || $dataToInsert[$a]['email_corporate'] != '' && $dataToInsert[$a]['relationship'] == 'Self') { - // $job_details = new Jobs(); - // $r = Jobs::addJob(['job_name' => 'send_email','payload' => ['mail' => $mail, 'subject' => $subject,'message'=> $message]]); - // } - - // print_r($r);//die(); - // $jobWorker = new JobWorker(); - //JobWorker::processJob($r); - // $return_log = MailHelper::send_email($mail,$subject, $message); - // $return_log = json_decode($return_log); - // $this->myLogger->logme('info', "Email Status : {mail_status}, Sender Email:{email}", ['mail_status' => $return_log->status, 'email'=> $return_log->data]); + //trigger + $mail = $dataToInsert[$a]['email_corporate']; + $subject = 'Welcome, Employee Benefit Program Enrolment'; + // $message = 'Dear ' . $dataToInsert[$a]['name'] . ",
We are glad to welcome you to the employee benefit program ," .$policy_name['name'] ."offered by your employer,


Click on the link below to review your personal and family details:
Review Details" ; + $data['employee_name']=$dataToInsert[$a]['name']; + $data['policy_name']=$policy['name']; + + $message = view('mail_welcome', $data); + // if ($dataToInsert[$a]['email_corporate'] != null || $dataToInsert[$a]['email_corporate'] != '' && $dataToInsert[$a]['relationship'] == 'Self') { + // $job_details = new Jobs(); + // $r = Jobs::addJob(['job_name' => 'send_email','payload' => ['mail' => $mail, 'subject' => $subject,'message'=> $message]]); + // } + + // print_r($r);//die(); + // $jobWorker = new JobWorker(); + //JobWorker::processJob($r); + // $return_log = MailHelper::send_email($mail,$subject, $message); + // $return_log = json_decode($return_log); + // $this->myLogger->logme('info', "Email Status : {mail_status}, Sender Email:{email}", ['mail_status' => $return_log->status, 'email'=> $return_log->data]); + } + }else{ + return $this->respond(['status' => 'failed', 'code' => 404, 'message' => "Client id and Client Policy id is Not Match!" ], 404); + } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); } + + + + } diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index ccf52ee4..ed5c0a4b 100644 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -12,11 +12,14 @@ use App\Models\EmployeeModel; use App\Models\EmployeePolicyModel; use App\Models\ClientModel; use App\Models\ClientPolicyModel; +use App\Models\PolicesModel; use App\Models\FileModel; +use App\Models\EmpEndorsementModel; use App\Controllers\Jobs ; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use Kint\Kint; class EmployeeServiceController extends AdminController { @@ -27,9 +30,18 @@ class EmployeeServiceController extends AdminController protected $clientModel; protected $fileModel; protected $clientPolicyModel; + protected $policiesModel; + protected $empEndorsementModel; protected $general_relationships = ['self' => ['name' => 'Self', 'gender' => 'M','age_min' => 18,'age_max' => null], 'spouse' => ['name' => 'Spouse', 'gender' => 'F','age_min' => 18,'age_max' => null], 'son' => ['name' => 'Son', 'gender' => 'M','age_min' => null,'age_max' => 25], 'daughter' => ['name' => 'Daughter', 'gender' => 'F','age_min' => null,'age_max' => 25], 'father' => ['name' => 'Father', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother' => ['name' => 'Mother', 'gender' => 'F','age_min' => 18,'age_max' => null], 'father-in-law' => ['name' => 'Father in Law', 'gender' => 'M','age_min' => 18,'age_max' => null], 'mother-in-law' => ['name' => 'Mother in Law', 'gender' => 'F','age_min' => 18,'age_max' => null]]; - protected $inception_excel_columns = ['sno' => ['col_idx' => 0,'col_cell_name' => 'A','col_name' => 'S.No','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'emp_id' => ['col_idx' => 1,'col_cell_name' => 'B','col_name' => 'EMP ID','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'name_of_emp_dep' => ['col_idx' => 2,'col_cell_name' => 'C','col_name' => 'NAME OF EMP/DEP','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => null],'dob' => ['col_idx' => 3,'col_cell_name' => 'D','col_name' => 'DOB','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => 'd-M-Y','allowed_values' => null,'custom' => 'check_dob_diff','params' => ['row','relationship']],'gender' => ['col_idx' => 4,'col_cell_name' => 'E','col_name' => 'Gender','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => null,'allowed_values' => ['M','F']],'relationship' => ['col_idx' => 5,'col_cell_name' => 'F','col_name' => 'RELATIONSHIP','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_relationship','params' => ['row','relationship']],'basic_cover_si' => ['col_idx' => 6,'col_cell_name' => 'G','col_name' => 'BASIC COVER SI','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => null,'allowed_values' => null],'doj' => ['col_idx' => 7,'col_cell_name' => 'H','col_name' => 'DOJ','is_mandatory' => false,'data_type' => 'str','format' => 'd-M-Y','allowed_values' => null,'custom' => 'check_doj','params' => ['row']],'basic_pay' => ['col_idx' => 8,'col_cell_name' => 'I','col_name' => 'Basic Pay','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_basic_pay','params' => ['row']],'band_grade' => ['col_idx' => 9,'col_cell_name' => 'J','col_name' => 'Band/Grade','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null,'custom' => 'check_employee_band','params' => ['row']],'designation' => ['col_idx' => 10,'col_cell_name' => 'K','col_name' => 'Designation','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'phone' => ['col_idx' => 11,'col_cell_name' => 'L','col_name' => 'Phone','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'email' => ['col_idx' => 12,'col_cell_name' => 'M','col_name' => 'Email','is_mandatory' => false,'data_type' => 'str','format' => null,'allowed_values' => null],'pre_existing_ailments' => ['col_idx' => 13,'col_cell_name' => 'N','col_name' => 'PRE EXISTING AILMENTS','is_mandatory' => ['I','A','DA'],'data_type' => 'str','format' => null,'allowed_values' => ['0','1']],'change_event' => ['col_idx' => 14,'col_cell_name' => 'O','col_name' => 'Change event','is_mandatory' => ['A','DA','D'],'data_type' => 'str','format' => null,'allowed_values' => null],'date_of_exit' => ['col_idx' => 15,'col_cell_name' => 'P','col_name' => 'Date of exit','is_mandatory' => ['D'],'data_type' => 'str','format' => 'd-M-Y','allowed_values' => null],'reason_for_exit' => ['col_idx' => 16,'col_cell_name' => 'Q','col_name' => 'Reason for exit','is_mandatory' => ['D'],'data_type' => 'str','format' => null,'allowed_values' => null],'action' => ['col_idx' => 17,'col_cell_name' => 'R','col_name' => 'Action','is_mandatory' => true,'data_type' => 'str','format' => null,'allowed_values' => ['I','A','D','DA'] ]]; + protected $inception_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'dob'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'DOB','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_dob_diff','params'=>['row','relationship']],'gender'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Gender','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['M','F']],'relationship'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'RELATIONSHIP','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_relationship','params'=>['row','relationship']],'basic_cover_si'=>['col_idx'=>6,'col_cell_name'=>'G','col_name'=>'BASIC COVER SI','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_si','params' => ['row','policy_terms','slab_details']],'doc'=>['col_idx'=>7,'col_cell_name'=>'H','col_name'=>'Date of Coverage','is_mandatory'=>['A','DA'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'params'=>['row']],'doj'=>['col_idx'=>8,'col_cell_name'=>'I','col_name'=>'DOJ','is_mandatory'=>false,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null,'custom'=>'check_doj','params'=>['row']],'basic_pay'=>['col_idx'=>9,'col_cell_name'=>'J','col_name'=>'Basic Pay','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_basic_pay','params'=>['row','policy_terms','slab_details']],'band_grade'=>['col_idx'=>10,'col_cell_name'=>'K','col_name'=>'Band/Grade','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom'=>'check_employee_band','params'=>['row','policy_terms','slab_details']],'designation'=>['col_idx'=>11,'col_cell_name'=>'L','col_name'=>'Designation','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'phone'=>['col_idx'=>12,'col_cell_name'=>'M','col_name'=>'Phone','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'email'=>['col_idx'=>13,'col_cell_name'=>'N','col_name'=>'Email','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null],'pre_existing_ailments'=>['col_idx'=>14,'col_cell_name'=>'O','col_name'=>'PRE EXISTING AILMENTS','is_mandatory'=>['I','A','DA'],'data_type'=>'str','format'=>null,'allowed_values'=>['0','1']],'change_event'=>['col_idx'=>15,'col_cell_name'=>'P','col_name'=>'Change event','is_mandatory'=>['A','DA','D'],'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_exit'=>['col_idx'=>16,'col_cell_name'=>'Q','col_name'=>'Date of exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'reason_for_exit'=>['col_idx'=>17,'col_cell_name'=>'R','col_name'=>'Reason for exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; + + protected $deletion_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'change_event'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'Change event','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_exit'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Date of exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'reason_for_exit'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'Reason for exit','is_mandatory'=>['D'],'data_type'=>'str','format'=>null,'allowed_values'=>null]]; + + protected $correction_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'field'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'Field','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>['name','dob','relationship']],'value'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Value','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'date_of_correction'=>['col_idx'=>5,'col_cell_name'=>'F','col_name'=>'Date of Correction','is_mandatory'=>true,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null],'change_event'=>['col_idx'=>6,'col_cell_name'=>'G','col_name'=>'Change event','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'remarks'=>['col_idx'=>7,'col_cell_name'=>'H','col_name'=>'Remarks','is_mandatory'=>false,'data_type'=>'str','format'=>null,'allowed_values'=>null]]; + + protected $si_enhance_excel_columns = ['sno'=>['col_idx'=>0,'col_cell_name'=>'A','col_name'=>'S.No','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'emp_id'=>['col_idx'=>1,'col_cell_name'=>'B','col_name'=>'EMP ID','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'name_of_emp_dep'=>['col_idx'=>2,'col_cell_name'=>'C','col_name'=>'NAME OF EMP/DEP','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null],'augmented_si'=>['col_idx'=>3,'col_cell_name'=>'D','col_name'=>'Augmented SI','is_mandatory'=>true,'data_type'=>'str','format'=>null,'allowed_values'=>null,'custom' => 'check_si','params' => ['row','policy_terms','slab_details']],'date_of_enhancement'=>['col_idx'=>4,'col_cell_name'=>'E','col_name'=>'Date of SI Enhancement','is_mandatory'=>true,'data_type'=>'str','format'=>'d-M-Y','allowed_values'=>null]]; + public function __construct() { // helper('utility'); @@ -40,6 +52,8 @@ class EmployeeServiceController extends AdminController $this->clientModel = new ClientModel(); $this->fileModel = new FileModel(); $this->clientPolicyModel = new ClientPolicyModel(); + $this->policiesModel = new PolicesModel(); + $this->empEndorsementModel = new EmpEndorsementModel(); } public function excelFileFormatValidation($params) @@ -74,28 +88,21 @@ class EmployeeServiceController extends AdminController $sheet = $spreadsheet->getActiveSheet(); $highestRowAndColumn = $sheet->getHighestRowAndColumn(); - // $highestRow = $sheet->getHighestDataRow(); // 1048576, should be 2 - // $highestColumn = $sheet->getHighestDataColumn(); // L, should be B - // print_r($highestRowAndColumn); - // echo $highestRow;echo ' - ' . $highestColumn; + $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); - // $data = array_filter($data); - // echo '
'; 
-        // dd($excel_data);
-        // echo "
";die(); - // foreach ($excel_data as $key => $value) - // { - - // } - - + // dd($this->si_enhance_excel_columns); $columns_to_check = []; if($file['action'] == 'inception'){ $columns_to_check = $this->inception_excel_columns; } + if($file['action'] == 'addition'){ $columns_to_check = $this->inception_excel_columns; } + if($file['action'] == 'dependent_addition'){ $columns_to_check = $this->inception_excel_columns; } + if($file['action'] == 'deletion'){ $columns_to_check = $this->deletion_excel_columns; } + if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; } + if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; } //check no of columns in excel $total_defined_columns = count($columns_to_check); $excel_columns = ($excel_data[0]); - // var_dump($excel_columns);die(); + // var_dump($total_defined_columns);die(); $excel_columns_count = count($excel_columns); if($total_defined_columns != $excel_columns_count) { @@ -124,7 +131,15 @@ class EmployeeServiceController extends AdminController //start other checks $result = ['error_type' => 1,'error_summary' => [], 'error_data' => [] ]; $keys = array_keys($columns_to_check); - // print_r($keys);die(); + // dd($columns_to_check);die(); + + // get policy and rack details + $policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']); + $policy_terms = (array) $policy_terms[0];// convert obj to array + + //get policy slab rates + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); + // dd($slab_details); //remove header unset($excel_data[0]); @@ -134,7 +149,12 @@ class EmployeeServiceController extends AdminController //define row wise action/event in temporary variable $current_column_action = null; - if($file['action'] == 'inception'){ $current_column_action = $row[17]; } + if($file['action'] == 'inception'){ $current_column_action = 'I'; } + else if($file['action'] == 'addition'){ $current_column_action = 'A'; } + else if($file['action'] == 'dependent_addition'){ $current_column_action = 'DA'; } + else if($file['action'] == 'deletion'){ $current_column_action = 'D'; } + else if($file['action'] == 'correction'){ $current_column_action = 'C'; } + else if($file['action'] == 'si_enhancement'){ $current_column_action = 'SI'; } //1. avoid empty rows if(check_row_is_empty_or_null($row)) { @@ -144,15 +164,15 @@ class EmployeeServiceController extends AdminController foreach ($row as $col_key => $col) { - $is_mandatory = $this->inception_excel_columns[$keys[$col_key]]['is_mandatory']; - $format = $this->inception_excel_columns[$keys[$col_key]]['format']; - $allowed_values = $this->inception_excel_columns[$keys[$col_key]]['allowed_values']; - $custom_function = isset($this->inception_excel_columns[$keys[$col_key]]['custom']) ? $this->inception_excel_columns[$keys[$col_key]]['custom'] : null; - $binding_params = isset($this->inception_excel_columns[$keys[$col_key]]['params']) ? $this->inception_excel_columns[$keys[$col_key]]['params'] : null; - $column_dispaly_name = $this->inception_excel_columns[$keys[$col_key]]['col_name']; - $column_index = $this->inception_excel_columns[$keys[$col_key]]['col_idx']; - $column_cell = $this->inception_excel_columns[$keys[$col_key]]['col_cell_name']; - + $is_mandatory = $columns_to_check[$keys[$col_key]]['is_mandatory']; + $format = $columns_to_check[$keys[$col_key]]['format']; + $allowed_values = $columns_to_check[$keys[$col_key]]['allowed_values']; + $custom_function = isset($columns_to_check[$keys[$col_key]]['custom']) ? $columns_to_check[$keys[$col_key]]['custom'] : null; + $binding_params = isset($columns_to_check[$keys[$col_key]]['params']) ? $columns_to_check[$keys[$col_key]]['params'] : null; + $column_dispaly_name = $columns_to_check[$keys[$col_key]]['col_name']; + $column_index = $columns_to_check[$keys[$col_key]]['col_idx']; + $column_cell = $columns_to_check[$keys[$col_key]]['col_cell_name']; + $row['current_action'] = $current_column_action; //mandatory check if(is_bool($is_mandatory) && $is_mandatory === true) @@ -169,7 +189,7 @@ class EmployeeServiceController extends AdminController //if is_mandatory is array (action based mandatory check) if($current_column_action != null && is_array($is_mandatory) && in_array(strtoupper(trim($current_column_action)),$is_mandatory)) { - $allowed_actions = $this->inception_excel_columns[$keys[$col_key]]['is_mandatory']; + $allowed_actions = $columns_to_check[$keys[$col_key]]['is_mandatory']; if($col == "" || $col == NULL) { array_push($result['error_summary'],1); @@ -196,7 +216,7 @@ class EmployeeServiceController extends AdminController if($is_mandatory === true && isset($allowed_values) && is_array($allowed_values)) { - if(!in_array(trim($col),$allowed_values)) + if(!in_array(strtolower(trim($col)),$allowed_values)) { array_push($result['error_summary'],3); $result['error_data'][$row_key][$keys[$col_key]]['col_name'] = $column_dispaly_name; //push column name @@ -280,11 +300,16 @@ class EmployeeServiceController extends AdminController return array('error_summary' => [5], 'error_data' => $message); } - $columns_to_check = []; + $columns_to_check = []; if($file['action'] == 'inception'){ $columns_to_check = $this->inception_excel_columns; } + if($file['action'] == 'addition'){ $columns_to_check = $this->inception_excel_columns; } + if($file['action'] == 'dependent_addition'){ $columns_to_check = $this->inception_excel_columns; } + if($file['action'] == 'deletion'){ $columns_to_check = $this->deletion_excel_columns; } + if($file['action'] == 'correction'){ $columns_to_check = $this->correction_excel_columns; } + if($file['action'] == 'si_enhancement'){ $columns_to_check = $this->si_enhance_excel_columns; } // get policy and rack details - $policy_terms = $this->clientPolicyModel->getPolicyTermsJson($file['client_id'],$file['policy_id']); + $policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']); // dd($policy_terms); $policy_terms = json_decode($policy_terms[0]->policy_terms); $policy_terms = (array) $policy_terms;// convert obj to array @@ -306,78 +331,567 @@ class EmployeeServiceController extends AdminController $employee_data_group_by_family = data_group_by_family($excel_data); // dd($employee_data_group_by_family); - foreach ($employee_data_group_by_family as $emp_id => $family) - { + foreach ($employee_data_group_by_family as $emp_id => $family) + { - - //check name dup within a family - $res = name_dup_check_within_family($family); - if(count($res)) - { - foreach($res as $k => $rowid) + //if action is DA then get all familiy members,transfrom them into excel array, addd data source as db or excel + if($file['action'] == 'dependent_addition') { - array_push($result['error_summary'],7); // dup entry in excel file - $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Twofold Name found within family"; + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: 'active'); + // dd($existing_famility_details); + //transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites + $existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file); + // dd($existing_famility_details); + $family = array_merge($family,$existing_famility_details); } - } - //check allowed dependent count and relationship conflict within family at policy level - // if($policy_terms['family_floater'] == true) - // { - // dd($policy_terms['family_floaters']); - // } - // die('check'); - $res = check_dependent_conflict($family,$policy_terms); - // dd($res); - if(!$res['status']) - { - foreach($res['error_data'] as $key => $value) + // kint::dump($family);die(); + //check name dup within a family + + if($file['action'] == 'inception' || $file['action'] == 'addition' || $file['action'] == 'dependent_addition') { - array_push($result['error_summary'],$value['code']); //record not avail for deletion - $result['error_data'][$rowid][($value['col_name'])]['error'][] = $value['msg']; + $res = name_dup_check_within_family($family,$file['action']); + // dd($res); + if(count($res)) + { + foreach($res as $k => $rowid) + { + array_push($result['error_summary'],7); // dup entry in excel file + $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Twofold Name found within family"; + } + } + } + + + if($file['action'] == 'dependent_addition' || $file['action'] == 'addition' || $file['action'] == 'inception') + { + $res = check_dependent_conflict($family,$policy_terms,$file['action']); + // dd($res); + if(!$res['status']) + { + foreach($res['error_data'] as $key => $value) + { + array_push($result['error_summary'],$value['code']); + $result['error_data'][ $value['row_id'] ][($value['col_name'])]['error'][] = $value['msg']; + } + } + } + + //check dup with empid and name with db + $res = name_and_empid_check_in_db($family,$file); + // dd($file); + // echo '
'; + // print_r($res); + if(count($res['del'])) + { + foreach($res['del'] as $k => $rowid) + { + array_push($result['error_summary'],10); //record not avail for deletion + $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record Not found "; + } + } + if(count($res['i'])) + { + foreach($res['i'] as $k => $rowid) + { + array_push($result['error_summary'],9); //dup entry + $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record already exists"; + } } } - //check dup with empid and name with db - $res = name_and_empid_check_in_db($family,$file['client_id'],$file['policy_id']); - // print_r($result); - // echo '
'; - // print_r($res); - if(count($res['del'])) - { - foreach($res['del'] as $k => $rowid) - { - array_push($result['error_summary'],10); //record not avail for deletion - $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record Not found for deletion"; - } - } - if(count($res['i'])) - { - foreach($res['i'] as $k => $rowid) - { - array_push($result['error_summary'],9); //dup entry - $result['error_data'][$rowid]['name_of_emp_dep']['error'][] = "Record already exists"; - } - } - } - - // dd($result); - if(isset($result['error_summary']) && count($result['error_summary'])) - { - $result['error_summary'] = array_count_values($result['error_summary']); - $status = 'failed'; - $failure_reason = ((json_encode($result))); - $this->fileModel->where('id', $file_id)->set(['status' => $status,'reason' => $failure_reason])->update(); - $this->myLogger->logme("error",'{file_id} uploaded failed',['file_id' => $file_id]); - //return $this->respond(['dataStatus' => true,'code' => 404,'data' => 'file upload failed with errors'], 200); - // dd($failure_reason); - - - - } - return $result; + // s($result); + // die(); + if(isset($result['error_summary']) && count($result['error_summary'])) + { + $result['error_summary'] = array_count_values($result['error_summary']); + $status = 'failed'; + $failure_reason = ((json_encode($result))); + $this->fileModel->where('id', $file_id)->set(['status' => $status,'reason' => $failure_reason])->update(); + $this->myLogger->logme("error",'{file_id} uploaded failed',['file_id' => $file_id]); + //return $this->respond(['dataStatus' => true,'code' => 404,'data' => 'file upload failed with errors'], 200); + // dd($failure_reason); + } + else if($file['action'] == 'deletion') + { + //proceed next data level validation in JOB queue + $job_details = new Jobs(); + + $r = Jobs::addJob(['job_name' => 'employeeDisembark','payload' => ['file_id' => $file_id]]); + } + else if ($file['action'] == 'si_enhancement') + { + //proceed next data level validation in JOB queue + $job_details = new Jobs(); + + $r = Jobs::addJob(['job_name' => 'employeesSIEnhanceProcess','payload' => ['file_id' => $file_id]]); + } + else if ($file['action'] == 'correction') + { + //proceed next data level validation in JOB queue + $job_details = new Jobs(); + + $r = Jobs::addJob(['job_name' => 'employeesCorrectionProcess','payload' => ['file_id' => $file_id]]); + } + else //inception OR addition OR dependent addition + { + //proceed next data level validation in JOB queue + $job_details = new Jobs(); + + $r = Jobs::addJob(['job_name' => 'employeesOnboardPreprocess','payload' => ['file_id' => $file_id]]); + } + return $result; } + + + // calculate data points and premium + public function employeesOnboardPreprocess($params) + { + helper('excel_util_helper'); + // dd($params); + if(isset($params['file_id']))//handle data from excel to inception + { + //get file name + $file_id = $params['file_id']; + $file = $this->fileModel->find($file_id); + // dd($file); + $return = []; + if(!isset($file)) + { + //file not found in DB + return array('status' => false, 'msg' => 'file not found in DB'); + } + $file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name']; + + //check physical file + if(!file_exists($file_name_with_path)) + { + //file not found update status and reason + $message = "Physical file not found"; + // echo $message; + $this->myLogger->logme('error',($message . ' for file id ' . $file_id)); + $this->fileModel->where('id', $file_id)->set(['status' => 'failed','reason' => json_encode(['error_summary' => array_count_values([5]),'error_data' => $message])])->update(); + return array('error_summary' => [5], 'error_data' => $message); + } + + $columns_to_check = []; + if($file['action'] == 'inception'){ $columns_to_check = $this->inception_excel_columns; } + + // get policy and rack details + $policy_terms = $this->clientPolicyModel->getPolicyDetails($file['client_id'],$file['policy_id']); + $policy_terms = (array) $policy_terms[0];// convert obj to array + // $policy_terms = json_decode($policy_terms[0]->policy_terms); + + // dd($policy_terms); + //get excel data + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + unset($excel_data[0]); + + + //get policy slab rates + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); + // dd($slab_details); + + $employee_data_group_by_family = data_group_by_family($excel_data); + // dd($employee_data_group_by_family); + foreach ($employee_data_group_by_family as $emp_id => $family) + { + + //if action is DA then get all familiy members,transfrom them into excel array, addd data source as db or excel + if($file['action'] == 'dependent_addition') + { + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $emp_id,client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: 'active'); + // dd($existing_famility_details); + //transsform familiy details from db columns to exxcel row with column indexs for checking remaining functionalitites + $existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file); + // Kint::dump($existing_famility_details); + $family = array_merge($family,$existing_famility_details); + // dd($family); + } + + // Kint::dump($family);die(); + $data = calculate_premimum($family,$policy_terms,$slab_details,$file); + // dd($data); + $employee_data_group_by_family[$emp_id] = $data; + //$this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]); + } + } + else if(isset($params['client_policy_id']))//handle data from enrollment to inception + { + $client_policy_id = $params['client_policy_id']; + //get client id + $client_id = ($this->clientPolicyModel->select('client_id')->find($client_policy_id))['client_id']; + // dd($client_id); + + // get policy and rack details + $policy_terms = $this->clientPolicyModel->getPolicyDetails($client_id,$client_policy_id); + $policy_terms = (array) $policy_terms[0];// convert obj to array + + //get policy slab rates + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($client_policy_id,$client_id); + + $existing_famility_details = $this->employeeModel->getEmpFamilybyEmpCode(client_id: $client_id,client_policy_id: $client_policy_id,emp_status: 'draft'); + + $file = ['id' => null,'client_id' => $client_id,'policy_id' => $client_policy_id,'action' => 'inception']; + // dd($this->employeeModel->getLastQuery()); + // Kint::dump($existing_famility_details);die(); + $employee_data_group_by_family = data_group_by_family($existing_famility_details,$data_source = 'db'); + // dd($employee_data_group_by_family); + foreach ($employee_data_group_by_family as $emp_id => $family) + { + $transformed_famility_details = transform_db_data_to_excel($family); + $data = calculate_premimum($transformed_famility_details,$policy_terms,$slab_details,$file); + // dd($data); + $employee_data_group_by_family[$emp_id] = $data; + $this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]); + } + + // dd($employee_data_group_by_family); + } + + + // die(); + return ($employee_data_group_by_family); + + } + + //deletion of emp + public function employeeDisembark($params) + { + helper('excel_util_helper'); + //get file name + $file_id = $params['file_id']; + $file = $this->fileModel->find($file_id); + + $file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name']; + + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + + $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + + unset($excel_data[0]); + // dd($excel_data); + $endorsement_data = []; + + + //make closure funciton which is going to use only by this method + $endorsement = function($data,$file,$row){ + + //for emp table + $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'emp_status','old_value' => $data['emp_status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion']); + // dd( $this->empEndorsementModel->getLastQuery()); + // $this->empEndorsementModel->save(['pk' => (int)$data['emp_id'],'emp_code' => $data['emp_code'],'table_name' => 'employees','actions' => 'd','name' => $data['name'],'field_name' => 'change_event','old_value' => $data['change_event'],'new_value' => 'deletion','created_by' => $file['created_by'],'remarks' => 'general deletion']); + + // for employee policy table + $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'date_of_exit','old_value' => $data['date_of_exit'],'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general deletion']); + $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'reason_for_exit','old_value' => $data['reason_for_exit'],'new_value' => $row[5],'created_by' => $file['created_by'],'remarks' => 'general deletion']); + $this->empEndorsementModel->save(['pk' => (int)$data['emp_policy_id'],'emp_code' => $data['emp_code'],'table_name' => 'employee_polices','actions' => 'd','name' => $data['name'],'field_name' => 'status','old_value' => $data['status'],'new_value' => 'deactivate','created_by' => $file['created_by'],'remarks' => 'general deletion']); + }; + //iterate each row + foreach ($excel_data as $col_key => $row) + { + if(check_row_is_empty_or_null($row)) + { + break; + } + // echo '
START- ' . $row[2]; + $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->first(); + + $existing_endorsements = $this->empEndorsementModel->where('actions','d') + ->where('table_name','employees') + ->where('endorsement_id is null') + ->where('emp_code',$employee['emp_code']) + ->where('name',$employee['name']) + ->where('field_name','emp_status') + ->findAll(); + + + if(!count($existing_endorsements)) + { + if(strtolower($employee['relationship']) != 'self') + { + + if(!in_array($employee['id'],$endorsement_data))//make entry in endorsement firsttime only with checking that PK of emp exisintg in variable $endorsement_data + { + $employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first(); + $data = ['emp_id' => $employee['id'],'name' => $employee['name'],'emp_status' => $employee['emp_status'],'emp_policy_id' => $employee_policy['id'],'emp_code' => $employee['emp_code'],'change_event' => $employee['change_event'],'date_of_exit' => $employee_policy['date_of_exit'],'reason_for_exit' => $employee_policy['reason_for_exit'],'status' => $employee_policy['status']]; + $endorsement($data,$file,$row); + $endorsement_data[] = $employee['id']; + } + } + else + { + + $family = $this->employeeModel->getEmpFamilybyEmpCode(emp_code: $row[1],client_id: $file['client_id'],client_policy_id: $file ['policy_id'],emp_status: 'active'); + // Kint::dump($family); + foreach ($family as $key => $emp) { + + if(!in_array($emp['emp_id'],$endorsement_data)) + { + $endorsement($emp,$file,$row); + + $endorsement_data[] = $emp['emp_id']; + + } + } + + } + } + + // print_r($endorsement_data); + + } + return $endorsement_data; + + } + + //correction of emp + public function employeesCorrectionProcess($params) + { + helper('excel_util_helper'); + //get file name + $file_id = $params['file_id']; + $file = $this->fileModel->find($file_id); + + $file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name']; + + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + + $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + + unset($excel_data[0]); + // dd($excel_data); + + //iterate each row + foreach ($excel_data as $col_key => $row) + { + if(check_row_is_empty_or_null($row)) + { + break; + } + // echo '
START- ' . $row[2]; + + $field_name = $row[3]; + $field_value = ($field_name == 'dob' ? change_date_format($row[4],'d-M-Y','Y-m-d') : $row[4] ); + + + $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->first(); + $existing_endorsements = $this->empEndorsementModel->where('actions','c') + ->where('table_name','employees') + ->where('endorsement_id is null') + ->where('emp_code',$employee['emp_code']) + ->where('name',$employee['name']) + ->where('field_name',$field_name) + ->findAll(); + // dd($existing_endorsements); + //make entry in endorsement table + if(!count($existing_endorsements)) + { + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employees','actions' => 'c','name' => $employee['name'],'field_name' => $field_name,'old_value' => $employee[ $field_name ],'new_value' => $field_value,'created_by' => $file['created_by'],'remarks' => $row[7],'date_of_correction' => change_date_format($row[5],'d-M-Y','Y-m-d')]); + } + + + + + } + return true; + } + + + //enhance of emp + public function employeesSIEnhanceProcess($params) + { + helper('excel_util_helper'); + //get file name + $file_id = $params['file_id']; + $file = $this->fileModel->find($file_id); + + $file_name_with_path = WRITEPATH."/uploads/excel/".$file['file_name']; + + $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($file_name_with_path); + $sheet = $spreadsheet->getActiveSheet(); + + $highestRowAndColumn = $sheet->getHighestRowAndColumn(); + + $excel_data = $sheet->rangeToArray('A1:' . $highestRowAndColumn['column'] . $highestRowAndColumn['row']); + + unset($excel_data[0]); + // dd($excel_data); + + //get policy slab rates + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); + //iterate each row + // dd($slab_details); + foreach ($excel_data as $col_key => $row) + { + if(check_row_is_empty_or_null($row)) + { + break; + } + // echo '
START- ' . $row[2]; + $employee = $this->employeeModel->where('emp_code', $row[1])->where('name',$row[2])->where('client_id',$file['client_id'])->first(); + $employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first(); + + $existing_endorsements = $this->empEndorsementModel->where('actions','si') + ->where('table_name','employee_polices') + ->where('endorsement_id is null') + ->where('emp_code',$employee['emp_code']) + ->where('name',$employee['name']) + ->where('field_name','basic_cover_si') + ->findAll(); + // dd($existing_endorsements); + //make entry in endorsement table + if(!count($existing_endorsements)) + { + + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + if($slab_value['si'] == $row[3]) + { + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $row[3],'created_by' => $file['created_by'],'remarks' => 'general si enhancement']); + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'general si enhancement']); + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => change_date_format($row[4],'d-M-Y','Y-m-d'),'created_by' => $file['created_by'],'remarks' => 'general si enhancement']); + break; + } + } + } + + + + + } + return true; + } + + + // insert or update in db for inception addition depent addition + public function employeesOnboardProcess($params) + { + $familiy_data = $params['familiy_data']; + $file = $params['file']; + // dd($file); + // print_r($familiy_data); + // echo '------------------------------------------------------'; + + + + foreach($familiy_data as $fkey => $value) + { + if($file['id'] == null || ($value['temp']['source'] == 'excel' || (in_array($value['temp']['grid_type'],[10,11]) && strtolower($value['relationship']) == 'self'))) //insert data come from excel and from db + { + + $employee = $this->employeeModel->checkExistingEmp($value); + $policy_data = $value['policy_details']; + unset($value['policy_details']); + unset($value['temp']); + + if($file['id'] == null && (strtolower($value['relationship']) == 'self' && $value['temp']['source'] == 'db' && $value['temp']['emp_id'] != null && $value['temp']['emp_policy_id'] != null)) + { + //check existing si and new si + $employee_policy = $this->employeePolicyModel->where('employee_id',$employee['id'])->where('client_policy_id',$file['policy_id'])->first(); + if($employee_policy['basic_cover_si'] != $policy_data['basic_cover_si']) + { + + //check any existing si enhancement pending + $existing_endorsements = $this->empEndorsementModel->where('actions','si') + ->where('table_name','employee_polices') + ->where('endorsement_id is null') + ->where('emp_code',$employee['emp_code']) + ->where('name',$employee['name']) + ->where('field_name','basic_cover_si') + ->findAll(); + + if(!count($existing_endorsements)) + { + + $slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']); + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + if($slab_value['si'] == $policy_data['si']) + { + //add new premimum details in endorsement table + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'basic_cover_si','old_value' => $employee_policy['basic_cover_si'],'new_value' => $policy_data['premium'],'created_by' => $file['created_by'],'remarks' => 'da auto si enhancement']); + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'premium','old_value' => $employee_policy['premium'],'new_value' => $slab_value['premium'],'created_by' => $file['created_by'],'remarks' => 'da auto si enhancement']); + $this->empEndorsementModel->save(['pk' => (int)$employee['id'],'emp_code' => $employee['emp_code'],'table_name' => 'employee_polices','actions' => 'si','name' => $employee['name'],'field_name' => 'si_enhancement_date','old_value' => null,'new_value' => ($policy_data['date_coverage']),'created_by' => $file['created_by'],'remarks' => 'da auto si enhancement']); + break; + } + } + } + + + + + } + + break; + }// end of self employee si enhance ment + + + //save employee table + if(count($employee)) + { + $value['updated_by'] = $file['created_by']; + $value['id'] = $employee[0]['id']; + $log_message = 'Update Employee - '.$employee[0]['name'].'('.$employee[0]['emp_code'].') with PK '.$employee[0]['id']; + // $this->myLogger->logme('error',('Update - ' . $employee[0]['id'].' - '. $employee[0]['emp_code'] .' - '.$employee[0]['name'])); + } + else + { + $value['emp_status'] = 'active'; + $value['created_by'] = $file['created_by']; + $log_message = 'Insert Employee- '.$value['name'] .'('.$value['emp_code'] .') with PK '; + // $this->myLogger->logme('error',('Insert - ' . $value['emp_code'] .' - '. $value['name'])); + } + + $this->employeeModel->save($value); + $emp_id = $this->employeeModel->getInsertID(); + if($emp_id != 0){ $log_message .= $emp_id; } + else{ $emp_id = $employee[0]['id']; } + + $this->myLogger->logme('error',$log_message); + + //save policy table + $employee_policy = $this->employeePolicyModel->checkExistingEmpPolicy(['employee_id' => $emp_id,'client_policy_id' => $file['policy_id']]); + if(count($employee_policy)) + { + $policy_data['updated_by'] = $file['created_by']; + $policy_data['id'] = $employee_policy[0]['id']; + $policy_data['status'] = 'active'; + + $log_message = 'Update Employee Policy for '. $value['name'].'('. $value['emp_code'].') with PK- ' . $employee_policy[0]['id'] .' client policy ID '.$employee_policy[0]['client_policy_id'].' with SI '.$policy_data['basic_cover_si']; + } + else + { + $policy_data['employee_id'] = $emp_id; + $policy_data['client_policy_id'] = $file['policy_id']; + $policy_data['created_by'] = $file['created_by']; + $policy_data['status'] = 'active'; + $log_message = 'Insert Employee Policy for '. $value['name'].'('. $value['emp_code'].') - client policy id -'. $file['policy_id'].' - with SI '.$policy_data['basic_cover_si']; + } + + $this->employeePolicyModel->save($policy_data); + $emp_policy_id = $this->employeePolicyModel->getInsertID(); + if($emp_policy_id != 0){ $log_message .= ' with PK ' . $emp_policy_id; } + else{ $emp_policy_id = $employee_policy[0]['id']; } + + $this->myLogger->logme('error',$log_message); + + }// if end + }// for end + }//function end + + // --------------------------------------------------------------------------------- @@ -476,5 +990,6 @@ class EmployeeServiceController extends AdminController // --------------------------------------------------------------------------------- + } diff --git a/app/Controllers/LoginController.php b/app/Controllers/LoginController.php index c24f4ddc..1d646d01 100644 --- a/app/Controllers/LoginController.php +++ b/app/Controllers/LoginController.php @@ -15,8 +15,8 @@ class LoginController extends BaseController public function index(){ - // $session_data = ['isLoggedIn' => True ,'userid' => '4']; - // set_session_data($session_data); + $session_data = ['isLoggedIn' => True ,'userid' => '25']; + set_session_data($session_data); // $isLoggedIn = check_session(); $isLoggedIn = check_session(); @@ -42,23 +42,23 @@ class LoginController extends BaseController if($user){ if($user->is_active !== '0'){ - $session_data = ['isLoggedIn' => True ,'userid' => $user->id]; + $session_data = ['isLoggedIn' => True ,'userid' => $user->id, 'userData' => $user]; set_session_data($session_data); log_message('error', 'Set The UserId : `'. $user->id .'` in Session'); log_message('error', 'User Login Sucessfully'); - - // $this->getUserDeviceInfo($user->id); + $this->getUserDeviceInfo($user->id, 'NhanceUser'); return redirect()->to(base_url('/dashboard/view')); }else{ - log_message('error', 'User Not Activate'); - session()->setFlashdata('error', 'User Not Activate'); + log_message('error', 'User Not Active'); + session()->setFlashdata('error', 'User Not Active'); return redirect()->to(base_url('login')); } }else{ - log_message('error', 'User Not Register'); - session()->setFlashdata('error', 'User Not Register'); + + log_message('error', 'User Not Registered'); + session()->setFlashdata('error', 'User Not Registered'); return redirect()->to(base_url('login')); } } diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index f0d5cc4b..b702c77f 100644 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -90,7 +90,7 @@ class MasterController extends AdminController { $this->myLogger->logme('error','Edit Insurer Onboarding function called'); - $headerData['page_name'] = 'Edit Insurer Onboarding'; + $headerData['page_name'] = 'Edit Insurer Master'; $types = array( (object) array('id' => 'pvt', 'name' => 'PVT'), @@ -122,7 +122,7 @@ class MasterController extends AdminController { $this->myLogger->logme('error','Insurer Onboarding function called'); - $headerData['page_name'] = 'Insurer Onboarding'; + $headerData['page_name'] = 'Insurer Master'; $types = array( (object) array('id' => 'pvt', 'name' => 'PVT'), @@ -228,12 +228,6 @@ class MasterController extends AdminController } - - - - - - public function editInsurerGet($id = null) { $this->myLogger->logme('error','Edit TPA Onboarding function called'); @@ -248,10 +242,6 @@ class MasterController extends AdminController exit(); } - - - - public function editInsurerBranch() { $this->myLogger->logme('error','Insurer branch CREATE function called'); @@ -259,11 +249,6 @@ class MasterController extends AdminController $data = $this->request->getPost(); $update = $this->insurerBranchModel->update($id, $data); - // print_r($this->request->getPost('name[]')); - // print_r($this->request->getPost('email[]')); - // print_r($this->request->getPost('mobile[]')); - // print_r($this->request->getPost('designation[]')); - if($update){ $contactsToDelete = $this->levelContactModel->where(['ref_id' => $id,'contact_type' => 'insurer', 'is_active' => 1])->get()->getResult(); foreach ($contactsToDelete as $contact) { @@ -285,10 +270,10 @@ class MasterController extends AdminController } if($update){ - $branchData = $this->tpaBranchModel->where('tpa_id', $this->request->getPost('tpa_id'))->findAll(); - echo json_encode(array("status" => true , 'data' => $branchData)); + $branchData = $this->insurerBranchModel->where('insurer_id', $this->request->getPost('insurer_id'))->findAll(); + echo json_encode(array("status" => true , 'data' => $branchData, 'edit')); }else{ - echo json_encode(array("status" => false)); + echo json_encode(array("status" => false, 'edit')); } } @@ -325,7 +310,7 @@ class MasterController extends AdminController { $this->myLogger->logme('error','TPA Onboarding function called'); - $headerData['page_name'] = 'TPA Onboarding'; + $headerData['page_name'] = 'TPA Master'; // print_r($data['types']);die(); @@ -408,7 +393,7 @@ class MasterController extends AdminController { $this->myLogger->logme('error','Edit TPA Onboarding function called'); - $headerData['page_name'] = 'Edit TPA Onboarding'; + $headerData['page_name'] = 'Edit TPA Master'; $editData['tpa'] = $this->tpaModel->where(['id' => $id, 'is_active' => 1])->first(); $editData['tpa_branch'] = $this->tpaBranchModel->where(['tpa_id' => $id, 'is_active' => 1])->findAll(); @@ -546,7 +531,7 @@ class MasterController extends AdminController { $this->myLogger->logme('error','KYC Onboarding function called'); - $headerData['page_name'] = 'KYC Onboarding'; + $headerData['page_name'] = 'KYC Master'; // print_r($data['types']);die(); @@ -610,7 +595,7 @@ class MasterController extends AdminController { $this->myLogger->logme('error','Edit KYC Onboarding function called'); - $headerData['page_name'] = 'Edit KYC Onboarding'; + $headerData['page_name'] = 'Edit KYC Master'; $editData['kyc'] = $this->kycEntityTypeModel->where(['id' => $id, 'is_active' => 1])->first(); $editData['kyc_docs'] = $this->kycDocsModel->where(['kyc_type_id' => $id, 'is_active' => 1])->findAll(); @@ -716,7 +701,7 @@ class MasterController extends AdminController { $this->myLogger->logme('error','Policy Type Onboarding function called'); - $headerData['page_name'] = 'Policy Type Onboarding'; + $headerData['page_name'] = 'Policy Type Master'; // print_r($data['types']);die(); @@ -776,13 +761,11 @@ class MasterController extends AdminController } - - public function editPolicyTypeOnboarding($id = null) { $this->myLogger->logme('error','Edit KYC Onboarding function called'); - $headerData['page_name'] = 'Edit KYC Onboarding'; + $headerData['page_name'] = 'Edit KYC Master'; $editData['policytype'] = $this->policyTypeModel->where(['id' => $id, 'is_active' => 1])->first(); $editData['policies'] = $this->policesModel->where(['policy_type_id' => $id, 'is_active' => 1])->findAll(); @@ -794,9 +777,6 @@ class MasterController extends AdminController } - - - public function editPolicyType() { $this->myLogger->logme('error','edit Policy general info function called'); @@ -812,15 +792,13 @@ class MasterController extends AdminController } - - - public function policesList($id = null) { $this->myLogger->logme('error','Edit Policies Onboarding function called'); // $editData['policies'] = $this->policesModel->where(['policy_type_id' => $id, 'is_active' => 1])->findAll(); + $policies = $this->policesModel->where(['policy_type_id' => $id, 'is_active' => 1])->findAll(); foreach ($policies as $policy) { @@ -848,9 +826,7 @@ class MasterController extends AdminController public function editPoliciesGet($id = null) { $this->myLogger->logme('error','Edit Policies Onboarding function called'); - $editData['policies'] = $this->policesModel->where(['id' => $id, 'is_active' => 1])->first(); - // Return JSON response header('Content-Type: application/json'); echo json_encode($editData); @@ -858,8 +834,6 @@ class MasterController extends AdminController } - - public function editPolicies() { $this->myLogger->logme('error','edit Policy general info function called'); @@ -868,7 +842,8 @@ class MasterController extends AdminController $data['updated_by'] = get_session_userid(); $update = $this->policesModel->update($id,$data); if($update){ - echo json_encode(array("status" => true , 'data' => $data)); + $policyData = $this->policesModel->where(['id' => $id, 'is_active' => 1])->findAll(); + echo json_encode(array("status" => true , 'data' => $policyData)); }else{ echo json_encode(array("status" => false)); } diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 61ef2ff6..1801cc1c 100644 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -130,7 +130,6 @@ class RestAuthenticationController extends AdminController try { $mobile_number = $this->request->getJSON()->mobile_number; $randomNumber = rand(100000, 999999); - $randomNumber = 123456; $HrData = $this->hrModel->where('mobile', $mobile_number)->where('contact_type', 'client')->first(); if ($HrData) { diff --git a/app/Controllers/SwaggerController.php b/app/Controllers/SwaggerController.php new file mode 100644 index 00000000..75955f60 --- /dev/null +++ b/app/Controllers/SwaggerController.php @@ -0,0 +1,10 @@ +getHeader('Authorization'); + + $jwt =''; + + if($request->headers()['Auth']){ + $jwt = $request->headers()['Auth']; + }else{ + $jwt = $request->getHeader('Authorization'); + } + if ($jwt) { if (JWTToken::validateJWT($jwt)) { diff --git a/app/Helpers/JWTToken.php b/app/Helpers/JWTToken.php index dcee4d0d..6c6d29cf 100644 --- a/app/Helpers/JWTToken.php +++ b/app/Helpers/JWTToken.php @@ -16,7 +16,6 @@ use ReflectionClass; class JWTToken { - public static function encode($data =null) { $secret_Key="secret"; @@ -44,6 +43,7 @@ class JWTToken { $jwtParts = explode(' ', $jwt); + // print_r($jwtParts); if (count($jwtParts) != 2 || $jwtParts[0] == 'Bearer') { return false; } diff --git a/app/Helpers/excel_import_export_helper.php b/app/Helpers/excel_import_export_helper.php index 55ed7eda..b6bf615a 100644 --- a/app/Helpers/excel_import_export_helper.php +++ b/app/Helpers/excel_import_export_helper.php @@ -87,7 +87,9 @@ if (!function_exists('generate_excel')) { try { // Save Excel file to the specified path - $writer->save($filename); + // $writer->save($filename); + $filePath = WRITEPATH."/uploads/import_excel/" . $filename; + $writer->save($filePath); return true; // Return true if file was successfully saved } catch (\Exception $e) { // Log or handle the exception @@ -352,8 +354,6 @@ if (!function_exists('read_excel_file_to_array')) { } -// app/Helpers/filename_helper.php - if (! function_exists('generate_filename')) { function generate_filename($client_short_name, $event_type, $actions, $insurer_or_tpa, $policy_name) { @@ -366,6 +366,10 @@ if (! function_exists('generate_filename')) { $evenTypeLabel = 'C'; }else if($event_type == 'si_enhancement'){ $evenTypeLabel = 'SI'; + }else if($event_type == 'addition'){ + $evenTypeLabel = 'A'; + }else if($event_type == 'dependent_addition'){ + $evenTypeLabel = 'DA'; } $insurer_or_tpa_lable = ""; @@ -385,3 +389,12 @@ if (! function_exists('generate_filename')) { return $file_name; } } + + +if (!function_exists('remove_underscore_capitalize_first_letter')) { + function remove_underscore_capitalize_first_letter($word) { + // Remove underscore and capitalize first letter of each word + $formattedEvent = ucwords(str_replace('_', ' ', $word)); + return $formattedEvent; + } +} \ No newline at end of file diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index 1f1e9b47..e3b2d2f6 100644 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -2,6 +2,20 @@ use App\Models\EmployeeModel; + +if(!function_exists('calculate_days_bw_dates')) +{ + function calculate_days_bw_dates(string $from_date = "", string $to_date ="") + { + if($to_date == ""){ $currentDateTime = new DateTime(); } + else{ $currentDateTime = new DateTime($to_date); } + if($from_date == ""){ $passedDateTime = new DateTime(); } + else{ $passedDateTime = new DateTime($from_date); } + + return $interval = $currentDateTime->diff($passedDateTime); + } +} + if (!function_exists('check_columns_name')) { function check_columns_name($definedColumns,$excelColumns) { @@ -11,7 +25,7 @@ if (!function_exists('check_columns_name')) { $definedColIdx = $definedCol['col_idx']; $definedColName = $definedCol['col_name']; - if (strtolower(trim($excelColumns[$definedColIdx])) !== strtolower($definedColName)) { + if (strtolower(strip_tags(trim($excelColumns[$definedColIdx]))) !== strtolower($definedColName)) { $mismatchedColumns[] = "Column order conflict. Column order no ".($definedColIdx + 1)." expected : ".$definedColName." and received : ".$excelColumns[$definedColIdx]."
"; } } @@ -55,23 +69,29 @@ if(!function_exists('check_relationship')) { function check_relationship($row,$relationship) { - // print_r($col);print_r($relationship); + // print_r($relationship); // echo '
'; - if($row[17] != null && in_array(strtoupper($row[17]), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available { if($row[5] != null && $row[4] != null)//$row[5] = relationship $row[4] = Gender { $slug = \Config\Services::slug(); $col = $slug->slugify($row[5]); - // echo $col;die(); + // echo $col;//die(); if($col != 'self' && $col != 'spouse') { - if($relationship[ $col ]['gender'] != $row[4]) + if(!isset($relationship[ $col ])) + { + return array('status' => false,'error' => 'Rule Conflict: Unknown Relationship'); + } + + if(isset($relationship[ $col ]) && $relationship[ $col ]['gender'] != $row[4]) { $error = "Gender relationship conflict: Expected ".$relationship[ $col ]['gender'].", received $row[4]"; return array('status' => false,'error' => $error); } + } return array('status' => true); } @@ -90,12 +110,12 @@ if(!function_exists('check_doj')) function check_doj($row) { - if($row[17] != null && in_array(strtoupper($row[17]), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available { $slug = \Config\Services::slug(); $relationship = $slug->slugify($row[5]); // echo $relationship;echo $row[7]; - if($relationship == 'self' && $row[7] == "") { return array('status' => false,'error' => "DOJ mandantory for self"); } + if($relationship == 'self' && $row[8] == "") { return array('status' => false,'error' => "DOJ mandantory for self"); } return array('status' => true); } else { return array('status' => true); } // in else condition no need to check rule, just return true @@ -105,14 +125,52 @@ if(!function_exists('check_doj')) if(!function_exists('check_employee_band')) { - function check_employee_band($row) + function check_employee_band($row,$policy_terms,$slab_details) { - if($row[17] != null && in_array(strtoupper($row[17]), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available { + $is_emp_band_needed = $slab_details['grid_master']['emp_band']; $slug = \Config\Services::slug(); $relationship = $slug->slugify($row[5]); // echo $relationship;echo $row[7]; - if($relationship == 'self' && $row[9] == "") { return array('status' => false,'error' => "Band mandantory for self"); } + if($is_emp_band_needed && $relationship == 'self' && $row[10] == "") { return array('status' => false,'error' => "Band mandantory for self"); } + else if($is_emp_band_needed && $relationship == 'self' && $row[10] != "") + { + $received_grade = $row[10]; + $found = false; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + if($slab_value['grade'] == $received_grade) + { + $found = true; + break; + } + } + if(!$found) { return array('status' => false,'error' => "Emp band/Grade not found"); } + } + return array('status' => true); + }else { return array('status' => true); } // in else condition no need to check rule, just return true + } +} + + +if(!function_exists('check_si')) +{ + function check_si($row,$policy_terms,$slab_details) + { + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA','SI']))// check rule only of action column data available + { + $received_si = $row['current_action'] == 'SI' ? $row[3] : $row[6]; + $found = false; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + if($slab_value['si'] == $received_si) + { + $found = true; + break; + } + } + if(!$found) { return array('status' => false,'error' => "Sum insured not found"); } return array('status' => true); }else { return array('status' => true); } // in else condition no need to check rule, just return true } @@ -120,14 +178,15 @@ if(!function_exists('check_employee_band')) if(!function_exists('check_basic_pay')) { - function check_basic_pay($row) + function check_basic_pay($row,$policy_terms,$slab_details) { - if($row[17] != null && in_array(strtoupper($row[17]), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available { + $is_basic_pay_needed = $slab_details['grid_master']['basicpay']; $slug = \Config\Services::slug(); $relationship = $slug->slugify($row[5]); // echo $relationship;echo $row[7]; - if($relationship == 'self' && $row[8] == "") { return array('status' => false,'error' => "Basic pay mandantory for self"); } + if($is_basic_pay_needed && $relationship == 'self' && $row[9] == "") { return array('status' => false,'error' => "Basic pay mandantory for self"); } return array('status' => true); }else { return array('status' => true); } // in else condition no need to check rule, just return true } @@ -138,7 +197,7 @@ if (!function_exists('check_dob_diff')) { function check_dob_diff($row,$relationships) { // echo 'called'; - if($row[17] != null && in_array(strtoupper($row[17]), ['I','A','DA']))// check rule only of action column data available + if($row['current_action'] != null && in_array(strtoupper($row['current_action']), ['I','A','DA']))// check rule only of action column data available { if($row[3] != null && $row[5] != null) { @@ -150,8 +209,8 @@ if (!function_exists('check_dob_diff')) $slug = \Config\Services::slug(); $relationship = $slug->slugify($row[5]); - $age_min = $relationships[$relationship]['age_min']; - $age_max = $relationships[$relationship]['age_max']; + $age_min = isset($relationships[$relationship]['age_min']) ? $relationships[$relationship]['age_min'] : NULL; + $age_max = isset($relationships[$relationship]['age_max']) ? $relationships[$relationship]['age_max'] : NULL; // echo $relationship.','.$age_min.'-'.$age_max; if($age_min !== null && $age_min > $interval->y) { @@ -173,14 +232,21 @@ if (!function_exists('check_dob_diff')) if (!function_exists('data_group_by_family')) { - function data_group_by_family($emp_data) + function data_group_by_family($emp_data,$data_source = 'excel') { $result = []; foreach ($emp_data as $rkey => $row) { - if(!check_row_is_empty_or_null($row)) + if($data_source == 'excel') { - $result[$row[1]][] = $row; + if(!check_row_is_empty_or_null($row)) + { + $result[$row[1]][] = $row; + } + + }else if($data_source = 'db') + { + $result[$row['emp_code']][] = $row; } } @@ -216,10 +282,14 @@ if (!function_exists('name_dup_check_within_family')) if (!function_exists('name_and_empid_check_in_db')) { - function name_and_empid_check_in_db($family_data,$client_id,$policy_id) + function name_and_empid_check_in_db($family_data,$actionArr) { $employeeModel = new EmployeeModel(); $result = ['del' => [],'i' => []]; + $client_id = $actionArr['client_id']; + $policy_id = $actionArr['policy_id']; + $current_action = $actionArr['action']; + foreach ($family_data as $rkey => $row) { $res = $employeeModel @@ -227,22 +297,23 @@ if (!function_exists('name_and_empid_check_in_db')) ->join('employee_polices ep',"cp.id = ep.client_policy_id AND employees.id = ep.employee_id") ->where("cp.policy_id",$policy_id) ->where("employees.client_id",$client_id) - ->like('name',$row[2],'both')->like('emp_code',$row[1],'both') + // ->where("ep.client_id",$client_id) + ->where('name',$row[2])->where('emp_code',$row[1]) ->findAll(); - - if(count($res)) - { - if($row[17] == 'D') + // dd($employeeModel); + + + if(($current_action == 'deletion' || $current_action == 'correction' || $current_action == 'si_enhancement') && !count($res)) { array_push($result['del'],$row[0]); } - else + if(($current_action == 'inception' || $current_action == 'dependent_addition' || $current_action == 'addition') && count($res)) { array_push($result['i'],$row[0]); } - } + } return $result; @@ -251,7 +322,7 @@ if (!function_exists('name_and_empid_check_in_db')) if (!function_exists('check_dependent_conflict')) { - function check_dependent_conflict($family_data,$policy_terms) + function check_dependent_conflict($family_data,$policy_terms,$actionArr) { $result = ['status' => true]; @@ -267,24 +338,26 @@ if (!function_exists('check_dependent_conflict')) $allowed_parent_in_laws_count = 0; $received_parent_in_laws_count = 0; $overall_famility_relationships = []; + $self_emp_row_id = 0; $temp_counts = [2,3,4,5,6,7,8,9,10]; //temp variable for check relation repetaed count $slug = \Config\Services::slug(); - if($policy_terms['family_floater'] == true) - { + // if($policy_terms['family_floater'] == true) + // { // $temp_string = implode(" ",$policy_terms['family_floaters']); $temp = $policy_terms['family_floaters']; - $allowed_child_count = count(preg_grep('/child/',$temp)); - $allowed_spouse_count = count(preg_grep('/spouse/',$temp)); - $allowed_parents_count = count(preg_grep('/parent[12]/',$temp)); - $allowed_parent_in_laws_count = count(preg_grep('/parent_in_law[12]/',$temp)); - + $allowed_child_count = $temp['childrens']; + $allowed_spouse_count = $temp['spouse']; + $allowed_adults = $temp['either-parents-pil']; + $allowed_parents_count = $temp['either-parents-pil'] == 0 ? $temp['parents'] : 0; + $allowed_parent_in_laws_count = $temp['either-parents-pil'] == 0 ? $temp['parents-in-law'] : 0; + // dd($allowed_adults == 0); foreach ($family_data as $key => $row) { $relationship = $slug->slugify($row[5]); - if($row[17] != 'D' && $relationship != 'son' && $relationship != 'daughter') + if($actionArr != 'deletion' && $relationship != 'son' && $relationship != 'daughter') { array_push($overall_famility_relationships, $relationship); } @@ -293,6 +366,7 @@ if (!function_exists('check_dependent_conflict')) if($relationship == 'self') { $self_gender = $row[4]; + $self_emp_row_id = $row[0]; } if($relationship == 'spouse') { @@ -316,7 +390,7 @@ if (!function_exists('check_dependent_conflict')) // print_r($overall_famility_relationships); // echo '
'; - if($row[17] != 'D') + if($actionArr != 'deletion') { $repeated_relationships_count = array_count_values($overall_famility_relationships); // print_r($repeated_relationships_count); @@ -325,7 +399,7 @@ if (!function_exists('check_dependent_conflict')) if(is_array($repeated_count) && count($repeated_count)) { $result['status'] = false; - $result['error_data'][] = ['code' => 13,'col_name' => 'relationship','msg' => 'Rule conflict: Twofold relationship found within family']; + $result['error_data'][] = ['code' => 13,'col_name' => 'relationship','msg' => 'Rule conflict: Twofold relationship found within family','row_id' => $family_data[0][0]]; } } // print_r($repeated_count); @@ -339,29 +413,492 @@ if (!function_exists('check_dependent_conflict')) if($self_gender == $spouse_gender) { $result['status'] = false; - $result['error_data'][] = ['code' => 4,'col_name' => 'gender','msg' => 'Rule conflict: Self and Spouse cannot be same gender']; + $result['error_data'][] = ['code' => 4,'col_name' => 'gender','msg' => 'Rule conflict: Self and Spouse cannot be same gender','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])]; } - if(($allowed_spouse_count < $received_spouse_count) || ($allowed_child_count < $received_child_count) || ($allowed_parents_count < $received_parents_count) || ($allowed_parent_in_laws_count < $received_parent_in_laws_count)) + + if(($allowed_spouse_count < $received_spouse_count) || ($allowed_child_count < $received_child_count) ) { $result['status'] = false; - $result['error_data'][] = ['code' => 12,'col_name' => null,'msg' => 'Rule conflict: Dependent count greater than allowed dependent count'];//dependent count mismatch + $result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: Dependent count greater than allowed dependent count','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];//dependent count mismatch } - - } - else - { - if(count($family_data) > 1) + // || ($allowed_parents_count < $received_parents_count) || ($allowed_parent_in_laws_count < $received_parent_in_laws_count) + if($allowed_adults == 1 && $received_parents_count && $received_parent_in_laws_count ) { - $result['status'] = false; - $result['error_data'][] = ['code' => 11,'col_name' => null,'msg' => 'Rule conflict: Dependents not allowed'];//dependents not allowed + $result['status'] = false; + $result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: Parents and Parents in law both not allowed','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])]; + + if((2 < $received_parents_count) || (2 < $received_parent_in_laws_count)) + { + $result['status'] = false; + $result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: Dependent count greater than allowed dependent count','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];//dependent count mismatch + } } - } + + // var_dump($allowed_adults == 0); + // dd($allowed_adults == 0 && (($allowed_parents_count < $received_parents_count) || ($allowed_parent_in_laws_count < $received_parent_in_laws_count))); + if($allowed_adults == 0 && (($allowed_parents_count < $received_parents_count) || ($allowed_parent_in_laws_count < $received_parent_in_laws_count) )) + { + // dd($allowed_adults); + $result['status'] = false; + $result['error_data'][] = ['code' => 12,'col_name' => 'sno','msg' => 'Rule conflict: Dependent count greater than allowed dependent count','row_id' => (isset($self_emp_row_id) ? $self_emp_row_id : $family_data[0][0])];//dependent count mismatch + } + + + // } + // else + // { + // if(count($family_data) > 1) + // { + // $result['status'] = false; + // $result['error_data'][] = ['code' => 11,'col_name' => 'sno','msg' => 'Rule conflict: Dependents not allowed','row_id' => $row[0]];//dependents not allowed + // } + // } return $result; } } +if (!function_exists('generate_relationship_code')) +{ + function generate_relationship_code($arr) + { + $gender = ['M' => 1,'F' => 2]; + $relationship = ['self' => 1,'spouse' => 2,'son' => 3,'daughter' => 4,'father' => 5,'mother' => 6,'father-in-law' => 7,'mother-in-law' => 8]; + $slug = \Config\Services::slug(); + $relationship_code = $slug->slugify($arr['relationship']); + $relationship_code = $gender[ $arr['gender'] ] . $relationship[ $relationship_code ] ; + return $relationship_code; + } +} + +if (!function_exists('calculate_premimum')) +{ + function calculate_premimum($family_data,$policy_terms,$slab_details,$fileArr) + { +// + // dd($fileArr); + // grid type + // 1 = premium => si + $result = []; + $grid_type = $slab_details['grid_master']['ui_type']; + $fileArr['grid_type'] = $grid_type; + //this variable for store emp id and their band for emp band level premium calculation for all famility members (especially for grid type 9) also store max age and max count of a familiy for grid type 10,11 + $emp_details_with_empband_max_age_max_count = []; + //max age amoung familiy + $max_age = max(array_map(function($item) {return calculate_days_bw_dates(from_date: $item[3])->y; }, $family_data)); + + foreach($family_data as $fkey => $member) + { + //transform as db row column + $transformed_familiy_member_data = transform_excel_data_to_db($member,$fileArr); + // dd($transformed_familiy_member_data); + //store emp id and emp band and attach it to their familiy members where band is always empty + + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = null; + if(strtolower($transformed_familiy_member_data['relationship']) == 'self') + { + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band'] = $transformed_familiy_member_data['band']; + } + + //end of store emp id and emp band and attach it to their familiy members where band is always empty + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount'] =count($family_data); + + $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage'] = $max_age; + + //generate relationship code + if($transformed_familiy_member_data['temp']['action'] != 'D' && $transformed_familiy_member_data['temp']['action'] != 'C' && $transformed_familiy_member_data['temp']['action'] != 'SI') + { + $transformed_familiy_member_data['relationship_code'] = generate_relationship_code($transformed_familiy_member_data); + } + + //calculate primimum based on grid type + if($transformed_familiy_member_data['temp']['action'] != 'D' && $transformed_familiy_member_data['temp']['action'] != 'C' && $transformed_familiy_member_data['temp']['action'] != 'SI') + { + + //before call premium_calculation_manager attach band,max age and max count into the array temporarly for grid 9,10 and 11 + $transformed_familiy_member_data['temp']['band'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['band']; + $transformed_familiy_member_data['temp']['maxage'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxage']; + $transformed_familiy_member_data['temp']['maxcount'] = $emp_details_with_empband_max_age_max_count[ $transformed_familiy_member_data['emp_code'] ]['maxcount']; + + if( $fileArr['id'] == null || (in_array($grid_type,[10,11]) || $transformed_familiy_member_data['temp']['source'] == 'excel'))//if file id is null then data coming from enrollment (from DB) otherwise data coming from xcel, so calculate only data from excel (new entry) note: even data coming from excel for event dependet additon we fetch other dependts from db and calculate premium for whole family + { + $transformed_familiy_member_data = premium_calculation_manager($transformed_familiy_member_data,$policy_terms,$slab_details); + + $result[] = $transformed_familiy_member_data; + } + } + } + + return $result; + } +} +if (!function_exists('transform_excel_data_to_db')) +{ + function transform_excel_data_to_db($memArr,$actionArr) + { + + $current_column_action = null; + if($actionArr['action'] == 'inception'){ $current_column_action = 'I'; } + else if($actionArr['action'] == 'addition'){ $current_column_action = 'A'; } + else if($actionArr['action'] == 'dependent_addition'){ $current_column_action = 'DA'; } + else if($actionArr['action'] == 'deletion'){ $current_column_action = 'D'; } + else if($actionArr['action'] == 'correction'){ $current_column_action = 'C'; } + else if($actionArr['action'] == 'si_enhancement'){ $current_column_action = 'SI'; } + + if($actionArr['action'] == 'inception' || $actionArr['action'] == 'addition' || $actionArr['action'] == 'dependent_addition') + { + + $policy['basic_cover_si'] = $memArr[6]; + $policy['pre_existing_alignments'] = $memArr[14]; + $policy['date_of_exit'] = isset($memArr[16]) ? change_date_format($memArr[16],'d-M-Y','Y-m-d') : NULL; + $policy['reason_for_exit'] = $memArr[17]; + $policy['client_policy_id'] = $actionArr['policy_id']; + $policy['date_coverage'] = isset($memArr[7]) ? change_date_format($memArr[7],'d-M-Y','Y-m-d') : NULL;; + $policy['policy_end_date'] = null; + $policy['days'] = null; + $policy['premium'] = null; + $policy['rata_premimum'] = null; + $policy['gst'] = null; + + + $result['emp_code'] = $memArr[1]; + $result['name'] = $memArr[2]; + $result['dob'] = isset($memArr[3]) ? change_date_format($memArr[3],'d-M-Y','Y-m-d') : NULL; + $result['gender'] = $memArr[4]; + $result['relationship'] = $memArr[5]; + $result['relationship_code'] = $memArr[5]; + $result['doj'] = isset($memArr[8]) ? change_date_format($memArr[8],'d-M-Y','Y-m-d') : NULL; + $result['basic_pay'] = $memArr[9]; + $result['band'] = $memArr[10]; + $result['designation'] = $memArr[11]; + $result['mobile'] = $memArr[12]; + $result['email_corporate'] = $memArr[13]; + $result['file_id'] = $actionArr['id']; + $result['client_id'] = $actionArr['client_id']; + $result['change_event'] = $memArr[15]; + $result['temp']['grid_type'] = $actionArr['grid_type']; + $result['temp']['action'] = isset($memArr['current_action']) ? $memArr['current_action'] : $current_column_action; + $result['temp']['source'] = isset($memArr['temp']['source']) ? $memArr['temp']['source'] : 'excel'; + $result['temp']['emp_id'] = isset($memArr['temp']['emp_id']) ? $memArr['temp']['emp_id'] : null; + $result['temp']['emp_policy_id'] = isset($memArr['temp']['emp_policy_id']) ? $memArr['temp']['emp_policy_id'] : null; + $result['policy_details'] = $policy; + + return $result; + + } + } +} + + +if (!function_exists('premium_calculation_manager')) +{ + function premium_calculation_manager($emp_data,$policy_terms,$slab_details) + { + // grid type + // 1 = premium => si + $grid_type = $slab_details['grid_master']['ui_type']; + + switch ($grid_type) { + case "1": + //GPA - Sum Insured (SI) * Multiplier + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + if($slab_value['si'] == $employee_received_si) + { + $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); + + break; + } + } + + break; + case "2": + //GPA - Flat Rate for all SI + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + if($slab_value['si'] == $employee_received_si) + { + $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); + + break; + } + } + break; + case "3": + //GMC - SI + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + if($slab_value['si'] == $employee_received_si) + { + $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); + + break; + } + } + + break; + case "4": + //GMC - Employees Age band + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + { + $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); + + break; + } + } + break; + case "5": + //GMC - Employees Age + SI + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + { + + $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); + + break; + } + } + break; + case "6": + //GMC - Employees + Dependent Age band + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + { + + $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($emp_data['policy_details']['date_coverage'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); + + break; + } + } + break; + case "7": + //GMC - Employees + Dependent Age + SI + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + $age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y; + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age)) + { + + $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); + + + break; + } + } + break; + case "8": + //GMC - SI as per Grade or Band + $employee_received_band = $emp_data['temp']['band']; + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + + if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) + { + // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; + + $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); + + break; + } + } + break; + case "9": + //GMC - Flat Rate for all + $employee_received_band = $emp_data['temp']['band']; + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + + if($slab_value['grade'] == $employee_received_band && $slab_value['si'] == $employee_received_si) + { + // $emp_data['policy_details']['basic_cover_si'] = $slab_value['si']; + $emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']); + $emp_data['policy_details']['policy_end_date'] = $policy_terms['policy_end_date']; + $emp_data['policy_details']['days'] = calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days; + $emp_data['policy_details']['premium'] = $slab_value['premium']; + $emp_data['policy_details']['rata_premimum'] = calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']); + $emp_data['policy_details']['gst'] = (float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.',''); + + break; + } + } + break; + case "10": + //GMC - Maximum age of Dependents + $max_age = $emp_data['temp']['maxage']; + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $emp_data['policy_details']['basic_cover_si'] = null; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + + if($slab_value['si'] == $employee_received_si && ($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age)) + { + + $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); + $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); + $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); + $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); + $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); + $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + + break; + } + } + break; + case "11": + //GMC - Maximum count per Family + $max_count = $emp_data['temp']['maxage']; + $employee_received_band = $emp_data['temp']['band']; + $employee_received_si = $emp_data['policy_details']['basic_cover_si']; + $emp_data['policy_details']['basic_cover_si'] = null; + foreach ($slab_details['slab_rates'] as $skey => $slab_value) + { + + if($slab_value['si'] == $employee_received_si && ($slab_value['grade'] == $employee_received_band)) + { + //calculate premium based on count + $famility_si_covered = $employee_received_si * $max_count; + $famility_si_covered = ($famility_si_covered >= $slab_value['max_si'] ? $slab_value['max_si'] : $famility_si_covered); + + $emp_data['policy_details']['basic_cover_si'] = (strtolower($emp_data['relationship']) == 'self' ? $famility_si_covered : 0); + $emp_data['policy_details']['date_coverage'] = (strtolower($emp_data['relationship']) == 'self' ? (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']) : ""); + $emp_data['policy_details']['policy_end_date'] = (strtolower($emp_data['relationship']) == 'self' ? $policy_terms['policy_end_date'] : ""); + $emp_data['policy_details']['days'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_days_bw_dates($policy_terms['policy_start_date'],$policy_terms['policy_end_date'])->days : 0); + $emp_data['policy_details']['premium'] = (strtolower($emp_data['relationship']) == 'self' ? $slab_value['premium'] : 0); + $emp_data['policy_details']['rata_premimum'] = (strtolower($emp_data['relationship']) == 'self' ? calculate_pro_rata_premimum($slab_value['premium'],$emp_data['policy_details']['days']) : 0); + $emp_data['policy_details']['gst'] = (strtolower($emp_data['relationship']) == 'self' ? ((float) number_format(($emp_data['policy_details']['rata_premimum'] * (18/100)),2,'.','')) : 0); + + break; + } + } + break; + + default: + echo "Not a valid grid"; + } + + // unset($emp_data['temp']);//remove temp data + return $emp_data; + + } +} + + +if (!function_exists('calculate_pro_rata_premimum')) +{ + function calculate_pro_rata_premimum($premium,$days) + { + return (float) number_format(($premium / 365) * $days,2,'.',''); + } +} + +//transform db columns into excel rows with indexs +if (!function_exists('transform_db_data_to_excel')) +{ + function transform_db_data_to_excel($familiyArr,$actionArr = []) + { + // if($actionArr['action'] == 'dependent_addition') + // { + $return_data = []; + + foreach ($familiyArr as $key => $value) + { + // dd($value); + $row = []; + $row[0] = ($key + 1); + $row[6] = $value['basic_cover_si']; + $row[14] = $value['pre_existing_alignments']; + $row[16] = isset($value['date_of_exit']) ? change_date_format($value['date_of_exit'], 'Y-m-d', 'd-M-Y') : NULL; + $row[17] = $value['reason_for_exit']; + + + $row[7] = isset($value['date_coverage']) ? change_date_format($value['date_coverage'], 'Y-m-d', 'd-M-Y') : NULL; + + $row[1] = $value['emp_code']; + $row[2] = $value['name']; + $row[3] = isset($value['dob']) ? change_date_format($value['dob'], 'Y-m-d', 'd-M-Y') : NULL; + $row[4] = $value['gender']; + $row[5] = $value['relationship']; + + $row[8] = isset($value['doj']) ? change_date_format($value['doj'], 'Y-m-d', 'd-M-Y') : NULL; + $row[9] = $value['basic_pay']; + $row[10] = $value['band']; + $row[11] = $value['designation']; + $row[12] = $value['mobile']; + $row[13] = $value['email_corporate']; + // $actionArr['id'] = $value['file_id']; + // $actionArr['client_id'] = $value['client_id']; + $row[15] = $value['change_event']; + $row['current_action'] = 'DA'; + $row['temp']['source'] = 'db'; + $row['temp']['emp_id'] = $value['emp_id']; + $row['temp']['emp_policy_id'] = $value['emp_policy_id']; + + array_push($return_data, ($row)); + } + + return $return_data; + // } + + + } +} \ No newline at end of file diff --git a/app/Helpers/session_helper.php b/app/Helpers/session_helper.php index b42f04e7..29255bcc 100644 --- a/app/Helpers/session_helper.php +++ b/app/Helpers/session_helper.php @@ -19,6 +19,15 @@ if (!function_exists('get_session_userid')) { } } +if (!function_exists('get_session_userdata')) { + function get_session_userdata() + { + // $ci =& get_instance(); + $session = \Config\Services::session(); + return $session->get('userData'); + } +} + if (!function_exists('get_session_user')) { function get_session_user() { diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index ce5de4c4..26c7aa08 100644 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -44,37 +44,29 @@ if (!function_exists('change_date_format')) { } if (!function_exists('file_Upload')) { - function file_Upload($fileToUpload, $imageDetails = null) + function file_Upload($fileToUpload, $filepath) { - // Retrieve the name of the file - $fileName = $fileToUpload->getName(); - - // Check if the file is not null and has a name - if ($fileToUpload !== null && $fileName !== "") { - // Check if the file is valid and has not been moved already - if ($fileToUpload->isValid() && !$fileToUpload->hasMoved()) { - // Construct the path where the image should exist - $existingImagePath = ROOTPATH . 'public/uploads/logo/' . $imageDetails; - - // Check if imageDetails is not null and if the image exists in the upload folder - if ($imageDetails !== null && file_exists($existingImagePath)) { - // If the image exists, delete it - unlink($existingImagePath); - } - - // Move the new image to the upload folder - $fileToUpload->move(ROOTPATH . 'public/uploads/logo', $fileName); - } + if ($fileToUpload !== null && $fileToUpload->isValid() && !$fileToUpload->hasMoved()) { + $fileName = $fileToUpload->getName(); + $fileToUpload->move($filepath, $fileName); + return $fileName; } else { - // Set fileName to empty string if file is null or doesn't have a name - $fileName = ""; + return ""; } - - // Return the file name - return $fileName; } } +if (!function_exists('file_unlink')) { + function file_unlink($filepath) + { + if (is_file($filepath) && file_exists($filepath)) { + unlink($filepath); + } + } +} + + + if (!function_exists('compressImage')) { function compressImage($file, $destinationPath, $newWidth = 100, $newHeight = 100) { diff --git a/app/Models/BatchFileModel.php b/app/Models/BatchFileModel.php index d97a7391..119a73aa 100644 --- a/app/Models/BatchFileModel.php +++ b/app/Models/BatchFileModel.php @@ -22,4 +22,38 @@ class BatchFileModel extends Model "updated_by", "is_active", ]; + + // Callbacks + protected $allowCallbacks = true; + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $afterInsert = []; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + protected $afterUpdate = []; + protected $beforeFind = []; + protected $afterFind = []; + protected $beforeDelete = []; + protected $afterDelete = []; + + protected function checkAndADDCreatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['created_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['created_by'] = get_session_userid(); + } + + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['updated_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['updated_by'] = get_session_userid(); + } + + return $data; + } + } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index ff437dc1..053e6f25 100644 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -37,6 +37,8 @@ class ClientPolicyModel extends Model "created_by", "updated_by", "Is_active", + "date_of_exit", + "reason_for_exit" ]; public function getClientPolicyById($id){ @@ -99,11 +101,11 @@ class ClientPolicyModel extends Model } - public function getPolicyTermsJson($client_id,$policy_id) + public function getPolicyDetails($client_id,$policy_id) { - return $this->select('policy_terms') + return $this->select('*') ->where('client_id',$client_id) - ->where('policy_id',$policy_id) + ->where('id',$policy_id) ->get() ->getResult(); diff --git a/app/Models/EmpEndorsementModel.php b/app/Models/EmpEndorsementModel.php index 26272fea..b6956259 100644 --- a/app/Models/EmpEndorsementModel.php +++ b/app/Models/EmpEndorsementModel.php @@ -10,7 +10,7 @@ class EmpEndorsementModel extends Model protected $primaryKey = 'id'; protected $allowedFields = [ 'id', - 'emp_id', + 'pk', 'endorsement_id', 'emp_code', 'table_name', @@ -19,10 +19,12 @@ class EmpEndorsementModel extends Model 'field_name', 'old_value', 'new_value', + 'date_of_correction', 'status', "created_by", "updated_by", "is_active", + "remarks" ]; } diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 5a564363..914c623b 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -13,6 +13,8 @@ class EmployeeModel extends Model "client_id", "employee_id", "change_event", + "relationship", + "relationship_code", "relationship_id", "relationship", "batch_id", @@ -24,6 +26,8 @@ class EmployeeModel extends Model "gender", "dob", "doj", + "basic_pay", + "band","designation", "otp", "family_floater_key", "emp_status", @@ -31,8 +35,87 @@ class EmployeeModel extends Model "updated_by", "updated_at", "is_active", + "file_id" ]; + // Callbacks + protected $allowCallbacks = true; + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $afterInsert = []; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + protected $afterUpdate = []; + protected $beforeFind = []; + protected $afterFind = []; + protected $beforeDelete = []; + protected $afterDelete = []; + + protected function checkAndADDCreatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['created_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['created_by'] = get_session_userid(); + } + + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['updated_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['updated_by'] = get_session_userid(); + } + + return $data; + } + + + + // for emp onboard process do not change + public function checkExistingEmp($arr) + { + + return $this->where('emp_code',$arr['emp_code']) + ->where('name',$arr['name']) + ->where('client_id',$arr['client_id']) + // ->where('relationship_code',$arr['relationship_code']) + ->where('gender',$arr['gender']) + ->where('dob',$arr['dob']) + ->find(); + } + + + public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,string $emp_status = null) + { + $result = $this->select(['employees.id as emp_id', 'employees.client_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit']) + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employees.is_active',1) + ->when($client_policy_id, function($query) use ($client_policy_id){ + return $query->where('employee_polices.client_policy_id',$client_policy_id); + }) + + ->where('employee_polices.is_active',1) + ->where('employees.emp_status', ($emp_status !== null ? $emp_status : 'active')) + // ->where('employees.emp_code',$emp_code) + ->when($emp_code, function($query) use ($emp_code){ + return $query->where('employees.emp_code',$emp_code); + + }) + // ->when($emp_status, function($query) use ($emp_status){ + // $emp_status = ($emp_status !== null ? $emp_status : 'active'); + // dd($emp_status); + // return $query->where('employees.emp_status', $emp_status); + // }) + ->when($client_id, function($query) use ($client_id){ + return $query->where('employees.client_id',$client_id); + }) + ->findAll(); + // dd($this->db->getLastQuery()); + + return ($result); + } @@ -48,16 +131,10 @@ class EmployeeModel extends Model ->getResult(); } - - - // for EMP rest API process do not change public function checkExistingEmployee($arr) { return $this->where('emp_code',$arr['emp_code'])->where('name',$arr['name'])->where('client_id', $arr['client_id'])->first(); } - - - } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 2eadf306..94a6e80e 100644 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -33,7 +33,40 @@ class EmployeePolicyModel extends Model "is_active", ]; + // Callbacks + protected $allowCallbacks = true; + protected $beforeInsert = ["checkAndADDCreatedByValue"]; + protected $afterInsert = []; + protected $beforeUpdate = ["checkAndUpdateUpdatedByValue"]; + protected $afterUpdate = []; + protected $beforeFind = []; + protected $afterFind = []; + protected $beforeDelete = []; + protected $afterDelete = []; + protected function checkAndADDCreatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['created_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['created_by'] = get_session_userid(); + } + + return $data; + } + + protected function checkAndUpdateUpdatedByValue(array $data) + { + // Check if 'updated_by' value is null or empty + if (empty($data['data']['updated_by'])) { + // Set 'updated_by' value to the current session user ID + $data['data']['updated_by'] = get_session_userid(); + } + + return $data; + } + +// ----------------------------------------------------------------------------------------------------- public function getEmployeePolicy($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']) @@ -51,36 +84,52 @@ class EmployeePolicyModel extends Model return ($result); } + + + //for emp onboard do not change + public function checkExistingEmpPolicy($arr) + { + return $this->where('employee_id',$arr['employee_id']) + ->where('client_policy_id',$arr['client_policy_id']) + ->find(); + } + //------------------------------------------------------------------ - public function getInceptionEmployeeDataForExportExcel($client_policy_id, $insurer_or_tpa, $event_type) - { - return $this->db->table('employee_polices') - ->select('employees.name AS emp_name, - employees.emp_code AS emp_code, - employees.dob AS emp_dob, - employees.gender AS emp_gender, - employees.change_event AS change_event, - employees.relationship AS emp_relationship, - employees.relationship_code AS emp_relationship_code, - TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age, - "Has Define" as emp_type, - employee_polices.id as primaryKey, - employee_polices.pre_existing_alignments, - employee_polices.basic_cover_si, - employee_polices.date_coverage, - employee_polices.policy_end_date, - employee_polices.days, - employee_polices.premium, - employee_polices.rata_premimum, - employee_polices.gst, - (employee_polices.rata_premimum + employee_polices.gst) AS total, - batch_data.emp_policy_id, - batch_data.bl AS batch_list_batch_code, - batch_data.bf AS batch_files_batch_code') - ->join('employees', 'employees.id = employee_polices.employee_id', 'left') - ->join("( + public function getInceptionEmployeeDataForExportExcel($ref_data) + { + $client_policy_id = $ref_data['client_policy_id']; + $insurer_or_tpa = $ref_data['insurer_or_tpa']; + + $sql = " + SELECT + employees.name AS emp_name, + employees.emp_code AS emp_code, + employees.dob AS emp_dob, + employees.gender AS emp_gender, + employees.change_event AS change_event, + employees.relationship AS emp_relationship, + employees.relationship_code AS emp_relationship_code, + TIMESTAMPDIFF(YEAR, employees.dob, CURDATE()) AS emp_age, + 'Has Define' as emp_type, + + employee_polices.id as primaryKey, + employee_polices.pre_existing_alignments, + employee_polices.basic_cover_si, + employee_polices.date_coverage, + employee_polices.policy_end_date, + employee_polices.days, + employee_polices.premium, + employee_polices.rata_premimum, + employee_polices.gst, + (employee_polices.rata_premimum + employee_polices.gst) AS total, + batch_data.emp_policy_id, + batch_data.bl AS batch_list_batch_code, + batch_data.bf AS batch_files_batch_code + FROM employee_polices + LEFT JOIN employees ON employees.id = employee_polices.employee_id + LEFT JOIN ( SELECT batch_list.emp_policy_id, batch_list.batch_code as bl, @@ -89,19 +138,29 @@ class EmployeePolicyModel extends Model LEFT JOIN batch_list ON batch_files.batch_code = batch_list.batch_code WHERE batch_files.event_type = 'inception' AND batch_files.actions = 'export' - AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}') as batch_data", 'employee_polices.id = batch_data.emp_policy_id', 'left') - ->where('batch_data.bf', null) - ->where('batch_data.bl', null) - ->where('employee_polices.client_policy_id', $client_policy_id) - ->where('employee_polices.is_active', 1) - ->get() - ->getResult(); + AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}' + ) as batch_data ON employee_polices.id = batch_data.emp_policy_id + WHERE batch_data.bf IS NULL + AND batch_data.bl IS NULL + AND employee_polices.client_policy_id = '{$client_policy_id}' + AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id = '') + AND (employee_polices.uhid IS NULL OR employee_polices.uhid = '') + AND employee_polices.is_active = 1"; + + // Get the result set + $query = $this->db->query($sql); + $results = $query->getResult(); + return $results; } - public function getCorrectionEmployeesDataForExportExcel($client_id, $client_policy_id, $insurer_or_tpa) + public function getCorrectionEmployeesDataForExportExcel($ref_data) { + $client_id = $ref_data['client_id']; + $client_policy_id = $ref_data['client_policy_id']; + $insurer_or_tpa = $ref_data['insurer_or_tpa']; + $sql = " SELECT DISTINCT emp_endorsement.id, @@ -162,7 +221,12 @@ class EmployeePolicyModel extends Model } - public function getSIEnhancementEmployeesDataForExportExcel($client_id, $client_policy_id, $insurer_or_tpa){ + public function getSIEnhancementEmployeesDataForExportExcel($ref_data) + { + + $client_id = $ref_data['client_id']; + $client_policy_id = $ref_data['client_policy_id']; + $insurer_or_tpa = $ref_data['insurer_or_tpa']; $query = $this->db->query(" SELECT @@ -177,7 +241,7 @@ class EmployeePolicyModel extends Model employee_polices.pre_existing_alignments, employee_polices.policy_end_date, employee_polices.basic_cover_si as old_basic_cover_si, - employee_polices.premium as old_si_premium, + employee_polices.rata_premimum as old_si_premium, batch_data.emp_policy_id, batch_data.bl AS batch_list_batch_code, batch_data.bf AS batch_files_batch_code, @@ -185,10 +249,10 @@ class EmployeePolicyModel extends Model sidata.new_si_premium, sidata.date_of_coverage, DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1 AS no_of_days, - sidata.new_si_premium - employee_polices.premium AS difference_premium, - ROUND((sidata.new_si_premium - employee_polices.premium) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premimum, - ROUND(((sidata.new_si_premium - employee_polices.premium) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst, - ((sidata.new_si_premium - employee_polices.premium) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) + ROUND(((sidata.new_si_premium - employee_polices.premium) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS total + sidata.new_si_premium - employee_polices.rata_premimum AS difference_premium, + ROUND((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365, 2) AS pro_rata_premimum, + ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS gst, + ((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) + ROUND(((sidata.new_si_premium - employee_polices.rata_premimum) * (DATEDIFF(employee_polices.policy_end_date, sidata.date_of_coverage) + 1) / 365) * 0.18, 2) AS total FROM emp_endorsement a @@ -263,7 +327,12 @@ class EmployeePolicyModel extends Model } - public function getDeletionEmployeeDataForExportExcel($client_id, $client_policy_id, $insurer_or_tpa){ + public function getDeletionEmployeeDataForExportExcel($ref_data) + { + + $client_id = $ref_data['client_id']; + $client_policy_id = $ref_data['client_policy_id']; + $insurer_or_tpa = $ref_data['insurer_or_tpa']; $query = $this->db->query(" SELECT @@ -278,7 +347,7 @@ class EmployeePolicyModel extends Model employee_polices.basic_cover_si, employee_polices.uhid as risk_id, employee_polices.policy_end_date, - employee_polices.premium, + employee_polices.rata_premimum as premium, batch_data.emp_policy_id AS emp_policy_id, batch_data.bl AS batch_list_batch_code, @@ -291,9 +360,9 @@ class EmployeePolicyModel extends Model deletiondata.status, DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit) AS no_of_days, - ROUND((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365, 2) AS pro_rata_premium, - ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18, 2) AS gst, - ROUND(((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) + (((employee_polices.premium * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18), 2) AS total + ROUND((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365, 2) AS pro_rata_premium, + ROUND(((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18, 2) AS gst, + ROUND(((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) + (((employee_polices.rata_premimum * DATEDIFF(employee_polices.policy_end_date, deletiondata.dateofexit)) / 365) * 0.18), 2) AS total FROM emp_endorsement a LEFT JOIN @@ -330,12 +399,12 @@ class EmployeePolicyModel extends Model WHERE batch_files.event_type = 'deletion' AND batch_files.actions = 'export' - AND batch_files.insurer_or_tpa = 'insurer' + AND batch_files.insurer_or_tpa = '{$insurer_or_tpa}' ) AS batch_data ON employee_polices.id = batch_data.emp_policy_id WHERE batch_data.bf IS NULL AND batch_data.bl IS NULL - AND employee_polices.client_policy_id = 12 + AND employee_polices.client_policy_id = {$client_policy_id} AND employee_polices.is_active = 1 AND (a.endorsement_id IS NULL OR a.endorsement_id = '') AND a.field_name = 'status' "); @@ -346,35 +415,37 @@ class EmployeePolicyModel extends Model } - public function updateTPAIDorUHID( $client_policy_id, $client_id, $name, $emp_code, $uhid, $tpa_id) - { + public function updateTPAIDorUHID($update_data) + { + $client_id = $update_data['client_id']; + $client_policy_id = $update_data['client_policy_id']; + $name = $update_data['name']; + $emp_code = $update_data['emp_code']; + $uhid = $update_data['uhid']; + $tpa_id = $update_data['tpa_id']; - // $this->table('employee_polices') - // ->join('employees', 'employees.id = employee_polices.employee_id') - // ->set('employee_polices.tpa_id', $tpa_id) - // ->set('employee_polices.uhid', $uhid) - // ->where('employees.emp_code', $emp_code) - // ->where('employees.name', $name) - // ->where('employees.client_id', $client_id) - // ->where('employee_polices.client_policy_id', $client_policy_id) - // ->update(); - - $query = "UPDATE employee_polices + $query = " + UPDATE employee_polices JOIN employees ON employees.id = employee_polices.employee_id SET employee_polices.tpa_id = '{$tpa_id}', employee_polices.uhid = '{$uhid}' WHERE employees.emp_code = '{$emp_code}' AND employees.name = '{$name}' AND employees.client_id = '{$client_id}' - AND employee_polices.client_policy_id = '{$client_policy_id}'"; + AND employee_polices.client_policy_id = '{$client_policy_id}' + "; $this->query($query); - } - public function updateCorrectionData($emp_code, $uhid, $endorsement_id){ + public function updateCorrectionData($update_data) + { + + $emp_code = $update_data['emp_code']; + $uhid = $update_data['uhid']; + $endorsement_id = $update_data['tpa_id']; $sql = " UPDATE emp_endorsement @@ -388,8 +459,38 @@ class EmployeePolicyModel extends Model } - public function updateEndoresmentIdForSIEnhancement($emp_code, $client_id, $client_policy_id, $emp_name, $endorsement_id){ + public function updateEndoresmentIdForSIEnhancement($update_data){ + $client_id = $update_data['client_id']; + $client_policy_id = $update_data['client_policy_id']; + $emp_name = $update_data['name']; + $emp_code = $update_data['emp_code']; + $endorsement_id = $update_data['uhid']; + + $sql = " + UPDATE emp_endorsement + JOIN employee_polices ON employee_polices.id = emp_endorsement.pk + JOIN employees ON employee_polices.employee_id = employees.id + SET emp_endorsement.endorsement_id = '$endorsement_id' + WHERE emp_endorsement.emp_code = '$emp_code' + AND employees.client_id = '$client_id' + AND employee_polices.client_policy_id = '$client_policy_id' + AND emp_endorsement.actions = 'si' + AND emp_endorsement.name = '$emp_name' + "; + $query = $this->query($sql); + + } + + + public function updateEndoresmentIdForDeletion($update_data){ + + $client_id = $update_data['client_id']; + $client_policy_id = $update_data['client_policy_id']; + $emp_name = $update_data['name']; + $emp_code = $update_data['emp_code']; + $endorsement_id = $update_data['uhid']; + $sql = " UPDATE emp_endorsement JOIN employee_polices ON employee_polices.id = emp_endorsement.pk @@ -404,24 +505,12 @@ class EmployeePolicyModel extends Model } - public function updateEndoresmentIdForDeletion($emp_code, $client_id, $client_policy_id, $emp_name, $endorsement_id){ - - $sql = " - UPDATE emp_endorsement - JOIN employee_polices ON employee_polices.id = emp_endorsement.pk - JOIN employees ON employee_polices.employee_id = employees.id - SET emp_endorsement.endorsement_id = '$endorsement_id' - WHERE employees.emp_code = '$emp_code' - AND employees.client_id = '$client_id' - AND employee_polices.client_policy_id = '$client_policy_id' - AND employees.name = '$emp_name' - "; - $query = $this->query($sql); - } - - - public function fetchEmpEndorsementData($emp_code, $client_policy_id, $emp_name) + public function fetchEmpEndorsementData($fetch_data) { + $client_policy_id = $fetch_data['client_policy_id']; + $emp_name = $fetch_data['name']; + $emp_code = $fetch_data['emp_code']; + // Your raw SQL query $sql = " SELECT @@ -449,13 +538,13 @@ class EmployeePolicyModel extends Model } - //for emp onboard do not change - public function checkExistingEmpPolicy($arr) - { - return $this->where('employee_id',$arr['employee_id']) - ->where('client_policy_id',$arr['client_policy_id']) - ->find(); - } + // //for emp onboard do not change + // public function checkExistingEmpPolicy($arr) + // { + // return $this->where('employee_id',$arr['employee_id']) + // ->where('client_policy_id',$arr['client_policy_id']) + // ->find(); + // } public function updateSiAndPremium( $client_policy_id, $employee_id,$basic_cover_si,$premium) @@ -472,4 +561,5 @@ class EmployeePolicyModel extends Model } //------------------------------------------------------------------ + } diff --git a/app/Models/PolicesModel.php b/app/Models/PolicesModel.php index 70724d71..9f0a2718 100644 --- a/app/Models/PolicesModel.php +++ b/app/Models/PolicesModel.php @@ -5,6 +5,9 @@ use App\Models\PolicyPremium1Model; use App\Models\PolicyPremium2Model; use App\Models\PolicyGridModel; use CodeIgniter\Model; +use App\Models\PolicyGridModel; +use App\Models\PolicyPremium1Model; +use App\Models\PolicyPremium2Model; class PolicesModel extends Model { @@ -32,23 +35,26 @@ class PolicesModel extends Model } - - public function getPolicySlabRatesForEmpOnboard($policy_id,$client_id) - { - $premium_slab_data = null; - $policyPremium1Model = new PolicyPremium1Model(); - $premium_slab_data = $policyPremium1Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); - - if((!count($premium_slab_data))) - { - $policyPremium2Model = new PolicyPremium2Model(); - $premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); - - } - $grid_id = $premium_slab_data[0]['policy_grid_id']; - $policyGridModel = new PolicyGridModel(); - $results = $policyGridModel->find($grid_id); - return ['slab_rates' => $premium_slab_data,'grid_master' => $results]; + public function getPolicySlabRatesForEmpOnboard($policy_id,$client_id) + + { + + $premium_slab_data = null; + + $policyPremium1Model = new PolicyPremium1Model(); + $premium_slab_data = $policyPremium1Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); + // dd($premium_slab_data); + if(is_array($premium_slab_data) && !count($premium_slab_data)) + { + // echo '2'; + $policyPremium2Model = new PolicyPremium2Model(); + $premium_slab_data = $policyPremium2Model->where(['client_id' => $client_id, 'client_policy_id' => $policy_id, 'is_active' => 1])->findAll(); + } + + $grid_id = $premium_slab_data[0]['policy_grid_id']; + $policyGridModel = new PolicyGridModel(); + $results = $policyGridModel->find($grid_id); + return ['slab_rates' => $premium_slab_data,'grid_master' => $results]; } } diff --git a/app/Views/batch_list.php b/app/Views/batch_list.php new file mode 100644 index 00000000..2e31acd9 --- /dev/null +++ b/app/Views/batch_list.php @@ -0,0 +1,47 @@ +
+
+
+
+
+

Batch List

+
+ +
+ + + + + + + + + + + + + + + + $file) { + ?> + + + + + + + + + + + + + + +
SNOBatch CodeClientClient PolicyEvent TypeInsurer/TPAActionCount
+
+
+
\ No newline at end of file diff --git a/app/Views/client_basic_info.php b/app/Views/client_basic_info.php index 562b3ae1..62420438 100644 --- a/app/Views/client_basic_info.php +++ b/app/Views/client_basic_info.php @@ -107,7 +107,7 @@

- Image dimensions 100 x 100 pixels and size of 200KB. + ( Image dimensions 100 x 100 pixels and size of 200KB. )
" width="100" height="100" id="uploadPreview" class="avatar img-circle img-thumbnail" alt="avatar"/> @@ -198,7 +198,7 @@ $(document).ready(function () { $('#client_id_relation').val(res.data.id); $('#relation_PrimaryKey').val(res.data.id); $('#client_id_branch').val(res.data.id); - $('#branch_PrimaryKey').val(res.data.id); + $('#client_id_for_client_branch').val(res.data.id); $('#client_id_policy').val(res.data.id); $('#policy_PrimaryKey').val(res.data.id); $('#client_id_kyc').val(res.data.id); @@ -229,7 +229,7 @@ $(document).ready(function () {
- +
diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index c050dbc6..fafb06ba 100644 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -1,5 +1,5 @@
- +
@@ -31,8 +31,8 @@
- +
@@ -65,7 +65,8 @@ placeholder="Enter District" name="district" required>
- +
@@ -116,17 +117,16 @@
+ \ No newline at end of file diff --git a/app/Views/insurer_basic_info.php b/app/Views/insurer_basic_info.php index 8abe76d4..3a48d493 100644 --- a/app/Views/insurer_basic_info.php +++ b/app/Views/insurer_basic_info.php @@ -22,7 +22,7 @@
-
diff --git a/app/Views/insurer_branch.php b/app/Views/insurer_branch.php index 638abe01..ab4c23e4 100644 --- a/app/Views/insurer_branch.php +++ b/app/Views/insurer_branch.php @@ -67,7 +67,8 @@ placeholder="Enter District" name="district" required>
- +
@@ -123,99 +124,101 @@ \ No newline at end of file diff --git a/app/Views/insurer_or_tpa_data.php b/app/Views/insurer_or_tpa_data.php index b3318f13..91c63f58 100644 --- a/app/Views/insurer_or_tpa_data.php +++ b/app/Views/insurer_or_tpa_data.php @@ -1,111 +1,135 @@
-
-
-
- - - -
-
-
-
- -
+
+
+
+
+ + + +
+
+
+ + + +
+
+
+
+ +
-
-
- -
+
+
+ +
-
-
- + + $action) + { + echo ""; + } + } + ?> + +
+
+ +
+ +
+
+ +
+ +
+
+ -
-
+ +
-
+
-
-
- -
+
-
-
- -
+
+
+ + +
+
+
+ +
+
+
-
- -
- -
-
- - -
-
-
- +
+
+
+ +
+
-
- -
-
-
- -
-
-
+
- +
+
+ + +
+ +
+
@@ -116,11 +140,11 @@ var clientPolicies = []; $(document).ready(function() { has('error')): ?> - toastr.error('getFlashdata('error') ?>', 'Failed'); + toastr.error('getFlashdata('error') ?>', 'Failed'); has('success')): ?> - toastr.success('getFlashdata('success') ?>', 'success'); + toastr.success('getFlashdata('success') ?>', 'success'); $('#import_excel_btn').hide(); @@ -165,7 +189,7 @@ $(document).ready(function() { $('.loader-mask').delay(350).fadeOut('slow'); $$("#import_export_excel_form")[0].reset() toastr.success('File Download successs', 'success'); - + } else if (response.code === 404 && response.status === false) { console.error('no data found', response); @@ -330,5 +354,12 @@ $('#action_type').change(function() { } }); + +document.getElementById('toggleIcon').addEventListener('click', function() { + var icon = document.getElementById('icon'); + icon.classList.toggle('mdi-chevron-down'); + icon.classList.toggle('mdi-chevron-up'); +}); + //-------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index f69de0f3..c59073f7 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -393,8 +393,8 @@
+ placeholder="Enter Allocg" value="" name="allocg" required>