FIX_RATA_PREMIUM

This commit is contained in:
VENKATESHWARAN 2025-12-03 17:25:40 +05:30
parent 72954ffe58
commit 5a1570cade
2 changed files with 53 additions and 43 deletions

View File

@ -1394,9 +1394,6 @@ class EmployeeServiceController extends AdminController
// Kint::dump($family); // Kint::dump($family);
$data = calculate_premium_new(family_data:$family,policy_terms: $policy_terms,slab_details : $slab_details,fileArr: $file, existing_units:$existing_units); $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);
}
// dd($data); // dd($data);
$employee_data_group_by_family[$emp_id] = $data; $employee_data_group_by_family[$emp_id] = $data;
$this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]); $this->employeesOnboardProcess(['familiy_data' => $data,'file' => $file]);

View File

@ -945,6 +945,10 @@ if (!function_exists('calculate_premium_new')) {
// $result[] = $transformed_familiy_member_data; // $result[] = $transformed_familiy_member_data;
} }
if($fileArr['action'] == 'dependent_addition') {
$result = validatet_family_floter_rata_premium($result);
}
// dd($result); // dd($result);
return ($result); return ($result);
// //
@ -1923,6 +1927,7 @@ if (!function_exists('transform_db_data_to_excel')) {
$row['temp']['emp_status'] = $value['emp_status']; $row['temp']['emp_status'] = $value['emp_status'];
$row['temp']['policy_status'] = $value['status']; $row['temp']['policy_status'] = $value['status'];
$row['temp']['rata_premimum'] = $value['rata_premimum']; $row['temp']['rata_premimum'] = $value['rata_premimum'];
$row['temp']['premium'] = $value['premium'];
$row['temp']['file_id'] = $value['file_id']; $row['temp']['file_id'] = $value['file_id'];
array_push($return_data, ($row)); array_push($return_data, ($row));
@ -2883,66 +2888,73 @@ if (!function_exists('is_valid_or_empty_email')) {
} }
if (!function_exists('validatet_family_floter_rata_premium')) { if (!function_exists('validatet_family_floter_rata_premium')) {
function validatet_family_floter_rata_premium($family){ function validatet_family_floter_rata_premium($family)
{
// print_rr($family); die; // If only two members, skip
if (count($family) === 2) { if (count($family) === 2) {
return $family; // skip if only two members return $family;
} }
$excelCount = count(array_filter($family, fn($r) => ($r['data_from'] ?? '') === 'excel') ?? []); // Count excel rows
$reset_family_premium = false; $excelCount = count(array_filter($family, fn($r) =>
($r['data_from'] ?? '') === 'excel'
));
// Extract self row
$selfDataArr = array_filter($family, fn($r) =>
strtolower($r['relationship'] ?? '') === 'self'
);
$selfData = reset($selfDataArr);
$dependentRataGiven = false; $dependentRataGiven = false;
if($excelCount == 1){ /**
* ---------------------------------------------------
$selfPremium = 0; * 1. RESET DEPENDENT PREMIUM IF SELF HAS SAME RATA
$familyPremium = 0; * ---------------------------------------------------
*/
foreach ($family as $row) { if (
!empty($selfData['temp']) &&
// Get self premium !empty($selfData['policy_details']) &&
if (isset($row['relationship']) && strtolower($row['relationship']) == 'self') { ($selfData['temp']['premium'] ?? 0) == ($selfData['policy_details']['premium'] ?? 0)
$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) { foreach ($family as &$row) {
// Skip if the member is self if (strtolower($row['relationship'] ?? '') === 'self') {
if (isset($row['relationship']) && strtolower($row['relationship']) == 'self') {
continue; continue;
} }
// For dependents if (
if (isset($row['temp']['premium_type']) && $row['temp']['premium_type'] == 1) { ($row['temp']['premium_type'] ?? null) == 1 &&
($row['data_from'] ?? '') === 'excel'
) {
$row['policy_details']['rata_premimum'] = 0;
$row['policy_details']['gst'] = 0;
}
}
}
if (!$dependentRataGiven && isset($row['data_from']) && $row['data_from'] === 'excel') { /**
// First eligible dependent keeps premium * ---------------------------------------------------
* 2. APPLY FINAL PREMIUM ADJUSTMENT TO DEPENDENTS
* ---------------------------------------------------
*/
foreach ($family as &$row) {
if (strtolower($row['relationship'] ?? '') === 'self') {
continue;
}
if (($row['temp']['premium_type'] ?? null) == 1) {
// FIRST excel dependent keeps premium
if (!$dependentRataGiven && ($row['data_from'] ?? '') === 'excel') {
$dependentRataGiven = true; $dependentRataGiven = true;
} else if(isset($row['data_from']) && $row['data_from'] === 'excel'){ } else if (($row['data_from'] ?? '') === 'excel') {
$row['policy_details']['rata_premimum'] = 0; $row['policy_details']['rata_premimum'] = 0;
$row['policy_details']['gst'] = 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; return $family;
@ -2950,6 +2962,7 @@ if (!function_exists('validatet_family_floter_rata_premium')) {
} }
if (!function_exists('validate_excel_value')) { if (!function_exists('validate_excel_value')) {
function validate_excel_value($value, $data_type, $format = null, $allowed_values = null) function validate_excel_value($value, $data_type, $format = null, $allowed_values = null)
{ {