The DevolutionSync dashboard provides comprehensive analytics for product returns, displaying real-time statistics filtered by date with breakdowns by status, return type, and quantities. All users can access the dashboard with role-appropriate data visibility.
public function __construct() { // Iniciamos sesión si no está iniciada if (session_status() === PHP_SESSION_NONE) session_start(); // Verificamos autenticación if (!isset($_SESSION['logged_in'])) { header('Location: index.php?url=auth/index'); exit; } // Usamos DevolucionModel que ya tiene la lógica de estadísticas centralizada $this->model = new DevolucionModel();}
Unlike other features, the dashboard is accessible to all user roles (Admin, Auxiliary, and Consultation).
public function index() { // Capturar fecha del filtro o usar la actual $fechaFiltro = $_GET['fecha'] ?? date('Y-m-d'); // 1. Obtener estadísticas del día seleccionado $statsHoy = $this->model->obtenerEstadisticas($fechaFiltro); // 2. Obtener estadísticas históricas (sin pasar fecha) $statsGeneral = $this->model->obtenerEstadisticas(); // 3. Obtener fechas disponibles para el select $fechas = $this->model->obtenerFechas(); $titulo = "Dashboard General - DevolutionSync"; require_once 'Views/home/dashboard.php';}
The obtenerEstadisticas() method generates comprehensive analytics:
models/DevolucionModel.php
public function obtenerEstadisticas($fecha = null) { $where = $fecha ? "WHERE DATE(fecha_creacion) = :fecha" : ""; // Usamos COALESCE para que devuelva 0 en vez de NULL si no hay datos $sql = "SELECT COUNT(*) as total, COALESCE(SUM(cantidad_kg), 0) as total_kg, COALESCE(SUM(cantidad_und), 0) as total_und, -- Conteo por Estados COUNT(CASE WHEN estado = 'Pendiente' THEN 1 END) as pendientes, COUNT(CASE WHEN estado = 'Aprobado' THEN 1 END) as aprobados, COUNT(CASE WHEN estado = 'Rechazado' THEN 1 END) as rechazados, -- Conteo por Motivos COUNT(CASE WHEN motivo = 'Devolucion' THEN 1 END) as motivo_dev, COUNT(CASE WHEN motivo = 'Faltante' THEN 1 END) as motivo_fal, COUNT(CASE WHEN motivo = 'Sobrante' THEN 1 END) as motivo_sob FROM devoluciones $where"; $stmt = $this->db->prepare($sql); if ($fecha) $stmt->bindValue(':fecha', $fecha); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC);}
With Date Filter
Without Date Filter
When $fecha is provided, the query includes WHERE DATE(fecha_creacion) = :fecha to return statistics for a specific day.
When $fecha is null, the query returns aggregate statistics across all dates in the database.
public function obtenerFechas() { $stmt = $this->db->query("SELECT DISTINCT DATE(fecha_creacion) as fecha FROM devoluciones ORDER BY fecha DESC"); return $stmt->fetchAll(PDO::FETCH_COLUMN);}