diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 3daa030c..3e18c556 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -871,6 +871,7 @@ $routes->group("/bdsReport", ["filter" => "authMVC"], function ($routes) { //New Tickets $routes->group("/ticket", ["filter" => "authMVC"], function ($routes) { $routes->match( ['get', 'post'], 'list','TicketController::ticketList'); + $routes->post('export','TicketController::exportTickets'); $routes->get('feedback-list','TicketController::feedbackList'); $routes->match(['get', 'post'], 'claim-upload','TicketController::claimDumpUpload'); $routes->get('remove','TicketController::removeTicket'); diff --git a/app/Controllers/TicketController.php b/app/Controllers/TicketController.php index c549be78..cb197432 100644 --- a/app/Controllers/TicketController.php +++ b/app/Controllers/TicketController.php @@ -461,6 +461,155 @@ class TicketController extends BaseController } } + public function exportTickets() + { + $format = $this->request->getPost('export_format') ?? 'csv'; + $rows = $this->ticketSearch(); // uses same POST filters as the list + + // Restrict to DataTables-visible rows when client sends export_ids + if ($this->request->getPost('export_ids') !== null) { + $exportIds = array_values(array_filter(array_map('intval', explode(',', (string) $this->request->getPost('export_ids'))))); + if (empty($exportIds)) { + $rows = []; + } else { + $idOrder = array_flip($exportIds); + $rows = array_values(array_filter($rows, function ($row) use ($idOrder) { + return isset($idOrder[(int) ($row['id'] ?? 0)]); + })); + usort($rows, function ($a, $b) use ($idOrder) { + return ($idOrder[(int) $a['id']] ?? 0) <=> ($idOrder[(int) $b['id']] ?? 0); + }); + } + } + + $headers = [ + 'Created At', 'Updated At', 'Status', 'Policy Type', 'Claim Number', 'TPA ID', 'Emp ID', 'Emp Name', + 'Insured Name', 'Corporate Name', 'ACM', 'Insurer', 'TPA', 'Policy No', + 'Priority', 'Relationship', 'Emp Mobile', 'Emp Email', 'Emp Personal Email', + 'Mode of Intimation', 'Claim Type', 'Claim Category', 'Hospital Name', 'DOA', 'DOD', + 'Claim Amount', 'POD No.', 'Date of Join', 'Date of Inception', 'DOB', + 'Date of Accident', 'Date of Death', 'Date of Intimation', 'Sum Insured', + 'Raised Date', 'Registration Date', 'Query Received Date', 'Denial Date', + 'Approved Date', 'Settled Date', 'Denial Reason', 'Approved Letter', + 'Approved Amount', 'UTR Details', 'Settle Letter', 'Return Remark', + 'Cancel Remark', 'AWB No & Courier Name', 'Non ID Reason', + 'Payment Initiate Date', 'Approved Description', 'TAT', 'Claim Created By', + ]; + + $claimTypeMap = $this->claimType; + $priorityMap = $this->priorityType; + $modeMap = $this->modeOFIntimate; + $ticketTypeMap = $this->ticketType; + + $buildRow = function (array $row) use ($claimTypeMap, $priorityMap, $modeMap, $ticketTypeMap): array { + $typeId = (int) ($row['ticket_type_id'] ?? 0); + $claimKey = $row['claim_type'] ?? ''; + $claimTypeLabel = $claimTypeMap[$typeId][$claimKey] ?? ''; + $claimCreatedBy = strtoupper((string) ($row['claim_created_by'] ?? '')); + $claimCreatedByLabel = $claimCreatedBy === 'CRM' ? 'STAFF' : $claimCreatedBy; + $claimCategory = trim((string) ($row['tpa_claim_type'] ?? '')); + + return [ + $row['ticket_created_date'] ?? '', + $row['ticket_updated_date'] ?? '', + $row['status'] ?? '', + str_replace('Claim-', '', $ticketTypeMap[$typeId] ?? ''), + $row['claim_no'] ?? '', + $row['tpa_no'] ?? '', + $row['emp_code'] ?? '', + $row['emp_name'] ?? '', + $row['insured_name'] ?? '', + $row['short_name'] ?? '', + $row['acm_name'] ?? '', + $row['insurer_name'] ?? '', + $row['tpa_name'] ?? '', + $row['policy_no'] ?? '', + $priorityMap[$row['priority'] ?? 0] ?? '', + $row['relationship'] ?? '', + $row['emp_mobile'] ?? '', + $row['emp_mail'] ?? '', + $row['emp_personal_mail'] ?? '', + $modeMap[$row['mode_of_intimation'] ?? ''] ?? '', + $claimTypeLabel, + $claimCategory, + $row['hospital_name'] ?? '', + $row['doa'] ?? '', + $row['dod'] ?? '', + $row['claim_amount'] ?? '', + $row['pod_no'] ?? '', + $row['date_of_join'] ?? '', + $row['date_of_incep'] ?? '', + $row['dob'] ?? '', + $row['date_of_accident'] ?? '', + $row['date_of_death'] ?? '', + $row['date_of_intimat'] ?? '', + $row['si_amt'] ?? '', + $row['raised_date'] ?? '', + $row['registration_date'] ?? '', + $row['query_received_date'] ?? '', + $row['denial_date'] ?? '', + $row['approved_date'] ?? '', + $row['settled_date'] ?? '', + $row['denial_reason'] ?? '', + $row['approved_letter'] ?? '', + $row['approved_amount'] ?? '', + $row['utr_details'] ?? '', + $row['settle_letter'] ?? '', + $row['return_remark'] ?? '', + $row['cancel_remark'] ?? '', + $row['awb_no_courier_name'] ?? '', + $row['non_id_reason'] ?? '', + $row['pay_initiate_date'] ?? '', + $row['approved_description'] ?? '', + $row['tat'] ?? '', + $claimCreatedByLabel, + ]; + }; + + $filename = 'Claim-List-' . date('Y-m-d'); + + if ($format === 'excel') { + $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); + $sheet = $spreadsheet->getActiveSheet(); + $sheet->setTitle('Claim List'); + + $sheet->fromArray([$headers], null, 'A1'); + $rowIndex = 2; + foreach ($rows as $row) { + $sheet->fromArray([$buildRow($row)], null, 'A' . $rowIndex); + $rowIndex++; + } + + // Bold header row + $lastCol = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex(count($headers)); + $sheet->getStyle('A1:' . $lastCol . '1')->getFont()->setBold(true); + + $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet); + header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); + header('Content-Disposition: attachment; filename="' . $filename . '.xlsx"'); + header('Cache-Control: max-age=0'); + ob_end_clean(); + $writer->save('php://output'); + exit; + } + + // Default: CSV + header('Content-Type: text/csv; charset=UTF-8'); + header('Content-Disposition: attachment; filename="' . $filename . '.csv"'); + header('Cache-Control: max-age=0'); + ob_end_clean(); + + $out = fopen('php://output', 'w'); + // UTF-8 BOM for Excel compatibility + fwrite($out, "\xEF\xBB\xBF"); + fputcsv($out, $headers); + foreach ($rows as $row) { + fputcsv($out, $buildRow($row)); + } + fclose($out); + exit; + } + public function ticketSearch($action = null) { $db = db_connect(); @@ -620,6 +769,12 @@ class TicketController extends BaseController // print_r($search_data); die() $where = []; foreach ($search_data as $search_objects => $key) { + if (stripos((string)$search_objects, 'csrf') !== false) { + continue; + } + if ($search_objects === 'export_format' || $search_objects === 'export_ids') { + continue; + } if ($key != null && $key != '' && $key != 0 && $search_objects != 'is_dashboard') { if($search_objects == "date_type" && $search_data[$search_objects] === 'ticket_created_date'){ @@ -730,6 +885,15 @@ class TicketController extends BaseController } } + $exportIdsRaw = $this->request->getPost('export_ids'); + if ($exportIdsRaw !== null) { + $exportIds = array_values(array_filter(array_map('intval', explode(',', (string) $exportIdsRaw)))); + if (empty($exportIds)) { + return []; + } + $query->whereIn('tm.id', $exportIds); + } + $data = $query->get()->getResultArray(); // dd($db->getLastQuery()->getQuery());die; // dd($data); diff --git a/app/Views/ticket_list.php b/app/Views/ticket_list.php index fe1c1cf4..d77cead0 100644 --- a/app/Views/ticket_list.php +++ b/app/Views/ticket_list.php @@ -30,6 +30,15 @@ table.dataTable tbody td { color: #6c757d !important; } +.emp-name-cell { + font-weight: 500; +} + +.tpa-id-truncate { + cursor: default; + white-space: nowrap; +} + .policy-type-icon { display: inline-flex; align-items: center; @@ -93,6 +102,38 @@ table.dataTable tbody td { white-space: nowrap; } +#scroll-horizontal-datatable_wrapper .dt-buttons { + position: relative; +} + +#scroll-horizontal-datatable_wrapper .dt-button-collection { + z-index: 9999 !important; +} + +#scroll-horizontal-datatable_wrapper .ticket-backend-export-menu { + display: none; + background: #00999E; + border: 1px solid #00999E; + border-radius: .25rem; + box-shadow: 0 0.5rem 1rem rgba(0,0,0,.15); + padding: .25rem 0; +} + +#scroll-horizontal-datatable_wrapper .ticket-backend-export-menu .dropdown-item { + display: block; + width: 100%; + padding: .4rem .9rem; + clear: both; + color: #fff; + text-decoration: none; + white-space: nowrap; +} + +#scroll-horizontal-datatable_wrapper .ticket-backend-export-menu .dropdown-item:hover { + background-color: #007A7E; + color: #fff; +} +