Subir archivos a "Interfaz/scripts"
This commit is contained in:
parent
59e7b50564
commit
fe771121ec
Interfaz/scripts
|
@ -1,49 +1,163 @@
|
|||
const filas = 10;
|
||||
const columnas = 12;
|
||||
let diaSeleccionado = 23;
|
||||
const asientosVendidos = { 22: new Set(), 23: new Set(), 24: new Set() };
|
||||
let asientosSeleccionados = new Set();
|
||||
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 seleccionarDia(dia) {
|
||||
diaSeleccionado = dia;
|
||||
asientosSeleccionados.clear();
|
||||
document.querySelectorAll('.dias button').forEach(btn => btn.classList.remove('selected'));
|
||||
event.target.classList.add('selected');
|
||||
renderizarAsientos();
|
||||
}
|
||||
// Función para cargar los asientos desde el servidor
|
||||
function cargarAsientos() {
|
||||
const artista = "The Driver Era"; // Cambia esto según el artista
|
||||
const url = `consultar_asientos.php?artista=${encodeURIComponent(artista)}&dia=${diaSeleccionado}`;
|
||||
|
||||
function toggleAsiento(asiento) {
|
||||
if (asientosVendidos[diaSeleccionado].has(asiento)) return;
|
||||
if (asientosSeleccionados.has(asiento)) {
|
||||
asientosSeleccionados.delete(asiento);
|
||||
} else {
|
||||
asientosSeleccionados.add(asiento);
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.error) {
|
||||
console.error("Error al cargar los asientos:", data.error);
|
||||
return;
|
||||
}
|
||||
renderizarAsientos();
|
||||
}
|
||||
|
||||
function venderAsientos() {
|
||||
asientosSeleccionados.forEach(asiento => asientosVendidos[diaSeleccionado].add(asiento));
|
||||
asientosSeleccionados.clear();
|
||||
renderizarAsientos();
|
||||
}
|
||||
// Limpiar los asientos vendidos para el día seleccionado
|
||||
asientosVendidos[diaSeleccionado].clear();
|
||||
|
||||
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';
|
||||
// Actualizar los asientos vendidos
|
||||
data.asientos.forEach(asiento => {
|
||||
if (asiento.estado === 'vendido') {
|
||||
asientosVendidos[diaSeleccionado].add(asiento.asiento);
|
||||
}
|
||||
boton.textContent = asiento;
|
||||
boton.onclick = () => toggleAsiento(asiento);
|
||||
contenedor.appendChild(boton);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
renderizarAsientos();
|
||||
// Renderizar los asientos
|
||||
renderizarAsientos();
|
||||
})
|
||||
.catch(error => console.error('Error al cargar los asientos:', error));
|
||||
}
|
||||
|
||||
// Función para seleccionar un día
|
||||
function seleccionarDia(dia) {
|
||||
diaSeleccionado = dia;
|
||||
asientosSeleccionados.clear();
|
||||
document.querySelectorAll('.dias button').forEach(btn => btn.classList.remove('selected'));
|
||||
event.target.classList.add('selected');
|
||||
cargarAsientos();
|
||||
}
|
||||
|
||||
// Función para seleccionar/deseleccionar un asiento
|
||||
function toggleAsiento(asiento) {
|
||||
if (asientosVendidos[diaSeleccionado].has(asiento)) return;
|
||||
if (asientosSeleccionados.has(asiento)) {
|
||||
asientosSeleccionados.delete(asiento);
|
||||
} else {
|
||||
asientosSeleccionados.add(asiento);
|
||||
}
|
||||
renderizarAsientos();
|
||||
}
|
||||
|
||||
// Función para mostrar el comprobante
|
||||
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';
|
||||
}
|
||||
|
||||
// Función para confirmar la venta
|
||||
function confirmarVenta() {
|
||||
const artista = "The Driver Era"; // Cambia esto según el artista
|
||||
const url = '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';
|
||||
}
|
||||
|
||||
// Función para rechazar la venta
|
||||
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';
|
||||
}
|
||||
};
|
|
@ -0,0 +1,51 @@
|
|||
document.getElementById('formReporte').addEventListener('submit', function (event) {
|
||||
event.preventDefault(); // Evitar que el formulario se envíe
|
||||
|
||||
const fechaInicio = document.getElementById('fechaInicio').value;
|
||||
const fechaFin = document.getElementById('fechaFin').value;
|
||||
|
||||
// Cargar el reporte de ventas
|
||||
cargarReporte(fechaInicio, fechaFin);
|
||||
});
|
||||
|
||||
function cargarReporte(fechaInicio, fechaFin) {
|
||||
const url = `reporte_ventas.php?fechaInicio=${encodeURIComponent(fechaInicio)}&fechaFin=${encodeURIComponent(fechaFin)}`;
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.error) {
|
||||
console.error("Error al cargar el reporte:", data.error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Actualizar el total de boletos vendidos
|
||||
document.getElementById('totalBoletos').textContent = data.totalBoletos;
|
||||
|
||||
// Limpiar la tabla
|
||||
const tbody = document.querySelector('#tablaVentas tbody');
|
||||
tbody.innerHTML = '';
|
||||
|
||||
// Llenar la tabla con los datos de las ventas
|
||||
data.ventas.forEach(venta => {
|
||||
const fila = document.createElement('tr');
|
||||
fila.innerHTML = `
|
||||
<td>${venta.fecha_venta}</td>
|
||||
<td>${venta.asiento}</td>
|
||||
<td>$${venta.precio}</td>
|
||||
`;
|
||||
tbody.appendChild(fila);
|
||||
});
|
||||
})
|
||||
.catch(error => console.error('Error al cargar el reporte:', error));
|
||||
}
|
||||
|
||||
// Actualizar el reporte cada 10 segundos
|
||||
setInterval(() => {
|
||||
const fechaInicio = document.getElementById('fechaInicio').value;
|
||||
const fechaFin = document.getElementById('fechaFin').value;
|
||||
|
||||
if (fechaInicio && fechaFin) {
|
||||
cargarReporte(fechaInicio, fechaFin);
|
||||
}
|
||||
}, 10000); // 10 segundos
|
Loading…
Reference in New Issue