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 . ', '; ?>
-
+
@@ -261,9 +262,9 @@
$(document).ready(function(){
$('#lead_id').select2();
})
-
+ var table;
$(document).ready(function(){
- $('#tickets-table').DataTable({
+ table = $('#tickets-table').DataTable({
dom: "<'row'<'col-sm-0'f><'col-sm-7 text-right'B>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
@@ -271,6 +272,11 @@
extend: 'csv',
text: 'CSV',
title: 'ClientList',
+ // title: function() {
+ // return $('#toggleButtons').is(':checked')
+ // ? 'GC-Client-List'
+ // : 'RC-Client-List';
+ // },
className: 'my_class',
exportOptions: {
columns: ':not(:last-child)'
@@ -278,13 +284,91 @@
}],
language: {
search: "_INPUT_",
- searchPlaceholder: "Search..."
+ searchPlaceholder: "Search...",
+ emptyTable: ' No Data found '
},
paging: true ,
// pagingType: 'full_numbers'
});
- })
+ $(".dt-buttons").prepend(`
+
+
+
+
+
+
+ `);
+
+ $('#toggleButtons').on('change', function() {
+ let type = $(this).is(':checked') ? 1 : 2;
+ // $('div.col-6 h4').text(
+ // $(this).is(':checked')
+ // ? "GC Client List"
+ // : "RC Client List"
+ // );
+ let url = '= base_url('client/typeList/') ?>' + 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 = = json_encode($client_rm) ?>;
+ 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 = [
+ ` ${row.client_name} (${row.short_name})`,
+ account_managers,
+ ` `
+ ];
+
+ let newRow = table.row.add(rowData);
+ $(newRow.node()).find('td:eq(0)').addClass('client_info').attr('data-id', row.id);
+ });
+ }
+ table.draw();
+ }
//DO NOT REMOVE THIS FUNCTION >>> THI FUNCTION FOR CLIENT SOFT DELETE
// function removeClient(element)
// {
|