$value) { // Kint::dump($value['client_name'], $client_name); if(trim($value['client_name']) === trim($client_name)){ return array('status' => true, 'client_id' => $value['id'], 'error' => ''); } } } return array('status' => false, 'error' => 'This Client Name does not exist in the system'); } } if (!function_exists('check_insurer')) { function check_insurer($params) { $insurer_data = $params['insurer_data'] ?? []; $insurer_name = $params['insurer_name'] ?? ""; if (!empty($insurer_data)) { foreach ($insurer_data as $key => $value) { if(trim($value['short_name']) === trim($insurer_name)){ return array('status' => true, 'insuer_id' => $value['id'], 'error' => ''); } } } return array('status' => false, 'error' => 'This Insurer does not exist in the system'); } } if (!function_exists('check_tpa')) { function check_tpa($params) { $tpa_data = $params['tpa_data'] ?? []; $tpa_name = $params['tpa_name'] ?? ""; if (!empty($tpa_data)) { foreach ($tpa_data as $key => $value) { if(trim($value['short_name']) === trim($tpa_name)){ return array('status' => true, 'tpa_id' => $value['id'], 'error' => ''); } } } return array('status' => false, 'error' => 'This TPA does not exist in the system'); } } if (!function_exists('check_status')) { function check_status($params) { $data = $params['data'] ?? []; $check_value = $params['value'] ?? ""; if (!empty($data)) { foreach ($data as $key => $value) { // Kint::dump(strtolower(trim($value['claim_status'])), strtolower(trim($check_value))); if(strtolower(trim($value['claim_status'])) === strtolower(trim($check_value))){ return array('status' => true, 'status_id' => $value['id'], 'error' => ''); } } } return array('status' => false, 'error' => "This Status ('{$check_value}') does not exist in the system"); } } if (!function_exists('check_policy')) { function check_policy($params) { $data = $params['data'] ?? []; $client_id = $params['client_id'] ?? ""; $check_value = $params['value'] ?? ""; if (!empty($data)) { foreach ($data as $key => $value) { if($value['client_id'] === $client_id && trim($value['policy_no']) === trim($check_value)){ return array('status' => true, 'status_id' => $value['id'], 'error' => ''); } } } return array('status' => false, 'error' => "This Policy Number does not exist in the Client"); } } if (!function_exists('check_emp_and_insured')) { function check_emp_and_insured($params) { $employee_modal = new EmployeeModel(); $tpa_data = $employee_modal ->join('employee_polices', 'employees.id = employee_polices.employee_id') ->where('employees.client', $params['client_id']) ->where('employees.name', $params['emp_name']) ->where('employees.emp_code', $params['emp_code']) ->where('employees.is_active', 1) ->where('employees.emp_status !=', "truncated") ->where('employee_polices.is_active', 1) ->where('employees.status !=', "truncated") ->first(); if (empty($tpa_data)) { return false; } return $tpa_data['id']; } } if (!function_exists('dynamic_check_excel_date_format')) { function dynamic_check_excel_date_format($dateString, $format = 'd/m/Y') { if ($dateString == "") { return array('status' => true); } $date = DateTime::createFromFormat($format, $dateString); if ($date && $date->format($format) == $dateString) { return array('status' => true); } else { $res = validate_date_flexible($dateString, $format); if (!$res) { return array('status' => false, 'error' => "wrong date format: Expected {$format}({$res}) and received $dateString"); } else { return array('status' => true); } } } } if (!function_exists('validate_date_flexible')) { function validate_date_flexible($date, $format = 'm/d/Y') { // Create a DateTime from the given format $d = DateTime::createFromFormat($format, $date); if (!$d) return false; // Compare normalized values (remove leading zeros) $original = preg_replace('/\b0+/', '', $date); $normalized = preg_replace('/\b0+/', '', $d->format($format)); return $original === $normalized; } } if (!function_exists('normalizeDate')) { function normalizeDate($dateString, $formats = ['d-m-Y', 'd/m/Y', 'm-d-Y', 'm/d/Y', 'Y-m-d']) { if (empty($dateString)) { return null; // keep null if no value } foreach ($formats as $format) { $dt = DateTime::createFromFormat($format, trim($dateString)); if ($dt && $dt->format($format) === trim($dateString)) { return $dt->format('Y-m-d'); // ✅ return in DB format } } return null; // if no valid format found } } ?>