From 0848cb5eeb5d70755942e52b68269d6c1de5fd83 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Wed, 3 Jun 2026 09:33:49 +0530 Subject: [PATCH] CHNAGE_CD_INLINE_EDIT_AND_ACM_TPA_DASHBOARD_INPAM --- app/Config/Acl.php | 2 +- app/Config/Routes.php | 3 +- app/Controllers/ClientController.php | 103 +++++ app/Controllers/EmployeeController.php | 73 +++ app/Controllers/TestingController.php | 84 ++-- app/Models/ClientPolicyModel.php | 18 + app/Views/client_basic_info.php | 6 +- app/Views/client_deposit_list.php | 2 +- app/Views/layout/header.php | 5 + app/Views/meta_dashboard_demo_one.php | 364 +++++++++++++-- app/Views/view_deposit.php | 613 ++++++++++++++++++++++++- 11 files changed, 1203 insertions(+), 70 deletions(-) diff --git a/app/Config/Acl.php b/app/Config/Acl.php index ce46852c..8b0476ea 100644 --- a/app/Config/Acl.php +++ b/app/Config/Acl.php @@ -44,7 +44,7 @@ class Acl '#^/sendDataToTPA#' => ['roles' => [ADMIN_ROLE_ID, HEAD_ROLE_ID, ACCOUNT_MANAGER_ROLE_ID, MANAGER_ROLE_ID]], '#^/swagger#' => ['roles' => [ADMIN_ROLE_ID, HEAD_ROLE_ID, ACCOUNT_MANAGER_ROLE_ID, MANAGER_ROLE_ID]], '#^/viewClaimFile#' => ['roles' => [ADMIN_ROLE_ID, HEAD_ROLE_ID, ACCOUNT_MANAGER_ROLE_ID, MANAGER_ROLE_ID, STAFF_ROLE_ID]], - + '#^/employee/tpaReportsDashboard#' => ['roles' => [ACCOUNT_MANAGER_ROLE_ID]], diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4b2155c4..a152d831 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -137,6 +137,7 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->get('view_deposit/(:num)', 'ClientController::view_Deposit/$1'); $routes->get('createtransaction', 'ClientController::createtransaction'); $routes->post('save_deposit', 'ClientController::saveDeposit'); + $routes->post('update_deposit_amount', 'ClientController::updateDepositAmount'); $routes->post("saveApiData", "ClientController::saveApiData"); $routes->get("generateToken","ClientController::sendToken"); // $routes->get('view_Deposit/(:num)/(:num)','ClientController/view_Deposit/$1/$2'); @@ -240,7 +241,7 @@ $routes->group("/employee", ["filter" => "authMVC"], function ($routes) { $routes->get("bulkGenerateEcardAndStoreinS3", "EmployeeController::bulkGenerateEcardAndStoreinS3"); $routes->get('clearCdSession', 'EmployeeController::clearCdSession'); $routes->get('checkSessionStatus', 'EmployeeController::checkSessionStatus'); - + $routes->get("tpaReportsDashboard", "EmployeeController::tpaReportsDashboard"); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 7a3a89a1..4c9edd8d 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -902,6 +902,109 @@ class ClientController extends AdminController return $this->response->setJSON(['success' => $response['success']]); } + public function updateDepositAmount() + { + $rules = [ + 'deposit_id' => 'required|is_natural_no_zero', + 'amount' => 'required|numeric|greater_than_equal_to[0]', + 'transaction_type' => 'required|in_list[Credit,Debit]', + 'client_id' => 'required', + 'insurer_id' => 'required|is_natural_no_zero', + 'cd_ac_pk' => 'required|is_natural_no_zero', + ]; + + if (! $this->validate($rules)) { + return $this->response + ->setStatusCode(400) + ->setJSON([ + 'status' => 'error', + 'message' => 'Input validation failed', + 'errors' => $this->validator->getErrors(), + ]); + } + + $postData = sanitizeInputArrayAdvanced($this->request->getPost()); + $depositId = (int) ($postData['deposit_id'] ?? 0); + $clientId = $postData['client_id'] ?? null; + $insurerId = (int) ($postData['insurer_id'] ?? 0); + $cdAcPk = (int) ($postData['cd_ac_pk'] ?? 0); + $amount = (float) ($postData['amount'] ?? 0); + $transactionType = $postData['transaction_type'] ?? 'Credit'; + $loggedInUserID = get_session_userid(); + + $depositModel = new ClientDepositModel(); + + $targetRow = $depositModel + ->where('id', $depositId) + ->where('client_id', $clientId) + ->where('insurer_id', $insurerId) + ->where('cd_ac_pk', $cdAcPk) + ->where('is_active', 1) + ->first(); + + if (empty($targetRow)) { + return $this->response + ->setStatusCode(404) + ->setJSON([ + 'status' => 'error', + 'message' => 'Transaction not found for this account.', + ]); + } + + $existingType = $targetRow['transaction_type'] ?? ''; + if ($existingType !== $transactionType) { + return $this->response + ->setStatusCode(400) + ->setJSON([ + 'status' => 'error', + 'message' => 'Only ' . $existingType . ' value can be edited for this transaction.', + ]); + } + + $db = \Config\Database::connect(); + $db->transBegin(); + + $depositModel->update($depositId, [ + 'amount' => $amount, + 'transaction_type' => $transactionType, + 'updated_by' => $loggedInUserID, + ]); + + $rows = $depositModel + ->where('client_id', $clientId) + ->where('insurer_id', $insurerId) + ->where('cd_ac_pk', $cdAcPk) + ->where('is_active', 1) + ->orderBy('id', 'ASC') + ->findAll(); + + $runningBalance = 0.0; + foreach ($rows as $row) { + $rowAmount = (float) ($row['amount'] ?? 0); + $runningBalance += (($row['transaction_type'] ?? '') === 'Credit') ? $rowAmount : -$rowAmount; + $depositModel->update((int) $row['id'], [ + 'balance' => $runningBalance, + 'updated_by' => $loggedInUserID, + ]); + } + + if ($db->transStatus() === false) { + $db->transRollback(); + return $this->response + ->setStatusCode(500) + ->setJSON([ + 'status' => 'error', + 'message' => 'Failed to update transaction.', + ]); + } + + $db->transCommit(); + return $this->response->setJSON([ + 'status' => 'success', + 'message' => 'Transaction updated successfully.', + ]); + } + public function editClientOnboarding($id = null) { diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index c345330c..d209ca84 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -55,6 +55,8 @@ use Dompdf\Dompdf; use Dompdf\Options; use Kint; +use Firebase\JWT\JWT; + class EmployeeController extends AdminController { @@ -7339,4 +7341,75 @@ class EmployeeController extends AdminController } } + + public function tpaReportsDashboard() + { + $METABASE_SECRET_KEY = getenv('METABASE_SECRET_KEY'); + $policy_id = $this->request->getGet('client_policy') ?? null; + + if ($this->request->getGet('api') != 1) { + $data = [ + 'tab_name' => 'TPA Reports', + 'page_name' => 'TPA Reports', + 'metabaseUrl' => 'https://nsights.nhanceindia.in', + 'dashboardApiUrl' => base_url('/employee/tpaReportsDashboard'), + ]; + + return $this->loadLayout('meta_dashboard_demo_one', $data); + } + + if (empty($policy_id)) { + return $this->respond([ + 'status' => 'failed', + 'message' => 'Client policy is required.', + 'data' => [], + ]); + } + + $client_policy_data = $this->clientPolicyModel + ->select('tpa.dashboard_id') + ->join('tpa', 'client_policy.tpa_id = tpa.id') + ->where('client_policy.id', $policy_id) + ->first(); + + $database_id = isset($client_policy_data['dashboard_id']) ? (int) $client_policy_data['dashboard_id'] : null; + + if (empty($database_id)) { + + if ($this->request->getGet('api') == 1) { + return $this->respond([ + 'status' => 'failed', + 'message' => 'There is no dashboard for this TPA.', + 'data' => [] + ]); + } + + return view('errors/404', [ + 'message' => 'There is no dashboard for this TPA.' + ]); + } + + $payload = [ + 'resource' => [ + 'dashboard' => $database_id + ], + 'exp' => time() + (10 * 60), // 10 minutes + 'params' => (object) ['client_policy' => $policy_id ], // MUST be object for Metabase + + ]; + + $token = JWT::encode($payload, $METABASE_SECRET_KEY, 'HS256'); + // dd($token); + + return $this->respond([ + 'status' => 'success', + 'message' => 'Form data received successfully!', + 'data' => [ + 'metabaseToken' => $token, + 'metabaseUrl' => 'https://nsights.nhanceindia.in', + ], + ]); + } + + } diff --git a/app/Controllers/TestingController.php b/app/Controllers/TestingController.php index eecbfb45..3cb57320 100644 --- a/app/Controllers/TestingController.php +++ b/app/Controllers/TestingController.php @@ -365,7 +365,7 @@ class TestingController extends BaseController $insurerBranchModel = new InsurerBranchModel(); $insurer_branch = $insurerBranchModel->getInsurerBranchesWithInsurerNames(); - $dataArray = $data['pt_co_share_details']; // Example + $dataArray = $data['pt_co_share_details'] ?? []; // Example $cd_ac_pk = 'CD12345'; $role_id = 1; $team_id = ['6']; @@ -1101,10 +1101,8 @@ class TestingController extends BaseController // 🔐 Move this to .env in real projects $METABASE_SECRET_KEY = getenv('METABASE_SECRET_KEY'); - $database_id = (int)$this->request->getGet('database_id') ?? 2; + $database_id = (int) ($this->request->getGet('database_id') ?? 2); $policy_id = $this->request->getGet('client_policy') ?? null; - $tpa_url = 'https://nsights.nhanceindia.in/public/dashboard/4babf324-6c1e-4c5a-adbb-1c80a0f545b1'; - $policy_id = $policy_id ? $policy_id : 4687; $payload = [ 'resource' => [ // 'dashboard' => 1 @@ -1127,21 +1125,33 @@ class TestingController extends BaseController // 'token' => $token, // 'iframe_url' => "https://your-metabase-domain/embed/dashboard/{$token}#bordered=true&titled=true" // ]); - if($this->request->getGet('api') == 1) - { - return $this->respond([ - 'status' => 'success', - 'message' => 'Form data received successfully!', - 'data' => [ - 'metabaseToken' => $token, - 'metabaseUrl' => 'https://nsights.nhanceindia.in'] + if ($this->request->getGet('api') == 1) { + if (empty($policy_id)) { + return $this->respond([ + 'status' => 'failed', + 'message' => 'Client policy is required.', + 'data' => [], + ]); + } + + return $this->respond([ + 'status' => 'success', + 'message' => 'Dashboard token generated.', + 'data' => [ + 'metabaseToken' => $token, + 'metabaseUrl' => 'https://nsights.nhanceindia.in', + ], ]); } - return view('meta_dashboard_demo_one', [ - 'metabaseToken' => $token, - 'metabaseUrl' => 'https://nsights.nhanceindia.in', - ]); + $data = [ + 'tab_name' => 'Metabase Dashboard', + 'page_name' => 'Metabase Dashboard', + 'metabaseUrl' => 'https://nsights.nhanceindia.in', + 'dashboardApiUrl' => base_url('/metaDashboardDemo'), + ]; + + return $this->loadLayout('meta_dashboard_demo_one', $data); } public function testingquerys1(){ @@ -1175,7 +1185,26 @@ class TestingController extends BaseController public function metaTpaDashboardDemo() { $METABASE_SECRET_KEY = getenv('METABASE_SECRET_KEY'); - $policy_id = $this->request->getGet('client_policy') ?? 4687; + $policy_id = $this->request->getGet('client_policy') ?? null; + + if ($this->request->getGet('api') != 1) { + $data = [ + 'tab_name' => 'TPA Reports', + 'page_name' => 'TPA Reports', + 'metabaseUrl' => 'https://nsights.nhanceindia.in', + 'dashboardApiUrl' => base_url('/metaTpaDashboardDemo'), + ]; + + return $this->loadLayout('meta_dashboard_demo_one', $data); + } + + if (empty($policy_id)) { + return $this->respond([ + 'status' => 'failed', + 'message' => 'Client policy is required.', + 'data' => [], + ]); + } $client_policy_data = $this->ClientPolicyModel ->select('tpa.dashboard_id') @@ -1212,20 +1241,13 @@ class TestingController extends BaseController $token = JWT::encode($payload, $METABASE_SECRET_KEY, 'HS256'); // dd($token); - if ($this->request->getGet('api') == 1) { - return $this->respond([ - 'status' => 'success', - 'message' => 'Form data received successfully!', - 'data' => [ - 'metabaseToken' => $token, - 'metabaseUrl' => 'https://nsights.nhanceindia.in' - ] - ]); - } - - return view('meta_dashboard_demo_one', [ - 'metabaseToken' => $token, - 'metabaseUrl' => 'https://nsights.nhanceindia.in', + return $this->respond([ + 'status' => 'success', + 'message' => 'Form data received successfully!', + 'data' => [ + 'metabaseToken' => $token, + 'metabaseUrl' => 'https://nsights.nhanceindia.in', + ], ]); } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index c3acb681..b650d585 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -311,6 +311,24 @@ class ClientPolicyModel extends Model // Fetch the deposit data based on client and insurer IDs $query = $this->db->table('cash_deposit') ->select('cash_deposit.*') + ->select(" + (select old_value from auditing_history where pk = cash_deposit.id and field_name = 'amount' and table_name = 'cash_deposit' order by id desc limit 1) as old_amt, + (select new_value from auditing_history where pk = cash_deposit.id and field_name = 'amount' and table_name = 'cash_deposit' order by id desc limit 1) as new_amt, + (select created_by from auditing_history where pk = cash_deposit.id and field_name = 'amount' and table_name = 'cash_deposit' order by id desc limit 1) as amt_updated_by, + (select created_at from auditing_history where pk = cash_deposit.id and field_name = 'amount' and table_name = 'cash_deposit' order by id desc limit 1) as amt_updated_at, + ( + select up.first_name + from user_profiles up + where up.id = ( + select created_by + from auditing_history + where pk = cash_deposit.id and field_name = 'amount' and table_name = 'cash_deposit' + order by id desc + limit 1 + ) + limit 1 + ) as amt_updated_by_name + ") ->select('insurers.name as insurer_name, insurers.short_name as insurer_short') ->select('clients.client_name as clientname, clients.short_name as clientshort, client_policy.policy_no') ->select('cd_master.cd_ac_no as cd_master_account_no') diff --git a/app/Views/client_basic_info.php b/app/Views/client_basic_info.php index efbbb33a..58a16e1a 100755 --- a/app/Views/client_basic_info.php +++ b/app/Views/client_basic_info.php @@ -236,7 +236,7 @@ input:checked + .slider:before { class="text-danger">* - + @@ -293,7 +293,7 @@ input:checked + .slider:before {
- +
insurer_id}?client_id={$value->client_id}&cd_ac_pk={$value->cd_ac_pk}"); ?>"> - View Deposit + View Details diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index 36ead7b7..7a0e9ff2 100755 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -2017,6 +2017,11 @@ body[data-sidebar-size="condensed"] .footer {
  • Retail Endorsement
  • + +
  • + TPA Reports +
  • +
    diff --git a/app/Views/meta_dashboard_demo_one.php b/app/Views/meta_dashboard_demo_one.php index 4652f9e9..fa558443 100644 --- a/app/Views/meta_dashboard_demo_one.php +++ b/app/Views/meta_dashboard_demo_one.php @@ -1,33 +1,345 @@ - - - - - Metabase Dashboard + - + + - - - - + $elBranch.on('change', function () { + const branchId = $(this).val(); + const clientId = $elClient.val(); + rebuildSelect($elPolicy, 'Select', !branchId); + clearDashboard(); + setStatus(branchId ? '' : 'Select branch and policy to load the dashboard.'); - - + if (!branchId || !clientId) { + return; + } + + const policiesForClient = policyByClient[clientId] || []; + const policies = policiesForClient.filter(function (p) { + return String(p.client_branch_id) === String(branchId); + }); + + rebuildSelect($elPolicy, 'Select', policies.length === 0, policies, function (p) { return p.id; }, function (p) { + const type = p.policy_type || ''; + const no = p.policy_no || ''; + return (type && no) ? (type + ' - ' + no) : (no || type || ('Policy ' + p.id)); + }); + if (policies.length === 0) { + setStatus('No policies found for this branch.', 'error'); + } + }); + + $elPolicy.on('change', function () { + fetchDashboard($(this).val()); + }); + + initSelect2($elClient, false); + initSelect2($elBranch, true); + initSelect2($elPolicy, true); + loadFilterData(); + }); + diff --git a/app/Views/view_deposit.php b/app/Views/view_deposit.php index 50984d01..5bd008a9 100755 --- a/app/Views/view_deposit.php +++ b/app/Views/view_deposit.php @@ -31,8 +31,8 @@ foreach ($depositdata as $row) { $vd_col_max_len[9] = max($vd_col_max_len[9], mb_strlen((string) ($row->description ?? ''))); $vd_col_max_len[10] = max($vd_col_max_len[10], mb_strlen((string) ($row->username ?? ''))); } -$vd_col_min_px = [120, 100, 72, 160, 110, 88, 88, 88, 100, 140, 100]; -$vd_col_max_px = [200, 120, 120, 360, 160, 140, 120, 120, 140, 400, 200]; +$vd_col_min_px = [120, 100, 72, 160, 110, 88, 150, 150, 170, 140, 100]; +$vd_col_max_px = [200, 120, 120, 360, 160, 140, 180, 180, 220, 400, 200]; $vd_col_width_px = nhance_dt_column_widths_px($vd_header_labels, $vd_col_max_len, $vd_col_min_px, $vd_col_max_px); ?>