FIX_LIVE_ISSUES_4
This commit is contained in:
parent
346b2d59ec
commit
948bde3e0b
@ -1013,9 +1013,8 @@ class ClientController extends AdminController
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
'pan' => [
|
'pan' => [
|
||||||
'rules' => 'required|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]$/]',
|
'rules' => 'permit_empty|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]$/]',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'PAN Number is required.',
|
|
||||||
'regex_match' => 'Invalid PAN format. Example: ABCDE1234F'
|
'regex_match' => 'Invalid PAN format. Example: ABCDE1234F'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
@ -1129,9 +1128,8 @@ class ClientController extends AdminController
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
'pan' => [
|
'pan' => [
|
||||||
'rules' => 'required|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]$/]',
|
'rules' => 'permit_empty|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]$/]',
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'required' => 'PAN Number is required.',
|
|
||||||
'regex_match' => 'Invalid PAN format. Example: ABCDE1234F'
|
'regex_match' => 'Invalid PAN format. Example: ABCDE1234F'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
@ -5803,6 +5801,99 @@ class ClientController extends AdminController
|
|||||||
|
|
||||||
// print_r($postData); die;
|
// print_r($postData); die;
|
||||||
$client_type = $postData['client_type'] ?? null;
|
$client_type = $postData['client_type'] ?? null;
|
||||||
|
$from_modal = $postData['from_modal'] ?? null;
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'client_name' => [
|
||||||
|
'label' => 'Client Name',
|
||||||
|
'rules' => 'required|regex_match[/^[a-zA-Z0-9 ,\/_\-]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Client Name is required.',
|
||||||
|
'regex_match' => 'Client Name only allows letters, numbers, spaces, and , / _ -'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'short_name' => [
|
||||||
|
'label' => 'Client Short Name',
|
||||||
|
'rules' => 'required|regex_match[/^[a-zA-Z0-9,\/_\-]+$/]|is_unique[clients.short_name]',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Short Name is required.',
|
||||||
|
'regex_match' => 'Short Name only allows letters, numbers, and , / _ -',
|
||||||
|
'is_unique' => 'This Short Name is already in use.'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'pan' => [
|
||||||
|
'label' => 'PAN',
|
||||||
|
'rules' => 'permit_empty|regex_match[/^[A-Z]{5}[0-9]{4}[A-Z]{1}$/]',
|
||||||
|
'errors' => [
|
||||||
|
'regex_match' => 'Invalid PAN format (Example: ABCDE1234F).'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'entity_type_id' => [
|
||||||
|
'label' => 'Entity Type',
|
||||||
|
'rules' => 'required',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Please select an Entity Type.'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'branch_name' => [
|
||||||
|
'label' => 'Branch Name',
|
||||||
|
'rules' => 'required|regex_match[/^[a-zA-Z0-9 ,\/_\-]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Branch Name is required.',
|
||||||
|
'regex_match' => 'Branch Name only allows letters, numbers, spaces, and , / _ -'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'branch_code' => [
|
||||||
|
'label' => 'Branch Code',
|
||||||
|
'rules' => 'required|regex_match[/^[a-zA-Z0-9,\/_\-]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Branch Code is required.',
|
||||||
|
'regex_match' => 'Branch Code only allows letters, numbers, and , / _ -'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'name' => [
|
||||||
|
'label' => 'Contact Person Name',
|
||||||
|
'rules' => 'required|regex_match[/^[a-zA-Z0-9 ,\/_\-]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Name is required.',
|
||||||
|
'regex_match' => 'Name only allows letters, numbers, spaces, and , / _ -'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'mobile' => [
|
||||||
|
'label' => 'Mobile',
|
||||||
|
'rules' => 'required|numeric|exact_length[10]',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Mobile number is required.',
|
||||||
|
'numeric' => 'Mobile must contain only digits.',
|
||||||
|
'exact_length' => 'Mobile number must be exactly 10 digits.'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'email' => [
|
||||||
|
'label' => 'Email',
|
||||||
|
'rules' => 'required|valid_email',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'Email is required.',
|
||||||
|
'valid_email' => 'Please provide a valid email address.'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'gst' => [
|
||||||
|
'label' => 'GST',
|
||||||
|
'rules' => 'required|regex_match[/^\d{2}[A-Z]{5}\d{4}[A-Z]{1}[A-Z\d]{1}[Z]{1}[A-Z\d]{1}$/]',
|
||||||
|
'errors' => [
|
||||||
|
'required' => 'GST Number is required.',
|
||||||
|
'regex_match' => 'Invalid GST format (Example: 12ABCDE1234F5Z6).'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($from_modal) && !$this->validate($rules)) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'Input validation failed',
|
||||||
|
'code' => 400,
|
||||||
|
'errors' => $this->validator->getErrors()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$client_insert = null;
|
$client_insert = null;
|
||||||
if ($client_type == 2) {
|
if ($client_type == 2) {
|
||||||
@ -5928,7 +6019,8 @@ class ClientController extends AdminController
|
|||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
if (!$this->validate($rules)) {
|
|
||||||
|
if (!$this->validate($rules)) {
|
||||||
return $this->response->setStatusCode(400)->setJSON([
|
return $this->response->setStatusCode(400)->setJSON([
|
||||||
'status' => false,
|
'status' => false,
|
||||||
'message' => 'Input validation failed',
|
'message' => 'Input validation failed',
|
||||||
@ -5936,6 +6028,7 @@ class ClientController extends AdminController
|
|||||||
'errors' => $this->validator->getErrors()
|
'errors' => $this->validator->getErrors()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->request->getPost();
|
$data = $this->request->getPost();
|
||||||
$sanitized_post_data = sanitizeInputArrayAdvanced($data);
|
$sanitized_post_data = sanitizeInputArrayAdvanced($data);
|
||||||
$id = $sanitized_post_data['vehicle_primary_key'] ?? null;
|
$id = $sanitized_post_data['vehicle_primary_key'] ?? null;
|
||||||
|
|||||||
@ -1290,7 +1290,13 @@ class TicketController extends BaseController
|
|||||||
]
|
]
|
||||||
],
|
],
|
||||||
// --- ADDITIONAL / CONDITIONAL FIELDS ---
|
// --- ADDITIONAL / CONDITIONAL FIELDS ---
|
||||||
'claim_number' => ['label' => 'Claim Number','rules' => 'permit_empty|alpha_numeric_punct','errors' => ['alpha_numeric_punct' => 'Invalid Claim Number.']],
|
'claim_number' => [
|
||||||
|
'label' => 'Claim Number',
|
||||||
|
'rules' => 'permit_empty|regex_match[/^[a-zA-Z0-9\/_-]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'regex_match' => 'Claim Number only allows letters, numbers, slashes (/), hyphens (-), and underscores (_).'
|
||||||
|
]
|
||||||
|
],
|
||||||
'denial_date' => ['label' => 'Denial Date','rules' => 'permit_empty|regex_match[/^\d{2}\/\d{2}\/\d{4}$/]','errors' => ['regex_match' => 'Denial Date must be dd/mm/yyyy.']],
|
'denial_date' => ['label' => 'Denial Date','rules' => 'permit_empty|regex_match[/^\d{2}\/\d{2}\/\d{4}$/]','errors' => ['regex_match' => 'Denial Date must be dd/mm/yyyy.']],
|
||||||
'approved_amount' => ['label' => 'Approved Amount','rules' => 'permit_empty|numeric',
|
'approved_amount' => ['label' => 'Approved Amount','rules' => 'permit_empty|numeric',
|
||||||
'errors' => ['numeric' => 'Approved amount must be numeric']
|
'errors' => ['numeric' => 'Approved amount must be numeric']
|
||||||
@ -1649,7 +1655,13 @@ class TicketController extends BaseController
|
|||||||
],
|
],
|
||||||
|
|
||||||
// --- ADDITIONAL / CONDITIONAL FIELDS ---
|
// --- ADDITIONAL / CONDITIONAL FIELDS ---
|
||||||
'claim_number' => ['label' => 'Claim Number','rules' => 'permit_empty|alpha_numeric_punct','errors' => ['alpha_numeric_punct' => 'Invalid Claim Number.']],
|
'claim_number' => [
|
||||||
|
'label' => 'Claim Number',
|
||||||
|
'rules' => 'permit_empty|regex_match[/^[a-zA-Z0-9\/_-]+$/]',
|
||||||
|
'errors' => [
|
||||||
|
'regex_match' => 'Claim Number only allows letters, numbers, slashes (/), hyphens (-), and underscores (_).'
|
||||||
|
]
|
||||||
|
],
|
||||||
'denial_date' => ['label' => 'Denial Date','rules' => 'permit_empty|regex_match[/^\d{2}\/\d{2}\/\d{4}$/]','errors' => ['regex_match' => 'Denial Date must be dd/mm/yyyy.']],
|
'denial_date' => ['label' => 'Denial Date','rules' => 'permit_empty|regex_match[/^\d{2}\/\d{2}\/\d{4}$/]','errors' => ['regex_match' => 'Denial Date must be dd/mm/yyyy.']],
|
||||||
'approved_amount' => ['label' => 'Approved Amount','rules' => 'permit_empty|numeric',
|
'approved_amount' => ['label' => 'Approved Amount','rules' => 'permit_empty|numeric',
|
||||||
'errors' => ['numeric' => 'Approved amount must be numeric']
|
'errors' => ['numeric' => 'Approved amount must be numeric']
|
||||||
|
|||||||
@ -67,8 +67,7 @@
|
|||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="mobile">CD Account Number<span class="text-danger">*</span></label>
|
<label for="mobile">CD Account Number<span class="text-danger">*</span></label>
|
||||||
<input type="text" class="form-control" id="cd_ac_no_for_cd_master" name="cd_ac_no" onkeypress="return onlyNumbers(event)" required data-parsley-type="digits">
|
<input type="text" class="form-control" id="cd_ac_no_for_cd_master" name="cd_ac_no" pattern="[a-zA-Z0-9\/_-]+" title="Only letters, numbers, /, -, and _ are allowed" required> <small style="margin-left: 10px;font-size: 10px;"><span class="text-danger" id="cd_ac_no_for_cd_master_errorr"></span></small>
|
||||||
<small style="margin-left: 10px;font-size: 10px;"><span class="text-danger" id="cd_ac_no_for_cd_master_errorr"></span></small>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
@ -366,4 +365,33 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
// Target the input by its ID
|
||||||
|
$('#cd_ac_no_for_cd_master').on('keypress', function(e) {
|
||||||
|
// Get the character code
|
||||||
|
var keyCode = e.which || e.keyCode;
|
||||||
|
var char = String.fromCharCode(keyCode);
|
||||||
|
|
||||||
|
// Regular Expression: allow a-z, A-Z, 0-9, /, -, _
|
||||||
|
// If the character doesn't match, prevent it from being typed
|
||||||
|
var regex = /^[a-zA-Z0-9\/_-]+$/;
|
||||||
|
|
||||||
|
if (!regex.test(char)) {
|
||||||
|
e.preventDefault();
|
||||||
|
// Optional: Show a quick error message in your span
|
||||||
|
$('#cd_ac_no_for_cd_master_errorr').text('Character not allowed').fadeOut(2000, function() {
|
||||||
|
$(this).text('').show();
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Also handle "Paste" to ensure invalid data isn't pasted in
|
||||||
|
$('#cd_ac_no_for_cd_master').on('input', function() {
|
||||||
|
var value = $(this).val();
|
||||||
|
var sanitized = value.replace(/[^a-zA-Z0-9\/_-]/g, '');
|
||||||
|
$(this).val(sanitized);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@ -124,8 +124,8 @@ input:checked + .slider:before {
|
|||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-md-4">
|
<div class="form-group col-md-4">
|
||||||
<label for="pan">PAN<span class="text-danger">*</span></label>
|
<label for="pan">PAN<span class="text-danger"></span></label>
|
||||||
<input type="text" class="form-control" id="pan" placeholder="Enter PAN Number" data-parsley-error-message="Invalid PAN Number. Example: ABCDE1234F" value="<?= isset($client['pan']) ? $client['pan'] : '' ?>" name="pan" data-parsley-trigger="change" data-parsley-pattern="^[A-Z]{5}[0-9]{4}[A-Z]$" required>
|
<input type="text" class="form-control" id="pan" placeholder="Enter PAN Number" data-parsley-error-message="Invalid PAN Number. Example: ABCDE1234F" value="<?= isset($client['pan']) ? $client['pan'] : '' ?>" name="pan" data-parsley-trigger="change" data-parsley-pattern="^[A-Z]{5}[0-9]{4}[A-Z]$">
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="form-group col-md-4">
|
<!-- <div class="form-group col-md-4">
|
||||||
<label for="gst">GST<span class="text-danger">*</span></label>
|
<label for="gst">GST<span class="text-danger">*</span></label>
|
||||||
|
|||||||
@ -8,16 +8,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body" style="overflow-y: auto;height: 90vh;">
|
<div class="modal-body" style="overflow-y: auto;height: 90vh;">
|
||||||
<form class="parsley-examples" method="post" id="client_form" enctype="multipart/form-data">
|
<form class="parsley-examples" method="post" id="client_form" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="from_modal" value="1">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<label for="client_name">Client Name<span class="text-danger">*</span></label>
|
<label for="client_name_for_modal">Client Name<span class="text-danger">*</span></label>
|
||||||
<input type="text" class="form-control" id="client_name" name="client_name" required>
|
<input type="text" class="form-control" id="client_name_for_modal" name="client_name" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<label for="short_name">Client Short name<span class="text-danger">*</span></label>
|
<label for="client_short_name_for_modal">Client Short name<span class="text-danger">*</span></label>
|
||||||
<input type="text" class="form-control" id="short_name" name="short_name" onkeyup="validateInputForClient(this, 'clients', 'short_name')" required>
|
<input type="text" class="form-control" id="client_short_name_for_modal" name="short_name" onkeyup="validateInputForClient(this, 'clients', 'short_name')" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
@ -31,7 +32,7 @@
|
|||||||
<!-- Client Type -->
|
<!-- Client Type -->
|
||||||
<div class="form-row clienttypediv" style="display: none;">
|
<div class="form-row clienttypediv" style="display: none;">
|
||||||
|
|
||||||
<div class="form-group col-md-6">
|
<!-- <div class="form-group col-md-6">
|
||||||
<label for="dob">Date of Birth<span class="text-danger">*</span></label>
|
<label for="dob">Date of Birth<span class="text-danger">*</span></label>
|
||||||
<input type="text" class="form-control" id="dob" placeholder="DD/MM/YYYY" name="dob" >
|
<input type="text" class="form-control" id="dob" placeholder="DD/MM/YYYY" name="dob" >
|
||||||
</div>
|
</div>
|
||||||
@ -40,16 +41,16 @@
|
|||||||
<label for="cost_center">Mobile<span class="text-danger"></span></label>
|
<label for="cost_center">Mobile<span class="text-danger"></span></label>
|
||||||
<input type="text" class="form-control" id="phone" placeholder="Enter Mobile Number" maxlength="10" name="phone"
|
<input type="text" class="form-control" id="phone" placeholder="Enter Mobile Number" maxlength="10" name="phone"
|
||||||
onkeypress="return onlyNumbers(event)" onchange="validateInputForClient(this, 'clients', 'phone')">
|
onkeypress="return onlyNumbers(event)" onchange="validateInputForClient(this, 'clients', 'phone')">
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
<div class="form-group col-md-12">
|
<!-- <div class="form-group col-md-12">
|
||||||
<label for="email2">Email<span class="text-danger">*</span></label>
|
<label for="email2">Email<span class="text-danger">*</span></label>
|
||||||
<input type="email" class="form-control" id="email2" placeholder="Enter Email" name="email2">
|
<input type="email" class="form-control" id="email2" placeholder="Enter Email" name="email2">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<label for="aadhar">Aadhar</label>
|
<label for="aadhar">Aadhar</label>
|
||||||
<input type="text" class="form-control" id="aadhar" placeholder="Enter Aadher No" name="aadhar" maxlength="12" onchange="validateInputForClient(this, 'clients', 'aadhar')">
|
<input type="text" class="form-control" id="aadhar" placeholder="Enter Aadher No" name="aadhar" maxlength="12" onchange="validateInputForClient(this, 'clients', 'aadhar')">
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -57,8 +58,8 @@
|
|||||||
<div class="form-row branchdiv">
|
<div class="form-row branchdiv">
|
||||||
|
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<label for="short_name">Entity Type<span class="text-danger"></span></label>
|
<label for="short_name">Entity Type<span class="text-danger">*</span></label>
|
||||||
<select class="form-control" id="entity_type_id_for_client" name="entity_type_id">
|
<select class="form-control" id="entity_type_id_for_client" name="entity_type_id" required>
|
||||||
<option value="" selected>Select Entity</option>
|
<option value="" selected>Select Entity</option>
|
||||||
<?php
|
<?php
|
||||||
if (isset($entity) && count($entity)) {
|
if (isset($entity) && count($entity)) {
|
||||||
@ -87,7 +88,7 @@
|
|||||||
|
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="branch_code">Mobile<span class="text-danger">*</span></label>
|
<label for="branch_code">Mobile<span class="text-danger">*</span></label>
|
||||||
<input type="text" class="form-control" id="mobile" maxlength="10" name="mobile" onkeypress="return onlyNumbers(event)" required>
|
<input type="text" class="form-control" id="mobile" maxlength="10" name="mobile" onkeypress="return onlyNumbers(event)" oninput="this.value = this.value.replace(/[^0-9]/g, '');" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-12">
|
<div class="form-group col-md-12">
|
||||||
<label for="email">Email<span class="text-danger">*</span></label>
|
<label for="email">Email<span class="text-danger">*</span></label>
|
||||||
@ -285,11 +286,87 @@
|
|||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
console.error(xhr.responseText);
|
console.error(xhr.responseText);
|
||||||
console.error(status, error);
|
console.error(status, error);
|
||||||
isClientFormSubmitting = false;
|
setTimeout(function() {
|
||||||
$('.loader').fadeOut();
|
$('.loader').fadeOut();
|
||||||
$('.loader-mask').delay(350).fadeOut('slow');
|
$('.loader-mask').delay(350).fadeOut('slow');
|
||||||
|
// $('#client_add_modal_submit_btn').prop('disabled', false);
|
||||||
|
if (xhr.status === 400) {
|
||||||
|
let response = JSON.parse(xhr.responseText);
|
||||||
|
let errorMessages = "";
|
||||||
|
let seenMessages = []; // Array to store unique messages
|
||||||
|
if (response.errors) {
|
||||||
|
$.each(response.errors, function (field, message) {
|
||||||
|
if (!seenMessages.includes(message)) {
|
||||||
|
errorMessages += `• ${message}<br>`;
|
||||||
|
seenMessages.push(message); // Mark this message as "seen"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
|
||||||
|
} else {
|
||||||
|
toastr.warning(response.message || 'Validation failed', 'Warning');
|
||||||
|
}
|
||||||
|
} else if (xhr.status === 403) {
|
||||||
|
let response = JSON.parse(xhr.responseText);
|
||||||
|
toastr.error(response.message, 'Security Policy');
|
||||||
|
} else if (xhr.status === 404) {
|
||||||
|
toastr.warning('Resource not found', 'Warning');
|
||||||
|
} else if (xhr.status === 500) {
|
||||||
|
toastr.error('Something went wrong . Please try again later.', 'Server Error');
|
||||||
|
} else {
|
||||||
|
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#client_name_for_modal').on('input', function() {
|
||||||
|
clearTimeout(shortNameTimer);
|
||||||
|
shortNameTimer = setTimeout(generateShortNameModal, 200);
|
||||||
|
});
|
||||||
|
|
||||||
|
function generateShortNameModal() {
|
||||||
|
let clientInput = $("#client_name_for_modal");
|
||||||
|
let shortInput = $("#client_short_name_for_modal");
|
||||||
|
let newClientName = clientInput.val().trim();
|
||||||
|
|
||||||
|
console.log(`LN : NEW - ${newClientName}`);
|
||||||
|
if (newClientName.length == 0) {
|
||||||
|
shortInput.val('');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let shortName = newClientName.substring(0, 10).replace(/\s+/g, '').toUpperCase();
|
||||||
|
console.log(`LN : NEW - ${shortName}`);
|
||||||
|
makeUniqueShortNameModal(shortName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeUniqueShortNameModal(baseName) {
|
||||||
|
let input = $("#client_short_name_for_modal")[0];
|
||||||
|
|
||||||
|
checkDuplicateTableFieldValue("clients", "short_name", baseName, function(isDuplicate) {
|
||||||
|
if (isDuplicate) {
|
||||||
|
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();
|
||||||
|
} else {
|
||||||
|
$("#client_short_name_for_modal").val(newName);
|
||||||
|
validateInput(input, "clients", "short_name");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
tryNext();
|
||||||
|
} else {
|
||||||
|
$("#client_short_name_for_modal").val(baseName);
|
||||||
|
validateInput(input, "clients", "short_name");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user