-
+
-
-
+
+
Por favor, seleccione un departamento o conductor para ver el calendario y las citas.
+
+
+
+
+
+
+
+
+ Título de la cita
+
+
+
+
+ Seleccione departamento
+
+ >
+
+ Departamento
+
+ Seleccione un conductor (Opcional)
+
+ >
+
+ Conductor
+
+
+
+ Lugar
+
+
+
+ Usuarios
+
+
+ Pendiente
+ Confirmada
+ Cancelada
+ Estado
+ Añadir Cita
+
+
+
+
+
+?>
\ No newline at end of file
diff --git a/consultas.php b/consultas.php
index 6a12016..778bd9a 100644
--- a/consultas.php
+++ b/consultas.php
@@ -2,53 +2,82 @@
require_once 'db/config.php';
require_once 'header.php';
+$message = '';
+$message_type = '';
+
+// --- DB Schema and Data Fetching ---
try {
$pdo = db();
- // Create table if it doesn't exist
+ // Create/update consultas table
$pdo->exec("CREATE TABLE IF NOT EXISTS consultas (
id INT AUTO_INCREMENT PRIMARY KEY,
- id_taxista INT NOT NULL,
+ id_conductor INT NOT NULL,
id_departamento INT NOT NULL,
+ asunto VARCHAR(255) NOT NULL,
resultado TEXT,
+ status VARCHAR(50) DEFAULT 'Pendiente',
fecha_consulta TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
- FOREIGN KEY (id_taxista) REFERENCES drivers(id),
- FOREIGN KEY (id_departamento) REFERENCES departamentos(id)
+ FOREIGN KEY (id_conductor) REFERENCES taxis(id) ON DELETE CASCADE,
+ FOREIGN KEY (id_departamento) REFERENCES departamentos(id) ON DELETE CASCADE
)");
+ // Fetch departments for dropdowns
+ $departamentos = $pdo->query("SELECT id, nombre FROM departamentos ORDER BY nombre")->fetchAll(PDO::FETCH_ASSOC);
+
+ // Fetch taxis/conductores for dropdowns
+ $conductores = $pdo->query("SELECT id, matricula FROM taxis ORDER BY matricula")->fetchAll(PDO::FETCH_ASSOC);
+
+ // Get selected department for filtering
+ $selected_depto_id = $_GET['id_departamento'] ?? null;
+
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_consulta'])) {
- $id_taxista = $_POST['id_taxista'];
+ $id_conductor = $_POST['id_conductor'];
$id_departamento = $_POST['id_departamento'];
+ $asunto = trim($_POST['asunto']);
$resultado = trim($_POST['resultado']);
+ $status = $_POST['status'];
- if (!empty($id_taxista) && !empty($id_departamento)) {
- $stmt = $pdo->prepare("INSERT INTO consultas (id_taxista, id_departamento, resultado) VALUES (?, ?, ?)");
- $stmt->execute([$id_taxista, $id_departamento, $resultado]);
- echo '
Consulta añadida con éxito.
';
+ if (!empty($id_conductor) && !empty($id_departamento) && !empty($asunto)) {
+ $stmt = $pdo->prepare("INSERT INTO consultas (id_conductor, id_departamento, asunto, resultado, status) VALUES (?, ?, ?, ?, ?)");
+ $stmt->execute([$id_conductor, $id_departamento, $asunto, $resultado, $status]);
+ $message = '
Consulta añadida con éxito.
';
} else {
- echo '
Taxista y departamento son obligatorios.
';
+ $message = '
Conductor, departamento y asunto son obligatorios.
';
}
}
- // Fetch all drivers for dropdown
- $drivers_stmt = $pdo->query("SELECT id, name FROM drivers ORDER BY name");
- $drivers = $drivers_stmt->fetchAll(PDO::FETCH_ASSOC);
+ // Fetch consultations
+ $filter_status = $_GET['status'] ?? null;
+ $sql = "SELECT c.id, t.matricula as conductor_nombre, dep.nombre as departamento_nombre, c.asunto, c.resultado, c.status, c.fecha_consulta
+ FROM consultas c
+ JOIN taxis t ON c.id_conductor = t.id
+ JOIN departamentos dep ON c.id_departamento = dep.id";
+
+ $conditions = [];
+ $params = [];
+ if ($filter_status) {
+ $conditions[] = "c.status = :status";
+ $params[':status'] = $filter_status;
+ }
+ if ($selected_depto_id) {
+ $conditions[] = "c.id_departamento = :id_departamento";
+ $params[':id_departamento'] = $selected_depto_id;
+ }
- // Fetch all departments for dropdown
- $departamentos_stmt = $pdo->query("SELECT id, nombre FROM departamentos ORDER BY nombre");
- $departamentos = $departamentos_stmt->fetchAll(PDO::FETCH_ASSOC);
-
- // Fetch all consultas
- $stmt = $pdo->query("SELECT c.id, d.name as taxista_nombre, dep.nombre as departamento_nombre, c.resultado, c.fecha_consulta
- FROM consultas c
- JOIN drivers d ON c.id_taxista = d.id
- JOIN departamentos dep ON c.id_departamento = dep.id
- ORDER BY c.fecha_consulta DESC");
+ if (count($conditions) > 0) {
+ $sql .= " WHERE " . implode(' AND ', $conditions);
+ }
+
+ $sql .= " ORDER BY c.fecha_consulta DESC";
+ $stmt = $pdo->prepare($sql);
+ $stmt->execute($params);
$consultas = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
- die("Error de base de datos: " . $e->getMessage());
+ $message = "Error de base de datos: " . $e->getMessage();
+ $message_type = 'danger';
}
?>
@@ -59,85 +88,101 @@ try {
Consultas
+
+
+
+
+
+
-
+
-
-
-
-
-
- Seleccione un taxista
-
-
-
-
- Taxista
-
-
-
-
-
- Seleccione un departamento
-
-
-
-
- Departamento
-
-
-
-
-
- Resultado
-
-
-
- Añadir Consulta
-
+
+
-
+
-
-
-
- ID
- Taxista
- Departamento
- Resultado
- Fecha
-
-
+
+
+
+ Asunto
+
+
+
+
+
+ Seleccione un conductor
+
+
+
+
+ Conductor
+
+
+
+
+
+ Seleccione un departamento
+
+
+
+
+ Departamento
+
+
+
+
+
+ Resultado
+
+
+
+ Pendiente
+ En Progreso
+ Resuelta
+
+ Estado
+
+
+ Añadir Consulta
+
+
+
+
+
+
+
+
+
+ Conductor Departamento Asunto Resultado Estado Fecha
-
-
-
-
-
-
-
-
-
+
+ No hay consultas.
+
- No hay consultas registradas.
+
+
+
+
+
+
-
+
diff --git a/departamentos.php b/departamentos.php
index 6e0b2d5..440b869 100644
--- a/departamentos.php
+++ b/departamentos.php
@@ -1,114 +1,160 @@
exec("CREATE TABLE IF NOT EXISTS departamentos (
id INT AUTO_INCREMENT PRIMARY KEY,
- nombre VARCHAR(255) NOT NULL,
- color VARCHAR(7) DEFAULT '#FFFFFF',
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
- )");
+ nombre VARCHAR(255) NOT NULL UNIQUE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;");
- // Handle form submission
- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_department'])) {
- $nombre = trim($_POST['nombre']);
- $color = trim($_POST['color']);
-
- if (!empty($nombre)) {
- $stmt = $pdo->prepare("INSERT INTO departamentos (nombre, color) VALUES (?, ?)");
- $stmt->execute([$nombre, $color]);
- echo '
Departamento añadido con éxito.
';
- } else {
- echo '
El nombre del departamento es obligatorio.
';
+ $message = '';
+ // Handle POST requests
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ // Add new
+ if (isset($_POST['add_departamento'])) {
+ $nombre = trim($_POST['nombre']);
+ if (!empty($nombre)) {
+ $stmt = $pdo->prepare("INSERT INTO departamentos (nombre) VALUES (?)");
+ $stmt->execute([$nombre]);
+ $message = '
Departamento añadido.
';
+ } else {
+ $message = '
El nombre no puede estar vacío.
';
+ }
+ }
+ // Update
+ elseif (isset($_POST['update_departamento'])) {
+ $id = $_POST['id'];
+ $nombre = trim($_POST['nombre']);
+ if (!empty($nombre)) {
+ $stmt = $pdo->prepare("UPDATE departamentos SET nombre = ? WHERE id = ?");
+ $stmt->execute([$nombre, $id]);
+ $message = '
Departamento actualizado.
';
+ } else {
+ $message = '
El nombre no puede estar vacío.
';
+ }
+ }
+ // Delete
+ elseif (isset($_POST['delete_departamento'])) {
+ $id = $_POST['id'];
+ $stmt = $pdo->prepare("DELETE FROM departamentos WHERE id = ?");
+ $stmt->execute([$id]);
+ $message = '
Departamento eliminado.
';
}
}
// Fetch all departments
- $stmt = $pdo->query("SELECT id, nombre, color, created_at FROM departamentos ORDER BY created_at DESC");
- $departamentos = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ $departamentos = $pdo->query("SELECT * FROM departamentos ORDER BY nombre")->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
- die("Error de base de datos: " . $e->getMessage());
+ die("DB ERROR: " . $e->getMessage());
}
+
+include 'header.php';
?>
-
Departamentos
+
Gestión de Departamentos
Dashboard
Departamentos
-
-
-
-
-
-
-
-
- Nombre del departamento
-
-
-
-
-
-
- Añadir Departamento
-
-
-
-
-
+
-
-