From 2867ed7535db062d21f7eac5db73acad7e5b4367 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Thu, 9 Oct 2025 16:55:10 +0530 Subject: [PATCH 01/12] CHANGE_Pre_app_having_post_branch_id - VADIVEL J 2025-09-10 --- app/Controllers/ClientController.php | 96 ++++++++++++++++++++++++++++ app/Views/client_branch.php | 10 ++- 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 6646aa6..c43b256 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -877,7 +877,29 @@ class ClientController extends AdminController } $data['created_by'] = get_session_userid(); + + // before updating check if post_branch_id is already existing in the current db + + if(isset($data['post_branch_id']) && !empty($data['post_branch_id'])) + { + $existing_pre_branch = $this->clientBranchModel + ->where('post_branch_id',$data['post_branch_id']) + // ->where('id !=',$pre_branch_id) + ->where('is_active',1) + ->first(); + + if($existing_pre_branch) + { + return $this->respond([ + 'status' => false, + 'code' => 409, + 'message' => 'The pre branch id '.$data['pre_branch_id'].' is already mapped with another branch. Please check.', + ], 409); + } + } + $insert = $this->clientBranchModel->insert($data); + $pre_branch_id = $insert; if ($insert) { $level_contact_data = $this->request->getPost('level_contect_data'); @@ -885,6 +907,16 @@ class ClientController extends AdminController $this->saveLevelContacts($level_contact_data, $insert); } + if($pre_branch_id && isset($data['post_branch_id']) && !empty($data['post_branch_id'])) + { + // need to update the client_branch in the pre + $result = $this->updatePostClientBranch($data['post_branch_id'],$pre_branch_id , "create"); + + log_message('error','Post client_branch update result for post_branch_id '.$data['post_branch_id'].' and pre_branch_id '.$pre_branch_id.' is '.json_encode($result)); + } + + + // if ($insert) { // for ($i = 0; $i < count($this->request->getPost('name')); $i++) { // // Prepare data to insert @@ -925,7 +957,11 @@ class ClientController extends AdminController $this->myLogger->logme('error', 'Client branch EDIT function called'); $id = $this->request->getPost('branch_id_primarykey'); $client_id = $this->request->getPost('client_id'); + $post_branch_id = $this->request->getPost('post_branch_id') ?? ""; + $data = $this->request->getPost(); + $data['post_branch_id'] = $post_branch_id; + $units = $this->request->getPost('units'); $emp_unit_count = 0; @@ -984,7 +1020,44 @@ class ClientController extends AdminController } $data['updated_by'] = get_session_userid(); + + $pre_branch_id = $id; + + // before updating check if post_branch_id is already existing in the current db + + if(isset($data['post_branch_id']) && !empty($data['post_branch_id'])) + { + $existing_pre_branch = $this->clientBranchModel + ->where('post_branch_id',$data['post_branch_id']) + ->where('id !=',$pre_branch_id) + ->where('is_active',1) + ->first(); + + if($existing_pre_branch) + { + return $this->respond([ + 'status' => false, + 'code' => 409, + 'message' => 'The pre branch id '.$data['pre_branch_id'].' is already mapped with another branch. Please check.', + ], 409); + } + } + + + $insert = $this->clientBranchModel->update($id, $data); + + + + if($pre_branch_id && isset($data['post_branch_id']) && !empty($data['post_branch_id'])) + { + // need to update the client_branch in the post + $result = $this->updatePostClientBranch($data['post_branch_id'],$pre_branch_id , "update"); + + log_message('error','Post client_branch update result for post_branch_id '.$data['post_branch_id'].' and pre_branch_id '.$pre_branch_id.' is '.json_encode($result)); + } + + $this->myLogger->logme('error', 'Client branch EDITED by {data}', ['data' => get_session_userid()]); if ($insert) { @@ -5209,6 +5282,29 @@ class ClientController extends AdminController } + public function updatePostClientBranch($post_branch_id,$pre_branch_id , $operation){ + + + + + $postDB = \Config\Database::connect('postDB'); + + if($operation != 'create'){ + + $builder = $postDB->table('client_branch'); + $builder->where('pre_branch_id', $pre_branch_id); + $builder->update(['pre_branch_id' => null]); + } + + $builder = $postDB->table('client_branch'); + $builder->where('id', $post_branch_id); + $builder->update(['pre_branch_id' => $pre_branch_id]); + + return true; + + } + + diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 0dc28eb..4450e93 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -91,10 +91,14 @@ + + + + @@ -379,7 +383,7 @@ $("#branch_form").submit(function(event) { event.preventDefault(); branch_PrimaryKey = $('#client_id_branch').val(); - console.log('branch_PrimaryKey', branch_PrimaryKey) + console.log('branch_PrimaryKey', branch_PrimaryKey); if (branch_PrimaryKey === '') { toastr.error('Client is required', 'Error'); @@ -488,6 +492,10 @@ $("#branch_form").submit(function(event) { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); console.log('Something Wrong!', 'warning'); + if(xhr.status == 409){ + alert('The Current Branch is Already Existing..!!'); + } + }, 300); } }); From b75370fc100f39dae64ee20d54d0e733d2b90937 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Thu, 9 Oct 2025 17:07:38 +0530 Subject: [PATCH 02/12] CHANGE_Post_app_having_pre_branch_id - VADIVEL J 2025-09-10 --- app/Controllers/ClientController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 2d7fc0e..57fcb60 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -913,7 +913,7 @@ class ClientController extends AdminController return $this->respond([ 'status' => false, 'code' => 409, - 'message' => 'The pre branch id '.$data['pre_branch_id'].' is already mapped with another branch. Please check.', + 'message' => 'The pre branch id '.$data['post_branch_id'].' is already mapped with another branch. Please check.', ], 409); } } From c4bbe7b80cf945ea511f094ac127046b45d3cd55 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Thu, 9 Oct 2025 17:13:20 +0530 Subject: [PATCH 03/12] CHANGE_Post_app_having_pre_branch_id - VADIVEL J 2025-10-09 --- app/Controllers/ClientController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 57fcb60..9c0edf4 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -913,7 +913,7 @@ class ClientController extends AdminController return $this->respond([ 'status' => false, 'code' => 409, - 'message' => 'The pre branch id '.$data['post_branch_id'].' is already mapped with another branch. Please check.', + 'message' => 'The branch is already mapped with another branch. Please check.', ], 409); } } @@ -1058,7 +1058,7 @@ class ClientController extends AdminController return $this->respond([ 'status' => false, 'code' => 409, - 'message' => 'The pre branch id '.$data['pre_branch_id'].' is already mapped with another branch. Please check.', + 'message' => 'The branch is already mapped with another branch. Please check.', ], 409); } } From 16ce68e79e8d3630745284611382807b3e34fae4 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Thu, 9 Oct 2025 17:55:32 +0530 Subject: [PATCH 04/12] CHANGE_UI_FIX - VADIVEL J 2025-10-09 --- app/Views/client_onboarding.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Views/client_onboarding.php b/app/Views/client_onboarding.php index d67e88d..f7008b9 100755 --- a/app/Views/client_onboarding.php +++ b/app/Views/client_onboarding.php @@ -126,7 +126,7 @@ body {
- @@ -142,7 +142,7 @@ body {
- @@ -427,6 +427,10 @@ body { }) + + $(function() { + $('.select2').select2(); + }); From 0e770a2f4791ef0d876779852295ec3a7d195813 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Thu, 9 Oct 2025 20:30:03 +0530 Subject: [PATCH 05/12] CHANGE_UI_FIX - VADIVEL J 2025-10-09 --- app/Views/client_onboarding.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Views/client_onboarding.php b/app/Views/client_onboarding.php index f7008b9..536b67a 100755 --- a/app/Views/client_onboarding.php +++ b/app/Views/client_onboarding.php @@ -313,6 +313,12 @@ body { From 58ae91815911eca83349ba9f24b90b1934975db9 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Fri, 10 Oct 2025 09:47:37 +0530 Subject: [PATCH 06/12] CHANGE_UI_FIX - VADIVEL J 2025-10-10 --- app/Views/client_onboarding.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Views/client_onboarding.php b/app/Views/client_onboarding.php index 536b67a..40cf999 100755 --- a/app/Views/client_onboarding.php +++ b/app/Views/client_onboarding.php @@ -323,6 +323,9 @@ $(document).ready(function() { $('#auto_fetch_branch').html(``); + $('.loader').fadeIn(); + $('.loader-mask').fadeIn(); + $.ajax({ url: "", type: "POST", @@ -347,6 +350,8 @@ $(document).ready(function() { console.error("Error occurred:", status, error); }, complete: function() { + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); console.log("auto_fetch_client call is completed..!!"); } }); From 05c9a3ede748d1ce9af2cf2394e20dbfcc2860a8 Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Fri, 10 Oct 2025 10:55:55 +0530 Subject: [PATCH 07/12] CHANGE_UI_FIX - VADIVEL J 2025-10-10 --- app/Views/client_branch.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index 18c2301..a6419b7 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -312,6 +312,7 @@ $('#btnBranchAdd').click(function() { $('#district').val(''); $('#branch_city').val(''); $('#branch_form')[0].reset(); + $('#branch_form').parsley().reset(); $('.ac').css('display', 'block'); contactCount = 1 @@ -400,8 +401,13 @@ $("#branch_form").submit(function(event) { $('.loader').fadeIn(); $('.loader-mask').fadeIn(); + if (branch_PrimaryKey == '') { + $('#branch_form input[name="pre_branch_id"]').val(''); + } + var formData = new FormData($('#branch_form')[0]); + const jsonString = JSON.stringify(selectedValues); const level_contect_data_json_string = JSON.stringify(level_contect_data); console.log('jsonString', jsonString); @@ -492,7 +498,7 @@ $("#branch_form").submit(function(event) { $('.loader').fadeOut(); $('.loader-mask').delay(350).fadeOut('slow'); console.log('Something Wrong!', 'warning'); - if(xhr.status == 409){ + if(xhr.status === 409){ alert('The Current Branch is Already Existing..!!'); } From 1713e729121590c5faac0af602bbd87c5f88e5dd Mon Sep 17 00:00:00 2001 From: vadivelJ96 Date: Fri, 10 Oct 2025 12:28:46 +0530 Subject: [PATCH 08/12] CHANGE_UI_FIX - VADIVEL J 2025-10-10 --- app/Views/client_branch.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index a6419b7..882a7f1 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -314,6 +314,7 @@ $('#btnBranchAdd').click(function() { $('#branch_form')[0].reset(); $('#branch_form').parsley().reset(); $('.ac').css('display', 'block'); + $('#post_branch_id').val(''); contactCount = 1 var addButton = document.getElementById('add'); @@ -401,10 +402,6 @@ $("#branch_form").submit(function(event) { $('.loader').fadeIn(); $('.loader-mask').fadeIn(); - if (branch_PrimaryKey == '') { - $('#branch_form input[name="pre_branch_id"]').val(''); - } - var formData = new FormData($('#branch_form')[0]); From f6c6c37a7aec445f54ca02b8b506f29bc532d91f Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Fri, 10 Oct 2025 18:58:55 +0530 Subject: [PATCH 09/12] FIX_75. The system should allow the same HR contact to be linked with different corporates, instead of restricting them to just one. --- app/Config/Routes.php | 1 + app/Controllers/ClientController.php | 10 ++++++ app/Models/ClientModel.php | 14 ++++++++ app/Views/client_branch.php | 53 +++++++++++++++++++++++++++- 4 files changed, 77 insertions(+), 1 deletion(-) 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 57fcb60..2643143 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() + { + $request = service('request'); + $value = $request->getPost('value'); + $clientId = $request->getPost('client_id'); + $branchId = $request->getPost('branch_id'); + $isDuplicate = $this->clientModel->isDuplicateByClientBranch($value, $clientId, $branchId); + return $this->response->setJSON(['isDuplicate' => $isDuplicate]); + } + public function smapletest() { $headers = [ diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index cdd35ad..d7708b7 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -214,5 +214,19 @@ class ClientModel extends Model return $result; } + public function isDuplicateByClientBranch($email, $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.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 18c2301..f55b2dc 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -648,7 +648,7 @@ function appendContactHtml(contact = false, reset = false) {
- +
@@ -942,6 +942,57 @@ function validateInput(input, table, field, submitBtnId){ } +function validateDuplicateByClientBranch(input, 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}`); + + // 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 !== '') { + isLocalDuplicate = true; + return false; // break loop + } + }); + + if (isLocalDuplicate) { + console.log(`r u n Local`); + toastr.warning("Email is duplicate!", '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 !== '') { + console.log(`r u n Server`); + $.ajax({ + url: '', + 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); + } + }); + } +} + function getContactsData() { const contacts = []; From 830f2b247d78ab5571dcb1795e84d688bea039c9 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Sat, 11 Oct 2025 11:35:11 +0530 Subject: [PATCH 10/12] FIX_LIVE_ISSUE_VIEW_EROLLMENT : RV --- app/Controllers/EmployeeController.php | 61 ++++++++++------- app/Views/enrollment_list.php | 94 ++++++++++++++------------ 2 files changed, 86 insertions(+), 69 deletions(-) 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/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"); + } + }); } + From de07c1c06100dce15c9b59f2983ebc71e78f6b89 Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Sat, 11 Oct 2025 11:58:32 +0530 Subject: [PATCH 11/12] FIX_resolved - Email duplication based on ClientBrach vvj reported --- app/Views/client_branch.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index fe817b3..b8370c8 100755 --- a/app/Views/client_branch.php +++ b/app/Views/client_branch.php @@ -207,7 +207,7 @@
+ name="email[]" id="email" data-parsley-trigger="change" data-parsley-type="email" onkeyup="validateDuplicateByClientBranch(this, 'branchBtnSubmit')" required>
@@ -946,11 +946,11 @@ function validateInput(input, table, field, submitBtnId){ } function validateDuplicateByClientBranch(input, 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}`); - // Don't forgot be careful // 1 Local duplication check (User entered) let isLocalDuplicate = false; From 6dfdb270a23ee798a5e55d8bc5a8ee140c542061 Mon Sep 17 00:00:00 2001 From: venba-Inspriron-3558 Date: Sat, 11 Oct 2025 16:05:16 +0530 Subject: [PATCH 12/12] FIX_resolved - Email duplication based on ClientBrach vrs reported --- app/Controllers/ClientController.php | 10 ++++---- app/Models/ClientModel.php | 4 ++-- app/Views/client_branch.php | 35 +++++++++++++++++----------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 7d412c5..d2eb167 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -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]); } diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index d7708b7..89c77d6 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -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) diff --git a/app/Views/client_branch.php b/app/Views/client_branch.php index b8370c8..297451d 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,17 +945,21 @@ 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) { + console.log(`Entered value: ${value} | Contact ${index+1} value: ${$(this).val()}`); + if (this !== input && $(this).val().trim() === value) { isLocalDuplicate = true; return false; // break loop } @@ -963,7 +967,8 @@ function validateDuplicateByClientBranch(input, submitButId) { if (isLocalDuplicate) { console.log(`r u n Local`); - toastr.warning("Email is duplicate!", 'WARNING'); + console.log(`btn Dis - true`); + toastr.warning(message, 'WARNING'); $('#' + submitButId).prop('disabled', true); return; // don’t call server if duplicate in UI } @@ -971,21 +976,25 @@ function validateDuplicateByClientBranch(input, submitButId) { // Don't forgot be careful // 2 Server-side duplicate check (DB) if (!isLocalDuplicate && value !== '') { - console.log(`r u n Server`); + $.ajax({ url: '', type: 'POST', data: { client_id: clientId, branch_id: branchId, - value: value + value: value, + field: field }, dataType: 'json', success: function(response) { if (response.isDuplicate) { - toastr.warning("Email already exists!", 'WARNING'); + 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); } },