diff --git a/.env.sample b/.env.sample index cd4743fb..e834a822 100755 --- a/.env.sample +++ b/.env.sample @@ -111,4 +111,12 @@ FHPL_PRIMARY_KEY_CONSTANT = VIDAL_PRIMARY_KEY_CONSTANT = -MEDI_ASSIST_PRIMARY_KEY_CONSTANT = \ No newline at end of file +MEDI_ASSIST_PRIMARY_KEY_CONSTANT = + + +FHPL_TOKEN_URL = +FHPL_BASE_URL = +FHPL_USER_NAME = +FHPL_PASSWORD = +FHPL_GRANT_TYPE = + diff --git a/app/Config/Routes.php b/app/Config/Routes.php index b31bbbfa..129e9d4e 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -429,6 +429,7 @@ $routes->group("/util", ["filter" => "authMVC"], function ($routes) { $routes->get('proceedExcelFileDataValidation', 'EmployeeController::proceedExcelFileDataValidation'); $routes->get('checkTpaApiEnable', 'EmployeeRestController::checkTpaApiEnable'); $routes->get('generateDemographyDataTable', 'LeadsController::generateDemographyDataTable'); + $routes->post('insufficientCdBalanceHrMailSend', 'EmployeeController::insufficientCdBalanceHrMailSend'); }); $routes->post("policy_tranction/sendInstallmentRemainderMail","PolicyTransactionController::sendInstallmentRemainderMail"); @@ -772,11 +773,11 @@ $routes->get('fetchUHIDDetails','ICICILombardController::fetchUHIDDetails'); //Third party - testing route $routes->get('FhplGetBenefDetails','FhplApiController::FhplGetBenefDetails'); -$routes->get('EcardRequest','VidalApiController::EcardRequest'); +$routes->get('EcardRequest','FhplApiController::EcardRequest'); $routes->get('HospitalNetwork','MediAssistApiController::HospitalNetwork'); $routes->get('VidalGetBenefDetails','VidalApiController::VidalGetBenefDetails'); $routes->get('ClaimDetail','FhplApiController::ClaimDetail'); -$routes->get('SubmitClaim','FhplApiController::SubmitClaim'); +$routes->get('SubmitClaim','VidalApiController::SubmitClaim'); $routes->get('IntimateClaim','MediAssistApiController::IntimateClaim'); $routes->get('IRSubmission','MediAssistApiController::IRSubmission'); $routes->get('ClaimStatusUpdate','MediAssistApiController::ClaimStatusUpdate'); diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php index 7c256f40..075a7e01 100644 --- a/app/Controllers/ApiServiceController.php +++ b/app/Controllers/ApiServiceController.php @@ -12,6 +12,7 @@ use App\Controllers\BaseController; use App\Controllers\VidalApiController; use App\Controllers\ICICILombardController; use App\Controllers\MediAssistApiController; +use App\Controllers\FhplApiController; use App\Models\BatchFileModel; use App\Models\FileModel; use App\Helpers\TPADataCompareHelper; @@ -26,6 +27,7 @@ class ApiServiceController extends BaseController protected $medi_assist_primary_key; protected $vidal_primary_key; protected $icici_primary_key; + protected $fhpl_primary_key; public function __construct() { @@ -34,6 +36,7 @@ class ApiServiceController extends BaseController $this->medi_assist_primary_key = getenv('MEDI_ASSIST_PRIMARY_KEY_CONSTANT'); $this->vidal_primary_key = getenv('VIDAL_PRIMARY_KEY_CONSTANT'); $this->icici_primary_key = getenv('ICICI_PRIMARY_KEY_CONSTANT'); + $this->fhpl_primary_key = getenv('FHPL_PRIMARY_KEY_CONSTANT'); } // Push Claims @@ -55,6 +58,10 @@ class ApiServiceController extends BaseController { // Vidal $vidalApiController = new VidalApiController; return $vidalApiController->SubmitClaim($claimId); + }else if ($tpaID == $this->fhpl_primary_key) + { // fhpl + $fhplApiController = new FhplApiController; + return $fhplApiController->SubmitClaim($claimId); }else{ log_message('error', "This ticket id ( {$claimId} ) TPA has no API service enabled. TPA ID : {$tpaID}"); } @@ -130,6 +137,12 @@ class ApiServiceController extends BaseController $vidalApiController = new VidalApiController; $data['eCardDownload'] = $vidalApiController->EcardRequest( $emp_code, $policy_no , $employee_policy[0]['tpa_id'] ); + }else if($employee_policy[0]['tpa_primary_id'] == $this->fhpl_primary_key)// Fhpl + { + + $fhplApiController = new FhplApiController; + $data['eCardDownload'] = $fhplApiController->EcardRequest( $emp_code, $policy_no , $employee_policy[0]['tpa_id'] ); + }else{ if($type == "download"){ @@ -266,6 +279,17 @@ class ApiServiceController extends BaseController return $this->respond(['status' => true, 'code' => 200, 'message' => 'Action Triggered','data' => [] ]); + }else if ($tpa_id == $this->fhpl_primary_key) // Fhpl + { + $file_id = $fileModel->insert($data); + log_message('error', "Files table inserted successfully, File id : {$file_id}"); + // $fhplApiController = new FhplApiController; + // $fhplApiController->FhplGetBenefDetails( [ 'polict_no' => $policy_no, 'file_id' =>$file_id ] ); + $r = Jobs::addJob(['job_name' => 'FhplGetBenefDetails', 'payload' => ['policy_no' => $policy_no, 'file_id' => $file_id, 'client_policy_id' => $policy_id, 'return_type' => 'job']]); + log_message('error', "FhplGetBenefDetails job pushed successfully."); + + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Action Triggered','data' => [] ]); + }else{ return $this->respond(['status' => false, 'code' => 200,'message' => 'TPA not found ','data' => [] ]); } @@ -287,12 +311,20 @@ class ApiServiceController extends BaseController if ($tpaID == $this->medi_assist_primary_key) { // MediAssist $mediAssistController = new MediAssistApiController(); - return $mediAssistController->ClaimDetail($claimId); + $res = $mediAssistController->ClaimDetail($claimId); + return $this->response->setJSON(['status' => $res['status'],'message' => $res['message'] ]); }else if ($tpaID == $this->vidal_primary_key) { // vidal $vidalApiController = new VidalApiController; - return $vidalApiController->ClaimDetail($claimId); + $res = $vidalApiController->ClaimDetail($claimId); + return $this->response->setJSON(['status' => $res['status'],'message' => $res['message'] ]); + + }else if ($tpaID == $this->fhpl_primary_key) { // Fhpl + + $fhplApiController = new FhplApiController; + $res = $fhplApiController->ClaimDetail($claimId); + return $this->response->setJSON(['status' => $res['status'],'message' => $res['message'] ]); }else{ log_message('error', "This ticket id ( {$claimId} ) TPA has no API service enabled. TPA ID : {$tpaID}"); diff --git a/app/Controllers/ClientController.php b/app/Controllers/ClientController.php index 2c79d18b..c16c20eb 100755 --- a/app/Controllers/ClientController.php +++ b/app/Controllers/ClientController.php @@ -1015,10 +1015,9 @@ class ClientController extends AdminController ] ], 'short_name' => [ - 'rules' => 'required|alpha', + 'rules' => 'required', 'errors' => [ 'required' => 'Client Short Name is required', - 'alpha' => 'Client Short Name can only contain alphabets.', ] ], 'pan' => [ @@ -1810,7 +1809,7 @@ class ClientController extends AdminController } if ($insert) { - $branchData = $this->clientBranchModel->where('client_id', $sanitized_post_data('client_id'))->findAll(); + $branchData = $this->clientBranchModel->where('client_id', $sanitized_post_data['client_id'])->findAll(); $branchData['role'] = get_role_id(); return $this->respond([ 'status' => true, @@ -1832,6 +1831,7 @@ class ClientController extends AdminController $this->myLogger->logme('error', 'Client branch EDIT function called'); $data = $this->request->getPost(); + $sanitized_post_data = sanitizeInputArrayAdvanced($data); $id = $sanitized_post_data['branch_id_primarykey'] ?? null; $client_id = $sanitized_post_data['client_id'] ?? null; @@ -1839,7 +1839,7 @@ class ClientController extends AdminController $data['pre_branch_id'] = $pre_branch_id; - $units = $sanitized_post_data['units'] ?? null; + $raw_units = $this->request->getPost('units'); $emp_unit_count = 0; $rr_unit_count = 0; @@ -1847,12 +1847,13 @@ class ClientController extends AdminController $total_count = 0; $list_of_branch_units = $this->clientBranchModel->find((int)$id); - $units = json_decode($list_of_branch_units['units']); + $units = !empty($list_of_branch_units['units']) ? json_decode($list_of_branch_units['units'], true) : []; if (!is_array($units) || empty($units)) { $client_data = $this->clientModel->where('id', $sanitized_post_data['client_id'])->first(); $default_unit = trim(($client_data['short_name'] ?? '') . '-' . ($sanitized_post_data['branch_code'] ?? ''), '-'); $sanitized_post_data['units'] = json_encode([$default_unit]); + $units = [$default_unit]; // Update local variable for counting } if (!empty($units)) { @@ -1867,17 +1868,21 @@ class ClientController extends AdminController $uncommonValues = []; + if ($total_count > 0) { - $units = (string) $sanitized_post_data('units'); // Assuming 'units' is an array + + $post_units_raw = $sanitized_post_data['units'] ?? '[]'; - $list_of_branch_units = $this->clientBranchModel->find((int)$id); - $branch_units = json_decode($list_of_branch_units['units'], true); - $units = json_decode($units); - - $uncommonValues = array_diff($branch_units, $units); + $branch_units = json_decode($list_of_branch_units['units'] ?? '[]', true); + + // Ensure we handle both string-json and array types + $incoming_units = is_array($post_units_raw) ? $post_units_raw : json_decode($post_units_raw, true); + + if (is_array($branch_units) && is_array($incoming_units)) { + $uncommonValues = array_diff($branch_units, $incoming_units); + } if (count($uncommonValues) > 0) { - $branchData = $this->clientBranchModel->where('client_id', $client_id)->findAll(); return $this->respond([ @@ -1889,7 +1894,7 @@ class ClientController extends AdminController ], 200); } } - + if (!isset($sanitized_post_data['sez'])) { $sanitized_post_data['sez'] = 0; } elseif ($sanitized_post_data['sez']) { @@ -2036,7 +2041,7 @@ class ClientController extends AdminController $this->myLogger->logme('error', 'Client policy CREATE function called'); $request_post_data = $this->request->getPost(); - $$sanitized_post_data = sanitizeInputArrayAdvanced($request_post_data); + $sanitized_post_data = sanitizeInputArrayAdvanced($request_post_data); $policy_type_id = $sanitized_post_data['policy_type_id'] ?? null; $client_branch_id = $sanitized_post_data['client_branch_id'] ?? null; @@ -2070,10 +2075,12 @@ class ClientController extends AdminController $sanitized_post_data['earned_premium_date'] = change_date_format($sanitized_post_data['earned_premium_date'] ?? null, 'd-m-Y', 'Y-m-d') ?? null; $sanitized_post_data['claims_incurred_date'] = change_date_format($sanitized_post_data['claims_incurred_date'] ?? null, 'd-m-Y', 'Y-m-d') ?? null; - $sanitized_post_dataa['base_policy'] = ($sanitized_post_data['base_policy'] === '' || $sanitized_post_data['base_policy'] == 0) ? null : $sanitized_post_data['base_policy']; - $sanitized_post_data['policy_status'] = 1; - $sanitized_post_data['inception_type'] = $sanitized_post_data['inception_type'] ? 2 : 1; - + $sanitized_post_data['base_policy'] = ($sanitized_post_data['base_policy'] === '' || $sanitized_post_data['base_policy'] == 0) ? null : $sanitized_post_data['base_policy']; + $sanitized_post_data['policy_status'] = 1; + $sanitized_post_data['inception_type'] = (isset($sanitized_post_data['inception_type']) && $sanitized_post_data['inception_type'] !== "") + ? $sanitized_post_data['inception_type'] + : 1; + @@ -2104,7 +2111,7 @@ class ClientController extends AdminController $sanitized_post_data['policy_start_date'] = change_date_format($sanitized_post_data['policy_start_date'] ?? null, 'd-m-Y', 'Y-m-d'); $sanitized_post_data['policy_end_date'] = change_date_format($sanitized_post_data['policy_end_date'] ?? null, 'd-m-Y', 'Y-m-d'); $sanitized_post_data['policy_no'] = $sanitized_post_data['policy_no'] ?? null; - if ($sanitized_post_data['inception_type'] == 2) { + if (isset($sanitized_post_data['inception_type']) && $sanitized_post_data['inception_type'] == 2) { $sanitized_post_data['open_date'] = change_date_format($sanitized_post_data['open_date'] ?? null, 'd-m-Y', 'Y-m-d'); $sanitized_post_data['close_date'] = change_date_format($sanitized_post_data['close_date'] ?? null, 'd-m-Y', 'Y-m-d'); // $data['reminder_date'] = change_date_format($this->request->getPost('reminder_date'), 'd-m-Y', 'Y-m-d'); @@ -2121,7 +2128,7 @@ class ClientController extends AdminController if ($insert) { $clientPoliceData = $this->clientPolicyModel->getClientPolicyByClientId($sanitized_post_data['client_id']); $clientPoliceData['role'] = get_role_id(); - return $this->respond(['status' => true, 'code' => 200, 'data' => $clientPoliceData, 'client_id' => $client_id, 'method' => 'CERATE', 'post_data' => $insert_data], 200); + return $this->respond(['status' => true, 'code' => 200, 'data' => $clientPoliceData, 'client_id' => $client_id, 'method' => 'CERATE', 'post_data' => $insert], 200); } else { return $this->respond(['status' => false, 'code' => 404, 'message' => 'no data found'], 200); } @@ -5614,32 +5621,25 @@ class ClientController extends AdminController ], 'type' => [ - 'rules' => 'required|is_natural_no_zero', + 'rules' => 'required', 'errors' => [ 'required' => 'Vehicle type is required' ] ], 'description' => [ - 'rules' => 'required|is_natural_no_zero', + 'rules' => 'required', 'errors' => [ 'required' => 'Vehicle description is required' ] ], 'owner' => [ - 'rules' => 'required|is_natural_no_zero', + 'rules' => 'required', 'errors' => [ 'required' => 'Owner is required' ] ], - 'old_onwer' => [ - 'rules' => 'permit_empty|alpha_space', - 'errors' => [ - 'alpha_space' => 'Old owner name can contain only letters and spaces' - ] - ], - ]; if (!$this->validate($rules)) { return $this->response->setStatusCode(400)->setJSON([ @@ -6693,27 +6693,27 @@ class ClientController extends AdminController // ----------EMP DATA SERVICE CONTROLLER-------------------------------------------------------------------------------- - $batch_data = [ - 'client_id' => 51, - 'client_branch_id' => 40, - 'client_policy_id' => 63, - 'insurer_or_tpa' => "insurer", - 'event_type' => "correction", - 'actions' => "export", - 'file_name' => "deletion_enhancement_test_file.xlsx", - ]; - // $batch_data = [ - // 'client_id' => 20, - // 'client_policy_id' => 77, - // 'client_branch_id' => 72, + // 'client_id' => 51, + // 'client_branch_id' => 40, + // 'client_policy_id' => 63, // 'insurer_or_tpa' => "insurer", - // // 'insurer_or_tpa' => "tpa", - // 'event_type' => "si_enhancement", - // 'file_name' => "si_enhancement_test_file.xlsx", + // 'event_type' => "correction", // 'actions' => "export", + // 'file_name' => "deletion_enhancement_test_file.xlsx", // ]; + $batch_data = [ + 'client_id' => 12, + 'client_policy_id' => 8063, + 'client_branch_id' => 1, + 'insurer_or_tpa' => "insurer", + // 'insurer_or_tpa' => "tpa", + 'event_type' => "inception", + 'file_name' => "si_enhancement_test_file.xlsx", + 'actions' => "export", + ]; + // $batch_data['insurer_or_tpa'] = 'insurer'; // $batch_data['insurer_or_tpa'] = 'tpa'; @@ -6768,6 +6768,21 @@ class ClientController extends AdminController // $EmpDataServiceController->cashDepositCalculationForDeletion($array); // $result = $this->employeePolicyModel->getInceptionEmployeeDataForExportExcel($batch_data); + // $totals = 0; + // foreach ($result as $item) { + // $totals = $totals + $item->total; + // } + + // clear_cd_balance_session(); + + // $data = [ + // 'cd_balance' => session()->get('cd_balance'), + // 'hr_data' => session()->get('hr_data'), + // 'cd_balance_info' => session()->get('cd_balance_info'), + // get_cd_balance() + // ]; + + // dd($data); // $result = $this->employeePolicyModel->getCorrectionEmployeesDataForExportExcel($batch_data); // dd(db_connect()->getLastQuery()); diff --git a/app/Controllers/EmpDataServiceController.php b/app/Controllers/EmpDataServiceController.php index ff86177d..8d75b095 100755 --- a/app/Controllers/EmpDataServiceController.php +++ b/app/Controllers/EmpDataServiceController.php @@ -33,6 +33,8 @@ use App\Models\LeadsModel; use App\Models\LeadInstallmentPaymentDetails; use App\Models\PolicyTransactionModel; use App\Models\PTCOShareDetailsModel; +use App\Models\LevelContactModel; + use App\Controllers\Jobs; use App\Controllers\JobWorker; @@ -71,6 +73,8 @@ class EmpDataServiceController extends BaseController protected $leadInstallmentPaymentDetailesModel; protected $policyTransactionModel; protected $PTCOShareDetailsModel; + protected $LevelContactModel; + public function __construct() @@ -99,6 +103,7 @@ class EmpDataServiceController extends BaseController $this->leadInstallmentPaymentDetailesModel = new LeadInstallmentPaymentDetails(); $this->policyTransactionModel = new PolicyTransactionModel(); $this->PTCOShareDetailsModel = new PTCOShareDetailsModel(); + $this->LevelContactModel = new LevelContactModel(); } @@ -199,23 +204,28 @@ class EmpDataServiceController extends BaseController $totals = $totals + $item->total; } - $totals = round($totals, 2); + $totals = round($totals); //check CD amt insufficient only insurer, not tpa // DO NOT REMOVE THIS if($export_data['insurer_or_tpa'] == 'insurer') { if (!empty($cash_balance)) { - if ((int) $cash_balance['balance'] < (int) $totals) { + clear_cd_balance_session(); + if ((int) $cash_balance['balance'] == (int) $totals) { $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount.'); $this->myLogger->logme('error', 'Inception export failed due to insufficient deposit amount. CASH BALANCE : {balance} and TOTAL AMOUNT : {total}', ['balance' => $cash_balance['balance'], 'total' => $totals]); - session()->set('cd_balance', false); - session()->set('cd_amount', $cash_balance['balance']); - session()->set('excel_file_amt', $totals); + + $cd_session_data = json_encode(['cd_balance' => false, 'cd_amount' => $cash_balance['balance'], 'excel_file_amt' => $totals]); + session()->set('cd_balance_info', $cd_session_data); + session()->set('cd_balance', false); + + $hr_data = $this->getHrdataForInsufficientMailSend($export_data['client_branch_id']); + $session_data = json_encode(['client_id' => $export_data['client_id'], 'hr_data' => $hr_data]); + session()->set('hr_data', $session_data); + }else{ session()->set('cd_balance', true); - session()->set('cd_amount', $cash_balance['balance']); - session()->set('excel_file_amt', $totals); - + } } } @@ -5858,4 +5868,16 @@ class EmpDataServiceController extends BaseController 'gst' => round($amount['gst'] ?? 0, 2) ]; } + + public function getHrdataForInsufficientMailSend($ref_id) + { + $data = $this->LevelContactModel + ->select('id, name, email') + ->where('ref_id', $ref_id) + ->where('is_active', 1) + ->where('contact_type', 'client') + ->findAll(); + + return $data; + } } diff --git a/app/Controllers/EmployeeController.php b/app/Controllers/EmployeeController.php index ed60c502..edcae43c 100755 --- a/app/Controllers/EmployeeController.php +++ b/app/Controllers/EmployeeController.php @@ -8,6 +8,7 @@ use CodeIgniter\HTTP\ResponseInterface; use Psr\Log\LoggerInterface; use App\Helpers\DepositHelper; +use App\Helpers\MailHelper; use App\Models\EmployeeModel; @@ -29,6 +30,7 @@ use App\Models\AuditHistoryModel; use App\Models\UserModel; use App\Models\PartnerEndorsementRequestModel; use App\Models\TpaApiDataModel; +use App\Models\LevelContactModel; use App\Controllers\Jobs; @@ -74,6 +76,7 @@ class EmployeeController extends AdminController protected $auditHistory; protected $userModel; protected $partnerEndorsementRequestModel; + protected $LevelContactModel; public function __construct() { @@ -97,6 +100,7 @@ class EmployeeController extends AdminController $this->auditHistory = new AuditHistoryModel(); $this->userModel = new userModel(); $this->partnerEndorsementRequestModel = new PartnerEndorsementRequestModel(); + $this->LevelContactModel = new LevelContactModel(); } public function list() @@ -4528,7 +4532,7 @@ class EmployeeController extends AdminController 'details' => $result ]; - } catch (Exception $e) { + } catch (\Exception $e) { // 5. Catch network or system exceptions $this->myLogger->logme('error', 'VISIT_OFFBOARD API Exception: ' . $e->getMessage()); return [ @@ -4540,5 +4544,46 @@ class EmployeeController extends AdminController } + public function insufficientCdBalanceHrMailSend() + { + $post_data = $this->request->getJson(true); + + if(empty($post_data) || (!isset($post_data['mails']) && !empty($post_data['mails'])) || (!isset($post_data['client_id']) && !empty($post_data['client_id']))){ + return $this->respond(['status' => false, 'code' => 404, 'message' => 'No data send mail'], 200); + } + + $client_data = $this->clientModel->where('is_active', 1)->where('id', $post_data['client_id'])->first(); + + $common['mail_type'] = "insufficient_cd_balance_by_hr"; + $common['client_id'] = $post_data['client_id']; + $subject = 'Insufficient CD Balance Notification'; + $mail_content = ' + Dear {{HR_NAME}}, + + Greetings from Nhance. + + We would like to inform you that the CD balance for {{CLIENT_NAME}} is currently low / insufficient, which may impact further processing of insurance-related activities. + + Kindly request you to credit the required amount at the earliest to avoid any service disruption. + + Please let us know once the amount is credited, or if you need any clarification from our end. + + Thank you for your support and cooperation. + '; + + + foreach ($post_data['mails'] as $hr_id => $hr_data) { + + $mail_content = str_ireplace('{{HR_NAME}}', $hr_data['name'], $mail_content); + $mail_content = str_ireplace('{{CLIENT_NAME}}', $client_data['client_name'], $mail_content); + + $res = MailHelper::send_email(['mail' => $hr_data['mail'], 'subject' => $subject, 'message' => $mail_content, 'common' => $common]); + } + + return $this->respond(['status' => true, 'code' => 200, 'message' => 'Mail send successfully'], 200); + + } + + } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index fa58834a..379fe023 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -2305,8 +2305,35 @@ class EmployeeRestController extends AdminController } + if($this->request->getGet('policy_status') == 0){ + $emp_policy_status = 'expired'; + }else{ + $emp_policy_status = 'active'; + } - $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 ') + $db = \Config\Database::connect(); + $emp_policy_status = $db->escape($emp_policy_status); + + $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_start_date, '%d-%m-%Y') AS policy_start_date, + DATE_FORMAT(client_policy.policy_end_date, '%d-%m-%Y') AS policy_expiry_date, + ( + select COALESCE(ROUND(SUM(rata_premimum + gst)), 0) + from employee_polices + where is_active = 1 + and status = $emp_policy_status + and client_policy_id = client_policy.id + ) as total_premium + ", false) ->where('md5(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) @@ -2443,7 +2470,13 @@ class EmployeeRestController extends AdminController if ($this->request->is('get')) { - $data['claim_status'] = $this->claimStatusModel->select('id,ticket_type,claim_status')->where('is_active', 1)->findAll(); + $data['claim_status'] = $this->claimStatusModel + ->select('id,ticket_type, display_name as claim_status') + ->where('is_active', 1) + ->where('display_name IS NOT NULL OR display_name <> ""') + ->groupBy('display_name') + ->findAll(); + $data['ticket_type'] = [ ["ticket_type" => "1", "type_name" => "Claim-GMC"], ["ticket_type" => "2", "type_name" => "Claim-GPA"], @@ -2460,10 +2493,12 @@ class EmployeeRestController extends AdminController $client_id = isset($search_data['client_id']) ? (int) $search_data['client_id'] : 0; unset($search_data['client_id']); + unset($search_data['client_branch_id']); $from_date = isset($search_data['from_date']) ? $search_data['from_date'] : null; $to_date = isset($search_data['to_date']) ? $search_data['to_date'] : null; - unset($search_data['from_date'], $search_data['to_date']); + $claim_status_id = isset($search_data['claim_status_id']) ? $search_data['claim_status_id'] : null; + unset($search_data['from_date'], $search_data['to_date'], $search_data['claim_status_id']); $where = []; @@ -2474,6 +2509,11 @@ class EmployeeRestController extends AdminController } } + $claim_status_ids = []; + if(!empty($claim_status_id)){ + $claim_status_ids = $this->getTicketClaimStatusIdBasedOnTheDisplayName($claim_status_id); + } + $builder = $db->table('ticket_master tm'); $builder->select([ 'tm.id', @@ -2485,6 +2525,12 @@ class EmployeeRestController extends AdminController ELSE UPPER(tcs.display_name) END AS status ", + "CASE + WHEN tm.tpa_claim_type IS NOT NULL OR tm.tpa_claim_type != '' + THEN tm.tpa_claim_type + ELSE 'Reimbursement' + END AS cl_type + ", 'tm.claim_number AS claim_no', 'tm.claim_status_id', 'tm.is_head_approved', @@ -2568,6 +2614,10 @@ class EmployeeRestController extends AdminController $builder->where($where); } + if (!empty($claim_status_ids)) { + $builder->whereIn('claim_status_id', $claim_status_ids); + } + $builder->orderBy('tm.id', 'DESC'); $data = $builder->get()->getResultArray(); @@ -5305,6 +5355,20 @@ class EmployeeRestController extends AdminController return $this->respond(['status' => false, 'code' => 400, 'message' => 'Failed to upload the file'], 200); } } + + public function getTicketClaimStatusIdBasedOnTheDisplayName($claim_status_id) + { + $claim_status_data_display_name = $this->claimStatusModel->where('is_active', 1)->where('id', $claim_status_id)->first(); + $claim_status_data_id = $this->claimStatusModel + ->select('id') + ->where('is_active', 1) + ->where('display_name', $claim_status_data_display_name['display_name']) + ->findAll(); + + $claim_status_data_id = array_column($claim_status_data_id, 'id'); + return $claim_status_data_id; + } + } diff --git a/app/Controllers/FhplApiController.php b/app/Controllers/FhplApiController.php index 9497433c..f2ac8b17 100644 --- a/app/Controllers/FhplApiController.php +++ b/app/Controllers/FhplApiController.php @@ -69,7 +69,7 @@ class FhplApiController extends BaseController ]); } - public function SubmitClaim($claimId = 515) + public function SubmitClaim($claimId = null) // 515 { helper('api'); @@ -99,7 +99,7 @@ class FhplApiController extends BaseController if (count($data) && $data['filePath'] == null) { log_message('error', "TPA CLAIM PUSH FAILED FHPL | claimId: '.$claimId.' - Claim or File Missing"); - return $this->response->setJSON(['status' => false,'message' => 'Claim or File Missing', ]); + return; } // Build absolute file path @@ -108,7 +108,7 @@ class FhplApiController extends BaseController if (!file_exists($pdfPath)) { log_message('error', "TPA CLAIM PUSH FAILED FHPL | claimId: '.$claimId.' - PDF not found on server"); - return $this->response->setJSON(['status' => false,'message' => 'PDF not found on server']); + return; } // Convert PDF to Base64 @@ -117,7 +117,8 @@ class FhplApiController extends BaseController // Generate FHPL Token $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); if (empty($tokenResponse['data']['access_token'])) { - return $this->response->setJSON(['status' => false,'message' => 'FHPL Token generation failed']); + log_message('error', "TPA CLAIM PUSH FAILED FHPL | claimId: '.$claimId.' - FHPL Token generation failed"); + return; } $token = $tokenResponse['data']['access_token']; @@ -125,10 +126,10 @@ class FhplApiController extends BaseController $body = [ "IssueID" => $data['dependentUniqueId'], // this key added after seeing the error in responce have to click with fhpl team "Userid" => getenv('FHPL_USER_NAME'), - "PolicyNo" => "111700-TATAMTORS", // $data['policyNo'], - "UhidNo" => "OIC40830846", //$data['dependentUniqueId'], + "PolicyNo" => $data['policyNo'], // "111700-TATAMTORS", + "UhidNo" => $data['dependentUniqueId'], // "OIC40830846", "ClaimID" => (string) $data['id'], - "DOA" => "2025-10-11",//date('Y-m-d', strtotime($data['admissionDate'])), + "DOA" => date('Y-m-d', strtotime($data['admissionDate'])), //"2025-10-11", "DateofDischarge"=> $data['dischargeDate'] ? date('Y-m-d', strtotime($data['dischargeDate'])) : null, "ClaimedAmount" => (float) $data['requestedAmount'], "DocumentType" => 20, // Fresh Claim @@ -155,7 +156,7 @@ class FhplApiController extends BaseController $response = call_third_party_api($url, 'POST', $headers, $body); - log_message('error', 'FHPL RESPONSE | ' . json_encode($response)); + log_message('error', 'TPA CLAIM PUSH FHPL RESPONSE | ' . json_encode($response)); if($response['status'] != true){ log_message('error', 'TPA CLAIM PUSH FAILED FHPL | claimId: '.$claimId.' | response: '.json_encode($response)); @@ -185,14 +186,17 @@ class FhplApiController extends BaseController log_message('error', 'TPA CLAIM PUSH SUCCESS FHPL | claimId: '.$claimId.' | claimNO: '.$fhplClaimNo); + }else { + log_message('error', 'TPA CLAIM PUSH API SUCCESS BUT claimsInfo EMPTY | response: '.json_encode($response)); + return; } } - - return $this->response->setJSON($response); + return; + // return $this->response->setJSON($response); } - public function ClaimDetail($claimId = 515) + public function ClaimDetail($claimId = null) //515 { helper('api'); @@ -203,13 +207,13 @@ class FhplApiController extends BaseController ->get()->getRowArray(); - if(!$ticket) return $this->response->setJSON(['status'=>false,'message'=>'Invalid claim']); + if(!$ticket) return ['status'=>false,'message'=>'Invalid claim']; // Generate FHPL Token $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); if (empty($tokenResponse['data']['access_token'])) { - return $this->response->setJSON(['status' => false,'message' => 'FHPL Token generation failed']); + return ['status' => false,'message' => 'FHPL Token generation failed']; } $token = $tokenResponse['data']['access_token']; @@ -219,9 +223,9 @@ class FhplApiController extends BaseController $body = [ "UserName" => getenv('FHPL_USER_NAME'), "Password" => getenv('FHPL_PASSWORD'), - "PolicyNumber" => "GHI-81-25-00087313-000",//$ticket['policy_no'], - "Fromdate" => "2025-04-26",//$ticket['claimNo'], - "Todate" => "2025-04-27",//$ticket['claimNo'], + "PolicyNumber" => $ticket['policy_no'], //"GHI-81-25-00087313-000", + "Fromdate" => $ticket['policy_start_date'],//"2025-04-26", + "Todate" => $ticket['policy_end_date'],//"2025-04-27", ]; $headers = ["Authorization: Bearer ".$token,"Content-Type: application/json"]; @@ -232,12 +236,7 @@ class FhplApiController extends BaseController if (empty($response['data'][0])) { log_message('error', 'CLAIM STATUS FAILED | for ticket ID: ' . $claimId.' | response: '.json_encode($response)); - - return $this->response->setJSON([ - 'status' => false, - 'message' => 'API call failed.', - 'data' => $response - ]); + return ['status' => false,'message' => 'API call failed.','data' => $response ]; } @@ -263,18 +262,11 @@ class FhplApiController extends BaseController if( $status != null && isset($map[$status])) { $this->db->table('ticket_master')->where('id',$claimId)->update(['claim_status_id'=>$map[$status],'tpa_claim_status'=>$status]); - // LOG UPDATE log_message('error', "CLAIM STATUS SUCCESS | Updated ticket ID $claimId with claim status: $status"); } - - return $this->response->setJSON([ - 'status' => true, - 'message' => 'Claim status updated.', - 'updated_status' => $status, - 'api_response' => $response - ]); + return ['status' => true,'message' => 'Claim status updated.','updated_status' => $status,'api_response' => $response]; } @@ -298,24 +290,16 @@ class FhplApiController extends BaseController return $this->response->setJSON(['status'=>true,'updated'=>$count]); } - public function EcardRequest($employeeId,$policyNo,$uhid) + public function EcardRequest($employeeId = null,$policyNo = null,$uhid = null) { helper('api'); // Generate FHPL Token $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); - if (empty($tokenResponse['data']['access_token'])) { - return $this->response->setJSON(['status' => false,'message' => 'FHPL Token generation failed']); + log_message('error', 'Ecard Request FAILED | employeeId: '.$employeeId.' | policyNo: '.$policyNo.' | Message: FHPL Token generation failed'); + return null; } - - // Generate FHPL Token - $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); - - if (empty($tokenResponse['data']['access_token'])) { - return $this->response->setJSON(['status' => false,'message' => 'FHPL Token generation failed']); - } - $token = $tokenResponse['data']['access_token']; $url = getenv('FHPL_BASE_URL')."/api/GetEcard"; @@ -323,107 +307,402 @@ class FhplApiController extends BaseController $body = [ "UserName" => getenv('FHPL_USER_NAME'), "Password" => getenv('FHPL_PASSWORD'), - "PolicyNumber" => $policyNo, - "EmployeeID" => $employeeId + "PolicyNumber" => $policyNo, //'10/12/2025/16/17', + "EmployeeID" => $employeeId, //'101225', ]; $headers = ["Authorization: Bearer ".$token,"Content-Type: application/json"]; $response = call_third_party_api($url,'POST',$headers,$body); + // dd($response); - if(($response['data']['STATUS'] ?? '')=='SUCCESS'){ - return $response['data']['E_Card']; + if (($response['status'] ?? false) !== true) { + log_message('error', 'Ecard Request FAILED | response: ' . json_encode($response)); + return null; } + if (empty($response['data'][0])) { + log_message('error', 'Ecard Request FAILED | Empty data | response: ' . json_encode($response)); + return null; + } + + $apiData = $response['data'][0]; + + if (($apiData['STATUS'] ?? '') === 'SUCCESS') { + + $ecardUrl = $apiData['E_Card'] ?? ''; + + if (!empty($ecardUrl)) { + log_message( + 'info', + 'Ecard Request PUSH SUCCESS | employeeId: ' . $employeeId . + ' | policyNo: ' . $policyNo . + ' | ecardUrl: ' . $ecardUrl + ); + return $ecardUrl; + } + } + + log_message('error', 'Ecard Request FAILED | response: ' . json_encode($response)); return null; } public function FhplGetBenefDetails($requestData = null) { - helper('api'); - $policyNo = $requestData['policy_no'] ?? "10/12/2025/16/17"; - $client_policy_id = $requestData['client_policy_id'] ?? 0; + $function_calling_type = $requestData['return_type'] ?? 'job'; - // Generate FHPL Token - $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); - if (empty($tokenResponse['data']['access_token'])) { - return $this->response->setJSON(['status' => false,'message' => 'FHPL Token generation failed']); - } - $token = $tokenResponse['data']['access_token']; + try { + + helper('api'); - $url = getenv('FHPL_BASE_URL')."/api/GetEnrollmentDetailsPolicy"; + $policyNo = $requestData['policy_no'] ?? null; + $client_policy_id = $requestData['client_policy_id'] ?? null; - $headers = [ - "Authorization: Bearer ".$token, - "Content-Type: application/json" - ]; - - $startIndex = 0; - $range = 100; - $allMembers = []; - - do { - $body = [ - "UserName" => getenv('FHPL_USER_NAME'), - "Password" => getenv('FHPL_PASSWORD'), - "PolicyNumber" => $policyNo, - "StartIndex" => $startIndex, - "Range" => $range - ]; - - $response = call_third_party_api($url,'POST',$headers,$body); - - dd($response); - - if(empty($response['data']['Members'])){ - break; - } - - $allMembers = array_merge($allMembers,$response['data']['Members']); - - $startIndex += $range; - - } while($startIndex < ($response['data']['Total'] ?? 0)); - - - dd($allMembers); - - // Now same matching logic you already have - $employeePolicyModel = new EmployeePolicyModel(); - - $employeePolicyData = $employeePolicyModel - ->join('employees','employees.id=employee_polices.employee_id') - ->where('employee_polices.client_policy_id',$client_policy_id) - ->where('employee_polices.tpa_id IS NULL') - ->findAll(); - - $updated = 0; - - foreach($employeePolicyData as $policy){ - foreach($allMembers as $m){ - - if( - strtolower(trim($policy['name']))==strtolower(trim($m['Name'])) && - $policy['emp_code']==$m['MemberID'] && - strtolower($policy['relationship'])==strtolower($m['Relation']) - ){ - $this->db->table('employee_polices') - ->where('id',$policy['emp_policy_id']) - ->update(['tpa_id'=>$m['UHID']]); - - $updated++; + if (empty($policyNo)) { + log_message('error', 'TPA ID PULL | policy_no missing in request'); + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'policy_no required']; + }else{ + return $this->respond(['status' => false, 'message' => 'policy_no required']); } } - } - return [ - 'status'=>true, - 'total_fetched'=>count($allMembers), - 'updated'=>$updated - ]; + if (empty($client_policy_id)) { + log_message('error', 'TPA ID PULL | client_policy_id missing in request'); + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'client_policy_id required']; + }else{ + return $this->respond(['status' => false, 'message' => 'client_policy_id required']); + } + } + + log_message('error', "TPA ID PULL | called for policy_no: {$policyNo} , client_policy_id: {$client_policy_id}"); + + // Fetch file download dates + $batchFiles = $this->db->table('batch_files f') + ->select("f.created_at") + ->where('f.client_policy_id', $client_policy_id) + ->where('f.insurer_or_tpa', 'tpa') + ->where('f.actions', 'export') + ->get() + ->getResultArray(); + + if (empty($batchFiles)) { + log_message('error', 'TPA ID PULL FAILED | batchFiles is empty for this tpa id pull request'); + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'batchFiles not found']; + }else{ + return $this->respond(['status' => false, 'message' => 'batchFiles not found']); + } + } + + // Generate FHPL Token + $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); + if (empty($tokenResponse['data']['access_token'])) { + log_message('error', 'TPA ID PULL | FHPL Token generation failed'); + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'FHPL Token generation failed']; + }else{ + return $this->respond(['status' => false, 'message' => 'FHPL Token generation failed']); + } + } + $token = $tokenResponse['data']['access_token']; + + $url = getenv('FHPL_BASE_URL') . "/api/GetEnrollmentDetailsPolicy"; + + $headers = [ + "Authorization: Bearer " . $token, + "Content-Type: application/json" + ]; + + $startIndex = 0; + $range = 100; + $allMembers = []; + + while (true) { + + $body = [ + "UserName" => getenv('FHPL_USER_NAME'), + "Password" => getenv('FHPL_PASSWORD'), + "PolicyNumber" => $policyNo, + "StartIndex" => $startIndex, + "Range" => $range + ]; + + log_message('error', "TPA ID PULL | API parems " . json_encode([$url, 'POST', $headers, $body])); + + $response = call_third_party_api($url, 'POST', $headers, $body); + + if (($response['status'] ?? false) !== true) { + log_message('error', 'FHPL API FAILED | response: ' . json_encode($response)); + break; + } + + if ( + !isset($response['data']) || + !is_array($response['data']) || + count($response['data']) === 0 || + !array_is_list($response['data']) // PHP 8+ safe check + ) { + // STOP when data is not a valid list + break; + } + + $allMembers = array_merge($allMembers, $response['data']); + + // Move to next page + $startIndex += $range; + } + + if(empty($allMembers)) + { + + // update file table status after the tpa id failed to update + if (isset($requestData['file_id']) && !empty($requestData['file_id'])) { + $file_model = new BatchFileModel(); + $file_model->where('id', $requestData['file_id'])->set('status', 'failed-8')->update(); + log_message('error', "Files table status updated for the file id : {$requestData['file_id']}"); + } else { + log_message('error', "Failed to update file table status."); + } + + log_message('error', 'TPA ID PULL API FAILED | API failed: Empty menber data for this pull request'); + + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'API call failed', 'data' => 'Empty menber data for this pull request']; + }else{ + return $this->respond(['status' => false, 'message' => 'API call failed', 'data' => 'Empty menber data for this pull request']); + } + + } + + // dd($allMembers); + + //save API data as JSON for analysis + $json = json_encode($allMembers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + // $filename = time() . '.json'; + $filePath = WRITEPATH . 'tmp/'.time().'_'.$requestData['file_id'].'.json'; + file_put_contents($filePath, $json); + + //call a job for dump JSON data to DB + $job_details = new Jobs(); + $r = Jobs::addJob(['job_name' => 'saveFhplAPIData', 'payload' => [ 'file_id' => $requestData['file_id'],'json_file_path' => $filePath ]]); + + // ================= MATCHING LOGIC ================= + + $employeePolicyModel = new EmployeePolicyModel(); + + $employeePolicyData = $employeePolicyModel + ->join('employees', 'employees.id = employee_polices.employee_id') + ->where('employee_polices.client_policy_id', $client_policy_id) + ->where('employee_polices.tpa_id IS NULL') + ->findAll(); + + $updated = 0; + + foreach ($employeePolicyData as $policy) { + $hasMatchForThisPolicy = false; + foreach ($allMembers as $m) { + + if ( + strtolower(trim($policy['name'])) === strtolower(trim($m['EMPLOYEE_NAME'] ?? '')) && + ($policy['emp_code'] ?? '') == ($m['EMPLOYEE_ID'] ?? '') && + strtolower($policy['relationship']) === strtolower($m['RELATION'] ?? '') + ) { + + $hasMatchForThisPolicy = true; + + + $sql = "UPDATE employee_polices SET tpa_id = ? WHERE id = ?"; + $this->db->query($sql, [$m['TPA_TPADETAIL_ID'], $policy['emp_policy_id']]); + + // for e-card send + if(strtolower(trim($policy['relationship'])) == 'self'){ + $employee_policy_ids[] = $policy['emp_policy_id']; + } + + if ($this->db->affectedRows() > 0) { + $updated++; + log_message('error', "✅ Updated tpa_id={$m['TPA_TPADETAIL_ID']} for emp_policy_id={$policy['emp_policy_id']} policy={$policyNo}"); + } else { + log_message('error', "⚠️ No update (already set or not matched) for emp_policy_id={$policy['emp_policy_id']} policy={$policyNo}"); + } + } + } + } + + // Handle NO MATCH for this policy + if (!$hasMatchForThisPolicy) { + + $nhanceSideData = [ + 'name' => $policy_data['name'] ?? null, + 'emp_code' => $policy_data['emp_code'] ?? null, + 'relationship' => $policy_data['relationship'] ?? null, + 'gender' => $policy_data['gender'] ?? null, + 'dob' => $policy_data['dob'] ?? null, + ]; + $batch_file_success = 'partially success'; + + log_message( + 'error', + "❌ No match for Nhance = " . json_encode($nhanceSideData) + ); + } + + // send e-card + if(!empty($employee_policy_ids)){ + log_message('error', "sendMailForDownloadingECard JOB PUSHED."); + Jobs::addJob(['job_name' => 'sendMailForDownloadingECard', 'payload' => ['ids' => $employee_policy_ids, 'client_policy_id' => $client_policy_id]]); + } + + // update file table status after the tpa id successfully updated + if (isset($requestData['file_id']) && !empty($requestData['file_id'])) { + $file_model = new BatchFileModel(); + + $file_model->where('id', $requestData['file_id'])->set('status', $batch_file_success)->update(); + log_message('error', "Files table status updated for the file id : {$requestData['file_id']}"); + } else { + log_message('error', "Failed to update file table status."); + } + + $totalCount = count($allMembers); + + log_message('error', "TPA ID PULL SUCCESS | completed. Total fetched={$totalCount}, updated={$updated}"); + + if($function_calling_type == "job"){ + return [ + 'status' => true, + 'message' => 'Updated successfully', + 'total_fetched' => $totalCount, + 'total_updated' => $updated + ]; + }else{ + return $this->respond([ + 'status' => true, + 'message' => 'Updated successfully', + 'total_fetched' => $totalCount, + 'total_updated' => $updated + ]); + } + } catch (\Throwable $th) { + + // update file table status after the tpa id failed to update + if (isset($requestData['file_id']) && !empty($requestData['file_id'])) { + $file_model = new BatchFileModel(); + $file_model->where('id', $requestData['file_id'])->set('status', 'failed-8')->update(); + log_message('error', "Files table status updated for the file id : {$requestData['file_id']}"); + } else { + log_message('error', "Failed to update file table status."); + } + + $errorData = [ + 'message' => $th->getMessage(), + 'file' => $th->getFile(), + 'line' => $th->getLine(), + 'code' => $th->getCode(), + 'trace' => $th->getTraceAsString(), + 'trace_array' => $th->getTrace(), // full array version (optional) + 'function' => $th->getTrace()[0]['function'] ?? null, + 'class' => $th->getTrace()[0]['class'] ?? null, + ]; + + log_message('error', 'Exception thrown while calling GetBenefDetails API: ' . json_encode($errorData)); + if($function_calling_type == "job"){ + return ['status' => false, 'message' => 'API call failed', 'data' => $errorData]; + }else{ + return $this->respond(['status' => false, 'message' => 'API call failed', 'data' => $errorData]); + } + } } + + // public function FhplGetBenefDetails($requestData = null) + // { + // helper('api'); + + // $policyNo = $requestData['policy_no'] ?? "10/12/2025/16/17"; + // $client_policy_id = $requestData['client_policy_id'] ?? 0; + + // // Generate FHPL Token + // $tokenResponse = json_decode($this->generateAuthToken()->getBody(), true); + // if (empty($tokenResponse['data']['access_token'])) { + // return $this->response->setJSON(['status' => false,'message' => 'FHPL Token generation failed']); + // } + // $token = $tokenResponse['data']['access_token']; + + // $url = getenv('FHPL_BASE_URL')."/api/GetEnrollmentDetailsPolicy"; + + // $headers = [ + // "Authorization: Bearer ".$token, + // "Content-Type: application/json" + // ]; + + // $startIndex = 0; + // $range = 100; + // $allMembers = []; + + // do { + // $body = [ + // "UserName" => getenv('FHPL_USER_NAME'), + // "Password" => getenv('FHPL_PASSWORD'), + // "PolicyNumber" => $policyNo, + // "StartIndex" => $startIndex, + // "Range" => $range + // ]; + + // $response = call_third_party_api($url,'POST',$headers,$body); + + // dd($response); + + // if(empty($response['data']['Members'])){ + // break; + // } + + // $allMembers = array_merge($allMembers,$response['data']['Members']); + + // $startIndex += $range; + + // } while($startIndex < ($response['data']['Total'] ?? 0)); + + + // dd($allMembers); + + // // Now same matching logic you already have + // $employeePolicyModel = new EmployeePolicyModel(); + + // $employeePolicyData = $employeePolicyModel + // ->join('employees','employees.id=employee_polices.employee_id') + // ->where('employee_polices.client_policy_id',$client_policy_id) + // ->where('employee_polices.tpa_id IS NULL') + // ->findAll(); + + // $updated = 0; + + // foreach($employeePolicyData as $policy){ + // foreach($allMembers as $m){ + + // if( + // strtolower(trim($policy['name']))==strtolower(trim($m['Name'])) && + // $policy['emp_code']==$m['MemberID'] && + // strtolower($policy['relationship'])==strtolower($m['Relation']) + // ){ + // $this->db->table('employee_polices') + // ->where('id',$policy['emp_policy_id']) + // ->update(['tpa_id'=>$m['UHID']]); + + // $updated++; + // } + // } + // } + + // return [ + // 'status'=>true, + // 'total_fetched'=>count($allMembers), + // 'updated'=>$updated + // ]; + // } + public function syncFhplClaimsToNhance() { helper('api'); diff --git a/app/Controllers/JobWorker.php b/app/Controllers/JobWorker.php index 160c6fe9..f2020755 100755 --- a/app/Controllers/JobWorker.php +++ b/app/Controllers/JobWorker.php @@ -191,6 +191,10 @@ class JobWorker extends AdminController 'type' => 'CC', // Handler Category 'handler' => 'App\Controllers\VidalApiController', ], + 'FhplGetBenefDetails' => [ + 'type' => 'CC', // Handler Category + 'handler' => 'App\Controllers\FhplApiController', + ], 'bdsDumpExcelFileFormatValidation' => [ 'type' => 'CC', // Handler Category 'handler' => 'App\Controllers\PolicyTransactionController', diff --git a/app/Controllers/LeadsController.php b/app/Controllers/LeadsController.php index 8154fc82..c8413098 100644 --- a/app/Controllers/LeadsController.php +++ b/app/Controllers/LeadsController.php @@ -437,7 +437,7 @@ class LeadsController extends BaseController ]; $request_data = $this->request->getPost(); $data = sanitizeInputArrayAdvanced($request_data); - if($data['lead_form_type'] == 2){ + if (isset($data['lead_form_type']) && (int)$data['lead_form_type'] === 2) { $rules['client_type'] = [ 'rules' => 'required', 'errors' => ['required' => 'Client Type is required'] diff --git a/app/Controllers/LoginController.php b/app/Controllers/LoginController.php index fb073f21..0e118e10 100755 --- a/app/Controllers/LoginController.php +++ b/app/Controllers/LoginController.php @@ -62,7 +62,7 @@ class LoginController extends BaseController set_session_data($session_data); // Bind session to device - set_session_data(['fingerprint' => generateFingerprint()]); + // set_session_data(['fingerprint' => generateFingerprint()]); log_message('error', 'Set The UserId : `'. $user->id .'` in Session'); log_message('error', 'User Login Sucessfully'); diff --git a/app/Controllers/MasterController.php b/app/Controllers/MasterController.php index 7c46bc9a..dc6538d4 100755 --- a/app/Controllers/MasterController.php +++ b/app/Controllers/MasterController.php @@ -449,7 +449,7 @@ class MasterController extends AdminController $insert = $this->insurerBranchModel->insert($sanitized_post_data); if($insert){ - for ($i = 0; $i < count($sanitized_post_data('name')); $i++) { + for ($i = 0; $i < count($sanitized_post_data['name']); $i++) { // Prepare data to insert $sanitized_post_data_for_level = [ 'contact_type' => 'insurer', @@ -465,7 +465,7 @@ class MasterController extends AdminController } if($insert){ - $branchData = $this->insurerBranchModel->where('insurer_id', $sanitized_post_data_for_level['insurer_id'])->findAll(); + $branchData = $this->insurerBranchModel->where('insurer_id', $sanitized_post_data['insurer_id'])->findAll(); echo json_encode(array("status" => true , 'data' => $branchData)); }else{ echo json_encode(array("status" => false)); @@ -2168,72 +2168,74 @@ class MasterController extends AdminController public function createCDMasterData() { $this->myLogger->logme("error", 'Create CD Master Data API called.'); - $rules = [ - - // ====================== - // Client / Insurer Mapping - // ====================== - 'client_id' => [ - 'rules' => 'required|is_natural_no_zero', - 'errors' => [ - 'required' => 'Client is required' - ] - ], - - 'insurer_id' => [ - 'rules' => 'required|is_natural_no_zero', - 'errors' => [ - 'required' => 'Insurer is required' - ] - ], - - 'insurer_branch_id' => [ - 'rules' => 'required|is_natural_no_zero', - 'errors' => [ - 'required' => 'Insurer branch is required' - ] - ], - - // ====================== - // CD Account Details - // ====================== - 'opening_date' => [ - 'rules' => 'required|valid_date[d-m-Y]', - 'errors' => [ - 'required' => 'Opening date is required', - 'valid_date' => 'Opening date must be in DD-MM-YYYY format' - ] - ], - - 'cd_ac_no' => [ - 'rules' => 'required|trim', - 'errors' => [ - 'required' => 'CD account number is required' - ] - ], - - 'opening_bal' => [ - 'rules' => 'required|numeric|greater_than_equal_to[0]', - 'errors' => [ - 'required' => 'Opening amount is required', - 'numeric' => 'Opening amount must be numeric', - 'greater_than_equal_to' => 'Opening amount cannot be negative' - ] - ], - ]; - if (!$this->validate($rules)) { - return $this->response->setStatusCode(400)->setJSON([ - 'status' => false, - 'message' => 'Input validation failed', - 'code' => 400, - 'errors' => $this->validator->getErrors() - ]); - } $data = $this->request->getPost(); $sanitized_post_data = sanitizeInputArrayAdvanced($data); + $id = $sanitized_post_data['PrimaryKey'] ?? null; + if($id === null){ + $rules = [ + + // ====================== + // Client / Insurer Mapping + // ====================== + 'client_id' => [ + 'rules' => 'required|is_natural_no_zero', + 'errors' => [ + 'required' => 'Client is required' + ] + ], + + 'insurer_id' => [ + 'rules' => 'required|is_natural_no_zero', + 'errors' => [ + 'required' => 'Insurer is required' + ] + ], + + 'insurer_branch_id' => [ + 'rules' => 'required|is_natural_no_zero', + 'errors' => [ + 'required' => 'Insurer branch is required' + ] + ], + + // ====================== + // CD Account Details + // ====================== + 'opening_date' => [ + 'rules' => 'required|valid_date[d-m-Y]', + 'errors' => [ + 'required' => 'Opening date is required', + 'valid_date' => 'Opening date must be in DD-MM-YYYY format' + ] + ], + + 'cd_ac_no' => [ + 'rules' => 'required|trim', + 'errors' => [ + 'required' => 'CD account number is required' + ] + ], + + 'opening_bal' => [ + 'rules' => 'required|numeric|greater_than_equal_to[0]', + 'errors' => [ + 'required' => 'Opening amount is required', + 'numeric' => 'Opening amount must be numeric', + 'greater_than_equal_to' => 'Opening amount cannot be negative' + ] + ], + ]; + if (!$this->validate($rules)) { + return $this->response->setStatusCode(400)->setJSON([ + 'status' => false, + 'message' => 'Input validation failed', + 'code' => 400, + 'errors' => $this->validator->getErrors() + ]); + } + } $this->myLogger->logme("error", 'Received POST data: ' . json_encode($data)); - $id = $sanitized_post_data['PrimaryKey'] ?? null; $date = (string) ($sanitized_post_data['opening_date'] ?? ''); $sanitized_post_data['opening_date'] = date('Y-m-d', strtotime($date)); $this->myLogger->logme("error", 'Formatted opening_date: ' . $data['opening_date']); diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php index 9ce9be18..0452c797 100644 --- a/app/Controllers/MediAssistApiController.php +++ b/app/Controllers/MediAssistApiController.php @@ -518,7 +518,7 @@ class MediAssistApiController extends BaseController ->getRowArray(); if (!$ticket) { - return $this->response->setJSON(['status' => false,'message' => 'Invalid Claim ID' ]); + return ['status' => false,'message' => 'Invalid Claim ID' ]; } // REQUEST BODY @@ -548,8 +548,6 @@ class MediAssistApiController extends BaseController } - - // $body = [ // "policyNo" => "97000063250400000031", // "startDate" => "01/11/2025", @@ -568,11 +566,7 @@ class MediAssistApiController extends BaseController if ($response['status'] != true || empty($response['data']['claimsData'][0])) { log_message('error', 'CLAIM STATUS FAILED | for ticket ID: ' . $claimId.' | response: '.json_encode($response)); - return $this->response->setJSON([ - 'status' => false, - 'message' => 'API call failed.', - 'data' => $response - ]); + return ['status' => false,'message' => 'API call failed.','data' => $response ]; } // Extract claim status @@ -634,12 +628,7 @@ class MediAssistApiController extends BaseController // LOG UPDATE log_message('error', "CLAIM STATUS SUCCESS | Updated ticket ID $claimId with claim status: $currentStatus"); - return $this->response->setJSON([ - 'status' => true, - 'message' => 'Claim status updated.', - 'updated_status' => $currentStatus, - 'api_response' => $response - ]); + return ['status' => true,'message' => 'Claim status updated.','updated_status' => $currentStatus,'api_response' => $response]; } public function IRSubmission($claimId = null) // 585 this id for test diff --git a/app/Controllers/NotificationController.php b/app/Controllers/NotificationController.php index 0d85df18..b0e5b4cf 100755 --- a/app/Controllers/NotificationController.php +++ b/app/Controllers/NotificationController.php @@ -52,6 +52,7 @@ class NotificationController extends AdminController // Create Or Update the Notification public function createNotification() { + $form_data['template_name'] = $this->camelCaseToSnakeCase($this->request->getPost('template_name')); $form_data['subject'] = $this->request->getPost('subject'); $form_data['mail_content'] = $this->request->getPost('mailContent'); diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index 0c0bc293..f84364a9 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -254,8 +254,8 @@ class VidalApiController extends BaseController if($response['data']['status'] == 'SUCCESS') { - $claimNO = $response['data']['data']['claimNO'] ?? null; - $claimInwardNO = $response['data']['data']['claimInwardNO'] ?? null; + $claimNO = $response['data']['data']['claimNo'] ?? null; + $claimInwardNO = $response['data']['data']['claimInwardNo'] ?? null; if(!empty($claimNO) && !empty($claimInwardNO)){ @@ -263,7 +263,7 @@ class VidalApiController extends BaseController $this->db->table('ticket_master') ->where('id',$claimId) - ->update([ 'tpa_claim_push_reference_no' => $claimInwardNO , 'tpa_claim_id' => $claimNO ]); + ->update([ 'tpa_claim_push_reference_no' => $claimInwardNO , 'tpa_claim_id' => $claimNO , 'claim_number' => $claimNO ]); return; @@ -442,7 +442,7 @@ class VidalApiController extends BaseController ->getRowArray(); if (!$ticket) { - return $this->response->setJSON(['status' => false,'message' => 'Invalid Claim ID' ]); + return ['status' => false,'message' => 'Invalid Claim ID' ]; } $body = []; @@ -467,11 +467,7 @@ class VidalApiController extends BaseController if ($response['status'] != true || empty($response['data']['data']['claims'][0])) { log_message('error', 'CLAIM STATUS FAILED | for ticket ID: ' . $claimId.' | response: '.json_encode($response)); - return $this->response->setJSON([ - 'status' => false, - 'message' => 'API call failed.', - 'data' => $response - ]); + return ['status' => false, 'message' => 'API call failed.','data' => $response]; } // Extract claim status @@ -504,12 +500,7 @@ class VidalApiController extends BaseController // LOG UPDATE log_message('error', "CLAIM STATUS SUCCESS | Updated ticket ID $claimId with claim status: $currentStatus"); - return $this->response->setJSON([ - 'status' => true, - 'message' => 'Claim status updated.', - 'updated_status' => $currentStatus, - 'api_response' => $response - ]); + return ['status' => true,'message' => 'Claim status updated.','updated_status' => $currentStatus,'api_response' => $response]; } public function ClaimStatusUpdate() @@ -804,7 +795,7 @@ class VidalApiController extends BaseController //call a job for dump JSON data to DB $job_details = new Jobs(); - $r = Jobs::addJob(['job_name' => 'saveMediAssitAPIData', 'payload' => [ 'file_id' => $requestData['file_id'],'json_file_path' => $filePath ]]); + $r = Jobs::addJob(['job_name' => 'saveVidalAPIData', 'payload' => [ 'file_id' => $requestData['file_id'],'json_file_path' => $filePath ]]); // now update DB diff --git a/app/Helpers/excel_util_helper.php b/app/Helpers/excel_util_helper.php index db769589..5b5d6b7b 100755 --- a/app/Helpers/excel_util_helper.php +++ b/app/Helpers/excel_util_helper.php @@ -3173,6 +3173,13 @@ if (!function_exists('check_rto_data')) { $vehicle_no = strtoupper(trim($row[2])); // Example: TN10AB1234 $new_vehicle = strtolower(trim($row[2])); + if(!validate_indian_vehicle_number($vehicle_no)['status']){ + return [ + 'status' => false, + 'error' => 'Invalid Vehicle Number. Format should be like TN82AX2024 (no spaces or special characters).' + ]; + }; + // BH Series: 22BH1234AA $bhPattern = '/^[0-9]{2}BH[0-9]{4}[A-Z]{2}$/'; diff --git a/app/Helpers/sendMailNotification.php b/app/Helpers/sendMailNotification.php index cc46a3cd..5327f8d5 100755 --- a/app/Helpers/sendMailNotification.php +++ b/app/Helpers/sendMailNotification.php @@ -116,6 +116,21 @@ class sendMailNotification $tpa_id = $params['tpa_id']; $common = $params['common']; + $mailAttachmentModel = new MailAttachmentModel(); + $attachment_data = $mailAttachmentModel + ->select('file_path, file_name') + ->where('notification_id', $notification['id']) + ->where('is_active', 1) + ->findAll(); + + $attachments = []; + foreach ($attachment_data as $data) { + $attachments[] = [ + "filePath" => WRITEPATH . $data['file_path'], + "fileName" => $data['file_name'] + ]; + } + $mail_content = $notification['mail_content']; $mail = $get_emp_email_and_other_details['email_corporate']; @@ -160,7 +175,7 @@ class sendMailNotification $mail_content = view('mail_template', $data); - $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to'], 'common' => $common]; + $wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'],'attachments' => $attachments, 'reply_to' => $client_data['reply_to'], 'common' => $common]; return $wholeData; diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 79e4ddf9..efec7f1d 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -1101,3 +1101,33 @@ if (!function_exists('convertGoogleDriveToDownloadLink')) { } } +if (!function_exists('get_cd_balance')) { + function get_cd_balance(): array + { + $session = session(); + + return [ + 'has_cd_balance' => $session->has('cd_balance'), + 'hr_data' => $session->get('hr_data') ?? [], + 'cd_balance_info' => $session->get('cd_balance_info') ?? [], + ]; + } +} + +if (!function_exists('clear_cd_balance_session')) { + function clear_cd_balance_session(): void + { + $session = session(); + + $session->remove('cd_balance'); + $session->remove('hr_data'); + $session->remove('cd_balance_info'); + + log_message('error', 'clear_cd_balance_session clered'); + } +} + + + + + diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 70f0485c..7df0e021 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -494,7 +494,6 @@ class EmployeePolicyModel extends Model ) as batch_data ON employee_polices.id = batch_data.emp_policy_id WHERE employee_polices.client_policy_id = :client_policy_id: - AND (employee_polices.:id: IS NULL OR employee_polices.:id: = '') AND employees.client_branch_id = :client_branch_id: AND employee_polices.is_active = 1 AND employee_polices.status = 'active' @@ -502,6 +501,14 @@ class EmployeePolicyModel extends Model AND employees.emp_status = 'active' "; + if($insurer_or_tpa == 'insurer'){ + $sql .= "AND (employee_polices.uhid IS NULL OR employee_polices.uhid <> '')"; + } + + if($insurer_or_tpa == 'tpa'){ + $sql .= "AND (employee_polices.tpa_id IS NULL OR employee_polices.tpa_id <> '')"; + } + $binds = ["datas" => $datas,"event" => $event ,"insurer_or_tpa" => $insurer_or_tpa ,"client_policy_id" => $client_policy_id diff --git a/app/Models/TicketMasterModel.php b/app/Models/TicketMasterModel.php index 845a6fe2..f2feb0d5 100644 --- a/app/Models/TicketMasterModel.php +++ b/app/Models/TicketMasterModel.php @@ -92,6 +92,7 @@ class TicketMasterModel extends Model 'claim_description', 'required_docs', 'policy_transaction_id', + 'tpa_claim_type', ]; diff --git a/app/Views/insurer_or_tpa_data.php b/app/Views/insurer_or_tpa_data.php index 55c49153..9635fb4b 100755 --- a/app/Views/insurer_or_tpa_data.php +++ b/app/Views/insurer_or_tpa_data.php @@ -5,6 +5,354 @@ } + +
@@ -146,6 +494,10 @@
+ + + +
@@ -159,12 +511,57 @@ + + + + + \ No newline at end of file diff --git a/app/Views/leads_form.php b/app/Views/leads_form.php index 364a2da4..ede380ea 100644 --- a/app/Views/leads_form.php +++ b/app/Views/leads_form.php @@ -2156,10 +2156,9 @@ $('.btnDiv').show(); $('.claim-row').hide(); - - $('.emp_title').text('No of Employees') - $('.depnd_title').text('No of Dependents') - $('.total_title').text('Total Lives') + $('.emp_title_text').text('No of Employees') + $('.depnd_title_text').text('No of Dependents') + $('.total_title_text').text('Total Lives') $('.renewalFields').find('select, input').removeAttr('required'); $('.renewalFields').hide(); @@ -2193,9 +2192,9 @@ $('.btnDiv').hide(); $('.claim-row').show(); - $('.emp_title').text('No of Employees at Inception') - $('.depnd_title').text(' No of Dependents at Inception') - $('.total_title').text('Total Lives at Inception') + $('.emp_title_text').text('No of Employees at Inception') + $('.depnd_title_text').text(' No of Dependents at Inception') + $('.total_title_text').text('Total Lives at Inception') $('.freshFields').find('select, input').removeAttr('required'); $('.freshFields').hide(); diff --git a/app/Views/leads_non_eb.php b/app/Views/leads_non_eb.php index 2f59fe29..ebdf741b 100644 --- a/app/Views/leads_non_eb.php +++ b/app/Views/leads_non_eb.php @@ -738,9 +738,9 @@ $('.claim-row').hide(); - $('.emp_title').text('No of Employees') - $('.depnd_title').text('No of Dependents') - $('.total_title').text('Total Lives') + $('.emp_title_text').text('No of Employees') + $('.depnd_title_text').text('No of Dependents') + $('.total_title_text').text('Total Lives') $('.renewalFields').find('select, input').removeAttr('required'); $('.renewalFields').hide(); @@ -775,9 +775,9 @@ $('.btnDiv').hide(); $('.claim-row').show(); - $('.emp_title').text('No of Employees at Inception') - $('.depnd_title').text(' No of Dependents at Inception') - $('.total_title').text('Total Lives at Inception') + $('.emp_title_text').text('No of Employees at Inception') + $('.depnd_title_text').text(' No of Dependents at Inception') + $('.total_title_text').text('Total Lives at Inception') $('.freshFields').find('select, input').removeAttr('required'); $('.freshFields').hide(); @@ -812,7 +812,6 @@ } } - } var allContacts = ""; function getBranchData(input,inputType) { diff --git a/app/Views/notification.php b/app/Views/notification.php index 5248c2bf..635ca440 100755 --- a/app/Views/notification.php +++ b/app/Views/notification.php @@ -1524,7 +1524,7 @@
-
-
- +
- +
- +
diff --git a/app/Views/rfq/gpa.php b/app/Views/rfq/gpa.php index a9c74b6f..344d4b04 100644 --- a/app/Views/rfq/gpa.php +++ b/app/Views/rfq/gpa.php @@ -3,12 +3,16 @@
- +
- +