From 1add878d04eef46570637b087a7e41be22a3af10 Mon Sep 17 00:00:00 2001 From: "maria.ruiz" <zs22016128@estudiantes.uv.mx> Date: Thu, 13 Mar 2025 06:30:58 +0000 Subject: [PATCH] Actualizar Interfaz/reporte_ventas.php --- Interfaz/reporte_ventas.php | 71 +++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/Interfaz/reporte_ventas.php b/Interfaz/reporte_ventas.php index 61e3f6f..f064bbe 100644 --- a/Interfaz/reporte_ventas.php +++ b/Interfaz/reporte_ventas.php @@ -1,40 +1,33 @@ -<?php -// Incluir el archivo de conexión -require 'conexionbd.php'; - -// Obtener las fechas de inicio y fin desde la solicitud (GET) -$fechaInicio = $_GET['fechaInicio'] ?? ''; -$fechaFin = $_GET['fechaFin'] ?? ''; - -// Validar que las fechas estén presentes -if (empty($fechaInicio) || empty($fechaFin)) { - die(json_encode(['error' => 'Faltan parámetros (fechaInicio y fechaFin).'])); -} - -try { - // Consultar el total de boletos vendidos en el período - $stmtTotal = $conn->prepare("SELECT COUNT(*) AS total FROM ventas WHERE fecha_venta BETWEEN :fechaInicio AND :fechaFin"); - $stmtTotal->execute([':fechaInicio' => $fechaInicio, ':fechaFin' => $fechaFin]); - $totalBoletos = $stmtTotal->fetch(PDO::FETCH_ASSOC)['total']; - - // Consultar las ventas en el período con JOIN a la tabla asientos - $stmtVentas = $conn->prepare(" - SELECT v.fecha_venta, a.asiento, v.precio - FROM ventas v - JOIN asientos a ON v.asiento_id = a.id - WHERE v.fecha_venta BETWEEN :fechaInicio AND :fechaFin - "); - $stmtVentas->execute([':fechaInicio' => $fechaInicio, ':fechaFin' => $fechaFin]); - $ventas = $stmtVentas->fetchAll(PDO::FETCH_ASSOC); - - // Devolver los datos en formato JSON - echo json_encode([ - 'success' => true, - 'totalBoletos' => $totalBoletos, - 'ventas' => $ventas - ]); -} catch (PDOException $e) { - // Devolver un mensaje de error en caso de fallo - die(json_encode(['error' => 'Error al consultar las ventas: ' . $e->getMessage()])); -} +<?php +require 'conexionbd.php'; + +$fechaInicio = $_GET['fechaInicio'] ?? ''; +$fechaFin = $_GET['fechaFin'] ?? ''; + +if (empty($fechaInicio) || empty($fechaFin)) { + die(json_encode(['error' => 'Faltan parámetros (fechaInicio y fechaFin).'])); +} + +try { + $stmtTotal = $conn->prepare("SELECT COUNT(*) AS total FROM ventas WHERE fecha_venta BETWEEN :fechaInicio AND :fechaFin"); + $stmtTotal->execute([':fechaInicio' => $fechaInicio, ':fechaFin' => $fechaFin]); + $totalBoletos = $stmtTotal->fetch(PDO::FETCH_ASSOC)['total']; + + $stmtVentas = $conn->prepare(" + SELECT v.fecha_venta, a.asiento, v.precio + FROM ventas v + JOIN asientos a ON v.asiento_id = a.id + WHERE v.fecha_venta BETWEEN :fechaInicio AND :fechaFin + "); + $stmtVentas->execute([':fechaInicio' => $fechaInicio, ':fechaFin' => $fechaFin]); + $ventas = $stmtVentas->fetchAll(PDO::FETCH_ASSOC); + + echo json_encode([ + 'success' => true, + 'totalBoletos' => $totalBoletos, + 'ventas' => $ventas + ]); +} catch (PDOException $e) { + die(json_encode(['error' => 'Error al consultar las ventas: ' . $e->getMessage()])); +} ?> \ No newline at end of file