diff --git a/ap-pos/README.md b/ap-pos/README.md new file mode 100644 index 0000000..0b396dc --- /dev/null +++ b/ap-pos/README.md @@ -0,0 +1,7 @@ +# AP-POS WebApp + +Este es un sistema de punto de venta simple basado en la web. + +## Futuras Implementaciones + +Se tiene la intención de que esta aplicación se pueda ejecutar en un contenedor de Docker. Además, se buscará que la aplicación tenga la capacidad de interactuar con una impresora de tickets conectada vía USB en un entorno de macOS. diff --git a/ap-pos/app.js b/ap-pos/app.js index 9223602..ebb4783 100644 --- a/ap-pos/app.js +++ b/ap-pos/app.js @@ -29,6 +29,7 @@ const btnTestTicket = document.getElementById('btnTestTicket'); const formClient = document.getElementById('formClient'); const tblClientsBody = document.getElementById('tblClients')?.querySelector('tbody'); const clientDatalist = document.getElementById('client-list'); +const formCredentials = document.getElementById('formCredentials'); // --- LÓGICA DE NEGOCIO --- @@ -61,18 +62,17 @@ async function loadDashboardData() { }; if (incomeChart) { - incomeChart.data = chartData; - incomeChart.update(); - } else { - incomeChart = new Chart(ctx, { - type: 'pie', - data: chartData, - options: { - responsive: true, - maintainAspectRatio: false, - } - }); + incomeChart.destroy(); } + + incomeChart = new Chart(ctx, { + type: 'pie', + data: chartData, + options: { + responsive: true, + maintainAspectRatio: false, + } + }); } catch (error) { console.error('Error loading dashboard:', error); } @@ -254,6 +254,35 @@ async function handleSaveSettings(e) { alert('Configuración guardada.'); } +async function handleSaveCredentials(e) { + e.preventDefault(); + const username = document.getElementById('s-username').value; + const password = document.getElementById('s-password').value; + + const body = { username }; + if (password) { + body.password = password; + } + + try { + const response = await fetch('/api/user', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(body) + }); + + if (response.ok) { + alert('Credenciales actualizadas.'); + document.getElementById('s-password').value = ''; + } else { + const error = await response.json(); + alert(`Error: ${error.error}`); + } + } catch (error) { + alert('Error de conexión al guardar credenciales.'); + } +} + async function handleNewMovement(e) { e.preventDefault(); const form = e.target; @@ -393,6 +422,7 @@ async function initializeApp() { const btnLogout = document.getElementById('btnLogout'); formSettings?.addEventListener('submit', handleSaveSettings); + formCredentials?.addEventListener('submit', handleSaveCredentials); formMove?.addEventListener('submit', handleNewMovement); tblMovesBody?.addEventListener('click', handleTableClick); tblClientsBody?.addEventListener('click', handleTableClick); @@ -414,13 +444,17 @@ async function initializeApp() { Promise.all([ load(KEY_SETTINGS, DEFAULT_SETTINGS), load(KEY_DATA, []), - load(KEY_CLIENTS, []) + load(KEY_CLIENTS, []), + fetch('/api/user').then(res => res.json()) ]).then(values => { - [settings, movements, clients] = values; + [settings, movements, clients, user] = values; renderSettings(); renderTable(); renderClientsTable(); updateClientDatalist(); + if (user) { + document.getElementById('s-username').value = user.username; + } // Cargar datos del dashboard al inicio loadDashboardData(); }).catch(error => { diff --git a/ap-pos/index.html b/ap-pos/index.html index dc6bc9c..453d32c 100644 --- a/ap-pos/index.html +++ b/ap-pos/index.html @@ -178,6 +178,20 @@ Toda la información de tu negocio (clientes, recibos y configuración) se guarda de forma segura en el archivo ap-pos.db, ubicado en la misma carpeta que la aplicación. Para hacer un respaldo, simplemente copia este archivo.
+