GWM:Changes-inemployeePolicyApi

This commit is contained in:
bitbucket 2024-04-01 17:23:35 +05:30
parent 9121ece484
commit b950b24a26
2 changed files with 111 additions and 20 deletions

View File

@ -245,6 +245,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
$routes->get("deleteDependence", "EmployeeRestController::deleteDependence");
$routes->get("getEmployeeAndDependenceByClientId", "EmployeeRestController::getEmployeeAndDependenceByClientId");
$routes->get("getClientPolicy", "EmployeeRestController::getClientPolicy");
$routes->get("getClientDetails", "EmployeeRestController::getClientDetails");
});
$routes->post("sendEmail", "EmployeeRestController::send_email");

View File

@ -795,55 +795,71 @@ class EmployeeRestController extends AdminController
public function getEmployeePolicy()
{
try {
$id = $this->request->getGet('id');
$emp_code = $this->request->getGet('emp_code');
// This is an array containing keys to be removed from the terms and conditions array
$keysToRemove = ["removable_keys"];
// Retrieve employee policy data by passing the employee primary key
$empPolicy = $this->employeeModel->getEmployeePolicy($id);
$empData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
// print_r($empData);die;
// Retrieve employee and dependents data by passing the employee code
$employeeData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
dd($empPolicy);
if ($empPolicy) {
$result = [];
foreach ($empPolicy as $array) {
// Reset employee array
$empData = $employeeData;
// Removes specific keys from the decoded array and assigns the result to $refusingData
$decodedArray = json_decode($array->Policy_Terms);
$refusingData = (object) array_diff_key((array) $decodedArray, array_flip($keysToRemove));
$array->Policy_Terms = $refusingData;
// Retrieve slab rate and grid master data by passing the ClientPolicyId and ClientId
$getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array->ClientPolicyId,$array->ClientId);
$array->SlabRates = $getSlabAndGridData['slab_rates'];
$array->GridMaster = $getSlabAndGridData['grid_master'];
// Construct value for policy type GPA
if($getSlabAndGridData['grid_master']['policy_type'] == "GPA"){
$selfData = array_filter($empData, fn($arr) => $arr['family_floater_key'] === 'self');
// Filter employee data where the family_floater_key is 'self'
$selfData = array_filter($empData, fn($arr) => trim(strtolower($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']['mobile'] = $selfData[0]['mobile'];
$self['data']['client_policy_id'] = $array->ClientPolicyId;
$array->mapped_family_floaters = $self;
if($this->request->getGet('policy') == 'GPA'){
// Return result
if($this->request->getGet('policy') == 'GPA')
{
return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200);
}else{
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
}
// Construct value for policy type GMC
}else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC"){
//map family floates array to employee and dependent
// Map family floaters that already exist in the employee table
$familyFloates = $array->Policy_Terms->family_floaters;
// Convert familyFloaters terms data to plain array
$floters = $this->FloterConvertion($familyFloates);
$data = [];
foreach ($familyFloates as $familyFloatesValue) {
foreach ($floters as $familyFloatesValue) {
$dependent = preg_replace('/\d/', '', $familyFloatesValue);
if(count($empData)){
foreach ($empData as $key => $value) {
@ -857,25 +873,44 @@ public function getEmployeePolicy()
$temp['data']['client_policy_id'] = $array->ClientPolicyId;
array_push($data,$temp);
unset($empData[$key]);
$familyFloates = array_diff($familyFloates, [$familyFloatesValue]);
$floters = array_diff($floters, [$familyFloatesValue]);
break;
}
}
}
}
foreach ($familyFloates as $familyFloatesValue) {
// Remove Unwanted floter key from floters array based on either-parents-pil term value
if($familyFloates->{'either-parents-pil'} == 1 && count($floters))
{
$count_parent = 0;
$count_parent_in_law = 0;
foreach ($floters as $value) {
if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; }
if (preg_replace('/\d/', '', $value) == 'parent_in_law') {$count_parent_in_law++;}
}
if($count_parent != 2) {
$floters = array_filter($floters, fn($value) => strpos($value, 'parent_in_law') === false);
}
if($count_parent_in_law != 2) {
$floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false || strpos($value, 'parent_in_law') !== false);
}
}
// Add family floter buttons placement data for FE validation
if(count($floters)){
foreach ($floters 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']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue)));
$temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue);
array_push($data,$temp2);
}
}
$array->mapped_family_floaters = $data;
@ -883,13 +918,17 @@ public function getEmployeePolicy()
if($this->request->getGet('policy') == 'GMC'){
return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200);
}else{
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
}
}
$result[] = $array;
}
//return $this->respond(['status' => 'success','code' => 200,'data' => $result], 200);
}else{
return $this->respond(['status' => 'failed','code' => 404,'data' => []], 404);
}
@ -898,4 +937,55 @@ public function getEmployeePolicy()
}
}
public function FloterConvertion($array){
$result = [];
foreach ($array as $key => $value) {
if ($value > 0) {
if ($value != 0 && $key === 'childrens') {
for ($i = 1; $i <= $value; $i++) {
$result[] = "child" . $i;
}
} else if($value != 0 && $key ==='parents') {
for ($i = 1; $i <= $value; $i++) {
$result[] = "parent" . $i;
}
}else if($value != 0 && $key ==='parents-in-law') {
for ($i = 1; $i <= $value; $i++) {
$result[] = "parent_in_law" . $i;
}
}else if($value != 0 && $key ==='either-parents-pil') {
for ($i = 1; $i <= 2; $i++) {
$result[] = "parent" . $i;
$result[] = "parent_in_law" . $i;
}
}else {
$result[] = $key;
}
}
}
return $result;
}
public function getClientDetails()
{
try {
$client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first();
if($client) {
$clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll();
return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$clientPolicy]], 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);
}
}
}