diff --git a/app/Config/Routes.php b/app/Config/Routes.php index f8bed9c..cbb5b40 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -144,6 +144,7 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->group("others", ["filter" => "authMVC"], function ($routes) { $routes->post("create", "ClientController::createOtherTabContent"); + $routes->post('check-duplicate', 'ClientController::validateDuplicateByClientBranch'); }); }); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 9c0edf4..d2eb167 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -151,6 +151,16 @@ class ClientController extends AdminController return $this->response->setJSON(['isDuplicate' => $isDuplicate]); } + public function validateDuplicateByClientBranch() + { + $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]); + } + public function smapletest() { $headers = [ diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index feca6fd..564fc92 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -761,36 +761,45 @@ class EmployeeController extends AdminController } - public function empby_client_clientbranch($client_id, $branch_id) - { - - $results = $this->clientModel->select('employees.id as employee_id, employees.name as employee_name, - employees.relationship, employees.emp_code, - employees.emp_status, auth_history.user_type') - ->join('employees', $client_id .'= employees.client_id AND ' . $branch_id . '= employees.client_branch_id', 'left') - ->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left') - ->where('employees.is_active', 1) - ->where('employees.emp_status !=', 'truncated') - ->groupBy('employees.id') - ->findAll(); - + public function empby_client_clientbranch($client_id, $branch_id, $client_policy_id) + { + + $results = $this->clientModel->select(' + employees.id as employee_id, + employees.name as employee_name, + employees.relationship, + employees.emp_code, + employees.emp_status, + auth_history.user_type + ') + ->join('employees', $client_id . '= employees.client_id AND ' . $branch_id . '= employees.client_branch_id', 'left') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->join('auth_history', 'employees.id = auth_history.user_id AND "employee" = auth_history.user_type', 'left') + ->where('employees.is_active', 1) + ->where('employees.emp_status !=', 'truncated') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.is_active', 1) + ->where('employee_polices.status !=', 'truncated') + ->groupBy('employees.id') + ->findAll(); + $groupedData = []; $employeeId = ''; foreach ($results as $row) { - if($employeeId != $row['employee_id']){ + if ($employeeId != $row['employee_id']) { $employeeId = $row['employee_id']; - }else{ + } else { $employeeId = null; } - $employeeName = $row['employee_name'] ; - $employeeRelationship = $row['relationship'] ; - $employeeEmpCode = $row['emp_code'] ; + $employeeName = $row['employee_name']; + $employeeRelationship = $row['relationship']; + $employeeEmpCode = $row['emp_code']; $employeeEmpStatus = $row['emp_status']; $employeeUserType = $row['user_type']; - - + + // if ($employeeId !== null && $employeeRelationship == 'Self') { if ($employeeId !== null) { // Append employee info to the branch's employees list @@ -802,16 +811,16 @@ class EmployeeController extends AdminController 'emp_status' => $employeeEmpStatus, 'user_type' => $employeeUserType ]; - } $employeeId = $row['employee_id']; } - - - return json_encode($groupedData); - } - + // print_r($groupedData); die; + + return json_encode($groupedData); + } + + /** diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 9bab925..904f54a 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -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') diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index cdd35ad..89c77d6 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -214,5 +214,19 @@ class ClientModel extends Model return $result; } + 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.'.$field, $value) + ->where('lc.contact_type', 'client') + ->where('cb.client_id', $clientId) + ->where('lc.ref_id', $branchId) + ->get(); + + return $builder->getNumRows() > 0 ? true : false; + } + } diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 1e4ee40..fc524c9 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -207,12 +207,12 @@
+ name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" onchange="validateDuplicateByClientBranch(this, 'email','branchBtnSubmit')" required>
- +
- +
@@ -945,6 +948,66 @@ function validateInput(input, table, field, submitBtnId){ } +function validateDuplicateByClientBranch(input, field, submitButId) { + let value = $(input).val().trim(); + let clientId = $('#client_id_branch').val(); + let branchId = $('#branch_id_primarykey').val(); + 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="' + field + '[]"]').each(function(index) { + console.log(`Entered value: ${value} | Contact ${index+1} value: ${$(this).val()}`); + if (this !== input && $(this).val().trim() === value) { + isLocalDuplicate = true; + return false; // break loop + } + }); + + if (isLocalDuplicate) { + console.log(`r u n Local`); + console.log(`btn Dis - true`); + toastr.warning(message, 'WARNING'); + $('#' + submitButId).prop('disabled', true); + return; // don’t call server if duplicate in UI + } + + // Don't forgot be careful + // 2 Server-side duplicate check (DB) + if (!isLocalDuplicate && value !== '') { + + $.ajax({ + url: '', + 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(`btn Dis - true`); + toastr.warning(message, 'WARNING'); + $('#' + submitButId).prop('disabled', true); + } else { + console.log(`btn Dis - false`); + $('#' + submitButId).prop('disabled', false); + } + }, + error: function(xhr, status, error) { + console.error('AJAX Error:', error); + } + }); + } +} + function getContactsData() { const contacts = []; diff --git a/app/Views/enrollment_list.php b/app/Views/enrollment_list.php index d88a461..bc59899 100755 --- a/app/Views/enrollment_list.php +++ b/app/Views/enrollment_list.php @@ -314,17 +314,18 @@ var client_id = $('#clients').val(); var branch_id = $('#branch_id').val(); - if (client_id == '0' || branch_id == '0') { + var client_policy_id = $('#client_policy_id').val(); + if (client_id == '0' || branch_id == '0' || client_policy_id == '0') { Swal.fire({ title: "warning!", - text: 'Please select the Client and Client Branch.', + text: 'Please select the Client, Client Branch and Client Policy.', icon: "warning" }); return false; } $.ajax({ - url: '' + '/employee/empby_client_clientbranch/' + client_id + '/' + branch_id, + url: '' + '/employee/empby_client_clientbranch/' + client_id + '/' + branch_id + '/' + client_policy_id, method: 'GET', headers: { "Content-Type": "application/json", @@ -359,7 +360,7 @@ var loggedIn_count = 0; data.forEach(function(employee, index) { - if(employee.emp_status !== 'draft'){ + if(employee.emp_status === 'enrolled'){ var enrolled = 'Yes'; enrolled_count++; }else{ @@ -369,8 +370,13 @@ if(employee.user_type === 'employee'){ var loggedIn = 'Yes'; loggedIn_count++; - }else{ - var loggedIn = 'No'; + }else{ + + if (employee.relationship && employee.relationship.toLowerCase() === "self") { + var loggedIn = 'No'; + }else{ + var loggedIn = '-'; + } } table.row.add([ @@ -485,6 +491,8 @@ $('#emp_enrolled_view_click').on('click', function() { + + console.log($(this).hasClass('click_hover')); if ($(this).hasClass('click_hover')) { // $(this).removeClass('click_hover'); $('.click_hover').each(function() { @@ -496,7 +504,7 @@ $(this).removeClass('click_hover'); }); $('#emp_enrolled_view_click').addClass('click_hover'); - filterTable(3, 'Yes'); // Filter "Enrolled" column (4th column, index 3) + filterTable(4, 'Yes'); // Filter "Enrolled" column (4th column, index 3) } }); @@ -512,7 +520,7 @@ $(this).removeClass('click_hover'); }); $('#emp_not_enrolled_view_click').addClass('click_hover'); - filterTable(3, 'No'); // Filter "Enrolled" column (4th column, index 3) + filterTable(4, 'No'); // Filter "Enrolled" column (4th column, index 3) } }); @@ -528,7 +536,7 @@ $(this).removeClass('click_hover'); }); $('#emp_logged_in_view_click').addClass('click_hover'); - filterTable(4, 'Yes'); // Filter "Logged-In" column (5th column, index 4) + filterTable(5, 'Yes'); // Filter "Logged-In" column (5th column, index 4) } }); @@ -544,7 +552,7 @@ $(this).removeClass('click_hover'); }); $('#emp_not_logged_in_view_click').addClass('click_hover'); - filterTable(4, 'No'); // Filter "Logged-In" column (5th column, index 4) + filterTable(5, 'No'); // Filter "Logged-In" column (5th column, index 4) } }); @@ -738,7 +746,6 @@ }); }); - function sendManualReminder(input) { console.log('sendManualReminder function called'); @@ -779,44 +786,45 @@ return false; } - Swal.fire({ - title: "Do you want to send reminder mail?", - showDenyButton: true, - showCancelButton: false, - confirmButtonText: "Yes,Send", - denyButtonText: "Don't Send" - }).then((result) => { + Swal.fire({ + title: "Do you want to send reminder mail?", + showDenyButton: true, + showCancelButton: false, + confirmButtonText: "Yes,Send", + denyButtonText: "Don't Send" + }).then((result) => { - if (result.isConfirmed) { + if (result.isConfirmed) { - $.ajax({ - url: '' + client_id + '/' + client_branch_id + '/' + client_policy_id, - type: "GET", - dataType: 'json', - success: function(res) { + $.ajax({ + url: '' + client_id + '/' + client_branch_id + '/' + client_policy_id, + type: "GET", + dataType: 'json', + success: function(res) { - console.log('send_manual_reminder', res) + console.log('send_manual_reminder', res) - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); - if(res.status == false){ - toastr.info(res.message, 'INFO'); - }else{ - toastr.success(res.message, 'SUCCESS'); + if(res.status == false){ + toastr.info(res.message, 'INFO'); + }else{ + toastr.success(res.message, 'SUCCESS'); + } + + }, + error: function(xhr, status, error) { + console.error(xhr.responseText); + console.error(status, error); + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); } - - }, - error: function(xhr, status, error) { - console.error(xhr.responseText); - console.error(status, error); - $('.loader').fadeOut(); - $('.loader-mask').delay(350).fadeOut('slow'); - } - }); - // Swal.fire("Saved!", "", "success"); - } - }); + }); + // Swal.fire("Saved!", "", "success"); + } + }); } +