diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 285ca8e..f8bed9c 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -71,6 +71,7 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $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 // Add a route for the view_Deposit method diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 6646aa6..f940717 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -337,7 +337,7 @@ class ClientController extends AdminController { $this->myLogger->logme('error', 'Client list function called'); $headerData['page_name'] = 'Client List'; - $data['clientList'] = $this->clientModel->getCreatedByUserName(); + $data['clientList'] = $this->clientModel->getCreatedByUserName(1); $data['client_rm'] = $this->clientRMModel->getAllClientRM(); $data['lead_data'] = $this->leadsModel->getLeadForInsertClientList(); @@ -349,6 +349,26 @@ 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 1013d0d..cdd35ad 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -105,13 +105,21 @@ class ClientModel extends Model } - public function getCreatedByUserName(){ + public function getCreatedByUserName($client_type = null){ - return $this->db->table('clients') + // return $this->db->table('clients') + // ->select('clients.*') + // ->where('is_active', 1) + // ->get() + // ->getResult(); + $query = $this->db->table('clients') ->select('clients.*') - ->where('is_active', 1) - ->get() - ->getResult(); + ->where('clients.is_active', 1); + if (!empty($client_type)) { + $query->where('clients.client_type', $client_type); + } + $data = $query->get()->getResult(); + return $data; } diff --git a/app/Views/client_basic_info.php b/app/Views/client_basic_info.php index ab3233a..29d2c76 100755 --- a/app/Views/client_basic_info.php +++ b/app/Views/client_basic_info.php @@ -91,13 +91,14 @@ input:checked + .slider:before {
-
diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 0dc28eb..eb14309 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -847,6 +847,71 @@ function checkMobileNumber(input) { } +let shortNameTimer; + +$("#client_name").on("input change keyup", function() { + clearTimeout(shortNameTimer); // cancel previous call + shortNameTimer = setTimeout(() => { + generateShortName(); // only runs after 200ms pause + }, 200); // adjust debounce delay as needed +}); + +function generateShortName() { + let clientInput = $("#client_name"); + let shortInput = $("#short_name"); + + let oldClientName = clientInput.data("old-name"); // from DB + let oldShortName = shortInput.data("old-short"); // from DB + let newClientName = clientInput.val().trim(); + console.log(`LN 866 : NEW - ${newClientName} | OLD - ${oldClientName} | OLD SN - ${oldShortName}`); + + if (newClientName.toUpperCase() === (oldClientName || '').toUpperCase()) { + shortInput.val(oldShortName); + return; + } + + if (newClientName.length == 0) { + shortInput.val(''); + return; + } + + if (newClientName.length > 0) { + let shortName = newClientName.substring(0, 10).replace(/\s+/g, '').toUpperCase(); + shortInput.val(shortName); + makeUniqueShortName(shortName); + } +} + + + +function makeUniqueShortName(baseName) { + let input = $("#short_name")[0]; // input element + checkDuplicateTableFieldValue("clients", "short_name", baseName, function(isDuplicate) { + if (isDuplicate) { + // Append sequence until unique + let counter = 1; + function tryNext() { + let padded = String(counter).padStart(3, '0'); // 001, 002, 003 + let newName = baseName + padded; + + checkDuplicateTableFieldValue("clients", "short_name", newName, function(exists) { + if (exists) { + counter++; + tryNext(); // keep checking + } else { + $("#short_name").val(newName); + validateInput(input, "clients", "short_name", "clientBtnSubmit"); + } + }); + } + tryNext(); + } else { + $("#short_name").val(baseName); + validateInput(input, "clients", "short_name", "clientBtnSubmit"); + } + }); +} + function validateInput(input, table, field, submitBtnId){ let value = $(input).val(); diff --git a/app/Views/client_list.php b/app/Views/client_list.php index 6ecfc2c..89ff403 100755 --- a/app/Views/client_list.php +++ b/app/Views/client_list.php @@ -81,7 +81,8 @@ account_manager . ', '; ?> - +