70 lines
2.3 KiB
PHP
70 lines
2.3 KiB
PHP
<?php
|
|
// api/asientos.php - API para obtener el mapa de asientos
|
|
session_start();
|
|
|
|
require_once '../modelo/BaseDatos.php';
|
|
require_once '../modelo/Sala.php';
|
|
require_once '../modelo/Boleto.php';
|
|
require_once '../modelo/Venta.php';
|
|
require_once 'VendedorController.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
try {
|
|
// Conexión a base de datos
|
|
$db = new BaseDatos('localhost', 'root', 'password', 'boletos_db');
|
|
|
|
// Inicializar el controlador
|
|
$vendedorController = new VendedorController($db);
|
|
|
|
// Cargar sala (solo hay una sala con id=1)
|
|
$sala = $vendedorController->cargarSala(1);
|
|
|
|
// Si no hay sala, podríamos inicializarla para desarrollo
|
|
if (!$sala) {
|
|
$sala = new Sala(1, 'Sala Principal');
|
|
$sala->inicializarBoletos(10, 15, 50.00); // 10 filas, 15 asientos por fila, $50 cada uno
|
|
}
|
|
|
|
// Obtener parámetros de fecha
|
|
$fechaInicio = isset($_GET['fechaInicio']) ? $_GET['fechaInicio'] : null;
|
|
$fechaFin = isset($_GET['fechaFin']) ? $_GET['fechaFin'] : null;
|
|
|
|
// Obtener mapa de asientos
|
|
$mapaAsientos = $vendedorController->mostrarDisponibilidadAsientos();
|
|
|
|
// Filtrar por fecha si se proporcionan las fechas
|
|
if ($fechaInicio && $fechaFin) {
|
|
$query = "SELECT b.id, b.fila, b.numero, b.precio, b.estado
|
|
FROM boletos b
|
|
JOIN venta_boletos vb ON b.id = vb.id_boleto
|
|
JOIN ventas v ON vb.id_venta = v.id
|
|
WHERE DATE(v.fecha) BETWEEN ? AND ?";
|
|
$stmt = $db->getConexion()->prepare($query);
|
|
$stmt->bind_param("ss", $fechaInicio, $fechaFin);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
$mapaAsientos = [];
|
|
while ($fila = $result->fetch_assoc()) {
|
|
$mapaAsientos[$fila['fila']][$fila['numero']] = $fila['estado'];
|
|
}
|
|
}
|
|
|
|
// Preparar respuesta
|
|
$response = [
|
|
'success' => true,
|
|
'mapa' => $mapaAsientos,
|
|
'precio' => 50.00 // Agregamos el precio de los boletos a la respuesta
|
|
];
|
|
|
|
echo json_encode($response);
|
|
|
|
} catch (Exception $e) {
|
|
// Manejar errores y devolver una respuesta JSON
|
|
$response = [
|
|
'success' => false,
|
|
'message' => 'Error al obtener el mapa de asientos: ' . $e->getMessage()
|
|
];
|
|
echo json_encode($response);
|
|
} |