From 934823b6de1ba47db4d2ba17c0670e9d8c2b534d Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 27 Mar 2024 09:23:11 +0530 Subject: [PATCH] FIX_MASTER_BRANCH_ISSUE_RESOLVED : RV --- app/Controllers/ClientController.php | 14 +- app/Controllers/EmpDataServiceController.php | 1217 +++++++++++++----- app/Controllers/EmployeeController.php | 425 ++---- app/Controllers/MasterController.php | 53 +- app/Helpers/excel_import_export_helper.php | 19 +- app/Helpers/utility_helper.php | 42 +- app/Models/BatchFileModel.php | 34 + app/Models/EmployeeModel.php | 34 +- app/Models/EmployeePolicyModel.php | 244 ++-- app/Views/batch_list.php | 47 + app/Views/client_basic_info.php | 6 +- app/Views/client_branch.php | 42 +- app/Views/client_kyc.php | 4 +- app/Views/employee_upload.php | 187 +-- app/Views/insurer_basic_info.php | 2 +- app/Views/insurer_branch.php | 441 +++---- app/Views/insurer_or_tpa_data.php | 209 +-- app/Views/policies.php | 7 +- app/Views/policy_type_basic_info.php | 4 +- app/Views/policy_type_list.php | 2 +- 20 files changed, 1771 insertions(+), 1262 deletions(-) create mode 100644 app/Views/batch_list.php diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index b83853fc..1147796d 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(); 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..0c72a75e 100644 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -191,7 +191,7 @@ 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['import_or_export'] = ['import' => 'Import','export' =>'Export']; $data['insurer_or_tpa'] = ['insurer' => 'Insurer','tpa' =>'TPA']; $data['fileList'] = $this->fileModel @@ -200,6 +200,14 @@ class EmployeeController extends AdminController ->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(); + + $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 +230,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 +272,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 +307,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 +355,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/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/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/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/EmployeeModel.php b/app/Models/EmployeeModel.php index 5a564363..589d1a49 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -33,9 +33,41 @@ class EmployeeModel 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($id) { diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 2eadf306..8e59ce88 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,41 @@ class EmployeePolicyModel extends Model return ($result); } - //------------------------------------------------------------------ +//------------------------------------------------------------------ - 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, + public function getInceptionEmployeeDataForExportExcel($ref_data) + { + $client_policy_id = $ref_data['client_policy_id']; + $insurer_or_tpa = $ref_data['insurer_or_tpa']; - 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("( + $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 +127,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 +210,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 +230,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 +238,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 +316,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 +336,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 +349,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 +388,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 +404,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 +448,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 +494,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 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/policies.php b/app/Views/policies.php index 02944b17..f9fea440 100644 --- a/app/Views/policies.php +++ b/app/Views/policies.php @@ -37,7 +37,7 @@
+ placeholder="Enter Policy Type Name" value="" name="policy_type" required>
+ placeholder="Enter Allocg" value="" name="allocg" required>