is_numeric($id)); $selectedIdsList = implode(',', array_map('intval', $selectedIds)); if (empty($selectedIdsList)) { die('Invalid selection.'); } // Fetch only selected records $query = "SELECT * FROM `road_challans` WHERE id IN ($selectedIdsList) ORDER BY `id` DESC"; $result = $conn->query($query); // Set headers for Excel file download header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=delivery_lead_time_" . date("Ymd_His") . ".xls"); header("Pragma: no-cache"); header("Expires: 0"); // Begin table output echo ""; echo ""; if ($result && $result->num_rows > 0) { $index = 1; while ($row = $result->fetch_assoc()) { // Safely create DateTime objects $date = !empty($row['d_vehicle_date']) ? new DateTime($row['d_vehicle_date']) : null; $date_of_reach = !empty($row['date_of_reach']) ? new DateTime($row['date_of_reach']) : null; $date_of_unloading = !empty($row['date_of_unloading']) ? new DateTime($row['date_of_unloading']) : null; // Initialize difference values $days_to_reach = $days_to_unload = $total_days = 'N/A'; if ($date && $date_of_reach) { $days_to_reach = $date->diff($date_of_reach)->days; } if ($date_of_reach && $date_of_unloading) { $days_to_unload = $date_of_reach->diff($date_of_unloading)->days; } if ($date && $date_of_unloading) { $total_days = $date->diff($date_of_unloading)->days; } // Format unloaded date and time $unloaded_date = $date_of_unloading ? $date_of_unloading->format('Y-m-d') : 'N/A'; $unloaded_time = $date_of_unloading ? $date_of_unloading->format('H:i:s') : ''; echo ""; $index++; } } else { echo ""; } echo "
Sl No. Seller Company Purchaser Company Challan No. Challan Date Reach Date Unloaded Date Unloaded Time Despatch To Reach Time (Days) Reach To Unload Time (Days) Dispatch To Unload Time (Days)
{$index} " . htmlspecialchars($row['consignorName'] ?? '') . " " . htmlspecialchars($row['name'] ?? '') . " " . htmlspecialchars($row['challan_no'] ?? '') . " " . htmlspecialchars($row['date'] ?? '') . " " . htmlspecialchars($row['date_of_reach'] ?? '') . " {$unloaded_date} {$unloaded_time} {$days_to_reach} {$days_to_unload} {$total_days}
No matching data found.
";