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

@ -1372,7 +1372,7 @@ class EmployeeServiceController extends AdminController
$existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']); $existing_units = $this->clientBranchModel->getExisitingUnits(client_id: $file['client_id'],client_branch_id: $file['client_branch_id']);
$employee_data_group_by_family = data_group_by_family($excel_data, 'excel', '', $current_column_action); $employee_data_group_by_family = data_group_by_family($excel_data, 'excel', '', $current_column_action);
// dd($employee_data_group_by_family); // dd($employee_data_group_by_family);
foreach ($employee_data_group_by_family as $emp_id => $family) foreach ($employee_data_group_by_family as $emp_id => $family)
{ {
@ -1385,8 +1385,8 @@ class EmployeeServiceController extends AdminController
$existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file); $existing_famility_details = transform_db_data_to_excel($existing_famility_details,$file);
// Kint::dump($existing_famility_details); // Kint::dump($existing_famility_details);
$family = array_merge($family,$existing_famility_details); $family = array_merge($family,$existing_famility_details);
$family = data_group_by_family($family, 'excel', 1)[ $emp_id ];// reason to call this again is bring self to first index of the array $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); // dd($family);
$self = current(array_filter($family, fn($r) => strtolower($r[5] ?? '') === 'self')); $self = current(array_filter($family, fn($r) => strtolower($r[5] ?? '') === 'self'));
$premium = (int)($self['temp']['rata_premimum'] ?? 0); $premium = (int)($self['temp']['rata_premimum'] ?? 0);
foreach ($family as &$r) if (strtolower($r[5] ?? '') !== 'self') $r['self_rata_premium'] = $premium; foreach ($family as &$r) if (strtolower($r[5] ?? '') !== 'self') $r['self_rata_premium'] = $premium;
@ -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){ /**
* ---------------------------------------------------
* 1. RESET DEPENDENT PREMIUM IF SELF HAS SAME RATA
* ---------------------------------------------------
*/
if (
!empty($selfData['temp']) &&
!empty($selfData['policy_details']) &&
($selfData['temp']['premium'] ?? 0) == ($selfData['policy_details']['premium'] ?? 0)
) {
foreach ($family as &$row) {
$selfPremium = 0; if (strtolower($row['relationship'] ?? '') === 'self') {
$familyPremium = 0; continue;
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 (
if (isset($row['relationship']) && strtolower($row['relationship']) !== 'self') ($row['temp']['premium_type'] ?? null) == 1 &&
{ ($row['data_from'] ?? '') === 'excel'
$familyPremium += (float) ($row['policy_details']['rata_premimum'] ?? 0); ) {
$row['policy_details']['rata_premimum'] = 0;
$row['policy_details']['gst'] = 0;
} }
} }
if($selfPremium > $familyPremium || $selfPremium == $familyPremium){
$reset_family_premium = true;
}
} }
/**
* ---------------------------------------------------
* 2. APPLY FINAL PREMIUM ADJUSTMENT TO DEPENDENTS
* ---------------------------------------------------
*/
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 (($row['temp']['premium_type'] ?? null) == 1) {
if (isset($row['temp']['premium_type']) && $row['temp']['premium_type'] == 1) {
if (!$dependentRataGiven && isset($row['data_from']) && $row['data_from'] === 'excel') { // FIRST excel dependent keeps premium
// First eligible 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)
{ {