From 8929175f981f9f959c8f1b8c29fc573127c5415a Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Wed, 25 Mar 2026 17:05:23 +0530 Subject: [PATCH] FIX_LIVE_ISSUES_AND_OTHERS --- app/Config/Acl.php | 1 + app/Config/Routes.php | 1 + app/Controllers/ApiServiceController.php | 8 +- app/Controllers/ClientController.php | 13 +- .../PolicyTransactionController.php | 4 +- app/Controllers/TestingController.php | 167 +++++++++++++++++- app/Controllers/TicketController.php | 4 +- app/Models/PolicyTransactionModel.php | 2 +- app/Views/chartbrew_dashboard_view.php | 10 ++ app/Views/layout/header.php | 5 +- .../policy_transaction_inception_list.php | 105 ++++++++++- 11 files changed, 305 insertions(+), 15 deletions(-) create mode 100644 app/Views/chartbrew_dashboard_view.php diff --git a/app/Config/Acl.php b/app/Config/Acl.php index cb6547a0..c1a1e56a 100644 --- a/app/Config/Acl.php +++ b/app/Config/Acl.php @@ -24,6 +24,7 @@ class Acl '#^/downloadFileTableFile#' => ['public' => true], '#^/swagger#' => ['roles' => [ADMIN_ROLE_ID]], '#^/getEmployeeActiveOrInactivePolicy#' => ['roles' => [ADMIN_ROLE_ID, HEAD_ROLE_ID]], + '#^/test/chartbrewDashboardDemo#' => ['roles' => [ADMIN_ROLE_ID, HEAD_ROLE_ID]], '#^/bulkEcardDownloadAsZip#' => ['roles' => [ADMIN_ROLE_ID, HEAD_ROLE_ID]], '#^/sheet#' => ['roles' => [ADMIN_ROLE_ID, HEAD_ROLE_ID]], '#^/sendextraparam#' => ['roles' => [ADMIN_ROLE_ID, HEAD_ROLE_ID]], diff --git a/app/Config/Routes.php b/app/Config/Routes.php index d9dd3874..511d234a 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -882,6 +882,7 @@ $routes->group('test', function($routes) { $routes->get('logo_renaming','TestingController::logo_renaming'); $routes->get('testingquerys','TestingController::testingquerys'); $routes->get('thzReminderCrone','ThzController::getOpenTicketsOlderThan24HoursAndAssignNextLevel'); + $routes->get('chartbrewDashboardDemo','TestingController::chartbrewDashboardDemo'); // $routes->get('createDefaultMailTempalteInDB','TestingController::createDefaultMailTempalteInCrossDB'); // $routes->get('createDefaultMailTempalteInSameDB','TestingController::createDefaultMailTempalteInSameDB'); }); diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php index f4782afb..d14b731c 100644 --- a/app/Controllers/ApiServiceController.php +++ b/app/Controllers/ApiServiceController.php @@ -232,7 +232,13 @@ class ApiServiceController extends BaseController $policy_id = $this->request->getPost('client_policy_id') ?? null; $fileModel = new BatchFileModel(); - $filesData = $fileModel->where('is_active', 1)->where('event_type', 'api')->where('status', 'inprogress')->countAllResults(); + $filesData = $fileModel + ->join('client_policy', 'client_policy.id = batch_files.client_policy_id') + ->where('client_policy.tpa_id', $tpa_id) + ->where('batch_files.is_active', 1) + ->where('batch_files.event_type', 'api') + ->where('batch_files.status', 'inprogress') + ->countAllResults(); if($filesData > 0){ log_message('error', "TPA GetBenefDetails job is already in process."); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index df96dde0..9cd40875 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -6380,12 +6380,13 @@ class ClientController extends AdminController $client_type = $this->request->getGet('client_type') ?? null; // Check in Policy Transaction (BDS) - $bds_count = $this->policyTransactionModel + $bds_data = $this->policyTransactionModel ->where('is_active', 1) ->where('action_type', 'inception') ->where('TRIM(policy_no)', $policy_no) ->where('policy_no IS NOT NULL AND policy_no <> ""') - ->countAllResults(); + ->orderBy('id', 'desc') + ->first() ?? []; // Check in Enrollment (client_policy) $client_policy_data = $this->clientPolicyModel @@ -6395,14 +6396,15 @@ class ClientController extends AdminController ->first(); // Decide message + count - if ($bds_count > 0) { + if (count($bds_data) > 0) { return $this->respond([ 'status' => true, 'message' => "This policy number is already linked to another policy in the BDS", 'code' => 409, - 'data' => $bds_count, + 'data' => $bds_data['id'], 'received_data' => $received_data, + 'pt_id' => $bds_data['id'], 'client_policy_id' => $client_policy_data['id'] ?? null ], 200); @@ -6421,8 +6423,9 @@ class ClientController extends AdminController return $this->respond([ 'status' => false, - 'message' => 'No Data Found', + 'message' => 'Policy number not found in BDS or Enrollment, so proceed to add a new policy.', 'code' => 404, + 'is_dublicate' => false, 'received_data' => $received_data, 'client_policy_id' => null ], 200); diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index 7bce36eb..18acb569 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -549,6 +549,8 @@ class PolicyTransactionController extends BaseController public function viewInception() { $bds_edit_pt_id = $this->request->getGet('pt_id') ?? null; + $view = $this->request->getGet('view') ?? null; + $data['tab_name'] = 'Policies'; $data['page_name'] = 'Policies'; @@ -618,7 +620,7 @@ class PolicyTransactionController extends BaseController $issuer = empty($issuer) ? 0 : $issuer; $status = empty($status) ? 0 : $status; // Corrected from `$issuer` - if(empty($bds_edit_pt_id)){ + if(empty($bds_edit_pt_id) && empty($view)){ if ($this->request->is('get')) { // Fetch inception data list diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php index 917af897..51e71485 100644 --- a/app/Controllers/TestingController.php +++ b/app/Controllers/TestingController.php @@ -1322,7 +1322,7 @@ class TestingController extends BaseController * If env values are not present, sensible dummy defaults are used so that * the function can still be exercised. */ - public function testMediAssistWellness() + public function testMediAssistWellnessOld() { // Configuration – prefer environment variables, fall back to demo values @@ -1374,4 +1374,169 @@ class TestingController extends BaseController ], ], 200); } + + public function chartbrewDashboardDemo() + { + // 1. Configuration - Use a Chartbrew-specific Secret Key from .env + $chartbrew_base_url = "https://analytics.nhanceindia.in/report/my-first-dashboard-oHbWNWH0"; + $chartbrew_secret = getenv('METABASE_SECRET_KEY'); // Ensure this is set in your .env + + // 2. Get dynamic parameters (matching your screenshot's naming convention) + $policy_id = $this->request->getGet('client_policy_id') ?? 4687; + + // 3. Define the Payload + // Note: 'sub' (Subject) should usually be the user ID or a unique identifier + // depending on Chartbrew's specific JWT requirements. + $payload = [ + "sub" => [ + "type" => "Project", + "id" => 4, // Integer type usually preferred + "sharePolicyId" => 4 + ], + "iat" => time(), + "exp" => time() + (10 * 60), // 10 minute expiration + ]; + + // 4. Encode the JWT + // Make sure you have 'use Firebase\JWT\JWT;' at the top of your controller + $token = JWT::encode($payload, $chartbrew_secret, 'HS256'); + + // 5. Construct the URL + // We use http_build_query to ensure special characters are handled correctly + $params = [ + 'token' => $token, + 'theme' => 'light', + 'client_policy_id' => $policy_id + ]; + + $url = $chartbrew_base_url . '?' . http_build_query($params); + + // 6. Optional API response + if ($this->request->getGet('api') == 1) { + return $this->response->setJSON([ + 'status' => 'success', + 'data' => [ + 'chartbrewUrl' => $url, + 'policy_id' => $policy_id + ] + ]); + } + + // 7. Return the View + return view('chartbrew_dashboard_view', [ + 'iframe_url' => $url, + 'policy_id' => $policy_id + ]); + } + + public function testMediAssistWellness() + { + // Config + $keyString = env('MEDIASSIST_WELLNESS_KEY'); + $ivString = env('MEDIASSIST_WELLNESS_IV'); + $loginUrlTemplate = env('MEDIASSIST_WELLNESS_LOGIN_URL'); + $partnerCorpId = '15963'; + + $cipher_algorithm = 'AES-256-CBC'; + + // Payload (MATCH EXACT CASE from doc) + $payload = [ + 'Id' => '15022', + 'expiryTime' => (string)(time() + 600), // string format safer + 'CPartnerId' => $partnerCorpId, + ]; + + $plainJson = json_encode($payload, JSON_UNESCAPED_SLASHES); + + // ✅ IMPORTANT: Ensure correct key + IV length (ASCII based) + $key = substr(str_pad($keyString, 32, '0'), 0, 32); // 32 bytes + $iv = substr(str_pad($ivString, 16, '0'), 0, 16); // 16 bytes + + // Encrypt + $cipherTextRaw = openssl_encrypt( + $plainJson, + $cipher_algorithm, + $key, + OPENSSL_RAW_DATA, + $iv + ); + + if ($cipherTextRaw === false) { + return $this->respond([ + 'status' => false, + 'message' => 'Encryption failed.', + ], 500); + } + + // ✅ Use ONLY Base64 (NO urlencode unless explicitly required) + $encryptedSSO = base64_encode($cipherTextRaw); + + // Build URL + $loginUrl = str_replace( + ['{0}', '{1}'], + [$partnerCorpId, $encryptedSSO], + $loginUrlTemplate + ); + + return $this->respond([ + 'status' => true, + 'data' => [ + 'loginUrl' => $loginUrl, + 'encryptedSSO' => $encryptedSSO, + 'plainPayload' => $payload, + 'decryptMediAssistWellness' => $this->decryptMediAssistWellness($encryptedSSO), + ], + ], 200); + } + + public function decryptMediAssistWellness($encryptedSSO) + { + // Config + $keyString = env('MEDIASSIST_WELLNESS_KEY'); + $ivString = env('MEDIASSIST_WELLNESS_IV'); + + $cipher_algorithm = 'AES-256-CBC'; + + // Ensure same key + IV format used in encryption + $key = substr(str_pad($keyString, 32, '0'), 0, 32); // 32 bytes + $iv = substr(str_pad($ivString, 16, '0'), 0, 16); // 16 bytes + + // Decode Base64 + $cipherTextRaw = base64_decode($encryptedSSO, true); + + + if ($cipherTextRaw === false) { + return [ + 'status' => false, + 'message' => 'Invalid Base64 string.', + ]; + } + + // Decrypt + $decrypted = openssl_decrypt( + $cipherTextRaw, + $cipher_algorithm, + $key, + OPENSSL_RAW_DATA, + $iv + ); + + if ($decrypted === false) { + return [ + 'status' => false, + 'message' => 'Decryption failed.', + ]; + } + + // Convert JSON to array + $data = json_decode($decrypted, true); + + return [ + 'status' => true, + 'data' => [ + 'decryptedRaw' => $decrypted, + 'decoded' => $data + ], + ]; + } } diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index 2d99b088..f157d697 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -574,7 +574,9 @@ class TicketController extends BaseController ->join("({$subquery->getCompiledSelect()}) tat_category", 'tm.id = tat_category.ticket_id', 'left') ->where('tm.is_active', 1) ->whereNotIn('claim_status_id', [11, 12, 13, 22, 24, 32, 34, 42, 44, 47, 53, 58, 65]) - ->orderBy('tm.id', 'DESC'); + ->orderBy('tm.id', 'DESC') + ->limit(100); + $data = $query->get()->getResultArray(); diff --git a/app/Models/PolicyTransactionModel.php b/app/Models/PolicyTransactionModel.php index 514b63d2..940aeb41 100644 --- a/app/Models/PolicyTransactionModel.php +++ b/app/Models/PolicyTransactionModel.php @@ -1112,7 +1112,7 @@ // Default to Last 30 Days if No Filters Are Applied if (empty($client_id) && empty($insurer_id) && empty($policy_type_id) && empty($date_type) && empty($issuer) && empty($where)) { - $fromDate = date('Y-m-d', strtotime('-90 days')); + $fromDate = date('Y-m-d', strtotime('-30 days')); $toDate = date('Y-m-d 23:59:59'); $builder->where('policy_transaction.created_at >=', $fromDate) diff --git a/app/Views/chartbrew_dashboard_view.php b/app/Views/chartbrew_dashboard_view.php new file mode 100644 index 00000000..afb3d55d --- /dev/null +++ b/app/Views/chartbrew_dashboard_view.php @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index ee744b5d..69f7d3ab 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -2080,7 +2080,10 @@ body[data-sidebar-size="condensed"] .footer {
  • - Policy + Policy Add +
  • +
  • + Policy List