From 44b737c2532132fa5ea172f2df1cc8162709a5a9 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 30 Jul 2026 18:14:13 -0500 Subject: [PATCH] feat(tiempos): agregar tiempo total puerta a puerta en historial y dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - APIs: total_min = creado_at β†’ fin_lugar_at (solo finalizados) - Dashboard: KPI card 'Total prom. puerta a puerta' + columna Total en tabla - Historial: columna Total en tabla Co-Authored-By: Claude Sonnet 4.6 --- modules/turnero/api/get_dashboard.php | 13 +++++++++++-- modules/turnero/api/get_historial.php | 4 +++- modules/turnero/views/dashboard.php | 7 ++++++- modules/turnero/views/historial.php | 5 ++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/modules/turnero/api/get_dashboard.php b/modules/turnero/api/get_dashboard.php index 52ab270..148fd1f 100644 --- a/modules/turnero/api/get_dashboard.php +++ b/modules/turnero/api/get_dashboard.php @@ -73,7 +73,15 @@ $stmtRes = $pdo->prepare( THEN TIMESTAMPDIFF(SECOND, inicio_lugar_at, fin_lugar_at) / 60.0 END ), 1 - ) AS tiempo_servicio_promedio_min + ) AS tiempo_servicio_promedio_min, + ROUND( + AVG( + CASE + WHEN fin_lugar_at IS NOT NULL AND creado_at IS NOT NULL + THEN TIMESTAMPDIFF(SECOND, creado_at, fin_lugar_at) / 60.0 + END + ), 1 + ) AS tiempo_total_promedio_min FROM turnero_turnos WHERE sesion_id = ?" ); @@ -133,7 +141,8 @@ $stmtTurnos = $pdo->prepare( ul.full_name AS atendido_lugar_nombre, ts.observaciones AS notas, ROUND(TIMESTAMPDIFF(SECOND, t.creado_at, COALESCE(t.inicio_recepcion_at, NOW())) / 60.0, 1) AS espera_min, - ROUND(TIMESTAMPDIFF(SECOND, t.inicio_lugar_at, COALESCE(t.fin_lugar_at, NOW())) / 60.0, 1) AS servicio_min + ROUND(TIMESTAMPDIFF(SECOND, t.inicio_lugar_at, COALESCE(t.fin_lugar_at, NOW())) / 60.0, 1) AS servicio_min, + ROUND(TIMESTAMPDIFF(SECOND, t.creado_at, t.fin_lugar_at) / 60.0, 1) AS total_min FROM turnero_turnos t JOIN turnero_prioridades p ON p.id = t.prioridad_id LEFT JOIN turnero_lugares l ON l.id = t.lugar_destino_id diff --git a/modules/turnero/api/get_historial.php b/modules/turnero/api/get_historial.php index 39773a3..3e7d06e 100644 --- a/modules/turnero/api/get_historial.php +++ b/modules/turnero/api/get_historial.php @@ -116,7 +116,9 @@ $sqlTurnos = " AS espera_min, ROUND(TIMESTAMPDIFF(SECOND, t.inicio_lugar_at, COALESCE(t.fin_lugar_at, NOW())) / 60.0, 1) - AS servicio_min + AS servicio_min, + ROUND(TIMESTAMPDIFF(SECOND, t.creado_at, t.fin_lugar_at) / 60.0, 1) + AS total_min FROM turnero_turnos t JOIN turnero_sesiones s ON s.id = t.sesion_id JOIN turnero_prioridades p ON p.id = t.prioridad_id diff --git a/modules/turnero/views/dashboard.php b/modules/turnero/views/dashboard.php index f64d819..1760faf 100644 --- a/modules/turnero/views/dashboard.php +++ b/modules/turnero/views/dashboard.php @@ -240,6 +240,7 @@ try { Estado Espera Serv. + Total @@ -344,6 +345,7 @@ function renderDashboard(json) { const cancelados= parseInt(resumen.cancelados || 0); const tEspera = resumen.tiempo_espera_promedio_min; const tServicio = resumen.tiempo_servicio_promedio_min; + const tTotal = resumen.tiempo_total_promedio_min; const pct = total > 0 ? Math.round(atendidos / total * 100) : 0; document.getElementById('kpiGrid').innerHTML = ` @@ -352,8 +354,9 @@ function renderDashboard(json) { ${kpiCard(enEspera, '⏳ En espera', '')} ${kpiCard(ausentes, '🚫 Ausentes', '')} ${kpiCard(cancelados,'❌ Cancelados', '')} - ${kpiCard(tEspera !== null ? tEspera + ' min' : 'β€”', '⏱ Espera prom.', 'hasta recepciΓ³n')} + ${kpiCard(tEspera !== null ? tEspera + ' min' : 'β€”', '⏱ Espera prom.', 'hasta recepciΓ³n')} ${kpiCard(tServicio !== null ? tServicio + ' min' : 'β€”', '⏱ Servicio prom.', 'en lugar')} + ${kpiCard(tTotal !== null ? tTotal + ' min' : 'β€”', '⏱ Total prom.', 'puerta a puerta')} `; // ── Consentimientos ──────────────────────────────────── @@ -451,6 +454,7 @@ function renderTabla(turnos) { const estadoLbl = labelEstado[t.estado] || t.estado; const espMin = t.espera_min !== null ? t.espera_min + ' m' : 'β€”'; const srvMin = t.servicio_min !== null ? t.servicio_min + ' m' : 'β€”'; + const totMin = t.total_min !== null ? t.total_min + ' m' : 'β€”'; const rowId = `dash-det-${t.id}`; // RecepciΓ³n @@ -478,6 +482,7 @@ function renderTabla(turnos) { ${estadoLbl} ${espMin} ${srvMin} + ${totMin} diff --git a/modules/turnero/views/historial.php b/modules/turnero/views/historial.php index 1c7c63f..6a6f5b6 100644 --- a/modules/turnero/views/historial.php +++ b/modules/turnero/views/historial.php @@ -214,6 +214,7 @@ Layout::open('Historial de Turnos', 'fas fa-history'); Estado Espera Servicio + Total @@ -407,7 +408,7 @@ const ESTADO_LBL = { function renderTabla(turnos) { const tbody = document.getElementById('tbody'); if (!turnos.length) { - tbody.innerHTML = ` + tbody.innerHTML = `
Sin resultados para los filtros aplicados
`; return; @@ -425,6 +426,7 @@ function renderTabla(turnos) { : 'β€”'; const espMin = t.espera_min != null ? t.espera_min + ' m' : 'β€”'; const srvMin = t.servicio_min != null ? t.servicio_min + ' m' : 'β€”'; + const totMin = t.total_min != null ? t.total_min + ' m' : 'β€”'; const tel = esc(t.paciente_cel || 'β€”'); const priCls = esc(t.prioridad_color || '#888'); const cls = ESTADO_CLS[t.estado] || 'eb-finalizado'; @@ -467,6 +469,7 @@ function renderTabla(turnos) { ${lbl} ${espMin} ${srvMin} + ${totMin}