diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index bf626b79..d43e56bf 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -223,6 +223,10 @@ class EmployeeRestController extends AdminController { try { $data = $this->request->getJSON(); + + $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($data[0]->client_policy_id); + if($openForEnrollment == false){ return $this->respond(['status' => 'failed','code' => 404,'data' => 'Enrollment closed'], 404); } + if ($data) { $Count = 0; @@ -505,6 +509,10 @@ class EmployeeRestController extends AdminController try { $requestData = $this->request->getJSON(); + + $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($requestData[0]->client_policy_id); + if($openForEnrollment == false){ return $this->respond(['status' => 'failed','code' => 404,'data' => 'Enrollment closed'], 404); } + foreach ($requestData as $key => $value) { @@ -1996,6 +2004,7 @@ class EmployeeRestController extends AdminController { $postData = json_decode($this->request->getBody(), true); + $this->myLogger->logme("error", $this->request->getBody()); $client_policy_id = $postData['client_policy_id']; sort($client_policy_id); @@ -2003,7 +2012,7 @@ class EmployeeRestController extends AdminController $client_id = $postData['client_id']; $empData = $this->employeeModel->where('emp_code', $emp_code )->where('client_id', $client_id ) ->where('is_active', 1 )->findAll(); - + $employeeIds = array_column($empData, 'id'); //for mail common parameter $filteredEmpData = array_filter($empData, fn($item) => $item['relationship'] === 'Self'); @@ -2015,39 +2024,56 @@ class EmployeeRestController extends AdminController $policy = $this->clientPolicyModel->where('id',$value)->where('open_for_enrollment',1)->find(); if($policy) { - foreach ($empData as $empDataKey => $empDataValue) + $this->myLogger->logme("error", 'client policy id = '.$value.' is open for enrollment'); + + $empPolicyData = $this->employeePolicyModel->where('client_policy_id', $value ) + ->where('is_active', 1 ) + ->whereIn($employeeIds) + ->findAll(); + if(count($empPolicyData)) { + + $empIdsFromPolicyData = array_column($empPolicyData, 'employee_id'); + //update emp polict table $this->employeePolicyModel->where('client_policy_id', $value ) ->where('is_active', 1 ) - ->where('employee_id', $empDataValue['id'] ) - ->where('status', 'draft' ) + ->whereIn('employee_id', $empIdsFromPolicyData ) + ->groupStart() + ->where('status', 'draft') + ->orWhere('status', 'enrolled') + ->groupEnd() ->set(array('status'=>'enrolled')) ->update(); + //update Employee table + $this->employeeModel->where('emp_code', $emp_code) + ->where('id', $empIdsFromPolicyData) + ->where('client_id', $client_id) + ->where('is_active', 1) + ->groupStart() + ->where('emp_status', 'draft') + ->orWhere('emp_status', 'enrolled') + ->groupEnd() + ->set(['emp_status' => 'enrolled']) + ->update(); + } - + $find = $this->employeeModel->getEmpFamilybyEmpCode(client_policy_id: $value,emp_code: $emp_code,client_id: $client_id,emp_status:['draft','enrolled'],policy_status:['draft','enrolled']); if(count($find) > 0){ $array_list[] = $find; } - } + }else { $this->myLogger->logme("error", 'client policy id = '.$value.' is not open for enrollment');} } - //update Employee table - $this->employeeModel->where('emp_code', $emp_code)->where('client_id', $client_id)->where('is_active', 1) - ->groupStart() - ->where('emp_status', 'draft') - ->orWhere('emp_status', 'enrolled') - ->groupEnd() - ->set(['emp_status' => 'enrolled']) - ->update(); + $notification = $this->notificationModel->where('client_id' ,$client_id)->where('template_name', 'member_review_and_summary_mail')->first(); - if (isset($notification) && $notification['enabled'] == 1) { + if (isset($notification) && $notification['enabled'] == 1 && count($array_list)) { $params ['array_list'] = $array_list; $params ['client_policy_id'] = $client_policy_id; $params ['emp_code'] = $emp_code; @@ -2328,7 +2354,8 @@ class EmployeeRestController extends AdminController { try { - $clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id'))->findAll(); + $clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id')) + ->where('open_for_enrollment',1)->findAll(); if(count($clientPolicy)) { @@ -2990,6 +3017,19 @@ class EmployeeRestController extends AdminController return false; } } + + + public function findThePolicyIsOpenForEnrollment($plicy_id) + { + + $policy = $this->clientPolicyModel->where('id',$plicy_id)->where('open_for_enrollment',1)->find(); + + if($policy) + return true; + else + return false; + + }