feat: gestion de productos, administracion de personal y botones rapidos de transferencia
This commit is contained in:
@@ -1921,3 +1921,160 @@ body.dark-mode .selected-student-banner {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
BOTONES DE MONTO RÁPIDO (TRANSFERENCIAS P2P)
|
||||
========================================================================== */
|
||||
.mode-btn,
|
||||
.transfer-amount-btn {
|
||||
padding: 10px 8px;
|
||||
background: var(--card-bg, #ffffff);
|
||||
border: 1.5px solid var(--border, #cbd5e1);
|
||||
border-radius: 12px;
|
||||
font-size: 0.92rem;
|
||||
font-weight: 800;
|
||||
color: var(--text-main, #1e293b);
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.18s ease;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.mode-btn:hover,
|
||||
.transfer-amount-btn:hover {
|
||||
border-color: #0284c7;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.mode-btn.active,
|
||||
.transfer-amount-btn.active {
|
||||
background: linear-gradient(135deg, #0284c7, #0369a1) !important;
|
||||
color: #ffffff !important;
|
||||
border-color: #0284c7 !important;
|
||||
box-shadow: 0 4px 12px rgba(2, 132, 199, 0.35) !important;
|
||||
transform: scale(1.03);
|
||||
}
|
||||
|
||||
body.dark-mode .mode-btn,
|
||||
body.dark-mode .transfer-amount-btn {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
color: #f1f5f9;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
GESTIÓN DE PERSONAL (TARJETAS DE EMPLEADOS)
|
||||
========================================================================== */
|
||||
.admin-staff-card {
|
||||
background: var(--card-bg, #ffffff);
|
||||
border: 1px solid var(--border, #e2e8f0);
|
||||
border-radius: 14px;
|
||||
padding: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
transition: all 0.2s ease;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.04);
|
||||
}
|
||||
|
||||
.admin-staff-card:hover {
|
||||
border-color: #cbd5e1;
|
||||
box-shadow: 0 3px 8px rgba(0,0,0,0.06);
|
||||
}
|
||||
|
||||
.admin-staff-card.blocked {
|
||||
background: #fef2f2;
|
||||
border-color: #fca5a5;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
body.dark-mode .admin-staff-card.blocked {
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border-color: rgba(239, 68, 68, 0.3);
|
||||
}
|
||||
|
||||
.staff-role-badge {
|
||||
font-size: 0.72rem;
|
||||
font-weight: 800;
|
||||
padding: 2px 8px;
|
||||
border-radius: 6px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.staff-role-admin { background: #fef3c7; color: #b45309; }
|
||||
.staff-role-cajero { background: #e0f2fe; color: #0369a1; }
|
||||
.staff-role-vendedor { background: #dcfce7; color: #15803d; }
|
||||
|
||||
.staff-status-badge {
|
||||
font-size: 0.72rem;
|
||||
font-weight: 800;
|
||||
padding: 2px 8px;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.staff-status-active { background: #dcfce7; color: #166534; }
|
||||
.staff-status-blocked { background: #fee2e2; color: #991b1b; }
|
||||
|
||||
/* Botones de acción de inventario y personal */
|
||||
.btn-action-edit {
|
||||
padding: 6px 12px;
|
||||
background: #f1f5f9;
|
||||
color: #334155;
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: 8px;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.btn-action-edit:hover {
|
||||
background: #e2e8f0;
|
||||
color: #0f172a;
|
||||
}
|
||||
|
||||
.btn-action-block {
|
||||
padding: 6px 10px;
|
||||
background: #fff7ed;
|
||||
color: #c2410c;
|
||||
border: 1px solid #fed7aa;
|
||||
border-radius: 8px;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.btn-action-block:hover {
|
||||
background: #ffedd5;
|
||||
}
|
||||
|
||||
.btn-action-delete {
|
||||
padding: 6px 10px;
|
||||
background: #fef2f2;
|
||||
color: #dc2626;
|
||||
border: 1px solid #fecaca;
|
||||
border-radius: 8px;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.btn-action-delete:hover {
|
||||
background: #fee2e2;
|
||||
}
|
||||
|
||||
|
||||
+200
-12
@@ -10,7 +10,7 @@
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<meta name="apple-mobile-web-app-title" content="RecreoPay">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<link rel="stylesheet" href="/css/styles.css?v=9.4">
|
||||
<link rel="stylesheet" href="/css/styles.css?v=9.5">
|
||||
<style>
|
||||
/* Transiciones suaves */
|
||||
.fade-enter { animation: fadeIn 0.2s ease-in-out; }
|
||||
@@ -175,6 +175,9 @@
|
||||
<button class="admin-tab-btn" id="btnTabAdminEstudiantes" onclick="switchAdminTab('estudiantes')">
|
||||
🪪 Estudiantes, Carnés y Bloqueos
|
||||
</button>
|
||||
<button class="admin-tab-btn" id="btnTabAdminPersonal" onclick="switchAdminTab('personal')">
|
||||
👥 Personal y Cajeros
|
||||
</button>
|
||||
<button class="admin-tab-btn" id="btnTabAdminRecarga" onclick="switchAdminTab('recarga')">
|
||||
💵 Cargar Dinero Manual (Buscador y QR)
|
||||
</button>
|
||||
@@ -189,10 +192,15 @@
|
||||
<div>
|
||||
<h3 style="margin: 0; font-size: 1.1rem; font-weight: 800; color: var(--text-main);">Inventario y Existencias</h3>
|
||||
<p style="margin: 2px 0 0 0; font-size: 0.75rem; color: var(--text-muted);">
|
||||
Cuando el stock llega a 0, el producto se marca automáticamente como <strong>AGOTADO (greyed out)</strong>.
|
||||
Crea, edita productos, controla precios, existencias y sellos nutricionales MEP.
|
||||
</p>
|
||||
</div>
|
||||
<input type="text" id="adminSearchProduct" placeholder="🔍 Buscar alimento o bebida..." oninput="filterAdminProducts(this.value)" style="padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--border); font-size: 0.85rem; width: 220px;">
|
||||
<div style="display: flex; gap: 8px; align-items: center; flex-wrap: wrap;">
|
||||
<input type="text" id="adminSearchProduct" placeholder="🔍 Buscar alimento o bebida..." oninput="filterAdminProducts(this.value)" style="padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--border); font-size: 0.85rem; width: 190px; background: var(--card-bg); color: var(--text-main);">
|
||||
<button type="button" onclick="openCreateProductModal()" style="padding: 8px 14px; background: linear-gradient(135deg, #0284c7, #0369a1); color: white; border: none; border-radius: 10px; font-size: 0.82rem; font-weight: 800; cursor: pointer; display: flex; align-items: center; gap: 6px; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.25);">
|
||||
<span>➕</span> <span>Nuevo Producto</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="adminProductsList">
|
||||
@@ -367,6 +375,29 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- TAB 5: GESTIÓN DE PERSONAL Y CAJEROS -->
|
||||
<div id="adminTabContentPersonal" class="admin-card" style="display: none; max-width: 900px; margin: 0 auto;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
|
||||
<div>
|
||||
<h3 style="margin: 0; font-size: 1.2rem; font-weight: 900; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
|
||||
<span>👥</span> Control de Personal y Cajeros
|
||||
</h3>
|
||||
<p style="margin: 3px 0 0 0; font-size: 0.78rem; color: var(--text-muted);">
|
||||
Crea cajeros, vendedores y personal. Administra contraseñas, bloquea o elimina accesos.
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" onclick="openCreateStaffModal()" style="padding: 9px 16px; background: linear-gradient(135deg, #10b981, #059669); color: white; border: none; border-radius: 10px; font-size: 0.84rem; font-weight: 800; cursor: pointer; display: flex; align-items: center; gap: 6px; box-shadow: 0 2px 6px rgba(16, 185, 129, 0.25);">
|
||||
<span>➕</span> <span>Nuevo Empleado / Cajero</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="adminStaffList" style="display: flex; flex-direction: column; gap: 10px;">
|
||||
<div style="text-align: center; color: var(--text-muted); padding: 30px; font-size: 0.88rem;">
|
||||
Cargando personal...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ========================================== -->
|
||||
@@ -956,6 +987,163 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL: CREAR / EDITAR PRODUCTO (ADMIN) -->
|
||||
<div class="modal-qr-backdrop" id="modalAdminProduct" style="display: none;" onclick="closeAdminProductModal(event)">
|
||||
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 480px; text-align: left; max-height: 90vh; overflow-y: auto;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 14px;">
|
||||
<div>
|
||||
<h3 id="modalProductTitle" style="color: var(--text-main); font-size: 1.15rem; font-weight: 800; margin: 0;">➕ Crear Nuevo Producto</h3>
|
||||
<span style="font-size: 0.75rem; color: var(--text-muted);">Alimentos, bebidas y meriendas escolares</span>
|
||||
</div>
|
||||
<button type="button" onclick="closeAdminProductModal()" style="background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
|
||||
</div>
|
||||
|
||||
<form id="formAdminProduct" onsubmit="submitAdminProduct(event)">
|
||||
<input type="hidden" id="adminProdId" value="">
|
||||
|
||||
<div style="margin-bottom: 10px;">
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Nombre del Alimento / Bebida *:</label>
|
||||
<input type="text" id="adminProdNombre" placeholder="Ej: Empanada de Pollo, Fresco Natural..." required style="width: 100%; padding: 9px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||
</div>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px;">
|
||||
<div>
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Categoría *:</label>
|
||||
<select id="adminProdCategoria" required style="width: 100%; padding: 9px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||
<!-- Opciones dinámicas de categorías -->
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Precio en Colones (₡) *:</label>
|
||||
<input type="number" id="adminProdPrecio" placeholder="Ej: 1200" min="50" step="50" required style="width: 100%; padding: 9px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 800; color: #0284c7; box-sizing: border-box; background: var(--card-bg);">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 80px 1fr; gap: 10px; margin-bottom: 10px;">
|
||||
<div>
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Ícono:</label>
|
||||
<input type="text" id="adminProdIcono" value="🥪" maxlength="4" style="width: 100%; text-align: center; font-size: 1.5rem; padding: 4px; border-radius: 8px; border: 1.5px solid var(--border); box-sizing: border-box; background: var(--card-bg);">
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Íconos Rápidos:</label>
|
||||
<div style="display: flex; gap: 4px; flex-wrap: wrap;">
|
||||
<button type="button" onclick="selectProdIcon('🥪')" style="padding: 4px 6px; font-size: 1.1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); cursor: pointer;">🥪</button>
|
||||
<button type="button" onclick="selectProdIcon('🍎')" style="padding: 4px 6px; font-size: 1.1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); cursor: pointer;">🍎</button>
|
||||
<button type="button" onclick="selectProdIcon('🧃')" style="padding: 4px 6px; font-size: 1.1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); cursor: pointer;">🧃</button>
|
||||
<button type="button" onclick="selectProdIcon('🍕')" style="padding: 4px 6px; font-size: 1.1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); cursor: pointer;">🍕</button>
|
||||
<button type="button" onclick="selectProdIcon('🥗')" style="padding: 4px 6px; font-size: 1.1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); cursor: pointer;">🥗</button>
|
||||
<button type="button" onclick="selectProdIcon('🥛')" style="padding: 4px 6px; font-size: 1.1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); cursor: pointer;">🥛</button>
|
||||
<button type="button" onclick="selectProdIcon('🍪')" style="padding: 4px 6px; font-size: 1.1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); cursor: pointer;">🍪</button>
|
||||
<button type="button" onclick="selectProdIcon('🌮')" style="padding: 4px 6px; font-size: 1.1rem; border: 1px solid var(--border); border-radius: 6px; background: var(--card-bg); cursor: pointer;">🌮</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="margin-bottom: 10px;">
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Descripción (opcional):</label>
|
||||
<input type="text" id="adminProdDescripcion" placeholder="Ej: Rellena de pollo mechado, horneada al día" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 0.85rem; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||
</div>
|
||||
|
||||
<div style="background: var(--bg-main, #f8fafc); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 10px; margin-bottom: 12px;">
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center;">
|
||||
<div>
|
||||
<label style="display: flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 800; cursor: pointer; color: var(--text-main);">
|
||||
<input type="checkbox" id="adminProdControlStock" checked onchange="toggleStockInput(this.checked)">
|
||||
<span>Controlar Existencias</span>
|
||||
</label>
|
||||
<div style="margin-top: 6px;" id="boxProdStockCount">
|
||||
<label style="display: block; font-size: 0.72rem; color: var(--text-muted); font-weight: 700;">Stock Actual:</label>
|
||||
<input type="number" id="adminProdStock" value="10" min="0" style="width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); font-weight: 800; background: var(--card-bg); color: var(--text-main); box-sizing: border-box;">
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; font-size: 0.75rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px;">Sello Nutricional MEP:</label>
|
||||
<select id="adminProdMep" style="width: 100%; padding: 7px; border-radius: 6px; border: 1px solid var(--border); font-weight: 700; font-size: 0.8rem; background: var(--card-bg); color: var(--text-main); box-sizing: border-box;">
|
||||
<option value="1">🟢 Saludable MEP (Permitido)</option>
|
||||
<option value="0">🟠 Consumo Ocasional</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px;">
|
||||
<button type="button" id="btnDeleteProduct" onclick="handleDeleteProduct()" style="display: none; padding: 10px 14px; background: #fee2e2; color: #dc2626; border: 1px solid #fecaca; border-radius: 10px; font-weight: 800; font-size: 0.84rem; cursor: pointer;">
|
||||
🗑️ Eliminar
|
||||
</button>
|
||||
<button type="button" onclick="closeAdminProductModal()" style="padding: 10px 14px; background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; border-radius: 10px; font-weight: 800; font-size: 0.84rem; cursor: pointer;">
|
||||
Cancelar
|
||||
</button>
|
||||
<button type="submit" id="btnSaveProductSubmit" style="padding: 10px 18px; background: linear-gradient(135deg, #0284c7, #0369a1); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.88rem; cursor: pointer; display: flex; align-items: center; gap: 6px; box-shadow: 0 2px 6px rgba(2, 132, 199, 0.3);">
|
||||
<span>💾</span> <span>Guardar Producto</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL: CREAR / EDITAR EMPLEADO O CAJERO (ADMIN) -->
|
||||
<div class="modal-qr-backdrop" id="modalAdminStaff" style="display: none;" onclick="closeAdminStaffModal(event)">
|
||||
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 460px; text-align: left;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 14px;">
|
||||
<div>
|
||||
<h3 id="modalStaffTitle" style="color: var(--text-main); font-size: 1.15rem; font-weight: 800; margin: 0;">👥 Nuevo Empleado / Cajero</h3>
|
||||
<span style="font-size: 0.75rem; color: var(--text-muted);">Crea credenciales de acceso para la soda</span>
|
||||
</div>
|
||||
<button type="button" onclick="closeAdminStaffModal()" style="background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
|
||||
</div>
|
||||
|
||||
<form id="formAdminStaff" onsubmit="submitAdminStaff(event)">
|
||||
<input type="hidden" id="adminStaffId" value="">
|
||||
|
||||
<div style="margin-bottom: 10px;">
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Nombre Completo *:</label>
|
||||
<input type="text" id="adminStaffNombre" placeholder="Ej: Carlos Murillo Vega" required style="width: 100%; padding: 9px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||
</div>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px;">
|
||||
<div>
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Usuario de Acceso *:</label>
|
||||
<input type="text" id="adminStaffUsername" placeholder="cajero1" required style="width: 100%; padding: 9px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;">Rol en el Sistema *:</label>
|
||||
<select id="adminStaffRol" required style="width: 100%; padding: 9px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 800; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||
<option value="cajero">📟 Cajero (Terminal POS)</option>
|
||||
<option value="vendedor">🥪 Vendedor / Despacho</option>
|
||||
<option value="admin">👨🍳 Administrador</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="margin-bottom: 10px;">
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 3px;" id="lblStaffPassword">Contraseña de Acceso *:</label>
|
||||
<input type="password" id="adminStaffPassword" placeholder="••••••••" style="width: 100%; padding: 9px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-weight: 700; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||
<small id="hintStaffPassword" style="display: none; font-size: 0.7rem; color: var(--text-muted); margin-top: 3px;">Deja en blanco para conservar la contraseña actual.</small>
|
||||
</div>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px;">
|
||||
<div>
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-main); margin-bottom: 3px;">Teléfono:</label>
|
||||
<input type="text" id="adminStaffTel" placeholder="+506 8888-0000" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||
</div>
|
||||
<div>
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-main); margin-bottom: 3px;">Email (opcional):</label>
|
||||
<input type="email" id="adminStaffEmail" placeholder="[email protected]" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px;">
|
||||
<button type="button" onclick="closeAdminStaffModal()" style="padding: 10px 14px; background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; border-radius: 10px; font-weight: 800; font-size: 0.84rem; cursor: pointer;">
|
||||
Cancelar
|
||||
</button>
|
||||
<button type="submit" id="btnSaveStaffSubmit" style="padding: 10px 18px; background: linear-gradient(135deg, #10b981, #059669); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.88rem; cursor: pointer; display: flex; align-items: center; gap: 6px; box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);">
|
||||
<span>💾</span> <span>Guardar Empleado</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL: RECREOTRANSFER (PASAR PLATA A UN COMPAÑERO ESCANEANDO SU QR O CARNÉ) -->
|
||||
<div class="modal-qr-backdrop" id="modalTransfer" style="display: none;" onclick="closeTransferModal(event)">
|
||||
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 420px; text-align: left;">
|
||||
@@ -1025,20 +1213,20 @@
|
||||
<label style="display: block; font-size: 0.82rem; font-weight: 800; color: #1e293b; margin-bottom: 6px;">
|
||||
¿Cuánto le vas a pasar?
|
||||
</label>
|
||||
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 10px;">
|
||||
<button type="button" class="mode-btn active" id="btnTransfer500" onclick="setTransferAmount(500, this)" style="padding: 8px; text-align: center; justify-content: center; font-size: 0.85rem;">₡500</button>
|
||||
<button type="button" class="mode-btn" id="btnTransfer1000" onclick="setTransferAmount(1000, this)" style="padding: 8px; text-align: center; justify-content: center; font-size: 0.85rem;">₡1.000</button>
|
||||
<button type="button" class="mode-btn" id="btnTransfer1500" onclick="setTransferAmount(1500, this)" style="padding: 8px; text-align: center; justify-content: center; font-size: 0.85rem;">₡1.500</button>
|
||||
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px;">
|
||||
<button type="button" class="transfer-amount-btn active" id="btnTransfer500" onclick="setTransferAmount(500, this)">₡500</button>
|
||||
<button type="button" class="transfer-amount-btn" id="btnTransfer1000" onclick="setTransferAmount(1000, this)">₡1.000</button>
|
||||
<button type="button" class="transfer-amount-btn" id="btnTransfer1500" onclick="setTransferAmount(1500, this)">₡1.500</button>
|
||||
</div>
|
||||
|
||||
<div style="margin-bottom: 12px;">
|
||||
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputTransferCustomAmount" placeholder="Otro monto (ej. 750)" style="width: 100%; padding: 10px; border-radius: 10px; border: 1px solid #cbd5e1; font-size: 1rem; font-weight: 800; color: #0284c7;">
|
||||
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputTransferCustomAmount" value="500" placeholder="Otro monto (ej. 750)" style="width: 100%; padding: 10px; border-radius: 10px; border: 1.5px solid #cbd5e1; font-size: 1.05rem; font-weight: 800; color: #0284c7; box-sizing: border-box; text-align: center;">
|
||||
</div>
|
||||
|
||||
<!-- MOTIVO OPCIONAL -->
|
||||
<div style="margin-bottom: 12px;">
|
||||
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #64748b; margin-bottom: 4px;">Motivo (Opcional):</label>
|
||||
<input type="text" id="inputTransferMotivo" placeholder="Ej: Mitad de la empanada, fresco..." style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid #cbd5e1; font-size: 0.85rem;">
|
||||
<input type="text" id="inputTransferMotivo" placeholder="Ej: Mitad de la empanada, fresco..." style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid #cbd5e1; font-size: 0.85rem; box-sizing: border-box;">
|
||||
</div>
|
||||
|
||||
<!-- PIN DE SEGURIDAD (TECLADO NATIVO DEL TELÉFONO) -->
|
||||
@@ -1056,7 +1244,7 @@
|
||||
</div>
|
||||
|
||||
<button id="btnConfirmTransfer" onclick="executeP2PTransfer()" style="width: 100%; padding: 14px; background: linear-gradient(135deg, #10b981, #059669); color: white; border: none; border-radius: 14px; font-weight: 900; font-size: 1.05rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);">
|
||||
<span>💸</span> Enviar Dinero al Instante
|
||||
<span>💸</span> <span id="lblBtnConfirmTransferText">Enviar ₡500 al Instante</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1228,8 +1416,8 @@
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<script src="/js/sounds.js?v=9.4"></script>
|
||||
<script src="/js/sounds.js?v=9.5"></script>
|
||||
<script src="/js/jsQR.js"></script>
|
||||
<script src="/js/app.js?v=9.4"></script>
|
||||
<script src="/js/app.js?v=9.5"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+521
-14
@@ -11,6 +11,7 @@ let currentAppMode = 'teens';
|
||||
let adminProducts = [];
|
||||
let adminStats = null;
|
||||
let adminSearchQuery = '';
|
||||
let adminStaffList = [];
|
||||
|
||||
let CLOUDFLARE_TUNNEL_URL = 'https://recreopay.gammapos.app';
|
||||
|
||||
@@ -89,6 +90,23 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const customAmountEl = document.getElementById('inputTransferCustomAmount');
|
||||
if (customAmountEl) {
|
||||
customAmountEl.addEventListener('input', (e) => {
|
||||
const val = parseInt(e.target.value, 10);
|
||||
document.querySelectorAll('#transferStepConfirm .transfer-amount-btn, #transferStepConfirm .mode-btn').forEach(b => b.classList.remove('active'));
|
||||
if (val && val > 0) {
|
||||
currentTransferAmount = val;
|
||||
updateTransferConfirmButton(val);
|
||||
const match = document.getElementById(`btnTransfer${val}`);
|
||||
if (match) match.classList.add('active');
|
||||
} else {
|
||||
currentTransferAmount = 0;
|
||||
updateTransferConfirmButton(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// ==========================================
|
||||
@@ -259,16 +277,22 @@ async function applyUserRoleSession() {
|
||||
|
||||
if (viewLogin) viewLogin.style.display = 'none';
|
||||
|
||||
if (currentUser.rol === 'admin' || currentUser.rol === 'cajero') {
|
||||
if (currentUser.rol === 'admin' || currentUser.rol === 'cajero' || currentUser.rol === 'vendedor') {
|
||||
if (viewAdmin) viewAdmin.style.display = 'block';
|
||||
if (viewPadres) viewPadres.style.display = 'none';
|
||||
if (appContainer) appContainer.style.display = 'none';
|
||||
if (bottomNav) bottomNav.style.display = 'none';
|
||||
const adminNameEl = document.getElementById('adminLoggedName');
|
||||
if (adminNameEl) {
|
||||
const badgeRol = currentUser.rol === 'cajero' ? 'Cajero Soda' : 'Administrador';
|
||||
let badgeRol = 'Administrador';
|
||||
if (currentUser.rol === 'cajero') badgeRol = 'Cajero Soda';
|
||||
if (currentUser.rol === 'vendedor') badgeRol = 'Vendedor / Despacho';
|
||||
adminNameEl.textContent = `${currentUser.nombre} (${badgeRol})`;
|
||||
}
|
||||
const btnTabStaff = document.getElementById('btnTabAdminPersonal');
|
||||
if (btnTabStaff) {
|
||||
btnTabStaff.style.display = (currentUser.rol === 'admin') ? 'inline-block' : 'none';
|
||||
}
|
||||
await loadAdminData();
|
||||
setupAdminSmartSearch();
|
||||
} else if (currentUser.rol === 'padre') {
|
||||
@@ -1049,12 +1073,21 @@ function resetTransferScan() {
|
||||
|
||||
function setTransferAmount(val, btn) {
|
||||
currentTransferAmount = val;
|
||||
document.querySelectorAll('#transferStepConfirm .mode-btn').forEach(b => b.classList.remove('active'));
|
||||
document.querySelectorAll('#transferStepConfirm .transfer-amount-btn, #transferStepConfirm .mode-btn').forEach(b => b.classList.remove('active'));
|
||||
if (btn) btn.classList.add('active');
|
||||
document.getElementById('inputTransferCustomAmount').value = '';
|
||||
const customInput = document.getElementById('inputTransferCustomAmount');
|
||||
if (customInput) customInput.value = val;
|
||||
updateTransferConfirmButton(val);
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
}
|
||||
|
||||
function updateTransferConfirmButton(monto) {
|
||||
const lbl = document.getElementById('lblBtnConfirmTransferText');
|
||||
if (lbl) {
|
||||
lbl.textContent = `Enviar ₡${(monto || 0).toLocaleString('es-CR')} al Instante`;
|
||||
}
|
||||
}
|
||||
|
||||
// Control del Teclado Numérico Táctil del PIN
|
||||
function appendPinDigit(digit) {
|
||||
const pinInput = document.getElementById('inputTransferPin');
|
||||
@@ -2407,7 +2440,7 @@ async function confirmLinkValidatedChild() {
|
||||
// ==========================================
|
||||
|
||||
function switchAdminTab(tabName) {
|
||||
const tabs = ['inventario', 'estudiantes', 'recarga', 'movimientos'];
|
||||
const tabs = ['inventario', 'estudiantes', 'recarga', 'movimientos', 'personal'];
|
||||
tabs.forEach(t => {
|
||||
const btn = document.getElementById(`btnTabAdmin${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
||||
const content = document.getElementById(`adminTabContent${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
||||
@@ -2417,6 +2450,8 @@ function switchAdminTab(tabName) {
|
||||
|
||||
if (tabName === 'movimientos') {
|
||||
loadAdminMovimientos();
|
||||
} else if (tabName === 'personal') {
|
||||
loadAdminStaff();
|
||||
} else if (tabName === 'recarga') {
|
||||
if (!adminSelectedStudent) {
|
||||
clearAdminSelectedStudent();
|
||||
@@ -2448,6 +2483,15 @@ async function loadAdminData() {
|
||||
students = await resEst.json();
|
||||
renderAdminStudents(students);
|
||||
populateAdminRecargaStudents(students);
|
||||
|
||||
// 4. Si las categorías están vacías, cargarlas para los modales
|
||||
if (!categories || categories.length === 0) {
|
||||
const resCat = await fetch('/api/productos');
|
||||
const dataCat = await resCat.json();
|
||||
if (dataCat && dataCat.categorias) {
|
||||
categories = dataCat.categorias;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error cargando datos de administración:', err);
|
||||
}
|
||||
@@ -2492,17 +2536,26 @@ function renderAdminInventory(list) {
|
||||
|
||||
return `
|
||||
<div class="inventory-item-row" style="${isOutOfStock ? 'background: #fff1f2;' : ''}">
|
||||
<div class="inventory-item-top">
|
||||
<div style="font-size: 1.8rem; text-align: center; flex-shrink: 0; min-width: 40px;">${p.icono || '🥪'}</div>
|
||||
<div style="flex: 1; min-width: 0;">
|
||||
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;">
|
||||
<strong style="font-size: 0.92rem; color: var(--text-main); word-break: break-word;">${p.nombre}</strong>
|
||||
${statusPill}
|
||||
</div>
|
||||
<div style="font-size: 0.74rem; color: var(--text-muted); margin-top: 2px;">
|
||||
${p.categoria_nombre || 'General'} • ₡${p.precio_colones.toLocaleString('es-CR')}
|
||||
<div class="inventory-item-top" style="display: flex; align-items: center; justify-content: space-between; gap: 10px;">
|
||||
<div style="display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;">
|
||||
<div style="font-size: 1.8rem; text-align: center; flex-shrink: 0; min-width: 40px;">${p.icono || '🥪'}</div>
|
||||
<div style="flex: 1; min-width: 0;">
|
||||
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;">
|
||||
<strong style="font-size: 0.92rem; color: var(--text-main); word-break: break-word;">${p.nombre}</strong>
|
||||
${statusPill}
|
||||
${p.cumple_mep === 1 ? '<span style="font-size: 0.68rem; font-weight: 800; background: #dcfce7; color: #15803d; padding: 2px 6px; border-radius: 5px;">🟢 MEP</span>' : '<span style="font-size: 0.68rem; font-weight: 800; background: #fef3c7; color: #b45309; padding: 2px 6px; border-radius: 5px;">🟠 Ocasional</span>'}
|
||||
</div>
|
||||
<div style="font-size: 0.74rem; color: var(--text-muted); margin-top: 2px;">
|
||||
${p.categoria_nombre || 'General'} • ₡${p.precio_colones.toLocaleString('es-CR')}
|
||||
${p.descripcion ? ` • <span style="font-style: italic;">${p.descripcion}</span>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style="flex-shrink: 0;">
|
||||
<button type="button" class="btn-action-edit" onclick="openEditProductModal(${p.id})" title="Editar este producto">
|
||||
<span>✏️</span> <span>Editar</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Controles rápidos de stock -->
|
||||
@@ -3614,3 +3667,457 @@ async function revertirMovimientoAdmin(transaccionId, monto, nombreEstudiante, t
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// GESTIÓN DE PRODUCTOS (ADMIN)
|
||||
// ==========================================
|
||||
|
||||
async function populateCategorySelect(selectedId) {
|
||||
const select = document.getElementById('adminProdCategoria');
|
||||
if (!select) return;
|
||||
|
||||
if (!categories || categories.length === 0) {
|
||||
try {
|
||||
const res = await fetch('/api/productos');
|
||||
const data = await res.json();
|
||||
if (data && data.categorias) categories = data.categorias;
|
||||
} catch (e) {
|
||||
console.warn('Error al cargar categorías:', e);
|
||||
}
|
||||
}
|
||||
|
||||
select.innerHTML = (categories || []).map(c => `
|
||||
<option value="${c.id}" ${selectedId && Number(selectedId) === Number(c.id) ? 'selected' : ''}>
|
||||
${c.icono || '🏷️'} ${c.nombre}
|
||||
</option>
|
||||
`).join('');
|
||||
}
|
||||
|
||||
function selectProdIcon(emoji) {
|
||||
const input = document.getElementById('adminProdIcono');
|
||||
if (input) input.value = emoji;
|
||||
}
|
||||
|
||||
function toggleStockInput(checked) {
|
||||
const box = document.getElementById('boxProdStockCount');
|
||||
if (box) box.style.display = checked ? 'block' : 'none';
|
||||
}
|
||||
|
||||
function openCreateProductModal() {
|
||||
const modal = document.getElementById('modalAdminProduct');
|
||||
if (!modal) return;
|
||||
|
||||
document.getElementById('modalProductTitle').textContent = '➕ Crear Nuevo Producto';
|
||||
document.getElementById('adminProdId').value = '';
|
||||
document.getElementById('adminProdNombre').value = '';
|
||||
document.getElementById('adminProdPrecio').value = '';
|
||||
document.getElementById('adminProdIcono').value = '🥪';
|
||||
document.getElementById('adminProdDescripcion').value = '';
|
||||
document.getElementById('adminProdControlStock').checked = true;
|
||||
toggleStockInput(true);
|
||||
document.getElementById('adminProdStock').value = '15';
|
||||
document.getElementById('adminProdMep').value = '1';
|
||||
|
||||
const btnDel = document.getElementById('btnDeleteProduct');
|
||||
if (btnDel) btnDel.style.display = 'none';
|
||||
|
||||
const btnSubmit = document.getElementById('btnSaveProductSubmit');
|
||||
if (btnSubmit) btnSubmit.innerHTML = '<span>💾</span> <span>Guardar Producto</span>';
|
||||
|
||||
populateCategorySelect();
|
||||
modal.style.display = 'flex';
|
||||
if (window.sounds) window.sounds.playTap();
|
||||
}
|
||||
|
||||
function openEditProductModal(prodId) {
|
||||
const modal = document.getElementById('modalAdminProduct');
|
||||
if (!modal) return;
|
||||
|
||||
const prod = (adminProducts || []).find(p => p.id === prodId) || (products || []).find(p => p.id === prodId);
|
||||
if (!prod) {
|
||||
alert('No se encontró la información del producto.');
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('modalProductTitle').textContent = '✏️ Editar Producto';
|
||||
document.getElementById('adminProdId').value = prod.id;
|
||||
document.getElementById('adminProdNombre').value = prod.nombre || '';
|
||||
document.getElementById('adminProdPrecio').value = prod.precio_colones || 0;
|
||||
document.getElementById('adminProdIcono').value = prod.icono || '🥪';
|
||||
document.getElementById('adminProdDescripcion').value = prod.descripcion || '';
|
||||
|
||||
const hasControl = prod.control_stock === 1;
|
||||
document.getElementById('adminProdControlStock').checked = hasControl;
|
||||
toggleStockInput(hasControl);
|
||||
document.getElementById('adminProdStock').value = prod.stock !== undefined ? prod.stock : 0;
|
||||
document.getElementById('adminProdMep').value = (prod.cumple_mep !== undefined ? prod.cumple_mep : 1);
|
||||
|
||||
const btnDel = document.getElementById('btnDeleteProduct');
|
||||
if (btnDel) btnDel.style.display = 'inline-block';
|
||||
|
||||
const btnSubmit = document.getElementById('btnSaveProductSubmit');
|
||||
if (btnSubmit) btnSubmit.innerHTML = '<span>💾</span> <span>Actualizar Producto</span>';
|
||||
|
||||
populateCategorySelect(prod.categoria_id);
|
||||
modal.style.display = 'flex';
|
||||
if (window.sounds) window.sounds.playTap();
|
||||
}
|
||||
|
||||
function closeAdminProductModal(event) {
|
||||
if (event && event.target !== event.currentTarget) return;
|
||||
const modal = document.getElementById('modalAdminProduct');
|
||||
if (modal) modal.style.display = 'none';
|
||||
}
|
||||
|
||||
async function submitAdminProduct(e) {
|
||||
if (e) e.preventDefault();
|
||||
|
||||
const idVal = document.getElementById('adminProdId').value;
|
||||
const nombre = document.getElementById('adminProdNombre').value.trim();
|
||||
const categoria_id = parseInt(document.getElementById('adminProdCategoria').value, 10);
|
||||
const precio_colones = parseInt(document.getElementById('adminProdPrecio').value, 10);
|
||||
const icono = document.getElementById('adminProdIcono').value.trim() || '🥪';
|
||||
const descripcion = document.getElementById('adminProdDescripcion').value.trim();
|
||||
const control_stock = document.getElementById('adminProdControlStock').checked ? 1 : 0;
|
||||
const stock = parseInt(document.getElementById('adminProdStock').value, 10) || 0;
|
||||
const cumple_mep = parseInt(document.getElementById('adminProdMep').value, 10);
|
||||
|
||||
if (!nombre || isNaN(precio_colones) || precio_colones <= 0 || isNaN(categoria_id)) {
|
||||
alert('Por favor ingresa un nombre y precio válidos.');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
nombre,
|
||||
categoria_id,
|
||||
precio_colones,
|
||||
icono,
|
||||
descripcion,
|
||||
control_stock,
|
||||
stock,
|
||||
cumple_mep
|
||||
};
|
||||
|
||||
const isEdit = !!idVal;
|
||||
const url = isEdit ? `/api/admin/productos/${idVal}` : '/api/admin/productos';
|
||||
const method = isEdit ? 'PUT' : 'POST';
|
||||
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Error al guardar producto');
|
||||
|
||||
if (window.sounds) window.sounds.playSuccess();
|
||||
closeAdminProductModal();
|
||||
await loadAdminData();
|
||||
|
||||
if (typeof loadInitialData === 'function') {
|
||||
loadInitialData();
|
||||
}
|
||||
alert(isEdit ? '✅ Producto actualizado correctamente.' : '✅ Producto creado exitosamente.');
|
||||
} catch (err) {
|
||||
if (window.sounds) window.sounds.playError();
|
||||
alert(`Error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDeleteProduct() {
|
||||
const idVal = document.getElementById('adminProdId').value;
|
||||
if (!idVal) return;
|
||||
|
||||
const prodNombre = document.getElementById('adminProdNombre').value.trim();
|
||||
const conf = confirm(`¿Estás seguro de eliminar o desactivar "${prodNombre}"?\n\nSi tiene ventas históricas asociadas se desactivará para proteger el reporte contable. Si es nuevo, se eliminará permanentemente.`);
|
||||
if (!conf) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/admin/productos/${idVal}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Error al eliminar producto');
|
||||
|
||||
if (window.sounds) window.sounds.playSuccess();
|
||||
closeAdminProductModal();
|
||||
await loadAdminData();
|
||||
if (typeof loadInitialData === 'function') {
|
||||
loadInitialData();
|
||||
}
|
||||
alert(data.mensaje || '✅ Producto procesado correctamente.');
|
||||
} catch (err) {
|
||||
if (window.sounds) window.sounds.playError();
|
||||
alert(`Error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// GESTIÓN DE PERSONAL Y CAJEROS (ADMIN)
|
||||
// ==========================================
|
||||
|
||||
async function loadAdminStaff() {
|
||||
const container = document.getElementById('adminStaffList');
|
||||
if (!container) return;
|
||||
|
||||
try {
|
||||
container.innerHTML = `
|
||||
<div style="text-align: center; color: var(--text-muted); padding: 24px; font-size: 0.88rem;">
|
||||
Cargando personal de la soda...
|
||||
</div>
|
||||
`;
|
||||
|
||||
const res = await fetch('/api/admin/personal');
|
||||
if (!res.ok) throw new Error('Error al cargar la lista de personal');
|
||||
adminStaffList = await res.json();
|
||||
renderAdminStaff(adminStaffList);
|
||||
} catch (err) {
|
||||
console.error('Error cargando personal:', err);
|
||||
container.innerHTML = `
|
||||
<div style="text-align: center; color: #dc2626; padding: 20px;">
|
||||
Error al cargar personal: ${err.message}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
function renderAdminStaff(list) {
|
||||
const container = document.getElementById('adminStaffList');
|
||||
if (!container) return;
|
||||
|
||||
if (!list || list.length === 0) {
|
||||
container.innerHTML = `
|
||||
<div style="text-align: center; padding: 24px; color: var(--text-muted);">
|
||||
No hay personal registrado en el sistema.
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = list.map(s => {
|
||||
const isRootAdmin = (s.id === 1);
|
||||
const isBlocked = (s.activo === 0);
|
||||
const roleIcon = s.rol === 'admin' ? '👨🍳' : (s.rol === 'cajero' ? '📟' : '🥪');
|
||||
const roleLabel = s.rol === 'admin' ? 'Administrador' : (s.rol === 'cajero' ? 'Cajero POS' : 'Vendedor Despacho');
|
||||
|
||||
return `
|
||||
<div class="admin-staff-card ${isBlocked ? 'blocked' : ''}">
|
||||
<div style="display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1;">
|
||||
<div style="font-size: 2rem; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: var(--bg-main); border-radius: 12px; flex-shrink: 0;">
|
||||
${roleIcon}
|
||||
</div>
|
||||
<div style="min-width: 0; flex: 1;">
|
||||
<div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;">
|
||||
<strong style="font-size: 0.95rem; color: var(--text-main);">${s.nombre}</strong>
|
||||
<span class="staff-role-badge staff-role-${s.rol}">${roleLabel}</span>
|
||||
<span class="staff-status-badge ${isBlocked ? 'staff-status-blocked' : 'staff-status-active'}">
|
||||
${isBlocked ? '⛔ Bloqueado' : '● Activo'}
|
||||
</span>
|
||||
</div>
|
||||
<div style="font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 8px;">
|
||||
<span><strong>Usuario:</strong> @${s.username}</span>
|
||||
${s.telefono ? `<span>• 📞 ${s.telefono}</span>` : ''}
|
||||
${s.email ? `<span>• ✉️ ${s.email}</span>` : ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; align-items: center; gap: 6px; flex-shrink: 0; flex-wrap: wrap;">
|
||||
<button type="button" class="btn-action-edit" onclick="openEditStaffModal(${s.id})" title="Editar datos">
|
||||
<span>✏️</span> <span>Editar</span>
|
||||
</button>
|
||||
${!isRootAdmin ? `
|
||||
<button type="button" class="btn-action-block" onclick="toggleBlockStaff(${s.id}, ${isBlocked ? 1 : 0})" title="${isBlocked ? 'Desbloquear acceso' : 'Bloquear acceso'}">
|
||||
<span>${isBlocked ? '🔓' : '🔒'}</span> <span>${isBlocked ? 'Desbloquear' : 'Bloquear'}</span>
|
||||
</button>
|
||||
<button type="button" class="btn-action-delete" onclick="deleteStaff(${s.id}, '${s.nombre.replace(/'/g, "\\'")}')" title="Eliminar empleado">
|
||||
<span>🗑️</span> <span>Eliminar</span>
|
||||
</button>
|
||||
` : `
|
||||
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 700; padding: 4px 8px; background: rgba(0,0,0,0.04); border-radius: 6px;">
|
||||
👑 Principal
|
||||
</span>
|
||||
`}
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function openCreateStaffModal() {
|
||||
const modal = document.getElementById('modalAdminStaff');
|
||||
if (!modal) return;
|
||||
|
||||
document.getElementById('modalStaffTitle').textContent = '👥 Nuevo Empleado / Cajero';
|
||||
document.getElementById('adminStaffId').value = '';
|
||||
document.getElementById('adminStaffNombre').value = '';
|
||||
|
||||
const userInput = document.getElementById('adminStaffUsername');
|
||||
userInput.value = '';
|
||||
userInput.disabled = false;
|
||||
userInput.style.opacity = '1';
|
||||
|
||||
document.getElementById('adminStaffRol').value = 'cajero';
|
||||
|
||||
const passInput = document.getElementById('adminStaffPassword');
|
||||
passInput.value = '';
|
||||
passInput.required = true;
|
||||
document.getElementById('lblStaffPassword').textContent = 'Contraseña de Acceso *:';
|
||||
document.getElementById('hintStaffPassword').style.display = 'none';
|
||||
|
||||
document.getElementById('adminStaffTel').value = '';
|
||||
document.getElementById('adminStaffEmail').value = '';
|
||||
|
||||
const btnSubmit = document.getElementById('btnSaveStaffSubmit');
|
||||
if (btnSubmit) btnSubmit.innerHTML = '<span>💾</span> <span>Guardar Empleado</span>';
|
||||
|
||||
modal.style.display = 'flex';
|
||||
if (window.sounds) window.sounds.playTap();
|
||||
}
|
||||
|
||||
function openEditStaffModal(staffId) {
|
||||
const modal = document.getElementById('modalAdminStaff');
|
||||
if (!modal) return;
|
||||
|
||||
const staff = (adminStaffList || []).find(s => s.id === staffId);
|
||||
if (!staff) {
|
||||
alert('No se encontró el empleado especificado.');
|
||||
return;
|
||||
}
|
||||
|
||||
document.getElementById('modalStaffTitle').textContent = '✏️ Editar Empleado / Cajero';
|
||||
document.getElementById('adminStaffId').value = staff.id;
|
||||
document.getElementById('adminStaffNombre').value = staff.nombre || '';
|
||||
|
||||
const userInput = document.getElementById('adminStaffUsername');
|
||||
userInput.value = staff.username || '';
|
||||
userInput.disabled = true;
|
||||
userInput.style.opacity = '0.7';
|
||||
|
||||
document.getElementById('adminStaffRol').value = staff.rol || 'cajero';
|
||||
if (staff.id === 1) {
|
||||
document.getElementById('adminStaffRol').value = 'admin';
|
||||
}
|
||||
|
||||
const passInput = document.getElementById('adminStaffPassword');
|
||||
passInput.value = '';
|
||||
passInput.required = false;
|
||||
document.getElementById('lblStaffPassword').textContent = 'Nueva Contraseña (opcional):';
|
||||
document.getElementById('hintStaffPassword').style.display = 'block';
|
||||
|
||||
document.getElementById('adminStaffTel').value = staff.telefono || '';
|
||||
document.getElementById('adminStaffEmail').value = staff.email || '';
|
||||
|
||||
const btnSubmit = document.getElementById('btnSaveStaffSubmit');
|
||||
if (btnSubmit) btnSubmit.innerHTML = '<span>💾</span> <span>Actualizar Datos</span>';
|
||||
|
||||
modal.style.display = 'flex';
|
||||
if (window.sounds) window.sounds.playTap();
|
||||
}
|
||||
|
||||
function closeAdminStaffModal(event) {
|
||||
if (event && event.target !== event.currentTarget) return;
|
||||
const modal = document.getElementById('modalAdminStaff');
|
||||
if (modal) modal.style.display = 'none';
|
||||
}
|
||||
|
||||
async function submitAdminStaff(e) {
|
||||
if (e) e.preventDefault();
|
||||
|
||||
const idVal = document.getElementById('adminStaffId').value;
|
||||
const nombre = document.getElementById('adminStaffNombre').value.trim();
|
||||
const username = document.getElementById('adminStaffUsername').value.trim().toLowerCase();
|
||||
const rol = document.getElementById('adminStaffRol').value;
|
||||
const password = document.getElementById('adminStaffPassword').value.trim();
|
||||
const telefono = document.getElementById('adminStaffTel').value.trim();
|
||||
const email = document.getElementById('adminStaffEmail').value.trim().toLowerCase();
|
||||
|
||||
if (!nombre) {
|
||||
alert('El nombre es obligatorio.');
|
||||
return;
|
||||
}
|
||||
|
||||
const isEdit = !!idVal;
|
||||
if (!isEdit && (!username || !password)) {
|
||||
alert('Usuario y contraseña son obligatorios para crear un nuevo empleado.');
|
||||
return;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
nombre,
|
||||
rol,
|
||||
telefono,
|
||||
email
|
||||
};
|
||||
|
||||
if (!isEdit) {
|
||||
payload.username = username;
|
||||
payload.password = password;
|
||||
} else if (password) {
|
||||
payload.password = password;
|
||||
}
|
||||
|
||||
const url = isEdit ? `/api/admin/personal/${idVal}` : '/api/admin/personal';
|
||||
const method = isEdit ? 'PUT' : 'POST';
|
||||
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Error al procesar empleado');
|
||||
|
||||
if (window.sounds) window.sounds.playSuccess();
|
||||
closeAdminStaffModal();
|
||||
await loadAdminStaff();
|
||||
alert(isEdit ? '✅ Datos de empleado actualizados correctamente.' : '✅ Empleado creado exitosamente con credenciales de acceso.');
|
||||
} catch (err) {
|
||||
if (window.sounds) window.sounds.playError();
|
||||
alert(`Error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleBlockStaff(staffId, nuevoEstado) {
|
||||
const accion = (nuevoEstado === 1) ? 'desbloquear' : 'bloquear';
|
||||
const conf = confirm(`¿Estás seguro de ${accion.toUpperCase()} el acceso de este empleado a RecreoPay?`);
|
||||
if (!conf) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/admin/personal/${staffId}/estado`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ activo: nuevoEstado })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Error al cambiar estado del empleado');
|
||||
|
||||
if (window.sounds) window.sounds.playSuccess();
|
||||
await loadAdminStaff();
|
||||
} catch (err) {
|
||||
if (window.sounds) window.sounds.playError();
|
||||
alert(`Error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteStaff(staffId, nombre) {
|
||||
const conf = confirm(`⚠️ PELIGRO:\n¿Estás completamente seguro de ELIMINAR definitivamente al empleado "${nombre}"?\n\nEsta acción no se puede deshacer y perderá el acceso al sistema.`);
|
||||
if (!conf) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/admin/personal/${staffId}`, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Error al eliminar empleado');
|
||||
|
||||
if (window.sounds) window.sounds.playSuccess();
|
||||
await loadAdminStaff();
|
||||
alert(data.mensaje || '✅ Empleado eliminado correctamente.');
|
||||
} catch (err) {
|
||||
if (window.sounds) window.sounds.playError();
|
||||
alert(`Error: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user