From 6c7402ea4b0d8577598778caf6810b10792feb6d Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Thu, 11 Dec 2025 16:33:38 +0530 Subject: [PATCH 1/6] logs --- app/Config/Routes.php | 10 + app/Controllers/ApiServiceController.php | 7 +- app/Controllers/LogController.php | 259 +++++++++++ app/Controllers/MediAssistApiController.php | 25 +- app/Controllers/VidalApiController.php | 63 ++- app/Views/logs/index.php | 303 ++++++++++++ app/Views/logs/view.php | 483 ++++++++++++++++++++ 7 files changed, 1121 insertions(+), 29 deletions(-) create mode 100644 app/Controllers/LogController.php create mode 100644 app/Views/logs/index.php create mode 100644 app/Views/logs/view.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index a3a3f7ec..3b0b15a6 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -839,3 +839,13 @@ $routes->group('bds_upload', function($routes) { $routes->get('getBdsDumpFileErrorData',"PolicyTransactionController::getBdsDumpFileErrorData"); $routes->get('getBdsDumpExcelFileErrors/(:any)',"PolicyTransactionController::getBdsDumpExcelFileErrors/$1"); }); + + +// ----------------------------------------------------------------------------------------------------------------- +$routes->group('logs', function($routes) { + $routes->get('/', 'LogController::index'); + $routes->get('view/(:segment)', 'LogController::view/$1'); + $routes->get('download/(:segment)', 'LogController::download/$1'); + $routes->get('delete/(:segment)', 'LogController::delete/$1'); + $routes->get('clearAll', 'LogController::clearAll'); +}); diff --git a/app/Controllers/ApiServiceController.php b/app/Controllers/ApiServiceController.php index 69d789bb..642b8b87 100644 --- a/app/Controllers/ApiServiceController.php +++ b/app/Controllers/ApiServiceController.php @@ -45,9 +45,14 @@ class ApiServiceController extends BaseController $tpaID = $data['tpa_id']; - if ($tpaID == $this->medi_assist_primary_key) { // MediAssist + if ($tpaID == $this->medi_assist_primary_key) + { // MediAssist $mediAssistController = new MediAssistApiController(); return $mediAssistController->SubmitClaim($claimId); + }else if ($tpaID == $this->vidal_primary_key) + { // Vidal + $vidalApiController = new VidalApiController; + return $vidalApiController->SubmitClaim($claimId); }else{ log_message('error', "This ticket id ( {$claimId} ) TPA has no API service enabled. TPA ID : {$tpaID}"); } diff --git a/app/Controllers/LogController.php b/app/Controllers/LogController.php new file mode 100644 index 00000000..99652ff3 --- /dev/null +++ b/app/Controllers/LogController.php @@ -0,0 +1,259 @@ +logPath = WRITEPATH . 'logs/'; + $this->session = session(); + } + + /** + * Display list of all log files + */ + public function index() + { + + $logFiles = $this->getLogFiles(); + + $data = [ + 'title' => 'Log Files', + 'logFiles' => $logFiles + ]; + + return $this->loadLayout('logs/index', $data); + + // return view('logs/index', $data); + } + + /** + * Get all log files sorted by date (latest first) + */ + private function getLogFiles() + { + $files = []; + + if (!is_dir($this->logPath)) { + return $files; + } + + $iterator = new \DirectoryIterator($this->logPath); + + foreach ($iterator as $fileInfo) { + if ($fileInfo->isFile() && $fileInfo->getExtension() === 'log') { + $files[] = [ + 'name' => $fileInfo->getFilename(), + 'path' => $fileInfo->getPathname(), + 'size' => $this->formatBytes($fileInfo->getSize()), + 'modified' => $fileInfo->getMTime(), + 'modified_date' => date('Y-m-d H:i:s', $fileInfo->getMTime()) + ]; + } + } + + // Sort by modified time (latest first) + usort($files, function($a, $b) { + return $b['modified'] - $a['modified']; + }); + + return $files; + } + + /** + * View specific log file content + */ + public function view($filename = null) + { + + + + if (!$filename) { + return redirect()->to('/logs')->with('error', 'No log file specified'); + } + + // Security: prevent directory traversal + $filename = basename($filename); + $filePath = $this->logPath . $filename; + + if (!file_exists($filePath)) { + return redirect()->to('/logs')->with('error', 'Log file not found'); + } + + // ✅ extract date from filename: log-YYYY-MM-DD.log + if (preg_match('/log-(\d{4}-\d{2}-\d{2})\.log/', $filename, $match)) { + $currentDate = $match[1]; + + $prevDate = date('Y-m-d', strtotime('-1 day', strtotime($currentDate))); + $nextDate = date('Y-m-d', strtotime('+1 day', strtotime($currentDate))); + + $prevFile = "log-$prevDate.log"; + $nextFile = "log-$nextDate.log"; + + $prevExists = file_exists($this->logPath . $prevFile); + $nextExists = file_exists($this->logPath . $nextFile); + } + + // Read log file content + $content = file_get_contents($filePath); + $logEntries = $this->parseLogFile($content); + + $data = [ + 'title' => 'View Log: ' . $filename, + 'filename' => $filename, + 'logEntries' => $logEntries, + 'prevFile' => $prevExists ? $prevFile : null, + 'nextFile' => $nextExists ? $nextFile : null, + 'fileSize' => $this->formatBytes(filesize($filePath)), + 'lastModified' => date('Y-m-d H:i:s', filemtime($filePath)) + ]; + + // print_r( $data); die; + + return $this->loadLayout('logs/view', $data); + // return view('logs/view', $data); + } + + /** + * Parse log file into structured array + */ + + private function parseLogFile($content) + { + $entries = []; + $lines = explode("\n", $content); + + $currentEntry = null; + + // Messages to filter out + $skipPatterns = [ + '/Session: Class initialized using/', + '/Session class already loaded/', + ]; + + foreach ($lines as $line) { + // Match CI4 log format: LEVEL - date --> message + if (preg_match('/^(\w+)\s*-\s*(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2})\s*-->\s*(.*)$/', $line, $matches)) { + + // Save previous entry if exists (before checking skip) + if ($currentEntry !== null) { + $entries[] = $currentEntry; + $currentEntry = null; + } + + // Check if this message should be skipped + $shouldSkip = false; + foreach ($skipPatterns as $pattern) { + if (preg_match($pattern, $matches[3])) { + $shouldSkip = true; + break; + } + } + + if ($shouldSkip) { + continue; + } + + // Start new entry + $currentEntry = [ + 'level' => $matches[1], + 'date' => $matches[2], + 'message' => $matches[3] + ]; + } elseif ($currentEntry !== null && trim($line) !== '') { + // Continuation of previous message + $currentEntry['message'] .= "\n" . $line; + } + } + + // Add last entry + if ($currentEntry !== null) { + $entries[] = $currentEntry; + } + + return array_reverse($entries); // Latest first + } + + /** + * Download log file + */ + public function download($filename = null) + { + if (!$filename) { + return redirect()->to('/logs')->with('error', 'No log file specified'); + } + + $filename = basename($filename); + $filePath = $this->logPath . $filename; + + if (!file_exists($filePath)) { + return redirect()->to('/logs')->with('error', 'Log file not found'); + } + + return $this->response->download($filePath, null); + } + + /** + * Delete log file + */ + public function delete($filename = null) + { + if (!$filename) { + return redirect()->to('/logs')->with('error', 'No log file specified'); + } + + $filename = basename($filename); + $filePath = $this->logPath . $filename; + + if (!file_exists($filePath)) { + return redirect()->to('/logs')->with('error', 'Log file not found'); + } + + if (unlink($filePath)) { + return redirect()->to('/logs')->with('success', 'Log file deleted successfully'); + } else { + return redirect()->to('/logs')->with('error', 'Failed to delete log file'); + } + } + + /** + * Format bytes to human readable format + */ + private function formatBytes($bytes, $precision = 2) + { + $units = ['B', 'KB', 'MB', 'GB', 'TB']; + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + $bytes /= pow(1024, $pow); + + return round($bytes, $precision) . ' ' . $units[$pow]; + } + + /** + * Clear all log files + */ + public function clearAll() + { + $logFiles = $this->getLogFiles(); + $deleted = 0; + + foreach ($logFiles as $file) { + if (unlink($file['path'])) { + $deleted++; + } + } + + return redirect()->to('/logs')->with('success', $deleted . ' log file(s) deleted successfully'); + } +} \ No newline at end of file diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php index e0be4976..2b4d754e 100644 --- a/app/Controllers/MediAssistApiController.php +++ b/app/Controllers/MediAssistApiController.php @@ -150,7 +150,7 @@ class MediAssistApiController extends BaseController return; } else { - log_message('error', 'TPA CLAIM PUSH SUCCESS BUT claimReferenceNo EMPTY | claimId: '.$claimId.' | response: '.json_encode($response)); + log_message('error', 'TPA CLAIM PUSH API SUCCESS BUT claimReferenceNo EMPTY | claimId: '.$claimId.' | response: '.json_encode($response)); return; } @@ -223,7 +223,7 @@ class MediAssistApiController extends BaseController $client_policy_id = $requestData['client_policy_id'] ?? null; if (empty($policyNo)) { - log_message('error', 'GetBenefDetails: policy_no missing in request'); + log_message('error', 'TPA ID PULL | policy_no missing in request'); if($function_calling_type == "job"){ return ['status' => false, 'message' => 'policy_no required']; }else{ @@ -232,7 +232,7 @@ class MediAssistApiController extends BaseController } if (empty($client_policy_id)) { - log_message('error', 'GetBenefDetails: client_policy_id missing in request'); + 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{ @@ -240,8 +240,7 @@ class MediAssistApiController extends BaseController } } - log_message('error', "GetBenefDetails called for policy_no: {$policyNo}"); - log_message('error', "GetBenefDetails called for client_policy_id: {$client_policy_id}"); + log_message('error', "TPA ID PULL | called for policy_no: {$policyNo} , client_policy_id: {$client_policy_id}"); $employeePolicyModel = new EmployeePolicyModel(); $employeePolicyData = $employeePolicyModel @@ -260,7 +259,7 @@ class MediAssistApiController extends BaseController ->findAll(); if (empty($employeePolicyData)) { - log_message('error', 'GetBenefDetails: employeePolicyData is empty'); + log_message('error', 'TPA ID PULL FAILED | employeePolicyData is empty (tpa_id IS NULL from nhance) for this tpa id pull request'); if($function_calling_type == "job"){ return ['status' => false, 'message' => 'employeePolicyData not found']; }else{ @@ -284,8 +283,8 @@ class MediAssistApiController extends BaseController "employeeId" => "" ]; - log_message('error', "GetBenefDetails API Request (startIndex={$startIndex}): " . json_encode($body)); - log_message('error', "GetBenefDetails API parems " . json_encode([$url, $method, $headers, $body])); + log_message('error', "TPA ID PULL | API Request (startIndex={$startIndex}): " . json_encode($body)); + log_message('error', "TPA ID PULL | API parems " . json_encode([$url, $method, $headers, $body])); $response = call_third_party_api($url, $method, $headers, $body); @@ -300,7 +299,7 @@ class MediAssistApiController extends BaseController log_message('error', "Failed to update file table status."); } - log_message('error', 'GetBenefDetails API failed: ' . json_encode($response)); + log_message('error', 'TPA ID PULL API FAILED | API failed: ' . json_encode($response)); if($function_calling_type == "job"){ return ['status' => false, 'message' => 'API call failed', 'data' => $response]; @@ -312,7 +311,7 @@ class MediAssistApiController extends BaseController $data = $response['data'] ?? []; if (!isset($data['benefDetails'])) { - log_message('error', "GetBenefDetails: 'benefDetails' missing in API response: " . json_encode($data)); + log_message('error', "TPA ID PULL FAILED |: 'benefDetails' missing in API response: " . json_encode($data)); break; } @@ -406,7 +405,7 @@ class MediAssistApiController extends BaseController } - log_message('error', "GetBenefDetails completed. Total fetched={$totalCount}, updated={$updated}"); + log_message('error', "TPA ID PULL SUCCESS | completed. Total fetched={$totalCount}, updated={$updated}"); if($function_calling_type == "job"){ return [ @@ -532,7 +531,7 @@ class MediAssistApiController extends BaseController $response = call_third_party_api($url, $method, $headers, $body); if ($response['status'] != true || empty($response['data']['claimsData'][0])) { - log_message('error', 'Claim status API failed for ticket ID: ' . $claimId); + log_message('error', 'CLAIM STATUS FAILED | for ticket ID: ' . $claimId.' | response: '.json_encode($response)); return $this->response->setJSON([ 'status' => false, @@ -598,7 +597,7 @@ class MediAssistApiController extends BaseController $this->db->table('ticket_master')->where('id', $claimId)->update($updateArray); // LOG UPDATE - log_message('info', "Updated ticket ID $claimId with claim status: $currentStatus"); + log_message('info', "CLAIM STATUS SUCCESS | Updated ticket ID $claimId with claim status: $currentStatus"); return $this->response->setJSON([ 'status' => true, diff --git a/app/Controllers/VidalApiController.php b/app/Controllers/VidalApiController.php index a2875028..fae58531 100644 --- a/app/Controllers/VidalApiController.php +++ b/app/Controllers/VidalApiController.php @@ -7,15 +7,18 @@ use CodeIgniter\HTTP\ResponseInterface; class VidalApiController extends BaseController { - public function index() + protected $db; + + public function __construct() { - // + $this->db = \Config\Database::connect(); } function uploadFileToVidal($filePath,$filename) { - $apiUrl = "https://devapigw.vidalhealthtpa.com/partner-integration/api/files/upload-url"; + // $apiUrl = "https://devapigw.vidalhealthtpa.com/partner-integration/api/files/upload-url"; + $apiUrl = getenv('VIDAL_API_BASE_URL').'/files/upload-url'; $subscriptionKey = getenv('VIDAL_API_SUBSCRIPTION_KEY'); log_message('error', "Starting file upload process for filename: $filename | Path: $filePath"); @@ -105,10 +108,8 @@ class VidalApiController extends BaseController { helper('api'); - //Prepare body data - $db = \Config\Database::connect(); // Fetch the data from DB - $data = $db->table('ticket_master tm') + $data = $this->db->table('ticket_master tm') ->select(' tm.id, tm.emp_mobile as mobileNo, @@ -116,9 +117,14 @@ class VidalApiController extends BaseController tm.doa as admissionDate, tm.dod as dischargeDate, tm.hospital_name as hospitalName, + tm.hospital_address as hospitalAddress, + tm.hospital_state as hospitalState, + tm.hospital_city as hospitalCity, + tm.hospital_pin_code as hospitalPinCode, + tm.hospital_phone_no as hospitalPhoneNo, tm.claim_amount as requestedAmount, + tm.tpa_no as dependentUniqueId, cp.policy_no as policyNo, - e.id as dependentUniqueIdOld, e.emp_code as memberId, tn.note as disease, tn.note as reasonForHospitalization, @@ -126,7 +132,7 @@ class VidalApiController extends BaseController cf.url as filePath, pt.policy_type as typeOfClaim, ep.tpa_id as empanelmentNo, - ep.tpa_id as dependentUniqueId, + ') ->join('employees e', 'e.id = tm.emp_id', 'left') ->join('client_policy cp', 'tm.client_policy_id = cp.id', 'left') @@ -196,7 +202,9 @@ class VidalApiController extends BaseController ], ]; // dd($body); - log_message('error', "Submit claim failed - payload ". json_encode($body )); + + log_message('error', 'TPA CLAIM PUSH | claimId: '.$claimId.' | payload: '.json_encode($body)); + // $body = [ // 'policyNo' => "351500/D0534/PP/20-20/PC", // 'dependentUniqueId' => "EN000000182-C-41", @@ -227,16 +235,41 @@ class VidalApiController extends BaseController $response = call_third_party_api($url, $method, $headers, $body); if($response['status'] != true){ - return $this->response->setJSON([ - 'status' => false, - 'message' => 'failed.', - 'data' => $response - ]); + log_message('error', 'TPA CLAIM PUSH FAILED | claimId: '.$claimId.' | response: '.json_encode($response)); + return; } - return $this->response->setJSON($response); + // return $this->response->setJSON($response); + + if($response['data']['status'] == 'SUCCESS') + { + $claimNO = $response['data']['data']['claimNO'] ?? null; + $claimInwardNO = $response['data']['data']['claimInwardNO'] ?? null; + + if(!empty($claimNO) && !empty($claimInwardNO)){ + + log_message('error', 'TPA CLAIM PUSH SUCCESS | claimId: '.$claimId.' | claimNO: '.$claimNO.' | claimInwardNO: '.$claimInwardNO); + + $this->db->table('ticket_master') + ->where('id',$claimId) + ->update([ 'tpa_claim_push_reference_no' => $claimInwardNO , 'tpa_claim_id' => $claimNO ]); + + return; + + } else { + log_message('error', 'TPA CLAIM PUSH API SUCCESS BUT claimNO,claimInwardNO EMPTY | claimId: '.$claimId.' | response: '.json_encode($response)); + return; + } + }else{ + log_message('error', 'TPA CLAIM PUSH API FAILED | claimId: '.$claimId.' | response: '.json_encode($response)); + return; + } } + + + //----------yet to start only submit claim given + public function fileUpload() { diff --git a/app/Views/logs/index.php b/app/Views/logs/index.php new file mode 100644 index 00000000..8c3024c2 --- /dev/null +++ b/app/Views/logs/index.php @@ -0,0 +1,303 @@ + + + + + + <?= esc($title) ?> + + + +
+ + +
+ getFlashdata('success')): ?> +
+ ✓ getFlashdata('success') ?> +
+ + + getFlashdata('error')): ?> +
+ ✗ getFlashdata('error') ?> +
+ + + + +
+

