diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 4ec1f2b..9312886 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3308,10 +3308,26 @@ class EmployeeRestController extends AdminController { try { - $clientPolicy = $this->clientPolicyModel->where('id',$this->request->getGet('client_policy_id')) - ->where('open_for_enrollment',1)->findAll(); + $clientPolicy = $this->clientPolicyModel + ->where('id', $this->request->getGet('client_policy_id')) + ->findAll(); + + if (!count($clientPolicy ?? [])) { + return $this->respond([ + 'status' => 'failed', + 'code' => 404, + 'message' => 'Client policy not found', + 'data' => [] + ], 200); + } + + if(in_array($clientPolicy['policy_type_id'], [3,4,5,72])){ + $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($clientPolicy['base_policy'], $this->request->getGet('emp_code')); + }else{ + $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($this->request->getGet('client_policy_id'), $this->request->getGet('emp_code')); + } - if(count($clientPolicy)) + if($openForEnrollment) { @@ -3371,7 +3387,7 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => 'success','code' => 200,'data' =>[] ], 200); }else{ - return $this->respond(['status' => 'failed','code' => 404,'data' => [] ], 200); + return $this->respond(['status' => 'failed', 'message' => 'Enrollment closed for this policy','code' => 404,'data' => [] ], 200); }