FIX_Client short name - auto suggest
This commit is contained in:
parent
0897f79d2d
commit
3ba4a65497
@ -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
|
||||
|
||||
@ -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()
|
||||
{
|
||||
|
||||
@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -91,13 +91,14 @@ input:checked + .slider:before {
|
||||
<div class="form-group col-md-6">
|
||||
<label for="client_name">Client Name<span
|
||||
class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="client_name"
|
||||
<input type="text" class="form-control" id="client_name" data-old-name="<?= isset($client['client_name']) ? $client['client_name'] : '' ?>"
|
||||
placeholder="Enter Client Name" value="<?= isset($client['client_name']) ? $client['client_name'] : '' ?>" name="client_name" required>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="short_name">Client Short Name<span
|
||||
class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" id="short_name"
|
||||
data-old-short="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>"
|
||||
placeholder="Enter Short Name" value="<?= isset($client['short_name']) ? $client['short_name'] : '' ?>" name="short_name" onkeyup="validateInput(this, 'clients', 'short_name', 'clientBtnSubmit')" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -81,7 +81,8 @@
|
||||
<?php $account_managers .= $client->account_manager . ', '; ?>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
<?php echo rtrim($account_managers, ', '); ?>
|
||||
<?php $account_managers = rtrim($account_managers, ', ');
|
||||
echo $account_managers !== '' ? $account_managers : 'N/A'; ?>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group dropdown">
|
||||
@ -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: '<div class="text-center text-muted">No Data found</div>'
|
||||
},
|
||||
paging: true ,
|
||||
// pagingType: 'full_numbers'
|
||||
});
|
||||
})
|
||||
$(".dt-buttons").prepend(`
|
||||
<span id="statusSwitchWrapper" class="dt-switch-wrapper">
|
||||
<span class="custom-switch mr-2" style="text-align: left;">
|
||||
<input type="checkbox" class="custom-control-input" id="toggleButtons" checked>
|
||||
<label class="custom-control-label" for="toggleButtons" style="vertical-align: sub !important;">Group Client</label>
|
||||
</span>
|
||||
</span>
|
||||
`);
|
||||
|
||||
$('#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 = [
|
||||
`<span> ${row.client_name} (${row.short_name})</span>`,
|
||||
account_managers,
|
||||
`<div class="btn-group dropdown">
|
||||
<a href="javascript:void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown" aria-expanded="false">
|
||||
<i class="mdi mdi-dots-horizontal"></i>
|
||||
</a>
|
||||
<div class="dropdown-menu dropdown-menu-right">
|
||||
<a class="dropdown-item" href="<?= base_url("client/list/") ?>${row.id}">
|
||||
<i class="mdi mdi-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit
|
||||
</a>
|
||||
|
||||
<?php if(in_array(get_role_id(), [1, 5])) { ?>
|
||||
<a class="dropdown-item" data-id="${row.id}" onclick="removeClient(this)">
|
||||
<i class="mdi mdi-delete mr-2 text-muted font-18 vertical-middle"></i>Delete
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>`
|
||||
];
|
||||
|
||||
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)
|
||||
// {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user