diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3b9d49b1..f098faf4 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -402,6 +402,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->match(['get', 'post', 'delete'], 'rtoMaster', 'MasterController::rtoMaster'); $routes->get('checkDuplicateCdAccount', 'MasterController::checkDuplicateCdAccount'); $routes->get('proceedExcelFileDataValidation', 'EmployeeController::proceedExcelFileDataValidation'); + $routes->get('checkTpaApiEnable', 'EmployeeRestController::checkTpaApiEnable'); }); $routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail"); @@ -539,8 +540,12 @@ $routes->post("employeeRest/getPostEmployeeDataForAuth", "RestAuthenticationCont $routes->get("employeeRest/getClientDetails", "EmployeeRestController::getClientDetails"); + + $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { + $routes->post("ecardRequest", "ApiServiceController::ecardRequest"); + $routes->post("logHrActivity", "RestAuthenticationController::logHrActivity"); $routes->post("getVerifiedUserData", "RestAuthenticationController::getVerifiedUserData"); @@ -577,6 +582,7 @@ $routes->group("employeeRest", ["filter" => "authJWT"], function ($routes) { $routes->get("getFEContent", "EmployeeRestController::getFEContent"); $routes->get("getAdvertisementImage", "EmployeeRestController::getAdvertisementImage"); $routes->get("getWellnessURL", "EmployeeRestController::getWellnessURL"); + $routes->get("getEcardURL", "EmployeeRestController::getEcardURL"); //$routes->post('postDataForTicket',"EmployeeRestController::postDataForTicket"); @@ -685,9 +691,6 @@ $routes->get('createEnrollmentBatch','ICICILombardController::createEnrollmentBa $routes->get('getEnrollmentBatchStatus','ICICILombardController::getEnrollmentBatchStatus'); $routes->get('fetchUHIDDetails','ICICILombardController::fetchUHIDDetails'); -$routes->get('testTracelog','TestBusinessController::a'); -$routes->get("claimView", "EmployeeRestController::claimView"); - //Third party Vidal Api Call $routes->post('hospitalNetwork','VidalApiController::hospitalNetwork'); @@ -696,6 +699,29 @@ $routes->post('claimStatusCheck','VidalApiController::claimStatusCheck'); $routes->post('newClaim','VidalApiController::newClaim'); $routes->post('enrollment','VidalApiController::enrollment'); +//Third party MediAssist Api Call + +$routes->get('EcardRequest','MediAssistApiController::EcardRequest'); +$routes->get('HospitalNetwork','MediAssistApiController::HospitalNetwork'); +$routes->get('GetBenefDetails','MediAssistApiController::GetBenefDetails'); +$routes->get('ClaimDetail','MediAssistApiController::ClaimDetail'); +$routes->get('SubmitClaim','MediAssistApiController::SubmitClaim'); +$routes->get('IntimateClaim','MediAssistApiController::IntimateClaim'); +$routes->get('IRSubmission','MediAssistApiController::IRSubmission'); + + +// API service +$routes->post("ecardRequest", "ApiServiceController::ecardRequest"); +$routes->post("getTPAID", "ApiServiceController::getTPAID"); +$routes->get('fileDownload','MediAssistApiController::fileDownload'); + + + + + +$routes->get('testTracelog','TestBusinessController::a'); +$routes->get("claimView", "EmployeeRestController::claimView"); + // General Tickets $routes->post("ticketSave", "ThzController::ticketSave"); diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php new file mode 100644 index 00000000..28f74842 --- /dev/null +++ b/app/Controllers/ApiServiceController.php @@ -0,0 +1,216 @@ +db = \Config\Database::connect(); + $this->employeePolicyModel = new EmployeePolicyModel(); + } + + // Push Claims + public function pushClaims($claimId) + { + + $data = $this->db->table('ticket_master tm') + ->select('tm.id,tm.tpa_id ')->where('tm.id', $claimId)->get()->getRowArray(); // single record + + if($data){ + + $tpaID = $data['tpa_id']; + + if ($tpaID == 2) { // MediAssist + $mediAssistController = new MediAssistApiController(); + return $mediAssistController->SubmitClaim($claimId); + }else{ + + } + + } + + + } + + // E-Card Request + public function ecardRequest() + { + try{ + + $payload = $this->request->getJSON(true); + $id = $payload['id'] ?? null; + $emp_code = $payload['emp_code'] ?? null; + $client_policy_id = $payload['client_policy_id'] ?? null; + $policy_no = $payload['policy_no'] ?? null; + + + $employee_policy = $this->employeePolicyModel + ->select('employees.*, employee_polices.tpa_id , employee_polices.rand_string , employee_polices.uhid as uhid , client_policy.tpa_id as tpa_primary_id ') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id', 'left') + ->where('employee_polices.employee_id',$id) + ->where('employee_polices.client_policy_id',$client_policy_id) + ->where('employee_polices.is_active', 1 )->findAll(); + + + + if(count($employee_policy) > 0) + { + if($employee_policy[0]['tpa_id'] != null) + { + if($employee_policy[0]['tpa_primary_id'] == 2)//Medi assist + { + $mediAssistController = new MediAssistApiController(); + $data['eCardDownload'] = $mediAssistController->EcardRequest( $emp_code, $policy_no ); + }else{ + $data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/1'; + } + + } else { + $data['eCardDownload'] = null; + } + }else{ + $data['eCardDownload'] = null; + } + + + return $this->respond(['status' => true,'message' => '','data' => $data]); + + } catch(\Exception $e){ + + } + } + + // Get TPAID + public function getTPAID() + { + + $tpa_id = $this->request->getPost('tpa_id'); + $policy_no = $this->request->getPost('policy_no'); + $client_id = $this->request->getPost('client_id'); + $branch_id = $this->request->getPost('client_branch_id'); + $policy_id = $this->request->getPost('client_policy_id'); + + $fileModel = new FileModel(); + $filesData = $fileModel->where('is_active', 1)->where('action', 'api')->countAllResults(); + + if($filesData > 0){ + return $this->respond(['status' => false, 'code' => 200,'message' => 'TPA not found ','data' => [] ]); + } + + if ($tpa_id == 2) // MediAssist + { + + $mediAssistController = new MediAssistApiController(); + $mediAssistController->GetBenefDetails( [ 'polict_no' => $policy_no ] ); + + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Action Triggered','data' => [] ]); + + }else{ + return $this->respond(['status' => false, 'code' => 200,'message' => 'TPA not found ','data' => [] ]); + } + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // Get Claims + public function getClaims($id) + { + if ($id == 1) { + $controller = new VidalApiController(); + } elseif ($id == 2) { + $controller = new ICICILombardController(); + } elseif ($id == 3) { + $controller = new MediAssistApiController(); + } + } + + // Get UHID + public function getUhid($id) + { + if ($id == 1) { + $controller = new VidalApiController(); + } elseif ($id == 2) { + $controller = new ICICILombardController(); + } elseif ($id == 3) { + $controller = new MediAssistApiController(); + } + } + + // Push Enrollment + public function pushEnrollment($id) + { + if ($id == 1) { + $controller = new VidalApiController(); + } elseif ($id == 2) { + $controller = new ICICILombardController(); + } elseif ($id == 3) { + $controller = new MediAssistApiController(); + } + } + + // Get Hospital Network + public function getHospitalNetwork($id) + { + if ($id == 1) { + $controller = new VidalApiController(); + } elseif ($id == 2) { + $controller = new ICICILombardController(); + } elseif ($id == 3) { + $controller = new MediAssistApiController(); + } + } +} diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index 91086329..366849f8 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -12,6 +12,10 @@ use Psr\Log\LoggerInterface; use App\Helpers\sendMailNotification; +use App\Controllers\VidalApiController; +use App\Controllers\ICICILombardController; +use App\Controllers\MediAssistApiController; + use App\Models\EmployeeModel; use App\Models\EmployeePolicyModel; @@ -54,6 +58,7 @@ use Illuminate\Http\Request; use App\Controllers\EmployeeServiceController; use App\Models\ClaimFilesModel; use App\Models\TicketMailTemplateModel; +use App\Models\TpaApiSeviceModel; use Composer\Pcre\Preg; use Kreait\Firebase\Factory; use Kreait\Firebase\Messaging\CloudMessage; @@ -2189,7 +2194,7 @@ class EmployeeRestController extends AdminController // print_r($params);die; $wholeData =sendMailNotification::sendMailNotification('member_review_and_summary_mail', $params); $mail_send_return = MailHelper::send_email($wholeData[0]); - $this->myLogger->logme("info", $mail_send_return); + $this->myLogger->logme("error", $mail_send_return); if (isset($wholeData[0])) { @@ -2200,7 +2205,7 @@ class EmployeeRestController extends AdminController { foreach ($account_manager_wholeData as $key => $value) { $mail_send_return1 = MailHelper::send_email($value); - $this->myLogger->logme("info", $mail_send_return1); + $this->myLogger->logme("error", $mail_send_return1); } }else{ $this->myLogger->logme("error", 'Account Manager Mail Configuration not Enable for this client'); @@ -2213,7 +2218,7 @@ class EmployeeRestController extends AdminController { foreach ($client_hr_wholeData as $key => $value) { $mail_send_return2 = MailHelper::send_email($value); - $this->myLogger->logme("info", $mail_send_return2); + $this->myLogger->logme("error", $mail_send_return2); } }else{ $this->myLogger->logme("error", 'Client HR Mail Configuration not Enable for this client'); @@ -3720,7 +3725,7 @@ class EmployeeRestController extends AdminController ])->setStatusCode(404); } - $this->myLogger->logme('info', "Policy type IDs fetched: " . json_encode($policy_type_ids)); + $this->myLogger->logme('error', "Policy type IDs fetched: " . json_encode($policy_type_ids)); $ticket_type = $this->ticketController->ticketType; $filtered = []; @@ -3748,9 +3753,9 @@ class EmployeeRestController extends AdminController 'name' => $mappedName ]; - $this->myLogger->logme('info', "Ticket type resolved: ID={$ticketTypeId}, Name={$mappedName}"); + $this->myLogger->logme('error', "Ticket type resolved: ID={$ticketTypeId}, Name={$mappedName}"); } else { - $this->myLogger->logme('warning', "No valid ticket type mapping for policy_type_id={$ticketTypeId}"); + $this->myLogger->logme('error', "No valid ticket type mapping for policy_type_id={$ticketTypeId}"); } } @@ -3889,8 +3894,11 @@ class EmployeeRestController extends AdminController $userParams['employeeId'] = $row['employeeId']; $userParams['policyStartDate']= $row['policyStartDate']; $userParams['policyEndDate'] = $row['policyEndDate']; - $userParams['policyName'] = 'Nhance ' . $row['policy_type']; - $userParams['planId'] = 'NHANCE-PLAN-' . $row['policy_type']; + // $userParams['policyName'] = 'Nhance ' . $row['policy_type']; + // $userParams['planId'] = 'NHANCE-PLAN-' . $row['policy_type']; + $userParams['policyName'] = $row['policy_type']; + $userParams['planId'] = env('VISIT_PLAN_ID'); + $userParams['moduleName'] = 'home'; break; // stop after first GMC match } @@ -3923,6 +3931,7 @@ class EmployeeRestController extends AdminController $finalUrl = $baseURL . '/sso?userParams=' . $output . '&clientId=' . $clientId; if (!empty($finalUrl)) { + log_message('error', 'VISIT SSO | emp_id: '.$emp_id.' | URL: '.$finalUrl); return $this->respond(['status' => 'success','data' => $finalUrl], 200); } else { return $this->respond(['status' => 'failed','message' => 'Coming soon........!'], 200); @@ -4462,22 +4471,152 @@ class EmployeeRestController extends AdminController return $this->failServerError($e->getMessage()); } } + + public function hrFileUploadMasters() + { + try { + //for inception upload + $data['actions'] = ['addition' => 'Addition (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; - - public function hrFileUploadMasters() + return $this->respond([ + 'status' => true, + 'message' => 'File inception upload masters', + 'data' => $data + ]); + } catch (\Exception $e) { + return $this->failServerError($e->getMessage()); + } + } + + public function checkTpaApiEnable($policy_id = null, $api_name = null, $return_type = 'api') + { + $this->myLogger->logme('error', '--- START checkTpaApiEnable ---'); + + try { + // Step 1: Handle input parameters + if (empty($policy_id)) { + $policy_id = $this->request->getGet('policy_id'); + $api_name = $this->request->getGet('api_name'); + log_message('error', "Input parameters fetched from GET: policy_id={$policy_id}, api_name={$api_name}"); + } else { + log_message('error', "Input parameters received directly: policy_id={$policy_id}, api_name={$api_name}"); + } + + // Step 2: Validate policy_id + if (empty($policy_id)) { + log_message('error', 'Policy ID is empty'); + if ($return_type == 'api') { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'Policy ID missing']); + } + return false; + } + + // Step 3: Fetch policy data + log_message('error', "Fetching policy data for policy_id={$policy_id}"); + $policy_data = $this->clientPolicyModel + ->where('is_active', 1) + ->where('id', $policy_id) + ->first(); + + if (empty($policy_data)) { + log_message('error', "Policy data not found for policy_id={$policy_id}"); + if ($return_type == 'api') { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'Policy data not found']); + } + return false; + } + + // Step 4: Check for TPA ID + if (empty($policy_data['tpa_id'])) { + log_message('error', "TPA ID not found for policy_id={$policy_id}"); + if ($return_type == 'api') { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'TPA ID not found']); + } + return false; + } + + $tpa_id = $policy_data['tpa_id']; + log_message('error', "Found TPA ID={$tpa_id} for policy_id={$policy_id}"); + + // Step 5: Check if API service is enabled + log_message('error', "Checking TPA API service for TPA ID={$tpa_id} and API name={$api_name}"); + $tpaApiServiceModel = new TpaApiSeviceModel(); + $api_data = $tpaApiServiceModel + ->where('is_active', 1) + ->where('api_name', $api_name) + ->where('tpa_id', $tpa_id) + ->first(); + + if (!empty($api_data)) { + log_message('error', "API '{$api_name}' is enabled for TPA ID={$tpa_id}"); + if ($return_type == 'api') { + return $this->respond(['status' => true, 'code' => 200, 'message' => 'API services enabled']); + } + return true; + } else { + log_message('error', "API '{$api_name}' is NOT enabled for TPA ID={$tpa_id}"); + if ($return_type == 'api') { + return $this->respond(['status' => false, 'code' => 200, 'message' => 'API services not enabled']); + } + return false; + } + } catch (\Throwable $th) { + log_message('error', 'Exception in checkTpaApiEnable: ' . $th->getMessage()); + if ($return_type == 'api') { + return $this->respond(['status' => false, 'code' => 500, 'message' => 'Internal Server Error']); + } + return false; + } finally { + log_message('error', '--- END checkTpaApiEnable ---'); + } + } + + + + public function getEcardURL() { - try { - //for inception upload - $data['actions'] = ['addition' => 'Addition (Employee + Dependents)', 'missed_inception' => 'Missed Inception (Employee + Dependents)', 'dependent_addition' => 'Dependent Addition (Only Dependents)', 'deletion' => 'Deletion', 'correction' => 'Correction', 'si_enhancement' => 'SI Enhancement']; - - return $this->respond([ - 'status' => true, - 'message' => 'File inception upload masters', - 'data' => $data - ]); - } catch (\Exception $e) { - return $this->failServerError($e->getMessage()); - } + try{ + + $id = $this->request->getGet('id'); + $emp_code = $this->request->getGet('emp_code'); + $client_policy_id = $this->request->getGet('client_policy_id'); + $policy_no = $this->request->getGet('policy_no'); + + $employee_policy = $this->employeePolicyModel + ->select('employees.*, employee_polices.tpa_id , employee_polices.rand_string , employee_polices.uhid as uhid , client_policy.tpa_id as tpa_primary_id ') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id', 'left') + ->where('employee_polices.employee_id',$id) + ->where('employee_polices.client_policy_id',$client_policy_id) + ->where('employee_polices.is_active', 1 )->findAll(); + + + + if(count($employee_policy) > 0) + { + if($employee_policy[0]['tpa_id'] != null) + { + if($employee_policy[0]['tpa_primary_id'] == 2)//Medi assist + { + $mediAssistController = new MediAssistApiController(); + $data['eCardDownload'] = $mediAssistController->EcardRequest( $emp_code, $policy_no ); + }else{ + $data['eCardDownload'] = base_url('download-e-card/') . $employee_policy[0]['rand_string'].'/1'; + } + + } else { + $data['eCardDownload'] = null; + } + }else{ + $data['eCardDownload'] = null; + } + + + return $this->respond(['status' => true,'message' => '','data' => $data]); + + } catch(\Exception $e){ + + } } } \ No newline at end of file diff --git a/app/Controllers/ICICILombardController.php b/app/Controllers/ICICILombardController.php index 5c5bc627..a91cc147 100644 --- a/app/Controllers/ICICILombardController.php +++ b/app/Controllers/ICICILombardController.php @@ -87,32 +87,32 @@ class ICICILombardController extends AdminController $body = [ - "PolicyNumber" => "4016/A/O/53130557/00/000", + "PolicyNumber" => "4016/PPN/A/O/53167743/00/000", "CDBGAccountNumber" => "CD-MUM-0026", - "CorrelationId" => "550e8400-e29b-41d4-a716-446655440010", + "CorrelationId" => "550e8400-e29b-41d4-a716-446655440012", "MemberDetails" => [ [ - "MemberEmpId" => "EMPID3625557", + "MemberEmpId" => "EMPID3625559", "DOJ" => "21-MAR-2019", - "InsuredName" => "Kumar", - "DOB" => "7-JUL-1983", + "InsuredName" => "Gowtham", + "DOB" => "7-JUL-1993", "Relationship" => "SELF", "Gender" => "MALE", - "DOC" => "05-SEP-2025", + "DOC" => '2025-10-27', "SumInsured" => "400000", - "EmailId" => "KUMAR@GMAIL.COM", + "EmailId" => "Gowtham@GMAIL.COM", "FlagStatus" => "A" ], [ - "MemberEmpId" => "EMPID3625557", + "MemberEmpId" => "EMPID3625559", "DOJ" => "21-MAR-2019", - "InsuredName" => "Saranya", + "InsuredName" => "Lavanya", "DOB" => "8-AUG-1970", "Relationship" => "MOTHER", "Gender" => "FEMALE", - "DOC" => "05-SEP-2025", + "DOC" => '2025-10-27', "SumInsured" => "400000", - "EmailId" => "Saranya@GMAIL.COM", + "EmailId" => "Lavanya@GMAIL.COM", "FlagStatus" => "A" ], ] @@ -148,9 +148,9 @@ class ICICILombardController extends AdminController // dd($headers); $body = [ - "PolicyNumber" => "4016/A/O/53130557/00/000", - "BatchId" => "3658147", - "CorrelationId" => "550e8400-e29b-41d4-a716-446655440010" + "PolicyNumber" => "4016/PPN/A/O/53167743/00/000", + "BatchId" => "3672146", + "CorrelationId" => "550e8400-e29b-41d4-a716-446655440012" ]; $response = call_third_party_api($url, 'POST', $headers, $body, true); @@ -182,9 +182,9 @@ class ICICILombardController extends AdminController ]; $body = [ - "PolicyNumber" => "4016/A/51974976/00/000", - "IMID" => "2345617878", - "CorrelationId" => "86383c78-4c67-4e4d-9aa0-9f926fb0d55e" + "PolicyNumber" => "4016/PPN/A/O/53167743/00/000", + "IMID" => "3672145", + "CorrelationId" => "550e8400-e29b-41d4-a716-446655440011" ]; $response = call_third_party_api($url, 'POST', $headers, $body, true); diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php new file mode 100644 index 00000000..4eeeebae --- /dev/null +++ b/app/Controllers/MediAssistApiController.php @@ -0,0 +1,538 @@ +table('ticket_master tm') + ->select(' + tm.id, + tm.emp_mobile as mobileNo, + tm.emp_mail as emailId, + tm.doa as claimDateOfAdmission, + tm.dod as claimDateOfDischarge, + tm.hospital_name as hospName, + tm.claim_amount as claimAmount, + cp.policy_no as policyNo, + e.id as empId, + e.emp_code as memberId, + tn.note as disease, + tn.note as reasonForHospitalization, + cf.doc_name as fileName, + cf.url as filePath + ') + ->join('employees e', 'e.id = tm.emp_id', 'left') + ->join('client_policy cp', 'tm.client_policy_id = cp.id', 'left') + ->join('ticket_notes tn', 'tn.ticket_id = tm.id', 'left') + ->join('claim_files cf', 'cf.ticket_id = tm.id AND cf.file_type = 2', 'left') + ->where('tm.id', $claimId) + ->get() + ->getRowArray(); // single record + + + // Map DB result to request body + if ($data) { + + $filePath = $data['filePath'] ?? ''; + + $filename = basename($filePath); + + $fileDir = WRITEPATH . 'uploads/claim_files/'.$filename; + + + if ($fileDir) { + $downloadUrl = base_url('fileDownload?file_path=').$fileDir; + } else { + $downloadUrl = ''; + } + + $body = [ + "policyNo" => $data['policyNo'] ?? "", + "memberId" => $data['empId'] ?? "", + "mobileNo" => $data['mobileNo'] ?? "", + "emailId" => $data['emailId'] ?? "", + "claimDateOfAdmission" => $data['claimDateOfAdmission'] ?? "", + "claimDateOfDischarge" => $data['claimDateOfDischarge'] ?? "", + "hospName" => $data['hospName'] ?? "", + "hospAddress" => $data['hospName'] ?? "", // If hospAddress not available, reuse hospName + "reasonForHospitalization" => $data['reasonForHospitalization'] ?? "", + "disease" => $data['disease'] ?? "", + "claimAmount" => (float)($data['claimAmount'] ?? 0), + "claimType" => "HOSPITALIZATION", // static value + "claimSubmissionAttachments" => [ + "fileName" => $data['fileName'] ?? "", + "filePath" => $downloadUrl ?? "" + ] + ]; + } else { + $body = []; + } + + // dd($body); + + // $body = [ + // "policyNo" => "570000/48/2025/286", + // "memberId" => 4078919887, + // "mobileNo" => "95000XXXXX", + // "emailId" => "test@Medi.com", + // "claimDateOfAdmission" => "2023-12-14", + // "claimDateOfDischarge" => "2023-12-16", + // "hospName" => "TestHosp", + // "hospAddress" => "Testhosp", + // "reasonForHospitalization" => "test", + // "disease" => "testkediney", + // "claimAmount" => 10, + // "claimType" => "HOSPITALIZATION", + // "claimSubmissionAttachments" => [ + // "fileName" => "Test.pdf", + // "filePath" => "https://apiintegration.mediassist.in/IntegrationEcard/DownloadEcard/4078613742/Senthil Kumar P/556/5386" + // ] + // ]; + + $response = call_third_party_api($url, $method, $headers, $body); + + + if($response['status'] != true){ + + log_message('error', 'TPA CLAIM PUSH FAILED | claimId: '.$claimId.' | response: '.json_encode($response)); + return; + } + + // return $this->response->setJSON($response); + + $claimRef = $response['data']['claimReferenceNo'] ?? null; + + if(!empty($claimRef)){ + + log_message('error', 'TPA CLAIM PUSH SUCCESS | claimId: '.$claimId.' | claimReferenceNo: '.$claimRef); + + $db->table('ticket_master') + ->where('id',$claimId) + ->update([ 'tpa_claim_push_reference_no' => $claimRef ]); + + return; + + } else { + log_message('error', 'TPA CLAIM PUSH SUCCESS BUT claimReferenceNo EMPTY | claimId: '.$claimId.' | response: '.json_encode($response)); + return; + } + + } + + public function EcardRequest ($employeeId = null, $policyNo = null){ + + helper('api'); + + $url = ''. getenv('MEDI_ASSIST_API_BASE_URL_LIVE').'/EcardUrl'; + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Username:'. getenv('MEDI_ASSIST_API_USERNAME_LIVE').'', + 'Password:'. getenv('MEDI_ASSIST_API_PASSWORD_LIVE').'', + ]; + + $body = [ + "employeeId" => $employeeId, + "policyNo" => $policyNo + ]; + + // $body = [ + // "employeeId" => "CITPL120006", + // "policyNo" => "97000063250400000031" + // ]; + + $response = call_third_party_api($url, $method, $headers, $body); + + if($response['status'] != true){ + log_message('error', 'Ecard Request FAILED | employeeId: '.$employeeId.' | policyNo: '.$policyNo.' | response: '.json_encode($response)); + return null; + } + + $ecardUrl = $response['data']['ecardUrl'] ?? null; + + if(!empty($ecardUrl)){ + log_message('error', 'Ecard Request PUSH SUCCESS | employeeId: '.$employeeId.' | policyNo: '.$policyNo.' | ecardUrl: '.$ecardUrl); + return $ecardUrl; + } else { + log_message('error', 'Ecard Request SUCCESS BUT ecardUrl EMPTY | employeeId: '.$employeeId.' | policyNo: '.$policyNo.' | response: '.json_encode($response)); + return null; + } + + + } + + + public function GetBenefDetails($requestData) + { + + helper('api'); + + $url = getenv('MEDI_ASSIST_API_BASE_URL_LIVE') . '/GetBenefDetails'; + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Username:' . getenv('MEDI_ASSIST_API_USERNAME_LIVE'), + 'Password:' . getenv('MEDI_ASSIST_API_PASSWORD_LIVE'), + ]; + + $policyNo = $requestData['policy_no'] ?? null; + + if (empty($policyNo)) { + log_message('error', 'GetBenefDetails: policy_no missing in request'); + return $this->response->setJSON(['status' => false,'message' => 'policy_no required']); + } + + log_message('error', "GetBenefDetails called for policy_no: {$policyNo}"); + + $allBenef = []; + $startIndex = 0; + $range = 100; + $totalCount = 0; + + do { + $body = [ + "policyNo" => $policyNo, + "startDate" => "", + "endDate" => "", + "isDeActivedata" => false, + "startIndex" => $startIndex, + "range" => $range, + "employeeId" => "" + ]; + + log_message('error', "GetBenefDetails API Request (startIndex={$startIndex}): " . json_encode($body)); + + $response = call_third_party_api($url, $method, $headers, $body); + + if ($response['status'] != true) { + log_message('error', 'GetBenefDetails API failed: ' . json_encode($response)); + return $this->response->setJSON([ 'status' => false,'message' => 'API call failed','data' => $response]); + } + + $data = $response['data'] ?? []; + + if (!isset($data['benefDetails'])) { + log_message('error', "GetBenefDetails: 'benefDetails' missing in API response: " . json_encode($data)); + break; + } + + $count = $data['count'] ?? 0; + $totalCount = $count; + $fetchedCount = count($data['benefDetails']); + + log_message('error', "Fetched {$fetchedCount} records (startIndex={$startIndex}) of total {$count}"); + + $allBenef = array_merge($allBenef, $data['benefDetails']); + + $startIndex += $range; + + } while ($startIndex < $totalCount); + + // now update DB + $db = \Config\Database::connect(); + $updated = 0; + + + + foreach ($allBenef as $row) { + + // $update = $db->table('employee_polices') + // ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id AND client_policy.policy_no = ' . $db->escape($row['polNo']), 'left') + // ->join( + // 'employees', + // 'employee_polices.employee_id = employees.id + // AND employees.emp_code = ' . $db->escape($row['priBenefEmpCode']) . ' + // AND employees.relationship = ' . $db->escape($row['relName']), + // 'left' + // ) + // ->where('employee_polices.tpa_id IS NULL') + // ->update(['employee_polices.tpa_id' => $row['benefMediAssistID']]); + + $update = $db->table('employee_polices') + ->join('client_policy', 'employee_polices.client_policy_id = client_policy.id', 'left') + ->join('employees', 'employee_polices.employee_id = employees.id', 'left') + ->where('client_policy.policy_no', $row['polNo']) + ->where('employees.emp_code', $row['priBenefEmpCode']) + ->where('employees.relationship', $row['relName']) + ->where('employee_polices.tpa_id IS NULL', null, false) + ->update(['employee_polices.tpa_id' => $row['benefMediAssistID']]); + + + + if ($db->affectedRows() > 0) { + $updated++; + log_message('error', "Updated tpa_id for emp_code={$row['priBenefEmpCode']}, policy={$row['polNo']}"); + } + } + + log_message('error', "GetBenefDetails completed. Total fetched={$totalCount}, updated={$updated}"); + + return $this->response->setJSON([ + 'status' => true, + 'message' => 'Updated successfully', + 'total_fetched' => $totalCount, + 'total_updated' => $updated + ]); + } + + + // public function GetBenefDetails (){ + + // $postData = $this->request->getJSON(true); + + // helper('api'); + + // $url = ''. getenv('MEDI_ASSIST_API_BASE_URL_LIVE').'/GetBenefDetails'; + // $method = 'POST'; + + // $headers = [ + // 'Content-Type: application/json', + // 'Username:'. getenv('MEDI_ASSIST_API_USERNAME_LIVE').'', + // 'Password:'. getenv('MEDI_ASSIST_API_PASSWORD_LIVE').'', + // ]; + + // $body = [ + // "policyNo" => $$postData['policy_no'], + // "startDate" => "", + // "endDate" => "", + // "isDeActivedata" => false, + // "startIndex" => 0, + // "range" => 100 , + // "employeeId" => "" + // ]; + + // // $body = [ + // // "policyNo" => "97000063250400000031", + // // "startDate" => "", + // // "endDate" => "", + // // "isDeActivedata" => false, + // // "startIndex" => 0, + // // "range" => 100 , + // // "employeeId" => "" + // // ]; + + // $response = call_third_party_api($url, $method, $headers, $body); + + + // if($response['status'] != true){ + // return $this->response->setJSON([ + // 'status' => false, + // 'message' => 'failed.', + // 'data' => $response + // ]); + // } + + // return $this->response->setJSON($response); + + // } + + public function ClaimDetail (){ + + + helper('api'); + + $url = ''. getenv('MEDI_ASSIST_API_BASE_URL_LIVE').'/ClaimDetail'; + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Username:'. getenv('MEDI_ASSIST_API_USERNAME_LIVE').'', + 'Password:'. getenv('MEDI_ASSIST_API_PASSWORD_LIVE').'', + ]; + + $body = [ + "policyNo" => "97000063250400000031", + "startDate" => "", + "endDate" => "", + "employeeCode" => "CITPL120193", + "memberID" => "", + "claimNo" => "", + "claimRefNo" => "" + ]; + + $response = call_third_party_api($url, $method, $headers, $body); + + + if($response['status'] != true){ + return $this->response->setJSON([ + 'status' => false, + 'message' => 'failed.', + 'data' => $response + ]); + } + + return $this->response->setJSON($response); + + } + + + + + + + public function HospitalNetwork (){ + + $postData = $this->request->getJSON(true); + + helper('api'); + + $url = ''. getenv('MEDI_ASSIST_API_BASE_URL_LIVE').'/NetworkHospital'; + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Username:'. getenv('MEDI_ASSIST_API_USERNAME_LIVE').'', + 'Password:'. getenv('MEDI_ASSIST_API_PASSWORD_LIVE').'', + ]; + + $body = [ + "startIndex" => 0, + "endIndex" => 10, + "policyNumber" => "97000063250400000031" + ]; + + $response = call_third_party_api($url, $method, $headers, $body); + + + if($response['status'] != true){ + return $this->response->setJSON([ + 'status' => false, + 'message' => 'failed.', + 'data' => $response + ]); + } + + return $this->response->setJSON($response); + + } + + public function IntimateClaim (){ + + $postData = $this->request->getJSON(true); + + helper('api'); + + // $url = ''. getenv('MEDI_ASSIST_API_BASE_URL').'/ClaimAPIServiceUAT/Claim/IntimateClaim'; + $url = "https://apiintegration.mediassist.in/ClaimAPIServiceUAT/Claim/IntimateClaim"; + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Username:' .'NhanceUsr', + 'Password:' .'NhU$p&Cc5wGQbr2', + ]; + + + $p = 'NhU$p&Cc5wGQbr2'; + $body = [ + "Username" => "NhanceUsr", + "Password" => $p, + "policyNo" => "570000/48/2025/286", + "memberId" => 4078919887, + "DateOfAdmisssion" => date('Y-m-d', strtotime('2023-12-14')), + "HospitalName" => "test", + "AilmentDescription" => "Kidney", + "ContactNo" => "78745XXXXX" + ]; + + $response = call_third_party_api($url, $method, $headers, $body); + + + if($response['status'] != true){ + return $this->response->setJSON([ + 'status' => false, + 'message' => 'failed.', + 'data' => $response + ]); + } + + return $this->response->setJSON($response); + + } + + public function IRSubmission (){ + + $postData = $this->request->getJSON(true); + + helper('api'); + + // $url = ''. getenv('MEDI_ASSIST_API_BASE_URL').'/ClaimAPIServiceUAT/Claim/IRSubmission'; + $url = "https://apiintegration.mediassist.in/ClaimAPIServiceUAT/Claim/IRSubmission"; + $method = 'POST'; + + $headers = [ + 'Content-Type: application/json', + 'Username:' .'NhanceUsr', + 'Password:' .'NhU$p&Cc5wGQbr2', + ]; + + $body = [ + "ClaimID" => "134431104", + "Attachments" => [ + "AttachmentName" => "Test.pdf", + "AttachmentPath" => "https://apiintegration.mediassist.in/IntegrationEcard/DownloadEcard/4078613742/Senthil Kumar P/556/5386" + ] + ]; + + $response = call_third_party_api($url, $method, $headers, $body); + + + if($response['status'] != true){ + return $this->response->setJSON([ + 'status' => false, + 'message' => 'failed.', + 'data' => $response + ]); + } + + return $this->response->setJSON($response); + + } + + + public function fileDownload() + { + + $filePath = $this->request->getGet('file_path'); + $filename = basename($filePath); + + // Return file as download + return $this->response->download($filePath, null)->setFileName($filename); + } + + + + +} diff --git a/app/Controllers/RestAuthenticationController.php b/app/Controllers/RestAuthenticationController.php index 24f22283..11b1a8fc 100755 --- a/app/Controllers/RestAuthenticationController.php +++ b/app/Controllers/RestAuthenticationController.php @@ -869,6 +869,7 @@ class RestAuthenticationController extends AdminController return $this->respond(['status' => 'failed','code' => 404,'data' => $result],200); } + } catch (\Throwable $th) { $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - saveMpin: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine() . " --- Trace: " . $th->getTraceAsString()); log_message('error', ' '); @@ -1496,4 +1497,460 @@ class RestAuthenticationController extends AdminController return $this->fail("Invalid Token: " . $e->getMessage(), 401); } } + + // -------------- PASSWORD API'S ------------------------------------------------------------------------------------------------------------- + + public function savePassword() + { + log_message('error', ' '); + log_message('error', ' ************************************* POST START **************************************** '); + log_message('error', ' '); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Function called"); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + + $payload = $this->request->getJSON(); + $mobile_number = $payload->mobile_number ?? null; + $email_id = $payload->email_id ?? null; + $client_id = $payload->client_id ?? null; + $plain_password = $payload->password ?? null; + + if (empty($plain_password)) { + return $this->respond(['status' => 'failed', 'code' => 400, 'message' => 'Password cannot be empty'], 400); + } + + // Build employee query + if ($mobile_number) { + + $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 { + + $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(); + + } + + $lastQuery = $this->employeeModel->db->getLastQuery(); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Last Executed Query: " . $lastQuery); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: employeeData: " . json_encode($employeeData ?? [])); + + if ($employeeData) { + $id = $employeeData['id']; + $hashedPassword = password_hash($plain_password, PASSWORD_DEFAULT); + + $updateData = [ + 'password' => $hashedPassword, + ]; + + $updated = $this->employeeModel->where('id', $id)->set($updateData)->update(); + + if ($updated) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Password saved successfully"); + $result = ['user_verification' => true, 'message' => "Password saved successfully"]; + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $result], 200); + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Password save failed"); + $result = ['user_verification' => true, 'message' => "Password not saved"]; + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $result], 200); + } + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - savePassword: Employee not found"); + $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", "REST-AUTH-CONTROLLER - savePassword: Exception: " . $th->getMessage() . " --- Line: " . $th->getLine() . " --- Trace: " . $th->getTraceAsString()); + return $this->respond(['status' => 'failed', 'code' => 500, 'message' => $th->getMessage()], 500); + } + } + + public function changePassword() + { + log_message('error', ' '); + log_message('error', ' ************************************* CHANGE PASSWORD START **************************************** '); + log_message('error', ' '); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Function called"); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + $payload = $this->request->getJSON(true); + + $mobile_number = $payload['mobile_number'] ?? null; + $email_id = $payload['email_id'] ?? null; + $client_id = $payload['client_id'] ?? null; + $otp = $payload['otp'] ?? null; + $new_password = $payload['new_password'] ?? null; + + if (empty($otp) || empty($new_password)) { + return $this->respond([ + 'status' => 'failed', + 'code' => 400, + 'message' => 'OTP and new password are required' + ], 400); + } + + // Fetch employee details + $builder = $this->employeeModel + ->select('employees.*') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.relationship', 'Self') + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active']); + + if (!empty($client_id)) $builder->where('employees.client_id', $client_id); + + if ($mobile_number) { + $builder->where('employees.mobile', $mobile_number); + } elseif ($email_id) { + $builder->where('employees.email_corporate', $email_id); + } else { + return $this->respond([ + 'status' => 'failed', + 'code' => 400, + 'message' => 'Mobile number or Email ID is required' + ], 400); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: employeeData: " . json_encode($employeeData ?? [])); + + if (!$employeeData) { + return $this->respond(['status' => 'failed', 'code' => 404, 'message' => 'User not found'], 404); + } + + // Check OTP validity (assuming fields: otp, otp_expiry exist) + if (empty($employeeData['otp']) || $employeeData['otp'] != $otp) { + return $this->respond(['status' => 'failed', 'code' => 401, 'message' => 'Invalid OTP'], 200); + } + + if (!empty($employeeData['otp_expiry']) && strtotime($employeeData['otp_expiry']) < time()) { + return $this->respond(['status' => 'failed', 'code' => 401, 'message' => 'OTP expired'], 200); + } + + // Hash new password + $newHashedPassword = password_hash($new_password, PASSWORD_DEFAULT); + + // Update password and clear OTP + $updated = $this->employeeModel->update($employeeData['id'], [ + 'password' => $newHashedPassword, + 'otp' => null, + ]); + + if ($updated) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Password updated successfully"); + log_message('error', ' '); + log_message('error', ' ************************************* CHANGE PASSWORD END **************************************** '); + log_message('error', ' '); + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'message' => 'Password changed successfully' + ], 200); + } else { + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => 'Failed to update password' + ], 500); + } + + } catch (\Throwable $th) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - changePassword: Exception: " . $th->getMessage()); + log_message('error', ' '); + log_message('error', ' ************************************* CHANGE PASSWORD END **************************************** '); + log_message('error', ' '); + return $this->respond(['status' => 'failed', 'code' => 500, 'message' => $th->getMessage()], 500); + } + } + + public function verifyPassword() + { + log_message('error', ' '); + log_message('error', ' ************************************* POST START **************************************** '); + log_message('error', ' '); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - Verify Password: Function called"); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + $requestData = $this->request->getJSON(true); + + $mobile_number = $requestData['mobile_number'] ?? null; + $email_id = $requestData['email_id'] ?? null; + $password = $requestData['password'] ?? null; + $client_id = $requestData['client_id'] ?? null; + + if (!$password) { + return $this->respond(['status' => 'failed', 'code' => 400, 'data' => "", 'message' => 'Password is required'], 400); + } + + // 🔹 Fetch employee data + if ($mobile_number) { + $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(); + } 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' => 400, 'data' => "", 'message' => 'Mobile number or Email ID is required'], 400); + } + + $lastQuery = $this->employeeModel->db->getLastQuery(); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Last Executed Query: " . $lastQuery); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: employeeData: " . json_encode($employeeData ?? [])); + + // 🔹 Verify password hash + if ($employeeData && isset($employeeData['password']) && password_verify($password, $employeeData['password'])) { + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Verified employee found"); + + // ✅ Log authentication info + $auth = HttpRequestHelper::getRequestInfo(); + if ($auth) { + $this->authHistoryModel->insert([ + 'user_id' => $employeeData['id'], + 'user_type' => 'employee', + 'ip' => $auth['ip'], + 'platform' => $auth['platform'], + 'broswer' => $auth['browser'], + ]); + } + + // ✅ Generate JWT token + $employeeData['token_type'] = "post"; + $token = JWTToken::encode($employeeData); + + log_message('error', ' '); + log_message('error', ' ************************************* POST END **************************************** '); + log_message('error', ' '); + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $token], 200); + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Invalid password or employee not found"); + log_message('error', ' '); + log_message('error', ' ************************************* POST END **************************************** '); + log_message('error', ' '); + + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => "", 'message' => 'Invalid password'], 200); + } + } catch (\Exception $e) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - verifyPassword: Exception: " . $e->getMessage() . " --- Line: " . $e->getLine()); + log_message('error', ' '); + log_message('error', ' ************************************* POST END **************************************** '); + log_message('error', ' '); + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => "", 'message' => $e->getMessage()], 500); + } + } + + public function sendChangePasswordOTP() + { + log_message('error', ' '); + log_message('error', ' ************************************* SEND OTP START **************************************** '); + log_message('error', ' '); + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - sendChangePasswordOTP: Function called"); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - sendChangePasswordOTP: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + $requestData = $this->request->getJSON(true); + + $email_id = $requestData['email_id'] ?? null; + $client_id = $requestData['client_id'] ?? null; + + if (!$email_id) { + return $this->respond(['status' => 'failed', 'code' => 400, 'data' => "", 'message' => 'Email ID is required'], 400); + } + + // Get employee details + $builder = $this->employeeModel + ->select('employees.id, employees.mobile, employees.email_corporate, employees.client_id') + ->join('employee_polices', 'employees.id = employee_polices.employee_id') + ->where('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active']) + ->where('employees.relationship', 'Self'); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + if ($email_id) { + $builder->where('employees.email_corporate', $email_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - sendChangePasswordOTP: Employee Data: " . json_encode($employeeData ?? [])); + + if (!$employeeData) { + return $this->respond(['status' => 'failed', 'code' => 404, 'data' => "", 'message' => 'Employee not found'], 404); + } + + // Generate 6-digit OTP + $otp = rand(100000, 999999); + + // Save OTP to DB (assuming 'otp' and 'otp_expiry' columns exist) + $this->employeeModel->update($employeeData['id'], [ + 'otp' => $otp, + ]); + + // Send OTP via SMS or Email (you can replace with your actual helper) + if ($email_id) { + // Example: MailHelper::sendMail($email_id, 'Password Change OTP', "Your OTP is {$otp}"); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - sendChangePasswordOTP: OTP {$otp} sent to email {$email_id}"); + } + + log_message('error', ' '); + log_message('error', ' ************************************* SEND OTP END **************************************** '); + log_message('error', ' '); + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => ['otp_sent_to' => $email_id], 'message' => 'OTP sent successfully'], 200); + } catch (\Exception $e) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - sendChangePasswordOTP: Exception: " . $e->getMessage() . " --- Line: " . $e->getLine()); + log_message('error', ' '); + log_message('error', ' ************************************* SEND OTP END **************************************** '); + log_message('error', ' '); + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => "", 'message' => $e->getMessage()], 500); + } + } + + // -------------- EMP MOBILE NUMBER UPDATE API'S ------------------------------------------------------------------------------------------------------------- + + public function updateMobileNumber() + { + log_message('error', ' '); + log_message('error', ' ************************************* UPDATE MOBILE START **************************************** '); + log_message('error', ' '); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Function called"); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Received payload = " . json_encode($this->request->getJSON() ?? [])); + + try { + + $payload = $this->request->getJSON(true); + + $email_id = $payload['email_id'] ?? null; + $client_id = $payload['client_id'] ?? null; + $new_mobile = $payload['new_mobile_number'] ?? null; + + if (empty($email_id) || empty($new_mobile)) { + return $this->respond([ + 'status' => 'failed', + 'code' => 400, + 'message' => 'Email ID and new mobile number are required' + ], 400); + } + + // Fetch employee by email + $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('employees.is_active', 1) + ->whereIn('employees.emp_status', ['active']) + ->where('employee_polices.is_active', 1) + ->whereIn('employee_polices.status', ['active']); + + if (!empty($client_id)) { + $builder->where('employees.client_id', $client_id); + } + + $employeeData = $builder->orderBy('employees.id', 'desc')->first(); + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: employeeData: " . json_encode($employeeData ?? [])); + + if (!$employeeData) { + return $this->respond([ + 'status' => 'failed', + 'code' => 404, + 'message' => 'User not found with this Email ID' + ], 404); + } + + // Update mobile number + $updated = $this->employeeModel->update($employeeData['id'], [ + 'mobile' => $new_mobile, + ]); + + if ($updated) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Mobile number updated successfully"); + log_message('error', ' '); + log_message('error', ' ************************************* UPDATE MOBILE END **************************************** '); + log_message('error', ' '); + + return $this->respond([ + 'status' => 'success', + 'code' => 200, + 'message' => 'Mobile number updated successfully' + ], 200); + } else { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Failed to update mobile number"); + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => 'Failed to update mobile number' + ], 500); + } + } catch (\Throwable $th) { + $this->myLogger->logme("error", "REST-AUTH-CONTROLLER - updateMobileNumber: Exception: " . $th->getMessage()); + log_message('error', ' '); + log_message('error', ' ************************************* UPDATE MOBILE END **************************************** '); + log_message('error', ' '); + return $this->respond([ + 'status' => 'failed', + 'code' => 500, + 'message' => $th->getMessage() + ], 500); + } + } } \ No newline at end of file diff --git a/app/Helpers/api_helper.php b/app/Helpers/api_helper.php index 95096fdb..ad25d3b4 100644 --- a/app/Helpers/api_helper.php +++ b/app/Helpers/api_helper.php @@ -58,6 +58,8 @@ if (!function_exists('call_third_party_api')) { ]; } + // echo ($response); die; + $decoded = json_decode($response, true); return [ diff --git a/app/Models/TpaApiSeviceModel.php b/app/Models/TpaApiSeviceModel.php new file mode 100644 index 00000000..9801614a --- /dev/null +++ b/app/Models/TpaApiSeviceModel.php @@ -0,0 +1,19 @@ +