FIX_DATE_FORMAT_NEW_FUNC
This commit is contained in:
parent
92960b2f37
commit
8a319604f7
@ -1980,7 +1980,9 @@ public function getFileMetaDataByFileId($file_id, $status = 'success'){
|
||||
$policy_details = $this->clientPolicyModel->where('id', $file['policy_id'])->first();
|
||||
|
||||
// dd($policy_details);
|
||||
|
||||
|
||||
//get policy slab rates
|
||||
$slab_details = $this->policiesModel->getPolicySlabRatesForEmpOnboard($file['policy_id'],$file['client_id']);
|
||||
foreach ($excel_data as $key => $row)
|
||||
{
|
||||
$is_row_empty = check_row_is_empty_or_null($row);
|
||||
|
||||
@ -1209,7 +1209,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
$employee_received_si = $default_si == null ? $emp_data['policy_details']['basic_cover_si'] : $default_si;
|
||||
foreach ($temp_slab_rates as $skey => $slab_value)
|
||||
{
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3 ) ))
|
||||
{
|
||||
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
|
||||
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
|
||||
@ -1232,7 +1232,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
foreach ($temp_slab_rates as $skey => $slab_value)
|
||||
{
|
||||
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ))
|
||||
{
|
||||
// dd($slab_value);
|
||||
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
|
||||
@ -1253,7 +1253,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
foreach ($temp_slab_rates as $skey => $slab_value)
|
||||
{
|
||||
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3 ) ))
|
||||
{
|
||||
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
|
||||
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
|
||||
@ -1273,7 +1273,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
foreach ($temp_slab_rates as $skey => $slab_value)
|
||||
{
|
||||
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ))
|
||||
{
|
||||
// echo $emp_data['name'];
|
||||
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
|
||||
@ -1295,7 +1295,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
foreach ($temp_slab_rates as $skey => $slab_value)
|
||||
{
|
||||
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ))
|
||||
{
|
||||
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
|
||||
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
|
||||
@ -1317,7 +1317,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
foreach ($temp_slab_rates as $skey => $slab_value)
|
||||
{
|
||||
|
||||
if($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
|
||||
if($slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && $slab_value['si'] == $employee_received_si && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) ) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ))
|
||||
{
|
||||
// $emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
|
||||
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
|
||||
@ -1339,7 +1339,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
foreach ($temp_slab_rates as $skey => $slab_value)
|
||||
{
|
||||
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ))
|
||||
{
|
||||
$emp_data['policy_details']['basic_cover_si'] = $slab_value['si'];
|
||||
$emp_data['policy_details']['date_coverage'] = (isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date']);
|
||||
@ -1366,7 +1366,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] &&
|
||||
($slab_value['age_from'] <= $max_age && $slab_value['age_to'] >= $max_age) &&
|
||||
(($slab_value['premium_type'] == 1 &&
|
||||
( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ) )
|
||||
( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ) )
|
||||
{
|
||||
$emp_data['policy_details']['basic_cover_si'] = $employee_received_si;
|
||||
$emp_data['policy_details']['date_coverage'] = isset($emp_data['policy_details']['date_coverage']) ? $emp_data['policy_details']['date_coverage'] : $policy_terms['policy_start_date'];
|
||||
@ -1391,7 +1391,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
{
|
||||
|
||||
if($slab_value['si'] == $employee_received_si && $slab_value['grade'] == $employee_received_band && $slab_value['unit'] == $emp_data['unit'] && (($slab_value['premium_type'] == 1 &&
|
||||
( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) ))
|
||||
( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] )) || ($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) ))
|
||||
{
|
||||
//calculate premium based on count
|
||||
// echo $emp_data['name'];
|
||||
@ -1420,7 +1420,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
$emp_data['policy_details']['basic_cover_si'] = null;
|
||||
foreach ($temp_slab_rates as $skey => $slab_value)
|
||||
{
|
||||
if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) )
|
||||
if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) )
|
||||
{
|
||||
|
||||
$emp_data['policy_details']['basic_cover_si'] = $employee_received_si;
|
||||
@ -1445,7 +1445,7 @@ if (!function_exists('premium_calculation_manager'))
|
||||
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
|
||||
foreach ($temp_slab_rates as $skey => $slab_value)
|
||||
{
|
||||
if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) )
|
||||
if( $slab_value['si'] == $employee_received_si && $slab_value['unit'] == $emp_data['unit'] && ($slab_value['age_from'] <= $age && $slab_value['age_to'] >= $age) && ((($slab_value['premium_type'] == 2 || $slab_value['premium_type'] == null || $slab_value['premium_type'] == 3) && $slab_value['relationship'] == $employee_relationship) || ($slab_value['premium_type'] == 1 && ( strtolower($emp_data['relationship']) == 'self' || $emp_data['temp']['acting_self'] ) )) )
|
||||
{
|
||||
|
||||
$emp_data['policy_details']['basic_cover_si'] = $employee_received_si;
|
||||
@ -1466,6 +1466,13 @@ if (!function_exists('premium_calculation_manager'))
|
||||
default:
|
||||
$myLogger->logme('error',($emp_data['emp_code'].'-'.$emp_data['name'].' - grid type not found'));
|
||||
}
|
||||
|
||||
//this if condition for premium calculated & premium type 3 (familiy floater but premium calculated every individual implemented later) then remove si amount only for dependents (not self)
|
||||
if($is_match_found && strtolower($emp_data['relationship']) != 'self' && $temp_slab_rates[0]['premium_type'] == 3)
|
||||
{
|
||||
//set dependent si to 0
|
||||
$emp_data['policy_details']['basic_cover_si'] = 0;
|
||||
}
|
||||
if(!$is_match_found)
|
||||
{
|
||||
$age = calculate_days_bw_dates(from_date: $emp_data['dob'])->y;
|
||||
|
||||
@ -24,9 +24,9 @@ if (!function_exists('generate_uuid')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('change_date_format')) {
|
||||
if (!function_exists('change_date_format2')) {
|
||||
|
||||
function change_date_format($data, $source_format, $output_format)
|
||||
function change_date_format2($data, $source_format, $output_format)
|
||||
{
|
||||
$data = trim($data);
|
||||
// echo $data, $source_format, $output_format;return true;
|
||||
@ -501,3 +501,86 @@ if (!function_exists('isJsonString')) {
|
||||
return (json_last_error() === JSON_ERROR_NONE); // Check if the last JSON error is "no error"
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('isValidDate')) {
|
||||
function isValidDate($date, $format) {
|
||||
$parsed_date = DateTime::createFromFormat($format, $date);
|
||||
return $parsed_date && $parsed_date->format($format) === $date;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!function_exists('change_date_format'))
|
||||
{
|
||||
|
||||
function change_date_format($date_str, $source_format = null, $output_format = 'Y-m-d') {
|
||||
|
||||
$date_str = trim($date_str);
|
||||
// Allowed date formats
|
||||
$allowed_formats = [
|
||||
// Day Month Year (clear unambiguous formats)
|
||||
'd M Y', // 01 Dec 2024
|
||||
'd-M-Y', // 01-Dec-2024
|
||||
'd/M/Y', // 01/Dec/2024
|
||||
'd.M.Y', // 01.Dec.2024
|
||||
'd,M,Y', // 01,Dec,2024
|
||||
|
||||
// Month Day Year (clear unambiguous formats)
|
||||
'M d Y', // Dec 01 2024
|
||||
'M-d-Y', // Dec-01-2024
|
||||
'M/d/Y', // Dec/01/2024
|
||||
'M.d.Y', // Dec.01.2024
|
||||
'M,d,Y', // Dec,01,2024
|
||||
|
||||
// Year Month Day (clear unambiguous formats)
|
||||
'Y M d', // 2024 Dec 01
|
||||
'Y-M-d', // 2024-Dec-01
|
||||
'Y/M/d', // 2024/Dec/01
|
||||
'Y.M.d', // 2024.Dec.01
|
||||
'Y,M,d', // 2024,Dec,01
|
||||
|
||||
// Year Numeric Month Numeric Day
|
||||
'Y-m-d', // 2024-12-01
|
||||
'Y/m/d', // 2024/12/01
|
||||
'Y.m.d', // 2024.12.01
|
||||
'Y,m,d', // 2024,12,01
|
||||
];
|
||||
|
||||
try {
|
||||
// Case 1: Source and Output formats are provided
|
||||
if ($source_format !== null && $output_format !== null) {
|
||||
$date = DateTime::createFromFormat($source_format, $date_str);
|
||||
if (!$date) {
|
||||
throw new Exception("Invalid date string for source format: $source_format");
|
||||
}
|
||||
return $date->format($output_format);
|
||||
}
|
||||
|
||||
// Case 2: Source format is provided, Output format is null
|
||||
if ($source_format !== null && $output_format === null) {
|
||||
$date = DateTime::createFromFormat($source_format, $date_str);
|
||||
if (!$date) {
|
||||
throw new Exception("Invalid date string for source format: $source_format");
|
||||
}
|
||||
return $date->format('Y-m-d'); // MySQL default format
|
||||
}
|
||||
|
||||
// Case 3: Source format is null, auto-detect format
|
||||
if ($source_format === null) {
|
||||
foreach ($allowed_formats as $format) {
|
||||
if (isValidDate($date_str, $format)) {
|
||||
$date = DateTime::createFromFormat($format, $date_str);
|
||||
return $date->format($output_format); // Default is MySQL format
|
||||
}
|
||||
}
|
||||
// If no format matches, throw an exception
|
||||
$allowed_placeholders = implode(', ', $allowed_formats);
|
||||
throw new Exception("Invalid date string format. Allowed formats: $allowed_placeholders");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
return "Error: " . $e->getMessage();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user