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()
|
public function validateDuplicateByClientBranch()
|
||||||
{
|
{
|
||||||
$request = service('request');
|
$value = $this->request->getPost('value');
|
||||||
$value = $request->getPost('value');
|
$clientId = $this->request->getPost('client_id');
|
||||||
$clientId = $request->getPost('client_id');
|
$branchId = $this->request->getPost('branch_id');
|
||||||
$branchId = $request->getPost('branch_id');
|
$field = $this->request->getPost('field');
|
||||||
$isDuplicate = $this->clientModel->isDuplicateByClientBranch($value, $clientId, $branchId);
|
$isDuplicate = $this->clientModel->isDuplicateByClientBranch($value, $field, $clientId, $branchId);
|
||||||
return $this->response->setJSON(['isDuplicate' => $isDuplicate]);
|
return $this->response->setJSON(['isDuplicate' => $isDuplicate]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1774,53 +1774,28 @@ class EmployeeRestController extends AdminController
|
|||||||
|
|
||||||
public function getClientDetails()
|
public function getClientDetails()
|
||||||
{
|
{
|
||||||
log_message('error', 'STEP 1: getClientDetails called');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// STEP 2: Extract Authorization header
|
$pre_client_id = $this->request->getGet('pre_client_id');
|
||||||
$jwt = $this->request->getHeaderLine('Authorization');
|
$pre_branch_id = $this->request->getGet('pre_branch_id');
|
||||||
log_message('error', 'STEP 2: Authorization header: ' . $jwt);
|
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
$token = $jwtParts[1];
|
if ($pre_client_id != null) {
|
||||||
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);
|
$client = $this->clientModel->where('id', $pre_client_id)->first();
|
||||||
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();
|
|
||||||
if ($client) {
|
if ($client) {
|
||||||
log_message('error', 'STEP 8: Found client: ' . json_encode($client));
|
|
||||||
|
|
||||||
$client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
$client['client_logo'] = base_url() . 'public/uploads/logo/' . $client['client_logo'];
|
||||||
|
|
||||||
$clientPolicy = $this->clientPolicyModel
|
$clientPolicy = $this->clientPolicyModel
|
||||||
->where('client_id', $client_id)
|
->where('client_id', $pre_client_id)
|
||||||
->where('client_branch_id', $client_branch_id)
|
->where('client_branch_id', $pre_branch_id)
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
log_message('error', 'STEP 9: Found client policy count: ' . count($clientPolicy));
|
|
||||||
|
|
||||||
return $this->respond([
|
return $this->respond([
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
@ -1831,33 +1806,34 @@ class EmployeeRestController extends AdminController
|
|||||||
]
|
]
|
||||||
], 200);
|
], 200);
|
||||||
} else {
|
} else {
|
||||||
log_message('error', 'STEP 10: No client found for client_id: ' . $client_id);
|
|
||||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||||
}
|
}
|
||||||
} elseif ($token_type === 'post') {
|
} elseif ($post_client_id != null) {
|
||||||
log_message('error', 'STEP 11: Handling "post" token type');
|
|
||||||
|
|
||||||
$restAuthController = new RestAuthenticationController;
|
$restAuthController = new RestAuthenticationController;
|
||||||
|
|
||||||
$queryParams = [
|
$queryParams = [
|
||||||
'client_id' => $client_id,
|
'client_id' => $post_client_id,
|
||||||
'client_branch_id' => $client_branch_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 {
|
} else {
|
||||||
log_message('error', 'STEP 13: Unknown token_type: ' . $token_type);
|
|
||||||
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
return $this->respond(['status' => 'failed', 'code' => 404, 'data' => []], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
log_message('error', 'STEP 14: Exception occurred - ' . $e->getMessage());
|
|
||||||
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $e->getMessage()], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function getSiMappedArray($policy_id,$base_policy_id)
|
public function getSiMappedArray($policy_id,$base_policy_id)
|
||||||
{
|
{
|
||||||
$selfGMC = $this->employeeModel->select('employees.name , employee_polices.basic_cover_si')
|
$selfGMC = $this->employeeModel->select('employees.name , employee_polices.basic_cover_si')
|
||||||
|
|||||||
@ -214,12 +214,12 @@ class ClientModel extends Model
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isDuplicateByClientBranch($email, $clientId, $branchId)
|
public function isDuplicateByClientBranch($value, $field, $clientId, $branchId)
|
||||||
{
|
{
|
||||||
$builder = $this->db->table('level_contacts lc')
|
$builder = $this->db->table('level_contacts lc')
|
||||||
->select('lc.id')
|
->select('lc.id')
|
||||||
->join('client_branch cb', 'lc.ref_id = cb.id', 'left')
|
->join('client_branch cb', 'lc.ref_id = cb.id', 'left')
|
||||||
->where('lc.email', $email)
|
->where('lc.'.$field, $value)
|
||||||
->where('lc.contact_type', 'client')
|
->where('lc.contact_type', 'client')
|
||||||
->where('cb.client_id', $clientId)
|
->where('cb.client_id', $clientId)
|
||||||
->where('lc.ref_id', $branchId)
|
->where('lc.ref_id', $branchId)
|
||||||
|
|||||||
@ -73,7 +73,7 @@
|
|||||||
|
|
||||||
<div class="row float-left" style="position: relative; bottom: 20px; left: 13px;">
|
<div class="row float-left" style="position: relative; bottom: 20px; left: 13px;">
|
||||||
<button type="button" id="btnAutoBranchFetch"
|
<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>
|
||||||
|
|
||||||
<div class="row float-right" style="position: relative; bottom: 20px; right: 13px;">
|
<div class="row float-right" style="position: relative; bottom: 20px; right: 13px;">
|
||||||
@ -207,12 +207,12 @@
|
|||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="last_name">Email<span class="text-danger">*</span></label>
|
<label for="last_name">Email<span class="text-danger">*</span></label>
|
||||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Email"
|
<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>
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="mobile">Mobile<span class="text-danger">*</span></label>
|
<label for="mobile">Mobile<span class="text-danger">*</span></label>
|
||||||
<input value="" type="text" class="form-control" placeholder="Enter Contact Mobile"
|
<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"
|
onkeypress="return onlyNumbers(event)" maxlength="10" minlength="10"
|
||||||
data-parsley-type-message="Please enter a valid 10-digit mobile number."
|
data-parsley-type-message="Please enter a valid 10-digit mobile number."
|
||||||
data-parsley-required-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();
|
$('#branch_form').parsley().reset();
|
||||||
$('.ac').css('display', 'block');
|
$('.ac').css('display', 'block');
|
||||||
$('#post_branch_id').val('');
|
$('#post_branch_id').val('');
|
||||||
|
$('#branch_id_primarykey').val('');
|
||||||
contactCount = 1
|
contactCount = 1
|
||||||
|
|
||||||
var addButton = document.getElementById('add');
|
var addButton = document.getElementById('add');
|
||||||
@ -378,6 +379,8 @@ $("#branch_form").submit(function(event) {
|
|||||||
|
|
||||||
var selectedValues = $("#selected").val();
|
var selectedValues = $("#selected").val();
|
||||||
console.log(selectedValues, selectedValues);
|
console.log(selectedValues, selectedValues);
|
||||||
|
console.log("branch_id_primarykey", $('#branch_id_primarykey').val());
|
||||||
|
|
||||||
|
|
||||||
let level_contect_data = getContactsData();
|
let level_contect_data = getContactsData();
|
||||||
console.log('level_contect_data', level_contect_data);
|
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-row">
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="${uniqueId}_last_name">Email<span class="text-danger">*</span></label>
|
<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>
|
||||||
<div class="form-group col-md-6">
|
<div class="form-group col-md-6">
|
||||||
<label for="${uniqueId}_mobile">Mobile<span class="text-danger">*</span></label>
|
<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>
|
</div>
|
||||||
<div class="form-group" style="display: flex;">
|
<div class="form-group" style="display: flex;">
|
||||||
@ -945,48 +948,62 @@ function validateInput(input, table, field, submitBtnId){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateDuplicateByClientBranch(input, submitButId) {
|
function validateDuplicateByClientBranch(input, field, submitButId) {
|
||||||
let value = $(input).val().trim();
|
let value = $(input).val().trim();
|
||||||
let clientId = $('#client_id_branch').val();
|
let clientId = $('#client_id_branch').val();
|
||||||
let branchId = $('#branch_id_primarykey').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
|
// Don't forgot be careful
|
||||||
// 1 Local duplication check (User entered)
|
// 1 Local duplication check (User entered)
|
||||||
let isLocalDuplicate = false;
|
let isLocalDuplicate = false;
|
||||||
$('input[name="email[]"]').each(function() {
|
$('input[name="' + field + '[]"]').each(function(index) {
|
||||||
if (this !== input && $(this).val().trim() === value && value !== '') {
|
let compareVal = $(this).val().trim();
|
||||||
|
console.log(`Entered value: ${value} | Contact ${index+1} value: ${$(this).val()}`);
|
||||||
|
if (this !== input && compareVal !== '' && compareVal === value) {
|
||||||
isLocalDuplicate = true;
|
isLocalDuplicate = true;
|
||||||
return false; // break loop
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (isLocalDuplicate) {
|
if (isLocalDuplicate) {
|
||||||
console.log(`r u n Local`);
|
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);
|
$('#' + 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
|
// Don't forgot be careful
|
||||||
// 2 Server-side duplicate check (DB)
|
// 2 Server-side duplicate check (DB)
|
||||||
if (!isLocalDuplicate && value !== '') {
|
|
||||||
console.log(`r u n Server`);
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '<?= base_url("client/others/check-duplicate") ?>',
|
url: '<?= base_url("client/others/check-duplicate") ?>',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: {
|
data: {
|
||||||
client_id: clientId,
|
client_id: clientId,
|
||||||
branch_id: branchId,
|
branch_id: branchId,
|
||||||
value: value
|
value: value,
|
||||||
|
field: field
|
||||||
},
|
},
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
if (response.isDuplicate) {
|
if (response.isDuplicate) {
|
||||||
toastr.warning("Email already exists!", 'WARNING');
|
console.log(`r u n Server`);
|
||||||
|
console.log(`duplicate found for ${field}`);
|
||||||
|
toastr.warning(message, 'WARNING');
|
||||||
$('#' + submitButId).prop('disabled', true);
|
$('#' + submitButId).prop('disabled', true);
|
||||||
} else {
|
} else {
|
||||||
$('#' + submitButId).prop('disabled', false);
|
console.log(`No duplicate for ${field}`);
|
||||||
|
checkAllFieldsValid(submitButId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
@ -994,6 +1011,54 @@ function validateDuplicateByClientBranch(input, submitButId) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContactsData() {
|
function getContactsData() {
|
||||||
|
|||||||
@ -115,7 +115,7 @@ body {
|
|||||||
<div class="modal-dialog modal-dialog-centered" style="margin-left: 400px !important;">
|
<div class="modal-dialog modal-dialog-centered" style="margin-left: 400px !important;">
|
||||||
<div class="modal-content modal-lg">
|
<div class="modal-content modal-lg">
|
||||||
<div class="modal-header">
|
<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">
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
<span aria-hidden="true">×</span>
|
<span aria-hidden="true">×</span>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user