From 76a41264e8590b89c2745b9a85b5e9dc509d78f2 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Fri, 27 Mar 2026 17:40:43 +0530 Subject: [PATCH] FIX_DUPLICATE_EMP_CODE_CHECK --- app/Controllers/EmployeeServiceController.php | 17 ++- app/Helpers/excel_util_helper.php | 12 ++ app/Views/file_list.php | 104 +++++++++--------- 3 files changed, 78 insertions(+), 55 deletions(-) diff --git a/app/Controllers/EmployeeServiceController.php b/app/Controllers/EmployeeServiceController.php index 69c1d0f..3dbf417 100755 --- a/app/Controllers/EmployeeServiceController.php +++ b/app/Controllers/EmployeeServiceController.php @@ -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) { diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index a6b6222..c1f6159 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -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' => ""); + } +} diff --git a/app/Views/file_list.php b/app/Views/file_list.php index dbbef80..1e765aa 100755 --- a/app/Views/file_list.php +++ b/app/Views/file_list.php @@ -166,31 +166,37 @@ - + + +