myLogger = \Config\Services::mylogger(); $this->employeeModel = new EmployeeModel(); $this->employeePolicyModel = new EmployeePolicyModel(); $this->clientModel = new ClientModel(); $this->fileModel = new FileModel(); $this->clientPolicyModel = new ClientPolicyModel(); $this->batchListModel = new BatchListModel(); $this->batchFileModel = new BatchFileModel(); $this->empEndorsementModel = new EmpEndorsementModel(); } public function batchFilesAndBatchListEntry($data, $objects){ $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; } /** * Generates an Excel file for Inception_Addititon_DependentAddititon, Correction, SI_Enhancement and Deletion events based on given export data. * * @param array $export_data An array containing export data such as * client_policy_id, * insurer_or_tpa, * event_type, * actions, * file_name. * @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']); // 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 } 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 = []) { $arrayData = array( array( 0 => 6, 1 => 10, 2 => 17, 3 => 101, 4 => 102 ), ); // Flatten the array to get all IDs in a single array $idArray = call_user_func_array('array_merge', $arrayData); // Select from the employee_policy table where the id is in the $idArray $results = $this->employeePolicyModel ->select('employee_polices.pro_rata_premium') ->whereIn('id', $idArray) ->get() ->getResultArray(); // Output the results print_r($results); die; } public function cashDepositCalculationForSIEnhancement($arrayData) { } public function cashDepositCalculationForDeletion($arrayData) { } // ----------------------------------------------------------------------------------- }