Updated ReadMe

This commit is contained in:
Marco Gallegos
2025-08-13 07:09:14 -06:00
parent bb0ca83820
commit e36bf76425
2 changed files with 25 additions and 25 deletions

View File

@@ -39,7 +39,7 @@ const tblUsersBody = document.getElementById('tblUsers')?.querySelector('tbody')
async function loadDashboardData() { async function loadDashboardData() {
// Solo admins pueden cargar esto // Solo admins pueden cargar esto
if (currentUser.role !== 'admin') return; if (currentUser.role !== 'admin' || !incomeChart) return;
try { try {
const response = await fetch('/api/dashboard'); const response = await fetch('/api/dashboard');
if (!response.ok) { if (!response.ok) {
@@ -55,30 +55,11 @@ async function loadDashboardData() {
document.getElementById('stat-total-income').textContent = `${Number(data.totalIncome || 0).toFixed(2)}`; document.getElementById('stat-total-income').textContent = `${Number(data.totalIncome || 0).toFixed(2)}`;
document.getElementById('stat-total-movements').textContent = data.totalMovements || 0; document.getElementById('stat-total-movements').textContent = data.totalMovements || 0;
// Update chart // Update chart data instead of recreating it
const ctx = document.getElementById('incomeChart').getContext('2d'); incomeChart.data.labels = data.incomeByService.map(item => item.tipo);
const chartData = { incomeChart.data.datasets[0].data = data.incomeByService.map(item => item.total);
labels: data.incomeByService.map(item => item.tipo), incomeChart.update();
datasets: [{
label: 'Ingresos por Servicio',
data: data.incomeByService.map(item => item.total),
backgroundColor: ['#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0', '#9966FF', '#FF9F40'],
}]
};
if (incomeChart) {
incomeChart.destroy();
}
incomeChart = new Chart(ctx, {
type: 'pie',
data: chartData,
options: {
responsive: true,
maintainAspectRatio: false,
animation: false // Desactivar la animación para evitar la sensación de "bucle"
}
});
} catch (error) { } catch (error) {
console.error('Error loading dashboard:', error); console.error('Error loading dashboard:', error);
} }
@@ -557,6 +538,25 @@ async function initializeApp() {
if (currentUser.role === 'admin') { if (currentUser.role === 'admin') {
formAddUser?.addEventListener('submit', handleAddUser); formAddUser?.addEventListener('submit', handleAddUser);
tblUsersBody?.addEventListener('click', handleTableClick); tblUsersBody?.addEventListener('click', handleTableClick);
// Inicializar el gráfico vacío para el admin
const ctx = document.getElementById('incomeChart').getContext('2d');
incomeChart = new Chart(ctx, {
type: 'pie',
data: {
labels: [],
datasets: [{
label: 'Ingresos por Servicio',
data: [],
backgroundColor: ['#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0', '#9966FF', '#FF9F40'],
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
animation: false
}
});
} }
btnLogout?.addEventListener('click', async () => { btnLogout?.addEventListener('click', async () => {

View File

@@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>AP-POS — Iniciar Sesión</title> <title>Ale Ponce | AlMa</title>
<link rel="stylesheet" href="styles.css" /> <link rel="stylesheet" href="styles.css" />
<style> <style>
body { body {