diff --git a/admin-dashboard.html b/admin-dashboard.html
index e515fc4..441e9a9 100644
--- a/admin-dashboard.html
+++ b/admin-dashboard.html
@@ -1252,6 +1252,57 @@
+
+
@@ -4314,38 +4365,34 @@ function displayReservations(reservations) {
return;
}
- tbody.innerHTML = reservations.map(res => {
- const startDate = new Date(res.start);
- const endDate = new Date(res.end);
-
- // Format date as DD.MM.YYYY
- const formatDate = (date) => {
- const day = String(date.getDate()).padStart(2, '0');
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const year = date.getFullYear();
- return `${day}.${month}.${year}`;
- };
-
- // Format time as HH:MM
- const formatTime = (date) => {
- const hours = String(date.getHours()).padStart(2, '0');
- const minutes = String(date.getMinutes()).padStart(2, '0');
- return `${hours}:${minutes}`;
- };
-
- return `
-
- | ${res.driverName || '-'} |
- ${res.vehicle || '-'} |
- ${formatDate(startDate)} |
- ${formatTime(startDate)} |
- ${formatDate(endDate)} |
- ${formatTime(endDate)} |
- ${res.purpose || '-'} |
- ${calculateDuration(res)} |
-
- `;
- }).join('');
+ // Format date and time as DD.MM.YYYY HH:MM
+ const formatDateTime = (dateString) => {
+ const date = new Date(dateString);
+ const day = String(date.getDate()).padStart(2, '0');
+ const month = String(date.getMonth() + 1).padStart(2, '0');
+ const year = date.getFullYear();
+ const hours = String(date.getHours()).padStart(2, '0');
+ const minutes = String(date.getMinutes()).padStart(2, '0');
+ return `${day}.${month}.${year} ${hours}:${minutes}`;
+ };
+
+ tbody.innerHTML = reservations.map(res => `
+
+ | ${res.driverName || '-'} |
+ ${res.vehicle || '-'} |
+ ${formatDateTime(res.start)} |
+ ${formatDateTime(res.end)} |
+ ${res.purpose || '-'} |
+
+
+
+ |
+
+ `).join('');
}
// Function to filter reservations
@@ -4379,39 +4426,98 @@ function exportReservations() {
const vehicleFilter = document.getElementById('vehicleFilter').value;
const dateFilter = document.getElementById('dateFilter').value;
- let dataToExport = window.allReservations;
+ let dataToExport = [...window.allReservations];
+
+ // Apply filters if set
if (vehicleFilter) {
dataToExport = dataToExport.filter(res => res.vehicle === vehicleFilter);
}
if (dateFilter) {
- dataToExport = dataToExport.filter(res => res.startDate === dateFilter);
+ dataToExport = dataToExport.filter(res => {
+ const resDate = new Date(res.start).toISOString().split('T')[0];
+ return resDate === dateFilter;
+ });
}
- // Create CSV content
- const headers = ['Řidič', 'Vozidlo', 'Datum od', 'Čas od', 'Datum do', 'Čas do', 'Účel', 'Doba trvání'];
- const csvContent = [
- headers.join(','),
- ...dataToExport.map(res => [
- `"${res.driverName}"`,
- `"${res.vehicle}"`,
- res.startDate,
- res.startTime,
- res.endDate,
- res.endTime,
- `"${res.purpose || ''}"`,
- `"${calculateDuration(res)}"`
- ].join(','))
- ].join('\n');
+ // Sort by start date
+ dataToExport.sort((a, b) => new Date(a.start) - new Date(b.start));
- // Create and trigger download
- const blob = new Blob(['\ufeff' + csvContent], { type: 'text/csv;charset=utf-8;' });
+ // Format date as DD.MM.YYYY
+ const formatDate = (dateString) => {
+ const date = new Date(dateString);
+ const day = String(date.getDate()).padStart(2, '0');
+ const month = String(date.getMonth() + 1).padStart(2, '0');
+ const year = date.getFullYear();
+ return `${day}.${month}.${year}`;
+ };
+
+ // Format time as HH:MM
+ const formatTime = (dateString) => {
+ const date = new Date(dateString);
+ const hours = String(date.getHours()).padStart(2, '0');
+ const minutes = String(date.getMinutes()).padStart(2, '0');
+ return `${hours}:${minutes}`;
+ };
+
+ // Format date and time for Excel (YYYY-MM-DD HH:MM)
+ const excelDateTime = (dateString) => {
+ const date = new Date(dateString);
+ const year = date.getFullYear();
+ const month = String(date.getMonth() + 1).padStart(2, '0');
+ const day = String(date.getDate()).padStart(2, '0');
+ const hours = String(date.getHours()).padStart(2, '0');
+ const minutes = String(date.getMinutes()).padStart(2, '0');
+ return `${year}-${month}-${day} ${hours}:${minutes}`;
+ };
+
+ // Create CSV content with semicolon as delimiter for better Excel compatibility
+ const headers = [
+ 'Řidič',
+ 'Vozidlo',
+ 'Začátek rezervace',
+ 'Konec rezervace',
+ 'Doba trvání',
+ 'Účel cesty'
+ ];
+
+ const csvContent = [
+ headers.join(';'),
+ ...dataToExport.map(res => {
+ const start = new Date(res.start);
+ const end = new Date(res.end);
+
+ return [
+ `"${res.driverName || 'Neznámý řidič'}"`,
+ `"${res.vehicle || 'Neznámé vozidlo'}"`,
+ `"${excelDateTime(start)}"`,
+ `"${excelDateTime(end)}"`,
+ `"${calculateDuration(res)}"`,
+ `"${res.purpose || 'Nespecifikováno'}"`
+ ].join(';');
+ })
+ ].join('\r\n');
+
+ // Create and trigger download with proper encoding for Excel
+ const blob = new Blob([
+ '\ufeff', // UTF-8 BOM for Excel
+ csvContent
+ ], {
+ type: 'text/csv;charset=utf-8;'
+ });
+
const link = document.createElement('a');
- const date = new Date().toISOString().split('T')[0];
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
link.href = URL.createObjectURL(blob);
- link.download = `rezervace_${date}.csv`;
+ link.download = `rezervace_${timestamp}.csv`;
+ link.style.display = 'none';
document.body.appendChild(link);
link.click();
- document.body.removeChild(link);
+
+ // Clean up
+ setTimeout(() => {
+ document.body.removeChild(link);
+ URL.revokeObjectURL(link.href);
+ }, 100);
}
// Helper function to format date and time