Implementar Buscador Universal SINPE Móvil y suite de auditoría y conciliación Developer

This commit is contained in:
unknown
2026-10-09 02:24:00 -06:00
parent e784a84f10
commit 87125987b1
5 changed files with 1918 additions and 13 deletions
+369 -4
View File
@@ -247,6 +247,11 @@
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span>Carga Masiva (Excel/CSV)</span>
</button>
<button class="dev-tab-btn" id="btnDevTabSinpe" onclick="switchDevTab('sinpe')" style="display: inline-flex; align-items: center; gap: 8px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
<span>🔍 Buscador SINPE Móvil</span>
<span id="devSinpePendingBadge" style="display: none; background: #ef4444; color: #ffffff; font-size: 0.68rem; font-weight: 900; padding: 2px 7px; border-radius: 999px; line-height: 1;">0</span>
</button>
</nav>
<!-- 1. PESTAÑA: USUARIOS Y ADMINISTRADORES -->
@@ -593,6 +598,171 @@
<div id="devImportResultMsg" style="display: none; margin-top: 16px; padding: 14px; border-radius: 12px; font-size: 0.84rem; line-height: 1.45;"></div>
</div>
</div>
<!-- 6. PESTAÑA: BUSCADOR UNIVERSAL SINPE MÓVIL & AUDITORÍA -->
<div id="devTabContentSinpe" class="dev-tab-content" style="display: none;">
<!-- CABECERA Y ACCIONES RÁPIDAS -->
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; flex-wrap: wrap; gap: 14px;">
<div>
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 38px; height: 38px; border-radius: 12px; background: linear-gradient(135deg, #0284c7, #0369a1); color: #ffffff; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; box-shadow: 0 4px 12px rgba(2,132,199,0.3);">
🔍
</div>
<div>
<h3 style="margin: 0; font-size: 1.25rem; font-weight: 900; color: var(--text-main);">Buscador Universal de SINPE Móvil & Conciliación</h3>
<p style="margin: 3px 0 0 0; font-size: 0.82rem; color: var(--text-muted);">Auditoría global en tiempo real de comprobantes, solicitudes de padres, depósitos bancarios y resolución de disputas.</p>
</div>
</div>
</div>
<div style="display: flex; gap: 8px; flex-wrap: wrap; align-items: center;">
<button type="button" onclick="loadDevSinpeUniversal()" class="dev-action-btn" style="padding: 9px 15px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px;" title="Actualizar datos en tiempo real">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.5 2v6h-6M2.5 22v-6h6M2 11.5a10 10 0 0 1 18.8-4.3M22 12.5a10 10 0 0 1-18.8 4.2"/></svg>
<span>Actualizar</span>
</button>
<button type="button" onclick="openModalDevSimularSinpe()" class="dev-action-btn" style="padding: 9px 15px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px; background: #f0fdf4; color: #166534; border: 1.5px solid #bbf7d0; font-weight: 800;" title="Simular depósito bancario para pruebas">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>
<span>⚡ Simular Depósito Banco</span>
</button>
<button type="button" onclick="exportarSinpeUniversalCsv()" class="dev-action-btn" style="padding: 9px 15px; font-size: 0.84rem; display: inline-flex; align-items: center; gap: 6px;" title="Descargar reporte en Excel / CSV">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
<span>Descargar CSV</span>
</button>
</div>
</div>
<!-- KPIS EN TIEMPO REAL -->
<div id="devSinpeKpiGrid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 22px;">
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="font-size: 0.72rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between;">
<span>Acreditado SINPE</span>
<span style="color: #10b981; font-size: 1rem;">💳</span>
</div>
<div id="devSinpeKpiTotalMonto" style="font-size: 1.35rem; font-weight: 900; color: #10b981;">₡0</div>
<div id="devSinpeKpiTotalCant" style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">0 recargas verificadas</div>
</div>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="font-size: 0.72rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between;">
<span>En Revisión (Pendientes)</span>
<span style="color: #f59e0b; font-size: 1rem;">⏳</span>
</div>
<div id="devSinpeKpiPendientes" style="font-size: 1.35rem; font-weight: 900; color: #f59e0b;">0</div>
<div style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">Requieren verificación</div>
</div>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="font-size: 0.72rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between;">
<span>Rechazadas / Alertas</span>
<span style="color: #ef4444; font-size: 1rem;">⚠️</span>
</div>
<div id="devSinpeKpiRechazadas" style="font-size: 1.35rem; font-weight: 900; color: #ef4444;">0</div>
<div style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">Comprobantes no válidos</div>
</div>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.03);">
<div style="font-size: 0.72rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px; margin-bottom: 6px; display: flex; align-items: center; justify-content: space-between;">
<span>Banco Sin Reclamar</span>
<span style="color: #0284c7; font-size: 1rem;">🏦</span>
</div>
<div id="devSinpeKpiBancoUnclaimed" style="font-size: 1.35rem; font-weight: 900; color: #0284c7;">0</div>
<div id="devSinpeKpiBancoUnclaimedMonto" style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700; margin-top: 2px;">₡0 en depósitos huérfanos</div>
</div>
</div>
<!-- CAJA DE BÚSQUEDA Y FILTROS MULTI-CRITERIO -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 16px; padding: 18px; margin-bottom: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.04);">
<!-- Fila de barra de búsqueda principal -->
<div style="display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap;">
<div style="position: relative; flex: 1; min-width: 280px;">
<input type="text" id="devSinpeSearchInput" placeholder="Buscar por comprobante (ej: BAC244304, 303063), cód. detalle (SIBO-XC69), estudiante, teléfono padre..." oninput="debounceDevSinpeSearch()" style="width: 100%; padding: 12px 38px 12px 42px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.90rem; font-weight: 700; box-sizing: border-box;">
<div style="position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none;">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
</div>
<button type="button" onclick="clearDevSinpeSearch()" id="btnDevSinpeClearSearch" style="position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 1.1rem; color: var(--text-muted); cursor: pointer; display: none;">✕</button>
</div>
<button type="button" onclick="loadDevSinpeUniversal()" class="dev-action-btn dev-action-btn-primary" style="padding: 12px 22px; font-size: 0.90rem; font-weight: 800; display: inline-flex; align-items: center; gap: 8px;">
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
<span>Buscar</span>
</button>
</div>
<!-- Fila de filtros selectivos -->
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px;">
<div>
<label style="font-size: 0.74rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 4px;">Estado:</label>
<select id="devSinpeFilterEstado" onchange="loadDevSinpeUniversal()" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; font-weight: 700;">
<option value="todas">Todos los Estados</option>
<option value="pendiente">⏳ Solo Pendientes</option>
<option value="aprobada">✓ Aprobadas / Acreditadas</option>
<option value="rechazada">✕ Rechazadas</option>
<option value="unclaimed">🏦 Banco Sin Reclamar</option>
</select>
</div>
<div>
<label style="font-size: 0.74rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 4px;">Escuela / Sede:</label>
<select id="devSinpeFilterEscuela" onchange="loadDevSinpeUniversal()" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; font-weight: 700;">
<option value="todas">Todas las Escuelas</option>
</select>
</div>
<div>
<label style="font-size: 0.74rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 4px;">Rango de Fecha:</label>
<select id="devSinpeFilterFecha" onchange="loadDevSinpeUniversal()" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; font-weight: 700;">
<option value="todas">Todo el Historial</option>
<option value="hoy">Hoy</option>
<option value="7dias">Últimos 7 días</option>
<option value="30dias">Últimos 30 días</option>
</select>
</div>
<div>
<label style="font-size: 0.74rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 4px;">Tipo de Registro:</label>
<select id="devSinpeFilterOrigen" onchange="loadDevSinpeUniversal()" style="width: 100%; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; font-weight: 700;">
<option value="todas">Todo Unificado</option>
<option value="solicitudes">📱 Solicitudes de Padres</option>
<option value="banco">🏦 Notificaciones Bancarias</option>
<option value="saldo">💳 Movimientos de Saldo</option>
</select>
</div>
</div>
</div>
<!-- LISTADO DE RESULTADOS -->
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: 0 4px 15px rgba(0,0,0,0.04);">
<div style="padding: 14px 18px; border-bottom: 1.5px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px;">
<div style="font-weight: 800; font-size: 0.88rem; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
<span>Resultados de Búsqueda</span>
<span id="devSinpeResultCountBadge" style="background: #e0f2fe; color: #0284c7; padding: 2px 8px; border-radius: 8px; font-size: 0.75rem; font-weight: 800;">0 registros</span>
</div>
<span style="font-size: 0.76rem; color: var(--text-muted);">Haz clic en cualquier acción para gestionar o auditar</span>
</div>
<div style="overflow-x: auto; max-height: 600px; overflow-y: auto;">
<table class="dev-table" style="width: 100%; border-collapse: collapse; font-size: 0.82rem; text-align: left;">
<thead style="position: sticky; top: 0; background: var(--card-bg); z-index: 2; border-bottom: 1.5px solid var(--border);">
<tr style="color: var(--text-muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.5px;">
<th style="padding: 12px 14px;">Fecha / Hora</th>
<th style="padding: 12px 14px;">Comprobante / Detalle</th>
<th style="padding: 12px 14px;">Origen</th>
<th style="padding: 12px 14px;">Estudiante / Sede</th>
<th style="padding: 12px 14px;">Remitente / Banco</th>
<th style="padding: 12px 14px;">Monto</th>
<th style="padding: 12px 14px;">Estado</th>
<th style="padding: 12px 14px; text-align: right;">Acciones</th>
</tr>
</thead>
<tbody id="devSinpeTableBody">
<tr>
<td colspan="8" style="text-align: center; padding: 30px; color: var(--text-muted);">
Cargando transacciones de SINPE Móvil...
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- PANEL DE ADMINISTRACIÓN DE LA SODA (#viewAdmin) -->
@@ -3689,6 +3859,201 @@
</div>
</div>
<!-- ======================================================== -->
<!-- MODALES DE CONTROL DEVELOPER: BUSCADOR Y AUDITORÍA SINPE -->
<!-- ======================================================== -->
<!-- 1. MODAL: FICHA TÉCNICA Y AUDITORÍA DE TRANSACCIÓN SINPE -->
<div class="modal-qr-backdrop" id="modalDevSinpeDetalle" style="display: none;" onclick="closeModalDevSinpeDetalle()">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 560px; text-align: left; padding: 24px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 14px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.2rem;">
🔍
</div>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Ficha de Auditoría SINPE</h3>
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Detalle completo de trazabilidad bancaria</span>
</div>
</div>
<button type="button" onclick="closeModalDevSinpeDetalle()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<div id="modalDevSinpeDetalleBody" style="max-height: 480px; overflow-y: auto; padding-right: 4px;">
<!-- Inyectado dinámicamente -->
</div>
<div style="display: flex; justify-content: space-between; align-items: center; border-top: 1.5px solid var(--border); padding-top: 14px; margin-top: 16px; flex-wrap: wrap; gap: 10px;">
<button type="button" onclick="copiarMensajeSoporteWhatsAppSinpe()" class="dev-action-btn" style="padding: 9px 15px; font-size: 0.82rem; display: inline-flex; align-items: center; gap: 6px; background: #f0fdf4; color: #166534; border: 1.5px solid #bbf7d0; font-weight: 800;">
<span>💬 Copiar para WhatsApp</span>
</button>
<div id="modalDevSinpeDetalleActions" style="display: flex; gap: 8px;">
<!-- Inyectado dinámicamente según el estado -->
</div>
</div>
</div>
</div>
<!-- 2. MODAL: RECHAZAR SOLICITUD SINPE DEVELOPER -->
<div class="modal-qr-backdrop" id="modalDevSinpeRechazar" style="display: none;" onclick="closeModalDevSinpeRechazar()">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 480px; text-align: left; padding: 22px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #fef2f2; color: #ef4444; display: flex; align-items: center; justify-content: center; font-size: 1.2rem;">
⚠️
</div>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: #ef4444;">Rechazar Recarga SINPE</h3>
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Se registrará en auditoría y notificará al padre</span>
</div>
</div>
<button type="button" onclick="closeModalDevSinpeRechazar()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formDevSinpeRechazar" onsubmit="ejecutarRechazoSinpeDev(event)">
<input type="hidden" id="devRechazoSolicitudId">
<div style="margin-bottom: 14px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Motivo Frecuente:</label>
<select id="devRechazoSelectMotivo" onchange="actualizarTextoMotivoRechazoDev()" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.85rem;">
<option value="Comprobante no verificado en cuenta bancaria">Comprobante no aparece en la cuenta bancaria</option>
<option value="El monto transferido no coincide con la solicitud">Monto no coincide con lo reportado</option>
<option value="Comprobante duplicado ya utilizado anteriormente">Comprobante duplicado / ya utilizado</option>
<option value="Comprobante ilegible o incompleto">Comprobante ilegible o cortado</option>
<option value="otro">Otro motivo personalizado...</option>
</select>
</div>
<div style="margin-bottom: 18px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Detalle o Explicación para el Usuario:</label>
<textarea id="devRechazoTextoExplicacion" rows="3" required style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.85rem; font-weight: 600; box-sizing: border-box;"></textarea>
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
<button type="button" onclick="closeModalDevSinpeRechazar()" style="padding: 10px 16px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" id="btnDevConfirmarRechazo" class="dev-action-btn dev-action-btn-danger" style="padding: 10px 20px; font-size: 0.88rem; font-weight: 800;">
Confirmar Rechazo
</button>
</div>
</form>
</div>
</div>
<!-- 3. MODAL: VINCULAR DEPÓSITO BANCARIO HUÉRFANO A UN ESTUDIANTE -->
<div class="modal-qr-backdrop" id="modalDevSinpeVincular" style="display: none;" onclick="closeModalDevSinpeVincular()">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 520px; text-align: left; padding: 22px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #f0f9ff; color: #0284c7; display: flex; align-items: center; justify-content: center; font-size: 1.2rem;">
🔗
</div>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Vincular Depósito Bancario</h3>
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Asignar dinero huérfano al monedero de un alumno</span>
</div>
</div>
<button type="button" onclick="closeModalDevSinpeVincular()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formDevSinpeVincular" onsubmit="ejecutarVinculacionBancoDev(event)">
<input type="hidden" id="devVincularBancoTxId">
<!-- Resumen del depósito bancario -->
<div id="devVincularDepositoResumen" style="background: #f8fafc; border: 1.5px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 16px; font-size: 0.82rem; line-height: 1.5;">
<!-- Inyectado dinámicamente -->
</div>
<div style="margin-bottom: 16px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Buscar Estudiante Beneficiario: *</label>
<input type="text" id="devVincularEstudianteSearch" placeholder="Escribe el nombre del alumno o carné..." oninput="filtrarEstudiantesParaVincular()" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.86rem; font-weight: 700; box-sizing: border-box; margin-bottom: 6px;">
<select id="devVincularEstudianteSelect" required size="5" style="width: 100%; padding: 6px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-size: 0.82rem; font-weight: 600;">
<!-- Opciones inyectadas -->
</select>
</div>
<div style="margin-bottom: 18px;">
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Nota de Auditoría (Opcional):</label>
<input type="text" id="devVincularNotas" placeholder="Ej: Confirmado vía WhatsApp con el padre Carlos" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.84rem; box-sizing: border-box;">
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
<button type="button" onclick="closeModalDevSinpeVincular()" style="padding: 10px 16px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" id="btnDevConfirmarVincular" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.88rem; font-weight: 800;">
Acreditar y Vincular
</button>
</div>
</form>
</div>
</div>
<!-- 4. MODAL: SIMULADOR DE CORREO / NOTIFICACIÓN BANCARIA SINPE -->
<div class="modal-qr-backdrop" id="modalDevSimularSinpe" style="display: none;" onclick="closeModalDevSimularSinpe()">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 480px; text-align: left; padding: 22px;">
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1.5px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;">
<div style="display: flex; align-items: center; gap: 10px;">
<div style="width: 36px; height: 36px; border-radius: 10px; background: #f0fdf4; color: #166534; display: flex; align-items: center; justify-content: center; font-size: 1.2rem;">
⚡
</div>
<div>
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">Simulador de Notificación Bancaria</h3>
<span style="font-size: 0.76rem; color: var(--text-muted); font-weight: 600;">Inyecta una transferencia real o huérfana para pruebas</span>
</div>
</div>
<button type="button" onclick="closeModalDevSimularSinpe()" style="background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-muted); padding: 4px;">✕</button>
</div>
<form id="formDevSimularSinpe" onsubmit="ejecutarSimulacionSinpeDev(event)">
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;">
<div>
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Banco Emisor:</label>
<select id="devSimBanco" style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.84rem;">
<option value="BAC San José">BAC San José</option>
<option value="Banco Nacional">Banco Nacional (BNCR)</option>
<option value="Banco de Costa Rica">Banco de Costa Rica (BCR)</option>
<option value="Banco Popular">Banco Popular</option>
</select>
</div>
<div>
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Monto (₡): *</label>
<input type="number" id="devSimMonto" value="3500" step="500" min="500" required style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.90rem; box-sizing: border-box;">
</div>
</div>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px;">
<div>
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Nombre Remitente:</label>
<input type="text" id="devSimRemitente" value="Carlos Alvarado" style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.84rem; box-sizing: border-box;">
</div>
<div>
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Teléfono Remitente:</label>
<input type="text" id="devSimTelefono" value="88776655" style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.84rem; box-sizing: border-box;">
</div>
</div>
<div style="margin-bottom: 14px;">
<label style="font-size: 0.80rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 4px;">Código de Detalle (Opcional):</label>
<input type="text" id="devSimCodigoDetalle" placeholder="Ej: SIBO-XC69 (deja vacío para depósito huérfano)" style="width: 100%; padding: 9px 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 700; font-size: 0.84rem; box-sizing: border-box;">
<span style="font-size: 0.72rem; color: var(--text-muted);">Si lo dejas vacío, el depósito llegará como 'Sin Reclamar' para probar la vinculación.</span>
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; border-top: 1.5px solid var(--border); padding-top: 14px;">
<button type="button" onclick="closeModalDevSimularSinpe()" style="padding: 10px 16px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-weight: 800; font-size: 0.85rem; cursor: pointer;">
Cancelar
</button>
<button type="submit" id="btnDevConfirmarSimulacion" class="dev-action-btn dev-action-btn-primary" style="padding: 10px 22px; font-size: 0.88rem; font-weight: 800;">
⚡ Disparar Transacción
</button>
</div>
</form>
</div>
</div>
<!-- ======================================================== -->
<!-- MODAL DE VALIDACIÓN Y ESTADO SINPE EN TIEMPO REAL -->
<!-- ======================================================== -->
@@ -4172,10 +4537,10 @@
</button>
</nav>
<script src="/js/dialogs.js?v=18.1"></script>
<script src="/js/sounds.js?v=18.1"></script>
<script src="/js/dialogs.js?v=19.0"></script>
<script src="/js/sounds.js?v=19.0"></script>
<script src="/js/jsQR.js" defer></script>
<script src="/js/food-icons.js?v=18.1" defer></script>
<script src="/js/app.js?v=18.1"></script>
<script src="/js/food-icons.js?v=19.0" defer></script>
<script src="/js/app.js?v=19.0"></script>
</body>
</html>
+864
View File
@@ -616,6 +616,12 @@ function switchDevTab(tab) {
if (btn) btn.classList.add('active');
if (content) content.style.display = 'block';
cargarEscuelasSelectImportacion();
} else if (tab === 'sinpe') {
const btn = document.getElementById('btnDevTabSinpe');
const content = document.getElementById('devTabContentSinpe');
if (btn) btn.classList.add('active');
if (content) content.style.display = 'block';
loadDevSinpeUniversal();
}
}
@@ -9813,3 +9819,861 @@ function triggerGlobalHapticFeedback(e) {
document.addEventListener('touchstart', triggerGlobalHapticFeedback, { passive: true });
document.addEventListener('pointerdown', triggerGlobalHapticFeedback, { passive: true });
// ========================================================
// BUSCADOR UNIVERSAL SINPE MÓVIL Y AUDITORÍA MASTER (DEVELOPER)
// ========================================================
let currentDevSinpeItems = [];
let devSinpeSearchTimer = null;
let currentDevSinpeSelectedItem = null;
let devCachedEstudiantesList = [];
/**
* Carga y actualiza los datos del Buscador Universal de SINPE Móvil
*/
async function loadDevSinpeUniversal() {
const tbody = document.getElementById('devSinpeTableBody');
const countBadge = document.getElementById('devSinpeResultCountBadge');
const pendingBadge = document.getElementById('devSinpePendingBadge');
const q = (document.getElementById('devSinpeSearchInput')?.value || '').trim();
const estado = document.getElementById('devSinpeFilterEstado')?.value || 'todas';
const escuelaId = document.getElementById('devSinpeFilterEscuela')?.value || 'todas';
const fecha = document.getElementById('devSinpeFilterFecha')?.value || 'todas';
const origen = document.getElementById('devSinpeFilterOrigen')?.value || 'todas';
// Mostrar / ocultar botón limpiar
const btnClear = document.getElementById('btnDevSinpeClearSearch');
if (btnClear) btnClear.style.display = q ? 'block' : 'none';
// Poblar select de escuelas si aún no tiene las opciones cargadas
await poblarSelectEscuelasSinpeDev();
if (tbody) {
tbody.innerHTML = `
<tr>
<td colspan="8" style="text-align: center; padding: 35px; color: var(--text-muted);">
<div style="display: inline-flex; align-items: center; gap: 8px;">
<svg class="spin" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.5"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>
<span style="font-weight: 700;">Consultando transacciones SINPE en tiempo real...</span>
</div>
</td>
</tr>
`;
}
try {
const params = new URLSearchParams();
if (q) params.set('q', q);
if (estado !== 'todas') params.set('estado', estado);
if (escuelaId !== 'todas') params.set('escuela_id', escuelaId);
if (fecha !== 'todas') params.set('fecha', fecha);
if (origen !== 'todas') params.set('origen', origen);
const res = await fetch(`/api/developer/sinpe/buscar?${params.toString()}`);
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'Error al consultar transacciones');
// 1. Actualizar KPIs de la cabecera
const kpiMonto = document.getElementById('devSinpeKpiTotalMonto');
const kpiCant = document.getElementById('devSinpeKpiTotalCant');
const kpiPend = document.getElementById('devSinpeKpiPendientes');
const kpiRech = document.getElementById('devSinpeKpiRechazadas');
const kpiBancoUncl = document.getElementById('devSinpeKpiBancoUnclaimed');
const kpiBancoUnclMonto = document.getElementById('devSinpeKpiBancoUnclaimedMonto');
if (kpiMonto) kpiMonto.textContent = `₡${Number(data.resumen?.total_acreditado_sinpe || 0).toLocaleString('es-CR')}`;
if (kpiCant) kpiCant.textContent = `${data.resumen?.total_recargas_count || 0} recargas verificadas`;
if (kpiPend) kpiPend.textContent = data.resumen?.total_pendientes_count || 0;
if (kpiRech) kpiRech.textContent = data.resumen?.total_rechazadas_count || 0;
if (kpiBancoUncl) kpiBancoUncl.textContent = data.resumen?.total_banco_unclaimed_count || 0;
if (kpiBancoUnclMonto) kpiBancoUnclMonto.textContent = `₡${Number(data.resumen?.total_banco_unclaimed_monto || 0).toLocaleString('es-CR')} en depósitos huérfanos`;
// Badge en la pestaña superior
if (pendingBadge) {
const numPend = data.resumen?.total_pendientes_count || 0;
pendingBadge.textContent = numPend;
pendingBadge.style.display = numPend > 0 ? 'inline-block' : 'none';
}
currentDevSinpeItems = data.resultados || [];
if (countBadge) countBadge.textContent = `${currentDevSinpeItems.length} registros`;
renderDevSinpeTable(currentDevSinpeItems);
} catch (err) {
console.error('Error al cargar SINPE dev:', err);
if (tbody) {
tbody.innerHTML = `
<tr>
<td colspan="8" style="text-align: center; padding: 25px; color: #ef4444; font-weight: 700;">
⚠️ Error al cargar transacciones: ${err.message}
</td>
</tr>
`;
}
}
}
window.loadDevSinpeUniversal = loadDevSinpeUniversal;
/**
* Renderiza las filas de la tabla de resultados SINPE
*/
function renderDevSinpeTable(items) {
const tbody = document.getElementById('devSinpeTableBody');
if (!tbody) return;
if (!items || items.length === 0) {
tbody.innerHTML = `
<tr>
<td colspan="8" style="text-align: center; padding: 40px 20px; color: var(--text-muted);">
<div style="font-size: 2.2rem; margin-bottom: 8px;">🔍</div>
<div style="font-weight: 800; font-size: 1rem; color: var(--text-main);">No se encontraron transacciones SINPE</div>
<p style="font-size: 0.82rem; margin: 4px 0 0; color: var(--text-muted);">Intenta ajustar los términos de búsqueda o cambiar los filtros de estado/fecha.</p>
</td>
</tr>
`;
return;
}
tbody.innerHTML = items.map(item => {
// Formatear Fecha
let fechaStr = 'N/A';
if (item.fecha) {
try {
const d = new Date(item.fecha);
fechaStr = d.toLocaleDateString('es-CR', { day: '2-digit', month: '2-digit', year: 'numeric' }) +
' ' + d.toLocaleTimeString('es-CR', { hour: '2-digit', minute: '2-digit', hour12: true });
} catch (e) {
fechaStr = String(item.fecha);
}
}
// Badge de Origen
let origenBadge = '';
if (item.origen === 'solicitud') {
origenBadge = `<span style="background: #f0f9ff; color: #0284c7; border: 1px solid #bae6fd; font-size: 0.70rem; font-weight: 800; padding: 2px 7px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;">📱 Solicitud App</span>`;
} else if (item.origen === 'banco') {
origenBadge = `<span style="background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; font-size: 0.70rem; font-weight: 800; padding: 2px 7px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;">🏦 Banco Notif.</span>`;
} else {
origenBadge = `<span style="background: #f8fafc; color: #475569; border: 1px solid #cbd5e1; font-size: 0.70rem; font-weight: 800; padding: 2px 7px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;">💳 Saldo Directo</span>`;
}
// Badge de Estado
let estadoBadge = '';
if (item.estado === 'aprobada' || item.estado === 'used') {
estadoBadge = `<span style="background: #dcfce7; color: #15803d; border: 1px solid #86efac; font-size: 0.74rem; font-weight: 900; padding: 3px 9px; border-radius: 8px; display: inline-flex; align-items: center; gap: 4px;">✓ Aprobada</span>`;
} else if (item.estado === 'pendiente') {
estadoBadge = `<span style="background: #fef3c7; color: #b45309; border: 1px solid #fde68a; font-size: 0.74rem; font-weight: 900; padding: 3px 9px; border-radius: 8px; display: inline-flex; align-items: center; gap: 4px;">⏳ Pendiente</span>`;
} else if (item.estado === 'rechazada') {
estadoBadge = `<span style="background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; font-size: 0.74rem; font-weight: 900; padding: 3px 9px; border-radius: 8px; display: inline-flex; align-items: center; gap: 4px;">✕ Rechazada</span>`;
} else if (item.estado === 'unclaimed') {
estadoBadge = `<span style="background: #e0f2fe; color: #0369a1; border: 1px solid #7dd3fc; font-size: 0.74rem; font-weight: 900; padding: 3px 9px; border-radius: 8px; display: inline-flex; align-items: center; gap: 4px;">🏦 Sin Reclamar</span>`;
} else {
estadoBadge = `<span style="background: #f1f5f9; color: #475569; font-size: 0.74rem; font-weight: 800; padding: 3px 8px; border-radius: 8px;">${item.estado}</span>`;
}
// Comprobante y Código Detalle
const compLabel = item.comprobante || 'Sin ref.';
const codigoDetalleHtml = item.codigo_detalle
? `<div style="margin-top: 3px;"><span style="background: #e2e8f0; color: #334155; font-family: monospace; font-size: 0.70rem; font-weight: 800; padding: 2px 6px; border-radius: 4px;">Cód: ${item.codigo_detalle}</span></div>`
: '';
// Estudiante y Escuela
let estHtml = '';
if (item.estudiante_nombre) {
estHtml = `
<div>
<strong style="color: var(--text-main); font-size: 0.85rem; display: block;">${item.estudiante_nombre}</strong>
<span style="font-size: 0.74rem; color: var(--text-muted);">${item.estudiante_grado || ''} ${item.estudiante_seccion || ''} · <span style="color: #0284c7; font-weight: 700;">${item.escuela_nombre || ''}</span></span>
<div style="font-size: 0.72rem; color: #10b981; font-weight: 800; margin-top: 2px;">Saldo: ₡${Number(item.estudiante_saldo || 0).toLocaleString('es-CR')}</div>
</div>
`;
} else {
estHtml = `<span style="background: #fef3c7; color: #92400e; font-size: 0.75rem; font-weight: 800; padding: 3px 8px; border-radius: 6px;">[Depósito Sin Asignar]</span>`;
}
// Remitente / Banco
const remitenteNombre = item.padre_nombre || 'No indicado';
const remitenteTel = item.padre_telefono ? `<span style="color: var(--text-muted); font-size: 0.74rem;">${item.padre_telefono}</span>` : '';
const bancoBadge = item.banco_origen ? `<div style="font-size: 0.70rem; color: #0284c7; font-weight: 700; margin-top: 2px;">🏦 ${item.banco_origen}</div>` : '';
// Botones de Acción
let accionesHtml = `
<button type="button" onclick="openModalDevSinpeDetalle('${item.uid}')" class="dev-action-btn" style="padding: 5px 9px; font-size: 0.75rem;" title="Ver ficha técnica completa">
👁️ Ficha
</button>
`;
// Si es solicitud pendiente
if (item.origen === 'solicitud' && item.estado === 'pendiente') {
accionesHtml += `
<button type="button" onclick="forzarAprobacionSinpeDev(${item.raw_id})" class="dev-action-btn dev-action-btn-primary" style="padding: 5px 10px; font-size: 0.75rem; background: #16a34a; border-color: #16a34a;" title="Aprobar y acreditar saldo ahora">
✓ Aprobar
</button>
<button type="button" onclick="abrirModalRechazoSinpeDev(${item.raw_id})" class="dev-action-btn dev-action-btn-danger" style="padding: 5px 8px; font-size: 0.75rem;" title="Rechazar solicitud con motivo">
✕
</button>
`;
}
// Si es notificación bancaria huérfana (sin reclamar)
if (item.origen === 'banco' && item.estado === 'unclaimed') {
accionesHtml += `
<button type="button" onclick="abrirModalVincularBancoDev('${item.raw_id}')" class="dev-action-btn dev-action-btn-primary" style="padding: 5px 10px; font-size: 0.75rem;" title="Asignar y acreditar a un estudiante">
🔗 Vincular
</button>
`;
}
return `
<tr style="border-bottom: 1px solid var(--border); transition: background 0.15s ease;">
<td style="padding: 12px 14px; white-space: nowrap; color: var(--text-muted); font-size: 0.78rem;">
${fechaStr}
</td>
<td style="padding: 12px 14px;">
<div style="display: flex; align-items: center; gap: 6px;">
<strong style="color: var(--text-main); font-family: monospace; font-size: 0.88rem;">${compLabel}</strong>
<button type="button" onclick="copiarAlPortapapelesTexto('${compLabel}', this)" style="background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 2px;" title="Copiar comprobante">
📋
</button>
</div>
${codigoDetalleHtml}
</td>
<td style="padding: 12px 14px; white-space: nowrap;">
${origenBadge}
</td>
<td style="padding: 12px 14px;">
${estHtml}
</td>
<td style="padding: 12px 14px;">
<div style="font-weight: 700; color: var(--text-main); font-size: 0.82rem;">${remitenteNombre}</div>
${remitenteTel}
${bancoBadge}
</td>
<td style="padding: 12px 14px; white-space: nowrap;">
<strong style="font-size: 1rem; color: #10b981; font-weight: 900;">₡${Number(item.monto || 0).toLocaleString('es-CR')}</strong>
</td>
<td style="padding: 12px 14px; white-space: nowrap;">
${estadoBadge}
</td>
<td style="padding: 12px 14px; text-align: right; white-space: nowrap;">
<div style="display: inline-flex; gap: 5px; align-items: center;">
${accionesHtml}
</div>
</td>
</tr>
`;
}).join('');
}
/**
* Debounce para búsqueda en tiempo real
*/
function debounceDevSinpeSearch() {
if (devSinpeSearchTimer) clearTimeout(devSinpeSearchTimer);
devSinpeSearchTimer = setTimeout(() => {
loadDevSinpeUniversal();
}, 280);
}
window.debounceDevSinpeSearch = debounceDevSinpeSearch;
function clearDevSinpeSearch() {
const inp = document.getElementById('devSinpeSearchInput');
if (inp) inp.value = '';
loadDevSinpeUniversal();
}
window.clearDevSinpeSearch = clearDevSinpeSearch;
/**
* Llena el selector de escuelas del filtro
*/
async function poblarSelectEscuelasSinpeDev() {
const select = document.getElementById('devSinpeFilterEscuela');
if (!select || select.options.length > 1) return;
try {
const res = await fetch('/api/developer/escuelas');
const data = await res.json();
if (res.ok && Array.isArray(data)) {
data.forEach(esc => {
const opt = document.createElement('option');
opt.value = esc.id;
opt.textContent = `${esc.nombre} (${esc.codigo || 'ESC'})`;
select.appendChild(opt);
});
}
} catch (e) {}
}
/**
* Abre el modal con la ficha técnica completa de una transacción SINPE
*/
function openModalDevSinpeDetalle(uid) {
const item = currentDevSinpeItems.find(x => x.uid === uid);
if (!item) return;
currentDevSinpeSelectedItem = item;
const modal = document.getElementById('modalDevSinpeDetalle');
const body = document.getElementById('modalDevSinpeDetalleBody');
const actionsContainer = document.getElementById('modalDevSinpeDetalleActions');
if (!modal || !body) return;
const compLabel = item.comprobante || 'N/A';
const fechaFmt = item.fecha ? new Date(item.fecha).toLocaleString('es-CR') : 'N/A';
const procesadoFmt = item.fecha_procesado ? new Date(item.fecha_procesado).toLocaleString('es-CR') : 'Sin procesar';
body.innerHTML = `
<!-- Tarjeta Principal con Monto y Comprobante -->
<div style="background: #f8fafc; border: 1.5px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;">
<div>
<div style="font-size: 0.70rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted); letter-spacing: 0.5px;">Comprobante de Pago</div>
<div style="display: flex; align-items: center; gap: 8px; margin-top: 2px;">
<span style="font-family: monospace; font-size: 1.25rem; font-weight: 900; color: var(--text-main);">${compLabel}</span>
<button type="button" onclick="copiarAlPortapapelesTexto('${compLabel}', this)" style="background: none; border: none; cursor: pointer; color: #0284c7; padding: 2px;" title="Copiar comprobante">
📋 Copiar
</button>
</div>
${item.codigo_detalle ? `<div style="font-size: 0.74rem; color: #64748b; margin-top: 2px;">Código de Detalle: <strong>${item.codigo_detalle}</strong></div>` : ''}
</div>
<div style="text-align: right;">
<div style="font-size: 0.70rem; font-weight: 800; text-transform: uppercase; color: var(--text-muted);">Monto Transferido</div>
<div style="font-size: 1.45rem; font-weight: 900; color: #10b981;">₡${Number(item.monto || 0).toLocaleString('es-CR')}</div>
</div>
</div>
<!-- Datos del Estudiante y Escuela -->
<div style="margin-bottom: 14px;">
<h4 style="margin: 0 0 8px 0; font-size: 0.84rem; font-weight: 900; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;">Beneficiario</h4>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 12px; font-size: 0.84rem;">
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Nombre Estudiante:</span>
<strong style="color: var(--text-main);">${item.estudiante_nombre || '[Sin Asignar]'}</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Grado y Sección:</span>
<span style="color: var(--text-main); font-weight: 700;">${item.estudiante_grado || 'N/A'} ${item.estudiante_seccion || ''}</span>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Escuela / Sede:</span>
<span style="color: #0284c7; font-weight: 800;">${item.escuela_nombre || 'N/A'}</span>
</div>
<div style="display: flex; justify-content: space-between;">
<span style="color: var(--text-muted);">Saldo Disponible Actual:</span>
<strong style="color: #10b981; font-weight: 900;">₡${Number(item.estudiante_saldo || 0).toLocaleString('es-CR')}</strong>
</div>
</div>
</div>
<!-- Datos de Origen y Remitente -->
<div style="margin-bottom: 14px;">
<h4 style="margin: 0 0 8px 0; font-size: 0.84rem; font-weight: 900; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;">Remitente & Origen Bancario</h4>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 12px; font-size: 0.84rem;">
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Nombre Remitente / Padre:</span>
<strong style="color: var(--text-main);">${item.padre_nombre || 'No especificado'}</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Teléfono Remitente:</span>
<span style="color: var(--text-main); font-weight: 700;">${item.padre_telefono ? `<a href="tel:${item.padre_telefono}" style="color:#0284c7;">${item.padre_telefono}</a>` : 'N/A'}</span>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Banco Emisor:</span>
<span style="color: var(--text-main); font-weight: 700;">${item.banco_origen || 'SINPE Móvil Interbancario'}</span>
</div>
<div style="display: flex; justify-content: space-between;">
<span style="color: var(--text-muted);">Canal de Registro:</span>
<span style="font-weight: 800;">${item.origen === 'solicitud' ? '📱 Formulario App Padres' : (item.origen === 'banco' ? '🏦 Webhook / IMAP Bancario' : '💳 Movimiento de Caja')}</span>
</div>
</div>
</div>
<!-- Auditoría y Tiempos -->
<div>
<h4 style="margin: 0 0 8px 0; font-size: 0.84rem; font-weight: 900; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;">Auditoría y Estado</h4>
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 12px; font-size: 0.84rem;">
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Estado Actual:</span>
<strong style="text-transform: uppercase;">${item.estado}</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Fecha de Creación:</span>
<span style="color: var(--text-main);">${fechaFmt}</span>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Fecha de Procesamiento:</span>
<span style="color: var(--text-main);">${procesadoFmt}</span>
</div>
${item.procesado_por ? `
<div style="display: flex; justify-content: space-between; margin-bottom: 6px;">
<span style="color: var(--text-muted);">Procesado Por:</span>
<strong style="color: #0284c7;">${item.procesado_por}</strong>
</div>
` : ''}
${item.notas ? `
<div style="margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); font-size: 0.80rem; color: #64748b;">
<strong>Notas / Motivo:</strong> ${item.notas}
</div>
` : ''}
</div>
</div>
`;
// Botones de acción dinámicos en el pie del modal
if (actionsContainer) {
let actHtml = '';
if (item.origen === 'solicitud' && item.estado === 'pendiente') {
actHtml = `
<button type="button" onclick="closeModalDevSinpeDetalle(); forzarAprobacionSinpeDev(${item.raw_id});" class="dev-action-btn dev-action-btn-primary" style="background: #16a34a; border-color: #16a34a; font-weight: 800;">
✓ Aprobar Ahora
</button>
<button type="button" onclick="closeModalDevSinpeDetalle(); abrirModalRechazoSinpeDev(${item.raw_id});" class="dev-action-btn dev-action-btn-danger" style="font-weight: 800;">
✕ Rechazar
</button>
`;
} else if (item.origen === 'banco' && item.estado === 'unclaimed') {
actHtml = `
<button type="button" onclick="closeModalDevSinpeDetalle(); abrirModalVincularBancoDev('${item.raw_id}');" class="dev-action-btn dev-action-btn-primary" style="font-weight: 800;">
🔗 Vincular a Estudiante
</button>
`;
}
actHtml += `
<button type="button" onclick="closeModalDevSinpeDetalle()" class="dev-action-btn" style="font-weight: 800;">
Cerrar
</button>
`;
actionsContainer.innerHTML = actHtml;
}
modal.style.display = 'flex';
}
window.openModalDevSinpeDetalle = openModalDevSinpeDetalle;
function closeModalDevSinpeDetalle() {
const modal = document.getElementById('modalDevSinpeDetalle');
if (modal) modal.style.display = 'none';
}
window.closeModalDevSinpeDetalle = closeModalDevSinpeDetalle;
/**
* Copia mensaje listo para responder al padre en WhatsApp
*/
function copiarMensajeSoporteWhatsAppSinpe() {
if (!currentDevSinpeSelectedItem) return;
const it = currentDevSinpeSelectedItem;
const comp = it.comprobante || 'N/A';
const monto = `₡${Number(it.monto || 0).toLocaleString('es-CR')}`;
const est = it.estudiante_nombre || 'Estudiante';
let estadoText = 'Aprobada y acreditada con éxito ✓';
if (it.estado === 'pendiente') estadoText = 'En proceso de verificación en soda ⏳';
if (it.estado === 'rechazada') estadoText = `Rechazada (${it.notas || 'Comprobante no verificado'}) ✕`;
if (it.estado === 'unclaimed') estadoText = 'Depósito recibido en cuenta bancaria pendiente de vincular 🏦';
const msg =
`Hola, le saluda Soporte de SiboPay.
Referente a su recarga SINPE Móvil:
• Comprobante: #${comp}
• Monto: ${monto}
• Estudiante: ${est}
• Estado: ${estadoText}
${it.estudiante_saldo !== undefined ? `• Saldo actual disponible: ₡${Number(it.estudiante_saldo).toLocaleString('es-CR')}` : ''}
¡Gracias por utilizar SiboPay Costa Rica!`;
copiarAlPortapapelesTexto(msg);
if (window.sounds) window.sounds.playSuccess();
alert('¡Mensaje copiado al portapapeles! Puedes pegarlo directamente en el chat de WhatsApp con el padre de familia.');
}
window.copiarMensajeSoporteWhatsAppSinpe = copiarMensajeSoporteWhatsAppSinpe;
/**
* Aprobación forzada por Developer Master
*/
async function forzarAprobacionSinpeDev(solicitudId) {
const confirmar = confirm('¿Confirmas la aprobación y acreditación inmediata de esta recarga SINPE para el estudiante?');
if (!confirmar) return;
try {
const res = await fetch('/api/developer/sinpe/aprobar', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
solicitud_id: solicitudId,
usuario_id: currentUser?.id || null,
motivo: 'Aprobación manual forzada desde Master Developer Suite'
})
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'No se pudo aprobar la recarga');
if (window.sounds) window.sounds.playSuccess();
alert(data.mensaje || '¡Recarga acreditada con éxito!');
await loadDevSinpeUniversal();
} catch (err) {
if (window.sounds) window.sounds.playError();
alert('Error al aprobar: ' + err.message);
}
}
window.forzarAprobacionSinpeDev = forzarAprobacionSinpeDev;
/**
* Rechazo de solicitud Developer
*/
function abrirModalRechazoSinpeDev(solicitudId) {
const modal = document.getElementById('modalDevSinpeRechazar');
const inputId = document.getElementById('devRechazoSolicitudId');
const select = document.getElementById('devRechazoSelectMotivo');
const textarea = document.getElementById('devRechazoTextoExplicacion');
if (!modal) return;
if (inputId) inputId.value = solicitudId;
if (select) select.value = 'Comprobante no verificado en cuenta bancaria';
if (textarea) textarea.value = 'El comprobante reportado no aparece acreditado en los movimientos de la cuenta bancaria de la soda.';
modal.style.display = 'flex';
}
window.abrirModalRechazoSinpeDev = abrirModalRechazoSinpeDev;
function closeModalDevSinpeRechazar() {
const modal = document.getElementById('modalDevSinpeRechazar');
if (modal) modal.style.display = 'none';
}
window.closeModalDevSinpeRechazar = closeModalDevSinpeRechazar;
function actualizarTextoMotivoRechazoDev() {
const select = document.getElementById('devRechazoSelectMotivo');
const textarea = document.getElementById('devRechazoTextoExplicacion');
if (!select || !textarea) return;
if (select.value === 'Comprobante no verificado en cuenta bancaria') {
textarea.value = 'El comprobante reportado no aparece acreditado en los movimientos de la cuenta bancaria de la soda.';
} else if (select.value === 'El monto transferido no coincide con la solicitud') {
textarea.value = 'El monto verificado en la cuenta difiere del valor ingresado en la solicitud de recarga.';
} else if (select.value === 'Comprobante duplicado ya utilizado anteriormente') {
textarea.value = 'Este número de comprobante ya fue procesado y acreditado previamente en otra transacción.';
} else if (select.value === 'Comprobante ilegible o incompleto') {
textarea.value = 'El número o datos del comprobante bancario no son legibles o están incompletos.';
} else {
textarea.value = '';
textarea.focus();
}
}
window.actualizarTextoMotivoRechazoDev = actualizarTextoMotivoRechazoDev;
async function ejecutarRechazoSinpeDev(e) {
e.preventDefault();
const inputId = document.getElementById('devRechazoSolicitudId');
const textarea = document.getElementById('devRechazoTextoExplicacion');
const btn = document.getElementById('btnDevConfirmarRechazo');
if (!inputId || !textarea) return;
const solId = inputId.value;
const motivo = textarea.value.trim();
try {
if (btn) {
btn.disabled = true;
btn.textContent = 'Rechazando...';
}
const res = await fetch('/api/developer/sinpe/rechazar', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
solicitud_id: solId,
motivo,
usuario_id: currentUser?.id || null
})
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'No se pudo rechazar la solicitud');
closeModalDevSinpeRechazar();
if (window.sounds) window.sounds.playSuccess();
alert(data.mensaje || 'Solicitud rechazada con éxito.');
await loadDevSinpeUniversal();
} catch (err) {
if (window.sounds) window.sounds.playError();
alert('Error al rechazar: ' + err.message);
} finally {
if (btn) {
btn.disabled = false;
btn.textContent = 'Confirmar Rechazo';
}
}
}
window.ejecutarRechazoSinpeDev = ejecutarRechazoSinpeDev;
/**
* Vincular notificación bancaria huérfana a estudiante
*/
async function abrirModalVincularBancoDev(bancoTxId) {
const item = currentDevSinpeItems.find(x => x.raw_id === bancoTxId && x.origen === 'banco');
if (!item) return;
const modal = document.getElementById('modalDevSinpeVincular');
const inputId = document.getElementById('devVincularBancoTxId');
const resumenBox = document.getElementById('devVincularDepositoResumen');
if (!modal) return;
if (inputId) inputId.value = bancoTxId;
if (resumenBox) {
resumenBox.innerHTML = `
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
<span style="color: var(--text-muted);">Comprobante / Ref:</span>
<strong style="color: var(--text-main); font-family: monospace;">${item.comprobante}</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
<span style="color: var(--text-muted);">Monto Bancario:</span>
<strong style="color: #10b981; font-size: 1rem;">₡${Number(item.monto).toLocaleString('es-CR')}</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-bottom: 4px;">
<span style="color: var(--text-muted);">Banco de Origen:</span>
<span>${item.banco_origen || 'Banco'}</span>
</div>
<div style="display: flex; justify-content: space-between;">
<span style="color: var(--text-muted);">Remitente:</span>
<span>${item.padre_nombre || 'N/A'} ${item.padre_telefono ? `(${item.padre_telefono})` : ''}</span>
</div>
`;
}
// Cargar estudiantes para selector
await cargarEstudiantesParaVinculacion();
modal.style.display = 'flex';
}
window.abrirModalVincularBancoDev = abrirModalVincularBancoDev;
function closeModalDevSinpeVincular() {
const modal = document.getElementById('modalDevSinpeVincular');
if (modal) modal.style.display = 'none';
}
window.closeModalDevSinpeVincular = closeModalDevSinpeVincular;
async function cargarEstudiantesParaVinculacion() {
const select = document.getElementById('devVincularEstudianteSelect');
if (!select) return;
if (devCachedEstudiantesList.length === 0) {
try {
const res = await fetch('/api/admin/estudiantes');
const data = await res.json();
if (res.ok && Array.isArray(data)) {
devCachedEstudiantesList = data;
}
} catch (e) {}
}
filtrarEstudiantesParaVincular();
}
function filtrarEstudiantesParaVincular() {
const searchInput = document.getElementById('devVincularEstudianteSearch');
const select = document.getElementById('devVincularEstudianteSelect');
if (!select) return;
const query = (searchInput?.value || '').toLowerCase().trim();
const filtered = devCachedEstudiantesList.filter(e => {
if (!query) return true;
return (e.nombre_completo || '').toLowerCase().includes(query) ||
(e.codigo_estudiante || '').toLowerCase().includes(query) ||
(e.padre_nombre || '').toLowerCase().includes(query);
});
select.innerHTML = filtered.map(e => `
<option value="${e.id}">
${e.nombre_completo} · ${e.grado || ''} ${e.seccion || ''} (${e.codigo_estudiante || 'ID ' + e.id}) - Saldo actual: ₡${(e.saldo_colones || 0).toLocaleString('es-CR')}
</option>
`).join('');
if (filtered.length > 0) {
select.selectedIndex = 0;
}
}
window.filtrarEstudiantesParaVincular = filtrarEstudiantesParaVincular;
async function ejecutarVinculacionBancoDev(e) {
e.preventDefault();
const inputId = document.getElementById('devVincularBancoTxId');
const selectEst = document.getElementById('devVincularEstudianteSelect');
const inputNotas = document.getElementById('devVincularNotas');
const btn = document.getElementById('btnDevConfirmarVincular');
if (!inputId || !selectEst || !selectEst.value) {
alert('Por favor selecciona el estudiante que recibirá el saldo.');
return;
}
try {
if (btn) {
btn.disabled = true;
btn.textContent = 'Acreditando...';
}
const res = await fetch('/api/developer/sinpe/vincular-banco', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
banco_tx_id: inputId.value,
estudiante_id: parseInt(selectEst.value, 10),
usuario_id: currentUser?.id || null,
notas: inputNotas?.value || null
})
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'No se pudo vincular la transacción');
closeModalDevSinpeVincular();
if (window.sounds) window.sounds.playSuccess();
alert(data.mensaje || '¡Depósito bancario acreditado con éxito!');
await loadDevSinpeUniversal();
} catch (err) {
if (window.sounds) window.sounds.playError();
alert('Error al vincular: ' + err.message);
} finally {
if (btn) {
btn.disabled = false;
btn.textContent = 'Acreditar y Vincular';
}
}
}
window.ejecutarVinculacionBancoDev = ejecutarVinculacionBancoDev;
/**
* Simulador de Notificación Bancaria para pruebas
*/
function openModalDevSimularSinpe() {
const modal = document.getElementById('modalDevSimularSinpe');
if (modal) modal.style.display = 'flex';
}
window.openModalDevSimularSinpe = openModalDevSimularSinpe;
function closeModalDevSimularSinpe() {
const modal = document.getElementById('modalDevSimularSinpe');
if (modal) modal.style.display = 'none';
}
window.closeModalDevSimularSinpe = closeModalDevSimularSinpe;
async function ejecutarSimulacionSinpeDev(e) {
e.preventDefault();
const banco = document.getElementById('devSimBanco')?.value;
const monto = parseInt(document.getElementById('devSimMonto')?.value || 3500, 10);
const remitente = document.getElementById('devSimRemitente')?.value;
const telefono = document.getElementById('devSimTelefono')?.value;
const codigo = document.getElementById('devSimCodigoDetalle')?.value || null;
const btn = document.getElementById('btnDevConfirmarSimulacion');
const randomRef = 'BAC' + Math.floor(100000 + Math.random() * 900000);
try {
if (btn) {
btn.disabled = true;
btn.textContent = 'Inyectando...';
}
const res = await fetch('/api/sinpe/simular-correo', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
banco,
monto,
remitente,
telefono,
codigo,
comprobante: randomRef
})
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'No se pudo simular la transacción');
closeModalDevSimularSinpe();
if (window.sounds) window.sounds.playSuccess();
alert(`⚡ ¡Transacción simulada con éxito!\nReferencia: #${randomRef} por ₡${monto.toLocaleString('es-CR')}.\nYa aparece en el Buscador SINPE.`);
await loadDevSinpeUniversal();
} catch (err) {
if (window.sounds) window.sounds.playError();
alert('Error al simular: ' + err.message);
} finally {
if (btn) {
btn.disabled = false;
btn.textContent = '⚡ Disparar Transacción';
}
}
}
window.ejecutarSimulacionSinpeDev = ejecutarSimulacionSinpeDev;
/**
* Exportar resultados a CSV
*/
function exportarSinpeUniversalCsv() {
if (!currentDevSinpeItems || currentDevSinpeItems.length === 0) {
alert('No hay registros en los resultados actuales para exportar.');
return;
}
const headers = ['Fecha', 'Comprobante', 'Codigo Detalle', 'Origen', 'Estado', 'Monto (CRC)', 'Estudiante', 'Escuela', 'Remitente', 'Telefono', 'Banco', 'Notas'];
const rows = currentDevSinpeItems.map(item => [
item.fecha || '',
item.comprobante || '',
item.codigo_detalle || '',
item.origen || '',
item.estado || '',
item.monto || 0,
item.estudiante_nombre || 'Sin Asignar',
item.escuela_nombre || '',
item.padre_nombre || '',
item.padre_telefono || '',
item.banco_origen || '',
(item.notas || '').replace(/\r?\n/g, ' ')
]);
const csvContent = '\uFEFF' + [headers.join(','), ...rows.map(r => r.map(c => `"${String(c).replace(/"/g, '""')}"`).join(','))].join('\r\n');
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
const dateTag = new Date().toISOString().slice(0, 10);
a.download = `reporte_sinpe_universal_sibopay_${dateTag}.csv`;
document.body.appendChild(a);
a.click();
setTimeout(() => {
if (a.parentNode) a.parentNode.removeChild(a);
URL.revokeObjectURL(url);
}, 250);
}
window.exportarSinpeUniversalCsv = exportarSinpeUniversalCsv;
/**
* Helper para copiar texto al portapapeles
*/
function copiarAlPortapapelesTexto(texto, btnEl) {
if (!texto) return;
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(texto).then(() => {
if (btnEl) {
const orig = btnEl.innerHTML;
btnEl.innerHTML = '✓ Copiado';
setTimeout(() => { btnEl.innerHTML = orig; }, 1500);
}
}).catch(() => {});
} else {
const ta = document.createElement('textarea');
ta.value = texto;
document.body.appendChild(ta);
ta.select();
document.execCommand('copy');
document.body.removeChild(ta);
if (btnEl) {
const orig = btnEl.innerHTML;
btnEl.innerHTML = '✓ Copiado';
setTimeout(() => { btnEl.innerHTML = orig; }, 1500);
}
}
}
window.copiarAlPortapapelesTexto = copiarAlPortapapelesTexto;
+7 -7
View File
@@ -1,5 +1,5 @@
// SiboPay PWA Service Worker v18.1 - Ultra Fast Startup & Stale-While-Revalidate
const CACHE_NAME = 'sibopay-v18.1';
// SiboPay PWA Service Worker v19.0 - Ultra Fast Startup & Stale-While-Revalidate
const CACHE_NAME = 'sibopay-v19.0';
const STATIC_ASSETS = [
'/',
'/index.html',
@@ -8,13 +8,13 @@ const STATIC_ASSETS = [
'/pistola.html',
'/carnet.html',
'/manifest.json',
'/css/styles.css?v=18.1',
'/css/styles.css?v=19.0',
'/css/desktop.css?v=2.2',
'/js/dialogs.js?v=18.1',
'/js/app.js?v=18.1',
'/js/dialogs.js?v=19.0',
'/js/app.js?v=19.0',
'/js/pos.js',
'/js/sounds.js?v=18.1',
'/js/food-icons.js?v=18.1',
'/js/sounds.js?v=19.0',
'/js/food-icons.js?v=19.0',
'/icons/icon-192.png',
'/icons/icon-512.png',
'/img/sibopay-emblem.png',