Log Files

+ + + +
+ + +
+ + + +

No Log Files Found

+

There are no log files to display at the moment.

+
+ +
+ + + + + + + + + + + + + + + + + + + +
File NameSizeLast ModifiedActions
+ + 📄 + + + +
+
+ +
+
+ + \ No newline at end of file diff --git a/app/Views/logs/view.php b/app/Views/logs/view.php new file mode 100644 index 00000000..de031e03 --- /dev/null +++ b/app/Views/logs/view.php @@ -0,0 +1,483 @@ + + + + + + <?= esc($title) ?> + + + +
+
+
+

+ 📄 +

+ +
+ + Previous + + + + + + Next + + + +
+
+ + + +
+ + + + +
+
+ + + + + + + +
+

+ stripos($e['message'], 'TPA CLAIM PUSH SUCCESS') !== false)) ?> +

+

Claim success

+
+
+

+ stripos($e['message'], 'TPA CLAIM PUSH FAILED') !== false)) ?> +

+

Claim failed

+
+
+

+ stripos($e['message'], 'TPA ID PULL SUCCESS') !== false)) ?> +

+

Tpa no pull success

+
+
+

+ stripos($e['message'], 'TPA ID PULL FAILED') !== false)) ?> +

+

Tpa no pull Failed

+
+
+

