Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
aadhavan valli 2024-04-03 15:27:26 +05:30
commit fc17aeb058
4 changed files with 276 additions and 39 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");
@ -245,6 +244,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

@ -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();
@ -814,55 +822,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)->where('is_addon_value',0)->findAll();
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']['dob'] = $this->convertDateFormatDMY($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 $this->respond(['status' => 'success','code' => 200,'data' => $array], 200);
// Return result
if($this->request->getGet('policy') == 'GPA')
{
return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200);
}
// 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;
// Generate Notes string based on familyFloates terms
$array->notes = $this->FloterNotesConvertion($familyFloates);
// 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) {
@ -872,29 +896,49 @@ 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]);
$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;
@ -908,7 +952,201 @@ public function getEmployeePolicy()
$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);
}
}
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 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()
{
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);
}

View File

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

View File

@ -176,8 +176,6 @@
$('.btnBack').click(function(){
$('#policy_form')[0].reset();
$('#GMC').remove();
$('#GPA').remove();
$('#add_form').hide();
$('#table_list').show();
$('.btnBack').hide();
@ -339,8 +337,8 @@
<a href="javascript: void(0);" class="dropdown-toggle arrow-none btn btn-light btn-sm" data-toggle="dropdown"aria-expanded="false"><i class="mdi mdi-dots-horizontal"></i></a>
<div class="dropdown-menu dropdown-menu-right">
<a href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnPolicyEdit"><i class="mdi mdi-lead-pencil mr-2 text-muted font-18 vertical-middle"></i>Edit</a>
<a href="#" data-id="${item.id}" class="dropdown-item btnPolicyMaster" data-toggle="modal" id="${search_term}"><i class="mdi mdi-wrench mr-2 text-muted font-18 vertical-middle"></i>Terms</a>
<a href="#" data-id="${item.id}" class="dropdown-item btnPolicyModel" data-toggle="modal" data-target="#bs-example-modal-lg"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Rac Rate</a>
<a href="#" data-id="${item.id}" id="${search_term}" class="dropdown-item btnPolicyMaster" data-toggle="modal"><i class="mdi mdi-wrench mr-2 text-muted font-18 vertical-middle"></i>Terms</a>
<a href="#" data-id="${item.id}" id="${search_term}"class="dropdown-item btnPolicyModel" data-toggle="modal" data-target="#bs-example-modal-lg"><i class="mdi mdi-book-open mr-2 text-muted font-18 vertical-middle"></i>Rac Rate</a>
<a href="#" data-id="${item.id}" id="${item.policy_id}" class="dropdown-item btnOpenEnroll"><i class="mdi mdi-file-lock mr-2 text-muted font-18 vertical-middle"></i>Open Enrollment</a>
</div>
</div>