This commit is contained in:
Lizandro Guarnizo
2026-06-09 16:44:39 -05:00
parent 4e6913c41e
commit ab8b5ae620
9 changed files with 1590 additions and 323 deletions
File diff suppressed because it is too large Load Diff
+163
View File
@@ -0,0 +1,163 @@
# Webhook WhatsApp — Endpoints y Características
## Endpoint principal
```
URL: /api/webhook.php
```
---
## GET — Verificación de webhook
```
GET /api/webhook.php?hub.mode=subscribe&hub.verify_token=TOKEN&hub.challenge=CHALLENGE
```
### Parámetros que envía Meta
| Parámetro | Valor esperado |
|---|---|
| `hub.mode` | `subscribe` |
| `hub.verify_token` | El token configurado en `system_config.webhook_verify_token` |
| `hub.challenge` | Número aleatorio que debe devolverse tal cual |
### ⚠️ Bug conocido
El código lee `$_GET['hub_verify_token']` (con guión bajo), pero PHP convierte los puntos a guiones bajos automáticamente al parsear `$_GET`, por lo que **funciona correctamente**.
### Respuesta exitosa
```
HTTP 200
Body: {challenge}
```
### Respuesta fallida
```
HTTP 403
Body: {"error":"Token de verificación inválido"}
```
---
## POST — Recepción de eventos
```
POST /api/webhook.php
Content-Type: application/json
```
### Estructura del payload esperado (Meta Cloud API)
```json
{
"object": "whatsapp_business_account",
"entry": [{
"id": "WABA_ID",
"changes": [{
"field": "messages",
"value": {
"messaging_product": "whatsapp",
"metadata": {
"phone_number_id": "PHONE_NUMBER_ID"
},
"contacts": [{
"wa_id": "573001234567",
"profile": { "name": "Nombre Contacto" }
}],
"messages": [{
"from": "573001234567",
"id": "wamid.XXX",
"timestamp": "1234567890",
"type": "text",
"text": { "body": "Hola" }
}]
}
}]
}]
}
```
### Tipos de mensaje soportados
| `type` | Descripción |
|---|---|
| `text` | Texto plano |
| `image` | Imagen (con caption opcional) |
| `audio` | Audio / nota de voz |
| `video` | Video |
| `document` | Documento / PDF |
| `sticker` | Sticker |
| `reaction` | Reacción emoji a otro mensaje |
| `interactive` | Respuesta de lista o botón |
### El campo `field` del change puede ser
- `messages` → mensajes entrantes y estados
- `conversations` → alias aceptado también
### Eventos de estado (statuses)
```json
"statuses": [{
"id": "wamid.XXX",
"status": "sent|delivered|read|failed",
"recipient_id": "573001234567"
}]
```
### Respuesta exitosa
```
HTTP 200
Body: {"status":"success"}
```
---
## Configuración necesaria en `system_config` (BD)
| config_key | Descripción |
|---|---|
| `whatsapp_token` | Access Token de Meta |
| `whatsapp_phone_number_id` | Phone Number ID de la línea |
| `webhook_verify_token` | Token de verificación del webhook |
| `whatsapp_api_url` | `https://graph.facebook.com/v22.0/` |
---
## Variables de entorno equivalentes (`.env`)
```env
WHATSAPP_TOKEN=
WHATSAPP_PHONE_NUMBER_ID=
WEBHOOK_VERIFY_TOKEN=
WHATSAPP_API_URL=https://graph.facebook.com/v22.0/
DB_HOST=
DB_PORT=3306
DB_NAME=
DB_USER=
DB_PASS=
```
---
## Tablas BD que usa el webhook
| Tabla | Uso |
|---|---|
| `users` | Crea o busca usuario por `phone_number` |
| `conversations` | Guarda cada mensaje (deduplicado por `message_id`) |
| `webhook_logs` | Registra el payload crudo de cada POST |
| `notifications` | Crea aviso de nuevo mensaje entrante |
| `media_queue` | Encola media que no pudo descargarse en el momento |
| `system_config` | Lee tokens y configuración |
---
## Seguridad — pendiente de implementar
- No valida la firma `X-Hub-Signature-256` en el POST.
- Se recomienda agregar antes de procesar:
```php
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE_256'] ?? '';
$expected = 'sha256=' . hash_hmac('sha256', $input, APP_SECRET);
if (!hash_equals($expected, $signature)) {
http_response_code(401);
exit;
}
```
+27 -28
View File
@@ -5,6 +5,32 @@
* Fecha: 4 de enero de 2026 - Sistema de autenticación unificado * Fecha: 4 de enero de 2026 - Sistema de autenticación unificado
*/ */
// ── Cargar .env ANTES de definir cualquier constante ──────────────────────────
// Si no se hace aquí, getenv() devuelve vacío y los define() usan el fallback
// 'mysql' (nombre del contenedor Docker) en lugar de la IP real de la BD.
if (!function_exists('loadEnvFile')) {
function loadEnvFile($path) {
if (!file_exists($path)) {
return false;
}
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos($line, '#') === 0 || strpos($line, '=') === false) {
continue;
}
[$name, $value] = explode('=', $line, 2);
$name = trim($name);
$value = trim($value, " \t\n\r\0\x0B\"'");
if (!array_key_exists($name, $_ENV)) {
$_ENV[$name] = $value;
putenv("$name=$value");
}
}
return true;
}
}
loadEnvFile(__DIR__ . '/../.env');
// Configuración de la base de datos - 100% desde variables de entorno (o .env) // Configuración de la base de datos - 100% desde variables de entorno (o .env)
define('DB_HOST', getenv('DB_HOST') ?: 'mysql'); define('DB_HOST', getenv('DB_HOST') ?: 'mysql');
define('DB_PORT', getenv('DB_PORT') ?: '3306'); define('DB_PORT', getenv('DB_PORT') ?: '3306');
@@ -46,34 +72,7 @@ define('SYSTEM_MODULES', [
'resultados' => 'Resultados', 'resultados' => 'Resultados',
]); ]);
// Función para cargar archivo .env // loadEnvFile ya fue definida y ejecutada al inicio del archivo.
if (!function_exists('loadEnvFile')) {
function loadEnvFile($path) {
if (!file_exists($path)) {
return false;
}
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos($line, '#') === 0 || strpos($line, '=') === false) {
continue;
}
[$name, $value] = explode('=', $line, 2);
$name = trim($name);
$value = trim($value, " \t\n\r\0\x0B\"'");
if (!array_key_exists($name, $_ENV)) {
$_ENV[$name] = $value;
putenv("$name=$value");
}
}
return true;
}
}
// Cargar .env si existe
loadEnvFile(__DIR__ . '/../.env');
// Cargar autoloader de Composer si existe (solo una vez) // Cargar autoloader de Composer si existe (solo una vez)
$composerAutoload = __DIR__ . '/../vendor/autoload.php'; $composerAutoload = __DIR__ . '/../vendor/autoload.php';
+19
View File
@@ -171,6 +171,25 @@ function siguienteNumero(int $sesionId): int
return (int) $stmt->fetchColumn(); return (int) $stmt->fetchColumn();
} }
/**
* Genera el siguiente número correlativo de turno POR PRIORIDAD para una sesión.
* Cada prioridad (A, B, C, D, E, F) tiene su propia secuencia independiente.
* Usa bloqueo a nivel de fila para evitar duplicados en concurrencia.
*/
function siguienteNumeroPorPrioridad(int $sesionId, int $prioridadId): int
{
$pdo = db();
$stmt = $pdo->prepare(
'SELECT COALESCE(MAX(numero), 0) + 1 AS siguiente
FROM turnero_turnos
WHERE sesion_id = ?
AND prioridad_id = ?
FOR UPDATE'
);
$stmt->execute([$sesionId, $prioridadId]);
return (int) $stmt->fetchColumn();
}
/** /**
* Selecciona el siguiente turno a llamar según el motor de prioridades. * Selecciona el siguiente turno a llamar según el motor de prioridades.
* *
+4 -2
View File
@@ -34,7 +34,6 @@ $pdo->beginTransaction();
try { try {
$sesionId = obtenerOCrearSesionHoy(); $sesionId = obtenerOCrearSesionHoy();
$numero = siguienteNumero($sesionId);
// Buscar prioridad_id // Buscar prioridad_id
$stmt = $pdo->prepare( $stmt = $pdo->prepare(
@@ -50,7 +49,10 @@ try {
$prioridadId = (int) $prioridad['id']; $prioridadId = (int) $prioridad['id'];
// Código visual: "A001", "E042", etc. // Correlativo independiente por prioridad (A-001, A-002... B-001, B-002... etc.)
$numero = siguienteNumeroPorPrioridad($sesionId, $prioridadId);
// Código visual: "A001", "B001", "E001", etc.
$codigo = $prioCodigo . str_pad($numero, 3, '0', STR_PAD_LEFT); $codigo = $prioCodigo . str_pad($numero, 3, '0', STR_PAD_LEFT);
$stmt = $pdo->prepare( $stmt = $pdo->prepare(
+12 -4
View File
@@ -30,12 +30,20 @@ $sesion = $stmtSesion->fetch(PDO::FETCH_ASSOC);
if (!$sesion) { if (!$sesion) {
jsonOk([ jsonOk([
'fecha' => $fecha, 'fecha' => $fecha,
'sesion' => null, 'sesion' => null,
'resumen' => ['total' => 0, 'atendidos' => 0, 'en_espera' => 0, 'resumen' => [
'ausentes' => 0, 'cancelados' => 0, 'tiempo_promedio_min' => null], 'total' => 0,
'atendidos' => 0,
'en_espera' => 0,
'ausentes' => 0,
'cancelados' => 0,
'tiempo_espera_promedio_min' => null,
'tiempo_servicio_promedio_min' => null,
],
'por_prioridad' => [], 'por_prioridad' => [],
'por_lugar' => [], 'por_lugar' => [],
'consent_stats' => [],
'turnos' => [], 'turnos' => [],
]); ]);
} }
+4 -4
View File
@@ -68,7 +68,7 @@ Layout::open('Dashboard Turnero', 'fas fa-chart-bar');
</style> </style>
<div class="page-header"> <div class="page-header">
<a href="<?= BASE_URL ?>/erp.php?m=turnero&v=recepcion" class="back-btn"> <a href="<?= BASE_URL ?>erp.php?m=turnero&v=recepcion" class="back-btn">
<i class="fas fa-arrow-left me-1"></i>Volver <i class="fas fa-arrow-left me-1"></i>Volver
</a> </a>
<h1><i class="fas fa-chart-bar me-2 text-primary"></i>Dashboard Turnero</h1> <h1><i class="fas fa-chart-bar me-2 text-primary"></i>Dashboard Turnero</h1>
@@ -84,7 +84,7 @@ Layout::open('Dashboard Turnero', 'fas fa-chart-bar');
<button class="btn btn-outline-secondary btn-sm" onclick="cargarDatos()" title="Refrescar"> <button class="btn btn-outline-secondary btn-sm" onclick="cargarDatos()" title="Refrescar">
<i class="fas fa-sync-alt"></i> <i class="fas fa-sync-alt"></i>
</button> </button>
<a href="<?= BASE_URL ?>/erp.php?m=turnero&v=configuracion" class="btn btn-outline-secondary btn-sm"> <a href="<?= BASE_URL ?>erp.php?m=turnero&v=configuracion" class="btn btn-outline-secondary btn-sm">
<i class="fas fa-cogs"></i> <i class="fas fa-cogs"></i>
</a> </a>
</div> </div>
@@ -151,7 +151,7 @@ Layout::open('Dashboard Turnero', 'fas fa-chart-bar');
/* ═══════════════════════════════════════════════════════════ /* ═══════════════════════════════════════════════════════════
Dashboard Turnero Dashboard Turnero
═══════════════════════════════════════════════════════════ */ ═══════════════════════════════════════════════════════════ */
const API = '<?= BASE_URL ?>/modules/turnero/api/'; const API = '<?= BASE_URL ?>modules/turnero/api/';
const BASE_WA = '<?= BASE_URL ?>'; const BASE_WA = '<?= BASE_URL ?>';
let _turnos = []; // cache para búsqueda local let _turnos = []; // cache para búsqueda local
let _autoReloadId = null; let _autoReloadId = null;
@@ -194,7 +194,7 @@ function mostrarError(msg) {
// ── Render ─────────────────────────────────────────────────── // ── Render ───────────────────────────────────────────────────
function renderDashboard(json) { function renderDashboard(json) {
const { sesion, resumen, por_prioridad, por_lugar, consent_stats, turnos } = json; const { sesion, resumen, por_prioridad, por_lugar, consent_stats = {}, turnos } = json;
// ── Sesión info ──────────────────────────────────────── // ── Sesión info ────────────────────────────────────────
const si = document.getElementById('sesionInfo'); const si = document.getElementById('sesionInfo');
+337 -283
View File
@@ -12,8 +12,8 @@ $_labNombre = htmlspecialchars($_dispCfg['empresa_nombre'] ?? 'Sistema de Turnos
$_labLogo = $_dispCfg['doc_logo_base64'] ?? ''; $_labLogo = $_dispCfg['doc_logo_base64'] ?? '';
$_labColor = preg_match('/^#[0-9a-fA-F]{3,8}$/', $_dispCfg['doc_color'] ?? '') ? $_dispCfg['doc_color'] : '#1565c0'; $_labColor = preg_match('/^#[0-9a-fA-F]{3,8}$/', $_dispCfg['doc_color'] ?? '') ? $_dispCfg['doc_color'] : '#1565c0';
$_tvVideo = $_dispCfg['turnero_tv_video'] ?? ''; $_tvVideo = $_dispCfg['turnero_tv_video'] ?? '';
// Validar que sea una URL del mismo origen (solo rutas relativas o mismo dominio)
if ($_tvVideo && !preg_match('#^https?://#', $_tvVideo)) { $_tvVideo = ''; } if ($_tvVideo && !preg_match('#^https?://#', $_tvVideo)) { $_tvVideo = ''; }
$_hasVideo = (bool)$_tvVideo;
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="es"> <html lang="es">
@@ -24,336 +24,369 @@ if ($_tvVideo && !preg_match('#^https?://#', $_tvVideo)) { $_tvVideo = ''; }
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style> <style>
*, *::before, *::after { box-sizing: border-box; } *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { html, body {
margin: 0; padding: 0;
height: 100%; width: 100%; height: 100%; width: 100%;
overflow: hidden; overflow: hidden;
background: #f0f4f8; background: #ffffff;
font-family: 'Segoe UI', system-ui, sans-serif; font-family: 'Segoe UI', system-ui, sans-serif;
color: #1e293b; color: #0f172a;
} }
:root { :root {
--brand: <?= $_labColor ?>; --brand: <?= $_labColor ?>;
--brand-dark: color-mix(in srgb, <?= $_labColor ?> 70%, #000); --brand-dk: color-mix(in srgb, <?= $_labColor ?> 72%, #000);
--brand-light: color-mix(in srgb, <?= $_labColor ?> 15%, #fff); --brand-lt: color-mix(in srgb, <?= $_labColor ?> 10%, #fff);
} }
/* ── Layout principal ──────────────────────────────── */ /* ─── Wrapper principal ─────────────────────────────────── */
.pg-grid { .pg-wrap {
display: grid; display: grid;
grid-template-rows: auto 1fr auto auto; grid-template-rows: auto 1fr auto auto;
height: 100vh; height: 100vh;
overflow: hidden;
} }
/* ── Header ─────────────────────────────────────────── */ /* ── Header ────────────────────────────────────────────── */
.pg-header { .pg-header {
display: flex; align-items: center; justify-content: space-between; display: flex; align-items: center; gap: 1rem;
padding: .6rem 2rem; padding: .65rem 1.8rem;
background: var(--brand); background: var(--brand);
gap: 1rem; flex-shrink: 0; flex-shrink: 0;
box-shadow: 0 3px 14px rgba(0,0,0,.2);
} }
.header-brand { .hd-brand { display: flex; align-items: center; gap: .8rem; flex: 1; min-width: 0; }
display: flex; align-items: center; gap: .8rem; .hd-brand .logo {
flex: 1; min-width: 0; height: 46px; max-width: 120px; object-fit: contain;
background: rgba(255,255,255,.16); border-radius: 8px; padding: 4px 7px;
} }
.header-brand img.logo { .lab-nombre {
height: 44px; max-width: 120px; object-fit: contain; font-size: clamp(1rem, 2.4vw, 1.55rem);
background: rgba(255,255,255,.12); border-radius: 8px; padding: 4px 6px;
}
.header-brand .lab-nombre {
font-size: clamp(.9rem, 2vw, 1.3rem);
font-weight: 800; color: #fff; font-weight: 800; color: #fff;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
} }
.header-brand .lab-sub { .lab-sub {
font-size: .7rem; color: rgba(255,255,255,.65); font-size: .62rem; color: rgba(255,255,255,.65);
font-weight: 500; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 1.5px;
display: block; margin-top: 1px; display: block; margin-top: 1px;
} }
.header-right { .hd-right { display: flex; align-items: center; gap: .7rem; flex-shrink: 0; }
display: flex; align-items: center; gap: .75rem; flex-shrink: 0;
}
.reloj { .reloj {
font-size: clamp(1rem, 2.2vw, 1.45rem); font-size: clamp(1.2rem, 3vw, 2rem);
font-weight: 800; color: #fff; font-weight: 800; color: #fff;
font-variant-numeric: tabular-nums; font-variant-numeric: tabular-nums; letter-spacing: 1px;
letter-spacing: 1px;
} }
.btn-sonido { .live-dot {
background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3); width: 9px; height: 9px; border-radius: 50%;
color: #fff; border-radius: 8px; padding: 5px 12px; background: #4ade80; box-shadow: 0 0 9px #4ade80;
font-size: .78rem; cursor: pointer; animation: pdot 2s ease-in-out infinite; flex-shrink: 0;
}
@keyframes pdot { 0%,100%{opacity:1} 50%{opacity:.35} }
.btn-son {
background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.28);
color: rgba(255,255,255,.9); border-radius: 8px; padding: 5px 12px;
font-size: .7rem; font-weight: 600; cursor: pointer; font-family: inherit;
transition: background .2s;
}
.btn-son.on { background: rgba(74,222,128,.22); border-color: rgba(74,222,128,.45); color: #86efac; }
.btn-fs {
background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22);
color: rgba(255,255,255,.82); border-radius: 8px; padding: 5px 10px;
font-size: .7rem; cursor: pointer; font-family: inherit;
} }
/* ── Cuerpo: paneles de área ─────────────────────── */ /* ─── Body layout ───────────────────────────────────────── */
.pg-body { .pg-body {
display: grid; display: grid;
grid-template-columns: 1fr 1fr; /* recepción | lugares */
gap: 0;
overflow: hidden; overflow: hidden;
} }
.pg-body.has-video { grid-template-columns: 1fr 38%; }
.pg-body.no-video { grid-template-columns: 1fr 1fr; }
/* Panel genérico de área */ /* ─── Turnos area (stacked when video) ──────────────────── */
.area-panel { .turnos-area {
display: grid;
overflow: hidden;
border-right: 3px solid #e8ecf0;
}
.pg-body.has-video .turnos-area { grid-template-rows: 1fr 1fr; }
.pg-body.no-video .turnos-area { grid-template-rows: 1fr; }
/* ─── Section panel ─────────────────────────────────────── */
.section-panel {
display: flex; flex-direction: column; display: flex; flex-direction: column;
overflow: hidden; overflow: hidden;
background: #f8fafc;
}
.turnos-area .section-panel + .section-panel {
border-top: 3px solid #e8ecf0;
}
/* no-video: muestras column sits right of turnos-area */
.mue-panel {
display: flex; flex-direction: column;
overflow: hidden;
background: #f8fafc;
border-left: 3px solid #e8ecf0;
} }
/* Encabezado del área */ /* Section header */
.area-header { .sec-hdr {
padding: .55rem 1.2rem; display: flex; align-items: center; gap: .5rem;
font-size: clamp(.7rem, 1.4vw, .9rem); padding: .5rem 1.2rem;
font-weight: 800; text-transform: uppercase; letter-spacing: 2px; font-size: .72rem; font-weight: 800;
color: #fff; display: flex; align-items: center; gap: .5rem; text-transform: uppercase; letter-spacing: 2.5px;
color: #fff; flex-shrink: 0;
}
.sec-hdr.rec { background: var(--brand); }
.sec-hdr.mue { background: var(--brand-dk); }
/* ─── Slots container ───────────────────────────────────── */
.slots-row {
flex: 1; display: grid;
grid-auto-flow: column;
grid-auto-columns: 1fr;
gap: 10px; padding: 10px;
overflow: hidden;
}
/* ─── Single slot card ──────────────────────────────────── */
.slot {
background: #fff;
border-radius: 16px;
border: 2.5px solid #e2e8f0;
display: flex; flex-direction: column;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,.06);
transition: border-color .45s, box-shadow .45s;
}
.slot.lit {
border-color: var(--pc, var(--brand));
box-shadow: 0 6px 28px color-mix(in srgb, var(--pc, var(--brand)) 24%, transparent),
0 2px 8px rgba(0,0,0,.06);
}
/* Slot header bar */
.slot-hdr {
display: flex; align-items: center; gap: .45rem;
padding: .35rem .9rem;
font-size: .62rem; font-weight: 800;
text-transform: uppercase; letter-spacing: 2px;
background: var(--brand-lt); color: var(--brand);
border-bottom: 2px solid color-mix(in srgb, var(--brand) 18%, transparent);
flex-shrink: 0; flex-shrink: 0;
transition: background .45s, color .45s, border-color .45s;
}
.slot.lit .slot-hdr {
background: color-mix(in srgb, var(--pc, var(--brand)) 12%, #fff);
color: var(--pc, var(--brand));
border-color: color-mix(in srgb, var(--pc, var(--brand)) 30%, transparent);
} }
.area-header.recepcion { background: #1e40af; }
.area-header.muestras { background: #15803d; }
/* Turno activo dentro del área */ /* Slot body */
.area-turno { .slot-body {
flex: 1; display: flex; flex-direction: column; flex: 1; display: flex; flex-direction: column;
align-items: center; justify-content: center; align-items: center; justify-content: center;
padding: 1.5rem 1rem; padding: .6rem .4rem;
position: relative; overflow: hidden; position: relative; overflow: hidden;
background: #fff;
transition: background .5s;
}
.area-turno::before {
content: ''; position: absolute; top: 0; left: 0; right: 0; height: 6px;
background: var(--prio-color, var(--brand));
transition: background .5s;
}
.area-turno .lbl-destino {
font-size: clamp(.65rem, 1.3vw, .85rem);
color: #94a3b8; font-weight: 700;
text-transform: uppercase; letter-spacing: 3px;
margin-bottom: .15rem;
}
.area-turno .codigo-num {
font-size: clamp(4rem, 16vw, 12rem);
font-weight: 900; line-height: 1; letter-spacing: -3px;
color: var(--prio-color, var(--brand));
transition: color .4s;
}
.area-turno .pac-nombre {
font-size: clamp(.9rem, 2.2vw, 1.5rem);
font-weight: 700; color: #334155;
margin-top: .3rem; text-align: center;
}
.area-turno .prio-chip {
display: inline-flex; align-items: center; gap: .4rem;
padding: .35rem 1.1rem; border-radius: 30px;
font-size: clamp(.7rem, 1.3vw, .95rem); font-weight: 700;
margin-top: .75rem;
transition: background .4s, color .4s;
}
.area-turno .sin-turno {
font-size: clamp(1rem, 2.5vw, 1.8rem);
color: #cbd5e1; text-align: center;
} }
/* Anillo */ /* Ring pop on new turno */
@keyframes ping-ring { .ring-pop-el {
0% { transform: scale(.8); opacity: .7; } position: absolute; top: 50%; left: 50%;
100% { transform: scale(2.6); opacity: 0; } width: 10px; height: 10px; border-radius: 50%;
} transform: translate(-50%,-50%);
.ring {
position: absolute; inset: 0;
display: flex; align-items: center; justify-content: center;
pointer-events: none; z-index: 0; pointer-events: none; z-index: 0;
} }
.ring::before { .ring-pop-el.do-pop { animation: r-pop .85s ease-out forwards; }
content: ''; width: 30vmin; height: 30vmin; border-radius: 50%; @keyframes r-pop {
background: transparent; 0% { transform:translate(-50%,-50%) scale(1); background:var(--pc,var(--brand)); opacity:.2; }
border: 5px solid var(--prio-color, var(--brand)); opacity: 0; 100% { transform:translate(-50%,-50%) scale(50); background:var(--pc,var(--brand)); opacity:0; }
}
.ring.animar::before { animation: ping-ring .75s ease-out 1; }
.area-turno > *:not(.ring) { position: relative; z-index: 1; }
/* Divisor entre áreas */
.area-divider {
width: 3px; background: #e2e8f0; flex-shrink: 0;
} }
/* Sub-paneles múltiples cuando hay varios lugares */ /* Labels */
.lugares-grid { .lbl-dest {
display: grid; font-size: clamp(.5rem, .88vw, .68rem);
grid-template-rows: repeat(auto-fill, 1fr); font-weight: 700; text-transform: uppercase; letter-spacing: 3px;
height: 100%; color: #94a3b8; margin-bottom: .05rem;
z-index: 1; position: relative;
transition: color .4s;
}
.slot-body.lit .lbl-dest { color: var(--pc, var(--brand)); opacity: .75; }
/* BIG turno code */
.big-code {
font-size: clamp(3rem, 9vw, 10rem);
font-weight: 900; line-height: 1; letter-spacing: -2px;
color: #dde3eb;
font-variant-numeric: tabular-nums;
z-index: 1; position: relative;
transition: color .4s;
}
.slot-body.lit .big-code { color: var(--pc, var(--brand)); }
/* Patient name */
.pac-name {
font-size: clamp(.7rem, 1.4vw, 1.15rem);
font-weight: 700; color: #334155;
margin-top: .25rem; text-align: center; min-height: 1.2em;
z-index: 1; position: relative;
}
/* Priority badge */
.prio-badge {
display: inline-flex; align-items: center; gap: .3rem;
padding: .22rem .7rem; border-radius: 99px;
font-size: clamp(.52rem, .75vw, .68rem); font-weight: 700;
margin-top: .25rem; border: 1.5px solid #e2e8f0;
color: #94a3b8; background: #f8fafc;
transition: all .4s;
z-index: 1; position: relative;
}
.slot-body.lit .prio-badge {
color: var(--pc, var(--brand));
border-color: color-mix(in srgb, var(--pc, var(--brand)) 40%, transparent);
background: color-mix(in srgb, var(--pc, var(--brand)) 8%, #fff);
}
/* ─── Video panel ───────────────────────────────────────── */
.video-panel {
display: flex; align-items: center; justify-content: center;
overflow: hidden; overflow: hidden;
background: #f1f5f9;
border-left: 3px solid #e8ecf0;
} }
.lugar-sub { .video-panel video {
display: flex; flex-direction: column; width: 100%; height: 100%;
border-bottom: 2px solid #e2e8f0; object-fit: contain; /* video completo, sin recortar */
} display: block;
.lugar-sub:last-child { border-bottom: none; }
.lugar-sub .area-header { background: #166534; }
.lugar-sub .area-turno .codigo-num {
font-size: clamp(2.5rem, 10vw, 7rem);
} }
/* ── Cola en espera ──────────────────────────────── */ /* ── Cola en espera ────────────────────────────────────── */
.pg-cola { .pg-cola {
background: #f8fafc; background: #fff;
border-top: 2px solid #e2e8f0; border-top: 2.5px solid #e8ecf0;
padding: .4rem .8rem; padding: .45rem 1rem;
display: flex; align-items: center; gap: .6rem; display: flex; align-items: center; gap: .55rem;
overflow-x: auto; flex-shrink: 0; overflow-x: auto; flex-shrink: 0;
scrollbar-width: none; scrollbar-width: none;
min-height: 38px;
} }
.pg-cola::-webkit-scrollbar { display: none; } .pg-cola::-webkit-scrollbar { display: none; }
.cola-lbl { .cola-lbl {
font-size: .7rem; font-weight: 800; text-transform: uppercase; font-size: .64rem; font-weight: 800;
letter-spacing: 1.5px; color: var(--brand); white-space: nowrap; text-transform: uppercase; letter-spacing: 2px;
flex-shrink: 0; color: var(--brand); white-space: nowrap; flex-shrink: 0;
} }
.cola-sep { width: 1px; height: 14px; background: #e2e8f0; flex-shrink: 0; }
.cola-chip { .cola-chip {
display: inline-flex; align-items: center; gap: .3rem; display: inline-flex; align-items: center; gap: .3rem;
padding: .25rem .7rem; border-radius: 99px; padding: .22rem .7rem; border-radius: 99px;
font-size: .78rem; font-weight: 700; font-size: .78rem; font-weight: 700;
background: #fff; border: 1.5px solid; background: #fff; border: 1.5px solid;
white-space: nowrap; flex-shrink: 0; white-space: nowrap; flex-shrink: 0;
} }
.cola-vacia-msg { .cola-chip .cdot { width: 6px; height: 6px; border-radius: 50%; }
font-size: .78rem; color: #94a3b8; .cola-empty { font-size: .72rem; color: #94a3b8; }
}
/* ── Footer stats ─────────────────────────────────── */ /* ── Footer stats ──────────────────────────────────────── */
.pg-footer { .pg-footer {
display: flex; justify-content: center; align-items: center; display: flex; justify-content: center; align-items: center;
gap: 2rem; flex-wrap: wrap; gap: 2.5rem; flex-wrap: wrap;
padding: .4rem 2rem; padding: .5rem 2rem;
background: var(--brand); background: var(--brand);
flex-shrink: 0; flex-shrink: 0;
} }
.stat-item { text-align: center; } .stat-item { text-align: center; }
.stat-item .val { font-size: 1.15rem; font-weight: 800; color: #fff; } .stat-item .val {
.stat-item .lbl { font-size: .6rem; color: rgba(255,255,255,.65); text-transform: uppercase; letter-spacing: 1px; } font-size: clamp(.95rem, 2vw, 1.35rem);
.stat-sep { width: 1px; height: 26px; background: rgba(255,255,255,.2); } font-weight: 800; color: #fff;
</style> font-variant-numeric: tabular-nums;
<style>
/* ══ DARK THEME OVERRIDE ═════════════════════════════════════ */
:root {
--bg: #070e1d;
--glass: rgba(255,255,255,.04);
--border:rgba(255,255,255,.08);
--muted: #4a5568;
} }
html, body { .stat-item .lbl {
background: var(--bg); font-size: .58rem; color: rgba(255,255,255,.65);
font-family: 'Inter', 'Segoe UI', system-ui, sans-serif; text-transform: uppercase; letter-spacing: 1.5px;
color: #e2e8f0;
} }
/* Layout: sin scroll */ .stat-sep { width: 1px; height: 24px; background: rgba(255,255,255,.22); }
.pg-wrap { display: grid; grid-template-rows: auto 1fr auto auto; height: 100vh; overflow: hidden; }
/* Header/footer: brand más oscuro */ /* ─── Announcement overlay ──────────────────────────────── */
.pg-header { background: color-mix(in srgb, var(--brand) 72%, #000) !important; }
.pg-footer { background: color-mix(in srgb, var(--brand) 42%, #000) !important; border-top: 1px solid color-mix(in srgb, var(--brand) 35%, transparent) !important; }
/* Botón pantalla completa */
.btn-fs { background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.2); color: rgba(255,255,255,.8); border-radius: 8px; padding: 4px 10px; font-size: .68rem; cursor: pointer; font-family: inherit; transition: background .2s; }
.btn-fs:hover { background: rgba(255,255,255,.22); }
/* Header modernize */
.pg-header::before {
content: ''; position: absolute; inset: 0; pointer-events: none;
background: linear-gradient(135deg,rgba(0,0,0,.32) 0%,rgba(0,0,0,0) 55%,rgba(255,255,255,.07) 100%);
}
.pg-header { position: relative; }
.pg-header::after {
content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 1px;
background: linear-gradient(90deg,transparent,rgba(255,255,255,.28),transparent);
}
.btn-son {
background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2);
color: rgba(255,255,255,.82); border-radius: 8px; padding: 4px 11px;
font-size: .68rem; font-weight: 600; cursor: pointer; font-family: inherit;
transition: background .2s;
}
.btn-son.on { background: rgba(34,197,94,.2); border-color: rgba(34,197,94,.35); color: #86efac; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 8px #22c55e; animation: pdot 2s ease-in-out infinite; }
@keyframes pdot { 0%,100%{opacity:1} 50%{opacity:.35} }
/* Override body/pg-* for dark */
.pg-body { background: var(--bg); }
.v-split { background: linear-gradient(180deg,transparent,var(--border) 12%,var(--border) 88%,transparent); width: 1px; }
.area-col { background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
.col-hdr { display: flex; align-items: center; gap: .55rem; padding: .38rem 1.1rem; font-size: .62rem; font-weight: 800; text-transform: uppercase; letter-spacing: 2.5px; color: rgba(255,255,255,.88); flex-shrink: 0; }
.col-hdr.rec { background: linear-gradient(90deg, color-mix(in srgb,var(--brand) 38%,#000), color-mix(in srgb,var(--brand) 58%,#000)); border-bottom: 1px solid color-mix(in srgb,var(--brand) 45%,transparent); }
.col-hdr.mue { background: linear-gradient(90deg, color-mix(in srgb,var(--brand) 28%,#000), color-mix(in srgb,var(--brand) 44%,#000)); border-bottom: 1px solid color-mix(in srgb,var(--brand) 35%,transparent); opacity: .88; }
.slot-grid { display: grid; grid-auto-rows: 1fr; height: 100%; overflow: hidden; }
.slot { display: flex; flex-direction: column; border-bottom: 1px solid var(--border); position: relative; overflow: hidden; }
.slot:last-child { border-bottom: none; }
.slot-hdr { display: flex; align-items: center; gap: .4rem; padding: .27rem .9rem; font-size: .59rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1.8px; flex-shrink: 0; z-index: 1; position: relative; }
.slot-hdr.rec { color: color-mix(in srgb,var(--brand) 88%,#fff); border-bottom: 1px solid color-mix(in srgb,var(--brand) 28%,transparent); background: color-mix(in srgb,var(--brand) 18%,transparent); }
.slot-hdr.mue { color: color-mix(in srgb,var(--brand) 78%,#fff); border-bottom: 1px solid color-mix(in srgb,var(--brand) 22%,transparent); background: color-mix(in srgb,var(--brand) 12%,transparent); }
.slot-hdr .hdot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.slot-hdr.rec .hdot { background: var(--brand); box-shadow: 0 0 5px color-mix(in srgb,var(--brand) 80%,transparent); }
.slot-hdr.mue .hdot { background: color-mix(in srgb,var(--brand) 75%,#fff); box-shadow: 0 0 5px color-mix(in srgb,var(--brand) 65%,transparent); }
.slot-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: .3rem .7rem; position: relative; overflow: hidden; }
.slot-body::after { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .6s; background: radial-gradient(ellipse 80% 60% at 50% 60%, var(--pc,transparent) 0%, transparent 70%); }
.slot-body.lit::after { opacity: .07; }
.slot-body::before { content: ''; position: absolute; left: 0; top: 18%; bottom: 18%; width: 3px; border-radius: 0 3px 3px 0; background: var(--pc,transparent); opacity: 0; transition: opacity .5s,background .5s; }
.slot-body.lit::before { opacity: 1; }
.lbl-dest { font-size: clamp(.5rem,.95vw,.66rem); font-weight: 700; text-transform: uppercase; letter-spacing: 3px; color: var(--muted); margin-bottom: .1rem; z-index: 1; position: relative; transition: color .4s; }
.slot-body.lit .lbl-dest { color: var(--pc); opacity: .7; }
.big-code { font-size: clamp(1.8rem,5.5vw,5.5rem); font-weight: 900; line-height: 1; color: var(--muted); letter-spacing: -2px; font-variant-numeric: tabular-nums; z-index: 1; position: relative; transition: color .45s; }
.slot-body.lit .big-code { color: var(--pc); }
.pac-name { font-size: clamp(.55rem,1vw,.8rem); font-weight: 700; color: rgba(255,255,255,.6); margin-top: .15rem; text-align: center; min-height: 1em; z-index: 1; position: relative; }
.prio-badge { display: inline-flex; align-items: center; gap: .3rem; padding: .16rem .6rem; border-radius: 99px; font-size: clamp(.46rem,.72vw,.6rem); font-weight: 700; margin-top: .2rem; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.04); color: var(--muted); transition: background .4s,color .4s,border-color .4s; z-index: 1; position: relative; }
.ring-pop-el { position: absolute; top: 50%; left: 50%; width: 10px; height: 10px; border-radius: 50%; transform: translate(-50%,-50%); pointer-events: none; z-index: 0; }
.ring-pop-el.do-pop { animation: r-pop .85s ease-out forwards; }
@keyframes r-pop { 0%{transform:translate(-50%,-50%) scale(1);background:var(--pc,var(--brand));opacity:.38} 100%{transform:translate(-50%,-50%) scale(50);background:var(--pc,var(--brand));opacity:0} }
/* Cola dark */
.pg-cola { background: rgba(255,255,255,.022); border-top: 1px solid var(--border); }
/* Video de fondo TV */
.tv-bg-video {
position: absolute; inset: 0; width: 100%; height: 100%;
object-fit: cover; opacity: .14; z-index: 0; pointer-events: none;
}
.pg-body { position: relative; }
.pg-body > *:not(.tv-bg-video) { position: relative; z-index: 1; }
.cola-lbl { color: var(--brand); }
.cola-sep { width: 1px; height: 12px; background: var(--border); flex-shrink: 0; }
.cola-chip { background: rgba(255,255,255,.04); font-size: .68rem; }
.cola-chip .cdot { width: 5px; height: 5px; border-radius: 50%; }
.cola-empty { font-size: .68rem; color: var(--muted); }
/* Footer dark */
.pg-footer { background: rgba(0,0,0,.45); border-top: 1px solid var(--border); }
.stat-item .val { font-size: clamp(.78rem,1.6vw,1rem); font-variant-numeric: tabular-nums; }
.stat-sep { background: var(--border); height: 19px; }
/* ══ ANNOUNCEMENT OVERLAY ════════════════════════════════════ */
#ann-overlay { #ann-overlay {
position: fixed; inset: 0; z-index: 9999; position: fixed; inset: 0; z-index: 9999;
display: flex; align-items: center; justify-content: center; display: flex; align-items: center; justify-content: center;
opacity: 0; pointer-events: none; transition: opacity .3s ease; opacity: 0; pointer-events: none; transition: opacity .3s ease;
} }
#ann-overlay.visible { opacity: 1; pointer-events: all; } #ann-overlay.visible { opacity: 1; pointer-events: all; }
.ann-bg { position: absolute; inset: 0; background: rgba(4,8,20,.92); backdrop-filter: blur(18px); transition: background .4s; } .ann-bg {
position: absolute; inset: 0;
background: rgba(4,8,20,.93);
backdrop-filter: blur(18px);
transition: background .4s;
}
.ann-card { .ann-card {
position: relative; z-index: 1; width: min(600px,88vw); position: relative; z-index: 1;
background: rgba(255,255,255,.055); border: 1px solid rgba(255,255,255,.11); width: min(600px, 88vw);
background: rgba(255,255,255,.055);
border: 1px solid rgba(255,255,255,.12);
border-radius: 28px; padding: 2.8rem 3.5rem 2.4rem; text-align: center; border-radius: 28px; padding: 2.8rem 3.5rem 2.4rem; text-align: center;
box-shadow: 0 30px 90px rgba(0,0,0,.7), 0 0 70px var(--ac,#1565c0)44; box-shadow: 0 30px 90px rgba(0,0,0,.7), 0 0 70px var(--ac, #1565c0)44;
transform: scale(.88) translateY(14px); transform: scale(.88) translateY(14px);
transition: transform .4s cubic-bezier(.34,1.5,.64,1); transition: transform .4s cubic-bezier(.34,1.5,.64,1);
} }
#ann-overlay.visible .ann-card { transform: scale(1) translateY(0); } #ann-overlay.visible .ann-card { transform: scale(1) translateY(0); }
.ann-card::before { content: ''; position: absolute; left: 0; top: 12%; bottom: 12%; width: 4px; border-radius: 0 4px 4px 0; background: var(--ac,var(--brand)); box-shadow: 0 0 28px var(--ac,var(--brand)); } .ann-card::before {
.ann-ring { position: absolute; top: 50%; left: 50%; width: 10px; height: 10px; border-radius: 50%; transform: translate(-50%,-50%); pointer-events: none; } content: ''; position: absolute; left: 0; top: 12%; bottom: 12%;
width: 4px; border-radius: 0 4px 4px 0;
background: var(--ac, var(--brand));
box-shadow: 0 0 28px var(--ac, var(--brand));
}
.ann-ring {
position: absolute; top: 50%; left: 50%;
width: 10px; height: 10px; border-radius: 50%;
transform: translate(-50%,-50%); pointer-events: none;
}
.ann-ring.pop { animation: ann-pop 1.1s ease-out forwards; } .ann-ring.pop { animation: ann-pop 1.1s ease-out forwards; }
@keyframes ann-pop { 0%{transform:translate(-50%,-50%) scale(1);background:var(--ac,var(--brand));opacity:.4} 100%{transform:translate(-50%,-50%) scale(55);background:var(--ac,var(--brand));opacity:0} } @keyframes ann-pop {
.ann-label { font-size: clamp(.68rem,1.5vw,.88rem); font-weight: 700; text-transform: uppercase; letter-spacing: 3.5px; color: rgba(255,255,255,.42); margin-bottom: .5rem; } 0% { transform:translate(-50%,-50%) scale(1); background:var(--ac,var(--brand)); opacity:.4; }
.ann-code { font-size: clamp(5rem,17vw,11rem); font-weight: 900; line-height: 1; letter-spacing: -4px; font-variant-numeric: tabular-nums; color: var(--ac,var(--brand)); text-shadow: 0 0 90px var(--ac,var(--brand))55; position: relative; z-index: 1; } 100% { transform:translate(-50%,-50%) scale(55); background:var(--ac,var(--brand)); opacity:0; }
.ann-pac { font-size: clamp(.85rem,2.1vw,1.25rem); font-weight: 700; color: rgba(255,255,255,.72); margin-top: .55rem; min-height: 1.5em; } }
.ann-chip { display: inline-flex; align-items: center; gap: .35rem; padding: .34rem 1.1rem; border-radius: 99px; font-size: clamp(.6rem,1.05vw,.8rem); font-weight: 700; margin-top: .7rem; border: 1px solid; } .ann-label {
.ann-progress { width: 100%; height: 3px; background: rgba(255,255,255,.07); border-radius: 99px; margin-top: 1.7rem; overflow: hidden; } font-size: clamp(.7rem, 1.5vw, .92rem); font-weight: 700;
.ann-bar { height: 100%; width: 100%; border-radius: 99px; background: var(--ac,var(--brand)); box-shadow: 0 0 12px var(--ac,var(--brand)); } text-transform: uppercase; letter-spacing: 3.5px;
color: rgba(255,255,255,.44); margin-bottom: .5rem;
}
.ann-code {
font-size: clamp(5rem, 17vw, 11rem); font-weight: 900;
line-height: 1; letter-spacing: -4px;
font-variant-numeric: tabular-nums;
color: var(--ac, var(--brand));
text-shadow: 0 0 90px var(--ac, var(--brand))55;
position: relative; z-index: 1;
}
.ann-pac {
font-size: clamp(.88rem, 2.2vw, 1.3rem); font-weight: 700;
color: rgba(255,255,255,.72); margin-top: .55rem; min-height: 1.5em;
}
.ann-chip {
display: inline-flex; align-items: center; gap: .35rem;
padding: .34rem 1.1rem; border-radius: 99px;
font-size: clamp(.62rem, 1.05vw, .82rem); font-weight: 700;
margin-top: .7rem; border: 1px solid;
}
.ann-progress {
width: 100%; height: 3px;
background: rgba(255,255,255,.07);
border-radius: 99px; margin-top: 1.7rem; overflow: hidden;
}
.ann-bar {
height: 100%; width: 100%; border-radius: 99px;
background: var(--ac, var(--brand));
box-shadow: 0 0 12px var(--ac, var(--brand));
}
</style> </style>
</head> </head>
<body> <body>
<!-- ══ Announcement overlay ══════════════════════════════════════ --> <!-- ══ Announcement overlay ══════════════════════════════════════ -->
<div id="ann-overlay"> <div id="ann-overlay">
<div class="ann-bg" id="ann-bg"></div> <div class="ann-bg" id="ann-bg"></div>
<div class="ann-card"> <div class="ann-card">
@@ -370,7 +403,7 @@ if ($_tvVideo && !preg_match('#^https?://#', $_tvVideo)) { $_tvVideo = ''; }
<div class="pg-wrap"> <div class="pg-wrap">
<header class="pg-header"> <header class="pg-header">
<div class="header-brand"> <div class="hd-brand">
<?php if ($_labLogo): ?> <?php if ($_labLogo): ?>
<img class="logo" src="<?= htmlspecialchars($_labLogo) ?>" alt="Logo"> <img class="logo" src="<?= htmlspecialchars($_labLogo) ?>" alt="Logo">
<?php endif; ?> <?php endif; ?>
@@ -379,33 +412,52 @@ if ($_tvVideo && !preg_match('#^https?://#', $_tvVideo)) { $_tvVideo = ''; }
<span class="lab-sub">Sistema de Turnos — Vista General</span> <span class="lab-sub">Sistema de Turnos — Vista General</span>
</div> </div>
</div> </div>
<div class="header-right"> <div class="hd-right">
<div class="live-dot" title="En línea"></div> <div class="live-dot" title="En línea"></div>
<button class="btn-son" id="btn-sonido" onclick="event.stopPropagation();activarSonido()"> <button class="btn-son" id="btn-sonido" onclick="event.stopPropagation();activarSonido()">
<i class="fas fa-volume-mute"></i> Sonido <i class="fas fa-volume-mute"></i> Sonido
</button> </button>
<button class="btn-fs" id="btn-fs" onclick="toggleFullscreen()" title="Pantalla completa"> <button class="btn-fs" onclick="toggleFullscreen()" title="Pantalla completa">
<i class="fas fa-expand" id="fs-icon"></i> <i class="fas fa-expand" id="fs-icon"></i>
</button> </button>
<div class="reloj" id="reloj">--:--:--</div> <div class="reloj" id="reloj">--:--:--</div>
</div> </div>
</header> </header>
<div class="pg-body"> <div class="pg-body <?= $_hasVideo ? 'has-video' : 'no-video' ?>">
<?php if ($_tvVideo): ?>
<video class="tv-bg-video" autoplay muted loop playsinline> <?php if ($_hasVideo): ?>
<source src="<?= htmlspecialchars($_tvVideo) ?>"> <!-- Layout con video: recepción+muestras apiladas (izq) | video (der) -->
</video> <div class="turnos-area">
<div class="section-panel">
<div class="sec-hdr rec"><i class="fas fa-door-open"></i> Recepción</div>
<div class="slots-row" id="rec-grid"></div>
</div>
<div class="section-panel">
<div class="sec-hdr mue"><i class="fas fa-vials"></i> Toma de Muestras</div>
<div class="slots-row" id="lugares-grid"></div>
</div>
</div>
<div class="video-panel">
<video autoplay muted loop playsinline>
<source src="<?= htmlspecialchars($_tvVideo) ?>">
</video>
</div>
<?php else: ?>
<!-- Layout sin video: recepción (izq) | muestras (der) -->
<div class="turnos-area">
<div class="section-panel">
<div class="sec-hdr rec"><i class="fas fa-door-open"></i> Recepción</div>
<div class="slots-row" id="rec-grid"></div>
</div>
</div>
<div class="mue-panel">
<div class="sec-hdr mue"><i class="fas fa-vials"></i> Toma de Muestras</div>
<div class="slots-row" id="lugares-grid"></div>
</div>
<?php endif; ?> <?php endif; ?>
<div class="area-col">
<div class="col-hdr rec"><i class="fas fa-door-open"></i> Recepción</div>
<div class="slot-grid" id="rec-grid"></div>
</div>
<div class="v-split"></div>
<div class="area-col">
<div class="col-hdr mue"><i class="fas fa-vials"></i> Toma de Muestras</div>
<div class="slot-grid" id="lugares-grid"></div>
</div>
</div> </div>
<div class="pg-cola" id="pg-cola"> <div class="pg-cola" id="pg-cola">
@@ -431,7 +483,7 @@ if ($_tvVideo && !preg_match('#^https?://#', $_tvVideo)) { $_tvVideo = ''; }
<script> <script>
const BASE_API = '<?= BASE_URL ?>modules/turnero/api/'; const BASE_API = '<?= BASE_URL ?>modules/turnero/api/';
// ── Reloj ────────────────────────────────────────────────────── /* ── Reloj ──────────────────────────────────────────────────────── */
function tick() { function tick() {
const d = new Date(); const d = new Date();
document.getElementById('reloj').textContent = document.getElementById('reloj').textContent =
@@ -441,7 +493,7 @@ function tick() {
} }
tick(); setInterval(tick, 1000); tick(); setInterval(tick, 1000);
// ── Pantalla completa ───────────────────────────────────────── /* ── Pantalla completa ──────────────────────────────────────────── */
function toggleFullscreen() { function toggleFullscreen() {
if (!document.fullscreenElement) { if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().catch(() => {}); document.documentElement.requestFullscreen().catch(() => {});
@@ -454,7 +506,7 @@ document.addEventListener('fullscreenchange', () => {
if (ico) ico.className = document.fullscreenElement ? 'fas fa-compress' : 'fas fa-expand'; if (ico) ico.className = document.fullscreenElement ? 'fas fa-compress' : 'fas fa-expand';
}); });
// ── Audio ────────────────────────────────────────────────────── /* ── Audio ──────────────────────────────────────────────────────── */
let audioCtx = null, sonidoActivo = false; let audioCtx = null, sonidoActivo = false;
function activarSonido() { function activarSonido() {
@@ -505,8 +557,7 @@ function anunciarTurno(codigo, destino) {
} }
} }
// ── Estado previo ────────────────────────────────────────────── /* ── Announcement queue ─────────────────────────────────────────── */
// ── Announcement queue ────────────────────────────────────────
const annQueue = []; const annQueue = [];
let isAnnouncing = false; let isAnnouncing = false;
@@ -515,13 +566,11 @@ function queueAnnouncement(item) {
annQueue.push(item); annQueue.push(item);
if (!isAnnouncing) processQueue(); if (!isAnnouncing) processQueue();
} }
function processQueue() { function processQueue() {
if (annQueue.length === 0) { isAnnouncing = false; return; } if (annQueue.length === 0) { isAnnouncing = false; return; }
isAnnouncing = true; isAnnouncing = true;
showAnnouncement(annQueue.shift()); showAnnouncement(annQueue.shift());
} }
function showAnnouncement({ codigo, destino, paciente, prio_codigo, prio_nombre, color }) { function showAnnouncement({ codigo, destino, paciente, prio_codigo, prio_nombre, color }) {
const ov = document.getElementById('ann-overlay'); const ov = document.getElementById('ann-overlay');
const bg = document.getElementById('ann-bg'); const bg = document.getElementById('ann-bg');
@@ -564,11 +613,11 @@ function showAnnouncement({ codigo, destino, paciente, prio_codigo, prio_nombre,
}, 1950); }, 1950);
} }
// ── State ─────────────────────────────────────────────── /* ── State ──────────────────────────────────────────────────────── */
const lastRec = {}; const lastRec = {};
const lastLugar = {}; const lastLugar = {};
// ── Helpers ─────────────────────────────────────────────────── /* ── Helpers ────────────────────────────────────────────────────── */
function esc(s) { function esc(s) {
const d = document.createElement('div'); const d = document.createElement('div');
d.appendChild(document.createTextNode(String(s ?? ''))); d.appendChild(document.createTextNode(String(s ?? '')));
@@ -576,21 +625,23 @@ function esc(s) {
} }
function buildSlot(id, nombre, turno, tipo) { function buildSlot(id, nombre, turno, tipo) {
const has = !!turno; const has = !!turno;
const c = has ? (turno.prioridad_color || '#1565c0') : null; const c = has ? (turno.prioridad_color || '#1565c0') : null;
const pcSt = c ? '--pc:' + c + ';' : ''; const slotCl = has ? 'slot lit' : 'slot';
const cls = has ? 'slot-body lit' : 'slot-body'; const slotSt = c ? ' style="--pc:' + c + '"' : '';
const hCls = tipo === 'rec' ? 'slot-hdr rec' : 'slot-hdr mue'; const bodyCl = has ? 'slot-body lit' : 'slot-body';
const icon = tipo === 'rec' ? 'fas fa-concierge-bell' : 'fas fa-flask'; const bodySt = c ? '--pc:' + c + ';' : '';
const cod = has ? esc(turno.codigo) : '—'; const hCls = tipo === 'rec' ? 'slot-hdr rec' : 'slot-hdr mue';
const pac = has ? esc(turno.paciente_nombre || '') : ''; const icon = tipo === 'rec' ? 'fas fa-concierge-bell' : 'fas fa-flask';
const chip = has const cod = has ? esc(turno.codigo) : '—';
const pac = has ? esc(turno.paciente_nombre || '') : '';
const chip = has
? "<i class='fas fa-ticket-alt'></i> " + esc(turno.prioridad_codigo) + ' — ' + esc(turno.prioridad_nombre) ? "<i class='fas fa-ticket-alt'></i> " + esc(turno.prioridad_codigo) + ' — ' + esc(turno.prioridad_nombre)
: "<i class='fas fa-hourglass-half'></i> En espera"; : "<i class='fas fa-hourglass-half'></i> En espera";
const chipSt = has && c ? 'style="color:' + c + ';border-color:' + c + '44;background:' + c + '15"' : ''; const chipSt = has && c ? 'style="color:' + c + ';border-color:' + c + '44;background:' + c + '15"' : '';
return '<div class="slot" id="slot-' + tipo + '-' + id + '">' return '<div class="' + slotCl + '" id="slot-' + tipo + '-' + id + '"' + slotSt + '>'
+ '<div class="' + hCls + '"><span class="hdot"></span><i class="' + icon + '"></i> ' + esc(nombre) + '</div>' + '<div class="' + hCls + '"><i class="' + icon + '"></i> ' + esc(nombre) + '</div>'
+ '<div class="' + cls + '" id="body-' + tipo + '-' + id + '" style="' + pcSt + '">' + '<div class="' + bodyCl + '" id="body-' + tipo + '-' + id + '" style="' + bodySt + '">'
+ '<div class="ring-pop-el" id="ring-' + tipo + '-' + id + '"></div>' + '<div class="ring-pop-el" id="ring-' + tipo + '-' + id + '"></div>'
+ '<div class="lbl-dest">' + esc(nombre) + '</div>' + '<div class="lbl-dest">' + esc(nombre) + '</div>'
+ '<div class="big-code" id="cod-' + tipo + '-' + id + '">' + cod + '</div>' + '<div class="big-code" id="cod-' + tipo + '-' + id + '">' + cod + '</div>'
@@ -600,15 +651,17 @@ function buildSlot(id, nombre, turno, tipo) {
} }
function updateSlot(id, turno, tipo) { function updateSlot(id, turno, tipo) {
const body = document.getElementById('body-' + tipo + '-' + id); const slotEl = document.getElementById('slot-' + tipo + '-' + id);
const cod = document.getElementById('cod-' + tipo + '-' + id); const body = document.getElementById('body-' + tipo + '-' + id);
const pac = document.getElementById('pac-' + tipo + '-' + id); const cod = document.getElementById('cod-' + tipo + '-' + id);
const chip = document.getElementById('chip-' + tipo + '-' + id); const pac = document.getElementById('pac-' + tipo + '-' + id);
const chip = document.getElementById('chip-' + tipo + '-' + id);
if (!body) return false; if (!body) return false;
const c = turno ? (turno.prioridad_color || '#1565c0') : null; const c = turno ? (turno.prioridad_color || '#1565c0') : null;
if (turno) { if (turno) {
body.className = 'slot-body lit'; body.className = 'slot-body lit';
body.style.setProperty('--pc', c); body.style.setProperty('--pc', c);
if (slotEl) { slotEl.className = 'slot lit'; slotEl.style.setProperty('--pc', c); }
cod.textContent = turno.codigo; cod.textContent = turno.codigo;
pac.textContent = turno.paciente_nombre || ''; pac.textContent = turno.paciente_nombre || '';
chip.innerHTML = "<i class='fas fa-ticket-alt'></i> " + esc(turno.prioridad_codigo) + ' — ' + esc(turno.prioridad_nombre); chip.innerHTML = "<i class='fas fa-ticket-alt'></i> " + esc(turno.prioridad_codigo) + ' — ' + esc(turno.prioridad_nombre);
@@ -616,6 +669,7 @@ function updateSlot(id, turno, tipo) {
} else { } else {
body.className = 'slot-body'; body.className = 'slot-body';
body.style.removeProperty('--pc'); body.style.removeProperty('--pc');
if (slotEl) { slotEl.className = 'slot'; slotEl.style.removeProperty('--pc'); }
cod.textContent = '—'; cod.textContent = '—';
pac.textContent = ''; pac.textContent = '';
chip.innerHTML = "<i class='fas fa-hourglass-half'></i> En espera"; chip.innerHTML = "<i class='fas fa-hourglass-half'></i> En espera";
@@ -624,7 +678,7 @@ function updateSlot(id, turno, tipo) {
return true; return true;
} }
// ── Render ──────────────────────────────────────────────────── /* ── Render snapshot ────────────────────────────────────────────── */
function renderSnapshot(snap) { function renderSnapshot(snap) {
const recList = snap.activos_recepcion || []; const recList = snap.activos_recepcion || [];
const mueList = snap.lugares || []; const mueList = snap.lugares || [];
@@ -700,7 +754,7 @@ function renderSnapshot(snap) {
? s.tiempo_promedio_atencion.substring(0, 5) : '—'; ? s.tiempo_promedio_atencion.substring(0, 5) : '—';
} }
// ── Polling ─────────────────────────────────────────────────── /* ── Polling ─────────────────────────────────────────────────────── */
async function cargarSnapshot() { async function cargarSnapshot() {
try { try {
const res = await fetch(BASE_API + 'get_display_global.php', { cache: 'no-store' }); const res = await fetch(BASE_API + 'get_display_global.php', { cache: 'no-store' });
+2 -2
View File
@@ -98,7 +98,7 @@ Layout::open('Historial de Turnos', 'fas fa-history');
<!-- ── Encabezado ────────────────────────────────────────────── --> <!-- ── Encabezado ────────────────────────────────────────────── -->
<div class="page-header"> <div class="page-header">
<a href="<?= BASE_URL ?>/erp.php?m=turnero&v=dashboard" class="text-muted text-decoration-none small"> <a href="<?= BASE_URL ?>erp.php?m=turnero&v=dashboard" class="text-muted text-decoration-none small">
<i class="fas fa-arrow-left me-1"></i>Dashboard <i class="fas fa-arrow-left me-1"></i>Dashboard
</a> </a>
<h1><i class="fas fa-history me-2 text-primary"></i>Historial de Turnos</h1> <h1><i class="fas fa-history me-2 text-primary"></i>Historial de Turnos</h1>
@@ -205,7 +205,7 @@ Layout::open('Historial de Turnos', 'fas fa-history');
/* ═══════════════════════════════════════════════════════════ /* ═══════════════════════════════════════════════════════════
Historial de Turnos Historial de Turnos
═══════════════════════════════════════════════════════════ */ ═══════════════════════════════════════════════════════════ */
const API = '<?= BASE_URL ?>/modules/turnero/api/'; const API = '<?= BASE_URL ?>modules/turnero/api/';
let _state = { let _state = {
fechaDesde : '', fechaDesde : '',