FIX_DUPLICATE_EMP_CODE_CHECK

This commit is contained in:
VENKATESHWARAN 2026-03-27 17:40:43 +05:30
parent fbbe6f791e
commit 76a41264e8
3 changed files with 78 additions and 55 deletions

View File

@ -116,7 +116,9 @@ class EmployeeServiceController extends AdminController
'is_mandatory' => true,
'data_type' => 'str',
'format' => null,
'allowed_values' => null
'allowed_values' => null,
'custom' => 'check_emp_code_duplicate',
'params' => ['self_data', 'row']
],
'name_of_emp_dep' => [
'col_idx' => 2,
@ -797,6 +799,19 @@ class EmployeeServiceController extends AdminController
$existing_mobilenos = $this->employeePolicyModel->getExisitingMobileNos(client_policy_id: $file['policy_id']);
//get existing units in the current branch
$existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']);
$self_data = $this->employeeModel
->select('employees.id, employees.name, employees.emp_code')
->join('employee_polices ep', 'employees.id = ep.employee_id')
->where('employees.is_active', 1)
->where('ep.is_active', 1)
->whereIn('emp_status', ['draft', 'enrolled'])
->whereIn('status', ['draft', 'enrolled'])
->where('LOWER(relationship)', 'self')
->where('client_id', $file['client_id'])
->findAll();
// dd($excel_data);
foreach ($excel_data as $row_key => $row)
{

View File

@ -2369,5 +2369,17 @@ if(!function_exists('modify_si_for_the_family'))
// --------AUTO SI Functions End---------------------------------------------------------------------------------------
if(!function_exists('check_emp_code_duplicate'))
{
function check_emp_code_duplicate($data, $row)
{
foreach ($data as $member) {
if(strtolower($row[5]) == 'self' && $member['emp_code'] == trim($row[1])) {
return array('status' => false,'error' => "This employee code already exist for this client");
}
}
return array('status' => true,'error' => "");
}
}

View File

@ -166,31 +166,37 @@
</div><!-- /.modal -->
<!-- Center modal content for reupload file-->
<div class="modal fade" id="file-upload-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myCenterModalLabel">ReUpload the file</h4>
<h4 class="modal-title">ReUpload the file</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<form class="parsley-examples" id="uploadForm" action="<?php echo base_url() . 'employee/upload' ?>"
enctype="multipart/form-data">
<!-- Added data-parsley-validate for auto initialization -->
<form class="parsley-examples" id="uploadForm" enctype="multipart/form-data" data-parsley-validate>
<input type="hidden" id="file_client_id" name="client_id">
<input type="hidden" id="file_policy_id" name="policy_id">
<input type="hidden" id="file_branch_id" name="client_branch_id">
<input type="hidden" id="file_enrollment_open_date" name="enrollment_open_date">
<input type="hidden" id="file_enrollment_close_date" name="enrollment_close_date">
<input type="hidden" id="file_upload_actions" name="upload-action-type">
<input type="file" id="fileInput" name="emplist" required
accept=" application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet">
<button type="submit" class="btn btn-primary">Upload</button>
<div class="form-group mb-3">
<label for="fileInput">Choose Excel File</label>
<input type="file" id="fileInput" name="emplist" class="form-control-file" required
accept=".xlsx, .xls, .ods">
</div>
<div class="text-right">
<button type="submit" id="uploadBtn" class="btn btn-primary">Upload Now</button>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
</div>
</div>
<script>
@ -421,72 +427,62 @@ function handleNoDataFound(response, fileId) {
}
}
$('#uploadForm').submit(function() {
$('#uploadForm').on('submit', function(e) {
// 1. STOP the default page reload
e.preventDefault();
var isValid = $('#uploadForm').parsley().validate();
// 2. Validate using Parsley
var form = $(this);
var isValid = form.parsley().validate();
if (!isValid) {
console.log('Form is Empty', 'Warning');
return;
console.warn('Form validation failed');
return false;
}
// Create FormData object
var formData = new FormData($(this)[0]);
for (var pair of formData.entries()) {
console.log(pair[0] + ', ' + pair[1]);
}
// 3. UI Feedback (Disable button to prevent multiple clicks)
var $btn = $('#uploadBtn');
$btn.prop('disabled', true).text('Uploading...');
// return false;
// 4. Prepare Data
var formData = new FormData(this);
// 5. API Call
$.ajax({
url: $(this).attr("action"),
url: '<?= base_url("employee/upload") ?>',
type: "POST",
data: formData,
processData: false, // Prevent jQuery from automatically processing the data
contentType: false, // Let jQuery handle the content type
processData: false,
contentType: false,
headers: {
// "Content-Type":"multipart/form-data",
"X-Requested-With": "XMLHttpRequest"
},
success: function(response) {
console.log('API Response:', response);
console.log(response);
$('#uploadForm')[0].reset();
if (response.code === 200 && response.dataStatus === true && response
.data !== "") {
toastr.success(
'File upload successs, Data validation is in-progress',
'Success');
$('.close').click()
window.location.reload(true);
} else if (response.code === 404 && response.dataStatus === false) {
console.error('no data found', response);
// alert(response.message);
toastr.error(response.message, 'Failed');
window.location.reload(true);
if (response.code == 200 && response.dataStatus == true) {
toastr.success('File upload success, Data validation is in-progress', 'Success');
$('.close').click(); // Close Modal
form[0].reset(); // Clear Form
} else {
console.error('Something went wrong!');
// alert('Something went wrong! Try later');
toastr.error('Something went wrong! Try later', 'Error');
window.location.reload(true);
toastr.error(response.message || 'Upload failed', 'Error');
$btn.prop('disabled', false).text('Upload'); // Re-enable if failed
}
},
error: function(xhr, status, error) {
// Request failed, handle error
console.error("Request failed:", status, error);
toastr.error('Something went wrong! Try later', 'Error');
$('#uploadForm')[0].reset();
error: function(xhr) {
console.error("Critical Error:", xhr.responseText);
toastr.error('Something went wrong on the server', 'Error');
$btn.prop('disabled', false).text('Upload');
},
complete: function() {
console.log("Request finished. Reloading in 2 seconds...");
// This ensures the reload only happens AFTER the API process is totally done
console.log("Process complete. Reloading...");
setTimeout(function() {
window.location.reload();
}, 2000);
}, 500);
}
});
})
});
$('body').on('click', '.reload', function() {