Merge branch 'dev' of bitbucket.org:jubilian/nhance-enrollment into dev
This commit is contained in:
commit
240e4806bd
@ -153,11 +153,11 @@ class ClientController extends AdminController
|
||||
|
||||
public function validateDuplicateByClientBranch()
|
||||
{
|
||||
$request = service('request');
|
||||
$value = $request->getPost('value');
|
||||
$clientId = $request->getPost('client_id');
|
||||
$branchId = $request->getPost('branch_id');
|
||||
$isDuplicate = $this->clientModel->isDuplicateByClientBranch($value, $clientId, $branchId);
|
||||
$value = $this->request->getPost('value');
|
||||
$clientId = $this->request->getPost('client_id');
|
||||
$branchId = $this->request->getPost('branch_id');
|
||||
$field = $this->request->getPost('field');
|
||||
$isDuplicate = $this->clientModel->isDuplicateByClientBranch($value, $field, $clientId, $branchId);
|
||||
return $this->response->setJSON(['isDuplicate' => $isDuplicate]);
|
||||
}
|
||||
|
||||
|
||||
@ -1774,53 +1774,28 @@ class EmployeeRestController extends AdminController
|
||||
|
||||
public function getClientDetails()
|
||||
{
|
||||
log_message('error', 'STEP 1: getClientDetails called');
|
||||
|
||||
try {
|
||||
// STEP 2: Extract Authorization header
|
||||
$jwt = $this->request->getHeaderLine('Authorization');
|
||||
log_message('error', 'STEP 2: Authorization header: ' . $jwt);
|
||||
$pre_client_id = $this->request->getGet('pre_client_id');
|
||||
$pre_branch_id = $this->request->getGet('pre_branch_id');
|
||||
$post_client_id = $this->request->getGet('post_client_id');
|
||||
$post_branch_id = $this->request->getGet('post_branch_id');
|
||||
|
||||
|
||||
$jwtParts = explode(' ', $jwt);
|
||||
if (count($jwtParts) < 2) {
|
||||
log_message('error', 'STEP 2.1: Invalid Authorization header format');
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Invalid Authorization header'], 400);
|
||||
}
|
||||
if ($pre_client_id != null) {
|
||||
|
||||
|
||||
$token = $jwtParts[1];
|
||||
log_message('error', 'STEP 3: Extracted JWT token');
|
||||
|
||||
$tokenParts = explode('.', $token);
|
||||
if (count($tokenParts) !== 3) {
|
||||
log_message('error', 'STEP 3.1: Invalid JWT structure');
|
||||
return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Invalid JWT token'], 400);
|
||||
}
|
||||
|
||||
$decodedPayload = json_decode(base64_decode($tokenParts[1]), true);
|
||||
log_message('error', 'STEP 4: Decoded JWT payload: ' . json_encode($decodedPayload));
|
||||
|
||||
$token_type = $decodedPayload['token_type'] ?? null;
|
||||
log_message('error', 'STEP 5: Token type = ' . $token_type);
|
||||
|
||||
$client_id = $this->request->getGet('client_id');
|
||||
$client_branch_id = $this->request->getGet('client_branch_id');
|
||||
log_message('error', 'STEP 6: Query params - client_id: ' . $client_id . ', client_branch_id: ' . $client_branch_id);
|
||||
|
||||
if ($token_type === 'pre') {
|
||||
log_message('error', 'STEP 7: Handling "pre" token type');
|
||||
|
||||
$client = $this->clientModel->where('id', $client_id)->first();
|
||||
$client = $this->clientModel->where('id', $pre_client_id)->first();
|
||||
if ($client) {
|
||||
log_message('error', 'STEP 8: Found client: ' . json_encode($client));
|
||||
|
||||
|
||||
$client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
||||
|
||||
$clientPolicy = $this->clientPolicyModel
|
||||
->where('client_id', $client_id)
|
||||
->where('client_branch_id', $client_branch_id)
|
||||
->where('client_id', $pre_client_id)
|
||||
->where('client_branch_id', $pre_branch_id)
|
||||
->findAll();
|
||||
|
||||
log_message('error', 'STEP 9: Found client policy count: ' . count($clientPolicy));
|
||||
|
||||
|
||||
return $this->respond([
|
||||
'status' => 'success',
|
||||
@ -1831,33 +1806,34 @@ class EmployeeRestController extends AdminController
|
||||
]
|
||||
], 200);
|
||||
} else {
|
||||
log_message('error', 'STEP 10: No client found for client_id: ' . $client_id);
|
||||
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
}
|
||||
} elseif ($token_type === 'post') {
|
||||
log_message('error', 'STEP 11: Handling "post" token type');
|
||||
} elseif ($post_client_id != null) {
|
||||
|
||||
|
||||
$restAuthController = new RestAuthenticationController;
|
||||
|
||||
$queryParams = [
|
||||
'client_id' => $client_id,
|
||||
'client_branch_id' => $client_branch_id
|
||||
'client_id' => $post_client_id,
|
||||
'client_branch_id' => $post_branch_id
|
||||
];
|
||||
|
||||
log_message('error', 'STEP 12: Calling post enrollment API with params: ' . json_encode($queryParams));
|
||||
return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails');
|
||||
|
||||
return $restAuthController->callThirdPartyGETAPI($queryParams, 'getClientDetails', ['token' => $jwt]);
|
||||
} else {
|
||||
log_message('error', 'STEP 13: Unknown token_type: ' . $token_type);
|
||||
|
||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
log_message('error', 'STEP 14: Exception occurred - ' . $e->getMessage());
|
||||
|
||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getSiMappedArray($policy_id,$base_policy_id)
|
||||
{
|
||||
$selfGMC = $this->employeeModel->select('employees.name , employee_polices.basic_cover_si')
|
||||
|
||||
@ -214,12 +214,12 @@ class ClientModel extends Model
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function isDuplicateByClientBranch($email, $clientId, $branchId)
|
||||
public function isDuplicateByClientBranch($value, $field, $clientId, $branchId)
|
||||
{
|
||||
$builder = $this->db->table('level_contacts lc')
|
||||
->select('lc.id')
|
||||
->join('client_branch cb', 'lc.ref_id = cb.id', 'left')
|
||||
->where('lc.email', $email)
|
||||
->where('lc.'.$field, $value)
|
||||
->where('lc.contact_type', 'client')
|
||||
->where('cb.client_id', $clientId)
|
||||
->where('lc.ref_id', $branchId)
|
||||
|
||||
@ -73,7 +73,7 @@
|
||||
|
||||
<div class="row float-left" style="position: relative; bottom: 20px; left: 13px;">
|
||||
<button type="button" id="btnAutoBranchFetch"
|
||||
class="btn btn-primary waves-effect waves-light btn-sm "> Auto Fetch branch Details</button>
|
||||
class="btn btn-primary waves-effect waves-light btn-sm "> Fetch Client Branch (Post-Enrolment)</button>
|
||||
</div>
|
||||
|
||||
<div class="row float-right" style="position: relative; bottom: 20px; right: 13px;">
|
||||
@ -207,12 +207,12 @@
|
||||
<div class="form-group col-md-6">
|
||||
<label for="last_name">Email<span class="text-danger">*</span></label>
|
||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Email"
|
||||
name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" onkeyup="validateInput(this, 'level_contacts', 'email', 'branchBtnSubmit')" required>
|
||||
name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" onchange="validateDuplicateByClientBranch(this, 'email','branchBtnSubmit')" required>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="mobile">Mobile<span class="text-danger">*</span></label>
|
||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Mobile"
|
||||
name="mobile[]" id="mobile" onkeyup="validateInput(this, 'level_contacts', 'mobile', 'branchBtnSubmit')"
|
||||
name="mobile[]" id="mobile" onchange="validateDuplicateByClientBranch(this, 'mobile', 'branchBtnSubmit')"
|
||||
onkeypress="return onlyNumbers(event)" maxlength="10" minlength="10"
|
||||
data-parsley-type-message="Please enter a valid 10-digit mobile number."
|
||||
data-parsley-required-message="Please enter a valid 10-digit mobile number."
|
||||
@ -315,6 +315,7 @@ $('#btnBranchAdd').click(function() {
|
||||
$('#branch_form').parsley().reset();
|
||||
$('.ac').css('display', 'block');
|
||||
$('#post_branch_id').val('');
|
||||
$('#branch_id_primarykey').val('');
|
||||
contactCount = 1
|
||||
|
||||
var addButton = document.getElementById('add');
|
||||
@ -378,6 +379,8 @@ $("#branch_form").submit(function(event) {
|
||||
|
||||
var selectedValues = $("#selected").val();
|
||||
console.log(selectedValues, selectedValues);
|
||||
console.log("branch_id_primarykey", $('#branch_id_primarykey').val());
|
||||
|
||||
|
||||
let level_contect_data = getContactsData();
|
||||
console.log('level_contect_data', level_contect_data);
|
||||
@ -651,11 +654,11 @@ function appendContactHtml(contact = false, reset = false) {
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<label for="${uniqueId}_last_name">Email<span class="text-danger">*</span></label>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.email : ''}" type="text" class="form-control" placeholder="Enter Contact Email" name="email[]" id="${uniqueId}_email" data-parsley-trigger="change" data-parsley-type="email" onkeyup="validateDuplicateByClientBranch(this, 'branchBtnSubmit')" required>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.email : ''}" type="text" class="form-control" placeholder="Enter Contact Email" name="email[]" id="${uniqueId}_email" data-parsley-trigger="change" data-parsley-type="email" onchange="validateDuplicateByClientBranch(this, 'email','branchBtnSubmit')" required>
|
||||
</div>
|
||||
<div class="form-group col-md-6">
|
||||
<label for="${uniqueId}_mobile">Mobile<span class="text-danger">*</span></label>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.mobile : ''}" type="text" class="form-control" placeholder="Enter Contact Mobile" name="mobile[]" id="${uniqueId}_mobile" onkeyup="validateInput(this, 'level_contacts', 'mobile', 'branchBtnSubmit')" onkeypress = "return onlyNumbers(event)" maxlength="10" min="10" data-parsley-type-message="Please enter a valid 10-digit mobile number." data-parsley-required-message="Please enter a valid 10-digit mobile number." required>
|
||||
<input value="${contact !== undefined && contact !== false ? contact.mobile : ''}" type="text" class="form-control" placeholder="Enter Contact Mobile" name="mobile[]" id="${uniqueId}_mobile" onchange="validateDuplicateByClientBranch(this, 'mobile', 'branchBtnSubmit')" onkeypress = "return onlyNumbers(event)" maxlength="10" min="10" data-parsley-type-message="Please enter a valid 10-digit mobile number." data-parsley-required-message="Please enter a valid 10-digit mobile number." required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" style="display: flex;">
|
||||
@ -945,54 +948,116 @@ function validateInput(input, table, field, submitBtnId){
|
||||
|
||||
}
|
||||
|
||||
function validateDuplicateByClientBranch(input, submitButId) {
|
||||
function validateDuplicateByClientBranch(input, field, submitButId) {
|
||||
let value = $(input).val().trim();
|
||||
let clientId = $('#client_id_branch').val();
|
||||
let branchId = $('#branch_id_primarykey').val();
|
||||
console.log(`Ln968 cId: ${clientId} | bId: ${branchId}`);
|
||||
|
||||
let label = $(input).closest('.form-group').find('label').text().replace('*', '').trim();
|
||||
let message = label ? label + " is duplicate!" : "Value is duplicate!";
|
||||
|
||||
console.log(`cId: ${clientId} | bId: ${branchId}`);
|
||||
|
||||
// Don't forgot be careful
|
||||
// 1 Local duplication check (User entered)
|
||||
let isLocalDuplicate = false;
|
||||
$('input[name="email[]"]').each(function() {
|
||||
if (this !== input && $(this).val().trim() === value && value !== '') {
|
||||
$('input[name="' + field + '[]"]').each(function(index) {
|
||||
let compareVal = $(this).val().trim();
|
||||
console.log(`Entered value: ${value} | Contact ${index+1} value: ${$(this).val()}`);
|
||||
if (this !== input && compareVal !== '' && compareVal === value) {
|
||||
isLocalDuplicate = true;
|
||||
return false; // break loop
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (isLocalDuplicate) {
|
||||
console.log(`r u n Local`);
|
||||
toastr.warning("Email is duplicate!", 'WARNING');
|
||||
console.log(`duplicate found for ${field}`);
|
||||
toastr.warning(message, 'WARNING');
|
||||
$('#' + submitButId).prop('disabled', true);
|
||||
return; // don’t call server if duplicate in UI
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// important Skip empty values
|
||||
if (value === '') {
|
||||
checkAllFieldsValid(submitButId);
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't forgot be careful
|
||||
// 2 Server-side duplicate check (DB)
|
||||
if (!isLocalDuplicate && value !== '') {
|
||||
console.log(`r u n Server`);
|
||||
$.ajax({
|
||||
url: '<?= base_url("client/others/check-duplicate") ?>',
|
||||
type: 'POST',
|
||||
data: {
|
||||
client_id: clientId,
|
||||
branch_id: branchId,
|
||||
value: value
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.isDuplicate) {
|
||||
toastr.warning("Email already exists!", 'WARNING');
|
||||
$('#' + submitButId).prop('disabled', true);
|
||||
} else {
|
||||
$('#' + submitButId).prop('disabled', false);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX Error:', error);
|
||||
$.ajax({
|
||||
url: '<?= base_url("client/others/check-duplicate") ?>',
|
||||
type: 'POST',
|
||||
data: {
|
||||
client_id: clientId,
|
||||
branch_id: branchId,
|
||||
value: value,
|
||||
field: field
|
||||
},
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.isDuplicate) {
|
||||
console.log(`r u n Server`);
|
||||
console.log(`duplicate found for ${field}`);
|
||||
toastr.warning(message, 'WARNING');
|
||||
$('#' + submitButId).prop('disabled', true);
|
||||
} else {
|
||||
console.log(`No duplicate for ${field}`);
|
||||
checkAllFieldsValid(submitButId);
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX Error:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// recheck all contacts before enabling submit
|
||||
function checkAllFieldsValid(submitButId) {
|
||||
let emailDuplicates = false;
|
||||
let mobileDuplicates = false;
|
||||
|
||||
// cross check all EMAIL duplicates
|
||||
let emailSeen = [];
|
||||
$('input[name="email[]"]').each(function() {
|
||||
let val = $(this).val().trim();
|
||||
if (val && emailSeen.includes(val)) {
|
||||
emailDuplicates = true;
|
||||
} else if (val) {
|
||||
emailSeen.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
// cross check all MOBILE duplicates
|
||||
let mobileSeen = [];
|
||||
$('input[name="mobile[]"]').each(function() {
|
||||
let val = $(this).val().trim();
|
||||
if (val && mobileSeen.includes(val)) {
|
||||
mobileDuplicates = true;
|
||||
} else if (val) {
|
||||
mobileSeen.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
if (emailDuplicates || mobileDuplicates) {
|
||||
$('#' + submitButId).prop('disabled', true);
|
||||
// show correct message based on what’s duplicated
|
||||
if (emailDuplicates && mobileDuplicates) {
|
||||
toastr.warning("Email and Mobile values are duplicate!", "WARNING");
|
||||
console.log('Both Email and Mobile duplicates');
|
||||
} else if (emailDuplicates) {
|
||||
toastr.warning("Email duplicate!", "WARNING");
|
||||
console.log('Cross Check Email duplicates');
|
||||
} else if (mobileDuplicates) {
|
||||
toastr.warning("Mobile duplicate!", "WARNING");
|
||||
console.log('Cross Check Mobile duplicates');
|
||||
}
|
||||
console.log(`btn Dis - true`);
|
||||
} else {
|
||||
console.log('unique — enable');
|
||||
console.log(`btn Dis - false`);
|
||||
$('#' + submitButId).prop('disabled', false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -115,7 +115,7 @@ body {
|
||||
<div class="modal-dialog modal-dialog-centered" style="margin-left: 400px !important;">
|
||||
<div class="modal-content modal-lg">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="autoFetchBranchModalLabel">Auto Fetch Branch Details</h5>
|
||||
<h5 class="modal-title" id="autoFetchBranchModalLabel">Fetch Client Branch (Post-Enrolment)</h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user