Files
recreopay/public/pos.html
T

326 lines
21 KiB
HTML

<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RecreoPay POS - Terminal de Mostrador y Despacho</title>
<link rel="stylesheet" href="/css/styles.css">
<style>
/* Estilos específicos de terminal de alta velocidad */
.student-badge-scanned {
background: #0f172a;
border: 2px solid #38bdf8;
border-radius: 14px;
padding: 12px;
margin-bottom: 14px;
display: flex;
align-items: center;
gap: 12px;
}
.status-pill {
font-size: 0.72rem;
font-weight: 800;
padding: 3px 8px;
border-radius: 6px;
text-transform: uppercase;
}
.status-pendiente { background: #fef3c7; color: #92400e; }
.status-en_preparacion { background: #e0e7ff; color: #3730a3; }
.status-listo { background: #dcfce7; color: #166534; }
.status-entregado { background: #f1f5f9; color: #64748b; }
@keyframes pulse {
0%, 100% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.08); opacity: 0.85; }
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
</style>
<body style="background: #0b1120; color: #f8fafc;" class="pos-mobile-view-catalog">
<!-- BANNER DE ADVERTENCIA HTTPS PARA TERMINALES REMOTAS -->
<div id="posBannerHttpsWarning" style="display: none; background: linear-gradient(135deg, #b45309, #d97706); color: white; padding: 10px 14px; font-size: 0.8rem; font-weight: 700; text-align: center;">
🔒 Terminal en HTTP. Para activar la cámara en vivo del dispositivo, se requiere conexión HTTPS:
<a id="posLinkHttpsRedirect" href="https://somewhat-ships-looksmart-optical.trycloudflare.com/pos.html" style="margin-left: 8px; color: white; text-decoration: underline; font-weight: 900;">
🚀 Abrir en HTTPS Seguro ↗
</a>
</div>
<!-- BARRA DE PESTAÑAS MÓVIL (PANTALLAS <= 900px) -->
<div class="pos-mobile-nav" id="posMobileNav">
<button class="pos-mobile-nav-btn active" id="btnMobileNavCatalog" onclick="switchPosMobileView('catalog')">
<span>🥪</span> Catálogo
</button>
<button class="pos-mobile-nav-btn" id="btnMobileNavCheckout" onclick="switchPosMobileView('checkout')">
<span>💳</span> Caja / Cobro QR
<span class="pos-mobile-nav-badge" id="mobileCartBadge" style="display: none;">0</span>
</button>
</div>
<div class="pos-layout">
<!-- PANEL IZQUIERDO: CATÁLOGO TÁCTIL Y COLA DE PRE-ÓRDENES -->
<div class="pos-catalog-pane">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #334155; padding-bottom: 12px; flex-wrap: wrap; gap: 10px;">
<div style="display: flex; align-items: center; gap: 10px;">
<span style="font-size: 1.8rem;">🥪</span>
<div>
<h1 style="font-size: 1.25rem; font-weight: 900; color: #ffffff; margin: 0;">RecreoPay <span style="color: #38bdf8;">Terminal Soda</span></h1>
<span style="font-size: 0.78rem; color: #94a3b8;">Soda Escolar • Ventana de Atención Rápida</span>
</div>
</div>
<div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;">
<span id="pistolaStatusBadge" style="display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; background: #0c4a6e; color: #38bdf8; padding: 4px 10px; border-radius: 20px; font-weight: 800; border: 1px solid #0284c7;" title="Pistola lectora USB/Bluetooth lista para escanear en cualquier momento">
<span>🔫</span> Pistola QR Conectada
</span>
<span style="display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; background: #064e3b; color: #34d399; padding: 4px 8px; border-radius: 20px; font-weight: 700;">
<span style="width: 8px; height: 8px; background: #34d399; border-radius: 50%; display: inline-block;"></span>
En Línea (SSE)
</span>
<a href="/index.html" style="color: #cbd5e1; font-size: 0.75rem; font-weight: 700; text-decoration: none; border: 1px solid #475569; padding: 4px 8px; border-radius: 8px; background: #1e293b;">
👨‍🍳 Admin
</a>
<a href="/index.html" target="_blank" style="color: #38bdf8; font-size: 0.75rem; font-weight: 700; text-decoration: none; border: 1px solid #38bdf8; padding: 4px 8px; border-radius: 8px;">
PWA Estudiante ↗
</a>
</div>
</div>
<!-- TABS DE MODO DE TERMINAL -->
<div class="pos-tabs">
<button class="pos-tab-btn active" id="tabBtnMostrador" onclick="switchPosTab('mostrador')">
<span>🛒</span> Venta de Mostrador
</button>
<button class="pos-tab-btn" id="tabBtnPreordenes" onclick="switchPosTab('preordenes')">
<span>📦</span> Fila Rápida Pre-Órdenes <span id="badgePreordenesCount" style="background: #ef4444; color: white; padding: 2px 7px; border-radius: 10px; font-size: 0.75rem;">0</span>
</button>
</div>
<!-- VISTA 1: CATÁLOGO TÁCTIL DE PRODUCTOS (MOSTRADOR) -->
<div id="viewPosMostrador">
<div style="display: flex; gap: 8px; margin-bottom: 14px; overflow-x: auto;" id="posCategoriesBar">
<!-- Filtros de categorías -->
</div>
<div class="pos-products-grid" id="posProductsGrid">
<!-- Tarjetas táctiles de productos -->
</div>
</div>
<!-- VISTA 2: FILA RÁPIDA DE PRE-ÓRDENES (RETIRO EN RECREO) -->
<div id="viewPosPreordenes" style="display: none;">
<div style="background: #1e293b; border: 1px solid #334155; border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;">
<div>
<strong style="color: #38bdf8; font-size: 0.95rem;">⚡ Despacho Exclusivo Recreo</strong>
<p style="font-size: 0.78rem; color: #94a3b8; margin: 2px 0 0 0;">Los estudiantes con pre-orden retiran en 3 segundos escaneando su QR aquí.</p>
</div>
<div style="display: flex; gap: 8px; align-items: center;">
<button onclick="openPreOrderScanModal()" style="background: linear-gradient(135deg, #0284c7, #0369a1); border: none; color: white; padding: 8px 14px; border-radius: 8px; font-weight: 800; font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; gap: 6px; box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);">
<span>📷</span> Escanear QR para Entregar
</button>
<button onclick="loadPreOrders()" style="background: #334155; border: none; color: white; padding: 8px 12px; border-radius: 8px; font-weight: 700; cursor: pointer;">
🔄 Refrescar
</button>
</div>
</div>
<div id="preOrdersList" style="display: flex; flex-direction: column; gap: 10px;">
<!-- Lista de pre-órdenes -->
</div>
</div>
<!-- BARRA FLOTANTE DE ACCESO RÁPIDO A CAJA EN MÓVIL -->
<div id="posFloatingCheckoutBar" class="pos-floating-checkout-bar" onclick="switchPosMobileView('checkout')" style="display: none;">
<div style="display: flex; align-items: center; gap: 10px;">
<span style="font-size: 1.3rem;">🛒</span>
<div>
<div style="font-weight: 800; font-size: 0.88rem; color: #ffffff;" id="posFloatingCartText">0 ítems</div>
<div style="font-size: 0.72rem; color: #94a3b8;">Toca para cobrar o escanear QR</div>
</div>
</div>
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1.15rem; font-weight: 900; color: #38bdf8;" id="posFloatingCartTotal">₡0</span>
<span style="background: #0284c7; color: white; padding: 6px 12px; border-radius: 8px; font-weight: 800; font-size: 0.8rem;">Cobrar ➔</span>
</div>
</div>
</div>
<!-- PANEL DERECHO: SCANNER QR, IDENTIFICACIÓN Y COBRO -->
<div class="pos-checkout-pane">
<div>
<!-- BOTÓN VOLVER EN MÓVIL DENTRO DE CHECKOUT -->
<div class="pos-mobile-back-bar">
<button onclick="switchPosMobileView('catalog')" class="pos-mobile-back-btn">
<span>⬅</span> Volver al Catálogo de Alimentos
</button>
</div>
<!-- SECCIÓN DE IDENTIFICACIÓN / ALUMNO EN MOSTRADOR -->
<div id="posStudentSection" style="margin-bottom: 12px;">
<!-- ESTADO INICIAL: SIN ALUMNO IDENTIFICADO -->
<div id="posNoStudentPlaceholder" style="background: #1e293b; border: 1.5px dashed #334155; border-radius: 14px; padding: 14px 16px; text-align: center;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px;">
<span style="font-size: 0.85rem; font-weight: 800; color: #38bdf8;">👤 Alumno en Mostrador</span>
<span style="font-size: 0.7rem; color: #34d399; background: #064e3b; padding: 2px 8px; border-radius: 6px; font-weight: 800;">Caja Lista</span>
</div>
<p style="font-size: 0.76rem; color: #94a3b8; margin: 0 0 10px 0;">
Selecciona productos y presiona <strong>Cobrar</strong> para escanear, o identifica primero al estudiante:
</p>
<button type="button" onclick="openStudentIdModal()" style="padding: 8px 16px; background: #0284c7; color: white; border: none; border-radius: 10px; font-size: 0.8rem; font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; box-shadow: 0 2px 8px rgba(2, 132, 199, 0.3);">
<span>📷</span> Identificar Alumno / Ver Saldo
</button>
</div>
<!-- TARJETA DEL ESTUDIANTE IDENTIFICADO POR QR -->
<div id="studentScannedCard" style="display: none;" class="student-badge-scanned">
<img id="scannedAvatar" src="" style="width: 44px; height: 44px; border-radius: 50%; border: 2px solid #38bdf8; background: white; flex-shrink: 0; object-fit: cover;">
<div style="flex: 1; min-width: 0; word-break: break-word;">
<h4 id="scannedName" style="font-size: 0.92rem; font-weight: 800; color: #ffffff; margin: 0; line-height: 1.2;">Nombre del Alumno</h4>
<div id="scannedGrade" style="font-size: 0.74rem; color: #94a3b8; margin-top: 2px;">2° Grado • Sección 2-A</div>
<div style="display: flex; gap: 8px; margin-top: 4px; font-size: 0.74rem; flex-wrap: wrap;">
<span>Saldo: <strong id="scannedBalance" style="color: #34d399;">₡0</strong></span>
<span>Disp. hoy: <strong id="scannedAvailable" style="color: #38bdf8;">₡0</strong></span>
</div>
</div>
<button onclick="clearScannedStudent()" style="background: none; border: none; color: #ef4444; font-size: 1.2rem; cursor: pointer; padding: 4px 8px; flex-shrink: 0;" title="Desconectar alumno">✕</button>
</div>
<!-- ALERTA DE ALERGIAS AL CAJERO -->
<div id="scannedAllergyAlert" style="display: none; background: #7f1d1d; border: 1px solid #ef4444; border-radius: 10px; padding: 8px 12px; margin-top: 10px; font-size: 0.78rem; color: #fecaca;">
⚠️ <strong>ALERTA MÉDICA:</strong> <span id="scannedAllergyText"></span>
</div>
</div>
<!-- LISTA DE PRODUCTOS SELECCIONADOS EN CAJA -->
<div style="margin-top: 14px;">
<div style="display: flex; justify-content: space-between; align-items: center; font-size: 0.82rem; font-weight: 700; color: #94a3b8; border-bottom: 1px solid #334155; padding-bottom: 6px;">
<span>Ítems en Mostrador</span>
<button onclick="clearPosCart()" style="background: none; border: none; color: #ef4444; font-size: 0.75rem; font-weight: 700; cursor: pointer; padding: 2px 6px;">Limpiar</button>
</div>
<div class="pos-cart-list" id="posCartList">
<p style="text-align: center; color: #64748b; padding: 20px; font-size: 0.85rem;">Toca productos del menú para cobrar</p>
</div>
</div>
</div>
<!-- BOTÓN DE COBRO Y TOTAL -->
<div style="border-top: 2px solid #334155; padding-top: 14px; margin-top: auto;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px;">
<span style="font-size: 0.88rem; font-weight: 800; color: #94a3b8; letter-spacing: 0.5px;">TOTAL A DEBITAR:</span>
<span id="posCartTotal" style="font-size: 1.7rem; font-weight: 900; color: #38bdf8;">₡0</span>
</div>
<button id="btnCobrarPos" onclick="executePosDebit()" style="width: 100%; padding: 14px; background: linear-gradient(135deg, #0284c7, #0369a1); border: none; border-radius: 14px; color: white; font-size: 1rem; font-weight: 900; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; box-shadow: 0 4px 14px rgba(2, 132, 199, 0.4); box-sizing: border-box;">
<span>🔫</span> COBRAR CON PISTOLA QR
</button>
</div>
</div>
</div>
<!-- MODAL DE COBRO RÁPIDO CON PISTOLA QR -->
<div class="modal-qr-backdrop" id="modalPistolaCobro" style="display: none;" onclick="closePistolaModal(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; background: #0f172a; border: 2px solid #38bdf8; border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,0.8); padding: 22px; color: #f8fafc; text-align: center;">
<!-- CABECERA -->
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #334155; padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1.5rem;" id="pistolaModalIcon">📷</span>
<strong style="font-size: 1.1rem; color: #38bdf8; letter-spacing: 0.5px;" id="pistolaModalTitle">Escanear Carné QR</strong>
</div>
<button type="button" onclick="closePistolaModal()" style="background: none; border: none; font-size: 1.3rem; color: #94a3b8; cursor: pointer;">✕</button>
</div>
<!-- ESTADO 1: ESPERANDO ESCANEO (DEFAULT) -->
<div id="pistolaStateWaiting">
<!-- TOTAL A COBRAR GIGANTE (SOLO EN MODO COBRO) -->
<div id="pistolaTotalContainer" style="background: #1e293b; border: 1.5px solid #0284c7; border-radius: 14px; padding: 12px; margin-bottom: 14px;">
<div style="font-size: 0.78rem; font-weight: 800; color: #94a3b8; text-transform: uppercase;">Monto Total a Cobrar</div>
<div id="pistolaModalTotal" style="font-size: 2.3rem; font-weight: 900; color: #38bdf8; margin: 4px 0;">₡0</div>
<div id="pistolaModalItemCount" style="font-size: 0.75rem; color: #cbd5e1;">0 productos en mostrador</div>
</div>
<!-- CÁMARA BAJO DEMANDA INTEGRADA EN EL MODAL -->
<div id="modalCameraContainer" style="position: relative; border-radius: 14px; overflow: hidden; background: #000; min-height: 200px; max-height: 230px; margin-bottom: 12px; display: flex; align-items: center; justify-content: center; border: 2px solid #0284c7;">
<video id="modalScannerVideo" style="width: 100%; height: 210px; object-fit: cover;" autoplay playsinline webkit-playsinline muted></video>
<div class="laser-scan-line"></div>
<div id="modalCameraStatusBadge" style="position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); background: rgba(15, 23, 42, 0.92); color: #38bdf8; padding: 4px 12px; border-radius: 20px; font-size: 0.74rem; font-weight: 800; border: 1px solid #0284c7; white-space: nowrap; box-shadow: 0 4px 10px rgba(0,0,0,0.5);">
📷 Apunta el carné a la cámara o dispara pistola
</div>
<div id="modalCameraOverlay" style="display: none; position: absolute; inset: 0; background: rgba(15, 23, 42, 0.95); padding: 14px; text-align: center; flex-direction: column; justify-content: center; align-items: center; gap: 8px; z-index: 10;">
<span style="font-size: 2rem;">📷</span>
<div id="modalCameraHelpText" style="font-size: 0.8rem; color: #f8fafc; line-height: 1.35;">Toca el botón para permitir el uso de la cámara</div>
<button type="button" onclick="startModalCamera(true)" style="padding: 8px 16px; background: #0284c7; color: white; border: none; border-radius: 8px; font-weight: 800; font-size: 0.82rem; cursor: pointer; box-shadow: 0 4px 10px rgba(2, 132, 199, 0.4);">
Permitir Cámara
</button>
</div>
</div>
<!-- CAMPO DE ENTRADA ENFOCADO PARA PISTOLA USB -->
<div style="margin-bottom: 12px;">
<input type="text" id="inputPistolaDirectScan" placeholder="Esperando lectura de carné o pistola..." autocomplete="off" style="width: 100%; padding: 10px; border-radius: 10px; border: 1.5px solid #334155; background: #1e293b; color: #f8fafc; font-size: 0.88rem; font-weight: 800; text-align: center; box-sizing: border-box;">
</div>
<!-- ACCESOS RÁPIDOS DE PRUEBA -->
<div style="border-top: 1px dashed #334155; padding-top: 10px; margin-top: 10px;">
<span style="font-size: 0.72rem; color: #94a3b8; display: block; margin-bottom: 6px;">Simulación rápida sin pistola física ni cámara:</span>
<div style="display: flex; gap: 6px; justify-content: center; flex-wrap: wrap;">
<button type="button" onclick="handlePistolBarcodeScan('QR-MATEO-2026-A891')" style="padding: 5px 10px; background: #334155; color: white; border: none; border-radius: 6px; font-size: 0.72rem; font-weight: 700; cursor: pointer;">🧒 Mateo (8a)</button>
<button type="button" onclick="handlePistolBarcodeScan('QR-SOFIA-2026-B442')" style="padding: 5px 10px; background: #334155; color: white; border: none; border-radius: 6px; font-size: 0.72rem; font-weight: 700; cursor: pointer;">👧 Sofía (9a)</button>
<button type="button" onclick="handlePistolBarcodeScan('QR-NACHO-2026-D902')" style="padding: 5px 10px; background: #334155; color: white; border: none; border-radius: 6px; font-size: 0.72rem; font-weight: 700; cursor: pointer;">🧑 Ignacio (14a)</button>
</div>
</div>
</div>
<!-- ESTADO 2: PROCESANDO COBRO -->
<div id="pistolaStateProcessing" style="display: none; padding: 20px 0;">
<div style="font-size: 2.8rem; animation: spin 1s infinite linear;">⚡</div>
<h3 style="font-size: 1.15rem; color: #38bdf8; margin: 10px 0 4px 0;">Procesando Débito...</h3>
<p style="font-size: 0.8rem; color: #94a3b8;" id="pistolaProcessingName">Verificando carné y saldo del alumno...</p>
</div>
<!-- ESTADO 3: ÉXITO -->
<div id="pistolaStateSuccess" style="display: none; padding: 10px 0;">
<div style="font-size: 3rem;">✅</div>
<h3 style="font-size: 1.3rem; color: #34d399; margin: 6px 0;">¡COBRO EXITOSO!</h3>
<div style="background: #1e293b; border-radius: 12px; padding: 12px; margin: 12px 0; text-align: left; font-size: 0.82rem;">
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
<span style="color: #94a3b8;">Estudiante:</span>
<strong id="pistolaSuccessStudent" style="color: #f8fafc;">-</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
<span style="color: #94a3b8;">Ticket:</span>
<strong id="pistolaSuccessTicket" style="color: #38bdf8;">-</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
<span style="color: #94a3b8;">Monto Cobrado:</span>
<strong id="pistolaSuccessAmount" style="color: #f8fafc;">-</strong>
</div>
<div style="display: flex; justify-content: space-between; border-top: 1px dashed #334155; padding-top: 6px; margin-top: 6px;">
<span style="color: #94a3b8;">Nuevo Saldo Disponible:</span>
<strong id="pistolaSuccessBalance" style="color: #34d399; font-size: 0.95rem;">-</strong>
</div>
</div>
<button type="button" onclick="closePistolaModal()" style="width: 100%; padding: 12px; background: #10b981; color: white; border: none; border-radius: 10px; font-weight: 800; font-size: 0.9rem; cursor: pointer;">
Listo / Siguiente Alumno (Enter) ➔
</button>
</div>
<!-- ESTADO 4: ERROR / ALERTA -->
<div id="pistolaStateError" style="display: none; padding: 10px 0;">
<div style="font-size: 3rem;">⛔</div>
<h3 style="font-size: 1.2rem; color: #ef4444; margin: 6px 0;" id="pistolaErrorTitle">No se pudo cobrar</h3>
<p style="font-size: 0.85rem; color: #fca5a5; line-height: 1.4; margin-bottom: 16px;" id="pistolaErrorDesc">Detalle del error</p>
<button type="button" onclick="resetPistolaModalWaiting()" style="padding: 10px 20px; background: #334155; color: white; border: none; border-radius: 10px; font-weight: 800; font-size: 0.85rem; cursor: pointer;">
🔄 Intentar con otro carné
</button>
</div>
</div>
</div>
<script src="/js/sounds.js?v=8.5"></script>
<script src="/js/jsQR.js"></script>
<script src="/js/pos.js?v=8.5"></script>
</body>
</html>