From 5762848cc82dd1550f9aff1914347a7a2b927387 Mon Sep 17 00:00:00 2001 From: Venkatesh Date: Sat, 2 May 2026 18:41:06 +0530 Subject: [PATCH] FIX_CLAIM_RELATED_ISSUE --- app/Config/Routes.php | 2 + app/Controllers/MediAssistApiController.php | 2 +- app/Controllers/TicketController.php | 71 ++++++++- app/Views/claim_files_upload.php | 155 +++++++++++++++++++- app/Views/ticket_reply.php | 37 ++++- app/Views/ticket_search.php | 31 +++- 6 files changed, 281 insertions(+), 17 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 251e26ee..0129af3d 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -87,6 +87,7 @@ $routes->get('download-e-card/(:any)', 'EmployeeController::generateIDCardForEmp $routes->get('download-kyc-docs/(:segment)', 'ClientController::downloadKYCDocument/$1'); $routes->get('claim-form-download/(:any)', 'TicketController::downloadClaimForm/$1'); $routes->get('downloadClaimFile/(:any)', 'TicketController::downloadClaimFile/$1'); +$routes->get('viewClaimFile/(:any)', 'TicketController::viewClaimFile/$1'); $routes->match (['get','post'],"claims-feedback-form/(:any)/(:any)", "TicketController::viewClaimFeedbackForm/$1/$2"); $routes->match (['get','post'],"claims-feedback-form/(:any)", "TicketController::viewClaimFeedbackForm/$1"); $routes->get('downloadEmployeeEcardZip/(:any)', 'EmployeeController::downloadEmployeeEcardZip/$1'); @@ -812,6 +813,7 @@ $routes->group("/ticket", ["filter" => "authMVC"], function ($routes) { $routes->get("getMoreInfo","TicketController::getMoreInfo"); $routes->post('upload_url',"TicketController::upload_url"); $routes->post('getUrlDataByTicketId',"TicketController::getUrlDataByTicketId"); + $routes->post('uploadClaimFilesToTPA', 'TicketController::uploadClaimFilesToTPA'); $routes->get('remove_url',"TicketController::remove_url"); $routes->get('fetchVehiclePolicy/(:any)','TicketController::fetchVehiclePolicy/$1'); $routes->post('saveIRDocsJson',"TicketController::saveIRDocsJson"); diff --git a/app/Controllers/MediAssistApiController.php b/app/Controllers/MediAssistApiController.php index 65a8992a..94470ad7 100644 --- a/app/Controllers/MediAssistApiController.php +++ b/app/Controllers/MediAssistApiController.php @@ -703,7 +703,7 @@ class MediAssistApiController extends BaseController return [ 'status' => false, - 'message' => "ClaimID not found for ticket {$claimId}" + 'message' => "Claim Number not found for Claim {$claimId}" ]; } diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index b3607027..d7f3129a 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -33,6 +33,8 @@ use Kint\Kint; use App\Helpers\MailHelper; +use CodeIgniter\Exceptions\PageNotFoundException; + class TicketController extends BaseController { use ResponseTrait; @@ -628,7 +630,14 @@ class TicketController extends BaseController $startDate = date('Y-m-d 00:00:00', strtotime($search_data['start_date'])); $endDate = date('Y-m-d 23:59:59', strtotime($search_data['end_date'])); $rawWhere[] = "tm.updated_at BETWEEN '$startDate' AND '$endDate'"; - }elseif($search_objects != "date_type" && $search_objects != "start_date" && $search_objects != "end_date"){ + } elseif ($search_objects === 'tpa_claim_type') { + $cat = strtolower(trim((string) $key)); + if ($cat === 'cashless') { + $rawWhere[] = "LOWER(COALESCE(tm.tpa_claim_type, '')) LIKE '%cash%'"; + } elseif ($cat === 'reimbursement') { + $rawWhere[] = "LOWER(COALESCE(tm.tpa_claim_type, '')) LIKE '%reimburse%'"; + } + } elseif($search_objects != "date_type" && $search_objects != "start_date" && $search_objects != "end_date"){ $where[$search_objects] = $key; } } @@ -2382,6 +2391,39 @@ class TicketController extends BaseController } } + /** + * Inline preview in browser for uploaded claim files (PDF / PNG / JPG / JPEG only). + */ + public function viewClaimFile($claim_file_id = null) + { + if ($claim_file_id === null || $claim_file_id === '') { + throw PageNotFoundException::forPageNotFound(); + } + + $claimFiles = new ClaimFilesModel(); + $file_record = $claimFiles->where('id', $claim_file_id)->where('is_active', 1)->first(); + + if ($file_record === null || (int) ($file_record['file_type'] ?? 0) !== 2) { + throw PageNotFoundException::forPageNotFound(); + } + + $url = $file_record['url']; + $parts = explode('/', $url); + $fileName = end($parts); + $filePath = WRITEPATH . '/uploads/claim_files/' . $fileName; + + if (! is_file($filePath)) { + throw PageNotFoundException::forPageNotFound(); + } + + $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION) ?: ''); + if (! in_array($ext, ['pdf', 'png', 'jpg', 'jpeg'], true)) { + throw PageNotFoundException::forPageNotFound(); + } + + return $this->response->download($filePath, null, true)->inline()->setFileName($fileName); + } + public function convertHtmlToTextOld($html) { if(!empty($html)){ @@ -3950,7 +3992,9 @@ class TicketController extends BaseController return $this->respond(['status' => false, 'message' => 'Ticket not found'], 404); } - if (!empty($ticket_data['approved_letter'])) { + $claimStatusId = (int) ($ticket_data['claim_status_id'] ?? 0); + $approvedLetterReplaceStatuses = [10, 11]; + if (!empty($ticket_data['approved_letter']) && !in_array($claimStatusId, $approvedLetterReplaceStatuses, true)) { return $this->respond([ 'status' => false, 'message' => 'Approved letter already available', @@ -4008,6 +4052,29 @@ class TicketController extends BaseController } } + public function uploadClaimFilesToTPA() + { + try { + $ticket_id = $this->request->getPost('ticket_id'); + + if (empty($ticket_id)) { + return $this->respond(['status' => false, 'message' => 'Ticket ID and Status ID are required'], 400); + } + + $apiServiceController = new ApiServiceController(); + $response = $apiServiceController->pushClaimFiles($ticket_id); + if ($response['status'] ?? false) { + return $this->respond(['status' => true, 'message' => 'Claim files uploaded to TPA successfully'], 200); + } else { + return $this->respond(['status' => false, 'message' => $response['message'] ?? 'Failed to upload claim files to TPA'], 200); + } + + } catch (\Exception $e) { + $this->myLogger->logme('error', 'Error in uploadClaimFilesToTPA: ' . $e->getMessage() . ' in file ' . $e->getFile() . ' on line ' . $e->getLine() . $e->getTraceAsString()); + return $this->respond(['status' => false, 'message' => 'An error occurred while uploading claim files to TPA'], 500); + } + } + // -------- CLAIM DUMP UPLOAD ---------------------------------------------------------------------------------------------- public function claimDumpUpload() diff --git a/app/Views/claim_files_upload.php b/app/Views/claim_files_upload.php index 4a8380b7..e8f4429e 100644 --- a/app/Views/claim_files_upload.php +++ b/app/Views/claim_files_upload.php @@ -98,11 +98,16 @@
-
-
-

File List

+
+
+

File List

+
+
+
-
@@ -111,6 +116,7 @@ + @@ -167,7 +173,60 @@ let ticket_id = $('#ticket_master_id').val(); $('#ticket_id_url').val(ticket_id); let urlData = getUrlDataByTicketId(ticket_id); - }) + }); + + function getClaimFileListTicketId() { + var id = $('#ticket_master_id').val(); + if (!id) { + id = $('#ticket_id_url').val(); + } + return id; + } + + $(document).on('click', '#btn_upload_claim_files_to_tpa', function () { + var ticket_id = getClaimFileListTicketId(); + if (!ticket_id) { + toastr.warning('Ticket ID is missing. Please reload the page.', 'Validation'); + return; + } + var $btn = $(this); + $.ajax({ + url: "", + type: "POST", + data: { ticket_id: ticket_id }, + dataType: "json", + beforeSend: function () { + $btn.prop('disabled', true); + $('.loader').fadeIn(); + $('.loader-mask').fadeIn(); + }, + success: function (res) { + if (res && res.status === true) { + toastr.success(res.message || 'Claim files uploaded to TPA successfully', 'Success'); + getUrlDataByTicketId(ticket_id); + } else { + toastr.error((res && res.message) ? res.message : 'Failed to upload claim files to TPA', 'Error'); + } + }, + error: function (xhr) { + if (xhr.status === 400 || xhr.status === 500) { + try { + var r = JSON.parse(xhr.responseText); + toastr.error(r.message || 'Request failed', 'Error'); + } catch (e) { + toastr.error('Request failed', 'Error'); + } + } else { + toastr.error('An unexpected error occurred. Please try again later.', 'Error'); + } + }, + complete: function () { + $btn.prop('disabled', false); + $('.loader').fadeOut(); + $('.loader-mask').delay(350).fadeOut('slow'); + } + }); + }); $("#drive_file_upload_form").submit(function(event) { @@ -386,6 +445,60 @@ return false; }); + function escapeClaimFileListAttr(s) { + return String(s == null ? '' : s) + .replace(/&/g, '&') + .replace(/"/g, '"') + .replace(/ { + const sentToTpa = item.is_file_sent_to_tpa == 1 || item.is_file_sent_to_tpa === true || item.is_file_sent_to_tpa === '1'; + const tpaBadgeClass = sentToTpa ? 'badge-success' : 'badge-secondary'; + const tpaLabel = sentToTpa ? 'Yes' : 'No'; + const viewOk = claimFileViewSupported(item); + const viewHref = escapeClaimFileListAttr(claimFileViewOpenUrl(item, base_url)); + const viewSupportedAttr = viewOk ? '1' : '0'; + const viewIconClass = viewOk ? 'text-primary' : 'text-muted'; + const viewTitle = viewOk ? 'View in new tab' : 'Preview not available for this format'; html += ` + '); + $('#table_bd').html(''); } } + $(document).on('click', '.view-claim-file', function (e) { + e.preventDefault(); + var supported = $(this).data('view-supported') == 1 || $(this).data('view-supported') === '1'; + var viewUrl = $(this).attr('data-view-url'); + if (!supported) { + toastr.warning('Not supported format. Only PDF and images (PNG, JPG, JPEG) can be previewed.', 'View file'); + return; + } + if (viewUrl) { + window.open(viewUrl, '_blank', 'noopener,noreferrer'); + } + }); + $(document).on('click', '.delete-url', function (e) { e.preventDefault(); const url = $(this).data('href'); diff --git a/app/Views/ticket_reply.php b/app/Views/ticket_reply.php index b05168c7..f8395fd6 100644 --- a/app/Views/ticket_reply.php +++ b/app/Views/ticket_reply.php @@ -6,13 +6,14 @@
@@ -31,6 +32,13 @@
+ + +
+ +
+ +
@@ -223,6 +231,7 @@ const editorConfig = { $(document).ready(function() { const replyTicketId = ``; + const replyClaimStatusId = ``; let replyApprovedLetter = ; console.log('Approved Letter from server:', replyApprovedLetter); @@ -457,6 +466,12 @@ $(document).ready(function() { toastr.success(res.message || 'Approved letter uploaded successfully', 'Success'); cleanup(); approvedLetterModalInstance.hide(); + const templateStatusId = String(statusId); + if ($('#status_back_option').length) { + $('#status_back_option').val(templateStatusId); + } + $('#claim_status').val(templateStatusId); + loadClaimTemplateForStatus(ticketId, templateStatusId); dfd.resolve(); } else { $uploadBtn.prop('disabled', false); @@ -480,17 +495,25 @@ $(document).ready(function() { return; } - if (String(selectedStatusId) === '9' && !hasApprovedLetterValue(replyApprovedLetter)) { - openApprovedLetterUploadModalAndHandle(replyTicketId, selectedStatusId) - .done(function() { - loadClaimTemplateForStatus(replyTicketId, selectedStatusId); - }); + const needsApprovedLetterModal = + String(replyClaimStatusId) === '11' || !hasApprovedLetterValue(replyApprovedLetter); + + if (String(selectedStatusId) === '9' && needsApprovedLetterModal) { + openApprovedLetterUploadModalAndHandle(replyTicketId, selectedStatusId); return; } loadClaimTemplateForStatus(replyTicketId, selectedStatusId); } + $('#approved_letter_reupload_btn').on('click', function() { + if (!replyTicketId) { + return; + } + openApprovedLetterUploadModalAndHandle(replyTicketId, '9') + .done(function() {}); + }); + $('#status_back_option').on('change', function() { handleStatusTemplateFlow(); }); diff --git a/app/Views/ticket_search.php b/app/Views/ticket_search.php index 92bb084d..659b6deb 100644 --- a/app/Views/ticket_search.php +++ b/app/Views/ticket_search.php @@ -74,6 +74,15 @@ ?>
+ +
+ + +
+
+ + +
+
S.No  Docs Name  File Name Sent to TPA  Action 
${index + 1} ${item.doc_name} ${item.file_type == 1 ? item.url : item.doc_name} + ${tpaLabel} + + + + @@ -413,10 +543,23 @@ $('#table_bd').append(html); } else { - $('#table_bd').html('
No Data Found
No Data Found