FIX_EMAIL_VALID_IN_THE_EXCEL
This commit is contained in:
parent
cb0cc20448
commit
eb4e2752fa
@ -238,7 +238,7 @@ class EmployeeMultiEventServiceController extends BaseController
|
||||
'format' => null,
|
||||
'allowed_values' => null,
|
||||
'custom' => 'check_dup_email',
|
||||
'params' => ['row', 'existing_mobilenos']
|
||||
'params' => ['row', 'existing_mobilenos', 'excel_data', 'row_key']
|
||||
],
|
||||
'pre_existing_ailments' => [
|
||||
'col_idx' => 14,
|
||||
|
||||
@ -241,7 +241,7 @@ class EmployeeServiceController extends AdminController
|
||||
'format' => null,
|
||||
'allowed_values' => null,
|
||||
'custom' => 'check_dup_email',
|
||||
'params' => ['row', 'existing_mobilenos']
|
||||
'params' => ['row', 'existing_mobilenos', 'excel_data', 'row_key']
|
||||
],
|
||||
'pre_existing_ailments' => [
|
||||
'col_idx' => 14,
|
||||
|
||||
@ -2173,8 +2173,8 @@ if (!function_exists('check_dup_mobileno')) {
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!function_exists('check_dup_email')) {
|
||||
function check_dup_email(array $row, array $existing_mobilenos)
|
||||
if (!function_exists('check_dup_email_old')) {
|
||||
function check_dup_email_old(array $row, array $existing_mobilenos)
|
||||
{
|
||||
$errorMessages = [];
|
||||
|
||||
@ -2203,6 +2203,54 @@ if (!function_exists('check_dup_email')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('check_dup_email')) {
|
||||
function check_dup_email(array $row, array $existing_mobilenos, $excel_data = [], $row_key = null)
|
||||
{
|
||||
$errorMessages = [];
|
||||
$current_relation = strtolower(trim($row['5'] ?? ''));
|
||||
$current_email = trim((string) ($row['13'] ?? ''));
|
||||
|
||||
// Validate email
|
||||
$emailCheck = is_valid_or_empty_email($current_email);
|
||||
if (!$emailCheck) {
|
||||
$errorMessages[] = 'Invalid email format';
|
||||
}
|
||||
|
||||
// Check duplicate only if email is not empty
|
||||
if (!empty($current_email)) {
|
||||
foreach ($existing_mobilenos as $value) {
|
||||
if ($current_relation === 'self' && strcasecmp($current_email, trim((string) ($value['email_corporate'] ?? ''))) === 0) {
|
||||
$errorMessages[] = 'Duplicate Email';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($excel_data as $ed_row => $value) {
|
||||
if ($row_key !== null && (string) $ed_row === (string) $row_key) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$excel_relation = strtolower(trim($value['5'] ?? ''));
|
||||
$excel_email = trim((string) ($value['13'] ?? ''));
|
||||
|
||||
if ($current_relation === 'self' && $excel_relation === 'self' && $excel_email !== '' && strcasecmp($current_email, $excel_email) === 0) {
|
||||
$duplicate_row_no = is_numeric($ed_row) ? $ed_row + 1 : $ed_row;
|
||||
$current_row_no = is_numeric($row_key) ? $row_key + 1 : $row_key;
|
||||
$errorMessages[] = "This email has already been used for another self in Excel at row no. " . ($duplicate_row_no) . " and " . ($current_row_no);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare final return
|
||||
if (!empty($errorMessages)) {
|
||||
return ['status' => false, 'error' => implode(' & ', $errorMessages)];
|
||||
}
|
||||
|
||||
return ['status' => true, 'error' => ''];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('generate_family_relationship_array')) {
|
||||
function generate_family_relationship_array($family_structure_from_policy_terms)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user