Actualizar Interfaz/scripts/reporte_ventas.js

This commit is contained in:
maria.ruiz 2025-03-13 06:23:24 +00:00
parent 37620d21c6
commit 52eedeadd4
1 changed files with 46 additions and 51 deletions
Interfaz/scripts

View File

@ -1,51 +1,46 @@
document.getElementById('formReporte').addEventListener('submit', function (event) { document.getElementById('formReporte').addEventListener('submit', function (event) {
event.preventDefault(); // Evitar que el formulario se envíe event.preventDefault();
const fechaInicio = document.getElementById('fechaInicio').value; const fechaInicio = document.getElementById('fechaInicio').value;
const fechaFin = document.getElementById('fechaFin').value; const fechaFin = document.getElementById('fechaFin').value;
// Cargar el reporte de ventas cargarReporte(fechaInicio, fechaFin);
cargarReporte(fechaInicio, fechaFin); });
});
function cargarReporte(fechaInicio, fechaFin) {
function cargarReporte(fechaInicio, fechaFin) { const url = `control/reporte_ventas.php?fechaInicio=${encodeURIComponent(fechaInicio)}&fechaFin=${encodeURIComponent(fechaFin)}`;
const url = `reporte_ventas.php?fechaInicio=${encodeURIComponent(fechaInicio)}&fechaFin=${encodeURIComponent(fechaFin)}`;
fetch(url)
fetch(url) .then(response => response.json())
.then(response => response.json()) .then(data => {
.then(data => { if (data.error) {
if (data.error) { console.error("Error al cargar el reporte:", data.error);
console.error("Error al cargar el reporte:", data.error); return;
return; }
}
document.getElementById('totalBoletos').textContent = data.totalBoletos;
// Actualizar el total de boletos vendidos
document.getElementById('totalBoletos').textContent = data.totalBoletos; const tbody = document.querySelector('#tablaVentas tbody');
tbody.innerHTML = '';
// Limpiar la tabla
const tbody = document.querySelector('#tablaVentas tbody'); data.ventas.forEach(venta => {
tbody.innerHTML = ''; const fila = document.createElement('tr');
fila.innerHTML = `
// Llenar la tabla con los datos de las ventas <td>${venta.fecha_venta}</td>
data.ventas.forEach(venta => { <td>${venta.asiento}</td>
const fila = document.createElement('tr'); <td>$${venta.precio}</td>
fila.innerHTML = ` `;
<td>${venta.fecha_venta}</td> tbody.appendChild(fila);
<td>${venta.asiento}</td> });
<td>$${venta.precio}</td> })
`; .catch(error => console.error('Error al cargar el reporte:', error));
tbody.appendChild(fila); }
});
}) setInterval(() => {
.catch(error => console.error('Error al cargar el reporte:', error)); const fechaInicio = document.getElementById('fechaInicio').value;
} const fechaFin = document.getElementById('fechaFin').value;
// Actualizar el reporte cada 10 segundos if (fechaInicio && fechaFin) {
setInterval(() => { cargarReporte(fechaInicio, fechaFin);
const fechaInicio = document.getElementById('fechaInicio').value; }
const fechaFin = document.getElementById('fechaFin').value; }, 10000);
if (fechaInicio && fechaFin) {
cargarReporte(fechaInicio, fechaFin);
}
}, 10000); // 10 segundos