GWM:Changes-In-GetEmpPolicyApi
This commit is contained in:
parent
8a34b023ab
commit
505d29ad7c
@ -308,134 +308,134 @@ class EmployeeRestController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getEmployeePolicy()
|
// public function getEmployeePolicy()
|
||||||
{
|
// {
|
||||||
try {
|
// try {
|
||||||
$id = $this->request->getGet('id');
|
// $id = $this->request->getGet('id');
|
||||||
$emp_code = $this->request->getGet('emp_code');
|
// $emp_code = $this->request->getGet('emp_code');
|
||||||
|
|
||||||
$keysToRemove = ["removable_keys"];
|
// $keysToRemove = ["removable_keys"];
|
||||||
|
|
||||||
$empPolicy = $this->employeeModel->getEmployeePolicy($id);
|
// $empPolicy = $this->employeeModel->getEmployeePolicy($id);
|
||||||
|
|
||||||
$empData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
|
// $empData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
|
||||||
if ($empPolicy) {
|
// if ($empPolicy) {
|
||||||
|
|
||||||
$result = [];
|
// $result = [];
|
||||||
foreach ($empPolicy as $array) {
|
// foreach ($empPolicy as $array) {
|
||||||
|
|
||||||
$decodedArray = json_decode($array->Policy_Terms);
|
// $decodedArray = json_decode($array->Policy_Terms);
|
||||||
$refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove));
|
// $refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove));
|
||||||
|
|
||||||
|
|
||||||
$array->Policy_Terms = $refusingData;
|
// $array->Policy_Terms = $refusingData;
|
||||||
$getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId);
|
// $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId);
|
||||||
$array->SlabRates = $getSlabAndGridData['slab_rates'];
|
// $array->SlabRates = $getSlabAndGridData['slab_rates'];
|
||||||
$array->GridMaster = $getSlabAndGridData['grid_master'];
|
// $array->GridMaster = $getSlabAndGridData['grid_master'];
|
||||||
|
|
||||||
if($getSlabAndGridData['grid_master']['policy_type'] == "GPA"){
|
// if($getSlabAndGridData['grid_master']['policy_type'] == "GPA"){
|
||||||
$default_si = $array->Policy_Terms->sumInsured2;
|
// $default_si = $array->Policy_Terms->sumInsured2;
|
||||||
$index = -1;
|
// $index = -1;
|
||||||
foreach ($array->SlabRates as $key => $value) {
|
// foreach ($array->SlabRates as $key => $value) {
|
||||||
if ($value['si'] == $default_si) {
|
// if ($value['si'] == $default_si) {
|
||||||
$index = $key;
|
// $index = $key;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if ($index >= 0) {
|
// if ($index >= 0) {
|
||||||
$element =$array->SlabRates[$index];
|
// $element =$array->SlabRates[$index];
|
||||||
array_splice($array->SlabRates, $index, 1);
|
// array_splice($array->SlabRates, $index, 1);
|
||||||
array_unshift($array->SlabRates, $element);
|
// array_unshift($array->SlabRates, $element);
|
||||||
}
|
// }
|
||||||
|
|
||||||
$employee_policy = $this->employeePolicyModel->where('employee_id',$id)->where('client_policy_id',$array->ClientPolicyId)->get()->getRow();
|
// $employee_policy = $this->employeePolicyModel->where('employee_id',$id)->where('client_policy_id',$array->ClientPolicyId)->get()->getRow();
|
||||||
if($employee_policy){
|
// if($employee_policy){
|
||||||
$gpaSI['family_floater_key'] = 'self';
|
// $gpaSI['family_floater_key'] = 'self';
|
||||||
$gpaSI['label'] = 'Self';
|
// $gpaSI['label'] = 'Self';
|
||||||
$gpaSI['employee_id'] = $employee_policy->employee_id;
|
// $gpaSI['employee_id'] = $employee_policy->employee_id;
|
||||||
$gpaSI['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
|
// $gpaSI['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
|
||||||
$gpaSI['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
|
// $gpaSI['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
|
||||||
$gpaSI['client_policy_id'] = $array->ClientPolicyId;
|
// $gpaSI['client_policy_id'] = $array->ClientPolicyId;
|
||||||
|
|
||||||
$array->mapped_family_floaters = $gpaSI;
|
// $array->mapped_family_floaters = $gpaSI;
|
||||||
}else{
|
// }else{
|
||||||
$gpaSI['family_floater_key'] = 'self';
|
// $gpaSI['family_floater_key'] = 'self';
|
||||||
$gpaSI['label'] = 'Self';
|
// $gpaSI['label'] = 'Self';
|
||||||
$gpaSI['employee_id'] = $id;
|
// $gpaSI['employee_id'] = $id;
|
||||||
$gpaSI['basic_cover_si'] = null;
|
// $gpaSI['basic_cover_si'] = null;
|
||||||
$gpaSI['premium'] = null;
|
// $gpaSI['premium'] = null;
|
||||||
$gpaSI['client_policy_id'] = $array->ClientPolicyId;
|
// $gpaSI['client_policy_id'] = $array->ClientPolicyId;
|
||||||
|
|
||||||
$array->mapped_family_floaters = $gpaSI;
|
// $array->mapped_family_floaters = $gpaSI;
|
||||||
}
|
// }
|
||||||
|
|
||||||
}else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC"){
|
// }else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC"){
|
||||||
|
|
||||||
// re-arranging order of si
|
// // re-arranging order of si
|
||||||
$default_si = $array->Policy_Terms->sum_insured;
|
// $default_si = $array->Policy_Terms->sum_insured;
|
||||||
// Filter the array using the callback function
|
// // Filter the array using the callback function
|
||||||
$getPremium = array_filter($array->SlabRates , function ($value) use ($default_si) { return $value['si'] == $default_si; } );
|
// $getPremium = array_filter($array->SlabRates , function ($value) use ($default_si) { return $value['si'] == $default_si; } );
|
||||||
$default_premium = $getPremium[0]['premium'];
|
// $default_premium = $getPremium[0]['premium'];
|
||||||
|
|
||||||
$index = -1;
|
// $index = -1;
|
||||||
foreach ($array->SlabRates as $key => $value) {
|
// foreach ($array->SlabRates as $key => $value) {
|
||||||
if ($value['si'] == $default_si) {
|
// if ($value['si'] == $default_si) {
|
||||||
$index = $key;
|
// $index = $key;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if ($index >= 0) {
|
// if ($index >= 0) {
|
||||||
$element =$array->SlabRates[$index];
|
// $element =$array->SlabRates[$index];
|
||||||
array_splice($array->SlabRates, $index, 1);
|
// array_splice($array->SlabRates, $index, 1);
|
||||||
array_unshift($array->SlabRates, $element);
|
// array_unshift($array->SlabRates, $element);
|
||||||
}
|
// }
|
||||||
|
|
||||||
//map family floates array to employee and dependent
|
// //map family floates array to employee and dependent
|
||||||
$familyFloates = $array->Policy_Terms->family_floaters;
|
// $familyFloates = $array->Policy_Terms->family_floaters;
|
||||||
$data = [];
|
// $data = [];
|
||||||
foreach ($familyFloates as $familyFloatesValue) {
|
// foreach ($familyFloates as $familyFloatesValue) {
|
||||||
$dependent = preg_replace('/\d/', '', $familyFloatesValue);
|
// $dependent = preg_replace('/\d/', '', $familyFloatesValue);
|
||||||
if(count($empData)){
|
// if(count($empData)){
|
||||||
foreach ($empData as $key => $value) {
|
// foreach ($empData as $key => $value) {
|
||||||
if ($value['family_floater_key'] === $dependent) {
|
// if ($value['family_floater_key'] === $dependent) {
|
||||||
$employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->get()->getRow();
|
// $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array->ClientPolicyId)->get()->getRow();
|
||||||
$temp['family_floater_key'] = $familyFloatesValue;
|
// $temp['family_floater_key'] = $familyFloatesValue;
|
||||||
$temp['label'] = $value['relationship'];
|
// $temp['label'] = $value['relationship'];
|
||||||
$temp['name'] = $value['name'];
|
// $temp['name'] = $value['name'];
|
||||||
$temp['employee_id'] = $value['id'];
|
// $temp['employee_id'] = $value['id'];
|
||||||
$temp['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
|
// $temp['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null;
|
||||||
$temp['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
|
// $temp['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null;
|
||||||
$temp['client_policy_id'] = $array->ClientPolicyId;
|
// $temp['client_policy_id'] = $array->ClientPolicyId;
|
||||||
array_push($data,$temp);
|
// array_push($data,$temp);
|
||||||
unset($empData[$key]);
|
// unset($empData[$key]);
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
$array->mapped_family_floaters = $data;
|
// $array->mapped_family_floaters = $data;
|
||||||
|
|
||||||
$temp2=[];
|
// $temp2=[];
|
||||||
foreach ($array->SlabRates as $key => $value) {
|
// foreach ($array->SlabRates as $key => $value) {
|
||||||
$value['additional_premium'] = $value['premium'] - $default_premium;
|
// $value['additional_premium'] = $value['premium'] - $default_premium;
|
||||||
array_push($temp2,$value);
|
// array_push($temp2,$value);
|
||||||
}
|
// }
|
||||||
$array->SlabRates = $temp2;
|
// $array->SlabRates = $temp2;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
$result[] = $array;
|
// $result[] = $array;
|
||||||
}
|
// }
|
||||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
|
// return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
|
||||||
}else{
|
// }else{
|
||||||
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
|
// return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
|
||||||
}
|
// }
|
||||||
} catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
// return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Get the RelationShip list
|
// Get the RelationShip list
|
||||||
|
|
||||||
@ -790,6 +790,112 @@ class EmployeeRestController extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------
|
||||||
|
|
||||||
|
public function getEmployeePolicy()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$id = $this->request->getGet('id');
|
||||||
|
$emp_code = $this->request->getGet('emp_code');
|
||||||
|
|
||||||
|
$keysToRemove = ["removable_keys"];
|
||||||
|
|
||||||
|
$empPolicy = $this->employeeModel->getEmployeePolicy($id);
|
||||||
|
|
||||||
|
$empData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
|
||||||
|
// print_r($empData);die;
|
||||||
|
if ($empPolicy) {
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
foreach ($empPolicy as $array) {
|
||||||
|
|
||||||
|
$decodedArray = json_decode($array->Policy_Terms);
|
||||||
|
$refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove));
|
||||||
|
|
||||||
|
|
||||||
|
$array->Policy_Terms = $refusingData;
|
||||||
|
$getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId);
|
||||||
|
$array->SlabRates = $getSlabAndGridData['slab_rates'];
|
||||||
|
$array->GridMaster = $getSlabAndGridData['grid_master'];
|
||||||
|
|
||||||
|
if($getSlabAndGridData['grid_master']['policy_type'] == "GPA"){
|
||||||
|
|
||||||
|
$selfData = array_filter($empData, fn($arr) => $arr['family_floater_key'] === 'self');
|
||||||
|
$self['is_value_exist'] = true;
|
||||||
|
$self['data']['family_floater_key'] = 'self';
|
||||||
|
$self['data']['employee_id'] = $id;
|
||||||
|
$self['data']['relationship'] = 'Self';
|
||||||
|
$self['data']['name'] = $selfData[0]['name'];
|
||||||
|
$self['data']['dob'] = $selfData[0]['dob'];
|
||||||
|
$self['data']['client_policy_id'] = $array->ClientPolicyId;
|
||||||
|
|
||||||
|
$array->mapped_family_floaters = $self;
|
||||||
|
|
||||||
|
|
||||||
|
if($this->request->getGet('policy') == 'GPA'){
|
||||||
|
return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC"){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//map family floates array to employee and dependent
|
||||||
|
$familyFloates = $array->Policy_Terms->family_floaters;
|
||||||
|
$data = [];
|
||||||
|
foreach ($familyFloates as $familyFloatesValue) {
|
||||||
|
$dependent = preg_replace('/\d/', '', $familyFloatesValue);
|
||||||
|
if(count($empData)){
|
||||||
|
foreach ($empData as $key => $value) {
|
||||||
|
if ($value['family_floater_key'] === $dependent) {
|
||||||
|
$temp['is_value_exist'] = true;
|
||||||
|
$temp['data']['family_floater_key'] = $familyFloatesValue;
|
||||||
|
$temp['data']['employee_id'] = $value['id'];
|
||||||
|
$temp['data']['relationship'] = $value['relationship'];
|
||||||
|
$temp['data']['name'] = $value['name'];
|
||||||
|
$temp['data']['dob'] = $value['dob'];
|
||||||
|
$temp['data']['client_policy_id'] = $array->ClientPolicyId;
|
||||||
|
array_push($data,$temp);
|
||||||
|
unset($empData[$key]);
|
||||||
|
$familyFloates = array_diff($familyFloates, [$familyFloatesValue]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($familyFloates as $familyFloatesValue) {
|
||||||
|
|
||||||
|
$temp2['is_value_exist'] = false;
|
||||||
|
$temp2['data']['family_floater_key'] = $familyFloatesValue;
|
||||||
|
$temp2['data']['client_policy_id'] = $array->ClientPolicyId;
|
||||||
|
$temp2['data']['button_name'] = 'Add '.ucfirst(preg_replace('/\d/', '', $familyFloatesValue));
|
||||||
|
$temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue);
|
||||||
|
|
||||||
|
array_push($data,$temp2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$array->mapped_family_floaters = $data;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if($this->request->getGet('policy') == 'GMC'){
|
||||||
|
return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[] = $array;
|
||||||
|
}
|
||||||
|
//return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
|
||||||
|
}else{
|
||||||
|
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user