diff --git a/app/Config/Routes.php b/app/Config/Routes.php index de19fd7a..a6cef1ed 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -358,7 +358,8 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('getPolicyTypeFields', 'LeadsController::getPolicyTypeFields'); $routes->get('removeMultiFile', 'LeadsController::removeMultiFile'); $routes->get('removeInstallments', 'LeadsController::removeInstallments'); - $routes->get('constructHrAccessData', 'ClientController::constructHrAccessData'); + $routes->get('viewHrAccessData', 'ClientController::viewHrAccessData'); + $routes->post('saveHrAccessData', 'ClientController::saveHrAccessData'); }); $routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail"); @@ -487,6 +488,7 @@ $routes->group("/api", ["filter" => "authJWT"], function ($routes) { $routes->post("employeeRest/saveMpin", "RestAuthenticationController::saveMpin"); $routes->post("employeeRest/updateMpin", "RestAuthenticationController::updateMpin"); +$routes->post("employeeRest/getPostEmployeeDataForAuth", "RestAuthenticationController::getPostEmployeeDataForAuth"); $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { @@ -542,6 +544,8 @@ $routes->get("getEmployeeActiveOrInactivePolicy", "EmployeeRestController::getEm $routes->get("sendPushNotification", "EmployeeRestController::sendPushNotification"); $routes->post("sendEmail", "EmployeeRestController::send_email"); $routes->get("getPolicyLevelEmployeeSummaryData", "EmployeeRestController::getPolicyLevelEmployeeSummaryData"); +$routes->get("cdTransactionData", "EmployeeRestController::cdTransactionData"); +$routes->match( ['get', 'post'], 'claimsSearch','EmployeeRestController::claimsSearch'); $routes->get("getBackToEnrolledDetails", "EmployeeRestController::getBackToEnrolledDetails"); diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d9a89de8..e8cb43c7 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2316,7 +2316,7 @@ class EmployeeRestController extends AdminController - $ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type, client_policy.policy_no as policy_no, client_policy.insurer_id as insurer_id ') + $ClientPolicyData = $this->clientPolicyModel->select('client_policy.id as client_policy_id , client_policy.client_id as client_id, client_policy.policy_type_id as policy_type_id, client_policy.is_addon as is_addon , client_policy.open_for_enrollment as OpenForEnrollment , client_policy.inception_type as inception_type, client_policy.policy_no as policy_no, client_policy.insurer_id as insurer_id, DATE_FORMAT(client_policy.policy_end_date, "%d-%m-%Y") AS policy_expiry_date ') ->where('client_policy.client_id', $this->request->getGet('client_id') ) ->where('client_policy.client_branch_id', $this->request->getGet('client_branch_id') ) ->where('client_policy.is_active', 1 ) @@ -2552,12 +2552,16 @@ class EmployeeRestController extends AdminController 'tm.awb_no_courier_name', 'tm.non_id_reason', 'tm.pay_initiate_date', - 'tm.approved_description' + 'tm.approved_description', + 'pt.policy_type as policy_type', + 'cp.policy_no as client_policy_no', ]); $builder->join('insurers i', 'i.id = tm.insurer_id AND i.is_active = 1', 'left'); $builder->join('clients c', 'c.id = tm.client_id AND c.is_active = 1', 'left'); $builder->join('ticket_claim_status tcs', 'tcs.id = tm.claim_status_id AND tcs.is_active = 1', 'left'); + $builder->join('client_policy cp', 'tm.client_policy_id = cp.id', 'left'); + $builder->join('policy_type pt', 'cp.policy_type_id = pt.id', 'left'); $builder->where('tm.is_active', 1); diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 59a9dea4..56f7f1d0 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -1280,8 +1280,8 @@ class LeadsController extends BaseController 'No of Employees at Inception' => $rfq_data['incept_emp_count'], 'Total Sum Insured at Inception ' => $rfq_data['total_si_at_incept'], 'Policy Period' => !empty($rfq_data['policy_start_date']) && !empty($rfq_data['policy_end_date']) ? date('d-m-Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d-m-Y', strtotime($rfq_data['policy_end_date'])) : "To be decided", - 'Insurer' => $rfq_data['insurer_name'] ?? " - ", - 'TPA' => $rfq_data['tpa_name'] ?? " - ", + // 'Insurer' => $rfq_data['insurer_name'] ?? " - ", + // 'TPA' => $rfq_data['tpa_name'] ?? " - ", 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "", ]; } @@ -1322,11 +1322,11 @@ class LeadsController extends BaseController 'No of Employees at Renewal' => $rfq_data['renewal_emp_count'], 'Total Sum Insured at Renewal ' => $rfq_data['total_si_at_renewal'], 'Policy Period' => !empty($rfq_data['policy_start_date']) && !empty($rfq_data['policy_end_date']) ? date('d-m-Y', strtotime($rfq_data['policy_start_date'])) . ' to ' . date('d-m-Y', strtotime($rfq_data['policy_end_date'])) : "To be decided", - 'Insurer' => $rfq_data['insurer_name'] ?? " - ", - 'TPA' => $rfq_data['tpa_name'] ?? " - ", + // 'Insurer' => $rfq_data['insurer_name'] ?? " - ", + // 'TPA' => $rfq_data['tpa_name'] ?? " - ", 'Policy Type' => $this->leadType[$rfq_data['lead_type']] ?? "", 'Existing Insurer' => $rfq_data['insurer_name'], - 'TPA ' => $rfq_data['tpa_name'], + // 'TPA ' => $rfq_data['tpa_name'], ]; } } diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 04e15dfb..2e234f5c 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -22,6 +22,7 @@ use App\Models\EmployeeModel; use App\Models\AuthHistoryModel; use App\Models\LevelContactModel; use App\Models\HRAccessControlModel; +use App\Models\ClientModel; use Firebase\JWT\JWT; // require_once('../vendor/autoload.php'); @@ -37,6 +38,7 @@ class RestAuthenticationController extends AdminController protected $authHistoryModel; protected $hrModel; protected $hrAccessControlModel; + protected $clientModel; public function __construct() @@ -48,6 +50,7 @@ class RestAuthenticationController extends AdminController $this->authHistoryModel = new AuthHistoryModel(); $this->hrModel = new LevelContactModel(); $this->hrAccessControlModel = new HRAccessControlModel(); + $this->clientModel = new ClientModel(); } @@ -103,6 +106,7 @@ class RestAuthenticationController extends AdminController } } catch (\Throwable $th) { + $this->myLogger->logme("error", ($th->getMessage().' --- '.$th->getLine())); return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } @@ -110,10 +114,13 @@ class RestAuthenticationController extends AdminController public function verifyEmployeeWithEmailId() { try { + + log_message('error', json_encode($this->request->getJSON())); $email = $this->request->getJSON()->email; + $client_id = $this->request->getJSON()->client_id ?? null; - $employeeData = $this->employeeModel->select(' + $builder = $this->employeeModel->select(' employees.relationship, EP.employee_id, employees.client_id, @@ -124,19 +131,38 @@ class RestAuthenticationController extends AdminController ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner') ->where('employees.is_active', 1) ->where('employees.relationship', 'Self') - ->where('employees.emp_status !=', 'truncated') + ->whereIn('employees.emp_status', ['active', 'expired']) ->where('employees.email_corporate', $email) ->where('EP.is_active', 1) - ->whereIn('EP.status', ['active', 'expired']) - ->first(); + ->whereIn('EP.status', ['active', 'expired']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $builder->orderBy('employees.id', 'desc'); + $employeeData = $builder->first(); if (isset($employeeData['employee_id'])) { $otp = random_int(100000, 999999); - $update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'Self') - ->where('is_active', 1)->set(array('otp' => $otp)) - ->update(); + // $update = $this->employeeModel->where('email_corporate', $email)->where('relationship', 'Self') + // ->where('is_active', 1)->set(array('otp' => $otp)) + // ->update(); + + $builder = $this->employeeModel + ->where('email_corporate', $email) + ->where('relationship', 'Self') + ->where('is_active', 1) + ->where('id', $employeeData['employee_id']); + + if (!empty($client_id)) { + $builder->where('client_id', $client_id); + } + + $update = $builder->set(['otp' => $otp])->update(); + if ($update) { $common = [ @@ -164,11 +190,14 @@ class RestAuthenticationController extends AdminController $result = ['user_verification' => false, 'message' => "Verification failed , try again"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } + } else { $result = ['user_verification' => false, 'message' => "User not found"]; return $this->respond(['status' => 'failed', 'code' => 404, 'data' => $result], 200); } + } catch (\Throwable $th) { + $this->myLogger->logme("error", ($th->getMessage().' --- '.$th->getLine())); return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500); } } @@ -178,53 +207,163 @@ class RestAuthenticationController extends AdminController $email = $this->request->getJSON()->email; $otp = $this->request->getJSON()->otp; - - $this->employeeModel->where('email_corporate', $email)->where('relationship', 'Self') - ->where('is_active', 1)->set(array('otp' => $otp)) - ->update(); + $client_id = $this->request->getJSON()->client_id ?? null; + $employee_id = $this->request->getJSON()->employee_id ?? null; + + $builder = $this->employeeModel + ->where('email_corporate', $email) + ->where('relationship', 'Self') + ->where('is_active', 1); + + if (!empty($client_id)) { + $builder->where('client_id', $client_id); + } + + if (!empty($employee_id)) { + $builder->where('id', $employee_id); + } + + $builder->set(['otp' => $otp])->update(); + return true; } + // public function updateEmpMPIN() + // { + // $requestData = $this->request->getJSON(); + // print_r($requestData); die; + // $mobile_number = $requestData->mobile_number ?? null; + // $email_id = $requestData->email_id ?? null; + // $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null; + // $old_mpin = $requestData->old_mpin ?? null; + // $is_mpin_skipped = $requestData->is_mpin_skipped ?? null; + // $is_biometric_enabled = $requestData->is_biometric_enabled ?? null; + + // if (!$new_mpin) { + // return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']); + // } + + // $query = $this->employeeModel->where('relationship', 'self'); + + // if ($mobile_number) { + // $query->where('mobile', $mobile_number); + // } elseif ($email_id) { + // $query->where('email_corporate', $email_id); + // } else { + // return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']); + // } + + // if (!empty($old_mpin)) { + // $query->where('mpin', $old_mpin); + // } + + // // Fetch employee data + // $employeeData = $query->first(); + + // if (!$employeeData) { + // return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']); + // } + + // if(!empty($is_mpin_skipped) && !empty($is_biometric_enabled)){ + // $mpin_data_to_updata = [ + // 'mpin' => $new_mpin, + // 'is_mpin_skipped' => $is_mpin_skipped, + // 'is_biometric_enabled' => $is_biometric_enabled + // ]; + // }else{ + // $mpin_data_to_updata = ['mpin' => $new_mpin]; + // } + + // // Update MPIN + // $updated = $this->employeeModel->update($employeeData['id'], $mpin_data_to_updata); + + // return true; + // } + public function updateEmpMPIN() { - $requestData = $this->request->getJSON(); - $mobile_number = $requestData->mobile_number ?? null; - $email_id = $requestData->email_id ?? null; - $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null; - $old_mpin = $requestData->old_mpin ?? null; - - if (!$new_mpin) { - return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']); + try { + log_message('info', 'MPIN update request received.'); + + $requestData = $this->request->getJSON(); + log_message('debug', 'Request data: ' . json_encode($requestData)); + + $mobile_number = $requestData->mobile_number ?? null; + $email_id = $requestData->email_id ?? null; + $new_mpin = $requestData->new_mpin ?? $requestData->mpin ?? null; + $old_mpin = $requestData->old_mpin ?? null; + $is_mpin_skipped = $requestData->is_mpin_skipped ?? null; + $is_biometric_enabled = $requestData->is_biometric_enabled ?? null; + + if (!$new_mpin) { + log_message('warning', 'MPIN is missing.'); + return $this->response->setJSON(['status' => false, 'message' => 'MPIN is required.']); + } + + $query = $this->employeeModel->where('relationship', 'self'); + log_message('info', 'Query initialized with relationship=self'); + + if ($mobile_number) { + $query->where('mobile', $mobile_number); + log_message('info', "Filtering by mobile number: {$mobile_number}"); + } elseif ($email_id) { + $query->where('email_corporate', $email_id); + log_message('info', "Filtering by email ID: {$email_id}"); + } else { + log_message('warning', 'Neither mobile number nor email ID provided.'); + return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']); + } + + if (!empty($old_mpin)) { + $query->where('mpin', $old_mpin); + log_message('info', "Verifying old MPIN: {$old_mpin}"); + } + + $employeeData = $query->first(); + log_message('debug', 'Employee lookup result: ' . json_encode($employeeData)); + + if (!$employeeData) { + log_message('warning', 'Employee not found or invalid old MPIN.'); + return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']); + } + + $mpin_data_to_update = ['mpin' => $new_mpin]; + + if ($is_mpin_skipped != null && $is_biometric_enabled != null) { + $mpin_data_to_update['is_mpin_skipped'] = $is_mpin_skipped; + $mpin_data_to_update['is_biometric_enabled'] = $is_biometric_enabled; + log_message('info', 'Updating MPIN, MPIN skip flag, and biometric flag.'); + } else { + log_message('info', 'Updating MPIN only.'); + } + + $updated = $this->employeeModel->update($employeeData['id'], $mpin_data_to_update); + + if ($updated) { + log_message('info', "MPIN updated successfully for employee ID: {$employeeData['id']}"); + return $this->response->setJSON([ + 'status' => true, + 'message' => 'MPIN updated successfully.' + ]); + } else { + log_message('error', "Failed to update MPIN for employee ID: {$employeeData['id']}"); + return $this->response->setJSON([ + 'status' => false, + 'message' => 'Failed to update MPIN.' + ]); + } + } catch (\Exception $e) { + log_message('critical', 'Exception in updateEmpMPIN: ' . $e->getMessage()); + return $this->response->setJSON([ + 'status' => false, + 'message' => 'Unexpected error occurred.', + 'error' => $e->getMessage() + ]); } - - $query = $this->employeeModel->where('relationship', 'self'); - - if ($mobile_number) { - $query->where('mobile', $mobile_number); - } elseif ($email_id) { - $query->where('email_corporate', $email_id); - } else { - return $this->response->setJSON(['status' => false, 'message' => 'Mobile number or Email ID is required.']); - } - - if (!empty($old_mpin)) { - $query->where('mpin', $old_mpin); - } - - // Fetch employee data - $employeeData = $query->first(); - - if (!$employeeData) { - return $this->response->setJSON(['status' => false, 'message' => 'Employee not found or invalid MPIN.']); - } - - // Update MPIN - $updated = $this->employeeModel->update($employeeData['id'], ['mpin' => $new_mpin]); - - return true; } + @@ -237,6 +376,7 @@ class RestAuthenticationController extends AdminController $otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null; $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; + $client_id = $this->request->getJSON()->client_id ?? null; if (isset($this->request->getJSON()->login_by_hr)) { @@ -244,9 +384,41 @@ class RestAuthenticationController extends AdminController }else{ if (isset($mobile_number)) { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->where('emp_status !=', 'truncated')->where('is_active', 1)->first(); + $builder = $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', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->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(); + $builder = $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', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->where('otp', $otp); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); } } @@ -268,7 +440,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(); } return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); @@ -504,11 +676,43 @@ class RestAuthenticationController extends AdminController $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; + $client_id = $this->request->getJSON()->client_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(); + $builder = $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', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.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(); + $builder = $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', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); } $mpin = $this->request->getJSON()->mpin; @@ -541,6 +745,7 @@ class RestAuthenticationController extends AdminController } } catch (\Throwable $th) { + $this->myLogger->logme("error", ($th->getMessage().' --- '.$th->getLine())); return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } @@ -553,15 +758,54 @@ class RestAuthenticationController extends AdminController $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; $old_mpin = $this->request->getJSON()->old_mpin; $mpin = $this->request->getJSON()->new_mpin; + $client_id = $this->request->getJSON()->client_id ?? null; - 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(); + // }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(); + $builder = $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', ['active']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->where('employees.mpin', $old_mpin); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + + } else { + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('mpin', $old_mpin)->where('relationship', 'self')->first(); + $builder = $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', ['active']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->where('employees.mpin', $old_mpin); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); } - if ($employeeData) { $id= $employeeData["id"]; @@ -581,49 +825,164 @@ class RestAuthenticationController extends AdminController } } catch (\Throwable $th) { + $this->myLogger->logme("error", ($th->getMessage().' --- '.$th->getLine())); return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500); } } + // public function verifyMpin() + // { + // try { + + // $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; + // $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; + // $mpin = $this->request->getJSON()->mpin; + // if (isset($mobile_number)) + // { + // // $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', ['active']) + // ->where('employees.is_active', 1) + // ->whereIn('employees.emp_status', ['active']) + // ->get(); + // }else{ + // // $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('employee_polices.is_active', 1) + // ->whereIn('employee_polices.status', ['active']) + // ->where('employees.is_active', 1) + // ->whereIn('employees.emp_status', ['active']) + // ->where("employees.relationship", "Self") // RAW SQL condition + // ->first(); + + // } + // if ($employeeData && $mpin == $employeeData["mpin"]) { + + // $auth = HttpRequestHelper::getRequestInfo(); + // if ($auth) { + // $data = [ + // 'user_id' => $employeeData['id'], + // 'user_type' => 'employee', + // 'ip' => $auth['ip'], + // 'platform' => $auth['platform'], + // 'broswer' => $auth['browser'], + // ]; + + // $authdata= $this->authHistoryModel->insert($data); + + // } + + // $result = JWTToken::encode($employeeData); + // // $result = $employeeData; + // return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + // } else { + // return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP"],200); + // } + // } catch (\Exception $e) { + // return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); + // } + // } + public function verifyMpin() { try { + $requestData = $this->request->getJSON(true); - $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; - $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; - $mpin = $this->request->getJSON()->mpin; - if (isset($mobile_number)) - { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); - }else{ - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + $mobile_number = $requestData['mobile_number'] ?? null; + $email_id = $requestData['email_id'] ?? null; + $mpin = $requestData['mpin'] ?? null; + $client_id = $requestData['client_id'] ?? null; + // print_r($mpin); + + if (!$mpin) { + return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'MPIN is required'], 400); } - if ($employeeData && $mpin == $employeeData["mpin"]) { - $auth = HttpRequestHelper::getRequestInfo(); - if ($auth) { - $data = [ - 'user_id' => $employeeData['id'], - 'user_type' => 'employee', - 'ip' => $auth['ip'], - 'platform' => $auth['platform'], - 'broswer' => $auth['browser'], - ]; + if ($mobile_number) { - $authdata= $this->authHistoryModel->insert($data); - + $builder = $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', ['active']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); } + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); - $result = JWTToken::encode($employeeData); - // $result = $employeeData; - return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + } elseif ($email_id) { + + $builder = $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', ['active']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + } else { - return $this->respond(['status' => 'failed','code' => 404,'data' => "Invalid OTP"],200); + return $this->respond(['status' => 'failed', 'code' => 400, 'data' => 'Mobile number or Email ID is required'], 400); + } + + // print_r($employeeData); die; + + if ($employeeData && isset($employeeData['mpin']) && $mpin === $employeeData['mpin']) { + + $auth = HttpRequestHelper::getRequestInfo(); + if ($auth) { + $this->authHistoryModel->insert([ + 'user_id' => $employeeData['id'], + 'user_type' => 'employee', + 'ip' => $auth['ip'], + 'platform' => $auth['platform'], + 'broswer' => $auth['browser'], // Note: typo in 'broswer' retained if it's your actual DB field + ]); + } + + $token = JWTToken::encode($employeeData); + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'data' => $token + ], 200); + } else { + return $this->respond([ + 'status' => 'failed', + 'code' => 404, + 'data' => 'Invalid MPIN' + ], 200); } } catch (\Exception $e) { - return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); + $this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine())); + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'data' => $e->getMessage() + ], 500); } } @@ -633,15 +992,45 @@ class RestAuthenticationController extends AdminController $mobile_number = isset($this->request->getJSON()->mobile_number) ? $this->request->getJSON()->mobile_number : null; $email_id = isset($this->request->getJSON()->email_id) ? $this->request->getJSON()->email_id : null; // $mpin = $this->request->getJSON()->mpin; + $client_id = $this->request->getJSON()->client_id ?? null; + if (isset($mobile_number)) { - $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); - }else{ - $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); - } - + // $employeeData = $this->employeeModel->where('mobile', $mobile_number)->where('relationship', 'self')->first(); + $builder = $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', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']); + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + + }else{ + // $employeeData = $this->employeeModel->where('email_corporate', $email_id)->where('relationship', 'self')->first(); + $builder = $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', ['active', 'expired']) + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active', 'expired']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + } if ($employeeData && $employeeData["mpin"] != null) { @@ -651,6 +1040,7 @@ class RestAuthenticationController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => "Mpin - not found", 'Mpin' =>null],200); } } catch (\Exception $e) { + $this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine())); return $this->respond(['status' => 'failed','code' => 500,'data' => $e->getMessage()],500); } } @@ -663,6 +1053,7 @@ class RestAuthenticationController extends AdminController $json = $this->request->getJSON(); $mobile_number = $json->mobile_number ?? null; $email_id = $json->email_id ?? null; + $client_id = $json->client_id ?? null; log_message('info', 'Received input - Mobile: ' . var_export($mobile_number, true) . ', Email: ' . var_export($email_id, true)); @@ -678,19 +1069,46 @@ class RestAuthenticationController extends AdminController // Step 2: Fetch employee data 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(); + $builder = $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) + ->where('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->where('employees.emp_status', ['active']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.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(); + $builder = $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) + ->where('employee_polices.status', ['active']) + ->where('employees.is_active', 1) + ->where('employees.emp_status', ['active']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); } + log_message('info', '$employeeData : ' . json_encode($employeeData)); + // Step 3: Found employee if (!empty($employeeData)) { log_message('info', 'Employee found: ID = ' . $employeeData['id']); @@ -728,7 +1146,7 @@ class RestAuthenticationController extends AdminController log_message('warning', 'Employee not found locally. Falling back to third-party API.'); return $this->respond(['status' => 'failed','code' => 404,'data' => "Employee not found"],200); } } catch (\Throwable $e) { - log_message('error', 'Exception in forgotMPIN(): ' . $e->getMessage()); + $this->myLogger->logme("error", ($e->getMessage().' --- '.$e->getLine())); return $this->respond([ 'status' => 'failed', 'code' => 500, @@ -763,6 +1181,81 @@ class RestAuthenticationController extends AdminController return redirect()->to($url); } + public function getPostEmployeeDataForAuth() + { + $params = $this->request->getJSON(true); + // print_r( $params); die; + + $mobile_number = $params['mobile_number'] ?? null; + $email_id = $params['email_id'] ?? null; + $otp = $params['otp'] ?? null; + $old_mpin = $params['old_mpin'] ?? null; + + if (empty($mobile_number) && empty($email_id)) { + return $this->respond([ + 'status' => 'failed', + 'message' => 'Mobile number or Email ID is required.', + 'data' => [], + ], 400); + } + + if (!empty($mobile_number)) { + + $builder = $this->employeeModel + ->select('employees.id as employee_id, employees.*') + ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner') + ->where('employees.is_active', 1) + ->where("TRIM(employees.relationship) = 'self'", null, false) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->where('employees.mobile', $mobile_number) + ->where('EP.is_active', 1) + ->whereIn('EP.status', ['active', 'expired']); + + if (!empty($old_mpin)) { + $builder->where('employees.mpin', $old_mpin); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + + } else { + $builder = $this->employeeModel + ->select('employees.id as employee_id, employees.*') + ->join('employee_polices EP', 'EP.employee_id = employees.id', 'inner') + ->where('employees.is_active', 1) + ->where("TRIM(employees.relationship) = 'self'", null, false) + ->whereIn('employees.emp_status', ['active', 'expired']) + ->where('employees.email_corporate', $email_id) + ->where('EP.is_active', 1) + ->whereIn('EP.status', ['active', 'expired']); + + if (!empty($otp)) { + $builder->where('employees.otp', $otp); + } + + if (!empty($old_mpin)) { + $builder->where('employees.mpin', $old_mpin); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + } + + if ($employeeData) { + + $client_data = $this->clientModel->where('is_active', 1)->where('id', $employeeData['client_id'])->first(); + $employeeData['client_short_name'] = $client_data['short_name']; + + return $this->respond([ + 'status' => 'success', + 'data' => $employeeData, + ], 200); + } + + return $this->respond([ + 'status' => 'failed', + 'message' => 'No employee found.', + 'data' => [], + ], 404); + } diff --git a/app/Models/ClientPolicyModel.php b/app/Models/ClientPolicyModel.php index 5c43b52e..f571659e 100755 --- a/app/Models/ClientPolicyModel.php +++ b/app/Models/ClientPolicyModel.php @@ -249,8 +249,19 @@ class ClientPolicyModel extends Model } - public function getDepositData($clientId, $insurerId, $cd_ac_pk = null) - { + public function getDepositData($clientId, $insurerId, $cd_ac_pk = null, $subTypeOptions = null) + { + + if($subTypeOptions != null){ + $caseSql = "CASE cash_deposit.sub_type"; + foreach ($subTypeOptions as $key => $label) { + $caseSql .= " WHEN {$key} THEN " . $this->db->escape($label); + } + $caseSql .= " ELSE 'Unknown' END AS sub_type_text"; + }else{ + $caseSql = ""; + } + // Fetch the deposit data based on client and insurer IDs $query = $this->db->table('cash_deposit') ->select('cash_deposit.*') @@ -260,6 +271,7 @@ class ClientPolicyModel extends Model // ->select('policies.name as policy_name') ->select('policy_type.policy_type') ->select('user_profiles.first_name as username') + ->select($caseSql) ->join('user_profiles', 'user_profiles.id = cash_deposit.created_by', 'left') ->join('insurers', 'insurers.id = cash_deposit.insurer_id', 'left') ->join('clients', 'clients.id = cash_deposit.client_id', 'left') @@ -269,7 +281,8 @@ class ClientPolicyModel extends Model ->join('policy_type', 'policy_type.id = client_policy.policy_type_id', 'left') ->where('cash_deposit.client_id', $clientId) ->where('cash_deposit.insurer_id', $insurerId) - ->where('cash_deposit.is_active', 1); + ->where('cash_deposit.is_active', 1) + ->where('cd_master.is_active', 1); // ->where('cash_deposit.cd_ac_pk = cd_master.id') if(!empty($cd_ac_pk)){ $query->where('cash_deposit.cd_ac_pk', $cd_ac_pk); @@ -342,15 +355,32 @@ class ClientPolicyModel extends Model public function getDepositlistsummary($id) { - return $this->db->table('cash_deposit') - ->select('insurer_id, cd_ac_pk') - ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance') - ->where('client_id', $id) - ->where('is_active', 1) - ->groupBy('insurer_id') - // ->groupBy('cd_ac_pk') - ->get() - ->getResult(); + // return $this->db->table('cash_deposit') + // ->select('insurer_id, cd_ac_pk, balance') + // // ->select('SUM(CASE WHEN transaction_type = "Credit" THEN amount ELSE -amount END) AS balance') + // ->where('client_id', $id) + // ->where('is_active', 1) + // ->orderBy('id', 'desc') + // ->groupBy('insurer_id') + // // ->groupBy('cd_ac_pk') + // ->get() + // ->getResult(); + + $sql = " + SELECT cd.insurer_id, cd.cd_ac_pk, cd.balance + FROM cash_deposit cd + INNER JOIN ( + SELECT insurer_id, MAX(id) AS max_id + FROM cash_deposit + WHERE client_id = ? + AND is_active = 1 + GROUP BY insurer_id + ) latest ON cd.insurer_id = latest.insurer_id AND cd.id = latest.max_id + ORDER BY cd.id DESC + "; + + return $this->db->query($sql, [$id])->getResult(); + } diff --git a/app/Models/EmployeeModel.php b/app/Models/EmployeeModel.php index bb62234e..1bc55f06 100755 --- a/app/Models/EmployeeModel.php +++ b/app/Models/EmployeeModel.php @@ -271,6 +271,8 @@ class EmployeeModel extends Model ->join('employee_polices', 'employees.id = employee_polices.employee_id', 'left') ->where('employees.is_active', 1) ->where('employee_polices.is_active', 1) + ->where('employees.emp_status', "active") + ->where('employee_polices.status', "active") ->where('employees.emp_code', $emp_code); if(!empty($client_id)){ diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index f6ff81ed..ec4b9222 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -224,7 +224,28 @@ class EmployeePolicyModel extends Model public function getEmployeePolicy($client_id = 0, $policy_id = 0, $status = [], $branch_id = 0, $emp_code = "", $emp_name = "") { // dd($status); - + $ecard_download_link = " + CASE + WHEN + LOWER(emp.relationship) = 'self' AND + employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '' AND + employee_polices.uhid IS NOT NULL AND employee_polices.uhid != '' + THEN + CASE + WHEN + (employee_polices.tpa_id IS NOT NULL AND employee_polices.tpa_id != '') + AND + (employee_polices.uhid IS NOT NULL AND employee_polices.uhid != '') + THEN + CONCAT('" . base_url('download-e-card/') . "', employee_polices.rand_string, '/1') + ELSE + null + END + ELSE + NULL + END AS ecard_download_link + "; + $result = $this->select([ 'employee_polices.*', 'policy_type.policy_type as policy_name', @@ -257,6 +278,7 @@ class EmployeePolicyModel extends Model 'client_branch.branch_code as client_branch_code', 'cp.policy_no', 'cp.policy_type_id', + $ecard_download_link ]) ->join('employees emp', 'employee_polices.employee_id = emp.id') ->join('client_policy cp', 'employee_polices.client_policy_id = cp.id') //cp - client policy @@ -603,6 +625,7 @@ class EmployeePolicyModel extends Model $insurer_or_tpa = $ref_data['insurer_or_tpa']; $endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "AND (a.endorsement_id IS NOT NULL OR a.endorsement_id != '')" : "AND (a.endorsement_id IS NULL OR a.endorsement_id = '')"; + $subquery_endorsement_condition = "{$insurer_or_tpa}" === 'tpa' ? "WHERE (endorsement_id IS NOT NULL OR endorsement_id != '')" : "WHERE (endorsement_id IS NULL OR endorsement_id = '')"; $query = $this->db->query(" @@ -676,6 +699,7 @@ class EmployeePolicyModel extends Model CAST(MAX(CASE WHEN field_name = 'premium' THEN old_value END) AS DECIMAL(10,2)) AS old_si_premium, MAX(CASE WHEN field_name = 'si_enhancement_date' THEN new_value END) AS date_of_coverage FROM emp_endorsement + $subquery_endorsement_condition GROUP BY emp_code ) AS sidata ON a.emp_code = sidata.emp_code WHERE employee_polices.client_policy_id = '{$client_policy_id}' diff --git a/app/Models/InsurerModel.php b/app/Models/InsurerModel.php index e24dd00a..dcb7fe8b 100755 --- a/app/Models/InsurerModel.php +++ b/app/Models/InsurerModel.php @@ -47,6 +47,7 @@ class InsurerModel extends Model ->where('client_policy.insurer_id', $insurerId) ->where('client_policy.client_id', $client_id) ->where('cd_master.id = client_policy.cd_ac_pk') + ->where('cd_master.is_active', 1) ->get(); if ($query->resultID->num_rows > 0) { diff --git a/app/Views/policy_grid.php b/app/Views/policy_grid.php index d0e825f6..6626d85e 100755 --- a/app/Views/policy_grid.php +++ b/app/Views/policy_grid.php @@ -92,7 +92,6 @@
- @@ -144,7 +143,7 @@
- + Rename
@@ -191,10 +190,9 @@ $(document).on('click', '.close', function() { var rarc_rate_json_array = []; $(document).on('submit', 'form[id^="GridForm_"]', function(event) { - console.log('submitted function called') - event.preventDefault(); // Prevent the default form submission + console.log('submitted function called') var form = $(this); console.log('form', form) @@ -393,6 +391,8 @@ $('body').on('click', '.btnPolicyModel', function() $("#hidden_unit").val(branch_units[0]); console.log('unit', branch_units[0]); $("#gpa_unit1").val(branch_units[0]); + $("#gpa_unit2").val(branch_units[0]); + $("#gpa_unit3").val(branch_units[0]); } var data_for_the_rack_rate = JSON.parse(res.premiumData) ?? []; var groupedData = groupByRackRateName(data_for_the_rack_rate) ?? []; @@ -747,7 +747,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa var id_var = 'grid_'; - var default_unit = $('#hidden_unit').val(); + var default_unit = $('#hidden_unit').val() ?? ""; var dataIdValue = '' @@ -787,7 +787,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -828,12 +828,12 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
- +
@@ -864,7 +864,7 @@ function addGridHTML(event = false, data = false, ui_type = false, si_or_bp = fa
- +
@@ -1422,16 +1422,16 @@ function appendGridtHtml(ui_type = false, secondary = false, data = false) html = `
- +
- +
- +
@@ -1448,7 +1448,7 @@ function appendGridtHtml(ui_type = false, secondary = false, data = false) html = `
- +
@@ -1482,7 +1482,7 @@ function appendGridtHtml(ui_type = false, secondary = false, data = false)
- +
@@ -3356,7 +3356,6 @@ function appendNewTab(tabNameData = null, data = null) newTabPane.innerHTML = `
- @@ -3407,7 +3406,7 @@ function appendNewTab(tabNameData = null, data = null)
- + Delete Rename
diff --git a/app/Views/ticket_form_handler.php b/app/Views/ticket_form_handler.php index 2b3b700c..c454791f 100644 --- a/app/Views/ticket_form_handler.php +++ b/app/Views/ticket_form_handler.php @@ -43,18 +43,16 @@ -