diff --git a/api.php b/api.php index ee7d911..e7f02fe 100644 --- a/api.php +++ b/api.php @@ -29,14 +29,13 @@ try { $stmt = $pdo->query( "SELECT t.id, t.nombre, t.licencia, t.matricula, t.municipio, - lt.latitud, lt.longitud, lt.ultima_actualizacion, + t.ultima_localizacion_lat as latitud, t.ultima_localizacion_lng as longitud, (SELECT COUNT(*) FROM documents WHERE id_conductor = t.id) as num_documentos, (SELECT COUNT(*) FROM citas WHERE id_conductor = t.id) as num_citas, (SELECT COUNT(*) FROM consultas WHERE id_conductor = t.id) as num_consultas, (SELECT COUNT(*) FROM localizacion_historico WHERE id_taxi = t.id) as num_ubicaciones - FROM localizacion_taxis lt - JOIN taxis t ON lt.id_taxi = t.id - GROUP BY t.id, lt.latitud, lt.longitud, lt.ultima_actualizacion + FROM taxis t + GROUP BY t.id ORDER BY t.nombre ASC" ); $locations = $stmt->fetchAll(PDO::FETCH_ASSOC); diff --git a/citas.php b/citas.php index 3abba57..83c327b 100644 --- a/citas.php +++ b/citas.php @@ -55,12 +55,18 @@ try { $estado = $_POST['estado']; if (!empty($title) && !empty($fecha) && !empty($hora_inicio) && !empty($hora_fin) && !empty($id_departamento)) { - $start_event = $fecha . ' ' . $hora_inicio; - $end_event = $fecha . ' ' . $hora_fin; - - $stmt = $pdo->prepare("INSERT INTO citas (title, start_event, end_event, id_departamento, id_conductor, lugar, usuarios, estado) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); - $stmt->execute([$title, $start_event, $end_event, $id_departamento, $id_conductor, $lugar, $usuarios, $estado]); - $message = '
Cita añadida con éxito.
'; + try { + $start_event_dt = new DateTime($fecha . ' ' . $hora_inicio); + $end_event_dt = new DateTime($fecha . ' ' . $hora_fin); + $start_event = $start_event_dt->format('Y-m-d H:i:s'); + $end_event = $end_event_dt->format('Y-m-d H:i:s'); + + $stmt = $pdo->prepare("INSERT INTO citas (title, start_event, end_event, id_departamento, id_conductor, lugar, usuarios, estado) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$title, $start_event, $end_event, $id_departamento, $id_conductor, $lugar, $usuarios, $estado]); + $message = '
Cita añadida con éxito.
'; + } catch (Exception $e) { + $message = '
Formato de fecha u hora inválido.
'; + } } else { $message = '
Título, fecha, horas y departamento son obligatorios.
'; } diff --git a/drivers.php b/drivers.php index 95d6a8b..adb8831 100644 --- a/drivers.php +++ b/drivers.php @@ -58,7 +58,7 @@ try { (SELECT COUNT(*) FROM documents WHERE id_conductor = t.id) as num_documentos, (SELECT COUNT(*) FROM citas WHERE id_conductor = t.id) as num_citas, (SELECT COUNT(*) FROM consultas WHERE id_conductor = t.id) as num_consultas, - (SELECT COUNT(*) FROM taxi_locations WHERE taxi_id = t.id) as num_ubicaciones + (SELECT COUNT(*) FROM localizacion_historico WHERE id_taxi = t.id) as num_ubicaciones FROM taxis t GROUP BY t.id ORDER BY t.nombre ASC")->fetchAll(PDO::FETCH_ASSOC);