diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 182a0151..c6e26f17 100644 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -19,6 +19,7 @@ use App\Models\FileModel; use App\Models\ClientPolicyModel; use App\Models\PolicyPremium1Model; use App\Models\PolicyPremium2Model; +use App\Models\PolicyTypeModel; use App\Controllers\Jobs ; use App\Controllers\JobWorker ; @@ -47,6 +48,7 @@ class EmployeeRestController extends AdminController protected $clientPolicyModel; protected $policyPremium1Model; protected $policyPremium2Model; + protected $policyTypeModel; public function __construct() { @@ -62,6 +64,7 @@ class EmployeeRestController extends AdminController $this->clientPolicyModel = new ClientPolicyModel(); $this->policyPremium1Model = new PolicyPremium1Model(); $this->policyPremium2Model = new PolicyPremium2Model(); + $this->policyTypeModel = new PolicyTypeModel(); } @@ -1029,7 +1032,7 @@ class EmployeeRestController extends AdminController public function getEmployeePolicy() { - // try { + try { $id = $this->request->getGet('id'); $emp_code = $this->request->getGet('emp_code'); @@ -1051,8 +1054,8 @@ public function getEmployeePolicy() 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)); @@ -1095,7 +1098,7 @@ public function getEmployeePolicy() }else if($getSlabAndGridData['grid_master']['policy_type'] == "GMC"){ - + // Map family floaters that already exist in the employee table $familyFloates = $array->Policy_Terms->family_floaters; @@ -1170,11 +1173,25 @@ public function getEmployeePolicy() } $array->mapped_family_floaters = $data; - + $array->type = "Group Medical Coverage"; + $checkGmcParentsPolicyExist = $this->clientPolicyModel->select('client_policy.id as ClientPolicyId , client_policy.client_id as ClientId, policies.id as PolicyId , client_policy.policy_type_id as policy_type_id, policies.name as Policy_Name , client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type , client_policy.policy_terms as Policy_Terms') + ->join('policies', 'client_policy.policy_id = policies.id', 'left') + ->where('client_policy.policy_type_id', 3 ) + ->where('client_policy.is_addon', 1 ) + ->where('client_policy.client_id', $this->request->getGet('client_id') ) + ->where('client_policy.is_active', 1 ) + ->get() + ->getResult(); + if($checkGmcParentsPolicyExist) + { + $GmcParrentsData = $this->getGmcParrentsPolicy($checkGmcParentsPolicyExist,$emp_code,$client_id); + return $this->respond(['status' => 'success','code' => 200,'data' => [$array,$GmcParrentsData]], 200); + + } if($this->request->getGet('policy') == 'GMC'){ - return $this->respond(['status' => 'success','code' => 200,'data' => $array], 200); + return $this->respond(['status' => 'success','code' => 200,'data' => [$array]], 200); } } @@ -1188,11 +1205,139 @@ public function getEmployeePolicy() }else{ return $this->respond(['status' => 'failed','code' => 404,'data' => []], 200); } - // } catch (\Exception $e) { - // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); - // } + } catch (\Exception $e) { + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + } } + +public function getGmcParrentsPolicy($GmcParrentsPolicy,$emp_code,$client_id) +{ + + $employeeData = $this->employeeModel->where('emp_code',$emp_code)->where('client_id',$client_id) + ->where('is_active', 1 )->where('is_addon_value',0)->findAll(); + foreach ($GmcParrentsPolicy as $key => $array) { + + + + // Reset employee array + $empData = $employeeData; + + + $array->Policy_Terms = json_decode($array->Policy_Terms); + + + // 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']; + + $tpaArray = $this->employeeModel->select('employees.name as name , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') + ->join('employee_polices', 'employee_polices.employee_id = employees.id') + ->where('employees.emp_code',$emp_code) + ->where('employees.is_active',1) + ->where('employee_polices.client_policy_id',$array->ClientPolicyId) + ->get() + ->getResult(); + + if(count($tpaArray)) + { + + if($tpaArray[0]->tpa_id != null) + $array->eCardDownload = base_url('download-e-card/') . $tpaArray[0]->rand_string; + else + $array->eCardDownload = null; + + }else{ + $array->eCardDownload = null; + } + + // if($array->tpa_id != null){ + // $array->eCardDownload = base_url('download-e-card/') . $array->rand_string; + // }else{ $array->eCardDownload = null; } + $array->eCardDownload = null; + + // 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); + + if($getSlabAndGridData['slab_rates'][0]['premium_type'] == 1) + { + $array->floter_text_heading = 'Floater Sum Insured'; + $array->floter_text_description = 'This is a floater sum insured. A floater is a type of sum insured that provides coverage to more than one member ot a family at the same time. Simply put, its a single insurance cover for the entire family.'; + }else{ + $array->floter_text_heading = 'Sum Insured'; + $array->floter_text_description = ''; + } + + // Convert familyFloaters terms data to plain array + $floters = $this->FloterConvertion($familyFloates); + + $data = []; + foreach ($floters 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'] = $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]); + break; + } + } + } + } + + // 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(str_replace('_', ' ', preg_replace('/\d/', '', $familyFloatesValue))); + $temp2['data']['form_type'] = preg_replace('/\d/', '', $familyFloatesValue); + + array_push($data,$temp2); + + } + } + + $array->mapped_family_floaters = $data; + $array->type = "Group Medical Coverage - Parents"; + + return $array; + + } + +} public function FloterConvertion($array){ $result = []; @@ -1226,7 +1371,7 @@ public function FloterConvertion($array){ public function FloterNotesConvertion($array){ - $result = 'Can Add Self '; + $result = ' '; foreach ($array as $key => $value) { if ($value > 0) { if($value != 0 && $key ==='either-parents-pil') { @@ -1236,6 +1381,7 @@ public function FloterNotesConvertion($array){ $string = ucwords($string); $result .= ' + '.$string; }else if($value != 0 && $key ==='self') { + $result = 'Can Add Self '; }else if($value != 0 && $key ==='childrens') { if($value > 1){ $result .= ' + '.$value.' Children'; }else{ $result .= ' + '.$value.' Child'; } }else{ @@ -1278,13 +1424,13 @@ public function getAddOnPolicy() $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id')) ->where('policy_status', 1) ->findAll(); -// dd( $clientPolicy); + if(count($clientPolicy)) { $PolicyData = []; foreach ($clientPolicy as $key => $array) { $responce = []; - + $decodedArray = json_decode($array['policy_terms']); $policy_terms = $decodedArray; $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard($array['id'],$array['client_id']); @@ -1297,6 +1443,7 @@ public function getAddOnPolicy() $responce['is_addon'] = $array['is_addon']; $responce['OpenForEnrollment'] = $array['open_for_enrollment']; $responce['policy_terms'] = $decodedArray; + $responce['policy_type_id'] = $array['policy_type_id']; $tpaArray = $this->employeeModel->select('employees.name as name , employee_polices.tpa_id as tpa_id , employee_polices.rand_string as rand_string') ->join('employee_polices', 'employee_polices.employee_id = employees.id') @@ -1327,7 +1474,7 @@ public function getAddOnPolicy() } - if($array['is_addon'] == 3)//dependent add on policy + if($array['is_addon'] == 3 && $array['policy_type_id'] == 3)//dependent add on policy { @@ -1438,9 +1585,17 @@ public function getAddOnPolicy() //array_push($PolicyData, $responce); - }else if($array['is_addon'] == 2)//Topup policy + }else if($array['is_addon'] == 2 && $array['policy_type_id'] == 4)//Topup policy { + $whereArray = []; + foreach ( $decodedArray->family_floaters as $key => $value) { + if($value != 0){ + if($key == 'parents'){ $text = 'parent'; }else if($key == 'childrens'){ $text = 'child'; }else{ $text = $key; } + array_push($whereArray,$text); + } + } + $getAddOnType = $this->clientPolicyModel->where('id',$array['base_policy'])->where('policy_status', 1)->get()->getRow(); $basePolicyAddOnType = $getAddOnType->is_addon; @@ -1450,7 +1605,7 @@ public function getAddOnPolicy() $only_si_value = 0; $only_si_premium_value = 0; $only_si_gst_value = 0; - $BasePolicyEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',$is_addon_value)->findAll(); + $BasePolicyEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',$is_addon_value)->whereIn('family_floater_key',$whereArray)->findAll(); foreach ($BasePolicyEmployeeData as $key => $value) { $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); @@ -1473,12 +1628,62 @@ public function getAddOnPolicy() $responce['family_floaters_of_only_si_value'] = $only_si_value; $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; $responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value; + $responce['type'] = "Group Medical Coverage - Top Up"; if($this->request->getGet('policy') == 'GMC-SI-TOPUP'){ return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_topup'=>$responce]], 200); } + }else if($array['is_addon'] == 2 && $array['policy_type_id'] == 5)//Parents Topup policy + { + + $whereArray = []; + foreach ( $decodedArray->family_floaters as $key => $value) { + if($value != 0){ + if($key == 'parents'){ $text = 'parent'; }else if($key == 'childrens'){ $text = 'child'; }else{ $text = $key; } + array_push($whereArray,$text); + } + } + + $getAddOnType = $this->clientPolicyModel->where('id',$array['base_policy'])->where('policy_status', 1)->get()->getRow(); + $basePolicyAddOnType = $getAddOnType->is_addon; + // if is_addon value is 1 it is GMC if not it is one of the Add On policy + if($basePolicyAddOnType == 1){ $is_addon_value = 0; }else{ $is_addon_value = 1; } + $only_si_array = []; + $only_si_value = 0; + $only_si_premium_value = 0; + $only_si_gst_value = 0; + $BasePolicyEmployeeData = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('is_addon_value',$is_addon_value)->whereIn('family_floater_key',$whereArray)->findAll(); + foreach ($BasePolicyEmployeeData as $key => $value) { + + $employee_policy = $this->employeePolicyModel->where('employee_id',$value['id'])->where('client_policy_id',$array['id'])->where('is_active', 1 )->get()->getRow(); + if(isset($employee_policy->basic_cover_si)){ $only_si_value = $employee_policy->basic_cover_si; } + if(isset($employee_policy->premium)){ $only_si_premium_value = $only_si_premium_value + $employee_policy->premium;} + if(isset($employee_policy->gst)){ $only_si_gst_value = $only_si_gst_value + $employee_policy->gst;} + $temp3['is_value_exist'] = true; + $temp3['data']['employee_id'] = $value['id']; + $temp3['data']['relationship'] = $value['relationship']; + $temp3['data']['name'] = $value['name']; + $temp3['data']['dob'] = $this->convertDateFormatDMY($value['dob']); + $temp3['data']['client_policy_id'] = $array['id']; + $temp3['data']['basic_cover_si'] = isset($employee_policy->basic_cover_si) ? $employee_policy->basic_cover_si : null; + $temp3['data']['premium'] = isset($employee_policy->premium) ? $employee_policy->premium : null; + array_push($only_si_array,$temp3); + + } + + $responce['family_floaters_of_only_si_array'] = $only_si_array; + $responce['family_floaters_of_only_si_value'] = $only_si_value; + $responce['family_floaters_of_only_si_premium_value'] = $only_si_premium_value; + $responce['family_floaters_of_only_si_gst_value'] = $only_si_gst_value; + $responce['type'] = "Group Medical Coverage - Parents Top Up"; + + if($this->request->getGet('policy') == 'GMC-SI-PARENT-TOPUP'){ + return $this->respond(['status' => 'success','code' => 200,'data' => ['gmc_si_parent_topup'=>$responce]], 200); + } + + } } @@ -1605,17 +1810,17 @@ public function getCashDepositData() $data['balance'] = count($data['depositData']) ? $data['depositData'][0]->balance : 0; $data['policyDetails'] = []; - $ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id,policies.policy_type_id as policy_type_id, policies.name as policy_name , client_policy.is_addon as is_addon') + $ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, policies.id as policy_id , client_policy.policy_type_id as policy_type_id, policies.name as policy_name , client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type ') ->join('policies', 'client_policy.policy_id = policies.id', 'left') ->where('client_policy.insurer_id', $value['insurerId'] ) ->where('client_policy.client_id', $this->request->getGet('client_id') ) ->where('client_policy.is_active', 1 ) ->findAll(); + // dd( $ClientPolicyData); foreach ($ClientPolicyData as $key => $value) { - echo $value['client_policy_id']; - $getSlabAndGridData = $this->policesModel->getPolicySlabRatesForEmpOnboard( $value['client_policy_id'],$value['client_id']); - if($value['is_addon'] == "2"){ $value['type'] = 'SI TopUp'; }else if($value['is_addon'] == "3"){ $value['type'] = 'Dependent AddOn'; }else{ $value['type'] = $getSlabAndGridData['grid_master']['policy_type']; } + + $value['type'] = $this->policyTypeModel->where('id',$value['policy_type_id'])->get()->getRow()->policy_type; $employeeDetails = $this->employeePolicyModel->getEmployeePolicy( client_id:$value['client_id'],policy_id: $value['client_policy_id'],status:0); $enrolledCount = 0; $draftCount = 0; diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index 2824f4e1..f67671b3 100644 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -36,7 +36,8 @@ class EmployeeModel extends Model "updated_at", "is_active", "file_id", - "is_addon_value" + "is_addon_value", + "is_createdby_hr" ]; // Callbacks diff --git a/app/Views/layout/header.php b/app/Views/layout/header.php index f07176f8..e0c2e9dc 100644 --- a/app/Views/layout/header.php +++ b/app/Views/layout/header.php @@ -607,7 +607,7 @@ $currentUrl = base_url(); $parsedUrl = parse_url($currentUrl); $baseUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . '/'; - $redirectUrl = $baseUrl . 'Ticketing/nhance_login?' . http_build_query(['token' => $sessionData]); + $redirectUrl = $baseUrl . 'Ticketing/staff/login?' . http_build_query(['token' => $sessionData]); ?>