diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index 0bc55d7..0332ca7 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -4156,6 +4156,8 @@ function InspectionsTab({ inspections, user, onUpdate, onContinue }) {
const [selectedInspection, setSelectedInspection] = useState(null)
const [searchTerm, setSearchTerm] = useState('')
const [statusFilter, setStatusFilter] = useState('all') // all, completed, incomplete
+ const [dateFrom, setDateFrom] = useState('')
+ const [dateTo, setDateTo] = useState('')
const [currentPage, setCurrentPage] = useState(1)
const itemsPerPage = 10
@@ -4174,7 +4176,23 @@ function InspectionsTab({ inspections, user, onUpdate, onContinue }) {
(statusFilter === 'completed' && inspection.status === 'completed') ||
(statusFilter === 'incomplete' && inspection.status !== 'completed')
- return matchesSearch && matchesStatus
+ // Filtro por rango de fechas
+ let matchesDate = true
+ if (dateFrom || dateTo) {
+ const inspectionDate = new Date(inspection.created_at)
+ if (dateFrom) {
+ const fromDate = new Date(dateFrom)
+ fromDate.setHours(0, 0, 0, 0)
+ matchesDate = matchesDate && inspectionDate >= fromDate
+ }
+ if (dateTo) {
+ const toDate = new Date(dateTo)
+ toDate.setHours(23, 59, 59, 999)
+ matchesDate = matchesDate && inspectionDate <= toDate
+ }
+ }
+
+ return matchesSearch && matchesStatus && matchesDate
})
// Calcular paginación
@@ -4186,7 +4204,7 @@ function InspectionsTab({ inspections, user, onUpdate, onContinue }) {
// Reset a página 1 cuando cambian los filtros
useEffect(() => {
setCurrentPage(1)
- }, [searchTerm, statusFilter])
+ }, [searchTerm, statusFilter, dateFrom, dateTo])
if (inspections.length === 0) {
return (
@@ -4201,12 +4219,13 @@ function InspectionsTab({ inspections, user, onUpdate, onContinue }) {
<>
{/* Buscador y Filtros */}
-
+
{/* Buscador */}
-
+
+
setSearchTerm(e.target.value)}
className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
@@ -4214,36 +4233,92 @@ function InspectionsTab({ inspections, user, onUpdate, onContinue }) {
{/* Filtro de Estado */}
-
+
+
+
+
+
+ {/* Filtro por fecha desde */}
+
+
+ setDateFrom(e.target.value)}
+ className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
+ />
+
+
+
+ {/* Segunda fila de filtros */}
+
+ {/* Filtro por fecha hasta */}
+
+
+ setDateTo(e.target.value)}
+ className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
+ />
+
+
+ {/* Botón limpiar filtros */}
+ {(searchTerm || statusFilter !== 'all' || dateFrom || dateTo) && (
+
+
+
+ )}
{/* Contador de resultados */}
-
- Mostrando {startIndex + 1}-{Math.min(endIndex, filteredInspections.length)} de {filteredInspections.length} inspecciones
+
+
+ Mostrando {filteredInspections.length > 0 ? startIndex + 1 : 0}-{Math.min(endIndex, filteredInspections.length)} de {filteredInspections.length} inspecciones
+
+ {filteredInspections.length > 0 && (
+
+ Página {currentPage} de {totalPages}
+
+ )}
{/* Lista de Inspecciones */}
{filteredInspections.length === 0 ? (
-
No se encontraron inspecciones con los filtros aplicados
-
+
No se encontraron inspecciones
+ {(searchTerm || statusFilter !== 'all' || dateFrom || dateTo) && (
+
+ )}
) : (
@@ -4280,11 +4355,11 @@ function InspectionsTab({ inspections, user, onUpdate, onContinue }) {
)}
{/* Fechas de inspección */}
-
+
{inspection.created_at && (
-
+
📅
- Iniciada: {new Date(inspection.created_at).toLocaleDateString('es-ES', {
+ Inicio: {new Date(inspection.created_at).toLocaleDateString('es-ES', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
@@ -6812,13 +6887,15 @@ function ReportsTab({ user }) {
const [currentPage, setCurrentPage] = useState(1)
const itemsPerPage = 10
const [filters, setFilters] = useState({
- date: '',
+ dateFrom: '',
+ dateTo: '',
mechanicId: '',
checklistId: '',
vehiclePlate: ''
})
const [appliedFilters, setAppliedFilters] = useState({
- date: '',
+ dateFrom: '',
+ dateTo: '',
mechanicId: '',
checklistId: '',
vehiclePlate: ''
@@ -6862,8 +6939,11 @@ function ReportsTab({ user }) {
const API_URL = import.meta.env.VITE_API_URL || ''
let url = `${API_URL}/api/reports/dashboard?`
- if (filtersToApply.date) {
- url += `start_date=${filtersToApply.date}&end_date=${filtersToApply.date}&`
+ if (filtersToApply.dateFrom) {
+ url += `start_date=${filtersToApply.dateFrom}&`
+ }
+ if (filtersToApply.dateTo) {
+ url += `end_date=${filtersToApply.dateTo}&`
}
if (filtersToApply.mechanicId) url += `mechanic_id=${filtersToApply.mechanicId}&`
@@ -6892,8 +6972,11 @@ function ReportsTab({ user }) {
const API_URL = import.meta.env.VITE_API_URL || ''
let url = `${API_URL}/api/reports/inspections?`
- if (filtersToApply.date) {
- url += `start_date=${filtersToApply.date}&end_date=${filtersToApply.date}&`
+ if (filtersToApply.dateFrom) {
+ url += `start_date=${filtersToApply.dateFrom}&`
+ }
+ if (filtersToApply.dateTo) {
+ url += `end_date=${filtersToApply.dateTo}&`
}
if (filtersToApply.mechanicId) url += `mechanic_id=${filtersToApply.mechanicId}&`
@@ -6947,7 +7030,7 @@ function ReportsTab({ user }) {
// Cargar mecánicos y checklists primero
await Promise.all([loadMechanics(), loadChecklists()])
// Luego cargar datos sin filtros (filtros vacíos = todos los datos)
- const emptyFilters = { date: '', mechanicId: '', checklistId: '', vehiclePlate: '' }
+ const emptyFilters = { dateFrom: '', dateTo: '', mechanicId: '', checklistId: '', vehiclePlate: '' }
await Promise.all([loadDashboard(emptyFilters), loadInspections(emptyFilters)])
setLoading(false)
}
@@ -6967,15 +7050,26 @@ function ReportsTab({ user }) {
{/* Filtros */}
🔍 Filtros
-
+
setFilters({...filters, date: e.target.value})}
+ value={filters.dateFrom}
+ onChange={(e) => setFilters({...filters, dateFrom: e.target.value})}
+ className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
+ />
+
+
+
+ setFilters({...filters, dateTo: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
/>
@@ -6989,10 +7083,10 @@ function ReportsTab({ user }) {
onChange={(e) => setFilters({...filters, mechanicId: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
>
-
+
{mechanics.map(mechanic => (
))}
@@ -7007,7 +7101,7 @@ function ReportsTab({ user }) {
onChange={(e) => setFilters({...filters, checklistId: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500"
>
-
+
{checklists.map(checklist => (
-
+
+ {(filters.dateFrom || filters.dateTo || filters.mechanicId || filters.checklistId || filters.vehiclePlate) && (
+
+ )}