GWM:ClientPolicyChanges

This commit is contained in:
bitbucket 2024-04-03 15:00:33 +05:30
parent 321d1e198f
commit 7837cf16dc
3 changed files with 171 additions and 23 deletions

View File

@ -232,7 +232,6 @@ $routes->get("/getEmployeeProfile", "EmployeeRestController::getEmployeeProfile/
$routes->post("/editEmployeeProfile", "EmployeeRestController::editEmployeeProfile");
$routes->group("employeeRest", ["filter" => "authJWT"], function($routes){
$routes->post("employeeUpload", "EmployeeRestController::employeeUpload");
$routes->get("relationshipList", "EmployeeRestController::relationshipList");

View File

@ -145,7 +145,7 @@ class EmployeeRestController extends AdminController
foreach ($data as $item) {
$id = $item->id;
$item->dob = $this->convertDateFormat($item->dob);
$item->dob = $this->convertDateFormatYMD($item->dob);
$employee = $this->employeeModel->update($id, (array)$item);
if ($employee) {
$updatedCount++;
@ -179,7 +179,7 @@ class EmployeeRestController extends AdminController
//update old data
$id = $item->id;
$item->family_floater_key = $this->RelationshipMap($item->relationship);
$item->dob = $this->convertDateFormat($item->dob);
$item->dob = $this->convertDateFormatYMD($item->dob);
$employee = $this->employeeModel->update($id, (array)$item);
if ($employee) {
$Count++;
@ -187,7 +187,7 @@ class EmployeeRestController extends AdminController
}else{
//create new data
$item->family_floater_key = $this->RelationshipMap($item->relationship);
$item->dob = $this->convertDateFormat($item->dob);
$item->dob = $this->convertDateFormatYMD($item->dob);
$employee = $this->employeeModel->insert($item);
if ($employee) {
$Count++;
@ -224,24 +224,32 @@ class EmployeeRestController extends AdminController
}
}
private function convertDateFormat($dateString)
private function convertDateFormatYMD($dateString)
{
// Attempt to create a DateTime object from the provided date string
$dateTime = \DateTime::createFromFormat('d-m-Y', $dateString);
// Check if the conversion was successful and the date string is in the format dd-mm-yyyy
if ($dateTime instanceof \DateTime) {
// Format the date to yyyy-mm-dd
return $dateTime->format('Y-m-d');
} else {
// If the date string is not in the format dd-mm-yyyy, return null
return null;
}
}
private function convertDateFormatDMY($dateString)
{
// Attempt to create a DateTime object from the provided date string
$dateTime = \DateTime::createFromFormat('Y-m-d', $dateString);
if ($dateTime instanceof \DateTime) {
return $dateTime->format('d-m-Y');
} else {
return null;
}
}
public function deleteDependence()
{
try {
print_r($this->rquest);die;
if($this->request->getGet('id'))
{
$delete = $this->employeeModel->where('id', $this->request->getGet('id'))->delete();
@ -804,9 +812,9 @@ public function getEmployeePolicy()
// Retrieve employee policy data by passing the employee primary key
$empPolicy = $this->employeeModel->getEmployeePolicy($id);
// Retrieve employee and dependents data by passing the employee code
$employeeData = $this->employeeModel->where('emp_code',$emp_code)->findAll();
$employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('is_addon_value',0)->findAll();
dd($empPolicy);
if ($empPolicy) {
$result = [];
@ -834,7 +842,7 @@ public function getEmployeePolicy()
$self['data']['employee_id'] = $id;
$self['data']['relationship'] = 'Self';
$self['data']['name'] = $selfData[0]['name'];
$self['data']['dob'] = $selfData[0]['dob'];
$self['data']['dob'] = $this->convertDateFormatDMY($selfData[0]['dob']);
$self['data']['mobile'] = $selfData[0]['mobile'];
$self['data']['client_policy_id'] = $array->ClientPolicyId;
@ -843,9 +851,7 @@ public function getEmployeePolicy()
// 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);
return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200);
}
// Construct value for policy type GMC
@ -855,6 +861,8 @@ public function getEmployeePolicy()
// Map family floaters that already exist in the employee table
$familyFloates = $array->Policy_Terms->family_floaters;
// Generate Notes string based on familyFloates terms
$array->notes = $this->FloterNotesConvertion($familyFloates);
// Convert familyFloaters terms data to plain array
$floters = $this->FloterConvertion($familyFloates);
@ -869,8 +877,9 @@ public function getEmployeePolicy()
$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;
$temp['data']['dob'] = $this->convertDateFormatDMY($value['dob']);
$temp['data']['client_policy_id'] = $array->ClientPolicyId;
$temp['data']['form_type'] = $dependent;
array_push($data,$temp);
unset($empData[$key]);
$floters = array_diff($floters, [$familyFloatesValue]);
@ -918,8 +927,6 @@ 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);
}
}
@ -968,6 +975,149 @@ public function FloterConvertion($array){
return $result;
}
public function FloterNotesConvertion($array){
$result = 'Can Add Self ';
foreach ($array as $key => $value) {
if ($value > 0) {
if($value != 0 && $key ==='either-parents-pil') {
$result .= ' + Either 2 Parents or 2 Parents in law';
}else if($value != 0 && $key ==='spouse') {
$string = str_replace('-', ' ', $key);
$string = ucwords($string);
$result .= ' + '.$string;
}else if($value != 0 && $key ==='self') {
}else{
$string = str_replace('-', ' ', $key);
$string = ucwords($string);
$result .= ' + '.$value.' '.$string;
}
}
}
return $result;
}
// public function getClientDetails()
// {
// // try {
// $client = $this->clientModel->where('id',$this->request->getGet('client_id'))->first();
// // Retrieve employee and dependents data by passing the employee code
// $employeeData = $this->employeeModel->where('emp_code','EMP001-K1')->where('is_addon_value',0)->findAll();
// $addOnEmployeeData = $this->employeeModel->where('emp_code','EMP001-K1')->where('is_addon_value',1)->findAll();
// if($client) {
// $client['client_logo'] = base_url().'public/uploads/logo/'.$client['client_logo'];
// $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id'))->findAll();
// $PolicyData = [];
// foreach ($clientPolicy as $key => $array) {
// // Reset employee array
// $empData = $employeeData;
// $decodedArray = json_decode($array['policy_terms']);
// $policy_terms = $decodedArray;
// $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array['id'],$array['client_id']);
// // print_r($getSlabAndGridData);die;
// $data['SlabRates'] = $getSlabAndGridData['slab_rates'];
// $data['GridMaster'] = $getSlabAndGridData['grid_master'];
// $data['client_id'] = $array['client_id'];
// $data['client_policy_id'] = $array['id'];
// $data['is_addon'] = $array['is_addon'];
// $data['open_for_enrollment'] = $array['open_for_enrollment'];
// $data['policy_terms'] = $decodedArray;
// // Map family floaters that already exist in the employee table
// $familyFloates = $policy_terms->family_floaters;
// // Generate Notes string based on familyFloates terms
// $array['notes'] = $this->FloterNotesConvertion($familyFloates);
// // Convert familyFloaters terms data to plain array
// $floters = $this->FloterConvertion($familyFloates);
// print_r($familyFloates);
// print_r($floters);
// $data1 = [];
// foreach ($floters as $familyFloatesValue) {
// $dependent = preg_replace('/\d/', '', $familyFloatesValue);
// if(count($addOnEmployeeData)){
// foreach ($addOnEmployeeData 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'] = $this->convertDateFormatDMY($value['dob']);
// $temp['data']['client_policy_id'] = $array['id'];
// $temp['data']['form_type'] = $dependent;
// array_push($data1,$temp);
// unset($addOnEmployeeData[$key]);
// $floters = array_diff($floters, [$familyFloatesValue]);
// break;
// }
// }
// }
// }
// //Remove Unwanted floter key from floters array based on either-parents-pil term value
// if($familyFloates->{'either-parents-pil'} == 1 && count($floters))
// {
// if(count($addOnEmployeeData) == 0)
// {
// $GMCEmpData = $this->employeeModel->where('emp_code','EMP001-K1')
// ->where('is_addon_value',0)
// ->where('family_floater_key','parent')
// ->findAll();
// if(count($GMCEmpData)){
// $floters = array_diff($floters, [$familyFloatesValue]);
// }
// }
// $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);
// }
// }
// print_r($floters);
// // 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['id'];
// $temp2['data']['button_name'] = 'Add '.ucfirst(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue)));
// $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue);
// array_push($data1,$temp2);
// }
// }
// $data['mapped_family_floaters'] = $data1;
// array_push($PolicyData, $data);
// return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$PolicyData]], 200);
// }
// return $this->respond(['status' => 'success','code' => 200,'data' => ['client'=>$client,'client_policy'=>$PolicyData]], 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);
// // }
// }
public function getClientDetails()
{
@ -986,6 +1136,4 @@ public function getClientDetails()
}
}
}

View File

@ -35,7 +35,8 @@ class EmployeeModel extends Model
"updated_by",
"updated_at",
"is_active",
"file_id"
"file_id",
"is_addon_value"
];
// Callbacks