diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index aba83570..dbbe6982 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -327,7 +327,10 @@ class EmployeeRestController extends AdminController public function updatePremiumAmount($client_policy_id , $emp_code , $client_branch_id) { $response = $this->calculatePremium($client_policy_id , $emp_code , null , $client_branch_id); - + // echo '
'; + // print_r($response); + // echo ''; + // die(); if(count($response[$emp_code])) { @@ -441,35 +444,13 @@ class EmployeeRestController extends AdminController { try { + $requestData = $this->request->getJSON(); - - foreach ($requestData as $key => $value) { - - - $checkIfExist = $this->employeePolicyModel->where('employee_id', $value->employee_id) - ->where('client_policy_id', $value->client_policy_id) - ->where('is_active', 1 ) - ->findAll(); - - - - if ($checkIfExist) { - - $empPolicy = $this->employeePolicyModel->updateSiAndPremium($value->client_policy_id, $value->employee_id, $value->basic_cover_si); - - }else{ - - $data['employee_id']= $value->employee_id; - $data['client_policy_id']= $value->client_policy_id; - $data['basic_cover_si']= $value->basic_cover_si; - $data['status'] = 'draft'; - - $this->employeePolicyModel->insert($data); - } + if(count($requestData)) + { + $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code , $requestData[0]->client_branch_id); } - - $this->updatePremiumAmount($requestData[0]->client_policy_id , $requestData[0]->emp_code); - + return $this->respond(['status' => 'success','code' => 200,'data' => []], 200); } catch (\Exception $e) { @@ -1227,7 +1208,7 @@ class EmployeeRestController extends AdminController ->where('employee_polices.client_policy_id',$array->ClientPolicyId) ->get() ->getResult(); - + if(count($tpaArray)) { @@ -1517,7 +1498,7 @@ class EmployeeRestController extends AdminController ->where('client_branch_id',$this->request->getGet('client_branch_id')) ->where('is_addon_value',1)->findAll(); - + $clientPolicy = $this->clientPolicyModel->where('client_id',$this->request->getGet('client_id')) ->where('client_branch_id',$this->request->getGet('client_branch_id')) @@ -1526,8 +1507,17 @@ class EmployeeRestController extends AdminController if(count($clientPolicy)) { - $band = $this->employeeModel->where('is_active', 1 )->where('emp_code',$this->request->getGet('emp_code'))->where('client_id',$this->request->getGet('client_id'))->where('client_branch_id',$this->request->getGet('client_branch_id'))->where('family_floater_key','self')->get()->getRow()->band; - + $self = $this->employeeModel + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.is_active', 1) + ->where('employees.emp_code', $this->request->getGet('emp_code')) + ->where('employees.client_id', $this->request->getGet('client_id')) + ->where('employees.client_branch_id', $this->request->getGet('client_branch_id')) + ->where('employees.family_floater_key', 'self') + ->get() + ->getRow(); + + $band = $self->band; $PolicyData = []; foreach ($clientPolicy as $key => $array) { $responce = []; @@ -1579,6 +1569,7 @@ class EmployeeRestController extends AdminController ->get() ->getResult(); + if(count($tpaArray)) { if($tpaArray[0]->tpa_id != null) @@ -1602,7 +1593,13 @@ class EmployeeRestController extends AdminController if($array['is_addon'] == 3 && $array['policy_type_id'] == 3)//dependent add on policy { - + + $selfSi = $self->basic_cover_si; + $filteredSlabRates = array_filter($responce['SlabRates'], function ($rate) use ($selfSi) { + return $rate['si'] === $selfSi; + }); + // To reindex the array to have a proper 0 index + $responce['SlabRates'] = array_values($filteredSlabRates); // Map family floaters that already exist in the employee table $familyFloates = $policy_terms->family_floaters; @@ -1613,8 +1610,7 @@ class EmployeeRestController extends AdminController } // Convert familyFloaters terms data to plain array $floters = $this->FloterConvertion($familyFloates); - - + $data = []; $dependent_and_si_value = 0; $dependent_and_si_premium_value = 0; @@ -1649,59 +1645,30 @@ class EmployeeRestController extends AdminController } } } - - + //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',$this->request->getGet('emp_code')) - ->where('is_addon_value',0) - ->where('is_active', 1 ) - ->where('family_floater_key','parent') - ->findAll(); - - if(count($GMCEmpData) > 0){ - $floters = array_diff($floters, ["parent1","parent2"]); - }else{ - $floters = array_diff($floters, ["parent_in_law1","parent_in_law2"]); - } - }else{ + - $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); - } + $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); } } else if($familyFloates->{'either-parents-pil'} == 2 && count($floters)) { - if(count($addOnEmployeeData) == 0) - { - $GMCEmpData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) - ->where('is_addon_value',0) - ->where('is_active', 1 ) - ->where('family_floater_key','parent') - ->findAll(); - - if(count($GMCEmpData) > 0){ - $floters = array_diff($floters, ["parent1","parent2"]); - }else{ - $floters = array_diff($floters, ["parent_in_law1","parent_in_law2"]); - } - }else{ - $count_parent = 0; + $count_parent = 0; $count_parent_in_law = 0; foreach ($floters as $value) { if (preg_replace('/\d/', '', $value) == 'parent') { $count_parent++; } @@ -1710,12 +1677,10 @@ class EmployeeRestController extends AdminController if(($count_parent + $count_parent_in_law) == 2) { $floters = array_filter($floters, fn($value) => strpos($value, 'parent') === false); } - } } - - + // Add family floter buttons placement data for FE validation if(count($floters)){ foreach ($floters as $familyFloatesValue) { @@ -1732,11 +1697,11 @@ class EmployeeRestController extends AdminController } } - + $responce['family_floaters_of_dependent_and_si_array'] = $data; - $responce['family_floaters_of_dependent_and_si_value'] = $dependent_and_si_value; - $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value; - $responce['family_floaters_of_dependent_and_gst_value'] = $dependent_and_si_gst_value; + $responce['family_floaters_of_dependent_and_si_value'] = $dependent_and_si_value > 0 ? $dependent_and_si_value : 0; + $responce['family_floaters_of_dependent_and_si_premium_value'] = $dependent_and_si_premium_value > 0 ? $dependent_and_si_premium_value : 0; + $responce['family_floaters_of_dependent_and_gst_value'] = $dependent_and_si_gst_value > 0 ? $dependent_and_si_gst_value : 0; @@ -1868,7 +1833,7 @@ class EmployeeRestController extends AdminController $postData = json_decode($this->request->getBody(), true); $client_policy_id = $postData['client_policy_id']; sort($client_policy_id); - // Alternatively, you can use echo to see the type + $emp_code = $postData['emp_code']; $client_id = $postData['client_id']; @@ -1918,16 +1883,22 @@ class EmployeeRestController extends AdminController $account_manager_wholeData =sendMailNotification::sendMailNotification('account_maneger_summary_mail', $params); - foreach ($account_manager_wholeData as $key => $value) { - $mail_send_return1 = MailHelper::send_email($value); - $this->myLogger->logme("info", $mail_send_return1); + if($account_manager_wholeData != null && $account_manager_wholeData != '' && count($account_manager_wholeData)) + { + foreach ($account_manager_wholeData as $key => $value) { + $mail_send_return1 = MailHelper::send_email($value); + $this->myLogger->logme("info", $mail_send_return1); + } } $client_hr_wholeData =sendMailNotification::sendMailNotification('client_hr_summary_mail', $params); - foreach ($client_hr_wholeData as $key => $value) { - $mail_send_return2 = MailHelper::send_email($value); - $this->myLogger->logme("info", $mail_send_return2); + if($client_hr_wholeData != null && $client_hr_wholeData != '' &&count($client_hr_wholeData)) + { + foreach ($client_hr_wholeData as $key => $value) { + $mail_send_return2 = MailHelper::send_email($value); + $this->myLogger->logme("info", $mail_send_return2); + } } } }