Actualizar Interfaz/reporte_ventas.php

This commit is contained in:
maria.ruiz 2025-03-13 06:30:58 +00:00
parent 789acde865
commit 1add878d04
1 changed files with 32 additions and 39 deletions

View File

@ -1,23 +1,18 @@
<?php <?php
// Incluir el archivo de conexión
require 'conexionbd.php'; require 'conexionbd.php';
// Obtener las fechas de inicio y fin desde la solicitud (GET)
$fechaInicio = $_GET['fechaInicio'] ?? ''; $fechaInicio = $_GET['fechaInicio'] ?? '';
$fechaFin = $_GET['fechaFin'] ?? ''; $fechaFin = $_GET['fechaFin'] ?? '';
// Validar que las fechas estén presentes
if (empty($fechaInicio) || empty($fechaFin)) { if (empty($fechaInicio) || empty($fechaFin)) {
die(json_encode(['error' => 'Faltan parámetros (fechaInicio y fechaFin).'])); die(json_encode(['error' => 'Faltan parámetros (fechaInicio y fechaFin).']));
} }
try { 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 = $conn->prepare("SELECT COUNT(*) AS total FROM ventas WHERE fecha_venta BETWEEN :fechaInicio AND :fechaFin");
$stmtTotal->execute([':fechaInicio' => $fechaInicio, ':fechaFin' => $fechaFin]); $stmtTotal->execute([':fechaInicio' => $fechaInicio, ':fechaFin' => $fechaFin]);
$totalBoletos = $stmtTotal->fetch(PDO::FETCH_ASSOC)['total']; $totalBoletos = $stmtTotal->fetch(PDO::FETCH_ASSOC)['total'];
// Consultar las ventas en el período con JOIN a la tabla asientos
$stmtVentas = $conn->prepare(" $stmtVentas = $conn->prepare("
SELECT v.fecha_venta, a.asiento, v.precio SELECT v.fecha_venta, a.asiento, v.precio
FROM ventas v FROM ventas v
@ -27,14 +22,12 @@ try {
$stmtVentas->execute([':fechaInicio' => $fechaInicio, ':fechaFin' => $fechaFin]); $stmtVentas->execute([':fechaInicio' => $fechaInicio, ':fechaFin' => $fechaFin]);
$ventas = $stmtVentas->fetchAll(PDO::FETCH_ASSOC); $ventas = $stmtVentas->fetchAll(PDO::FETCH_ASSOC);
// Devolver los datos en formato JSON
echo json_encode([ echo json_encode([
'success' => true, 'success' => true,
'totalBoletos' => $totalBoletos, 'totalBoletos' => $totalBoletos,
'ventas' => $ventas 'ventas' => $ventas
]); ]);
} catch (PDOException $e) { } catch (PDOException $e) {
// Devolver un mensaje de error en caso de fallo
die(json_encode(['error' => 'Error al consultar las ventas: ' . $e->getMessage()])); die(json_encode(['error' => 'Error al consultar las ventas: ' . $e->getMessage()]));
} }
?> ?>