diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index bada67a..172caad 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -240,7 +240,19 @@ class RestAuthenticationController extends AdminController ->whereIn('EP.status', ['draft', 'enrolled']) ->first(); } else { - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->where('employees.otp', $otp) + ->orderBy('id', 'desc') + ->first(); } } @@ -263,7 +275,7 @@ class RestAuthenticationController extends AdminController $result = JWTToken::encode($employeeData); if(isset($this->request->getJSON()->otp)){ - $this->employeeModel->where('email_corporate', $email_id)->where('otp', $otp)->where('relationship', 'self')->set(['otp'=>null])->update(); + $this->employeeModel->where('id', $employeeData['id'])->where('otp', $otp)->where('relationship', 'self')->set(['otp'=>null])->update(); } // Call the third-party API function @@ -486,9 +498,31 @@ class RestAuthenticationController extends AdminController $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; if (isset($mobile_number)) { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->orderBy('id', 'desc') + ->first(); } else { - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->orderBy('id', 'desc') + ->first(); } $mpin = $this->request->getJSON()->mpin; @@ -533,11 +567,34 @@ class RestAuthenticationController extends AdminController $old_mpin = $this->request->getJSON()->old_mpin; $mpin = $this->request->getJSON()->new_mpin; - if (isset($mobile_number)) - { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); - }else{ - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + if (isset($mobile_number)) { + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->where('employees.mpin', $old_mpin) + ->orderBy('id', 'desc') + ->first(); + } else { + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->where('employees.mpin', $old_mpin) + ->orderBy('id', 'desc') + ->first(); } @@ -573,9 +630,31 @@ class RestAuthenticationController extends AdminController $mpin = $this->request->getJSON()->mpin; if (isset($mobile_number)) { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->orderBy('id', 'desc') + ->first(); } else { - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->orderBy('id', 'desc') + ->first(); } if ($employeeData && $mpin == $employeeData["mpin"]) { @@ -621,9 +700,31 @@ class RestAuthenticationController extends AdminController if (isset($mobile_number)) { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->orderBy('id', 'desc') + ->first(); }else{ - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + $employeeData = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->orderBy('id', 'desc') + ->first(); } if ($employeeData && $employeeData["mpin"] != null) { @@ -664,15 +765,29 @@ class RestAuthenticationController extends AdminController if ($mobile_number) { log_message('info', 'Looking up employee by mobile number: ' . $mobile_number); $employeeData = $this->employeeModel - ->where('mobile', $mobile_number) - ->where('relationship', 'self') - ->first(); + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.mobile', $mobile_number) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->orderBy('id', 'desc') + ->first(); } else { log_message('info', 'Looking up employee by email: ' . $email_id); $employeeData = $this->employeeModel - ->where('email_corporate', $email_id) - ->where('relationship', 'self') - ->first(); + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.email_corporate', $email_id) + ->where('employees.relationship', 'Self') + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['draft', 'enrolled']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['draft', 'enrolled']) + ->orderBy('id', 'desc') + ->first(); } // Step 3: Found employee