Merge branch 'dev' of bitbucket.org:jubilian/nhance-enrollment into dev

This commit is contained in:
Gowtham M 2025-10-11 16:10:08 +05:30
commit a828337c9a
7 changed files with 302 additions and 76 deletions

View File

@ -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');
});
});

View File

@ -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 = [
@ -897,7 +907,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 branch 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');
@ -905,6 +937,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
@ -945,7 +987,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;
@ -1004,7 +1050,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 branch 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) {
@ -5229,6 +5312,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;
}

View File

@ -761,16 +761,25 @@ class EmployeeController extends AdminController
}
public function empby_client_clientbranch($client_id, $branch_id)
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')
$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();
@ -779,14 +788,14 @@ class EmployeeController extends AdminController
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'];
@ -802,11 +811,11 @@ class EmployeeController extends AdminController
'emp_status' => $employeeEmpStatus,
'user_type' => $employeeUserType
];
}
$employeeId = $row['employee_id'];
}
// print_r($groupedData); die;
return json_encode($groupedData);
}

View File

@ -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;
}
}

View File

@ -91,10 +91,14 @@
<input type="hidden" class="form-control" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<!-- pre_client_id as client_id -->
<input type="hidden" name="client_id" id="client_id_branch"
value="<?= isset($client['id']) ? $client['id'] : '' ?>" />
<!-- post_branch_id -->
<input type="hidden" name="post_branch_id" id="post_branch_id"
value="<?= isset($post_branch_id) ? $post_branch_id : '' ?>" />
<!-- pre_branch_id as branch_id_primarykey -->
<input type="hidden" name="branch_id_primarykey" id="branch_id_primarykey" />
@ -203,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."
@ -308,7 +312,9 @@ $('#btnBranchAdd').click(function() {
$('#district').val('');
$('#branch_city').val('');
$('#branch_form')[0].reset();
$('#branch_form').parsley().reset();
$('.ac').css('display', 'block');
$('#post_branch_id').val('');
contactCount = 1
var addButton = document.getElementById('add');
@ -379,7 +385,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');
@ -398,6 +404,7 @@ $("#branch_form").submit(function(event) {
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);
@ -488,6 +495,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);
}
});
@ -640,11 +651,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" onchange="validateInput(this, 'level_contacts', 'email', '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;">
@ -934,6 +945,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: '<?= 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(`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 = [];

View File

@ -126,7 +126,7 @@ body {
<div class="col-md-6">
<div class="form-group col-md-12">
<label for="auto_fetch_client">Client List<span class="text-danger">*</span></label>
<select class="form-control" id="auto_fetch_client" name="auto_fetch_client" required>
<select class="form-control select2" id="auto_fetch_client" name="auto_fetch_client" required>
<option value="">Select Client</option>
<?php if (!empty($auto_fetch_client_list)): ?>
<?php foreach ($auto_fetch_client_list as $client_list): ?>
@ -142,7 +142,7 @@ body {
<div class="col-md-6">
<div class="form-group col-md-12">
<label for="auto_fetch_branch">Branch List<span class="text-danger">*</span></label>
<select class="form-control" id="auto_fetch_branch" name="auto_fetch_branch" required>
<select class="form-control select2" id="auto_fetch_branch" name="auto_fetch_branch" required>
<option value="">Select Branch</option>
</select>
@ -313,10 +313,19 @@ body {
</script>
<script>
$(document).ready(function() {
$('#auto_fetch_client').select2();
$('#auto_fetch_branch').select2();
$('#auto_fetch_client').change(function() {
$('#auto_fetch_branch').html(`<option value="">Select Branch</option>`);
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
url: "<?php echo base_url('client/branch/auto_fetch_branch'); ?>",
type: "POST",
@ -341,10 +350,18 @@ body {
console.error("Error occurred:", status, error);
},
complete: function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log("auto_fetch_client call is completed..!!");
}
});
});
});
</script>
<script>

View File

@ -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: '<?php echo base_url(); ?>' + '/employee/empby_client_clientbranch/' + client_id + '/' + branch_id,
url: '<?php echo base_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{
@ -370,7 +371,12 @@
var loggedIn = 'Yes';
loggedIn_count++;
}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');
@ -819,4 +826,5 @@
});
}
</script>