+ stripos($e['message'], 'CLAIM STATUS SUCCESS') !== false)) ?> +

+

Claim status fetch success

+
+
+

+ stripos($e['message'], 'CLAIM STATUS FAILED') !== false)) ?> +

+

Claim status fetch failed

+
+
+

+ stripos($e['message'], 'Ecard Request PUSH SUCCESS') !== false)) ?> +

+

Ecard Request

+
+ + + + +
+ +
+
+ Filter: + + + + + + +
+ +
+ + +
+

No Log Entries Found

+

This log file is empty or couldn't be parsed.

+
+ +
+ + +
+
+ + + + +
+
+
+ +
+ +
+
+ + + + \ No newline at end of file From 9eda830bc1d354379628c8bad473a0cc01a56b2e Mon Sep 17 00:00:00 2001 From: "sanjeev.p" Date: Thu, 11 Dec 2025 16:58:38 +0530 Subject: [PATCH 2/6] FIX_getAdvertisementImage api and upload path changed --- .../AppContentManagementController.php | 55 ++++++++----------- app/Controllers/EmployeeRestController.php | 52 +++++++++++++----- app/Views/add_image_list.php | 25 +++++---- 3 files changed, 74 insertions(+), 58 deletions(-) diff --git a/app/Controllers/AppContentManagementController.php b/app/Controllers/AppContentManagementController.php index fcc9a6d6..da65a7b1 100755 --- a/app/Controllers/AppContentManagementController.php +++ b/app/Controllers/AppContentManagementController.php @@ -28,11 +28,11 @@ class AppContentManagementController extends AdminController $this->feContentModel = new FEContentModel(); $this->clientModel = new ClientModel(); } + //listing public function add_image_index() { - $this->myLogger->logme('error','Addvertisement Image list function called'); - $headerData['tab_name'] = 'Addvertisement Images'; - $headerData['page_name'] = 'Addvertisement Images'; + $headerData['tab_name'] = 'Advertisement Images'; + $headerData['page_name'] = 'Advertisement Images'; // $data['addImageList'] = $this->addImgModel->findAll(); $data['addImageList'] = $this->addImgModel->select('advertisement_images.*, clients.client_name, @@ -53,7 +53,7 @@ class AppContentManagementController extends AdminController // $this->loadLayout('client_onboarding', $data); } - // using add and edit + // add and edit public function add_advertise_image() { try { $file = $this->request->getFile('advertise_image'); @@ -70,7 +70,8 @@ class AppContentManagementController extends AdminController return $this->respond(['status' => false, 'message' => 'No file uploaded or invalid file.'], 400); } - $uploadPath = WRITEPATH . 'uploads/advertiseImage/'; + // $uploadPath = WRITEPATH . 'uploads/advertiseImage/'; + $uploadPath = ROOTPATH . 'public/uploads/add_image_upload/'; if (!is_dir($uploadPath)) mkdir($uploadPath, 0755, true); @@ -91,6 +92,7 @@ class AppContentManagementController extends AdminController } } + // soft delete public function remove_advertise_image() { try { @@ -111,47 +113,34 @@ class AppContentManagementController extends AdminController } - // public function showAdvertiseImage($fileName) - // { - - // $filePath = WRITEPATH . 'uploads/advertiseImage/' . $fileName; - - // if (!file_exists($filePath)) { - // return $this->response->setStatusCode(404, 'File not found'); - // } - - // $mimeType = mime_content_type($filePath); - // header('Content-Type: ' . $mimeType); - // readfile($filePath); - // exit; - // } - - // In AppContentManagementController.php (This is what needs to be fixed if the direct path fails) - + // Preview image Went Edit. public function showAdvertiseImage($filename) { - $path = WRITEPATH . 'uploads/advertiseImage/' . $filename; + // $path = WRITEPATH . 'uploads/advertiseImage/' . $filename; + $path = ROOTPATH . 'public/uploads/add_image_upload/' . $filename; if (!file_exists($path)) { throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound(); + // return $this->response->setStatusCode(404, 'File not found'); } $mime = mime_content_type($path); + // header('Content-Type: ' . $mimeType); + // readfile($path); + // exit; return $this->response->setHeader('Content-Type', $mime)->setBody(file_get_contents($path)); } - public function getAdvertiseImage($image_id){ - - $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first(); - - if($image_data){ - return $image_data['name']; - }else{ - return ; - } - } + // public function getAdvertiseImage($image_id){ + // $image_data = $this->addImgModel->select('name')->where(['id' => $image_id])->first(); + // if($image_data){ + // return $image_data['name']; + // }else{ + // return ; + // } + // } diff --git a/app/Controllers/EmployeeRestController.php b/app/Controllers/EmployeeRestController.php index d80f9176..1a488767 100755 --- a/app/Controllers/EmployeeRestController.php +++ b/app/Controllers/EmployeeRestController.php @@ -3176,32 +3176,58 @@ class EmployeeRestController extends AdminController } } + // public function getAdvertisementImage_old() + // { + // try { + + // $client_id = $this->request->getGet('client_id'); + + // $img = $this->addImgModel->where('is_active', 1)->where('client_id',$client_id)->findAll(); + + // if (count($img) > 0) { + // $data = []; + // foreach ($img as $key => $value) { + // $url = base_url('public/uploads/add_image_upload/') . $value['name']; + // array_push($data, $url); + // } + + // return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200); + // } else { + + // return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'No Data'], 404); + // } + // } catch (\Throwable $th) { + // return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500); + // } + // } + public function getAdvertisementImage() { try { $client_id = $this->request->getGet('client_id'); + // get client_id & convert empty/null/undefined → 0 + // $client_id = ($client_id === null || $client_id === '' || $client_id === 'undefined') ? 0 : $client_id; - $img = $this->addImgModel->where('is_active', 1)->where('client_id',$client_id)->findAll(); + // fetch images for client + $images = $this->addImgModel->where('is_active', 1)->where('client_id', $client_id)->findAll(); - if (count($img) > 0) { - $data = []; - foreach ($img as $key => $value) { - $url = base_url('public/uploads/add_image_upload/') . $value['name']; - array_push($data, $url); - } - - return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200); - } else { - - return $this->respond(['status' => 'failed', 'code' => 404, 'data' => 'No Data'], 404); + // if no client images → load default client 0 + if (count($images) == 0) { + $images = $this->addImgModel->where('is_active', 1)->where('client_id', 0)->findAll(); } + + // prepare URLs + $data = array_map(function($img){ return base_url('public/uploads/add_image_upload/' . $img['name']); }, $images); + + return $this->respond(['status' => 'success', 'code' => 200, 'data' => $data], 200); + } catch (\Throwable $th) { + return $this->respond(['status' => 'failed', 'code' => 500, 'data' => $th], 500); } } - public function storeFireBase() { try { diff --git a/app/Views/add_image_list.php b/app/Views/add_image_list.php index e83cc7d7..a69924ea 100755 --- a/app/Views/add_image_list.php +++ b/app/Views/add_image_list.php @@ -51,15 +51,15 @@ table.dataTable thead th { - - + + @@ -136,6 +136,7 @@ table.dataTable thead th { @@ -2234,31 +2234,31 @@
-
Remuneration
-
-
- +
Remuneration
+
+
+
-
-
+
+
BP   %
-
+
TP   %
-
-
- -
-
-
- - - + + +
+ +
+ + + + + + +