From 6558e289f30f328273416fd22ff7ce07db5154ed Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Wed, 1 Apr 2026 20:09:12 +0000 Subject: [PATCH] fix(pos): reemplazar datos demo con datos reales del empleado logueado MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Nuevo app-init.js: auth check, inyecta nombre/rol real del empleado en sidebar, header, y status bar de TODAS las páginas - Eliminados 6 productos demo hardcodeados del catálogo - Sidebar muestra nombre real del usuario logueado - Links de navegación marcan la página activa correctamente - Función posLogout() global para cerrar sesión Co-Authored-By: Claude Opus 4.6 (1M context) --- pos/static/js/app-init.js | 143 ++++++++++++++++++++++++ pos/templates/accounting.html | 1 + pos/templates/catalog.html | 202 +--------------------------------- pos/templates/config.html | 1 + pos/templates/customers.html | 1 + pos/templates/dashboard.html | 1 + pos/templates/inventory.html | 1 + pos/templates/invoicing.html | 1 + pos/templates/pos.html | 1 + pos/templates/reports.html | 1 + 10 files changed, 154 insertions(+), 199 deletions(-) create mode 100644 pos/static/js/app-init.js diff --git a/pos/static/js/app-init.js b/pos/static/js/app-init.js new file mode 100644 index 0000000..39a7f70 --- /dev/null +++ b/pos/static/js/app-init.js @@ -0,0 +1,143 @@ +/** + * app-init.js — Shared initialization for all POS pages + * + * Handles: + * 1. Auth check (redirect to login if no valid token) + * 2. Set real employee name/role in sidebar and header + * 3. Set navigation links as active based on current page + * 4. Sidebar toggle for mobile + */ +(function() { + 'use strict'; + + // ─── Auth Check ─── + var token = localStorage.getItem('pos_token'); + if (!token) { + window.location.href = '/pos/login'; + return; + } + + // Validate token not expired + try { + var payload = JSON.parse(atob(token.split('.')[1])); + if (payload.exp * 1000 < Date.now()) { + localStorage.removeItem('pos_token'); + localStorage.removeItem('pos_employee'); + window.location.href = '/pos/login'; + return; + } + } catch(e) { + localStorage.removeItem('pos_token'); + window.location.href = '/pos/login'; + return; + } + + // ─── Get employee info ─── + var employee = {}; + try { + employee = JSON.parse(localStorage.getItem('pos_employee') || '{}'); + } catch(e) {} + + var name = employee.name || payload.name || 'Usuario'; + var role = employee.role || payload.role || ''; + var roleLabels = { + 'owner': 'Dueño', 'admin': 'Administrador', 'cashier': 'Cajero', + 'warehouse': 'Almacén', 'accountant': 'Contador' + }; + var roleLabel = roleLabels[role] || role; + var initials = name.split(' ').map(function(p) { return p[0]; }).join('').toUpperCase().substring(0, 2); + + // ─── Replace hardcoded names in sidebar ─── + // Sidebar user name + document.querySelectorAll('.sidebar__user-name').forEach(function(el) { + el.textContent = name; + }); + // Sidebar user role + document.querySelectorAll('.sidebar__user-role').forEach(function(el) { + el.textContent = roleLabel; + }); + // Sidebar user initials/avatar + document.querySelectorAll('.sidebar__user-avatar, .sidebar__avatar').forEach(function(el) { + el.textContent = initials; + }); + + // Profile info in headers (catalog uses this pattern) + document.querySelectorAll('.profile-info__name').forEach(function(el) { + el.textContent = name; + }); + document.querySelectorAll('.profile-info__role').forEach(function(el) { + el.textContent = roleLabel; + }); + + // Theme bar user labels + document.querySelectorAll('.theme-bar__label').forEach(function(el) { + if (el.textContent.indexOf('Usuario:') !== -1 || el.textContent.indexOf('Sucursal') !== -1) { + el.textContent = 'Sucursal Principal — ' + name; + } + }); + + // Status bar user names + document.querySelectorAll('.status-bar .user-name, .status-info span').forEach(function(el) { + var text = el.textContent; + // Replace common demo names + ['Hugo M.', 'Hugo García', 'J. Ramírez', 'José Ramírez', 'Carlos M.', 'Admin'].forEach(function(demo) { + if (text.indexOf(demo) !== -1) { + el.textContent = text.replace(demo, name); + } + }); + }); + + // ─── Set active nav link ─── + var path = window.location.pathname; + var navMap = { + '/pos/dashboard': 'dashboard', + '/pos/sale': 'pos', + '/pos/catalog': 'catalogo', + '/pos/inventory': 'inventario', + '/pos/customers': 'clientes', + '/pos/invoicing': 'facturacion', + '/pos/accounting': 'contabilidad', + '/pos/reports': 'reportes', + '/pos/config': 'configuracion' + }; + + document.querySelectorAll('.nav-item, .nav-link').forEach(function(link) { + link.classList.remove('is-active', 'active'); + var href = link.getAttribute('href') || ''; + if (href === path) { + link.classList.add('is-active'); + link.classList.add('active'); + } + }); + + // ─── Logout ─── + window.posLogout = function() { + localStorage.removeItem('pos_token'); + localStorage.removeItem('pos_employee'); + localStorage.removeItem('pos_tenant_id'); + localStorage.removeItem('pos_cart'); + window.location.href = '/pos/login'; + }; + + // Wire any logout buttons + document.querySelectorAll('[data-action="logout"], .btn-logout, .logout-btn').forEach(function(btn) { + btn.addEventListener('click', function(e) { + e.preventDefault(); + posLogout(); + }); + }); + + // ─── Expose globally ─── + window.POS_USER = { + name: name, + role: role, + roleLabel: roleLabel, + initials: initials, + token: token, + tenantId: payload.tenant_id, + employeeId: payload.employee_id, + branchId: payload.branch_id, + permissions: payload.permissions || [] + }; + +})(); diff --git a/pos/templates/accounting.html b/pos/templates/accounting.html index b15fbec..65e4577 100644 --- a/pos/templates/accounting.html +++ b/pos/templates/accounting.html @@ -2249,6 +2249,7 @@ + diff --git a/pos/templates/catalog.html b/pos/templates/catalog.html index 7830064..031142b 100644 --- a/pos/templates/catalog.html +++ b/pos/templates/catalog.html @@ -1890,206 +1890,9 @@ - +
- - -
-
- - -
En stock
-
-
-
Frenos
-
Pastillas de Freno Delanteras Cerámicas
-
OEM: 04465-02260
-
- Akebono - - Japón -
-
- - Compatible con: Toyota Corolla 2018–2022 -
-
- -
- - -
-
- - -
En stock
-
-
-
Suspensión
-
Amortiguador Delantero Gas KYB Excel-G
-
OEM: 339175
-
- KYB - - Japón -
-
- - Compatible con: Toyota Corolla 2014–2019 -
-
- -
- - -
-
- - -
Últimas 3
-
-
-
Eléctrico
-
Sensor de Oxígeno Aguas Arriba Denso
-
OEM: 234-4209
-
- Denso - - Japón -
-
- - Compatible con: Toyota Corolla 2009–2019 -
-
- -
- - -
-
- - -
En stock
-
-
-
Motor
-
Filtro de Aceite Motor Toyota Original
-
OEM: 90915-YZZE1
-
- Toyota Genuine - - OEM -
-
- - Compatible con: Toyota Corolla 2014–2024 -
-
- -
- - -
-
- - -
En stock
-
-
-
Motor
-
Kit Banda de Distribución con Bomba de Agua Gates
-
OEM: TCK328B
-
- Gates - - EUA -
-
- - Compatible con: Toyota Corolla 2009–2020 -
-
- -
- - -
-
- - -
Agotado
-
-
-
Frenos
-
Disco de Freno Ventilado Delantero Brembo
-
OEM: 09.9807.11
-
- Brembo - - Italia -
-
- - Compatible con: Toyota Corolla 2014–2022 -
-
- -
+
@@ -2334,6 +2137,7 @@ + diff --git a/pos/templates/config.html b/pos/templates/config.html index 1488a97..ad89792 100644 --- a/pos/templates/config.html +++ b/pos/templates/config.html @@ -1820,6 +1820,7 @@ + diff --git a/pos/templates/customers.html b/pos/templates/customers.html index 701b0c0..b2e171d 100644 --- a/pos/templates/customers.html +++ b/pos/templates/customers.html @@ -2144,6 +2144,7 @@ + diff --git a/pos/templates/dashboard.html b/pos/templates/dashboard.html index 37ee092..349f5de 100644 --- a/pos/templates/dashboard.html +++ b/pos/templates/dashboard.html @@ -1948,6 +1948,7 @@ + diff --git a/pos/templates/inventory.html b/pos/templates/inventory.html index 413e50b..e2aee41 100644 --- a/pos/templates/inventory.html +++ b/pos/templates/inventory.html @@ -2522,6 +2522,7 @@ + diff --git a/pos/templates/invoicing.html b/pos/templates/invoicing.html index 907be12..b2dc43a 100644 --- a/pos/templates/invoicing.html +++ b/pos/templates/invoicing.html @@ -2698,6 +2698,7 @@ + diff --git a/pos/templates/pos.html b/pos/templates/pos.html index f2ef0f8..40d4ee5 100644 --- a/pos/templates/pos.html +++ b/pos/templates/pos.html @@ -1472,6 +1472,7 @@ +