diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9ce825b5..5aea3a1f 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -842,3 +842,13 @@ $routes->group('bds_upload', function($routes) { $routes->get('getBdsDumpFileErrorData',"PolicyTransactionController::getBdsDumpFileErrorData"); $routes->get('getBdsDumpExcelFileErrors/(:any)',"PolicyTransactionController::getBdsDumpExcelFileErrors/$1"); }); + + +// ----------------------------------------------------------------------------------------------------------------- +$routes->group('logs', function($routes) { + $routes->get('/', 'LogController::index'); + $routes->get('view/(:segment)', 'LogController::view/$1'); + $routes->get('download/(:segment)', 'LogController::download/$1'); + $routes->get('delete/(:segment)', 'LogController::delete/$1'); + $routes->get('clearAll', 'LogController::clearAll'); +}); diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php index e2d1c5d7..b22a1470 100644 --- a/app/Controllers/ApiServiceController.php +++ b/app/Controllers/ApiServiceController.php @@ -45,9 +45,14 @@ class ApiServiceController extends BaseController $tpaID = $data['tpa_id']; - if ($tpaID == $this->medi_assist_primary_key) { // MediAssist + if ($tpaID == $this->medi_assist_primary_key) + { // MediAssist $mediAssistController = new MediAssistApiController(); return $mediAssistController->SubmitClaim($claimId); + }else if ($tpaID == $this->vidal_primary_key) + { // Vidal + $vidalApiController = new VidalApiController; + return $vidalApiController->SubmitClaim($claimId); }else{ log_message('error', "This ticket id ( {$claimId} ) TPA has no API service enabled. TPA ID : {$tpaID}"); } @@ -271,76 +276,65 @@ class ApiServiceController extends BaseController } - - - public function getWellnessUrl() + //wellness sso url generator landing + public function getWellnessUrl($emp_id) { - - $emp_id = $this->request->getGet('emp_id'); - $client_policy_id = $this->request->getGet('client_policy_id'); - + // $emp_id = $this->request->getGet('emp_id'); + $db = \Config\Database::connect(); - - // $data = $db->table('employees e') - // ->select('pt.policy_type, - // e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, - // cp.policy_no as policyNumber, cp.policy_no as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate') - // ->join('employee_polices ep', 'e.id = ep.employee_id') - // ->join('client_policy cp', 'ep.client_policy_id = cp.id') - // ->join('policy_type pt', 'cp.policy_type_id = pt.id') - // ->where('e.id', $emp_id) - // ->where('e.emp_status', 'active') - // ->where('ep.status', 'active') - // ->where('e.is_active', 1) - // ->where('ep.is_active', 1) - // ->get() - // ->getResultArray(); - - $data = $db->table('employee_polices ep') + $data = $db->table('employees e') ->select('pt.policy_type, - e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, e.id as employeeId - cp.policy_no as policyNumber, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate, cp.wellness_plan_id as planId') - ->join('employees e', 'e.id = ep.employee_id') + e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, + cp.policy_no as policyNumber, ep.employee_id as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate , cp.wellness_plan_id as planId , cp.wellness_vendor_id') + ->join('employee_polices ep', 'e.id = ep.employee_id') ->join('client_policy cp', 'ep.client_policy_id = cp.id') ->join('policy_type pt', 'cp.policy_type_id = pt.id') - ->where('ep.employee_id', $emp_id) - ->where('ep.client_policy_id', $client_policy_id) + ->where('e.id', $emp_id) + ->where('e.emp_status', 'active') ->where('ep.status', 'active') + ->where('e.is_active', 1) ->where('ep.is_active', 1) ->get() - ->getRow(); + ->getResultArray(); + - - $userParams = []; - if(!empty($data)) - { - $userParams['name'] = $data->name; - $userParams['email'] = $data->email; - $userParams['phone'] = $data->phone; - $userParams['memberId'] = $data->employeeId; // memberId is unique primary key. - $userParams['gender'] = $data->gender; - $userParams['dob'] = $data->dob; - $userParams['relation'] = $data->relation; - $userParams['policyNumber'] = $data->policyNumber; - $userParams['employeeId'] = $data->memberId; - $userParams['policyStartDate']= $data->policyStartDate; - $userParams['policyEndDate'] = $data->policyEndDate; - $userParams['policyName'] = 'Nhance ' . $data->policy_type; - $userParams['planId'] = $data->planId; - $userParams['moduleName'] = 'home'; + foreach ($data as $row) { + if($row['wellness_vendor_id'] != null) + { + $vidalApiController = new VidalApiController(); + return $vidalApiController->getWellnessSSORedirectUrl($row['email']); + + } + else if ($row['planId'] != null) // VISIT + { + $userParams['name'] = $row['name']; + $userParams['email'] = $row['email']; + $userParams['phone'] = $row['phone']; + $userParams['memberId'] = $row['employeeId']; // memberId is unique primary key. + $userParams['gender'] = $row['gender']; + $userParams['dob'] = $row['dob']; + $userParams['relation'] = $row['relation']; + $userParams['policyNumber'] = $row['policyNumber']; + $userParams['employeeId'] = $row['memberId']; + $userParams['policyStartDate']= $row['policyStartDate']; + $userParams['policyEndDate'] = $row['policyEndDate']; + $userParams['policyName'] = $row['policy_type']; + $userParams['planId'] = $row['planId']; + $userParams['moduleName'] = 'home'; + break; // stop after first GMC match + } } - - // dd($userParams); - + if (empty($userParams)) { - return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200); + return ['status' => 'failed','message' => 'Coming soon........!']; } - + + // echo 'coming';die(); // Derive 32-byte key from SHA256 $derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true); - + // Build query string like Node.js $plainText = ''; foreach ($userParams as $k => $v) { @@ -354,153 +348,114 @@ class ApiServiceController extends BaseController // Base64URL encode (same as Node.js output) $output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '='); - + $baseURL = env('VISIT_BASE_URL'); $clientId = env('VISIT_CLIENT_ID'); $finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId; if (!empty($finalUrl)) { log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl); - return $this->respond(['status' => 'success','data' => $finalUrl], 200); + return ['status' => 'success','data' => $finalUrl]; } else { - return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200); + return ['status' => 'failed','message' => 'Coming soon........!']; } } - function getSSORedirectUrl($email = 'test@getvisitapp.com') - { - log_message('info', "SSO: Starting authentication for email: $email"); - - // ---------- CONFIG ---------- - $authUrl = env('VIDAL_WELLNESS_BASE_URL'); - $subscriptionKey = env('VIDAL_WELLNESS_SUBSCRIPTION_KEY'); - $apiVersion = "1"; - // Provided Base64 AES key - $base64Key = env('VIDAL_WELLNESS_BASE64_KEY'); - $key = base64_decode($base64Key); - - log_message('info', "SSO: Config loaded, Auth URL: $authUrl"); - // ---------- STEP 1: Build plaintext payload ---------- - $plainPayload = json_encode([ - "email" => $email, - // "corporateId" => env('VIDAL_WELLNESS_CORPORATE_ID'), - "urlIdentifier" => env('VIDAL_WELLNESS_URL_IDENTIFIER') - ]); + // public function getWellnessUrl() + // { - // ---------- STEP 2: Encrypt payload ---------- - $iv = random_bytes(16); - $encryptedRaw = openssl_encrypt($plainPayload, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv); + // $emp_id = $this->request->getGet('emp_id'); + // $client_policy_id = $this->request->getGet('client_policy_id'); - $encryptedPayload = base64_encode($iv) . ":" . base64_encode($encryptedRaw); - - log_message('info', "SSO: Payload encrypted successfully"); + // $db = \Config\Database::connect(); - // ---------- STEP 3: Call Authentication API ---------- - $requestBody = json_encode([ - "payload" => $encryptedPayload, - "source" => env('VIDAL_WELLNESS_SUB_PARTNER_ID'), - "subPartnerId" => env('VIDAL_WELLNESS_SUB_PARTNER_ID') - ]); + // // $data = $db->table('employees e') + // // ->select('pt.policy_type, + // // e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, + // // cp.policy_no as policyNumber, cp.policy_no as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate') + // // ->join('employee_polices ep', 'e.id = ep.employee_id') + // // ->join('client_policy cp', 'ep.client_policy_id = cp.id') + // // ->join('policy_type pt', 'cp.policy_type_id = pt.id') + // // ->where('e.id', $emp_id) + // // ->where('e.emp_status', 'active') + // // ->where('ep.status', 'active') + // // ->where('e.is_active', 1) + // // ->where('ep.is_active', 1) + // // ->get() + // // ->getResultArray(); - $headers = [ - "Ocp-Apim-Subscription-Key: $subscriptionKey", - "apiver: $apiVersion", - "mode: encrypt", - "Content-Type: application/json" - ]; + // $data = $db->table('employee_polices ep') + // ->select('pt.policy_type, + // e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, e.id as employeeId + // cp.policy_no as policyNumber, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate, cp.wellness_plan_id as planId') + // ->join('employees e', 'e.id = ep.employee_id') + // ->join('client_policy cp', 'ep.client_policy_id = cp.id') + // ->join('policy_type pt', 'cp.policy_type_id = pt.id') + // ->where('ep.employee_id', $emp_id) + // ->where('ep.client_policy_id', $client_policy_id) + // ->where('ep.status', 'active') + // ->where('ep.is_active', 1) + // ->get() + // ->getRow(); - $ch = curl_init($authUrl); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + + // $userParams = []; + // if(!empty($data)) + // { + // $userParams['name'] = $data->name; + // $userParams['email'] = $data->email; + // $userParams['phone'] = $data->phone; + // $userParams['memberId'] = $data->employeeId; // memberId is unique primary key. + // $userParams['gender'] = $data->gender; + // $userParams['dob'] = $data->dob; + // $userParams['relation'] = $data->relation; + // $userParams['policyNumber'] = $data->policyNumber; + // $userParams['employeeId'] = $data->memberId; + // $userParams['policyStartDate']= $data->policyStartDate; + // $userParams['policyEndDate'] = $data->policyEndDate; + // $userParams['policyName'] = 'Nhance ' . $data->policy_type; + // $userParams['planId'] = $data->planId; + // $userParams['moduleName'] = 'home'; - $apiResponse = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $curlError = curl_error($ch); - curl_close($ch); - - log_message('info', "SSO: API response received, HTTP Code: $httpCode"); + // } + + // // dd($userParams); - // Check for cURL errors - if ($curlError) { - log_message('error', "SSO: cURL error - $curlError"); - return ["error" => "cURL error: $curlError"]; - } + // if (empty($userParams)) { + // return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200); + // } - // Check HTTP status - if ($httpCode !== 200) { - log_message('error', "SSO: HTTP error - Code: $httpCode, Response: $apiResponse"); - return ["error" => "HTTP error: $httpCode", "response" => $apiResponse]; - } + // // Derive 32-byte key from SHA256 + // $derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true); - $jsonResponse = json_decode($apiResponse, true); - - // Check JSON decode error - if (json_last_error() !== JSON_ERROR_NONE) { - log_message('error', "SSO: JSON decode error - " . json_last_error_msg()); - return ["error" => "JSON decode error: " . json_last_error_msg(), "response" => $apiResponse]; - } - - // Check API response status - if (!isset($jsonResponse["status"]) || $jsonResponse["status"] !== "success") { - log_message('error', "SSO: API error - " . json_encode($jsonResponse)); - return ["error" => "API error", "response" => $jsonResponse]; - } - - if (!isset($jsonResponse["data"])) { - log_message('error', "SSO: Missing data field in response"); - return ["error" => "Invalid API response - missing data field", "response" => $jsonResponse]; - } - - log_message('info', "SSO: API response validated successfully"); - - // ---------- STEP 4: Decrypt response ---------- - log_message('info', "SSO: Starting response decryption"); - - $dataParts = explode(":", $jsonResponse["data"]); - - if (count($dataParts) !== 2) { - log_message('error', "SSO: Invalid encrypted data format"); - return ["error" => "Invalid encrypted data format", "data" => $jsonResponse["data"]]; - } - - list($ivBase64, $cipherBase64) = $dataParts; - - $respIv = base64_decode($ivBase64); - $respCipher = base64_decode($cipherBase64); - - if ($respIv === false || $respCipher === false) { - log_message('error', "SSO: Base64 decode error"); - return ["error" => "Base64 decode error"]; - } - - $decryptedJson = openssl_decrypt($respCipher, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $respIv); - - if ($decryptedJson === false) { - log_message('error', "SSO: Decryption failed"); - return ["error" => "Decryption failed"]; - } - - $decryptedData = json_decode($decryptedJson, true); - - if (json_last_error() !== JSON_ERROR_NONE) { - log_message('error', "SSO: Decrypted JSON decode error - " . json_last_error_msg()); - return ["error" => "Decrypted JSON decode error: " . json_last_error_msg()]; - } - - if (!isset($decryptedData["redirectUrl"])) { - log_message('error', "SSO: redirectUrl missing in decrypted data"); - return ["error" => "redirectUrl missing", "decrypted" => $decryptedData]; - } - - // ---------- FINAL ---------- - log_message('info', "SSO: Authentication successful, redirectUrl obtained"); - return $decryptedData["redirectUrl"]; - } + // // Build query string like Node.js + // $plainText = ''; + // foreach ($userParams as $k => $v) { + // $plainText .= "&{$k}={$v}"; + // } + // $plainText = ltrim($plainText, '&'); + + // // Encrypt + // $algorithm = "aes-256-cbc"; + // $encrypted = openssl_encrypt($plainText, $algorithm, $derivedKey, OPENSSL_RAW_DATA, env('VISIT_IV')); + + // // Base64URL encode (same as Node.js output) + // $output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '='); + // $baseURL = env('VISIT_BASE_URL'); + // $clientId = env('VISIT_CLIENT_ID'); + // $finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId; + + // if (!empty($finalUrl)) { + // log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl); + // return $this->respond(['status' => 'success','data' => $finalUrl], 200); + // } else { + // return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200); + // } + // } // function getSSORedirectUrl($email = 'user@example.com') diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php index fcc9a6d6..da65a7b1 100755 --- a/app/Controllers/AppContentManagementController.php +++ b/app/Controllers/AppContentManagementController.php @@ -28,11 +28,11 @@ class AppContentManagementController extends AdminController $this->feContentModel = new FEContentModel(); $this->clientModel = new ClientModel(); } + //listing public function add_image_index() { - $this->myLogger->logme('error','Addvertisement Image list function called'); - $headerData['tab_name'] = 'Addvertisement Images'; - $headerData['page_name'] = 'Addvertisement Images'; + $headerData['tab_name'] = 'Advertisement Images'; + $headerData['page_name'] = 'Advertisement Images'; // $data['addImageList'] = $this->addImgModel->findAll(); $data['addImageList'] = $this->addImgModel->select('advertisement_images.*, clients.client_name, @@ -53,7 +53,7 @@ class AppContentManagementController extends AdminController // $this->loadLayout('client_onboarding', $data); } - // using add and edit + // add and edit public function add_advertise_image() { try { $file = $this->request->getFile('advertise_image'); @@ -70,7 +70,8 @@ class AppContentManagementController extends AdminController return $this->respond(['status' => false, 'message' => 'No file uploaded or invalid file.'], 400); } - $uploadPath = WRITEPATH . 'uploads/advertiseImage/'; + // $uploadPath = WRITEPATH . 'uploads/advertiseImage/'; + $uploadPath = ROOTPATH . 'public/uploads/add_image_upload/'; if (!is_dir($uploadPath)) mkdir($uploadPath, 0755, true); @@ -91,6 +92,7 @@ class AppContentManagementController extends AdminController } } + // soft delete public function remove_advertise_image() { try { @@ -111,47 +113,34 @@ class AppContentManagementController extends AdminController } - // public function showAdvertiseImage($fileName) - // { - - // $filePath = WRITEPATH . 'uploads/advertiseImage/' . $fileName; - - // if (!file_exists($filePath)) { - // return $this->response->setStatusCode(404, 'File not found'); - // } - - // $mimeType = mime_content_type($filePath); - // header('Content-Type: ' . $mimeType); - // readfile($filePath); - // exit; - // } - - // In AppContentManagementController.php (This is what needs to be fixed if the direct path fails) - + // Preview image Went Edit. public function showAdvertiseImage($filename) { - $path = WRITEPATH . 'uploads/advertiseImage/' . $filename; + // $path = WRITEPATH . 'uploads/advertiseImage/' . $filename; + $path = ROOTPATH . 'public/uploads/add_image_upload/' . $filename; if (!file_exists($path)) { throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); + // return $this->response->setStatusCode(404, 'File not found'); } $mime = mime_content_type($path); + // header('Content-Type: ' . $mimeType); + // readfile($path); + // exit; return $this->response->setHeader('Content-Type', $mime)->setBody(file_get_contents($path)); } - public function getAdvertiseImage($image_id){ - - $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first(); - - if($image_data){ - return $image_data['name']; - }else{ - return ; - } - } + // public function getAdvertiseImage($image_id){ + // $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first(); + // if($image_data){ + // return $image_data['name']; + // }else{ + // return ; + // } + // } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d80f9176..82ecc4e1 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3028,7 +3028,8 @@ class EmployeeRestController extends AdminController } $emp_reatail_policy_data = $this->getEmpRetailPolicy($employeeSelfData); - $emp_wellness_data = $this->getWellnessUrl($employeeSelfData->id ?? null); + $apiServiceController = new ApiServiceController; + $emp_wellness_data = $apiServiceController->getWellnessUrl($employeeSelfData->id ?? null); return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result, 'emp_name' => $employeeName, 'pre_policy_count' => $prePolicyCount, 'emp_not_enrolled_count' => $empNotEnrolledCount, 'retail_policy_data' => $emp_reatail_policy_data, 'wellness_data' => $emp_wellness_data], 200); } else { @@ -3176,32 +3177,58 @@ class EmployeeRestController extends AdminController } } + // public function getAdvertisementImage_old() + // { + // try { + + // $client_id = $this->request->getGet('client_id'); + + // $img = $this->addImgModel->where('is_active', 1)->where('client_id',$client_id)->findAll(); + + // if (count($img) > 0) { + // $data = []; + // foreach ($img as $key => $value) { + // $url = base_url('public/uploads/add_image_upload/') . $value['name']; + // array_push($data, $url); + // } + + // return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200); + // } else { + + // return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'No Data'], 404); + // } + // } catch (\Throwable $th) { + // return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500); + // } + // } + public function getAdvertisementImage() { try { $client_id = $this->request->getGet('client_id'); + // get client_id & convert empty/null/undefined → 0 + // $client_id = ($client_id === null || $client_id === '' || $client_id === 'undefined') ? 0 : $client_id; - $img = $this->addImgModel->where('is_active', 1)->where('client_id',$client_id)->findAll(); + // fetch images for client + $images = $this->addImgModel->where('is_active', 1)->where('client_id', $client_id)->findAll(); - if (count($img) > 0) { - $data = []; - foreach ($img as $key => $value) { - $url = base_url('public/uploads/add_image_upload/') . $value['name']; - array_push($data, $url); - } - - return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200); - } else { - - return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'No Data'], 404); + // if no client images → load default client 0 + if (count($images) == 0) { + $images = $this->addImgModel->where('is_active', 1)->where('client_id', 0)->findAll(); } + + // prepare URLs + $data = array_map(function($img){ return base_url('public/uploads/add_image_upload/' . $img['name']); }, $images); + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200); + } catch (\Throwable $th) { + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500); } } - public function storeFireBase() { try { @@ -5012,81 +5039,7 @@ class EmployeeRestController extends AdminController } } - public function getWellnessUrl($emp_id) - { - // $emp_id = $this->request->getGet('emp_id'); - - $db = \Config\Database::connect(); - $data = $db->table('employees e') - ->select('pt.policy_type, - e.name, e.email_corporate as email, e.mobile as phone, e.emp_code as memberId, e.gender, e.dob, e.relationship as relation, - cp.policy_no as policyNumber, ep.employee_id as employeeId, cp.policy_start_date as policyStartDate, cp.policy_end_date as policyEndDate , cp.wellness_plan_id as planId') - ->join('employee_polices ep', 'e.id = ep.employee_id') - ->join('client_policy cp', 'ep.client_policy_id = cp.id') - ->join('policy_type pt', 'cp.policy_type_id = pt.id') - ->where('e.id', $emp_id) - ->where('e.emp_status', 'active') - ->where('ep.status', 'active') - ->where('e.is_active', 1) - ->where('ep.is_active', 1) - ->get() - ->getResultArray(); - - - $userParams = []; - foreach ($data as $row) { - if ($row['planId'] != null) { - $userParams['name'] = $row['name']; - $userParams['email'] = $row['email']; - $userParams['phone'] = $row['phone']; - $userParams['memberId'] = $row['employeeId']; // memberId is unique primary key. - $userParams['gender'] = $row['gender']; - $userParams['dob'] = $row['dob']; - $userParams['relation'] = $row['relation']; - $userParams['policyNumber'] = $row['policyNumber']; - $userParams['employeeId'] = $row['memberId']; - $userParams['policyStartDate']= $row['policyStartDate']; - $userParams['policyEndDate'] = $row['policyEndDate']; - $userParams['policyName'] = $row['policy_type']; - $userParams['planId'] = $row['planId']; - $userParams['moduleName'] = 'home'; - break; // stop after first GMC match - } - } - - if (empty($userParams)) { - return ['status' => 'failed','message' => 'Coming soon........!']; - } - - // echo 'coming';die(); - // Derive 32-byte key from SHA256 - $derivedKey = hash('sha256', env('VISIT_SECRET_KEY'), true); - - // Build query string like Node.js - $plainText = ''; - foreach ($userParams as $k => $v) { - $plainText .= "&{$k}={$v}"; - } - $plainText = ltrim($plainText, '&'); - // Encrypt - $algorithm = "aes-256-cbc"; - $encrypted = openssl_encrypt($plainText, $algorithm, $derivedKey, OPENSSL_RAW_DATA, env('VISIT_IV')); - - // Base64URL encode (same as Node.js output) - $output = rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '='); - - $baseURL = env('VISIT_BASE_URL'); - $clientId = env('VISIT_CLIENT_ID'); - $finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId; - - if (!empty($finalUrl)) { - log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl); - return ['status' => 'success','data' => $finalUrl]; - } else { - return ['status' => 'failed','message' => 'Coming soon........!']; - } - } public function getPolicyTypeAndInsurer() { diff --git a/app/Controllers/LogController.php b/app/Controllers/LogController.php new file mode 100644 index 00000000..99652ff3 --- /dev/null +++ b/app/Controllers/LogController.php @@ -0,0 +1,259 @@ +logPath = WRITEPATH . 'logs/'; + $this->session = session(); + } + + /** + * Display list of all log files + */ + public function index() + { + + $logFiles = $this->getLogFiles(); + + $data = [ + 'title' => 'Log Files', + 'logFiles' => $logFiles + ]; + + return $this->loadLayout('logs/index', $data); + + // return view('logs/index', $data); + } + + /** + * Get all log files sorted by date (latest first) + */ + private function getLogFiles() + { + $files = []; + + if (!is_dir($this->logPath)) { + return $files; + } + + $iterator = new \DirectoryIterator($this->logPath); + + foreach ($iterator as $fileInfo) { + if ($fileInfo->isFile() && $fileInfo->getExtension() === 'log') { + $files[] = [ + 'name' => $fileInfo->getFilename(), + 'path' => $fileInfo->getPathname(), + 'size' => $this->formatBytes($fileInfo->getSize()), + 'modified' => $fileInfo->getMTime(), + 'modified_date' => date('Y-m-d H:i:s', $fileInfo->getMTime()) + ]; + } + } + + // Sort by modified time (latest first) + usort($files, function($a, $b) { + return $b['modified'] - $a['modified']; + }); + + return $files; + } + + /** + * View specific log file content + */ + public function view($filename = null) + { + + + + if (!$filename) { + return redirect()->to('/logs')->with('error', 'No log file specified'); + } + + // Security: prevent directory traversal + $filename = basename($filename); + $filePath = $this->logPath . $filename; + + if (!file_exists($filePath)) { + return redirect()->to('/logs')->with('error', 'Log file not found'); + } + + // ✅ extract date from filename: log-YYYY-MM-DD.log + if (preg_match('/log-(\d{4}-\d{2}-\d{2})\.log/', $filename, $match)) { + $currentDate = $match[1]; + + $prevDate = date('Y-m-d', strtotime('-1 day', strtotime($currentDate))); + $nextDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))); + + $prevFile = "log-$prevDate.log"; + $nextFile = "log-$nextDate.log"; + + $prevExists = file_exists($this->logPath . $prevFile); + $nextExists = file_exists($this->logPath . $nextFile); + } + + // Read log file content + $content = file_get_contents($filePath); + $logEntries = $this->parseLogFile($content); + + $data = [ + 'title' => 'View Log: ' . $filename, + 'filename' => $filename, + 'logEntries' => $logEntries, + 'prevFile' => $prevExists ? $prevFile : null, + 'nextFile' => $nextExists ? $nextFile : null, + 'fileSize' => $this->formatBytes(filesize($filePath)), + 'lastModified' => date('Y-m-d H:i:s', filemtime($filePath)) + ]; + + // print_r( $data); die; + + return $this->loadLayout('logs/view', $data); + // return view('logs/view', $data); + } + + /** + * Parse log file into structured array + */ + + private function parseLogFile($content) + { + $entries = []; + $lines = explode("\n", $content); + + $currentEntry = null; + + // Messages to filter out + $skipPatterns = [ + '/Session: Class initialized using/', + '/Session class already loaded/', + ]; + + foreach ($lines as $line) { + // Match CI4 log format: LEVEL - date --> message + if (preg_match('/^(\w+)\s*-\s*(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\s*-->\s*(.*)$/', $line, $matches)) { + + // Save previous entry if exists (before checking skip) + if ($currentEntry !== null) { + $entries[] = $currentEntry; + $currentEntry = null; + } + + // Check if this message should be skipped + $shouldSkip = false; + foreach ($skipPatterns as $pattern) { + if (preg_match($pattern, $matches[3])) { + $shouldSkip = true; + break; + } + } + + if ($shouldSkip) { + continue; + } + + // Start new entry + $currentEntry = [ + 'level' => $matches[1], + 'date' => $matches[2], + 'message' => $matches[3] + ]; + } elseif ($currentEntry !== null && trim($line) !== '') { + // Continuation of previous message + $currentEntry['message'] .= "\n" . $line; + } + } + + // Add last entry + if ($currentEntry !== null) { + $entries[] = $currentEntry; + } + + return array_reverse($entries); // Latest first + } + + /** + * Download log file + */ + public function download($filename = null) + { + if (!$filename) { + return redirect()->to('/logs')->with('error', 'No log file specified'); + } + + $filename = basename($filename); + $filePath = $this->logPath . $filename; + + if (!file_exists($filePath)) { + return redirect()->to('/logs')->with('error', 'Log file not found'); + } + + return $this->response->download($filePath, null); + } + + /** + * Delete log file + */ + public function delete($filename = null) + { + if (!$filename) { + return redirect()->to('/logs')->with('error', 'No log file specified'); + } + + $filename = basename($filename); + $filePath = $this->logPath . $filename; + + if (!file_exists($filePath)) { + return redirect()->to('/logs')->with('error', 'Log file not found'); + } + + if (unlink($filePath)) { + return redirect()->to('/logs')->with('success', 'Log file deleted successfully'); + } else { + return redirect()->to('/logs')->with('error', 'Failed to delete log file'); + } + } + + /** + * Format bytes to human readable format + */ + private function formatBytes($bytes, $precision = 2) + { + $units = ['B', 'KB', 'MB', 'GB', 'TB']; + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + $bytes /= pow(1024, $pow); + + return round($bytes, $precision) . ' ' . $units[$pow]; + } + + /** + * Clear all log files + */ + public function clearAll() + { + $logFiles = $this->getLogFiles(); + $deleted = 0; + + foreach ($logFiles as $file) { + if (unlink($file['path'])) { + $deleted++; + } + } + + return redirect()->to('/logs')->with('success', $deleted . ' log file(s) deleted successfully'); + } +} \ No newline at end of file diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php index 266862d2..e293c57f 100644 --- a/app/Controllers/MediAssistApiController.php +++ b/app/Controllers/MediAssistApiController.php @@ -150,7 +150,7 @@ class MediAssistApiController extends BaseController return; } else { - log_message('error', 'TPA CLAIM PUSH SUCCESS BUT claimReferenceNo EMPTY | claimId: '.$claimId.' | response: '.json_encode($response)); + log_message('error', 'TPA CLAIM PUSH API SUCCESS BUT claimReferenceNo EMPTY | claimId: '.$claimId.' | response: '.json_encode($response)); return; } @@ -223,7 +223,7 @@ class MediAssistApiController extends BaseController $client_policy_id = $requestData['client_policy_id'] ?? null; if (empty($policyNo)) { - log_message('error', 'GetBenefDetails: policy_no missing in request'); + log_message('error', 'TPA ID PULL | policy_no missing in request'); if($function_calling_type == "job"){ return ['status' => false, 'message' => 'policy_no required']; }else{ @@ -232,7 +232,7 @@ class MediAssistApiController extends BaseController } if (empty($client_policy_id)) { - log_message('error', 'GetBenefDetails: client_policy_id missing in request'); + log_message('error', 'TPA ID PULL | client_policy_id missing in request'); if($function_calling_type == "job"){ return ['status' => false, 'message' => 'client_policy_id required']; }else{ @@ -240,8 +240,7 @@ class MediAssistApiController extends BaseController } } - log_message('error', "GetBenefDetails called for policy_no: {$policyNo}"); - log_message('error', "GetBenefDetails called for client_policy_id: {$client_policy_id}"); + log_message('error', "TPA ID PULL | called for policy_no: {$policyNo} , client_policy_id: {$client_policy_id}"); $employeePolicyModel = new EmployeePolicyModel(); $employeePolicyData = $employeePolicyModel @@ -260,7 +259,7 @@ class MediAssistApiController extends BaseController ->findAll(); if (empty($employeePolicyData)) { - log_message('error', 'GetBenefDetails: employeePolicyData is empty'); + log_message('error', 'TPA ID PULL FAILED | employeePolicyData is empty (tpa_id IS NULL from nhance) for this tpa id pull request'); if($function_calling_type == "job"){ return ['status' => false, 'message' => 'employeePolicyData not found']; }else{ @@ -284,8 +283,8 @@ class MediAssistApiController extends BaseController "employeeId" => "" ]; - log_message('error', "GetBenefDetails API Request (startIndex={$startIndex}): " . json_encode($body)); - log_message('error', "GetBenefDetails API parems " . json_encode([$url, $method, $headers, $body])); + log_message('error', "TPA ID PULL | API Request (startIndex={$startIndex}): " . json_encode($body)); + log_message('error', "TPA ID PULL | API parems " . json_encode([$url, $method, $headers, $body])); $response = call_third_party_api($url, $method, $headers, $body); @@ -300,7 +299,7 @@ class MediAssistApiController extends BaseController log_message('error', "Failed to update file table status."); } - log_message('error', 'GetBenefDetails API failed: ' . json_encode($response)); + log_message('error', 'TPA ID PULL API FAILED | API failed: ' . json_encode($response)); if($function_calling_type == "job"){ return ['status' => false, 'message' => 'API call failed', 'data' => $response]; @@ -312,7 +311,7 @@ class MediAssistApiController extends BaseController $data = $response['data'] ?? []; if (!isset($data['benefDetails'])) { - log_message('error', "GetBenefDetails: 'benefDetails' missing in API response: " . json_encode($data)); + log_message('error', "TPA ID PULL FAILED |: 'benefDetails' missing in API response: " . json_encode($data)); break; } @@ -406,7 +405,7 @@ class MediAssistApiController extends BaseController } - log_message('error', "GetBenefDetails completed. Total fetched={$totalCount}, updated={$updated}"); + log_message('error', "TPA ID PULL SUCCESS | completed. Total fetched={$totalCount}, updated={$updated}"); if($function_calling_type == "job"){ return [ @@ -532,7 +531,7 @@ class MediAssistApiController extends BaseController $response = call_third_party_api($url, $method, $headers, $body); if ($response['status'] != true || empty($response['data']['claimsData'][0])) { - log_message('error', 'Claim status API failed for ticket ID: ' . $claimId); + log_message('error', 'CLAIM STATUS FAILED | for ticket ID: ' . $claimId.' | response: '.json_encode($response)); return $this->response->setJSON([ 'status' => false, @@ -598,7 +597,7 @@ class MediAssistApiController extends BaseController $this->db->table('ticket_master')->where('id', $claimId)->update($updateArray); // LOG UPDATE - log_message('info', "Updated ticket ID $claimId with claim status: $currentStatus"); + log_message('info', "CLAIM STATUS SUCCESS | Updated ticket ID $claimId with claim status: $currentStatus"); return $this->response->setJSON([ 'status' => true, @@ -633,10 +632,10 @@ class MediAssistApiController extends BaseController if (!$ticket || empty($ticket['ClaimID'])) { log_message('error', "IRSubmission FAILED → ClaimID NOT FOUND for ticket_id={$claimId}"); - return $this->response->setJSON([ - 'status' => false, - 'message' => "ClaimID not found for ticket {$claimId}" - ]); + return [ + 'status' => false, + 'message' => "ClaimID not found for ticket {$claimId}" + ]; } // 2. FETCH IR ATTACHMENTS diff --git a/app/Controllers/RuleImportController.php b/app/Controllers/RuleImportController.php index d1647bae..e624fbad 100644 --- a/app/Controllers/RuleImportController.php +++ b/app/Controllers/RuleImportController.php @@ -63,6 +63,19 @@ class RuleImportController extends AdminController public function commissionFileUploadList() { + + // print_rr($this->ruleImportService->processUpload([ + // 'id' => 60, + // 'file_name' => 'Sample_commission_file-New.xlsx', + // 'insurer_id' => 77, + // 'department' => 'motor', + // 'commission_month' => '2025-11-10', + // 'created_by' => 10 + // ])); + // die(); + + + $data['page_name'] = "Commision File Upload"; $data['departments'] = $this->departments; $data['insurers'] = $this->insurerModel->where('is_active', 1)->findAll(); diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index a2875028..78fc7d57 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -7,15 +7,18 @@ use CodeIgniter\HTTP\ResponseInterface; class VidalApiController extends BaseController { - public function index() + protected $db; + + public function __construct() { - // + $this->db = \Config\Database::connect(); } function uploadFileToVidal($filePath,$filename) { - $apiUrl = "https://devapigw.vidalhealthtpa.com/partner-integration/api/files/upload-url"; + // $apiUrl = "https://devapigw.vidalhealthtpa.com/partner-integration/api/files/upload-url"; + $apiUrl = getenv('VIDAL_API_BASE_URL').'/files/upload-url'; $subscriptionKey = getenv('VIDAL_API_SUBSCRIPTION_KEY'); log_message('error', "Starting file upload process for filename: $filename | Path: $filePath"); @@ -105,10 +108,8 @@ class VidalApiController extends BaseController { helper('api'); - //Prepare body data - $db = \Config\Database::connect(); // Fetch the data from DB - $data = $db->table('ticket_master tm') + $data = $this->db->table('ticket_master tm') ->select(' tm.id, tm.emp_mobile as mobileNo, @@ -116,9 +117,14 @@ class VidalApiController extends BaseController tm.doa as admissionDate, tm.dod as dischargeDate, tm.hospital_name as hospitalName, + tm.hospital_address as hospitalAddress, + tm.hospital_state as hospitalState, + tm.hospital_city as hospitalCity, + tm.hospital_pin_code as hospitalPinCode, + tm.hospital_phone_no as hospitalPhoneNo, tm.claim_amount as requestedAmount, + tm.tpa_no as dependentUniqueId, cp.policy_no as policyNo, - e.id as dependentUniqueIdOld, e.emp_code as memberId, tn.note as disease, tn.note as reasonForHospitalization, @@ -126,7 +132,7 @@ class VidalApiController extends BaseController cf.url as filePath, pt.policy_type as typeOfClaim, ep.tpa_id as empanelmentNo, - ep.tpa_id as dependentUniqueId, + ') ->join('employees e', 'e.id = tm.emp_id', 'left') ->join('client_policy cp', 'tm.client_policy_id = cp.id', 'left') @@ -196,7 +202,9 @@ class VidalApiController extends BaseController ], ]; // dd($body); - log_message('error', "Submit claim failed - payload ". json_encode($body )); + + log_message('error', 'TPA CLAIM PUSH | claimId: '.$claimId.' | payload: '.json_encode($body)); + // $body = [ // 'policyNo' => "351500/D0534/PP/20-20/PC", // 'dependentUniqueId' => "EN000000182-C-41", @@ -227,16 +235,175 @@ class VidalApiController extends BaseController $response = call_third_party_api($url, $method, $headers, $body); if($response['status'] != true){ - return $this->response->setJSON([ - 'status' => false, - 'message' => 'failed.', - 'data' => $response - ]); + log_message('error', 'TPA CLAIM PUSH FAILED | claimId: '.$claimId.' | response: '.json_encode($response)); + return; } - return $this->response->setJSON($response); + // return $this->response->setJSON($response); + + if($response['data']['status'] == 'SUCCESS') + { + $claimNO = $response['data']['data']['claimNO'] ?? null; + $claimInwardNO = $response['data']['data']['claimInwardNO'] ?? null; + + if(!empty($claimNO) && !empty($claimInwardNO)){ + + log_message('error', 'TPA CLAIM PUSH SUCCESS | claimId: '.$claimId.' | claimNO: '.$claimNO.' | claimInwardNO: '.$claimInwardNO); + + $this->db->table('ticket_master') + ->where('id',$claimId) + ->update([ 'tpa_claim_push_reference_no' => $claimInwardNO , 'tpa_claim_id' => $claimNO ]); + + return; + + } else { + log_message('error', 'TPA CLAIM PUSH API SUCCESS BUT claimNO,claimInwardNO EMPTY | claimId: '.$claimId.' | response: '.json_encode($response)); + return; + } + }else{ + log_message('error', 'TPA CLAIM PUSH API FAILED | claimId: '.$claimId.' | response: '.json_encode($response)); + return; + } } + function getWellnessSSORedirectUrl($email = 'test@getvisitapp.com') + { + log_message('info', "SSO: Starting authentication for email: $email"); + + // ---------- CONFIG ---------- + $authUrl = env('VIDAL_WELLNESS_BASE_URL'); + $subscriptionKey = env('VIDAL_WELLNESS_SUBSCRIPTION_KEY'); + $apiVersion = "1"; + + // Provided Base64 AES key + $base64Key = env('VIDAL_WELLNESS_BASE64_KEY'); + $key = base64_decode($base64Key); + + log_message('info', "SSO: Config loaded, Auth URL: $authUrl"); + + // ---------- STEP 1: Build plaintext payload ---------- + $plainPayload = json_encode([ + "email" => $email, + // "corporateId" => env('VIDAL_WELLNESS_CORPORATE_ID'), + "urlIdentifier" => env('VIDAL_WELLNESS_URL_IDENTIFIER') + ]); + + // ---------- STEP 2: Encrypt payload ---------- + $iv = random_bytes(16); + $encryptedRaw = openssl_encrypt($plainPayload, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $iv); + + $encryptedPayload = base64_encode($iv) . ":" . base64_encode($encryptedRaw); + + log_message('info', "SSO: Payload encrypted successfully"); + + // ---------- STEP 3: Call Authentication API ---------- + $requestBody = json_encode([ + "payload" => $encryptedPayload, + "source" => env('VIDAL_WELLNESS_SUB_PARTNER_ID'), + "subPartnerId" => env('VIDAL_WELLNESS_SUB_PARTNER_ID') + ]); + + $headers = [ + "Ocp-Apim-Subscription-Key: $subscriptionKey", + "apiver: $apiVersion", + "mode: encrypt", + "Content-Type: application/json" + ]; + + $ch = curl_init($authUrl); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + $apiResponse = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + $curlError = curl_error($ch); + curl_close($ch); + + log_message('info', "SSO: API response received, HTTP Code: $httpCode"); + + // Check for cURL errors + if ($curlError) { + log_message('error', "SSO: cURL error - $curlError"); + return ['status' => 'failed','message' => $curlError]; + } + + // Check HTTP status + if ($httpCode !== 200) { + log_message('error', "SSO: HTTP error - Code: $httpCode, Response: $apiResponse"); + return ['status' => 'failed','message' => "HTTP error: $httpCode" , "response" => $apiResponse ]; + } + + $jsonResponse = json_decode($apiResponse, true); + + // Check JSON decode error + if (json_last_error() !== JSON_ERROR_NONE) { + log_message('error', "SSO: JSON decode error - " . json_last_error_msg()); + return ['status' => 'failed','message' => "JSON decode error: " . json_last_error_msg(), "response" => $apiResponse]; + } + + // Check API response status + if (!isset($jsonResponse["status"]) || $jsonResponse["status"] !== "success") { + log_message('error', "SSO: API error - " . json_encode($jsonResponse)); + return ['status' => 'failed','message' => "API error", "response" => $jsonResponse]; + } + + if (!isset($jsonResponse["data"])) { + log_message('error', "SSO: Missing data field in response"); + return ['status' => 'failed','message' => "Invalid API response - missing data field", "response" => $jsonResponse]; + } + + log_message('info', "SSO: API response validated successfully"); + + // ---------- STEP 4: Decrypt response ---------- + log_message('info', "SSO: Starting response decryption"); + + $dataParts = explode(":", $jsonResponse["data"]); + + if (count($dataParts) !== 2) { + log_message('error', "SSO: Invalid encrypted data format"); + return ['status' => 'failed','message' => "Invalid encrypted data format", "data" => $jsonResponse["data"]]; + } + + list($ivBase64, $cipherBase64) = $dataParts; + + $respIv = base64_decode($ivBase64); + $respCipher = base64_decode($cipherBase64); + + if ($respIv === false || $respCipher === false) { + log_message('error', "SSO: Base64 decode error"); + return ['status' => 'failed','message' => "Base64 decode error"]; + } + + $decryptedJson = openssl_decrypt($respCipher, "AES-256-CBC", $key, OPENSSL_RAW_DATA, $respIv); + + if ($decryptedJson === false) { + log_message('error', "SSO: Decryption failed"); + return ['status' => 'failed','message' => "Decryption failed"]; + } + + $decryptedData = json_decode($decryptedJson, true); + + if (json_last_error() !== JSON_ERROR_NONE) { + log_message('error', "SSO: Decrypted JSON decode error - " . json_last_error_msg()); + return ['status' => 'failed','message' => "Decrypted JSON decode error: " . json_last_error_msg()]; + } + + if (!isset($decryptedData["redirectUrl"])) { + log_message('error', "SSO: redirectUrl missing in decrypted data"); + return ['status' => 'failed','message' => "redirectUrl missing", "decrypted" => $decryptedData]; + } + + // ---------- FINAL ---------- + log_message('info', "SSO: Authentication successful, redirectUrl obtained"); + return ['status' => 'success','data' => $decryptedData["redirectUrl"]]; + } + + + + //----------yet to start only submit claim given + public function fileUpload() { diff --git a/app/Filters/CommissionApiFilter.php b/app/Filters/CommissionApiFilter.php index f68e62cd..b2707b98 100644 --- a/app/Filters/CommissionApiFilter.php +++ b/app/Filters/CommissionApiFilter.php @@ -10,11 +10,19 @@ class CommissionApiFilter implements FilterInterface { public function before(RequestInterface $request, $arguments = null) { - return null; + // return null; // Read API key from header - // $authHeader = $request->getHeaderLine('X'); + $authHeader = $request->getHeaderLine('AUTHORIZATION'); + if(empty($authHeader)) + { $authHeader = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; - // echo $authHeader;die(); + } + + // $requestHeaders = getallheaders(); + // // $authHeader = $_SERVER['REDIRECT_HTTP_AUTHORIZATION']; + // // $authHeader = $_SERVER['Authorization']; + // print_r($authHeader); + // print_r($_SERVER);die(); if (empty($authHeader)) { return service('response')->setJSON([ 'success' => false, diff --git a/app/Libraries/RuleImportService.php b/app/Libraries/RuleImportService.php index 33fdab3d..09147729 100644 --- a/app/Libraries/RuleImportService.php +++ b/app/Libraries/RuleImportService.php @@ -36,6 +36,7 @@ class RuleImportService ]; // Column name constants + private const COL_SNO = 'S.No'; private const COL_RULE_NAME = 'Rule Name'; private const COL_POLICY_BUSINESS_TYPE = 'Policy Business Type'; private const COL_POLICY_NAME = 'Policy Name'; @@ -52,12 +53,17 @@ class RuleImportService private const COL_VEHICLE_WEIGHT_MIN = 'Vehicle Weight Min'; private const COL_VEHICLE_WEIGHT_MAX = 'Vehicle Weight Max'; private const COL_RTO_STATE = 'RTO State'; - private const COL_RTO_CITY = 'RTO City'; + private const COL_RTO_CITY = 'RTO Code'; private const COL_RENEWAL_TYPE = 'Renewal Type'; private const COL_RENEWAL_SUB_TYPE = 'Renewal Sub Type'; private const COL_COMMISSION_TYPE = 'Commission Type'; private const COL_COMMISSION_VALUE = 'Commission Value'; private const COL_COMMISSION_PARAMS = 'Commission Params(TP:OD:PA)'; + + private const COL_COMMISSION_PARAMS_OD = 'Commission Params (OD)'; + private const COL_COMMISSION_PARAMS_PA = 'Commission Params (PA)'; + private const COL_COMMISSION_PARAMS_TP = 'Commission Params (TP)'; + private const COL_NOTES = 'Notes'; protected array $expectedColumns; @@ -82,9 +88,10 @@ class RuleImportService private function initializeExpectedColumns(): void { $this->expectedColumns = [ - self::COL_RULE_NAME, - self::COL_POLICY_BUSINESS_TYPE, - self::COL_POLICY_NAME, + // self::COL_RULE_NAME, + // self::COL_POLICY_BUSINESS_TYPE, + // self::COL_POLICY_NAME, + self::COL_SNO, self::COL_PREMIUM_TYPE, self::COL_VEHICLE_TYPE, self::COL_VEHICLE_SUB_TYPE, @@ -100,11 +107,13 @@ class RuleImportService self::COL_RTO_STATE, self::COL_RTO_CITY, self::COL_RENEWAL_TYPE, - self::COL_RENEWAL_SUB_TYPE, + // self::COL_RENEWAL_SUB_TYPE, self::COL_COMMISSION_TYPE, self::COL_COMMISSION_VALUE, - self::COL_COMMISSION_PARAMS, - self::COL_NOTES + self::COL_COMMISSION_PARAMS_TP, + self::COL_COMMISSION_PARAMS_OD, + self::COL_COMMISSION_PARAMS_PA, + // self::COL_NOTES ]; } @@ -123,7 +132,7 @@ class RuleImportService self::COL_FUEL_TYPE => 'validateCommaList', self::COL_COMMISSION_TYPE => 'validateCommissionType', self::COL_COMMISSION_VALUE => 'validateNumeric', - self::COL_COMMISSION_PARAMS => 'validateCompositeParams', + // self::COL_COMMISSION_PARAMS => 'validateCompositeParams', ]; } @@ -402,13 +411,16 @@ class RuleImportService { $commissionType = strtolower($rowData[self::COL_COMMISSION_TYPE] ?? ''); $commissionValue = $rowData[self::COL_COMMISSION_VALUE] ?? ''; - $commissionParams = $rowData[self::COL_COMMISSION_PARAMS] ?? ''; + // $commissionParams = $rowData[self::COL_COMMISSION_PARAMS] ?? ''; + $commissionParams_od = $rowData[self::COL_COMMISSION_PARAMS_OD] ?? ''; + $commissionParams_pa = $rowData[self::COL_COMMISSION_PARAMS_PA] ?? ''; + $commissionParams_tp = $rowData[self::COL_COMMISSION_PARAMS_TP] ?? ''; // Composite commission requires params - if ($commissionType === self::COMMISSION_COMPOSITE && empty($commissionParams)) { + if ($commissionType === self::COMMISSION_COMPOSITE && empty($commissionParams_od) && empty($commissionParams_pa) && empty($commissionParams_tp)) { $this->validationResult->addError( $rowNum, - self::COL_COMMISSION_PARAMS, + self::COL_COMMISSION_PARAMS_OD, "Required when commission type is composite" ); } @@ -1255,10 +1267,14 @@ class RuleImportService $commissionType = strtolower(trim($rowData[self::COL_COMMISSION_TYPE] ?? '')); $commissionValue = $rowData[self::COL_COMMISSION_VALUE] ?? ''; $commissionParams = $rowData[self::COL_COMMISSION_PARAMS] ?? ''; + $commissionParams_od = $rowData[self::COL_COMMISSION_PARAMS_OD] ?? ''; + $commissionParams_pa = $rowData[self::COL_COMMISSION_PARAMS_PA] ?? ''; + $commissionParams_tp = $rowData[self::COL_COMMISSION_PARAMS_TP] ?? ''; + $commission = $commissionParams_tp.':'.$commissionParams_od.':'. $commissionParams_pa; switch ($commissionType) { case 'composite': - return $this->buildCompositeCalculation($commissionParams); + return $this->buildCompositeCalculation($commission); case 'percentage': return $this->buildPercentageCalculation($commissionValue); diff --git a/app/Views/add_image_list.php b/app/Views/add_image_list.php index e83cc7d7..a69924ea 100755 --- a/app/Views/add_image_list.php +++ b/app/Views/add_image_list.php @@ -51,15 +51,15 @@ table.dataTable thead th {