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,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()]));
}
?>