TicketMerc/Interfaz/control/reporte_ventas.php

33 lines
1.1 KiB
PHP

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