is_numeric($id)); $selectedIdsList = implode(',', array_map('intval', $selectedIds)); if (empty($selectedIdsList)) { die('Invalid selection.'); } // Fetch records $query = "SELECT * FROM `road_challans` WHERE id IN ($selectedIdsList) ORDER BY `id` DESC"; $result = $conn->query($query); // Excel headers header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=purchase_report_" . date("Ymd_His") . ".xls"); header("Pragma: no-cache"); header("Expires: 0"); // Output table echo ""; echo ""; if ($result && $result->num_rows > 0) { $index = 1; while ($row = $result->fetch_assoc()) { $cgst = ($row['cgst'] !== '' && $row['cgst'] !== null) ? $row['cgst'] : 'NULL'; $sgst = ($row['sgst'] !== '' && $row['sgst'] !== null) ? $row['sgst'] : 'NULL'; $igst = ($row['igst'] !== '' && $row['igst'] !== null) ? $row['igst'] : 'NULL'; echo ""; $index++; } } else { echo ""; } echo "
Sl No. Seller Company Purchaser Company Challan No. Challan Date Invoice No. Invoice Date Rate Value CGST SGST IGST Total
{$index} " . htmlspecialchars((string)($row['consignorName'] ?? '')) . " " . htmlspecialchars((string)($row['name'] ?? '')) . " " . htmlspecialchars((string)($row['challan_no'] ?? '')) . " " . htmlspecialchars((string)($row['date'] ?? '')) . " " . htmlspecialchars((string)($row['bill_book_invoice'] ?? '')) . " " . htmlspecialchars((string)($row['bill_book_date'] ?? '')) . " " . htmlspecialchars((string)($row['rate'] ?? '')) . " " . htmlspecialchars((string)($row['amount'] ?? '')) . " {$cgst} {$sgst} {$igst} " . htmlspecialchars((string)($row['finalAmount'] ?? '')) . "
No matching data found.
";