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=sales_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()) { $date_of_unloading = !empty($row['date_of_unloading']) ? new DateTime($row['date_of_unloading']) : null; $unloading_date = $date_of_unloading ? $date_of_unloading->format('Y-m-d') : 'N/A'; $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 Unloaded Date Quantity Unloaded Rate Value CGST SGST IGST Total
{$index} " . htmlspecialchars((string)($row['consignorName'] ?? '')) . " " . htmlspecialchars((string)($row['name'] ?? '')) . " " . htmlspecialchars((string)($row['challan_no'] ?? '')) . " " . htmlspecialchars((string)($row['date'] ?? '')) . " {$unloading_date} " . htmlspecialchars((string)($row['quantity_billed'] ?? '')) . " " . htmlspecialchars((string)($row['rate'] ?? '')) . " " . htmlspecialchars((string)($row['amount'] ?? '')) . " {$cgst} {$sgst} {$igst} " . htmlspecialchars((string)($row['finalAmount'] ?? '')) . "
No matching data found.
";