diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index ee2e072..2245a06 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3308,10 +3308,19 @@ 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 ?? []) == 0){ + return $this->respond(['status' => 'failed','code' => 404, 'message' => 'Client policy not found', 'data' => [] ], 200); + } + + if(in_array($clientPolicy[0]['policy_type_id'], [3,4,5,72])){ + $openForEnrollment = $this->findThePolicyIsOpenForEnrollment($clientPolicy[0]['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) { @@ -3323,6 +3332,11 @@ class EmployeeRestController extends AdminController $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) ->where('is_addon_value', 0 ) ->findAll(); + }else if($clientPolicy[0]['policy_type_id'] == 72)//OPD + { + $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) + ->where('is_addon_value', 0) + ->findAll(); }else if($clientPolicy[0]['policy_type_id'] == 5)//GMC-Parent-Topup { $empData = $this->employeeModel->where('emp_code',$this->request->getGet('emp_code')) @@ -3336,7 +3350,7 @@ class EmployeeRestController extends AdminController $this->employeePolicyModel->where('client_policy_id',$this->request->getGet('client_policy_id') ) ->where('employee_id', $value['id'] ) - ->set(array('is_active'=> 0 )) + ->set(array('is_active'=> 0 , 'status' => 'truncated')) ->update(); } @@ -3371,12 +3385,12 @@ 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); } } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 500); + return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()], 200); } } @@ -4567,10 +4581,17 @@ class EmployeeRestController extends AdminController ( SELECT id FROM client_policy - WHERE policy_type_id in (4, 72) + WHERE policy_type_id = 4 AND base_policy = gmc_client_policy_id LIMIT 1 - ) AS gmc_topup_policy_id + ) AS gmc_topup_policy_id, + + ( + SELECT id FROM client_policy + WHERE policy_type_id = 72 + AND base_policy = gmc_client_policy_id + LIMIT 1 + ) AS opd_topup_policy_id ") ->join('employee_polices', 'employees.id = employee_polices.employee_id') ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id') @@ -4607,6 +4628,7 @@ class EmployeeRestController extends AdminController $policyIds[] = $data['gmc_topup_policy_id']; $policyIds[] = $data['gmc_parent_policy_id']; + $policyIds[] = $data['opd_topup_policy_id'] ?? null; $policyIds[] = $getParentTopUp['gmc_parent_topup_policy_id'] ?? null; return $policyIds; diff --git a/app/Models/UserModel.php b/app/Models/UserModel.php index 49b8440..0541cbf 100755 --- a/app/Models/UserModel.php +++ b/app/Models/UserModel.php @@ -77,7 +77,7 @@ class UserModel extends Model public function getUserByEmail($email){ - $userData = $this->where('email', $email)->get(); + $userData = $this->where('email', $email)->where('is_active', 1)->get(); if ($userData->getNumRows() > 0) { return $userData->getRow(); } else { @@ -87,7 +87,7 @@ class UserModel extends Model public function getUserById($id){ - $userData = $this->where('id', $id)->get(); + $userData = $this->where('id', $id)->where('is_active', 1)->get(); if ($userData->getNumRows() > 0) { return $userData->getRow(); } else {