feat(admin): implementar dashboard ejecutivo de informacion con KPIs, momentos escolares y finanzas

This commit is contained in:
unknown
2026-10-08 14:32:31 -06:00
parent dff03f98d0
commit e9a38b15d7
6 changed files with 841 additions and 11 deletions
+252
View File
@@ -6024,5 +6024,257 @@ body.dark-mode .limit-preset-pill:hover {
color: #991b1b !important; color: #991b1b !important;
} }
/* ========================================================
DASHBOARD EJECUTIVO DE ADMINISTRACIÓN
======================================================== */
.admin-dash-container {
display: flex;
flex-direction: column;
gap: 18px;
}
.admin-dash-header {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 12px;
padding-bottom: 12px;
border-bottom: 1px solid var(--border, #e2e8f0);
}
.admin-dash-period-pills {
display: inline-flex;
background: var(--bg-main, #f1f5f9);
padding: 3px;
border-radius: 10px;
gap: 4px;
border: 1px solid var(--border, #e2e8f0);
}
body.dark-mode .admin-dash-period-pills {
background: #1e293b;
border-color: #334155;
}
.admin-dash-pill-btn {
border: none;
background: transparent;
color: var(--text-muted, #64748b);
font-size: 0.78rem;
font-weight: 700;
padding: 6px 14px;
border-radius: 7px;
cursor: pointer;
transition: all 0.15s ease;
}
.admin-dash-pill-btn:hover {
color: var(--text-main, #0f172a);
}
.admin-dash-pill-btn.active {
background: var(--card-bg, #ffffff);
color: #0284c7;
font-weight: 800;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
body.dark-mode .admin-dash-pill-btn.active {
background: #0f172a;
color: #38bdf8;
}
.admin-dash-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 14px;
}
.admin-dash-kpi-card {
background: var(--card-bg, #ffffff);
border: 1px solid var(--border, #e2e8f0);
border-radius: 14px;
padding: 16px;
display: flex;
flex-direction: column;
gap: 8px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
position: relative;
overflow: hidden;
}
.admin-dash-kpi-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 4px;
height: 100%;
}
.admin-dash-kpi-card.kpi-blue::before { background: #0284c7; }
.admin-dash-kpi-card.kpi-green::before { background: #10b981; }
.admin-dash-kpi-card.kpi-purple::before { background: #8b5cf6; }
.admin-dash-kpi-card.kpi-amber::before { background: #f59e0b; }
.admin-dash-kpi-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.admin-dash-kpi-title {
font-size: 0.74rem;
font-weight: 800;
text-transform: uppercase;
letter-spacing: 0.04em;
color: var(--text-muted, #64748b);
}
.admin-dash-kpi-icon {
width: 32px;
height: 32px;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.05rem;
}
.kpi-blue .admin-dash-kpi-icon { background: rgba(2, 132, 199, 0.12); color: #0284c7; }
.kpi-green .admin-dash-kpi-icon { background: rgba(16, 185, 129, 0.12); color: #10b981; }
.kpi-purple .admin-dash-kpi-icon { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }
.kpi-amber .admin-dash-kpi-icon { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.admin-dash-kpi-val {
font-size: 1.6rem;
font-weight: 900;
color: var(--text-main, #0f172a);
line-height: 1.1;
}
.admin-dash-kpi-meta {
font-size: 0.75rem;
color: var(--text-muted, #64748b);
display: flex;
flex-direction: column;
gap: 3px;
margin-top: 4px;
}
.admin-dash-split {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
@media (max-width: 860px) {
.admin-dash-split {
grid-template-columns: 1fr;
}
}
.admin-dash-section {
background: var(--card-bg, #ffffff);
border: 1px solid var(--border, #e2e8f0);
border-radius: 14px;
padding: 16px;
display: flex;
flex-direction: column;
gap: 12px;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}
.admin-dash-section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0;
font-size: 0.94rem;
font-weight: 800;
color: var(--text-main, #0f172a);
}
.admin-dash-bar-row {
display: flex;
flex-direction: column;
gap: 5px;
}
.admin-dash-bar-meta {
display: flex;
justify-content: space-between;
font-size: 0.78rem;
font-weight: 700;
color: var(--text-main, #0f172a);
}
.admin-dash-bar-track {
height: 9px;
background: var(--bg-main, #f1f5f9);
border-radius: 5px;
overflow: hidden;
position: relative;
}
body.dark-mode .admin-dash-bar-track {
background: #334155;
}
.admin-dash-bar-fill {
height: 100%;
border-radius: 5px;
transition: width 0.4s ease-out;
}
/* Gráfico semanal 7 días */
.admin-dash-chart {
display: flex;
align-items: flex-end;
justify-content: space-between;
height: 160px;
padding-top: 25px;
gap: 8px;
border-bottom: 2px solid var(--border, #e2e8f0);
}
.admin-dash-col {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
justify-content: flex-end;
position: relative;
}
.admin-dash-col-val {
font-size: 0.68rem;
font-weight: 800;
color: var(--text-muted, #64748b);
margin-bottom: 4px;
text-align: center;
white-space: nowrap;
}
.admin-dash-col-bar {
width: 70%;
max-width: 44px;
min-height: 4px;
border-radius: 6px 6px 0 0;
background: linear-gradient(180deg, #38bdf8, #0284c7);
transition: height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.admin-dash-col-bar:hover {
background: linear-gradient(180deg, #60a5fa, #2563eb);
}
.admin-dash-col-lbl {
font-size: 0.72rem;
font-weight: 700;
color: var(--text-muted, #64748b);
margin-top: 8px;
text-align: center;
}
+156 -5
View File
@@ -12,7 +12,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="SiboPay"> <meta name="apple-mobile-web-app-title" content="SiboPay">
<meta name="mobile-web-app-capable" content="yes"> <meta name="mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="/css/styles.css?v=13.7"> <link rel="stylesheet" href="/css/styles.css?v=13.9">
<link rel="stylesheet" href="/css/desktop.css?v=2.2"> <link rel="stylesheet" href="/css/desktop.css?v=2.2">
<style> <style>
/* Transiciones suaves */ /* Transiciones suaves */
@@ -612,12 +612,16 @@
</div> </div>
</div> </div>
<!-- FILA DE ACCIONES RÁPIDAS: RECARGAR SALDO, TERMINAL POS, PANEL DEV --> <!-- FILA DE ACCIONES RÁPIDAS: DASHBOARD, RECARGAR SALDO, TERMINAL POS, PANEL DEV -->
<div class="admin-header-actions" style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%;"> <div class="admin-header-actions" style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: 100%;">
<button id="btnAdminDevPanel" onclick="switchAdminToDev()" class="btn-saas btn-saas-outline" style="display: none; border-color: #0284c7; color: #0284c7; height: 34px;" title="Volver al Panel Developer Master"> <button id="btnAdminDevPanel" onclick="switchAdminToDev()" class="btn-saas btn-saas-outline" style="display: none; border-color: #0284c7; color: #0284c7; height: 34px;" title="Volver al Panel Developer Master">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/></svg> <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/></svg>
<span class="admin-btn-text">Panel Dev</span> <span class="admin-btn-text">Panel Dev</span>
</button> </button>
<button onclick="switchAdminTab('dashboard')" class="btn-saas btn-saas-outline" style="height: 34px; border-color: #0284c7; color: #0284c7; font-weight: 800; background: rgba(2, 132, 199, 0.05);" title="Ver Dashboard Ejecutivo de Métricas y Finanzas">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="9" x="3" y="3" rx="1"/><rect width="7" height="5" x="14" y="3" rx="1"/><rect width="7" height="9" x="14" y="12" rx="1"/><rect width="7" height="5" x="3" y="16" rx="1"/></svg>
<span class="admin-btn-text">📊 Dashboard</span>
</button>
<button onclick="switchAdminTab('recarga')" class="btn-saas btn-saas-primary" style="height: 34px;" title="Recargar saldo a un estudiante"> <button onclick="switchAdminTab('recarga')" class="btn-saas btn-saas-primary" style="height: 34px;" title="Recargar saldo a un estudiante">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="5" rx="2"/><line x1="2" x2="22" y1="10" y2="10"/></svg> <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="5" rx="2"/><line x1="2" x2="22" y1="10" y2="10"/></svg>
<span class="admin-btn-text">Recargar Saldo</span> <span class="admin-btn-text">Recargar Saldo</span>
@@ -663,7 +667,11 @@
<!-- PESTAÑAS DE NAVEGACIÓN ADMIN --> <!-- PESTAÑAS DE NAVEGACIÓN ADMIN -->
<div class="admin-tabs"> <div class="admin-tabs">
<button class="admin-tab-btn active" id="btnTabAdminInventario" onclick="switchAdminTab('inventario')"> <button class="admin-tab-btn active" id="btnTabAdminDashboard" onclick="switchAdminTab('dashboard')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="7" height="9" x="3" y="3" rx="1"/><rect width="7" height="5" x="14" y="3" rx="1"/><rect width="7" height="9" x="14" y="12" rx="1"/><rect width="7" height="5" x="3" y="16" rx="1"/></svg>
<span>Dashboard Ejecutivo</span>
</button>
<button class="admin-tab-btn" id="btnTabAdminInventario" onclick="switchAdminTab('inventario')">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7.5 4.27 9 5.15"/><path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/></svg> <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m7.5 4.27 9 5.15"/><path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/></svg>
<span>Inventario & Stock</span> <span>Inventario & Stock</span>
</button> </button>
@@ -690,8 +698,151 @@
</button> </button>
</div> </div>
<!-- TAB 0: DASHBOARD EJECUTIVO -->
<div id="adminTabContentDashboard" class="admin-card">
<div class="admin-dash-container">
<!-- CABECERA DASHBOARD: TÍTULO Y SELECTORES DE PERÍODO -->
<div class="admin-dash-header">
<div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1.3rem;">📊</span>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 800; color: var(--text-main);">Dashboard Ejecutivo & Finanzas</h3>
</div>
<p style="margin: 3px 0 0 0; font-size: 0.78rem; color: var(--text-muted);">
Métricas financieras, saldos circulantes en monederos y análisis operativo en tiempo real.
</p>
</div>
<div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;">
<div class="admin-dash-period-pills" id="adminDashPeriodPills">
<button type="button" class="admin-dash-pill-btn active" data-periodo="hoy" onclick="cambiarPeriodoDashboard('hoy')">Hoy</button>
<button type="button" class="admin-dash-pill-btn" data-periodo="7dias" onclick="cambiarPeriodoDashboard('7dias')">7 Días</button>
<button type="button" class="admin-dash-pill-btn" data-periodo="mes" onclick="cambiarPeriodoDashboard('mes')">Este Mes</button>
<button type="button" class="admin-dash-pill-btn" data-periodo="todo" onclick="cambiarPeriodoDashboard('todo')">Histórico</button>
</div>
<button type="button" onclick="cargarDashboardAdmin()" class="btn-saas btn-saas-outline" style="height: 32px; padding: 0 10px; font-size: 0.78rem;" title="Recargar datos del Dashboard">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 21h5v-5"/></svg>
<span>Actualizar</span>
</button>
</div>
</div>
<!-- BANNER DE ALERTAS OPERATIVAS (Oculto si no hay alertas) -->
<div id="adminDashAlertsContainer" style="display: none; flex-direction: column; gap: 8px;">
<!-- Dinámico -->
</div>
<!-- 4 TARJETAS KPI EJECUTIVAS -->
<div class="admin-dash-grid">
<!-- KPI 1: VENTAS TOTALES -->
<div class="admin-dash-kpi-card kpi-blue">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Ventas Totales</span>
<div class="admin-dash-kpi-icon">💰</div>
</div>
<div class="admin-dash-kpi-val" id="dashKpiVentas">₡0</div>
<div class="admin-dash-kpi-meta">
<span>Órdenes cobradas: <strong id="dashKpiOrdenes" style="color: var(--text-main);">0</strong></span>
<span>Ticket promedio: <strong id="dashKpiTicketPromedio" style="color: #0284c7;">₡0</strong></span>
</div>
</div>
<!-- KPI 2: SALDO CIRCULANTE EN MONEDEROS -->
<div class="admin-dash-kpi-card kpi-green">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Monederos Estudiantes</span>
<div class="admin-dash-kpi-icon">💳</div>
</div>
<div class="admin-dash-kpi-val" id="dashKpiSaldoCirculante">₡0</div>
<div class="admin-dash-kpi-meta">
<span>Disponible: <strong id="dashKpiSaldoDisponible" style="color: #10b981;">₡0</strong></span>
<span>Retenido preórdenes: <strong id="dashKpiSaldoRetenido" style="color: #f59e0b;">₡0</strong></span>
</div>
</div>
<!-- KPI 3: RECARGAS DEL PERÍODO -->
<div class="admin-dash-kpi-card kpi-purple">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Recargas Ingresadas</span>
<div class="admin-dash-kpi-icon">📥</div>
</div>
<div class="admin-dash-kpi-val" id="dashKpiRecargas">₡0</div>
<div class="admin-dash-kpi-meta">
<span>SINPE Móvil: <strong id="dashKpiRecargasSinpe" style="color: #8b5cf6;">₡0</strong></span>
<span>Efectivo / Caja: <strong id="dashKpiRecargasEfectivo" style="color: var(--text-main);">₡0</strong></span>
</div>
</div>
<!-- KPI 4: DESPACHO Y PREÓRDENES -->
<div class="admin-dash-kpi-card kpi-amber">
<div class="admin-dash-kpi-header">
<span class="admin-dash-kpi-title">Canal de Venta</span>
<div class="admin-dash-kpi-icon">⏱️</div>
</div>
<div class="admin-dash-kpi-val" id="dashKpiCanalRatio">0% Pre-orden</div>
<div class="admin-dash-kpi-meta">
<span>Preórdenes: <strong id="dashKpiPreordenDetalle" style="color: var(--text-main);">₡0 (0 ord)</strong></span>
<span>Mostrador: <strong id="dashKpiMostradorDetalle" style="color: var(--text-main);">₡0 (0 ord)</strong></span>
</div>
</div>
</div>
<!-- SECCIÓN 2 COLUMNAS: MOMENTOS ESCOLARES Y TOP PRODUCTOS -->
<div class="admin-dash-split">
<!-- COLUMNA 1: VENTAS POR MOMENTO ESCOLAR -->
<div class="admin-dash-section">
<div class="admin-dash-section-title">
<span>🕒 Ventas por Momento Escolar</span>
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Participación %</span>
</div>
<div id="adminDashMomentosList" style="display: flex; flex-direction: column; gap: 12px;">
<!-- Barras dinámicas de Primer Recreo, Almuerzo, Segundo Recreo, Mostrador -->
</div>
</div>
<!-- COLUMNA 2: TOP 5 PRODUCTOS MÁS VENDIDOS -->
<div class="admin-dash-section">
<div class="admin-dash-section-title">
<span>🏆 Top 5 Productos Más Vendidos</span>
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Unidades & Total</span>
</div>
<div id="adminDashTopProductosList" style="display: flex; flex-direction: column; gap: 10px;">
<!-- Lista dinámica de Top Productos -->
</div>
</div>
</div>
<!-- SECCIÓN TENDENCIA SEMANAL: ÚLTIMOS 7 DÍAS -->
<div class="admin-dash-section">
<div class="admin-dash-section-title">
<span>📈 Tendencia Semanal de Ventas (Últimos 7 Días)</span>
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Facturación diaria en ₡</span>
</div>
<div class="admin-dash-chart" id="adminDashChart7Dias">
<!-- 7 Columnas dinámicas -->
</div>
</div>
<!-- ACCIONES RÁPIDAS DE EXPORTACIÓN Y REPORTES -->
<div style="display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; padding-top: 10px; border-top: 1px solid var(--border, #e2e8f0);">
<button type="button" onclick="exportarVentasCsv()" class="btn-saas btn-saas-outline" style="height: 36px; border-color: #10b981; color: #166534; font-size: 0.82rem; font-weight: 800;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar Ventas XLSX</span>
</button>
<button type="button" onclick="descargarReporteRecargasExcel(true)" class="btn-saas btn-saas-outline" style="height: 36px; border-color: #8b5cf6; color: #6d28d9; font-size: 0.82rem; font-weight: 800;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar Recargas SINPE XLSX</span>
</button>
<button type="button" onclick="exportarEstudiantesCsv()" class="btn-saas btn-saas-outline" style="height: 36px; border-color: #0284c7; color: #0284c7; font-size: 0.82rem; font-weight: 800;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar Saldos Alumnos XLSX</span>
</button>
</div>
</div>
</div>
<!-- TAB 1: INVENTARIO Y STOCK --> <!-- TAB 1: INVENTARIO Y STOCK -->
<div id="adminTabContentInventario" class="admin-card"> <div id="adminTabContentInventario" class="admin-card" style="display: none;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px;"> <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px;">
<div> <div>
<h3 style="margin: 0; font-size: 1.1rem; font-weight: 800; color: var(--text-main);">Inventario y Existencias</h3> <h3 style="margin: 0; font-size: 1.1rem; font-weight: 800; color: var(--text-main);">Inventario y Existencias</h3>
@@ -3434,6 +3585,6 @@
<script src="/js/sounds.js?v=13.8"></script> <script src="/js/sounds.js?v=13.8"></script>
<script src="/js/jsQR.js"></script> <script src="/js/jsQR.js"></script>
<script src="/js/food-icons.js?v=1.1"></script> <script src="/js/food-icons.js?v=1.1"></script>
<script src="/js/app.js?v=13.8"></script> <script src="/js/app.js?v=13.9"></script>
</body> </body>
</html> </html>
+227 -2
View File
@@ -4627,8 +4627,228 @@ async function confirmLinkValidatedChild() {
// PANEL DE ADMINISTRACIÓN DE LA SODA // PANEL DE ADMINISTRACIÓN DE LA SODA
// ========================================== // ==========================================
let dashboardPeriodoActual = 'hoy';
async function cambiarPeriodoDashboard(periodo) {
dashboardPeriodoActual = periodo;
const container = document.getElementById('adminDashPeriodPills');
if (container) {
const buttons = container.querySelectorAll('.admin-dash-pill-btn');
buttons.forEach(btn => {
btn.classList.toggle('active', btn.dataset.periodo === periodo);
});
}
await cargarDashboardAdmin(periodo);
}
async function cargarDashboardAdmin(periodo = dashboardPeriodoActual) {
try {
const res = await fetch(`/api/admin/dashboard?periodo=${encodeURIComponent(periodo)}`);
if (!res.ok) throw new Error('Error al cargar datos del dashboard');
const data = await res.json();
// 1. KPI Ventas
const ord = data.ordenes || {};
const elVentas = document.getElementById('dashKpiVentas');
if (elVentas) elVentas.textContent = `₡${(ord.total_ventas || 0).toLocaleString('es-CR')}`;
const elOrdenes = document.getElementById('dashKpiOrdenes');
if (elOrdenes) elOrdenes.textContent = `${ord.ordenes_cobradas || 0} órdenes`;
const elTicket = document.getElementById('dashKpiTicketPromedio');
if (elTicket) elTicket.textContent = `₡${(ord.ticket_promedio || 0).toLocaleString('es-CR')} / ord`;
// 2. KPI Monederos Estudiantes
const saldos = data.saldos || {};
const elCirculante = document.getElementById('dashKpiSaldoCirculante');
if (elCirculante) elCirculante.textContent = `₡${(saldos.total_circulante || 0).toLocaleString('es-CR')}`;
const elDisponible = document.getElementById('dashKpiSaldoDisponible');
if (elDisponible) elDisponible.textContent = `₡${(saldos.disponible || 0).toLocaleString('es-CR')}`;
const elRetenido = document.getElementById('dashKpiSaldoRetenido');
if (elRetenido) elRetenido.textContent = `₡${(saldos.retenido_preordenes || 0).toLocaleString('es-CR')}`;
// 3. KPI Recargas
const rec = data.recargas || {};
const elRecargas = document.getElementById('dashKpiRecargas');
if (elRecargas) elRecargas.textContent = `₡${(rec.total_recargas || 0).toLocaleString('es-CR')}`;
const elRecSinpe = document.getElementById('dashKpiRecargasSinpe');
if (elRecSinpe) elRecSinpe.textContent = `₡${(rec.recargas_sinpe || 0).toLocaleString('es-CR')}`;
const elRecEfectivo = document.getElementById('dashKpiRecargasEfectivo');
if (elRecEfectivo) elRecEfectivo.textContent = `₡${(rec.recargas_efectivo || 0).toLocaleString('es-CR')} (${rec.cantidad_recargas || 0} recargas)`;
// 4. KPI Canales (Preorden vs Mostrador)
const totalVentas = ord.total_ventas || 0;
const ratioPreorden = totalVentas > 0 ? Math.round(((ord.ventas_preorden || 0) / totalVentas) * 100) : 0;
const elRatio = document.getElementById('dashKpiCanalRatio');
if (elRatio) elRatio.textContent = `${ratioPreorden}% Pre-orden`;
const elPreordenDet = document.getElementById('dashKpiPreordenDetalle');
if (elPreordenDet) elPreordenDet.textContent = `₡${(ord.ventas_preorden || 0).toLocaleString('es-CR')} (${ord.ordenes_preorden || 0} ord)`;
const elMostradorDet = document.getElementById('dashKpiMostradorDetalle');
if (elMostradorDet) elMostradorDet.textContent = `₡${(ord.ventas_mostrador || 0).toLocaleString('es-CR')} (${ord.ordenes_mostrador || 0} ord)`;
// 5. Momentos Escolares
const contMomentos = document.getElementById('adminDashMomentosList');
if (contMomentos) {
const momentos = data.momentos || [];
if (momentos.length === 0 || totalVentas === 0) {
contMomentos.innerHTML = `
<div style="text-align: center; padding: 20px 10px; color: var(--text-muted); font-size: 0.8rem;">
Sin registro de ventas en los recreos para este período.
</div>
`;
} else {
contMomentos.innerHTML = momentos.map(m => {
const pct = totalVentas > 0 ? Math.round((m.total / totalVentas) * 100) : 0;
return `
<div class="admin-dash-bar-row">
<div class="admin-dash-bar-meta">
<span style="display: flex; align-items: center; gap: 6px;">
<span style="width: 8px; height: 8px; border-radius: 50%; background: ${m.color}; display: inline-block;"></span>
<strong>${m.label}</strong>
<span style="color: var(--text-muted); font-size: 0.72rem; font-weight: normal;">(${m.cantidad} órdenes)</span>
</span>
<span>₡${m.total.toLocaleString('es-CR')} <small style="color: var(--text-muted); font-weight: normal;">(${pct}%)</small></span>
</div>
<div class="admin-dash-bar-track">
<div class="admin-dash-bar-fill" style="width: ${pct}%; background: ${m.color};"></div>
</div>
</div>
`;
}).join('');
}
}
// 6. Top 5 Productos
const contTop = document.getElementById('adminDashTopProductosList');
if (contTop) {
const top = data.top_productos || [];
if (top.length === 0) {
contTop.innerHTML = `
<div style="text-align: center; padding: 20px 10px; color: var(--text-muted); font-size: 0.8rem;">
No hay productos vendidos en este período.
</div>
`;
} else {
const maxCant = Math.max(...top.map(t => t.cantidad_total || 1));
const medallas = ['🥇', '🥈', '🥉', '4º', '5º'];
contTop.innerHTML = top.map((p, idx) => {
const pct = Math.round(((p.cantidad_total || 0) / maxCant) * 100);
return `
<div style="display: flex; flex-direction: column; gap: 4px; padding: 6px 0; border-bottom: 1px dashed var(--border, #e2e8f0);">
<div style="display: flex; justify-content: space-between; align-items: center; font-size: 0.82rem;">
<span style="display: flex; align-items: center; gap: 6px; min-width: 0;">
<span style="font-size: 0.85rem; font-weight: 800; width: 22px;">${medallas[idx] || (idx + 1)}</span>
<strong style="color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">${escapeHtml(p.nombre_producto)}</strong>
</span>
<span style="text-align: right; flex-shrink: 0; font-weight: 800; color: #0284c7;">
₡${(p.recaudacion_total || 0).toLocaleString('es-CR')}
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600; display: block;">${p.cantidad_total} uds</span>
</span>
</div>
<div class="admin-dash-bar-track" style="height: 5px;">
<div class="admin-dash-bar-fill" style="width: ${pct}%; background: linear-gradient(90deg, #38bdf8, #0284c7);"></div>
</div>
</div>
`;
}).join('');
}
}
// 7. Gráfico Semanal 7 Días
const contChart = document.getElementById('adminDashChart7Dias');
if (contChart) {
const dias = data.tendencia_7dias || [];
const maxVenta = Math.max(...dias.map(d => d.ventas || 0), 1000);
contChart.innerHTML = dias.map(d => {
const heightPct = Math.max(4, Math.round(((d.ventas || 0) / maxVenta) * 100));
const tieneVentas = (d.ventas || 0) > 0;
return `
<div class="admin-dash-col" title="${d.fecha}: ₡${d.ventas.toLocaleString('es-CR')} (${d.ordenes} órdenes)">
<div class="admin-dash-col-val" style="color: ${tieneVentas ? 'var(--text-main)' : 'var(--text-muted)'}; font-weight: ${tieneVentas ? '800' : '600'};">
${tieneVentas ? '₡' + (d.ventas >= 1000 ? Math.round(d.ventas / 1000) + 'k' : d.ventas) : '₡0'}
</div>
<div class="admin-dash-col-bar" style="height: ${heightPct}%; opacity: ${tieneVentas ? '1' : '0.2'};"></div>
<div class="admin-dash-col-lbl">${d.etiqueta}</div>
</div>
`;
}).join('');
}
// 8. Alertas Operativas
const contAlerts = document.getElementById('adminDashAlertsContainer');
if (contAlerts) {
const alertas = data.alertas || {};
const alertItems = [];
if (alertas.sinpe_pendientes > 0) {
alertItems.push(`
<div style="background: rgba(245, 158, 11, 0.08); border: 1px solid rgba(245, 158, 11, 0.3); border-radius: 9px; padding: 9px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px;">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1rem;">🔔</span>
<span style="font-size: 0.8rem; font-weight: 700; color: #b45309;">
Hay <strong>${alertas.sinpe_pendientes}</strong> solicitud(es) de recarga SINPE Móvil pendientes de verificación.
</span>
</div>
<button type="button" onclick="switchAdminTab('recarga')" class="btn-saas btn-saas-outline" style="height: 26px; padding: 0 10px; font-size: 0.74rem; border-color: #f59e0b; color: #b45309;">
Revisar SINPE
</button>
</div>
`);
}
if (alertas.productos_criticos > 0) {
alertItems.push(`
<div style="background: rgba(239, 68, 68, 0.08); border: 1px solid rgba(239, 68, 68, 0.3); border-radius: 9px; padding: 9px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px;">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1rem;">⚠️</span>
<span style="font-size: 0.8rem; font-weight: 700; color: #b91c1c;">
Hay <strong>${alertas.productos_criticos}</strong> producto(s) en stock crítico o agotados en el inventario.
</span>
</div>
<button type="button" onclick="switchAdminTab('inventario')" class="btn-saas btn-saas-outline" style="height: 26px; padding: 0 10px; font-size: 0.74rem; border-color: #ef4444; color: #b91c1c;">
Ver Inventario
</button>
</div>
`);
}
if (alertas.tarjetas_bloqueadas > 0) {
alertItems.push(`
<div style="background: rgba(100, 116, 139, 0.08); border: 1px solid rgba(100, 116, 139, 0.25); border-radius: 9px; padding: 9px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px;">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1rem;">🚫</span>
<span style="font-size: 0.8rem; font-weight: 700; color: var(--text-main);">
Hay <strong>${alertas.tarjetas_bloqueadas}</strong> carné(s) escolar(es) con tarjeta bloqueada.
</span>
</div>
<button type="button" onclick="switchAdminTab('estudiantes')" class="btn-saas btn-saas-outline" style="height: 26px; padding: 0 10px; font-size: 0.74rem;">
Ver Carnés
</button>
</div>
`);
}
if (alertItems.length > 0) {
contAlerts.innerHTML = alertItems.join('');
contAlerts.style.display = 'flex';
} else {
contAlerts.innerHTML = '';
contAlerts.style.display = 'none';
}
}
} catch (err) {
console.error('Error al cargar dashboard ejecutivo:', err);
}
}
function switchAdminTab(tabName) { function switchAdminTab(tabName) {
const tabs = ['inventario', 'estudiantes', 'recarga', 'movimientos', 'personal', 'horarios']; const tabs = ['dashboard', 'inventario', 'estudiantes', 'recarga', 'movimientos', 'personal', 'horarios'];
tabs.forEach(t => { tabs.forEach(t => {
const btn = document.getElementById(`btnTabAdmin${t.charAt(0).toUpperCase() + t.slice(1)}`); const btn = document.getElementById(`btnTabAdmin${t.charAt(0).toUpperCase() + t.slice(1)}`);
const content = document.getElementById(`adminTabContent${t.charAt(0).toUpperCase() + t.slice(1)}`); const content = document.getElementById(`adminTabContent${t.charAt(0).toUpperCase() + t.slice(1)}`);
@@ -4636,7 +4856,9 @@ function switchAdminTab(tabName) {
if (content) content.style.display = (t === tabName) ? 'block' : 'none'; if (content) content.style.display = (t === tabName) ? 'block' : 'none';
}); });
if (tabName === 'movimientos') { if (tabName === 'dashboard') {
cargarDashboardAdmin();
} else if (tabName === 'movimientos') {
loadAdminMovimientos(); loadAdminMovimientos();
} else if (tabName === 'personal') { } else if (tabName === 'personal') {
loadAdminStaff(); loadAdminStaff();
@@ -4773,6 +4995,9 @@ async function loadAdminData() {
// 6. Cargar horarios escolares para la pestaña de configuración // 6. Cargar horarios escolares para la pestaña de configuración
cargarHorariosAdmin(); cargarHorariosAdmin();
// 7. Cargar Dashboard Ejecutivo
cargarDashboardAdmin();
} catch (err) { } catch (err) {
console.error('Error cargando datos de administración:', err); console.error('Error cargando datos de administración:', err);
} }
+2 -2
View File
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SiboPay POS - Terminal de Mostrador y Despacho</title> <title>SiboPay POS - Terminal de Mostrador y Despacho</title>
<link rel="icon" type="image/png" href="/img/sibopay-emblem.png"> <link rel="icon" type="image/png" href="/img/sibopay-emblem.png">
<link rel="stylesheet" href="/css/styles.css?v=13.7"> <link rel="stylesheet" href="/css/styles.css?v=13.9">
<style> <style>
/* Estilos específicos de terminal de alta velocidad */ /* Estilos específicos de terminal de alta velocidad */
.student-badge-scanned { .student-badge-scanned {
@@ -677,6 +677,6 @@
<script src="/js/sounds.js?v=13.8"></script> <script src="/js/sounds.js?v=13.8"></script>
<script src="/js/jsQR.js"></script> <script src="/js/jsQR.js"></script>
<script src="/js/food-icons.js?v=1.1"></script> <script src="/js/food-icons.js?v=1.1"></script>
<script src="/js/pos.js?v=13.8"></script> <script src="/js/pos.js?v=13.9"></script>
</body> </body>
</html> </html>
+2 -2
View File
@@ -1,5 +1,5 @@
// SiboPay PWA Service Worker v13.8 - Sonidos desactivados en toda la aplicación // SiboPay PWA Service Worker v13.9 - Dashboard Ejecutivo de Soda
const CACHE_NAME = 'sibopay-v13.8'; const CACHE_NAME = 'sibopay-v13.9';
const STATIC_ASSETS = [ const STATIC_ASSETS = [
'/', '/',
'/index.html', '/index.html',
+202
View File
@@ -513,6 +513,208 @@ app.get('/api/admin/resumen', (req, res) => {
} }
}); });
// Dashboard Ejecutivo de Información y Finanzas de la Soda
app.get('/api/admin/dashboard', (req, res) => {
try {
const periodo = req.query.periodo || 'hoy';
const ahora = new Date();
const fHoy = new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Costa_Rica' }).format(ahora);
let fechaInicio = fHoy;
let fechaFin = fHoy;
let usarFiltroFechas = true;
if (periodo === 'hoy') {
fechaInicio = fHoy;
fechaFin = fHoy;
} else if (periodo === '7dias' || periodo === 'semana') {
const d7 = new Date();
d7.setDate(d7.getDate() - 6);
fechaInicio = new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Costa_Rica' }).format(d7);
fechaFin = fHoy;
} else if (periodo === 'mes') {
fechaInicio = new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Costa_Rica' }).format(new Date(ahora.getFullYear(), ahora.getMonth(), 1));
fechaFin = fHoy;
} else if (periodo === 'todo') {
usarFiltroFechas = false;
} else if (req.query.desde) {
fechaInicio = req.query.desde;
fechaFin = req.query.hasta || fHoy;
}
// 1. Métricas Generales de Órdenes y Ventas
let sqlOrdenes = `
SELECT
COALESCE(SUM(CASE WHEN estado != 'cancelado' THEN total_colones ELSE 0 END), 0) as total_ventas,
COALESCE(SUM(CASE WHEN estado != 'cancelado' THEN 1 ELSE 0 END), 0) as ordenes_cobradas,
ROUND(COALESCE(AVG(CASE WHEN estado != 'cancelado' THEN total_colones ELSE NULL END), 0)) as ticket_promedio,
COALESCE(SUM(CASE WHEN estado != 'cancelado' AND tipo_orden = 'preorden' THEN total_colones ELSE 0 END), 0) as ventas_preorden,
COALESCE(SUM(CASE WHEN estado != 'cancelado' AND tipo_orden = 'preorden' THEN 1 ELSE 0 END), 0) as ordenes_preorden,
COALESCE(SUM(CASE WHEN estado != 'cancelado' AND tipo_orden = 'mostrador' THEN total_colones ELSE 0 END), 0) as ventas_mostrador,
COALESCE(SUM(CASE WHEN estado != 'cancelado' AND tipo_orden = 'mostrador' THEN 1 ELSE 0 END), 0) as ordenes_mostrador,
COALESCE(SUM(CASE WHEN estado = 'entregado' THEN 1 ELSE 0 END), 0) as ordenes_entregadas,
COALESCE(SUM(CASE WHEN estado = 'cancelado' THEN 1 ELSE 0 END), 0) as ordenes_canceladas,
COALESCE(SUM(CASE WHEN estado IN ('pendiente', 'en_preparacion', 'listo') THEN 1 ELSE 0 END), 0) as ordenes_pendientes
FROM ordenes
`;
const paramsOrdenes = [];
if (usarFiltroFechas) {
sqlOrdenes += ` WHERE date(creado_en, 'localtime') >= ? AND date(creado_en, 'localtime') <= ?`;
paramsOrdenes.push(fechaInicio, fechaFin);
}
const ordenesStats = db.prepare(sqlOrdenes).get(...paramsOrdenes);
// 2. Desglose de Ventas por Momento Escolar
let sqlMomentos = `
SELECT momento_entrega, COALESCE(SUM(total_colones), 0) as total, COUNT(*) as cantidad
FROM ordenes
WHERE estado != 'cancelado'
`;
const paramsMomentos = [];
if (usarFiltroFechas) {
sqlMomentos += ` AND date(creado_en, 'localtime') >= ? AND date(creado_en, 'localtime') <= ?`;
paramsMomentos.push(fechaInicio, fechaFin);
}
sqlMomentos += ` GROUP BY momento_entrega`;
const rawMomentos = db.prepare(sqlMomentos).all(...paramsMomentos);
const mapaMomentos = {
'primer_recreo': { key: 'primer_recreo', label: '1er Recreo', total: 0, cantidad: 0, color: '#0284c7' },
'almuerzo': { key: 'almuerzo', label: 'Almuerzo', total: 0, cantidad: 0, color: '#10b981' },
'segundo_recreo': { key: 'segundo_recreo', label: '2do Recreo', total: 0, cantidad: 0, color: '#f59e0b' },
'inmediato': { key: 'inmediato', label: 'Mostrador / Inmediato', total: 0, cantidad: 0, color: '#6366f1' }
};
rawMomentos.forEach(m => {
let k = (m.momento_entrega || '').toLowerCase();
if (k === 'recreo_1' || k === 'primer_recreo') k = 'primer_recreo';
else if (k === 'recreo_2' || k === 'segundo_recreo') k = 'segundo_recreo';
else if (k === 'almuerzo') k = 'almuerzo';
else k = 'inmediato';
if (mapaMomentos[k]) {
mapaMomentos[k].total += m.total;
mapaMomentos[k].cantidad += m.cantidad;
}
});
const momentosList = Object.values(mapaMomentos);
// 3. Top 5 Productos Más Vendidos
let sqlTop = `
SELECT
od.nombre_producto,
COALESCE(SUM(od.cantidad), 0) as cantidad_total,
COALESCE(SUM(od.subtotal), 0) as recaudacion_total
FROM orden_detalles od
JOIN ordenes o ON od.orden_id = o.id
WHERE o.estado != 'cancelado'
`;
const paramsTop = [];
if (usarFiltroFechas) {
sqlTop += ` AND date(o.creado_en, 'localtime') >= ? AND date(o.creado_en, 'localtime') <= ?`;
paramsTop.push(fechaInicio, fechaFin);
}
sqlTop += ` GROUP BY od.nombre_producto ORDER BY cantidad_total DESC, recaudacion_total DESC LIMIT 5`;
const topProductos = db.prepare(sqlTop).all(...paramsTop);
// 4. Recargas de Saldo
let sqlRecargas = `
SELECT
COALESCE(SUM(monto_colones), 0) as total_recargas,
COALESCE(SUM(CASE WHEN tipo = 'recarga_sinpe' THEN monto_colones ELSE 0 END), 0) as recargas_sinpe,
COALESCE(SUM(CASE WHEN tipo = 'recarga_manual' THEN monto_colones ELSE 0 END), 0) as recargas_efectivo,
COUNT(*) as cantidad_recargas
FROM transacciones_saldo
WHERE tipo IN ('recarga_sinpe', 'recarga_manual') AND monto_colones > 0 AND (revertida IS NULL OR revertida = 0)
`;
const paramsRecargas = [];
if (usarFiltroFechas) {
sqlRecargas += ` AND date(fecha, 'localtime') >= ? AND date(fecha, 'localtime') <= ?`;
paramsRecargas.push(fechaInicio, fechaFin);
}
const recargasStats = db.prepare(sqlRecargas).get(...paramsRecargas);
// 5. Saldo Flotante en Monederos Estudiantiles
const saldoEstudiantes = db.prepare(`
SELECT
COUNT(*) as total_estudiantes,
COALESCE(SUM(saldo_colones), 0) as saldo_total_estudiantes,
COALESCE(SUM(CASE WHEN tarjeta_bloqueada = 1 THEN 1 ELSE 0 END), 0) as tarjetas_bloqueadas
FROM estudiantes
WHERE activo = 1
`).get();
const saldoRetenidoRow = db.prepare(`
SELECT COALESCE(SUM(total_colones), 0) as saldo_retenido
FROM ordenes
WHERE tipo_orden = 'preorden' AND estado IN ('pendiente', 'en_preparacion', 'listo')
`).get();
const saldoRetenido = saldoRetenidoRow ? saldoRetenidoRow.saldo_retenido : 0;
const saldoDisponible = Math.max(0, (saldoEstudiantes.saldo_total_estudiantes || 0) - saldoRetenido);
// 6. Tendencia Últimos 7 Días
const tendencia7Dias = [];
const diasSemanaNombres = ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'];
for (let i = 6; i >= 0; i--) {
const d = new Date();
d.setDate(d.getDate() - i);
const diaIso = new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Costa_Rica' }).format(d);
const diaNum = new Intl.DateTimeFormat('es-CR', { timeZone: 'America/Costa_Rica', day: '2-digit', month: '2-digit' }).format(d);
const diaSem = diasSemanaNombres[d.getDay()];
const statDia = db.prepare(`
SELECT
COALESCE(SUM(CASE WHEN estado != 'cancelado' THEN total_colones ELSE 0 END), 0) as ventas,
COALESCE(SUM(CASE WHEN estado != 'cancelado' THEN 1 ELSE 0 END), 0) as ordenes
FROM ordenes
WHERE date(creado_en, 'localtime') = ?
`).get(diaIso);
tendencia7Dias.push({
fecha: diaIso,
etiqueta: `${diaSem} ${diaNum}`,
ventas: statDia ? statDia.ventas : 0,
ordenes: statDia ? statDia.ordenes : 0
});
}
// 7. Alertas Operativas
const sinpePendientes = db.prepare(`
SELECT COUNT(*) as count FROM solicitudes_recarga_sinpe WHERE estado = 'pendiente'
`).get().count;
const prodsCriticos = db.prepare(`
SELECT COUNT(*) as count FROM productos WHERE control_stock = 1 AND (stock <= 3 OR disponible = 0)
`).get().count;
res.json({
periodo,
fecha_inicio: fechaInicio,
fecha_fin: fechaFin,
ordenes: ordenesStats,
recargas: recargasStats,
saldos: {
total_circulante: saldoEstudiantes.saldo_total_estudiantes,
retenido_preordenes: saldoRetenido,
disponible: saldoDisponible,
estudiantes_activos: saldoEstudiantes.total_estudiantes,
tarjetas_bloqueadas: saldoEstudiantes.tarjetas_bloqueadas
},
momentos: momentosList,
top_productos: topProductos,
tendencia_7dias: tendencia7Dias,
alertas: {
sinpe_pendientes: sinpePendientes,
productos_criticos: prodsCriticos,
tarjetas_bloqueadas: saldoEstudiantes.tarjetas_bloqueadas
}
});
} catch (err) {
console.error('Error en /api/admin/dashboard:', err);
res.status(500).json({ error: err.message });
}
});
// Listado de inventario para admin // Listado de inventario para admin
app.get('/api/admin/productos', (req, res) => { app.get('/api/admin/productos', (req, res) => {
try { try {