feat: Implementar panel Developer Master con gestión de usuarios, subida de diseños de tarjetas y diagnóstico del sistema
This commit is contained in:
@@ -2553,4 +2553,270 @@ body.dark-mode .carousel-nav-btn {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
DEVELOPER MASTER SUITE (#viewDeveloper)
|
||||
========================================================================== */
|
||||
.dev-container {
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
min-height: 100vh;
|
||||
background: var(--bg-main, #f8fafc);
|
||||
padding: calc(16px + var(--safe-top)) 16px calc(60px + var(--safe-bottom)) 16px;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.dev-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
background: var(--card-bg, #ffffff);
|
||||
border: 1.5px solid #8b5cf6;
|
||||
border-radius: 18px;
|
||||
padding: 14px 18px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 4px 20px -2px rgba(139, 92, 246, 0.15);
|
||||
}
|
||||
|
||||
.dev-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.dev-icon {
|
||||
font-size: 2rem;
|
||||
background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(16, 185, 129, 0.2));
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: 14px;
|
||||
border: 1px solid rgba(139, 92, 246, 0.4);
|
||||
}
|
||||
|
||||
.dev-header-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.dev-action-btn {
|
||||
padding: 8px 14px;
|
||||
border-radius: 10px;
|
||||
font-size: 0.82rem;
|
||||
font-weight: 800;
|
||||
border: 1px solid var(--border);
|
||||
background: var(--card-bg);
|
||||
color: var(--text-main);
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
text-decoration: none;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.dev-action-btn:hover {
|
||||
transform: translateY(-1px);
|
||||
border-color: #8b5cf6;
|
||||
}
|
||||
|
||||
.dev-action-btn-primary {
|
||||
background: linear-gradient(135deg, #8b5cf6, #7c3aed);
|
||||
color: white;
|
||||
border-color: #7c3aed;
|
||||
}
|
||||
|
||||
.dev-tabs-nav {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
overflow-x: auto;
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 4px;
|
||||
}
|
||||
|
||||
.dev-tab-btn {
|
||||
padding: 10px 18px;
|
||||
border-radius: 12px;
|
||||
font-size: 0.88rem;
|
||||
font-weight: 800;
|
||||
border: 1.5px solid var(--border);
|
||||
background: var(--card-bg);
|
||||
color: var(--text-muted);
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.dev-tab-btn.active {
|
||||
background: #8b5cf6;
|
||||
color: white;
|
||||
border-color: #7c3aed;
|
||||
box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
|
||||
}
|
||||
|
||||
.dev-card-uploader-box {
|
||||
background: var(--card-bg);
|
||||
border: 2px dashed #8b5cf6;
|
||||
border-radius: 16px;
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.dev-card-uploader-box:hover {
|
||||
background: rgba(139, 92, 246, 0.05);
|
||||
border-color: #7c3aed;
|
||||
}
|
||||
|
||||
.dev-role-badge {
|
||||
font-size: 0.72rem;
|
||||
font-weight: 800;
|
||||
padding: 3px 8px;
|
||||
border-radius: 6px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.role-developer {
|
||||
background: #fdf2f8;
|
||||
color: #db2777;
|
||||
border: 1px solid #f472b6;
|
||||
}
|
||||
|
||||
.role-admin {
|
||||
background: #f5f3ff;
|
||||
color: #7c3aed;
|
||||
border: 1px solid #c4b5fd;
|
||||
}
|
||||
|
||||
.role-cajero {
|
||||
background: #e0f2fe;
|
||||
color: #0284c7;
|
||||
border: 1px solid #7dd3fc;
|
||||
}
|
||||
|
||||
.role-vendedor {
|
||||
background: #fef3c7;
|
||||
color: #d97706;
|
||||
border: 1px solid #fcd34d;
|
||||
}
|
||||
|
||||
.role-padre {
|
||||
background: #dcfce7;
|
||||
color: #166534;
|
||||
border: 1px solid #86efac;
|
||||
}
|
||||
|
||||
.role-estudiante {
|
||||
background: #f3f4f6;
|
||||
color: #4b5563;
|
||||
border: 1px solid #d1d5db;
|
||||
}
|
||||
|
||||
/* Soporte de contraste dinámico para fondos de tarjetas en vivo */
|
||||
.wallet-card.has-custom-bg {
|
||||
background-size: cover !important;
|
||||
background-position: center !important;
|
||||
background-repeat: no-repeat !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-light-bg,
|
||||
.wallet-card.card-style-light {
|
||||
color: #0f172a !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-light-bg h2,
|
||||
.wallet-card.card-style-light h2,
|
||||
.wallet-card.card-text-light-bg #walletName,
|
||||
.wallet-card.card-style-light #walletName {
|
||||
color: #0f172a !important;
|
||||
text-shadow: 0 1px 2px rgba(255, 255, 255, 0.9) !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-light-bg .student-grade,
|
||||
.wallet-card.card-style-light .student-grade,
|
||||
.wallet-card.card-text-light-bg .label,
|
||||
.wallet-card.card-style-light .label {
|
||||
color: #334155 !important;
|
||||
font-weight: 700 !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-light-bg .amount span,
|
||||
.wallet-card.card-style-light .amount span,
|
||||
.wallet-card.card-text-light-bg #walletBalance,
|
||||
.wallet-card.card-style-light #walletBalance {
|
||||
color: #047857 !important;
|
||||
font-weight: 900 !important;
|
||||
text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8) !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-light-bg .qr-toggle-btn,
|
||||
.wallet-card.card-style-light .qr-toggle-btn {
|
||||
background: rgba(255, 255, 255, 0.85) !important;
|
||||
color: #0f172a !important;
|
||||
border: 1px solid rgba(0, 0, 0, 0.15) !important;
|
||||
box-shadow: 0 2px 6px rgba(0,0,0,0.1) !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-dark-bg,
|
||||
.wallet-card.card-style-dark {
|
||||
color: #ffffff !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-dark-bg h2,
|
||||
.wallet-card.card-style-dark h2,
|
||||
.wallet-card.card-text-dark-bg #walletName,
|
||||
.wallet-card.card-style-dark #walletName {
|
||||
color: #ffffff !important;
|
||||
text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9) !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-dark-bg .student-grade,
|
||||
.wallet-card.card-style-dark .student-grade,
|
||||
.wallet-card.card-text-dark-bg .label,
|
||||
.wallet-card.card-style-dark .label {
|
||||
color: #cbd5e1 !important;
|
||||
text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9) !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-dark-bg .amount span,
|
||||
.wallet-card.card-style-dark .amount span,
|
||||
.wallet-card.card-text-dark-bg #walletBalance,
|
||||
.wallet-card.card-style-dark #walletBalance {
|
||||
color: #4ade80 !important;
|
||||
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.95) !important;
|
||||
}
|
||||
|
||||
.wallet-card.card-text-dark-bg .qr-toggle-btn,
|
||||
.wallet-card.card-style-dark .qr-toggle-btn {
|
||||
background: rgba(0, 0, 0, 0.6) !important;
|
||||
color: #ffffff !important;
|
||||
border: 1px solid rgba(255, 255, 255, 0.25) !important;
|
||||
backdrop-filter: blur(6px) !important;
|
||||
}
|
||||
|
||||
@media (max-width: 650px) {
|
||||
.dev-header {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 12px;
|
||||
}
|
||||
.dev-header-actions {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -90,6 +90,10 @@
|
||||
<div class="login-demo-box">
|
||||
<div class="login-demo-title">Accesos Rápidos de Prueba:</div>
|
||||
<div class="login-demo-btns">
|
||||
<button type="button" class="login-demo-btn" onclick="quickFillLogin('dev', 'dev123')" style="border: 1.5px solid #8b5cf6; background: rgba(139, 92, 246, 0.08);">
|
||||
<span style="font-size: 1.3rem;">🛠️</span>
|
||||
<span style="color: #8b5cf6; font-weight: 800;">Developer</span>
|
||||
</button>
|
||||
<button type="button" class="login-demo-btn" onclick="quickFillLogin('admin', 'admin123')">
|
||||
<span style="font-size: 1.3rem;">👨🍳</span>
|
||||
<span>Admin Soda</span>
|
||||
@@ -115,6 +119,223 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PANEL MASTER DEVELOPER (#viewDeveloper) -->
|
||||
<div id="viewDeveloper" class="dev-container" style="display: none;">
|
||||
<!-- CABECERA DE DEVELOPER -->
|
||||
<header class="dev-header">
|
||||
<div class="dev-badge">
|
||||
<div class="dev-icon">🛠️</div>
|
||||
<div>
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<h2 style="font-size: 1.18rem; font-weight: 900; margin: 0; color: var(--text-main);">Developer Master Suite</h2>
|
||||
<span style="background: #fdf2f8; color: #db2777; border: 1px solid #f472b6; font-size: 0.68rem; font-weight: 800; padding: 2px 7px; border-radius: 6px;">ROOT MASTER</span>
|
||||
</div>
|
||||
<span id="devLoggedName" style="font-size: 0.78rem; color: #8b5cf6; font-weight: 700;">Master Developer (dev)</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dev-header-actions">
|
||||
<button onclick="toggleTheme()" class="theme-toggle-btn" title="Alternar Modo Oscuro / Claro">
|
||||
🌙
|
||||
</button>
|
||||
<button onclick="switchDevToView('admin')" class="dev-action-btn" title="Ir al Panel de Soda">
|
||||
<span>👨🍳</span> <span>Soda Admin</span>
|
||||
</button>
|
||||
<a href="/pos.html" target="_blank" class="dev-action-btn" title="Ir al Terminal de Caja POS">
|
||||
<span>📟</span> <span>Caja POS</span>
|
||||
</a>
|
||||
<button onclick="switchDevToView('student')" class="dev-action-btn" title="Probar Vista de Alumno">
|
||||
<span>🎒</span> <span>App Alumno</span>
|
||||
</button>
|
||||
<button onclick="logout(true)" class="dev-action-btn" style="color: #ef4444; border-color: rgba(239, 68, 68, 0.3);" title="Cerrar Sesión">
|
||||
<span>🚪</span> <span>Salir</span>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- NAVEGACIÓN DE PESTAÑAS DEVELOPER -->
|
||||
<nav class="dev-tabs-nav">
|
||||
<button class="dev-tab-btn active" id="btnDevTabUsuarios" onclick="switchDevTab('usuarios')">
|
||||
<span>👥</span> <span>Usuarios & Administradores</span>
|
||||
</button>
|
||||
<button class="dev-tab-btn" id="btnDevTabDisenos" onclick="switchDevTab('disenos')">
|
||||
<span>🎨</span> <span>Diseños de Tarjetas (Subir & Gestionar)</span>
|
||||
</button>
|
||||
<button class="dev-tab-btn" id="btnDevTabDiagnostico" onclick="switchDevTab('diagnostico')">
|
||||
<span>📊</span> <span>Diagnóstico del Sistema & BD</span>
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<!-- 1. PESTAÑA: USUARIOS Y ADMINISTRADORES -->
|
||||
<div id="devTabContentUsuarios" class="dev-tab-content">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 12px;">
|
||||
<div style="display: flex; gap: 8px; flex-wrap: wrap; align-items: center;">
|
||||
<input type="text" id="devUserSearchInput" placeholder="🔍 Buscar por nombre, usuario, rol..." oninput="filterDevUsuarios()" style="padding: 9px 14px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-size: 0.85rem; width: 260px; max-width: 100%;">
|
||||
<select id="devUserRoleFilter" onchange="filterDevUsuarios()" style="padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-size: 0.85rem; font-weight: 700;">
|
||||
<option value="all">Todos los Roles</option>
|
||||
<option value="admin">Administradores</option>
|
||||
<option value="developer">Developers</option>
|
||||
<option value="cajero">Cajeros</option>
|
||||
<option value="vendedor">Vendedores</option>
|
||||
<option value="padre">Padres de Familia</option>
|
||||
<option value="estudiante">Estudiantes</option>
|
||||
</select>
|
||||
</div>
|
||||
<button onclick="openModalDevUser()" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 18px; font-size: 0.88rem;">
|
||||
<span>➕</span> <span>Crear Nuevo Usuario / Admin</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Resumen rápido de usuarios -->
|
||||
<div id="devUserStatsStrip" style="display: flex; gap: 10px; overflow-x: auto; margin-bottom: 18px; padding-bottom: 4px;">
|
||||
<!-- Inyectado dinámicamente -->
|
||||
</div>
|
||||
|
||||
<!-- Tabla de usuarios -->
|
||||
<div style="background: var(--card-bg); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.05);">
|
||||
<div style="overflow-x: auto;">
|
||||
<table style="width: 100%; border-collapse: collapse; font-size: 0.86rem; text-align: left;">
|
||||
<thead>
|
||||
<tr style="background: var(--bg-main); border-bottom: 1.5px solid var(--border); color: var(--text-muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.5px;">
|
||||
<th style="padding: 12px 14px;">ID</th>
|
||||
<th style="padding: 12px 14px;">Usuario</th>
|
||||
<th style="padding: 12px 14px;">Nombre</th>
|
||||
<th style="padding: 12px 14px;">Rol</th>
|
||||
<th style="padding: 12px 14px;">Contacto</th>
|
||||
<th style="padding: 12px 14px;">Estado</th>
|
||||
<th style="padding: 12px 14px; text-align: right;">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="devUsersTableBody">
|
||||
<!-- Inyectado por JS -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 2. PESTAÑA: DISEÑOS DE TARJETAS (SUBIR & GESTIONAR) -->
|
||||
<div id="devTabContentDisenos" class="dev-tab-content" style="display: none;">
|
||||
<!-- FORMULARIO DE SUBIDA DE NUEVO DISEÑO -->
|
||||
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 18px; padding: 22px; margin-bottom: 30px; box-shadow: 0 6px 20px rgba(0,0,0,0.05);">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px;">
|
||||
<div>
|
||||
<h3 style="font-size: 1.15rem; font-weight: 900; margin: 0; color: var(--text-main);">➕ Subir Nuevo Diseño de Tarjeta</h3>
|
||||
<p style="font-size: 0.84rem; color: var(--text-muted); margin: 3px 0 0;">Sube una imagen personalizada. Quedará disponible inmediatamente para que los estudiantes la elijan.</p>
|
||||
</div>
|
||||
<span style="font-size: 0.78rem; font-weight: 800; background: rgba(139, 92, 246, 0.15); color: #8b5cf6; padding: 4px 10px; border-radius: 8px;">Recomendado: 1200x756 (3:2)</span>
|
||||
</div>
|
||||
|
||||
<form id="formDevCardDesign" onsubmit="saveDevCardDesign(event)" style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px;">
|
||||
<!-- Columna Izquierda: Input de archivo y campos -->
|
||||
<div>
|
||||
<!-- Zona de subida -->
|
||||
<label for="devCardFileInput" class="dev-card-uploader-box" id="devUploadDropZone" style="display: block;">
|
||||
<input type="file" id="devCardFileInput" accept="image/*" style="display: none;" onchange="handleDevCardFileSelect(event)">
|
||||
<div id="devUploadPrompt">
|
||||
<div style="font-size: 2.4rem; margin-bottom: 8px;">🖼️</div>
|
||||
<div style="font-weight: 800; font-size: 0.95rem; color: var(--text-main); margin-bottom: 4px;">Toca o arrastra una imagen de tarjeta aquí</div>
|
||||
<div style="font-size: 0.78rem; color: var(--text-muted);">Soporta JPG, PNG, WEBP o SVG (hasta 20MB)</div>
|
||||
</div>
|
||||
<div id="devUploadSuccess" style="display: none; color: #10b981; font-weight: 800; font-size: 0.88rem;">
|
||||
<span>✅ Imagen seleccionada con éxito</span>
|
||||
<div id="devUploadFileName" style="font-size: 0.75rem; color: var(--text-muted); margin-top: 4px;"></div>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<div style="margin-bottom: 12px;">
|
||||
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Nombre del Diseño:</label>
|
||||
<input type="text" id="devCardName" placeholder="Ej: Cyber Dragón, Galaxia Púrpura..." required style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;" oninput="updateDevCardLivePreview()">
|
||||
</div>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;">
|
||||
<div>
|
||||
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Categoría:</label>
|
||||
<select id="devCardCategory" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;" onchange="updateDevCardLivePreview()">
|
||||
<option value="uni">🌐 Unisex / Universal</option>
|
||||
<option value="fem">🌸 Femenino</option>
|
||||
<option value="masc">🚀 Masculino</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Contraste de Texto:</label>
|
||||
<select id="devCardTextStyle" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;" onchange="updateDevCardLivePreview()">
|
||||
<option value="dark">Texto Blanco (Fondo Oscuro)</option>
|
||||
<option value="light">Texto Oscuro (Fondo Claro)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" id="btnDevSubmitCard" class="dev-action-btn dev-action-btn-primary" style="width: 100%; padding: 12px; justify-content: center; font-size: 0.95rem; border-radius: 12px;">
|
||||
<span>🚀</span> <span>Guardar y Publicar Diseño</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Columna Derecha: Previsualizador en vivo con datos reales de estudiante -->
|
||||
<div>
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
|
||||
<span style="font-size: 0.82rem; font-weight: 800; color: var(--text-main);">👁️ Previsualización en Vivo de la Tarjeta</span>
|
||||
<span style="font-size: 0.72rem; color: #10b981; font-weight: 800;">✓ Sin asteriscos</span>
|
||||
</div>
|
||||
|
||||
<!-- Contenedor de la tarjeta simulada -->
|
||||
<div id="devLiveCardPreviewWrapper" style="position: relative; width: 100%; aspect-ratio: 1.586; border-radius: 18px; overflow: hidden; background: #0f172a; border: 1.5px solid var(--border); box-shadow: 0 10px 25px rgba(0,0,0,0.25);">
|
||||
<img id="devLiveCardBgImg" src="/img/cards/card_robo_lab.jpg" alt="Fondo" style="width: 100%; height: 100%; object-fit: cover; display: block;">
|
||||
<div id="devLiveCardOverlay" class="card-overlay" style="opacity: 1; position: absolute; inset: 0; padding: 16px 18px; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<div class="card-emv-chip" style="width: 34px; height: 25px; margin: 0;">
|
||||
<div class="chip-inner-circuit"></div>
|
||||
</div>
|
||||
<span id="devLiveCardBrand" style="font-weight: 900; font-size: 0.85rem; letter-spacing: 0.5px; text-transform: uppercase; color: #ffffff; text-shadow: 0 2px 8px rgba(0,0,0,0.8);">⚡ RECREOPAY</span>
|
||||
</div>
|
||||
<div style="margin-top: auto; margin-bottom: 6px;">
|
||||
<div id="devLiveCardName" style="font-size: 1.05rem; font-weight: 900; color: #ffffff; text-shadow: 0 2px 8px rgba(0,0,0,0.9);">MATEO ALVARADO CASTRO</div>
|
||||
<div id="devLiveCardGrade" style="font-size: 0.74rem; font-weight: 700; color: #cbd5e1; text-shadow: 0 2px 6px rgba(0,0,0,0.9);">2° Grado · Sección 2-A</div>
|
||||
</div>
|
||||
<div style="display: flex; justify-content: space-between; align-items: flex-end;">
|
||||
<div>
|
||||
<div id="devLiveCardBalLabel" style="font-size: 0.65rem; font-weight: 800; text-transform: uppercase; color: #cbd5e1; letter-spacing: 0.5px;">Saldo Disponible</div>
|
||||
<div id="devLiveCardBalValue" style="font-size: 1.25rem; font-weight: 900; color: #4ade80; text-shadow: 0 2px 10px rgba(0,0,0,0.95);">₡5.300</div>
|
||||
</div>
|
||||
<div id="devLiveCardCode" style="font-size: 0.72rem; font-weight: 800; color: #ffffff; background: rgba(0,0,0,0.5); padding: 3px 8px; border-radius: 6px; backdrop-filter: blur(4px); border: 1px solid rgba(255,255,255,0.2);">EST-2026-00001</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="devLiveCardThemeTitle" style="font-size: 0.85rem; font-weight: 800; color: var(--text-main); margin-top: 8px; text-align: center;">
|
||||
Robo-Lab Tech (Vista Previa)
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- GALERÍA DE DISEÑOS DISPONIBLES EN EL SISTEMA -->
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
|
||||
<div>
|
||||
<h3 style="font-size: 1.15rem; font-weight: 900; margin: 0; color: var(--text-main);">🖼️ Catálogo de Diseños Publicados (<span id="devDisenosCount">0</span>)</h3>
|
||||
<p style="font-size: 0.82rem; color: var(--text-muted); margin: 3px 0 0;">Estos son los diseños que pueden elegir los estudiantes en su carrusel.</p>
|
||||
</div>
|
||||
<div style="display: flex; gap: 6px;">
|
||||
<button class="dev-action-btn" onclick="filterDevDisenosGrid('all', this)">Todos</button>
|
||||
<button class="dev-action-btn" onclick="filterDevDisenosGrid('fem', this)">🌸 Femenino</button>
|
||||
<button class="dev-action-btn" onclick="filterDevDisenosGrid('masc', this)">🚀 Masculino</button>
|
||||
<button class="dev-action-btn" onclick="filterDevDisenosGrid('uni', this)">🌐 Unisex</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="devDisenosGrid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px;">
|
||||
<!-- Inyectado dinámicamente -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 3. PESTAÑA: DIAGNÓSTICO DEL SISTEMA & BD -->
|
||||
<div id="devTabContentDiagnostico" class="dev-tab-content" style="display: none;">
|
||||
<div id="devStatsContainer" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px;">
|
||||
<!-- Inyectado dinámicamente -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PANEL DE ADMINISTRACIÓN DE LA SODA (#viewAdmin) -->
|
||||
<div id="viewAdmin" class="admin-container" style="display: none;">
|
||||
<!-- CABECERA DE ADMINISTRADOR -->
|
||||
@@ -131,6 +352,9 @@
|
||||
<button onclick="toggleTheme()" class="theme-toggle-btn" title="Alternar Modo Oscuro / Modo Claro">
|
||||
🌙
|
||||
</button>
|
||||
<button id="btnAdminDevPanel" onclick="switchAdminToDev()" class="admin-action-btn" style="display: none; background: #8b5cf6; color: white; border-color: #7c3aed;" title="Volver al Panel Developer Master">
|
||||
<span>🛠️</span> <span class="admin-btn-text">Panel Dev</span>
|
||||
</button>
|
||||
<button onclick="switchAdminTab('recarga')" class="admin-action-btn admin-action-btn-recarga" title="Cargar dinero a un estudiante">
|
||||
<span>💵</span> <span class="admin-btn-text">Cargar Dinero</span>
|
||||
</button>
|
||||
@@ -1466,6 +1690,109 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL: CREAR / EDITAR USUARIO (DEVELOPER) -->
|
||||
<div class="modal-qr-backdrop" id="modalDevUser" style="display: none;" onclick="closeModalDevUser(event)">
|
||||
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 500px; text-align: left; padding: 22px;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<span style="font-size: 1.4rem;">👤</span>
|
||||
<div>
|
||||
<h3 id="modalDevUserTitle" style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Crear Nuevo Usuario</h3>
|
||||
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Control total de cuentas y permisos</span>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onclick="closeModalDevUser()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
|
||||
</div>
|
||||
|
||||
<form id="formDevUser" onsubmit="saveDevUser(event)">
|
||||
<input type="hidden" id="devUserId" value="">
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;">
|
||||
<div>
|
||||
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Usuario (Login):</label>
|
||||
<input type="text" id="devInputUsername" required placeholder="ej: admin2, carlos" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Rol en el Sistema:</label>
|
||||
<select id="devInputRol" required style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
|
||||
<option value="admin">Administrador (Soda/Escuela)</option>
|
||||
<option value="developer">Developer Master</option>
|
||||
<option value="cajero">Cajero POS</option>
|
||||
<option value="vendedor">Vendedor</option>
|
||||
<option value="padre">Padre de Familia</option>
|
||||
<option value="estudiante">Estudiante</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="margin-bottom: 12px;">
|
||||
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Nombre Completo:</label>
|
||||
<input type="text" id="devInputNombre" required placeholder="ej: Juan Pérez Rojas" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
|
||||
</div>
|
||||
|
||||
<div id="devPasswordRow" style="margin-bottom: 12px;">
|
||||
<label id="devPasswordLabel" style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Contraseña:</label>
|
||||
<input type="password" id="devInputPassword" placeholder="Contraseña de acceso" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
|
||||
<small id="devPasswordHelp" style="font-size: 0.72rem; color: var(--text-muted); display: none;">Dejar en blanco si no deseas cambiar la contraseña actual.</small>
|
||||
</div>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;">
|
||||
<div>
|
||||
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Teléfono:</label>
|
||||
<input type="text" id="devInputTelefono" placeholder="ej: 8888-8888" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
|
||||
</div>
|
||||
<div>
|
||||
<label style="font-size: 0.8rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Email:</label>
|
||||
<input type="email" id="devInputEmail" placeholder="[email protected]" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
|
||||
<button type="button" onclick="closeModalDevUser()" style="padding: 10px 18px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
|
||||
Cancelar
|
||||
</button>
|
||||
<button type="submit" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.9rem;">
|
||||
💾 Guardar Usuario
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL: CAMBIO RÁPIDO DE CONTRASEÑA (DEVELOPER) -->
|
||||
<div class="modal-qr-backdrop" id="modalDevPassword" style="display: none;" onclick="closeModalDevPassword(event)">
|
||||
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 420px; text-align: left; padding: 22px;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<span style="font-size: 1.4rem;">🔑</span>
|
||||
<div>
|
||||
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Cambiar Contraseña</h3>
|
||||
<span id="devPwdTargetUser" style="font-size: 0.78rem; color: #8b5cf6; font-weight: 700;">Usuario</span>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onclick="closeModalDevPassword()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
|
||||
</div>
|
||||
|
||||
<form id="formDevPassword" onsubmit="saveDevPassword(event)">
|
||||
<input type="hidden" id="devPwdUserId" value="">
|
||||
|
||||
<div style="margin-bottom: 16px;">
|
||||
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 6px;">Nueva Contraseña:</label>
|
||||
<input type="password" id="devInputNewPassword" required minlength="4" placeholder="Mínimo 4 caracteres" style="width: 100%; padding: 11px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; box-sizing: border-box; font-size: 0.95rem;">
|
||||
</div>
|
||||
|
||||
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
|
||||
<button type="button" onclick="closeModalDevPassword()" style="padding: 10px 18px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
|
||||
Cancelar
|
||||
</button>
|
||||
<button type="submit" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.9rem;">
|
||||
🔒 Actualizar Contraseña
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- BARRA DE NAVEGACIÓN INFERIOR PWA (MÓVILES) -->
|
||||
<nav class="pwa-bottom-nav" id="pwaBottomNav" style="display: none;">
|
||||
<button class="pwa-nav-item active" id="pwaNavMenu" onclick="pwaNavigateTo('menu')">
|
||||
|
||||
+812
-127
File diff suppressed because it is too large
Load Diff
+73
-7
@@ -145,28 +145,49 @@ function initDatabase() {
|
||||
try { db.exec('ALTER TABLE transacciones_saldo ADD COLUMN revertido_por_usuario_id INTEGER REFERENCES usuarios(id)'); } catch (e) {}
|
||||
try { db.exec('ALTER TABLE transacciones_saldo ADD COLUMN revertido_en DATETIME'); } catch (e) {}
|
||||
|
||||
// 10. Diseños de Tarjetas Virtuales para Estudiantes
|
||||
try {
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS disenos_tarjetas (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
theme_id TEXT UNIQUE NOT NULL,
|
||||
nombre TEXT NOT NULL,
|
||||
categoria TEXT DEFAULT 'uni', -- 'fem', 'masc', 'uni'
|
||||
imagen_url TEXT NOT NULL,
|
||||
estilo_texto TEXT DEFAULT 'dark', -- 'dark' (texto blanco) o 'light' (texto oscuro)
|
||||
es_predeterminado INTEGER DEFAULT 0,
|
||||
activo INTEGER DEFAULT 1,
|
||||
creado_en DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`);
|
||||
} catch (e) {}
|
||||
|
||||
seedInitialData();
|
||||
seedUsuarios();
|
||||
seedDisenosTarjetas();
|
||||
}
|
||||
|
||||
function seedUsuarios() {
|
||||
const count = db.prepare('SELECT COUNT(*) as count FROM usuarios').get().count;
|
||||
if (count === 0) {
|
||||
console.log('👤 Creando usuarios iniciales de demostración en RecreoPay...');
|
||||
const insert = db.prepare('INSERT INTO usuarios (username, password_hash, rol, nombre, telefono, email) VALUES (?, ?, ?, ?, ?, ?)');
|
||||
const insert = db.prepare('INSERT INTO usuarios (username, password_hash, rol, nombre, telefono, email, activo) VALUES (?, ?, ?, ?, ?, ?, ?)');
|
||||
|
||||
// 0. Developer Master
|
||||
insert.run('dev', 'dev123', 'developer', 'Master Developer', '+506 8888-9999', '[email protected]', 1);
|
||||
|
||||
// 1. Admin de la Soda
|
||||
insert.run('admin', 'admin123', 'admin', 'Administrador de la Soda', '+506 8888-7632', '[email protected]');
|
||||
insert.run('admin', 'admin123', 'admin', 'Administrador de la Soda', '+506 8888-7632', '[email protected]', 1);
|
||||
|
||||
// 2. Cajero de la Soda
|
||||
insert.run('cajero', 'cajero123', 'cajero', 'Cajero de la Soda', '+506 8888-0000', '[email protected]');
|
||||
insert.run('cajero', 'cajero123', 'cajero', 'Cajero de la Soda', '+506 8888-0000', '[email protected]', 1);
|
||||
|
||||
// 3. Padre de Mateo
|
||||
const resPadre = insert.run('padre', 'padre123', 'padre', 'Carlos Alvarado (Papá)', '+506 8888-1122', '[email protected]');
|
||||
const resPadre = insert.run('padre', 'padre123', 'padre', 'Carlos Alvarado (Papá)', '+506 8888-1122', '[email protected]', 1);
|
||||
|
||||
// 4. Estudiantes
|
||||
const resMateo = insert.run('mateo', '1234', 'estudiante', 'Mateo Alvarado Castro', '', '');
|
||||
const resSofia = insert.run('sofia', '1234', 'estudiante', 'Sofía Jiménez Morales', '', '');
|
||||
const resMateo = insert.run('mateo', '1234', 'estudiante', 'Mateo Alvarado Castro', '', '', 1);
|
||||
const resSofia = insert.run('sofia', '1234', 'estudiante', 'Sofía Jiménez Morales', '', '', 1);
|
||||
|
||||
// Vincular Mateo con su usuario y su padre
|
||||
try {
|
||||
@@ -174,16 +195,61 @@ function seedUsuarios() {
|
||||
db.prepare('UPDATE estudiantes SET usuario_id = ? WHERE id = 2').run(resSofia.lastInsertRowid);
|
||||
} catch (e) {}
|
||||
} else {
|
||||
// Asegurar que el usuario developer 'dev' exista
|
||||
try {
|
||||
const dev = db.prepare("SELECT id FROM usuarios WHERE username = 'dev'").get();
|
||||
if (!dev) {
|
||||
db.prepare("INSERT INTO usuarios (username, password_hash, rol, nombre, telefono, email, activo) VALUES ('dev', 'dev123', 'developer', 'Master Developer', '+506 8888-9999', '[email protected]', 1)").run();
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
// Asegurar que el usuario cajero exista en bases de datos ya pobladas
|
||||
try {
|
||||
const cajero = db.prepare("SELECT id FROM usuarios WHERE username = 'cajero'").get();
|
||||
if (!cajero) {
|
||||
db.prepare("INSERT INTO usuarios (username, password_hash, rol, nombre, telefono, email) VALUES ('cajero', 'cajero123', 'cajero', 'Cajero de la Soda', '+506 8888-0000', '[email protected]')").run();
|
||||
db.prepare("INSERT INTO usuarios (username, password_hash, rol, nombre, telefono, email, activo) VALUES ('cajero', 'cajero123', 'cajero', 'Cajero de la Soda', '+506 8888-0000', '[email protected]', 1)").run();
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
function seedDisenosTarjetas() {
|
||||
try {
|
||||
const count = db.prepare('SELECT COUNT(*) as count FROM disenos_tarjetas').get().count;
|
||||
if (count > 0) return;
|
||||
|
||||
console.log('🎨 Inicializando colección de 16 diseños de tarjetas en RecreoPay...');
|
||||
const insert = db.prepare(`
|
||||
INSERT INTO disenos_tarjetas (theme_id, nombre, categoria, imagen_url, estilo_texto, es_predeterminado, activo)
|
||||
VALUES (?, ?, ?, ?, ?, ?, 1)
|
||||
`);
|
||||
|
||||
// 6 Femeninos
|
||||
insert.run('card_fem_gatito', 'Gatito Tierno (Kitten Love)', 'fem', '/img/cards/card_fem_gatito.jpg', 'light', 0);
|
||||
insert.run('card_fem_unicornio', 'Unicornio de Ensueño', 'fem', '/img/cards/card_fem_unicornio.svg', 'light', 0);
|
||||
insert.run('card_fem_sirena', 'Océano de Sirena', 'fem', '/img/cards/card_fem_sirena.svg', 'light', 0);
|
||||
insert.run('card_fem_gamer', 'Gamer Girl Pastel', 'fem', '/img/cards/card_fem_gamer.svg', 'light', 0);
|
||||
insert.run('card_fem_ballet', 'Ballet & Danza', 'fem', '/img/cards/card_fem_ballet.svg', 'light', 0);
|
||||
insert.run('card_fem_mariposas', 'Jardín Botánico & Mariposas', 'fem', '/img/cards/card_fem_mariposas.svg', 'light', 0);
|
||||
|
||||
// 6 Masculinos
|
||||
insert.run('card_estrellas_futbol', 'Estrellas del Campo (Fútbol)', 'masc', '/img/cards/card_estrellas_futbol.jpg', 'dark', 0);
|
||||
insert.run('card_eco_aventura', 'Eco-Aventura', 'masc', '/img/cards/card_eco_aventura.jpg', 'light', 0);
|
||||
insert.run('card_pixel_quest', 'Pixel Quest (Videojuegos)', 'masc', '/img/cards/card_pixel_quest.jpg', 'dark', 0);
|
||||
insert.run('card_exploracion_galactica', 'Exploración Galáctica', 'masc', '/img/cards/card_exploracion_galactica.jpg', 'dark', 0);
|
||||
insert.run('card_masc_skate', 'Skate Park & Street Art', 'masc', '/img/cards/card_masc_skate.svg', 'light', 0);
|
||||
insert.run('card_masc_carreras', 'Velocidad Super Carreras', 'masc', '/img/cards/card_masc_carreras.svg', 'dark', 0);
|
||||
|
||||
// 4 Unisex
|
||||
insert.run('card_robo_lab', 'Robo-Lab Tech', 'uni', '/img/cards/card_robo_lab.jpg', 'dark', 1);
|
||||
insert.run('card_mundo_arte', 'Mundo de Arte', 'uni', '/img/cards/card_mundo_arte.jpg', 'light', 0);
|
||||
insert.run('card_uni_musica', 'Ritmo & Beats (DJ)', 'uni', '/img/cards/card_uni_musica.svg', 'dark', 0);
|
||||
insert.run('card_uni_titanium', 'Titanium Metal Edition', 'uni', '/img/cards/card_uni_titanium.svg', 'dark', 0);
|
||||
} catch (err) {
|
||||
console.error('Error inicializando diseños de tarjetas:', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
function seedInitialData() {
|
||||
const existingProducts = db.prepare('SELECT COUNT(*) as count FROM productos').get();
|
||||
if (existingProducts.count > 0) return;
|
||||
|
||||
+329
-1
@@ -1,6 +1,7 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const QRCode = require('qrcode');
|
||||
const { db, initDatabase, debitoCompraTransaction, recargaSaldoTransaction, crearOrdenCompleta, transferenciaP2PTransaction, revertirTransaccionSaldoTransaction } = require('./db');
|
||||
|
||||
@@ -11,7 +12,8 @@ const PORT = process.env.PORT || 3030;
|
||||
initDatabase();
|
||||
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
app.use(express.json({ limit: '25mb' }));
|
||||
app.use(express.urlencoded({ extended: true, limit: '25mb' }));
|
||||
app.use(express.static(path.join(__dirname, '../public'), {
|
||||
etag: false,
|
||||
setHeaders: (res, filePath) => {
|
||||
@@ -709,6 +711,332 @@ app.delete('/api/admin/personal/:id', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
// DEVELOPER MASTER SUITE & DISEÑOS DE TARJETAS
|
||||
// ==========================================
|
||||
|
||||
// Endpoint público para obtener diseños de tarjetas activas (utilizado por el carrusel y app de estudiantes)
|
||||
app.get('/api/disenos-tarjetas', (req, res) => {
|
||||
try {
|
||||
const disenos = db.prepare('SELECT * FROM disenos_tarjetas WHERE activo = 1 ORDER BY id ASC').all();
|
||||
res.json(disenos);
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Listar todos los usuarios del sistema (Acceso Developer)
|
||||
app.get('/api/developer/usuarios', (req, res) => {
|
||||
try {
|
||||
const usuarios = db.prepare(`
|
||||
SELECT u.id, u.username, u.password_hash, u.rol, u.nombre, u.telefono, u.email, u.activo, u.creado_en,
|
||||
(SELECT COUNT(*) FROM estudiantes e WHERE e.usuario_id = u.id) as es_estudiante,
|
||||
(SELECT COUNT(*) FROM padres_estudiantes pe WHERE pe.padre_usuario_id = u.id) as hijos_vinculados
|
||||
FROM usuarios u
|
||||
ORDER BY
|
||||
CASE u.rol
|
||||
WHEN 'developer' THEN 1
|
||||
WHEN 'admin' THEN 2
|
||||
WHEN 'cajero' THEN 3
|
||||
WHEN 'vendedor' THEN 4
|
||||
WHEN 'padre' THEN 5
|
||||
ELSE 6
|
||||
END, u.id ASC
|
||||
`).all();
|
||||
res.json(usuarios);
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Crear cualquier usuario con cualquier rol (Admin, Developer, Cajero, etc.)
|
||||
app.post('/api/developer/usuarios', (req, res) => {
|
||||
try {
|
||||
const { username, password, rol, nombre, telefono, email, activo } = req.body;
|
||||
if (!username || !password || !nombre || !rol) {
|
||||
return res.status(400).json({ error: 'Usuario, contraseña, nombre y rol son obligatorios.' });
|
||||
}
|
||||
|
||||
const cleanUser = String(username).trim().toLowerCase();
|
||||
const cleanPass = String(password).trim();
|
||||
const cleanRol = String(rol).trim().toLowerCase();
|
||||
const cleanActivo = activo === 0 ? 0 : 1;
|
||||
|
||||
const existe = db.prepare('SELECT id FROM usuarios WHERE LOWER(username) = ?').get(cleanUser);
|
||||
if (existe) {
|
||||
return res.status(400).json({ error: `El nombre de usuario "${cleanUser}" ya se encuentra registrado.` });
|
||||
}
|
||||
|
||||
const result = db.prepare(`
|
||||
INSERT INTO usuarios (username, password_hash, rol, nombre, telefono, email, activo)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
`).run(cleanUser, cleanPass, cleanRol, String(nombre).trim(), telefono || '', email || '', cleanActivo);
|
||||
|
||||
res.status(201).json({
|
||||
exito: true,
|
||||
mensaje: `Usuario "${nombre}" (${cleanRol}) creado exitosamente con privilegios.`,
|
||||
usuario: { id: result.lastInsertRowid, username: cleanUser, rol: cleanRol, nombre, activo: cleanActivo }
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Modificar datos completos de cualquier usuario (incluyendo administradores)
|
||||
app.put('/api/developer/usuarios/:id', (req, res) => {
|
||||
try {
|
||||
const userId = parseInt(req.params.id, 10);
|
||||
const { username, nombre, rol, telefono, email, password, activo } = req.body;
|
||||
|
||||
const user = db.prepare('SELECT * FROM usuarios WHERE id = ?').get(userId);
|
||||
if (!user) return res.status(404).json({ error: 'Usuario no encontrado.' });
|
||||
|
||||
// Validar nombre de usuario único si cambió
|
||||
if (username && username.trim().toLowerCase() !== user.username.toLowerCase()) {
|
||||
const existe = db.prepare('SELECT id FROM usuarios WHERE LOWER(username) = ? AND id != ?').get(username.trim().toLowerCase(), userId);
|
||||
if (existe) {
|
||||
return res.status(400).json({ error: 'Ese nombre de usuario ya pertenece a otra cuenta.' });
|
||||
}
|
||||
}
|
||||
|
||||
const nuevoUser = username ? username.trim().toLowerCase() : user.username;
|
||||
const nuevoNombre = nombre ? nombre.trim() : user.nombre;
|
||||
const nuevoRol = rol ? rol.trim().toLowerCase() : user.rol;
|
||||
const nuevoPass = (password && String(password).trim().length > 0) ? String(password).trim() : user.password_hash;
|
||||
const nuevoTel = telefono !== undefined ? telefono : user.telefono;
|
||||
const nuevoEmail = email !== undefined ? email : user.email;
|
||||
const nuevoActivo = activo !== undefined ? (activo ? 1 : 0) : user.activo;
|
||||
|
||||
db.prepare(`
|
||||
UPDATE usuarios
|
||||
SET username = ?, nombre = ?, rol = ?, password_hash = ?, telefono = ?, email = ?, activo = ?
|
||||
WHERE id = ?
|
||||
`).run(nuevoUser, nuevoNombre, nuevoRol, nuevoPass, nuevoTel, nuevoEmail, nuevoActivo, userId);
|
||||
|
||||
res.json({
|
||||
exito: true,
|
||||
mensaje: `Usuario "${nuevoNombre}" actualizado con éxito.`,
|
||||
usuario: { id: userId, username: nuevoUser, nombre: nuevoNombre, rol: nuevoRol, activo: nuevoActivo }
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Cambio directo de contraseña de cualquier usuario
|
||||
app.put('/api/developer/usuarios/:id/password', (req, res) => {
|
||||
try {
|
||||
const userId = parseInt(req.params.id, 10);
|
||||
const { password } = req.body;
|
||||
if (!password || String(password).trim().length === 0) {
|
||||
return res.status(400).json({ error: 'La nueva contraseña no puede estar vacía.' });
|
||||
}
|
||||
|
||||
const user = db.prepare('SELECT id, nombre, username FROM usuarios WHERE id = ?').get(userId);
|
||||
if (!user) return res.status(404).json({ error: 'Usuario no encontrado.' });
|
||||
|
||||
db.prepare('UPDATE usuarios SET password_hash = ? WHERE id = ?').run(String(password).trim(), userId);
|
||||
res.json({ exito: true, mensaje: `Contraseña de "${user.nombre}" cambiada correctamente.` });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Bloquear / Desbloquear usuario
|
||||
app.put('/api/developer/usuarios/:id/estado', (req, res) => {
|
||||
try {
|
||||
const userId = parseInt(req.params.id, 10);
|
||||
const { activo } = req.body;
|
||||
const nuevoEstado = activo ? 1 : 0;
|
||||
|
||||
const user = db.prepare('SELECT * FROM usuarios WHERE id = ?').get(userId);
|
||||
if (!user) return res.status(404).json({ error: 'Usuario no encontrado.' });
|
||||
|
||||
if (user.username === 'dev' && nuevoEstado === 0) {
|
||||
return res.status(400).json({ error: 'No es posible bloquear la cuenta Developer Master principal.' });
|
||||
}
|
||||
|
||||
db.prepare('UPDATE usuarios SET activo = ? WHERE id = ?').run(nuevoEstado, userId);
|
||||
res.json({
|
||||
exito: true,
|
||||
mensaje: `El usuario "${user.nombre}" ahora está ${nuevoEstado ? 'activo' : 'bloqueado'}.`,
|
||||
activo: nuevoEstado
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Eliminar usuario
|
||||
app.delete('/api/developer/usuarios/:id', (req, res) => {
|
||||
try {
|
||||
const userId = parseInt(req.params.id, 10);
|
||||
const user = db.prepare('SELECT * FROM usuarios WHERE id = ?').get(userId);
|
||||
if (!user) return res.status(404).json({ error: 'Usuario no encontrado.' });
|
||||
|
||||
if (user.username === 'dev') {
|
||||
return res.status(400).json({ error: 'No es posible eliminar la cuenta Developer Master del sistema.' });
|
||||
}
|
||||
|
||||
db.prepare('DELETE FROM usuarios WHERE id = ?').run(userId);
|
||||
res.json({ exito: true, mensaje: `Usuario "${user.nombre}" eliminado definitivamente.` });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Listar todos los diseños de tarjetas (panel developer)
|
||||
app.get('/api/developer/disenos-tarjetas', (req, res) => {
|
||||
try {
|
||||
const disenos = db.prepare('SELECT * FROM disenos_tarjetas ORDER BY id ASC').all();
|
||||
res.json(disenos);
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Subir nuevo diseño de tarjeta (soporta Base64 o URL directa)
|
||||
app.post('/api/developer/disenos-tarjetas', (req, res) => {
|
||||
try {
|
||||
const { nombre, categoria, estilo_texto, image_base64, image_url, es_predeterminado } = req.body;
|
||||
if (!nombre) {
|
||||
return res.status(400).json({ error: 'El nombre del diseño es obligatorio.' });
|
||||
}
|
||||
|
||||
let finalImageUrl = image_url;
|
||||
|
||||
// Si viene imagen en base64, guardarla en disco en public/img/cards/
|
||||
if (image_base64 && image_base64.startsWith('data:image/')) {
|
||||
const matches = image_base64.match(/^data:image\/([a-zA-Z0-9\+\-]+);base64,(.+)$/);
|
||||
if (!matches) {
|
||||
return res.status(400).json({ error: 'Formato de imagen base64 no válido.' });
|
||||
}
|
||||
|
||||
let ext = matches[1].toLowerCase();
|
||||
if (ext === 'jpeg') ext = 'jpg';
|
||||
if (ext === 'svg+xml') ext = 'svg';
|
||||
|
||||
const base64Data = matches[2];
|
||||
const buffer = Buffer.from(base64Data, 'base64');
|
||||
|
||||
const cardsDir = path.join(__dirname, '../public/img/cards');
|
||||
if (!fs.existsSync(cardsDir)) {
|
||||
fs.mkdirSync(cardsDir, { recursive: true });
|
||||
}
|
||||
|
||||
const filename = `card_custom_${Date.now()}.${ext}`;
|
||||
const filePath = path.join(cardsDir, filename);
|
||||
fs.writeFileSync(filePath, buffer);
|
||||
|
||||
finalImageUrl = `/img/cards/${filename}`;
|
||||
}
|
||||
|
||||
if (!finalImageUrl) {
|
||||
return res.status(400).json({ error: 'Debes subir una imagen o indicar una URL válida.' });
|
||||
}
|
||||
|
||||
const themeId = `card_custom_${Date.now()}`;
|
||||
const cleanCat = ['fem', 'masc', 'uni'].includes(categoria) ? categoria : 'uni';
|
||||
const cleanEstilo = estilo_texto === 'light' ? 'light' : 'dark';
|
||||
const cleanPred = es_predeterminado ? 1 : 0;
|
||||
|
||||
const result = db.prepare(`
|
||||
INSERT INTO disenos_tarjetas (theme_id, nombre, categoria, imagen_url, estilo_texto, es_predeterminado, activo)
|
||||
VALUES (?, ?, ?, ?, ?, ?, 1)
|
||||
`).run(themeId, String(nombre).trim(), cleanCat, finalImageUrl, cleanEstilo, cleanPred);
|
||||
|
||||
const nuevoDiseno = db.prepare('SELECT * FROM disenos_tarjetas WHERE id = ?').get(result.lastInsertRowid);
|
||||
broadcastEvent('disenos_actualizados', nuevoDiseno);
|
||||
|
||||
res.status(201).json({
|
||||
exito: true,
|
||||
mensaje: `¡Diseño "${nombre}" guardado y publicado con éxito para todos los estudiantes!`,
|
||||
diseno: nuevoDiseno
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Activar / Desactivar diseño de tarjeta
|
||||
app.put('/api/developer/disenos-tarjetas/:id/estado', (req, res) => {
|
||||
try {
|
||||
const id = parseInt(req.params.id, 10);
|
||||
const { activo } = req.body;
|
||||
const nuevoEstado = activo ? 1 : 0;
|
||||
|
||||
db.prepare('UPDATE disenos_tarjetas SET activo = ? WHERE id = ?').run(nuevoEstado, id);
|
||||
const diseno = db.prepare('SELECT * FROM disenos_tarjetas WHERE id = ?').get(id);
|
||||
|
||||
broadcastEvent('disenos_actualizados', diseno);
|
||||
res.json({ exito: true, diseno, activo: nuevoEstado });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Eliminar diseño de tarjeta
|
||||
app.delete('/api/developer/disenos-tarjetas/:id', (req, res) => {
|
||||
try {
|
||||
const id = parseInt(req.params.id, 10);
|
||||
const diseno = db.prepare('SELECT * FROM disenos_tarjetas WHERE id = ?').get(id);
|
||||
if (!diseno) return res.status(404).json({ error: 'Diseño no encontrado.' });
|
||||
|
||||
db.prepare('DELETE FROM disenos_tarjetas WHERE id = ?').run(id);
|
||||
broadcastEvent('disenos_actualizados', { id, eliminado: true });
|
||||
|
||||
res.json({ exito: true, mensaje: `Diseño "${diseno.nombre}" eliminado.` });
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Métricas de Diagnóstico del Sistema y Base de Datos (Developer)
|
||||
app.get('/api/developer/stats', (req, res) => {
|
||||
try {
|
||||
const totalUsuarios = db.prepare('SELECT COUNT(*) as count FROM usuarios').get().count;
|
||||
const rolesCount = db.prepare('SELECT rol, COUNT(*) as count FROM usuarios GROUP BY rol').all();
|
||||
const totalEstudiantes = db.prepare('SELECT COUNT(*) as count FROM estudiantes').get().count;
|
||||
const saldoTotal = db.prepare('SELECT COALESCE(SUM(saldo_colones), 0) as total FROM estudiantes').get().total;
|
||||
const totalProductos = db.prepare('SELECT COUNT(*) as count FROM productos WHERE disponible = 1').get().count;
|
||||
const totalOrdenes = db.prepare('SELECT COUNT(*) as count FROM ordenes').get().count;
|
||||
const totalTransacciones = db.prepare('SELECT COUNT(*) as count FROM transacciones_saldo').get().count;
|
||||
const totalDisenos = db.prepare('SELECT COUNT(*) as count FROM disenos_tarjetas WHERE activo = 1').get().count;
|
||||
|
||||
let dbSizeBytes = 0;
|
||||
try {
|
||||
const stats = fs.statSync(path.join(__dirname, 'recreopay.db'));
|
||||
dbSizeBytes = stats.size;
|
||||
} catch (e) {}
|
||||
|
||||
res.json({
|
||||
usuarios: {
|
||||
total: totalUsuarios,
|
||||
por_rol: rolesCount
|
||||
},
|
||||
estudiantes: {
|
||||
total: totalEstudiantes,
|
||||
saldo_circulante_colones: saldoTotal
|
||||
},
|
||||
negocio: {
|
||||
productos_activos: totalProductos,
|
||||
ordenes_totales: totalOrdenes,
|
||||
transacciones_totales: totalTransacciones,
|
||||
disenos_tarjetas_activas: totalDisenos
|
||||
},
|
||||
sistema: {
|
||||
node_version: process.version,
|
||||
uptime_segundos: Math.floor(process.uptime()),
|
||||
memoria_mb: (process.memoryUsage().rss / 1024 / 1024).toFixed(2),
|
||||
db_size_kb: (dbSizeBytes / 1024).toFixed(1),
|
||||
sse_clientes_conectados: sseClients.size
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Crear nuevo estudiante / usuario + carné QR (escalable a 5 dígitos y prefijos multi-negocio)
|
||||
app.post('/api/admin/estudiantes', (req, res) => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user