From f888db293289afc8605a7d930fdda4b1666581e6 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 5 Sep 2025 11:26:35 +0530 Subject: [PATCH] FIX_CLAIM_CLIENT_EMP_SEARCH_ISSUE : RV --- app/Config/Routes.php | 6 +- app/Controllers/ClientController.php | 80 ++++++++---- app/Controllers/TestingController.php | 178 ++++++++++++++++++++++++++ app/Views/ticket_form_handler.php | 7 +- 4 files changed, 241 insertions(+), 30 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d74d1d3f..9243bbba 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -364,7 +364,8 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('transformMailContent', 'LeadsController::transformMailContent'); $routes->get('getCDAmount', 'ClientController::getCDAmount'); $routes->get('getTheEmpDataForClaim/(:any)', 'ClientController::getTheEmpDataForClaim/$1'); - $routes->get('getTheEmpDataForClaimSearchByMobile/(:any)', 'ClientController::getTheEmpDataForClaimSearchByMobile/$1'); + // $routes->get('getTheEmpDataForClaimSearchByMobile/(:any)', 'ClientController::getTheEmpDataForClaimSearchByMobile/$1'); + $routes->get('getTheEmpDataForClaimSearchByMobile', 'ClientController::getTheEmpDataForClaimSearchByMobile'); $routes->get('getLeadNonEB/(:any)', 'LeadsController::getLeadNonEB/$1'); $routes->get('getPolicyTypeFields', 'LeadsController::getPolicyTypeFields'); $routes->get('removeMultiFile', 'LeadsController::removeMultiFile'); @@ -674,6 +675,9 @@ $routes->get("ticketHistoryList", "ThzController::ticketHistoryList"); $routes->group('test', function($routes) { $routes->post('api/saveForm', 'TestingController::saveForm'); $routes->get('insurerRFQRemainder', 'LeadsController::remainderForQcr'); + $routes->get('ecard/generate-pdf', 'TestingController::generatePDF'); + $routes->get('view-pdf', 'TestingController::viewPDF'); + $routes->get('generate-pdf-view', 'TestingController::generatePDFWithView'); }); $routes->cli('cli/testcli', 'TestingController::testcli'); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index d3120770..b7a4d343 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -5405,7 +5405,8 @@ class ClientController extends AdminController employees.mobile AS emp_mobile, employees.email_corporate AS emp_email, employees.relationship AS emp_relationship, - employee_polices.uhid AS policy_no + employee_polices.uhid AS policy_no, + employee_polices.client_policy_id ") ->join('clients', 'client_policy.client_id = clients.id', 'left') ->join('insurers', 'client_policy.insurer_id = insurers.id', 'left') @@ -5418,9 +5419,15 @@ class ClientController extends AdminController ->where('employees.is_active', 1) ->where('employees.relationship', "Self") ->where('employee_polices.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->whereIn('employee_polices.status', ['active']) + ->where('employees.is_active', 1) ->where('client_policy.id', $param) + ->groupBy('employees.emp_code') ->get() ->getResultArray(); + + // print_r(db_connect()->getLastQuery()); die; $dataForClientAndInsurer = $this->clientPolicyModel ->select(" @@ -5462,20 +5469,39 @@ class ClientController extends AdminController 'memberData' => $memberData ], 404); } - } - - public function getTheEmpDataForClaimSearchByMobile($param, $type = 'mobile', $client_policy_id = null, $client_id = null, $ticket_type_id = null) - { + } + + // public function getTheEmpDataForClaimSearchByMobile($param, $type = 'mobile', $client_policy_id = null, $client_id = null, $ticket_type_id = null) + public function getTheEmpDataForClaimSearchByMobile() + { + + $request = $this->request; + + // Get parameters from GET request + $param = $request->getGet('param'); + $type = $request->getGet('type') ?? 'mobile'; + $client_policy_id = $request->getGet('client_policy_id'); + $client_id = $request->getGet('client_id'); + $ticket_type_id = $request->getGet('ticket_type_id'); + + // Validate required parameter + if (empty($param)) { + return $this->response->setJSON([ + 'status' => false, + 'message' => 'Parameter is required' + ])->setStatusCode(400); + } + $field_name = 'employees.' . $type; $policy_type_id = []; - if($ticket_type_id == 1){ + if ($ticket_type_id == 1) { $policy_type_id = [2, 3, 4, 5]; - }else if($ticket_type_id == 2){ + } else if ($ticket_type_id == 2) { $policy_type_id = [1]; - }else if($ticket_type_id == 3){ + } else if ($ticket_type_id == 3) { $policy_type_id = [6]; - }else if($ticket_type_id == 4){ + } else if ($ticket_type_id == 4) { $policy_type_id = [7]; } @@ -5513,24 +5539,24 @@ class ClientController extends AdminController ->where('employee_polices.status', "active") ->where($field_name, $param); - if (!empty($client_id)) { - $query->where('employees.client_id', $client_id); - } + if (!empty($client_id)) { + $query->where('employees.client_id', $client_id); + } - if (!empty($client_policy_id)) { - $query->where('employee_polices.client_policy_id', $client_policy_id); - } + if (!empty($client_policy_id)) { + $query->where('employee_polices.client_policy_id', $client_policy_id); + } - if($policy_type_id != null){ - $query->whereIn('client_policy.policy_type_id', $policy_type_id); - } - - $query->groupBy('employees.id') - ->orderBy('employees.id', 'DESC'); - - $data = $query->get()->getRowArray(); + if ($policy_type_id != null) { + $query->whereIn('client_policy.policy_type_id', $policy_type_id); + } - // print_r(db_connect()->getLastQuery()); die; + $query->groupBy('employees.id') + ->orderBy('employees.id', 'DESC'); + + $data = $query->get()->getRowArray(); + + // print_r(db_connect()->getLastQuery()); die; $memberData = []; $dataForClientAndInsurer = []; @@ -5541,15 +5567,15 @@ class ClientController extends AdminController // ->where('user_profiles.role', 3) // ->get() // ->getResultArray(); - - if(!empty($data) && count($data) > 0){ + + if (!empty($data) && count($data) > 0) { $memberData = $this->employeeModel->getEmployeeByEmployeeCode($data['emp_code'], $client_policy_id, $client_id); $acms_datas = $this->employeeModel->getAcmUsingClientID($data['client_id']); // if(!empty($acms_datas)){ // $acms = $acms_datas; // } - }else{ + } else { $acms_datas = ""; } diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php index 495c27d4..b2d6968b 100644 --- a/app/Controllers/TestingController.php +++ b/app/Controllers/TestingController.php @@ -5,6 +5,8 @@ namespace App\Controllers; use App\Controllers\BaseController; use CodeIgniter\HTTP\ResponseInterface; use CodeIgniter\API\ResponseTrait; +use Dompdf\Dompdf; +use Dompdf\Options; class TestingController extends BaseController { @@ -36,4 +38,180 @@ class TestingController extends BaseController log_message('error', 'test message for log_message_function'); echo "hi 3"; } + + + public function generatePDF() + { + // Sample data - replace with your actual data source + $data = [ + 'NAME' => 'John Doe', + 'GENDER' => 'Male', + 'DOB' => '01/01/1990', + 'RELATION' => 'Self', + 'POLICY_NO' => 'POL123456789', + 'TPA_ID' => 'TPA987654321', + 'POLICY_START_DATE' => '01/01/2024', + 'POLICY_DATE' => '31/12/2024', + 'INSURER_NAME' => 'ABC Insurance Co.', + 'TPA_NAME' => 'XYZ TPA Ltd.', + 'FRONT_CARD' => base_url('assets/images/front-card.jpg'), // Your card images + 'BACK_CARD' => base_url('assets/images/back-card.jpg'), + 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' + ]; + + // Load the HTML template + $html = $this->loadTemplate($data); + + // Configure DomPDF options + $options = new Options(); + $options->set('isRemoteEnabled', true); // Enable loading of remote images + $options->set('isHtml5ParserEnabled', true); + $options->set('isPhpEnabled', true); + $options->set('debugPng', false); + $options->set('debugKeepTemp', false); + $options->set('debugCss', false); + $options->set('debugLayout', false); + $options->set('debugLayoutLines', false); + $options->set('debugLayoutBlocks', false); + $options->set('debugLayoutInline', false); + $options->set('debugLayoutPaddingBox', false); + + // Initialize DomPDF + $dompdf = new Dompdf($options); + + // Load HTML content + $dompdf->loadHtml($html); + + // Set paper size and orientation + $dompdf->setPaper('A4', 'landscape'); // or 'portrait' + + // Render PDF + $dompdf->render(); + + // Output PDF to browser + $filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf'; + $dompdf->stream($filename, ['Attachment' => true]); // Set to false for inline view + } + + public function viewPDF() + { + // Same as generatePDF but with inline view + $data = [ + 'NAME' => 'John Doe', + 'GENDER' => 'Male', + 'DOB' => '01/01/1990', + 'RELATION' => 'Self', + 'POLICY_NO' => 'POL123456789', + 'TPA_ID' => 'TPA987654321', + 'POLICY_START_DATE' => '01/01/2024', + 'POLICY_DATE' => '31/12/2024', + 'INSURER_NAME' => 'ABC Insurance Co.', + 'TPA_NAME' => 'XYZ TPA Ltd.', + 'FRONT_CARD' => base_url('assets/images/front-card.jpg'), + 'BACK_CARD' => base_url('assets/images/back-card.jpg'), + 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' + ]; + + $html = $this->loadTemplate($data); + $options = new Options(); + $options->set('isRemoteEnabled', true); + $options->set('isHtml5ParserEnabled', true); + + $dompdf = new Dompdf($options); + $dompdf->loadHtml($html); + $dompdf->setPaper('A4', 'portrait'); + $dompdf->render(); + + $filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf'; + $dompdf->stream($filename, ['Attachment' => false]); // Inline view + } + + private function loadTemplate($data) + { + // Load your HTML template + $template = file_get_contents(WRITEPATH . 'e_card_template/common.html'); + + // Replace placeholders with actual data + foreach ($data as $key => $value) { + $template = str_replace('{' . $key . '}', $value, $template); + } + + return $template; + } + + // Alternative method using CodeIgniter's view system + public function generatePDFWithView() + { + $data = [ + 'NAME' => 'John Doe', + 'GENDER' => 'Male', + 'DOB' => '01/01/1990', + 'RELATION' => 'Self', + 'POLICY_NO' => 'POL123456789', + 'TPA_ID' => 'TPA987654321', + 'POLICY_START_DATE' => '01/01/2024', + 'POLICY_DATE' => '31/12/2024', + 'INSURER_NAME' => 'ABC Insurance Co.', + 'TPA_NAME' => 'XYZ TPA Ltd.', + 'FRONT_CARD' => base_url('assets/images/front-card.jpg'), + 'BACK_CARD' => base_url('assets/images/back-card.jpg'), + 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' + ]; + + // Load view with data + $html = view('ecard_template', $data); + + $options = new Options(); + $options->set('isRemoteEnabled', true); + $options->set('isHtml5ParserEnabled', true); + + $dompdf = new Dompdf($options); + $dompdf->loadHtml($html); + $dompdf->setPaper('A4', 'portrait'); + $dompdf->render(); + + $filename = 'ecard_' . date('Y-m-d_H-i-s') . '.pdf'; + $dompdf->stream($filename, ['Attachment' => true]); + } + + public function generatePDFById($id) + { + // Get data from database + $ecardData = []; + + if (!$ecardData) { + throw new \CodeIgniter\Exceptions\PageNotFoundException('E-card not found'); + } + + $data = [ + 'NAME' => $ecardData['name'], + 'GENDER' => $ecardData['gender'], + 'DOB' => $ecardData['dob'], + 'RELATION' => $ecardData['relation'], + 'POLICY_NO' => $ecardData['policy_no'], + 'TPA_ID' => $ecardData['tpa_id'], + 'POLICY_START_DATE' => $ecardData['policy_start_date'], + 'POLICY_DATE' => $ecardData['policy_end_date'], + 'INSURER_NAME' => $ecardData['insurer_name'], + 'TPA_NAME' => $ecardData['tpa_name'], + 'FRONT_CARD' => base_url('assets/images/front-card.jpg'), + 'BACK_CARD' => base_url('assets/images/back-card.jpg'), + 'LEVELS' => 'Level 1: 1800-XXX-XXXX
Level 2: support@company.com' + ]; + + $html = view('ecard_template', $data); + + $options = new Options(); + $options->set('isRemoteEnabled', true); + $options->set('isHtml5ParserEnabled', true); + + $dompdf = new Dompdf($options); + $dompdf->loadHtml($html); + $dompdf->setPaper('A4', 'landscape'); + $dompdf->render(); + + $filename = 'ecard_' . $ecardData['policy_no'] . '_' . date('Y-m-d') . '.pdf'; + $dompdf->stream($filename, ['Attachment' => true]); + } + } diff --git a/app/Views/ticket_form_handler.php b/app/Views/ticket_form_handler.php index e066d030..804639af 100644 --- a/app/Views/ticket_form_handler.php +++ b/app/Views/ticket_form_handler.php @@ -601,8 +601,11 @@ param = $(input).val(); client_id = $('#emp_client_data_list').val() } - let url = '' + param + '/' + type + '/' + - client_policy_id + '/' + client_id + '/'+ selected_ticket_type_id; + + // let url = '' + param + '/' + type + '/' + + // client_policy_id + '/' + client_id + '/'+ selected_ticket_type_id; + + let url = ''; // Data to send in the AJAX request let requestData = {