From 52eedeadd450cebc370b72762e60f25cb98356db Mon Sep 17 00:00:00 2001 From: "maria.ruiz" <zs22016128@estudiantes.uv.mx> Date: Thu, 13 Mar 2025 06:23:24 +0000 Subject: [PATCH] Actualizar Interfaz/scripts/reporte_ventas.js --- Interfaz/scripts/reporte_ventas.js | 97 ++++++++++++++---------------- 1 file changed, 46 insertions(+), 51 deletions(-) diff --git a/Interfaz/scripts/reporte_ventas.js b/Interfaz/scripts/reporte_ventas.js index 0638fd3..704709d 100644 --- a/Interfaz/scripts/reporte_ventas.js +++ b/Interfaz/scripts/reporte_ventas.js @@ -1,51 +1,46 @@ -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 \ No newline at end of file +document.getElementById('formReporte').addEventListener('submit', function (event) { + event.preventDefault(); + + const fechaInicio = document.getElementById('fechaInicio').value; + const fechaFin = document.getElementById('fechaFin').value; + + cargarReporte(fechaInicio, fechaFin); +}); + +function cargarReporte(fechaInicio, fechaFin) { + const url = `control/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; + } + + document.getElementById('totalBoletos').textContent = data.totalBoletos; + + const tbody = document.querySelector('#tablaVentas tbody'); + tbody.innerHTML = ''; + + 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)); +} + +setInterval(() => { + const fechaInicio = document.getElementById('fechaInicio').value; + const fechaFin = document.getElementById('fechaFin').value; + + if (fechaInicio && fechaFin) { + cargarReporte(fechaInicio, fechaFin); + } +}, 10000);