diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a0627f87..fd1f09ca 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -164,6 +164,11 @@ $routes->group("/client", ["filter" => "authMVC"], function ($routes) { $routes->post("edit", "ClientController::editClientKYCInfo"); $routes->get("list/(:any)", "ClientController::getKycDocsById/$1"); $routes->get("delete/(:any)", "ClientController::deleteClientKycDocs/$1"); + + $routes->post("create_2", "ClientController::createClientKYCInfo_2"); + $routes->post("edit_2", "ClientController::editClientKYCInfo_2"); + $routes->post("delete_2", "ClientController::deleteClientKycDocs_2/$1"); + }); $routes->group("premimum", ["filter" => "authMVC"], function ($routes) { @@ -568,10 +573,15 @@ $routes->group("employeeRest", ['filter' => ["appSignature"] ], function ($route $routes->get("getHRAccessData", "RestAuthenticationController::getHRAccessData"); $routes->post("getPostEmployeeDataForAuth", "RestAuthenticationController::getPostEmployeeDataForAuth"); + $routes->post("getRetailUserData", "RestAuthenticationController::getRetailUserData"); $routes->get("getClientDetails", "EmployeeRestController::getClientDetails"); $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage"); + //retail user apis + $routes->post("getVerifiedRetailUserData", "RestAuthenticationController::getVerifiedRetailUserData"); + $routes->post("updateRetailUserAuthDetails", "RestAuthenticationController::updateRetailUserAuthDetails"); + }); $routes->group("employeeRest", ["filter" => ["authJWT"]], function ($routes) { diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index e0a556db..b67ae501 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1005,6 +1005,153 @@ class ClientController extends AdminController + public function createClientKYCInfo_2() + { + $this->myLogger->logme('error', 'create Client kyc function called'); + $data = $this->request->getPost(); + + $uploadedFile = $this->request->getFile('file_name'); + + if ($uploadedFile && $uploadedFile->isValid() && !$uploadedFile->hasMoved()) { + $this->myLogger->logme('info', 'File is valid and ready to move.'); + } else { + $this->myLogger->logme('error', 'File failed validation or was not uploaded.'); + } + + $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; + + $File = file_Upload($uploadedFile, $uploadFilePath); + $this->myLogger->logme('info', 'Result of file_Upload: ' . $File); + unset($data['file_name']); + + if (!empty($File)) { $data['file_name'] = $File; } + + $data['created_by'] = get_session_userid(); + $insert = $this->clientKYCDocsModel->insert($data); + + if ($insert) { + $html = $this->generateKycSingleTable($data['client_id']); + $dropdown = $this->fetch_dropdown($data['client_id']); + return $this->respond(['status' => true, 'code' => 200, 'file_name' => $File, 'html' => $html,'dropdown'=>$dropdown], 200); + } else { + $this->myLogger->logme('error', 'Database insert failed.'); + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to add document'], 200); + } + } + + public function editClientKYCInfo_2() + { + + $kyc_id = $this->request->getPost('id'); + $client_id = $this->request->getPost('client_id'); + $old_file_name = $this->request->getPost('old_file_name'); + $uploadedFile = $this->request->getFile('file_name'); + $new_file_name = null; + $uploadFilePath = WRITEPATH . 'uploads/client_kyc_documents'; + + + if ($uploadedFile && $uploadedFile->isValid() && !$uploadedFile->hasMoved()) { + + + $new_file_name = file_Upload($uploadedFile, $uploadFilePath); + + if (!empty($new_file_name)) { + + $updateData['file_name'] = $new_file_name; + + // Delete the old file from the storage if it exists + // if (!empty($old_file_name)) { + // $old_file_path = $uploadFilePath . '/' . $old_file_name; + // if (file_exists($old_file_path)) { + // unlink($old_file_path); + // // Optionally delete from G-Drive here if applicable + // } + // } + } else { + // New file upload failed + return $this->respond(['status' => false, 'code' => 500, 'message' => 'New file upload failed on server.'], 200); + } + } + + // 2. Perform the database update + if (!empty($updateData)) { + + $updateData['updated_by'] = get_session_userid(); + $update = $this->clientKYCDocsModel->update($kyc_id, $updateData); + $html = $this->generateKycSingleTable($client_id); + $dropdown = $this->fetch_dropdown($client_id); + + if ($update) { + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Document updated successfully.','html' => $html,'dropdown' => $dropdown], 200); + } + } else { + + return $this->respond(['status' => true, 'code' => 200, 'message' => 'No changes detected. Document remains the same.'], 200); + } + + + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Database update failed or record not found.'], 200); + } + + + public function deleteClientKycDocs_2() + { + + $kyc_id = $this->request->getPost('id'); + $client_id = $this->request->getPost('client_id'); + + if (empty($kyc_id)) { + return $this->respond(['status' => false, 'code' => 400, 'message' => 'Missing document ID.'], 200); + } + $updateData['updated_by'] = get_session_userid(); + $updateData['is_active'] = $this->request->getPost('is_active'); + + $delete = $this->clientKYCDocsModel->update($kyc_id, $updateData); + + if ($delete) { + $html = $this->generateKycSingleTable($client_id); + $dropdown = $this->fetch_dropdown($client_id); + return $this->respond(['status' => true, 'code' => 200, 'id' => $kyc_id, 'message' => 'Document successfully deactivated.','html' => $html,'dropdown' => $dropdown], 200); + } else { + return $this->respond(['status' => false, 'code' => 404, 'message' => 'Failed to update record (ID not found or DB error).'], 200); + } + } + + public function fetch_dropdown($client_id){ + + $db = db_connect(); + + + $submitted_ids_subquery = $db->table('client_kyc_documents ckd') + ->select('ckd.kyc_doc_type_id') + ->where('ckd.client_id', $client_id) + ->where('ckd.is_active', 1) + ->getCompiledSelect(); + + + $result = $db->table('kyc_docs kd') + ->select('kd.*') + ->join('clients c', 'kd.kyc_type_id = c.entity_type_id') + ->where('c.id', $client_id) + ->where("kd.kyc_type_id NOT IN ({$submitted_ids_subquery})") + ->groupBy('kd.id') + ->get() + ->getResultArray(); + + + $dropdown = ''; + $dropdown .= ''; + + foreach ($result as $row) { + $dropdown .= ''; + } + + return $dropdown; + } + + public function createClientRelation() { @@ -2361,6 +2508,36 @@ class ClientController extends AdminController } + + public function generateKycSingleTable($client_id) + { + + + $result['ckdlist'] = db_connect()->table('client_kyc_documents ckd') + ->select("ckd.id,ckd.client_id,ckd.kyc_doc_type_id,ckd.file_name,kd.file_name AS kd_docs_name,ckd.other_docs_name,ckd.vehicle_id,ckd.is_active, + CASE + WHEN ckd.kyc_doc_type_id IS NULL + OR ckd.kyc_doc_type_id = 0 + OR ckd.kyc_doc_type_id = '' + THEN ckd.other_docs_name + ELSE kd.file_name + END AS ui_docs_name") + ->join('kyc_docs kd','ckd.kyc_doc_type_id = kd.kyc_type_id','left') + ->where('ckd.client_id',$client_id) + ->where('ckd.is_active',1) + ->groupBy('ckd.id') + ->get() + ->getResultArray(); + + + $result['client_id'] = $client_id; + $table = view('client_kyc_single_table', $result); + + return $table; + // print_r($table); die; + + } + public function getPolicesByInsurerId($id = null) { $this->myLogger->logme('error', 'getPolicesByInsurerId function called'); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index c5581519..986a3fcd 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -5301,6 +5301,15 @@ class EmpDataServiceController extends BaseController $salse_person_id = $lead_data['created_by'] ?? null; } + // get the policy transaction id for client policy id + $policy_transaction_data = $this->policyTransactionModel->where('is_active', 1)->where('TRIM(policy_no)', $policy_data['policy_no'])->where('action_type', 'inception')->first(); + $client_policy_id = null; + if(!empty($policy_transaction_data) && $params['action_type'] != "inception"){ + $client_policy_id = $policy_transaction_data['id'] ?? null; + }else{ + $client_policy_id = $policy_data['id'] ?? null; + } + $policyTransactionData = [ 'issuer' => 2, @@ -5312,7 +5321,7 @@ class EmpDataServiceController extends BaseController 'tpa_id' => $policy_data['tpa_id'] ?? null, 'tpa_branch_id' => $policy_data['tpa_branch_id'] ?? null, 'policy_type_id' => $policy_data['policy_type_id'] ?? null, - 'client_policy_id' => $policy_data['id'] ?? null, + 'client_policy_id' => $client_policy_id, 'policy_no' => $policy_data['policy_no'] ?? null, 'cd_ac_no' => $policy_data['cd_ac_no'] ?? null, 'cd_ac_pk' => $policy_data['cd_ac_pk'] ?? null, diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index 9a4f7414..ca24ec6b 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -548,8 +548,7 @@ class EmployeeController extends AdminController 'file_name' => $file_name, ]; - - $batch_data['policy_issue_date'] = (!empty($policy_issue_date) && strtotime($policy_issue_date) !== false) ? change_date_format($policy_issue_date, 'd/m/Y', 'Y-m-d') : null; + $batch_data['policy_issue_date'] = !empty($policy_issue_date) ? change_date_format($policy_issue_date, 'd/m/Y', 'Y-m-d') : null; if ($actions == 'export') { diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 61e04379..859b51d1 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2820,7 +2820,43 @@ class EmployeeRestController extends AdminController function getEmployeeActiveOrInactivePolicy() - { + { + + // for retail user policy only + $receviedPayload = $this->request->getGet(); + + if( + empty($receviedPayload['client_id']) && + empty($receviedPayload['client_branch_id']) && + empty($receviedPayload['emp_code']) + ){ + + if(!empty($receviedPayload['mobile_no']) || !empty($receviedPayload['email_id'])){ + + $retailUserData = (object) [ + 'id' => null, + 'mobile' => $receviedPayload['mobile_no'], + 'email_id' => $receviedPayload['email_id'] + ]; + + $emp_reatail_policy_data = $this->getEmpRetailPolicy($retailUserData); + + $query = $this->clientModel + ->where('is_active', 1) + ->where('client_type', 2); + + if (!empty($receviedPayload['mobile_no'])) { + $query->where('phone', $receviedPayload['mobile_no']); + } else { + $query->where('email', $receviedPayload['email_id'] ?? null); + } + + $retailClientData = $query->first(); + $wellness_data = ['status' => 'failed','message' => 'Coming soon........!']; + return $this->respond(['status' => 'success', 'code' => 200, 'data' => [], 'emp_name' => $retailClientData['client_name'] ?? "", 'pre_policy_count' => 0, 'retail_policy_data' => $emp_reatail_policy_data, 'wellness_data' => $wellness_data], 200); + } + } + if ($this->request->getGet('type') == 'Active') { $policy_status = 1; $policy_status_key = "Active"; @@ -4648,6 +4684,7 @@ class EmployeeRestController extends AdminController $emp_id = $employeeData->id ?? null; $mobile_number = $employeeData->mobile ?? null; + $email_id = $employeeData->email_id ?? null; $emp_retail_policy_data = []; if ($emp_id != null) { @@ -4678,7 +4715,7 @@ class EmployeeRestController extends AdminController if (!empty($mobile_number)) { $emp_retail_client_data = $this->clientModel ->select(" - $emp_id as emp_id, + '{$emp_id}' AS emp_id, policy_transaction.insurer_id, policy_transaction.policy_type_id, policy_transaction.policy_no, @@ -4696,9 +4733,31 @@ class EmployeeRestController extends AdminController ->where('clients.is_active', 1) ->where('clients.phone', $mobile_number) ->findAll(); + }else { + $emp_retail_client_data = $this->clientModel + ->select(" + '{$emp_id}' AS emp_id, + policy_transaction.insurer_id, + policy_transaction.policy_type_id, + policy_transaction.policy_no, + DATE_FORMAT(policy_transaction.policy_start_date, '%d-%b-%Y') as policy_start_date, + DATE_FORMAT(policy_transaction.policy_end_date, '%d-%b-%Y') as policy_end_date, + policy_type.policy_type, + policy_type.long_name as policy_type_long_name, + insurers.name as insurer_name, + insurers.short_name as insurer_short_name + ") + ->join('policy_transaction', 'policy_transaction.client_id = clients.id') + ->join('insurers', 'policy_transaction.insurer_id = insurers.id') + ->join('policy_type', 'policy_transaction.policy_type_id = policy_type.id') + ->where('policy_transaction.is_active', 1) + ->where('clients.is_active', 1) + ->where('clients.email IS NOT NULL') + ->where('clients.email', $email_id) + ->findAll(); } - // print_r($emp_retail_policy_data); die; + // print_r($this->clientModel->getLastQuery()); die; $complete_emp_retail_policy_data = array_values( array_column( diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php index e288a7a0..cc13b100 100755 --- a/app/Controllers/NotificationController.php +++ b/app/Controllers/NotificationController.php @@ -375,7 +375,7 @@ class NotificationController extends AdminController // Insert file attachment record if ($this->MailAttachmentModel->insert($data)) { // Retrieve active attachments to return in response - $attachment_data = $this->MailAttachmentModel->where('is_active', 1)->findAll(); + $attachment_data = $this->MailAttachmentModel->where('notification_id', $find_notification['id'])->where('is_active', 1)->findAll()??[]; return $this->respond([ 'status' => true, 'code' => 200, diff --git a/app/Controllers/PolicyTransactionController.php b/app/Controllers/PolicyTransactionController.php index e60d0be1..5b348a0f 100644 --- a/app/Controllers/PolicyTransactionController.php +++ b/app/Controllers/PolicyTransactionController.php @@ -994,6 +994,7 @@ $clientController = new ClientController(); $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + // $data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']); $data['entity_type_id'] = $client_data['entity_type_id']; return $this->respondSuccess($insert, "Policy transaction created successfully", $data); @@ -1056,6 +1057,7 @@ $clientController = new ClientController(); $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + // $data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']); $data['entity_type_id'] = $client_data['entity_type_id']; @@ -1624,6 +1626,8 @@ $clientController = new ClientController(); $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + $data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']); + $data['client_kyc_dd_data'] = $clientController->fetch_dropdown($data['client_id']); $data['vehicle_docs'] = $this->clientKYCDocsModel ->where('client_id', $data['client_id']) @@ -1894,6 +1898,7 @@ $clientController = new ClientController(); $data['client_kyc_primary_table'] = $clientController->generateKycPrimaryTable($data['client_id']); $data['client_kyc_other_table'] = $clientController->generateKycOthersTable($data['client_id']); + $data['client_kyc_single_table'] = $clientController->generateKycSingleTable($data['client_id']); $data['vehicle_docs'] = $this->clientKYCDocsModel ->where('client_id', $data['client_id']) diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 4a4b7cbd..b0f56392 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -339,7 +339,7 @@ class RestAuthenticationController extends AdminController public function updateEmpMPIN() { try { - log_message('info', 'MPIN update request received.'); + log_message('error', 'MPIN update request received.'); $requestData = $this->request->getJSON(); log_message('debug', 'Request data: ' . json_encode($requestData)); @@ -361,7 +361,7 @@ class RestAuthenticationController extends AdminController $updated = $this->employeeModel->where('id', $employee_id)->set(['mpin' => $mpin])->update(); if ($updated) { - log_message('info', "MPIN updated successfully for employee ID: {$employee_id}"); + log_message('error', "MPIN updated successfully for employee ID: {$employee_id}"); return $this->response->setJSON([ 'status' => true, 'message' => 'MPIN updated successfully.' @@ -1283,7 +1283,7 @@ class RestAuthenticationController extends AdminController // Step 2: Fetch employee data if ($mobile_number) { - log_message('info', 'Looking up employee by mobile number: ' . $mobile_number); + log_message('error', 'Looking up employee by mobile number: ' . $mobile_number); $builder = $this->employeeModel ->select('employees.*') ->join('employee_polices', 'employees.id = employee_polices.employee_id') @@ -1302,7 +1302,7 @@ class RestAuthenticationController extends AdminController } else { - log_message('info', 'Looking up employee by email: ' . $email_id); + log_message('error', 'Looking up employee by email: ' . $email_id); $builder = $this->employeeModel ->select('employees.*') ->join('employee_polices', 'employees.id = employee_polices.employee_id') @@ -1343,7 +1343,7 @@ class RestAuthenticationController extends AdminController ->update(); if ($updated) { - log_message('info', 'MPIN reset successful for employee ID: ' . $employeeData['id']); + log_message('error', 'MPIN reset successful for employee ID: ' . $employeeData['id']); return $this->respond([ 'status' => 'success', 'code' => 200, @@ -1416,7 +1416,7 @@ class RestAuthenticationController extends AdminController 'status' => 'failed', 'message' => 'Mobile number or Email ID is required.', 'data' => [], - ], 400); + ], 200); } if (!empty($mobile_number)) { @@ -1477,8 +1477,9 @@ class RestAuthenticationController extends AdminController return $this->respond([ 'status' => 'failed', 'message' => 'No employee found.', + 'code' => 404, 'data' => [], - ], 404); + ], 200); } public function logHrActivity() @@ -1775,7 +1776,7 @@ class RestAuthenticationController extends AdminController $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Verified employee found"); - // ✅ Log authentication info + // ✅ Log authentication error $auth = HttpRequestHelper::getRequestInfo(); if ($auth) { $this->authHistoryModel->insert([ @@ -2042,4 +2043,247 @@ class RestAuthenticationController extends AdminController ], 500); } } + + public function getRetailUserData() + { + $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' => [],], 200); + } + + if (!empty($mobile_number)) { + + $builder = $this->clientModel + ->select('clients.*') + ->join('policy_transaction', 'policy_transaction.client_id = clients.id') + ->where('policy_transaction.is_active', 1) + ->where('clients.is_active', 1) + ->where('clients.phone', $mobile_number); + + if (!empty($otp)) { + $builder->where('clients.otp', $otp); + } + + if (!empty($old_mpin)) { + $builder->where('clients.mpin', $old_mpin); + } + + $retailUserData = $builder->orderBy('clients.id', 'desc')->first(); + } else { + + $builder = $this->clientModel + ->select('clients.*') + ->join('policy_transaction', 'policy_transaction.client_id = clients.id') + ->where('policy_transaction.is_active', 1) + ->where('clients.is_active', 1) + ->where('clients.email', $email_id); + + if (!empty($otp)) { + $builder->where('clients.otp', $otp); + } + + if (!empty($old_mpin)) { + $builder->where('clients.mpin', $old_mpin); + } + + $retailUserData = $builder->orderBy('clients.id', 'desc')->first(); + } + + if ($retailUserData) { + return $this->respond(['status' => 'success', 'data' => $retailUserData,], 200); + } + + return $this->respond(['status' => 'failed', 'message' => 'No employee found.', 'code' => 404, 'data' => [],], 200); + } + + public function updateRetailUserAuthDetails() + { + try { + + log_message('error', 'Retail Auth Update Request Received'); + + $requestData = $this->request->getJSON(); + + $client_id = $requestData->client_id ?? null; + $email_id = $requestData->email_id ?? null; + $mobile_number = $requestData->mobile_number ?? null; + $otp = $requestData->otp ?? null; + $mpin = $requestData->mpin ?? null; + $password = $requestData->password ?? null; + + /** Check if at least one identification exists */ + if (!$client_id && !$email_id && !$mobile_number) { + log_message('error', 'Identification missing: Need client_id or mobile/email.'); + return $this->respond(['status' => false,'message' => 'client_id, email or mobile number is required.']); + } + + /** Find client by ID or Email or Mobile */ + $clientQuery = $this->clientModel->where('is_active', 1); + + if ($client_id) { + $clientQuery->where('id', $client_id); + } elseif ($email_id) { + $clientQuery->where('email', $email_id); + } elseif ($mobile_number) { + $clientQuery->where('phone', $mobile_number); + } + + $clientData = $clientQuery->get()->getRowArray(); + + /** If no client found, return error */ + if (!$clientData) { + log_message('error', 'Client not found for given identifier.'); + return $this->respond(['status' => false,'message' => 'Client not found.']); + } + + /** Now update fields that exist in request */ + $updateData = []; + + if ($otp) { + $updateData['otp'] = $otp; + } + + if ($mpin) { + $updateData['mpin'] = password_hash($mpin, PASSWORD_DEFAULT); // Secure MPIN Hash + } + + if ($password) { + $updateData['password'] = password_hash($password, PASSWORD_DEFAULT); // Secure Password Hash + } + + /** If nothing to update */ + if (empty($updateData)) { + log_message('error', 'No valid fields to update (OTP/MPIN/Password missing)'); + return $this->respond(['status' => false,'message' => 'No valid credentials provided for update.']); + } + + /** Update */ + $updated = $this->clientModel->where('id', $clientData['id'])->set($updateData)->update(); + + if ($updated) { + log_message('error', "Credentials updated successfully for Client ID: {$clientData['id']}"); + return $this->respond(['status' => true,'message' => 'Credentials updated successfully.']); + } else { + log_message('error', "Failed updating credentials for Client ID: {$clientData['id']}"); + return $this->respond(['status' => false,'message' => 'Failed to update credentials.']); + } + + } catch (\Exception $e) { + + log_message('error', 'Exception in updateRetailAuthDetails: ' . $e->getMessage()); + return $this->respond(['status' => false,'message' => 'Unexpected error occurred.','error' => $e->getMessage()], 500); + } + } + + public function getVerifiedRetailUserData() + { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedRetailUserData: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + 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; + $otp = isset($this->request->getJSON()->otp) ? $this->request->getJSON()->otp : null; + $client_id = $this->request->getJSON()->client_id ?? null; + + if(empty($otp)){ + return $this->respond(['status' => 'OTP is required','code' => 400,'message' => 'OTP is required'], 200); + } + + if (empty($mobile_number) && empty($email_id)) { + return $this->respond(['status' => 'failed','code' => 400,'message' => 'Mobile number or Email ID is required'], 200); + } + + if (!empty($mobile_number)) { + + $builder = $this->clientModel + ->select('clients.*') + ->join('policy_transaction', 'policy_transaction.client_id = clients.id') + ->where('policy_transaction.is_active', 1) + ->where('clients.is_active', 1) + ->where('clients.phone', $mobile_number); + + if (!empty($otp)) { + $builder->where('clients.otp', $otp); + } + + if (!empty($old_mpin)) { + $builder->where('clients.mpin', $old_mpin); + } + + $retailUserData = $builder->orderBy('clients.id', 'desc')->first(); + } else { + + $builder = $this->clientModel + ->select('clients.*') + ->join('policy_transaction', 'policy_transaction.client_id = clients.id') + ->where('policy_transaction.is_active', 1) + ->where('clients.is_active', 1) + ->where('clients.email', $email_id); + + if (!empty($otp)) { + $builder->where('clients.otp', $otp); + } + + if (!empty($old_mpin)) { + $builder->where('clients.mpin', $old_mpin); + } + + $retailUserData = $builder->orderBy('clients.id', 'desc')->first(); + } + + $lastQuery = $this->clientModel->db->getLastQuery(); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedRetailUserData: Last Executed Query: " . $lastQuery); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedRetailUserData: retailUserData: " . json_encode($retailUserData ?? [])); + + + if ($retailUserData && isset($this->request->getJSON()->otp) ) + { + $auth = HttpRequestHelper::getRequestInfo(); + if ($auth) { + $data = [ + 'user_id' => $retailUserData['id'], + 'user_type' => 'retail_user', + 'ip' => $auth['ip'], + 'platform' => $auth['platform'], + 'broswer' => $auth['browser'], + ]; + $this->authHistoryModel->insert($data); + } + + $retailUserData['client_id'] = null; + $retailUserData['client_branch_id'] = null; + $retailUserData['emp_code'] = null; + $retailUserData['emp_status'] = null; + $retailUserData['name'] = $retailUserData['client_name']; + $retailUserData['email_corporate'] = $retailUserData['email']; + $retailUserData['mobile'] = $retailUserData['phone']; + $retailUserData['token_type'] = "retail"; + $result = JWTToken::encode($retailUserData); + + if(isset($this->request->getJSON()->otp)){ + $this->clientModel->where('id', $retailUserData['id'])->where('otp', $otp)->set(['otp'=>null])->update(); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedRetailUserData: Reset the otp to null"); + } + + + return $this->respond(['status' => 'success','code' => 200,'data' => $result],200); + + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedRetailUserData: Employee not verified POST"); + return $this->respond(['status' => 'failed','code' => 404,'data' => "", 'message' => 'Invalid OTP'],200); + } + } catch (\Exception $e) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - getVerifiedRetailUserData: Exception: " . $e->getMessage() . " --- Line: " . $e->getLine() . " --- Trace: " . $e->getTraceAsString()); + return $this->respond(['status' => 'failed','code' => 500,'data' => "", 'message' => "Invalid OTP", 'error' => $e->getMessage()],500); + } + } + } \ No newline at end of file diff --git a/app/Models/ClientModel.php b/app/Models/ClientModel.php index 2397f4df..90a9b1f6 100755 --- a/app/Models/ClientModel.php +++ b/app/Models/ClientModel.php @@ -41,6 +41,7 @@ class ClientModel extends Model "mail_domain", "addon_subheading", "parent_client_id", + "otp", ]; diff --git a/app/Views/client_kyc_2.php b/app/Views/client_kyc_2.php new file mode 100755 index 00000000..8a2ce5ed --- /dev/null +++ b/app/Views/client_kyc_2.php @@ -0,0 +1,322 @@ + + +
| S. No | +Document Name | +File Name | +Action | +
|---|