156 lines
5.0 KiB
JavaScript
156 lines
5.0 KiB
JavaScript
const filas = 10;
|
|
const columnas = 12;
|
|
let diaSeleccionado = 23;
|
|
const asientosVendidos = { 22: new Set(), 23: new Set(), 24: new Set() };
|
|
let asientosSeleccionados = new Set();
|
|
|
|
|
|
function cargarAsientos() {
|
|
const artista = "The Driver Era";
|
|
const url = `control/consultar_asientos.php?artista=${encodeURIComponent(artista)}&dia=${diaSeleccionado}`;
|
|
|
|
fetch(url)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.error) {
|
|
console.error("Error al cargar los asientos:", data.error);
|
|
return;
|
|
}
|
|
|
|
asientosVendidos[diaSeleccionado].clear();
|
|
|
|
data.asientos.forEach(asiento => {
|
|
if (asiento.estado === 'vendido') {
|
|
asientosVendidos[diaSeleccionado].add(asiento.asiento);
|
|
}
|
|
});
|
|
|
|
renderizarAsientos();
|
|
})
|
|
.catch(error => console.error('Error al cargar los asientos:', error));
|
|
}
|
|
|
|
function seleccionarDia(dia) {
|
|
diaSeleccionado = dia;
|
|
asientosSeleccionados.clear();
|
|
document.querySelectorAll('.dias button').forEach(btn => btn.classList.remove('selected'));
|
|
event.target.classList.add('selected');
|
|
cargarAsientos();
|
|
}
|
|
|
|
|
|
function toggleAsiento(asiento) {
|
|
if (asientosVendidos[diaSeleccionado].has(asiento)) return;
|
|
if (asientosSeleccionados.has(asiento)) {
|
|
asientosSeleccionados.delete(asiento);
|
|
} else {
|
|
asientosSeleccionados.add(asiento);
|
|
}
|
|
renderizarAsientos();
|
|
}
|
|
|
|
function venderAsientos() {
|
|
if (asientosSeleccionados.size === 0) {
|
|
alert("Selecciona al menos un asiento para vender.");
|
|
return;
|
|
}
|
|
|
|
const artista = "The Driver Era"; // Cambia esto según el artista
|
|
const precioPorAsiento = 100; // Precio en dólares
|
|
const precioTotal = asientosSeleccionados.size * precioPorAsiento;
|
|
const fechaHora = new Date().toLocaleString();
|
|
|
|
// Llenar los datos del modal
|
|
document.getElementById('modalArtista').textContent = artista;
|
|
document.getElementById('modalDia').textContent = diaSeleccionado;
|
|
document.getElementById('modalAsientos').textContent = Array.from(asientosSeleccionados).join(', ');
|
|
document.getElementById('modalPrecioTotal').textContent = `$${precioTotal}`;
|
|
document.getElementById('modalFechaHora').textContent = fechaHora;
|
|
|
|
// Mostrar el modal
|
|
document.getElementById('comprobanteModal').style.display = 'block';
|
|
}
|
|
|
|
function confirmarVenta() {
|
|
const artista = "The Driver Era"; // Cambia esto según el artista
|
|
const url = 'control/vender_asientos.php';
|
|
const data = {
|
|
artista: artista,
|
|
dia: diaSeleccionado,
|
|
asientos: Array.from(asientosSeleccionados)
|
|
};
|
|
|
|
fetch(url, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(data)
|
|
})
|
|
.then(response => response.json())
|
|
.then(result => {
|
|
if (result.error) {
|
|
console.error("Error al vender los asientos:", result.error);
|
|
alert("Error al vender los asientos: " + result.error);
|
|
} else {
|
|
console.log("Venta realizada:", result.message);
|
|
alert(result.message);
|
|
|
|
// Marcar los asientos como vendidos en la interfaz
|
|
asientosSeleccionados.forEach(asiento => {
|
|
asientosVendidos[diaSeleccionado].add(asiento);
|
|
});
|
|
asientosSeleccionados.clear();
|
|
renderizarAsientos();
|
|
}
|
|
})
|
|
.catch(error => console.error('Error al vender los asientos:', error));
|
|
|
|
// Cerrar el modal
|
|
document.getElementById('comprobanteModal').style.display = 'none';
|
|
}
|
|
|
|
function rechazarVenta() {
|
|
// Deseleccionar los asientos
|
|
asientosSeleccionados.clear();
|
|
renderizarAsientos();
|
|
|
|
// Mostrar mensaje de compra cancelada
|
|
alert("Compra cancelada");
|
|
|
|
// Cerrar el modal
|
|
document.getElementById('comprobanteModal').style.display = 'none';
|
|
}
|
|
|
|
// Función para renderizar los asientos
|
|
function renderizarAsientos() {
|
|
const contenedor = document.getElementById('asientos');
|
|
contenedor.innerHTML = '';
|
|
for (let i = 0; i < filas * columnas; i++) {
|
|
const asiento = `${Math.floor(i / columnas) + 1}${String.fromCharCode(65 + (i % columnas))}`;
|
|
const boton = document.createElement('button');
|
|
boton.className = 'asiento';
|
|
if (asientosVendidos[diaSeleccionado].has(asiento)) {
|
|
boton.classList.add('vendido');
|
|
} else if (asientosSeleccionados.has(asiento)) {
|
|
boton.style.backgroundColor = 'orange';
|
|
}
|
|
boton.textContent = asiento;
|
|
boton.onclick = () => toggleAsiento(asiento);
|
|
contenedor.appendChild(boton);
|
|
}
|
|
}
|
|
|
|
// Cargar los asientos al iniciar la página
|
|
cargarAsientos();
|
|
|
|
// Manejar el cierre del modal
|
|
const modal = document.getElementById('comprobanteModal');
|
|
const span = document.getElementsByClassName('close')[0];
|
|
|
|
span.onclick = () => modal.style.display = 'none';
|
|
window.onclick = (event) => {
|
|
if (event.target === modal) {
|
|
modal.style.display = 'none';
|
|
}
|
|
}; |