FIX_FAMILY_FLOATER
This commit is contained in:
parent
4d9776ec3c
commit
79c22a7b42
@ -1385,8 +1385,8 @@ class EmployeeServiceController extends AdminController
|
||||
$existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file);
|
||||
// Kint::dump($existing_famility_details);
|
||||
$family = array_merge($family,$existing_famility_details);
|
||||
$family = data_group_by_family($family)[ $emp_id ];// reason to call this again is bring self to first index of the array
|
||||
// dd($family);
|
||||
$family = data_group_by_family($family, 'excel', 1)[ $emp_id ];// reason to call this again is bring self to first index of the array
|
||||
// dd($family);
|
||||
$self = current(array_filter($family, fn($r) => strtolower($r[5] ?? '') === 'self'));
|
||||
$premium = (int)($self['temp']['rata_premimum'] ?? 0);
|
||||
foreach ($family as &$r) if (strtolower($r[5] ?? '') !== 'self') $r['self_rata_premium'] = $premium;
|
||||
@ -1394,9 +1394,9 @@ class EmployeeServiceController extends AdminController
|
||||
|
||||
// Kint::dump($family);
|
||||
$data = calculate_premium_new(family_data:$family,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units);
|
||||
// if($file['action'] == 'dependent_addition') {
|
||||
// $data = validatet_family_floter_rata_premium($data);
|
||||
// }
|
||||
if($file['action'] == 'dependent_addition') {
|
||||
$data = validatet_family_floter_rata_premium($data);
|
||||
}
|
||||
// dd($data);
|
||||
$employee_data_group_by_family[$emp_id] = $data;
|
||||
$this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]);
|
||||
|
||||
@ -375,6 +375,10 @@ if (!function_exists('data_group_by_family')) {
|
||||
if ($data_source == 'excel') {
|
||||
if (!check_row_is_empty_or_null($row)) {
|
||||
|
||||
if(empty($action)){
|
||||
$row['data_from'] = "excel";
|
||||
}
|
||||
|
||||
// for this condition to avoid 5,00,000 to 500000
|
||||
if($current_column_action == 'SI'){
|
||||
$row[3] = removeNumberFormatting($row[3]);
|
||||
@ -392,6 +396,8 @@ if (!function_exists('data_group_by_family')) {
|
||||
} else {
|
||||
$result[$row[1]][] = $row;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} else if ($data_source = 'db') {
|
||||
if (strtolower($row['relationship']) == 'self' && isset($result[$row['emp_code']])) {
|
||||
@ -1017,13 +1023,17 @@ if (!function_exists('transform_excel_data_to_db')) {
|
||||
$result['self_rata_premium'] = $memArr['self_rata_premium'] ?? 0;
|
||||
}
|
||||
|
||||
if(isset($memArr['data_from'])){
|
||||
$result['data_from'] = $memArr['data_from'] ?? 'excel';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('premium_calculation_manager')) {
|
||||
function premium_calculation_manager($emp_data, $policy_terms, $slab_details, $default_si = null)
|
||||
if (!function_exists('premium_calculation_manager_old')) {
|
||||
function premium_calculation_manager_old($emp_data, $policy_terms, $slab_details, $default_si = null)
|
||||
{
|
||||
// dd($emp_data,$policy_terms,$slab_details,$default_si);
|
||||
|
||||
@ -1429,8 +1439,8 @@ if (!function_exists('premium_calculation_manager')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('premium_calculation_manager_new')) {
|
||||
function premium_calculation_manager_new($emp_data, $policy_terms, $slab_details, $default_si = null)
|
||||
if (!function_exists('premium_calculation_manager')) {
|
||||
function premium_calculation_manager($emp_data, $policy_terms, $slab_details, $default_si = null)
|
||||
{
|
||||
// dd($emp_data,$policy_terms,$slab_details,$default_si);
|
||||
|
||||
@ -2875,31 +2885,64 @@ if (!function_exists('is_valid_or_empty_email')) {
|
||||
if (!function_exists('validatet_family_floter_rata_premium')) {
|
||||
function validatet_family_floter_rata_premium($family){
|
||||
|
||||
// print_rr($family); die;
|
||||
if (count($family) === 2) {
|
||||
return $family; // skip if only two members
|
||||
}
|
||||
|
||||
$excelCount = count(array_filter($family, fn($r) => ($r['data_from'] ?? '') === 'excel') ?? []);
|
||||
$reset_family_premium = false;
|
||||
$dependentRataGiven = false;
|
||||
|
||||
if($excelCount == 1){
|
||||
|
||||
$selfPremium = 0;
|
||||
$familyPremium = 0;
|
||||
|
||||
foreach ($family as $row) {
|
||||
|
||||
// Get self premium
|
||||
if (isset($row['relationship']) && strtolower($row['relationship']) == 'self') {
|
||||
$selfPremium = (float) ($row['policy_details']['rata_premimum'] ?? 0);
|
||||
}
|
||||
|
||||
// Sum the dependents premium
|
||||
if (isset($row['relationship']) && strtolower($row['relationship']) !== 'self')
|
||||
{
|
||||
$familyPremium += (float) ($row['policy_details']['rata_premimum'] ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
if($selfPremium > $familyPremium || $selfPremium == $familyPremium){
|
||||
$reset_family_premium = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($family as &$row) {
|
||||
|
||||
// Skip if the member is self
|
||||
if (strtolower($row['relationship']) == 'self') {
|
||||
if (isset($row['relationship']) && strtolower($row['relationship']) == 'self') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// For dependents
|
||||
if (isset($row['temp']['premium_type']) && $row['temp']['premium_type'] == 1) {
|
||||
|
||||
if (!$dependentRataGiven) {
|
||||
if (!$dependentRataGiven && isset($row['data_from']) && $row['data_from'] === 'excel') {
|
||||
// First eligible dependent keeps premium
|
||||
$dependentRataGiven = true;
|
||||
} else {
|
||||
} else if(isset($row['data_from']) && $row['data_from'] === 'excel'){
|
||||
$row['policy_details']['rata_premimum'] = 0;
|
||||
$row['policy_details']['gst'] = 0;
|
||||
}
|
||||
|
||||
if($reset_family_premium == true && isset($row['data_from']) && $row['data_from'] === 'excel'){
|
||||
$row['policy_details']['rata_premimum'] = 0;
|
||||
$row['policy_details']['gst'] = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $family;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user