From 54a99059b820ed01df27a2331938c5dee527742d Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Wed, 8 Oct 2025 11:24:41 +0530 Subject: [PATCH] FIX_passing client type --- app/Config/Routes.php | 2 + app/Controllers/ClientController.php | 25 ++++++- app/Models/ClientModel.php | 6 +- app/Views/client_list.php | 101 ++++++++++++++++++++++++++- 4 files changed, 129 insertions(+), 5 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9996931c..c54be9b2 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -90,11 +90,13 @@ $routes->group("/dashboard", ["filter" => "authMVC"], function ($routes) { $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->get("list", "ClientController::index"); + $routes->get("type/(:any)", "ClientController::type/$1"); $routes->get("create", "ClientController::clientOnboarding"); $routes->get('deposit/(:num)', 'ClientController::deposit/$1'); $routes->get('remove/(:num)', 'ClientController::removeClient/$1'); $routes->get("list/(:any)", "ClientController::editClientOnboarding/$1"); $routes->post('wipe', 'ClientController::wipeDemoClient'); + $routes->get("typeList/(:any)", "ClientController::typeList/$1"); // application/config/routes.php diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 9baf11cd..3a149d37 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -471,7 +471,7 @@ class ClientController extends AdminController $this->myLogger->logme('error', 'Client list function called'); $headerData['tab_name'] = 'Client List'; $headerData['page_name'] = 'Clients'; // Both Browser Tab name And Page name are same. - $data['clientList'] = $this->clientModel->getCreatedByUserName(); + $data['clientList'] = $this->clientModel->getCreatedByUserName(1); // passing client_type $data['client_rm'] = $this->clientRMModel->getAllClientRM(); $data['lead_data'] = $this->leadsModel->getLeadForInsertClientList(); @@ -484,6 +484,29 @@ class ClientController extends AdminController // $this->loadLayout('client_onboarding', $data); } + + public function typeList($id = null) + { + try { + $data = $this->clientModel->getCreatedByUserName($id); // passing client_type + if (empty($data)) { + return $this->response + ->setJSON(['status' => 'error', 'message' => 'No Records found']) + ->setStatusCode(404); + } + + return $this->response + ->setJSON(['status' => 'success', 'data' => $data]) + ->setStatusCode(200); + + } catch (\Throwable $e) { + return $this->response + ->setJSON(['status' => 'error', 'message' => $e->getMessage()]) + ->setStatusCode(500); + } + } + + public function updateEmpAndPolicyStatus() { diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index e1407c2c..9abe8929 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -108,7 +108,7 @@ class ClientModel extends Model } - public function getCreatedByUserName(){ + public function getCreatedByUserName($client_type = null){ $role_id = get_role_id(); $user_id = get_session_userid(); @@ -118,6 +118,10 @@ class ClientModel extends Model ->join('client_rm', 'client_rm.client_id = clients.id','left') ->where('clients.is_active', 1); + if (!empty($client_type)) { + $query->where('clients.client_type', $client_type); + } + if (in_array($role_id, [2, 3])) { // If the user is a Account Manager or Manager, filter by user_id diff --git a/app/Views/client_list.php b/app/Views/client_list.php index 8cacb6bc..4d7039b6 100755 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -294,10 +294,10 @@ table.dataTable thead th { $(document).ready(function(){ $('#lead_id').select2(); }) - +var table; $(document).ready(function() { - $('#tickets-table').DataTable({ + table = $('#tickets-table').DataTable({ dom: "<'row'<'col-12 d-flex justify-content-between align-items-center'<'datatable-search dataTables_filter'f><'datatable-buttons dt-buttons'B>>>" + "<'row'<'col-sm-12'tr>>" + "<'row'<'col-sm-5'i><'col-sm-7'p>>", @@ -340,13 +340,108 @@ $(document).ready(function() _INPUT_ `, - searchPlaceholder: "Search" + searchPlaceholder: "Search", + emptyTable: '
No Data found
' }, paging: true , // pagingType: 'full_numbers' }); + + // $(".datatable-buttons").prepend(` + // + // `); + + $(".datatable-buttons").prepend(` + + + + + + + `); + $("#toggleButtons").prop("checked", true); // default checked. + $('#toggleButtons').on('change', function() { + if ($(this).is(':checked')) { + console.log("Checked na gro"); + loadTableData(1); + } else { + console.log("UnChecked na indi"); + loadTableData(2); + } + }); + }) + function loadTableData(type) { + let url = '' + type + $.ajax({ + url: url, + method: 'GET', + success: function(response) { + if (response.status === "success" && Array.isArray(response.data)) { + renderRows(response.data); + } else { + renderRows([]); + } + }, + error: function(xhr, status, error) { + console.error("Error loading :", error); + renderRows([]); + } + }); + } + + function renderRows(data) { + table.clear(); + if (Array.isArray(data) && data.length) { + data.forEach((row, index) => { + let clientrm = ; + let account_managers = ""; + + clientrm.forEach(client => { + if (client.client_id == row.id) { + account_managers += client.account_manager + ", "; + } + }); + account_managers = account_managers.replace(/,\s*$/, ""); + if (account_managers === "") account_managers = "N/A"; + + let rowData = [ + index + 1, + `${row.client_name} (${row.short_name})`, + account_managers, + `` + ]; + + let newRow = table.row.add(rowData); + $(newRow.node()).find('td:eq(0)').addClass('text-center'); + $(newRow.node()).find('td:eq(1)').addClass('client_info').attr('data-id', row.id); + + }); + } + table.draw(); + } + //DO NOT REMOVE THIS FUNCTION >>> THI FUNCTION FOR CLIENT SOFT DELETE // function removeClient(element) // {