34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?php
|
|
include 'conexion.php';
|
|
|
|
$fechaInicio = $_GET['fechaInicio'] ?? null;
|
|
$fechaFin = $_GET['fechaFin'] ?? null;
|
|
|
|
if (!$fechaInicio || !$fechaFin) {
|
|
die("Debe seleccionar un período de fechas.");
|
|
}
|
|
|
|
header('Content-Type: text/csv; charset=utf-8');
|
|
header('Content-Disposition: attachment; filename=reporte_ventas.csv');
|
|
|
|
$output = fopen("php://output", "w");
|
|
fputcsv($output, ['ID', 'Concierto', 'Fecha', 'Hora', 'Zona', 'Asiento', 'Precio', 'Fecha Venta']);
|
|
|
|
$sql = "SELECT b.id, c.nombre AS concierto, c.fecha, c.hora, z.nombre AS zona, a.numero AS asiento, b.precio, b.fecha_venta
|
|
FROM boletos b
|
|
JOIN asientos a ON b.asiento_id = a.id
|
|
JOIN zonas z ON a.zona_id = z.id
|
|
JOIN conciertos c ON z.concierto_id = c.id
|
|
WHERE DATE(b.fecha_venta) BETWEEN ? AND ?";
|
|
$stmt = $conn->prepare($sql);
|
|
$stmt->bind_param("ss", $fechaInicio, $fechaFin);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
while ($row = $result->fetch_assoc()) {
|
|
fputcsv($output, $row);
|
|
}
|
|
|
|
fclose($output);
|
|
?>
|