feat: broadcast banners and SINPE suspension en caliente (v20.5)
This commit is contained in:
+121
-2
@@ -12,7 +12,7 @@
|
|||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||||
<meta name="apple-mobile-web-app-title" content="SiboPay">
|
<meta name="apple-mobile-web-app-title" content="SiboPay">
|
||||||
<link rel="preload" href="/css/styles.css?v=19.9" as="style">
|
<link rel="preload" href="/css/styles.css?v=19.9" as="style">
|
||||||
<link rel="preload" href="/js/app.js?v=20.4" as="script">
|
<link rel="preload" href="/js/app.js?v=20.5" as="script">
|
||||||
<link rel="stylesheet" href="/css/styles.css?v=19.9">
|
<link rel="stylesheet" href="/css/styles.css?v=19.9">
|
||||||
<link rel="stylesheet" href="/css/desktop.css?v=2.2">
|
<link rel="stylesheet" href="/css/desktop.css?v=2.2">
|
||||||
<style>
|
<style>
|
||||||
@@ -1843,6 +1843,32 @@
|
|||||||
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Se actualizará en tiempo real</span>
|
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 600;">Se actualizará en tiempo real</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Suspensión de SINPE -->
|
||||||
|
<div style="background: #fff7ed; border: 1.5px solid #fed7aa; border-radius: 12px; padding: 14px; margin-bottom: 16px;">
|
||||||
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; gap: 8px;">
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px;">
|
||||||
|
<span style="font-size: 1.2rem;">🔴</span>
|
||||||
|
<div>
|
||||||
|
<div style="font-size: 0.88rem; font-weight: 900; color: #9a3412;">Recepción de Recargas SINPE</div>
|
||||||
|
<div style="font-size: 0.72rem; color: #c2410c;">Desactiva para bloquear nuevos pagos temporalmente</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label style="display: flex; align-items: center; gap: 8px; cursor: pointer;">
|
||||||
|
<span style="font-size: 0.78rem; font-weight: 700; color: var(--text-muted);" id="lblAdminSinpeActivoEstado">Habilitado</span>
|
||||||
|
<div style="position: relative; width: 44px; height: 24px;">
|
||||||
|
<input type="checkbox" id="chkAdminSinpeActivo" checked style="opacity: 0; width: 0; height: 0; position: absolute;" onchange="actualizarPreviewAdminSinpe()">
|
||||||
|
<span onclick="document.getElementById('chkAdminSinpeActivo').click()" style="position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #16a34a; border-radius: 24px; transition: .3s;" id="toggleTrackSinpe">
|
||||||
|
<span id="toggleThumbSinpe" style="position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .3s; transform: translateX(0);"></span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="txtAdminSinpeMensajeSuspension" style="display: block; font-size: 0.78rem; font-weight: 800; color: #9a3412; margin-bottom: 4px;">Mensaje que verán los padres al intentar recargar:</label>
|
||||||
|
<textarea id="txtAdminSinpeMensajeSuspension" rows="2" placeholder="Ej: Recargas SINPE suspendidas por mantenimiento bancario. Se reanudarán el lunes." style="width: 100%; padding: 8px 12px; border-radius: 9px; border: 1.5px solid #fed7aa; font-size: 0.84rem; color: #9a3412; background: white; box-sizing: border-box; resize: vertical; font-family: inherit;">Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica. Se reanudarán a la brevedad.</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div style="display: flex; justify-content: flex-end; gap: 10px;">
|
<div style="display: flex; justify-content: flex-end; gap: 10px;">
|
||||||
<button type="button" id="btnGuardarAdminSinpe" onclick="guardarAdminSinpeConfig()" class="btn-saas btn-saas-primary" style="padding: 10px 22px; font-size: 0.88rem; font-weight: 800; display: inline-flex; align-items: center; gap: 7px; box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);">
|
<button type="button" id="btnGuardarAdminSinpe" onclick="guardarAdminSinpeConfig()" class="btn-saas btn-saas-primary" style="padding: 10px 22px; font-size: 0.88rem; font-weight: 800; display: inline-flex; align-items: center; gap: 7px; box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);">
|
||||||
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
|
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>
|
||||||
@@ -1851,6 +1877,80 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- SECCIÓN 1b: DIFUSIÓN DE AVISOS & BANNERS GLOBALES -->
|
||||||
|
<div style="margin-bottom: 26px; background: var(--bg-main); border: 1.5px solid #c4b5fd; border-radius: 18px; padding: 20px 20px 24px 20px; box-shadow: 0 4px 18px rgba(139,92,246,0.06);">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
|
||||||
|
<div>
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px;">
|
||||||
|
<span style="font-size: 1.35rem;">📢</span>
|
||||||
|
<h3 style="margin: 0; font-size: 1.18rem; font-weight: 900; color: var(--text-main);">Difusión de Avisos & Banners Globales</h3>
|
||||||
|
</div>
|
||||||
|
<p style="margin: 4px 0 0 0; font-size: 0.80rem; color: var(--text-muted); max-width: 650px;">
|
||||||
|
Publica avisos en tiempo real que aparecen como banners en las apps de estudiantes, padres y POS. Los avisos descartables desaparecen cuando el usuario los cierra.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button type="button" onclick="openModalCrearAviso()" class="btn-saas btn-saas-primary" style="display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; font-size: 0.84rem; background: #7c3aed; box-shadow: 0 2px 8px rgba(124,58,237,0.3);">
|
||||||
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M12 5v14"/><path d="M5 12h14"/></svg>
|
||||||
|
+ Crear Aviso
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Tabla de avisos activos -->
|
||||||
|
<div id="adminAvisosTableContainer">
|
||||||
|
<div id="adminAvisosEmptyMsg" style="text-align: center; color: var(--text-muted); font-size: 0.82rem; padding: 20px 0; display: none;">
|
||||||
|
No hay avisos publicados aún. Crea uno para que aparezca en las apps.
|
||||||
|
</div>
|
||||||
|
<div id="adminAvisosTable" style="display: flex; flex-direction: column; gap: 8px;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MODAL CREAR AVISO -->
|
||||||
|
<div id="modalCrearAviso" style="display: none; position: fixed; inset: 0; z-index: 9000; align-items: center; justify-content: center; background: rgba(0,0,0,0.55); backdrop-filter: blur(4px);">
|
||||||
|
<div style="background: var(--bg-main); border-radius: 20px; padding: 24px; max-width: 480px; width: 92%; box-shadow: 0 24px 60px rgba(0,0,0,0.22); position: relative; max-height: 90vh; overflow-y: auto;">
|
||||||
|
<button onclick="closeModalCrearAviso()" style="position: absolute; top: 14px; right: 14px; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); line-height: 1;">✕</button>
|
||||||
|
<h3 style="margin: 0 0 18px 0; font-size: 1.1rem; font-weight: 900; color: var(--text-main);">📢 Publicar Nuevo Aviso</h3>
|
||||||
|
|
||||||
|
<label style="display: block; font-size: 0.80rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px;">Título del Aviso *</label>
|
||||||
|
<input type="text" id="inputAvisoTitulo" placeholder="Ej: Cierre temprano hoy" style="width: 100%; padding: 9px 12px; border-radius: 9px; border: 1.5px solid var(--border); font-size: 0.95rem; background: var(--bg-main); color: var(--text-main); outline: none; box-sizing: border-box; margin-bottom: 12px;">
|
||||||
|
|
||||||
|
<label style="display: block; font-size: 0.80rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px;">Mensaje *</label>
|
||||||
|
<textarea id="inputAvisoMensaje" rows="3" placeholder="Ej: La soda cerrará a las 11:30 AM hoy por actividad escolar." style="width: 100%; padding: 9px 12px; border-radius: 9px; border: 1.5px solid var(--border); font-size: 0.90rem; background: var(--bg-main); color: var(--text-main); outline: none; box-sizing: border-box; resize: vertical; font-family: inherit; margin-bottom: 12px;"></textarea>
|
||||||
|
|
||||||
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px;">
|
||||||
|
<div>
|
||||||
|
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px;">Tipo</label>
|
||||||
|
<select id="selectAvisoTipo" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 0.88rem; background: var(--bg-main); color: var(--text-main); outline: none;">
|
||||||
|
<option value="info">ℹ️ Informativo</option>
|
||||||
|
<option value="promo">🎉 Promoción</option>
|
||||||
|
<option value="alerta">⚠️ Alerta</option>
|
||||||
|
<option value="urgente">🚨 Urgente</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main); margin-bottom: 4px;">Audiencia</label>
|
||||||
|
<select id="selectAvisoAudiencia" style="width: 100%; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 0.88rem; background: var(--bg-main); color: var(--text-main); outline: none;">
|
||||||
|
<option value="todos">👥 Todos</option>
|
||||||
|
<option value="padres">👨👩👧 Padres</option>
|
||||||
|
<option value="estudiantes">🎒 Estudiantes</option>
|
||||||
|
<option value="pos">🖥️ POS / Caja</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label style="display: flex; align-items: center; gap: 8px; font-size: 0.84rem; font-weight: 700; color: var(--text-main); cursor: pointer; margin-bottom: 20px;">
|
||||||
|
<input type="checkbox" id="chkAvisoDescartable" checked style="width: 16px; height: 16px; accent-color: #7c3aed;">
|
||||||
|
Aviso descartable (el usuario puede cerrarlo)
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div style="display: flex; gap: 10px; justify-content: flex-end;">
|
||||||
|
<button type="button" onclick="closeModalCrearAviso()" class="btn-saas" style="background: var(--bg-main); border: 1.5px solid var(--border); color: var(--text-main); padding: 10px 18px; font-size: 0.85rem; font-weight: 700;">Cancelar</button>
|
||||||
|
<button type="button" id="btnGuardarAviso" onclick="guardarNuevoAviso()" class="btn-saas btn-saas-primary" style="background: #7c3aed; padding: 10px 22px; font-size: 0.85rem; font-weight: 800; box-shadow: 0 2px 8px rgba(124,58,237,0.3);">
|
||||||
|
📢 Publicar Aviso
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- SECCIÓN 2: HORARIOS DE RECREOS Y ALMUERZO -->
|
<!-- SECCIÓN 2: HORARIOS DE RECREOS Y ALMUERZO -->
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
|
||||||
<div>
|
<div>
|
||||||
@@ -1964,6 +2064,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- BANNER DE AVISOS GLOBALES EN PORTAL DE PADRES -->
|
||||||
|
<div id="parentGlobalBannerContainer" style="display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px;"></div>
|
||||||
|
|
||||||
<!-- BANNER SI NO HAY HIJOS VINCULADOS -->
|
<!-- BANNER SI NO HAY HIJOS VINCULADOS -->
|
||||||
<div id="parentNoChildrenBanner" class="parent-card" style="display: none; text-align: center; border: 2px dashed #0284c7; background: #f0f9ff;">
|
<div id="parentNoChildrenBanner" class="parent-card" style="display: none; text-align: center; border: 2px dashed #0284c7; background: #f0f9ff;">
|
||||||
<div style="width: 52px; height: 52px; border-radius: 50%; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;">
|
<div style="width: 52px; height: 52px; border-radius: 50%; background: #e0f2fe; color: #0284c7; display: flex; align-items: center; justify-content: center; margin: 0 auto 10px;">
|
||||||
@@ -2287,6 +2390,16 @@
|
|||||||
<div class="parent-sinpe-desktop-grid">
|
<div class="parent-sinpe-desktop-grid">
|
||||||
<!-- Columna 1: Formulario de Recarga SINPE -->
|
<!-- Columna 1: Formulario de Recarga SINPE -->
|
||||||
<div class="parent-card parent-sinpe-form-card" style="background: #f0fdf4; border: 1.5px solid #86efac; margin-bottom: 0;">
|
<div class="parent-card parent-sinpe-form-card" style="background: #f0fdf4; border: 1.5px solid #86efac; margin-bottom: 0;">
|
||||||
|
<!-- Banner de SINPE Suspendido -->
|
||||||
|
<div id="parentSinpeSuspendedBanner" style="display: none; background: #fff1f2; border: 1.5px solid #fecdd3; color: #9f1239; padding: 14px 16px; border-radius: 14px; margin-bottom: 14px; align-items: flex-start; gap: 10px; box-shadow: 0 4px 12px rgba(225,29,72,0.08);">
|
||||||
|
<span style="font-size: 1.5rem; flex-shrink: 0;">🔴</span>
|
||||||
|
<div style="flex: 1;">
|
||||||
|
<strong style="display: block; font-size: 0.90rem; color: #881337; margin-bottom: 3px;">Recargas SINPE Suspendidas Temporalmente</strong>
|
||||||
|
<span id="parentSinpeSuspendedMsg" style="font-size: 0.82rem;">Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica. Se reanudarán a la brevedad.</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="parentSinpeFormFields">
|
||||||
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;">
|
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;">
|
||||||
<div style="display: flex; align-items: center; gap: 10px;">
|
<div style="display: flex; align-items: center; gap: 10px;">
|
||||||
<div style="width: 36px; height: 36px; border-radius: 10px; background: #dcfce7; color: #166534; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
|
<div style="width: 36px; height: 36px; border-radius: 10px; background: #dcfce7; color: #166534; display: flex; align-items: center; justify-content: center; flex-shrink: 0;">
|
||||||
@@ -2373,6 +2486,7 @@
|
|||||||
|
|
||||||
<!-- Banner de estado dinámico -->
|
<!-- Banner de estado dinámico -->
|
||||||
<div id="parentSinpeStatusMsg" style="display: none; margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 0.80rem; line-height: 1.4;"></div>
|
<div id="parentSinpeStatusMsg" style="display: none; margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 0.80rem; line-height: 1.4;"></div>
|
||||||
|
</div><!-- /parentSinpeFormFields -->
|
||||||
|
|
||||||
<!-- LISTA DE SOLICITUDES SINPE PENDIENTES DEL HIJO -->
|
<!-- LISTA DE SOLICITUDES SINPE PENDIENTES DEL HIJO -->
|
||||||
<div id="parentSinpePendingBox" style="margin-top: 14px; border-top: 1px dashed #86efac; padding-top: 10px; display: none;">
|
<div id="parentSinpePendingBox" style="margin-top: 14px; border-top: 1px dashed #86efac; padding-top: 10px; display: none;">
|
||||||
@@ -2646,8 +2760,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- 4. SUB-PANTALLA: HISTORIAL DE COMPRAS -->
|
<!-- 4. SUB-PANTALLA: HISTORIAL DE COMPRAS -->
|
||||||
|
|
||||||
<div id="parentSubViewHistorial" class="parent-subview" style="display: none;">
|
<div id="parentSubViewHistorial" class="parent-subview" style="display: none;">
|
||||||
<div class="parent-subview-header">
|
<div class="parent-subview-header">
|
||||||
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
|
<button type="button" onclick="closeParentSubView()" class="parent-subview-back-btn">
|
||||||
@@ -2879,6 +2995,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- BANNER DE AVISOS GLOBALES EN APP ESTUDIANTE -->
|
||||||
|
<div id="studentGlobalBannerContainer" style="display: flex; flex-direction: column; gap: 8px; margin: 10px 16px 0 16px;"></div>
|
||||||
|
|
||||||
<!-- BANNER DE ADVERTENCIA HTTPS PARA TELÉFONOS MÓVILES -->
|
<!-- BANNER DE ADVERTENCIA HTTPS PARA TELÉFONOS MÓVILES -->
|
||||||
<div id="bannerHttpsWarning" style="display: none; background: linear-gradient(135deg, #f59e0b, #d97706); color: white; padding: 10px 14px; font-size: 0.78rem; font-weight: 700; text-align: center; border-radius: 12px; margin: 10px 16px 0 16px; box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);">
|
<div id="bannerHttpsWarning" style="display: none; background: linear-gradient(135deg, #f59e0b, #d97706); color: white; padding: 10px 14px; font-size: 0.78rem; font-weight: 700; text-align: center; border-radius: 12px; margin: 10px 16px 0 16px; box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);">
|
||||||
<span style="display: inline-flex; align-items: center; gap: 6px;">
|
<span style="display: inline-flex; align-items: center; gap: 6px;">
|
||||||
@@ -5237,6 +5356,6 @@
|
|||||||
<script src="/js/sounds.js?v=19.4"></script>
|
<script src="/js/sounds.js?v=19.4"></script>
|
||||||
<script src="/js/jsQR.js" defer></script>
|
<script src="/js/jsQR.js" defer></script>
|
||||||
<script src="/js/food-icons.js?v=19.4" defer></script>
|
<script src="/js/food-icons.js?v=19.4" defer></script>
|
||||||
<script src="/js/app.js?v=20.4"></script>
|
<script src="/js/app.js?v=20.5"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+435
-4
@@ -592,6 +592,7 @@ async function applyUserRoleSession() {
|
|||||||
}
|
}
|
||||||
await loadAdminData();
|
await loadAdminData();
|
||||||
setupAdminSmartSearch();
|
setupAdminSmartSearch();
|
||||||
|
cargarAvisosActivos();
|
||||||
} else if (currentUser.rol === 'padre') {
|
} else if (currentUser.rol === 'padre') {
|
||||||
if (viewAdmin) viewAdmin.style.display = 'none';
|
if (viewAdmin) viewAdmin.style.display = 'none';
|
||||||
if (viewPadres) viewPadres.style.display = 'block'; // PANEL DEDICADO COMPLETO (NO MODAL)
|
if (viewPadres) viewPadres.style.display = 'block'; // PANEL DEDICADO COMPLETO (NO MODAL)
|
||||||
@@ -600,6 +601,7 @@ async function applyUserRoleSession() {
|
|||||||
|
|
||||||
await loadInitialData();
|
await loadInitialData();
|
||||||
await loadParentDashboard();
|
await loadParentDashboard();
|
||||||
|
cargarAvisosActivos();
|
||||||
|
|
||||||
// Si el padre tenía una sub-pantalla abierta (ej: recarga SINPE al ir al banco y volver), restaurarla exactamente
|
// Si el padre tenía una sub-pantalla abierta (ej: recarga SINPE al ir al banco y volver), restaurarla exactamente
|
||||||
try {
|
try {
|
||||||
@@ -635,6 +637,7 @@ async function applyUserRoleSession() {
|
|||||||
currentStudent = currentUser.estudiante;
|
currentStudent = currentUser.estudiante;
|
||||||
currentAppMode = 'teens';
|
currentAppMode = 'teens';
|
||||||
updateStudentUI();
|
updateStudentUI();
|
||||||
|
cargarAvisosActivos();
|
||||||
}
|
}
|
||||||
|
|
||||||
// En segundo plano y en paralelo: sincronizar datos frescos sin congelar la pantalla
|
// En segundo plano y en paralelo: sincronizar datos frescos sin congelar la pantalla
|
||||||
@@ -3392,12 +3395,36 @@ function initStudentSSE() {
|
|||||||
const parentTit = document.getElementById('parentSinpeTitular');
|
const parentTit = document.getElementById('parentSinpeTitular');
|
||||||
if (parentTit && data.nombre_sinpe) parentTit.textContent = data.nombre_sinpe;
|
if (parentTit && data.nombre_sinpe) parentTit.textContent = data.nombre_sinpe;
|
||||||
|
|
||||||
|
// Actualizar estado de suspensión en vivo para los padres
|
||||||
|
const bannerSusp = document.getElementById('parentSinpeSuspendedBanner');
|
||||||
|
const msgSusp = document.getElementById('parentSinpeSuspendedMsg');
|
||||||
|
const formFields = document.getElementById('parentSinpeFormFields');
|
||||||
|
|
||||||
|
if (data.sinpe_activo === false) {
|
||||||
|
if (bannerSusp) bannerSusp.style.display = 'flex';
|
||||||
|
if (msgSusp && data.sinpe_mensaje_suspension) msgSusp.textContent = data.sinpe_mensaje_suspension;
|
||||||
|
if (formFields) {
|
||||||
|
formFields.style.opacity = '0.4';
|
||||||
|
formFields.style.pointerEvents = 'none';
|
||||||
|
}
|
||||||
|
} else if (data.sinpe_activo === true) {
|
||||||
|
if (bannerSusp) bannerSusp.style.display = 'none';
|
||||||
|
if (formFields) {
|
||||||
|
formFields.style.opacity = '1';
|
||||||
|
formFields.style.pointerEvents = 'auto';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Actualizar campos del admin si está en su panel
|
// Actualizar campos del admin si está en su panel
|
||||||
if (currentUser && currentUser.rol === 'admin') {
|
if (currentUser && currentUser.rol === 'admin') {
|
||||||
const inpTel = document.getElementById('inputAdminTelefonoSinpe');
|
const inpTel = document.getElementById('inputAdminTelefonoSinpe');
|
||||||
const inpTitular = document.getElementById('inputAdminTitularSinpe');
|
const inpTitular = document.getElementById('inputAdminTitularSinpe');
|
||||||
if (inpTel) inpTel.value = data.telefono_sinpe || '';
|
const chkActivo = document.getElementById('chkAdminSinpeActivo');
|
||||||
if (inpTitular) inpTitular.value = data.nombre_sinpe || '';
|
const txtMsg = document.getElementById('txtAdminSinpeMensajeSuspension');
|
||||||
|
if (inpTel && data.telefono_sinpe) inpTel.value = data.telefono_sinpe;
|
||||||
|
if (inpTitular && data.nombre_sinpe) inpTitular.value = data.nombre_sinpe;
|
||||||
|
if (chkActivo && data.sinpe_activo !== undefined) chkActivo.checked = data.sinpe_activo;
|
||||||
|
if (txtMsg && data.sinpe_mensaje_suspension) txtMsg.value = data.sinpe_mensaje_suspension;
|
||||||
if (typeof actualizarPreviewAdminSinpe === 'function') actualizarPreviewAdminSinpe();
|
if (typeof actualizarPreviewAdminSinpe === 'function') actualizarPreviewAdminSinpe();
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -3405,6 +3432,35 @@ function initStudentSSE() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Avisos globales publicados, modificados o eliminados en tiempo real
|
||||||
|
sse.addEventListener('aviso_publicado', (e) => {
|
||||||
|
try {
|
||||||
|
if (typeof cargarAvisosActivos === 'function') cargarAvisosActivos();
|
||||||
|
if (currentUser && currentUser.rol === 'admin' && typeof loadAdminAvisos === 'function') loadAdminAvisos();
|
||||||
|
if (window.sounds) window.sounds.playTap();
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Error en SSE aviso_publicado:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sse.addEventListener('aviso_estado_cambiado', (e) => {
|
||||||
|
try {
|
||||||
|
if (typeof cargarAvisosActivos === 'function') cargarAvisosActivos();
|
||||||
|
if (currentUser && currentUser.rol === 'admin' && typeof loadAdminAvisos === 'function') loadAdminAvisos();
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Error en SSE aviso_estado_cambiado:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sse.addEventListener('aviso_eliminado', (e) => {
|
||||||
|
try {
|
||||||
|
if (typeof cargarAvisosActivos === 'function') cargarAvisosActivos();
|
||||||
|
if (currentUser && currentUser.rol === 'admin' && typeof loadAdminAvisos === 'function') loadAdminAvisos();
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Error en SSE aviso_eliminado:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Saldo actualizado (débito, recarga, ajuste de límite)
|
// Saldo actualizado (débito, recarga, ajuste de límite)
|
||||||
sse.addEventListener('saldo_actualizado', (e) => {
|
sse.addEventListener('saldo_actualizado', (e) => {
|
||||||
try {
|
try {
|
||||||
@@ -4744,6 +4800,27 @@ async function obtenerNuevoCodigoSinpe() {
|
|||||||
body: JSON.stringify({ estudiante_id: studentId })
|
body: JSON.stringify({ estudiante_id: studentId })
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
|
const bannerSusp = document.getElementById('parentSinpeSuspendedBanner');
|
||||||
|
const msgSusp = document.getElementById('parentSinpeSuspendedMsg');
|
||||||
|
const formFields = document.getElementById('parentSinpeFormFields');
|
||||||
|
|
||||||
|
if (data.suspended) {
|
||||||
|
if (bannerSusp) bannerSusp.style.display = 'flex';
|
||||||
|
if (msgSusp && data.mensaje_suspension) msgSusp.textContent = data.mensaje_suspension;
|
||||||
|
if (formFields) {
|
||||||
|
formFields.style.opacity = '0.4';
|
||||||
|
formFields.style.pointerEvents = 'none';
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (bannerSusp) bannerSusp.style.display = 'none';
|
||||||
|
if (formFields) {
|
||||||
|
formFields.style.opacity = '1';
|
||||||
|
formFields.style.pointerEvents = 'auto';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (data.success && data.codigo) {
|
if (data.success && data.codigo) {
|
||||||
currentSinpeCode = data.codigo;
|
currentSinpeCode = data.codigo;
|
||||||
if (display) display.textContent = data.codigo;
|
if (display) display.textContent = data.codigo;
|
||||||
@@ -4933,6 +5010,15 @@ function closeModalSinpeTerms(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function executeParentSinpeRecharge() {
|
async function executeParentSinpeRecharge() {
|
||||||
|
const bannerSusp = document.getElementById('parentSinpeSuspendedBanner');
|
||||||
|
if (bannerSusp && bannerSusp.style.display !== 'none') {
|
||||||
|
showSinpeModal('error', {
|
||||||
|
title: 'Recargas Temporalmente Suspendidas',
|
||||||
|
message: document.getElementById('parentSinpeSuspendedMsg')?.textContent || 'Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica.'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!currentParentChild) {
|
if (!currentParentChild) {
|
||||||
showSinpeModal('error', {
|
showSinpeModal('error', {
|
||||||
title: 'Estudiante no seleccionado',
|
title: 'Estudiante no seleccionado',
|
||||||
@@ -6230,9 +6316,15 @@ async function cargarHorariosAdmin() {
|
|||||||
const esc = dataInfo.escuela;
|
const esc = dataInfo.escuela;
|
||||||
const inpTel = document.getElementById('inputAdminTelefonoSinpe');
|
const inpTel = document.getElementById('inputAdminTelefonoSinpe');
|
||||||
const inpTitular = document.getElementById('inputAdminTitularSinpe');
|
const inpTitular = document.getElementById('inputAdminTitularSinpe');
|
||||||
|
const chkActivo = document.getElementById('chkAdminSinpeActivo');
|
||||||
|
const txtMsg = document.getElementById('txtAdminSinpeMensajeSuspension');
|
||||||
|
|
||||||
if (inpTel) inpTel.value = esc.telefono_sinpe || '8888-8888';
|
if (inpTel) inpTel.value = esc.telefono_sinpe || '8888-8888';
|
||||||
if (inpTitular) inpTitular.value = esc.nombre_sinpe || esc.nombre || 'Soda Escolar';
|
if (inpTitular) inpTitular.value = esc.nombre_sinpe || esc.nombre || 'Soda Escolar';
|
||||||
|
if (chkActivo) chkActivo.checked = esc.sinpe_activo !== false;
|
||||||
|
if (txtMsg && esc.sinpe_mensaje_suspension) txtMsg.value = esc.sinpe_mensaje_suspension;
|
||||||
actualizarPreviewAdminSinpe();
|
actualizarPreviewAdminSinpe();
|
||||||
|
loadAdminAvisos();
|
||||||
|
|
||||||
currentSchoolHorarios = {
|
currentSchoolHorarios = {
|
||||||
hora_recreo_1: esc.hora_recreo_1 || '09:30',
|
hora_recreo_1: esc.hora_recreo_1 || '09:30',
|
||||||
@@ -6283,23 +6375,41 @@ function actualizarPreviewAdminSinpe() {
|
|||||||
const inpTitular = document.getElementById('inputAdminTitularSinpe');
|
const inpTitular = document.getElementById('inputAdminTitularSinpe');
|
||||||
const prevTel = document.getElementById('previewAdminSinpeTel');
|
const prevTel = document.getElementById('previewAdminSinpeTel');
|
||||||
const prevTitular = document.getElementById('previewAdminSinpeTitular');
|
const prevTitular = document.getElementById('previewAdminSinpeTitular');
|
||||||
|
const chkActivo = document.getElementById('chkAdminSinpeActivo');
|
||||||
|
const lblEstado = document.getElementById('lblAdminSinpeActivoEstado');
|
||||||
|
const toggleTrack = document.getElementById('toggleTrackSinpe');
|
||||||
|
const toggleThumb = document.getElementById('toggleThumbSinpe');
|
||||||
|
|
||||||
const telVal = inpTel ? (inpTel.value.trim() || '8888-8888') : '8888-8888';
|
const telVal = inpTel ? (inpTel.value.trim() || '8888-8888') : '8888-8888';
|
||||||
const titularVal = inpTitular ? (inpTitular.value.trim() || 'Soda Escolar') : 'Soda Escolar';
|
const titularVal = inpTitular ? (inpTitular.value.trim() || 'Soda Escolar') : 'Soda Escolar';
|
||||||
|
|
||||||
if (prevTel) prevTel.textContent = telVal;
|
if (prevTel) prevTel.textContent = telVal;
|
||||||
if (prevTitular) prevTitular.textContent = titularVal;
|
if (prevTitular) prevTitular.textContent = titularVal;
|
||||||
|
|
||||||
|
const isActivo = chkActivo ? chkActivo.checked : true;
|
||||||
|
if (lblEstado) {
|
||||||
|
lblEstado.textContent = isActivo ? 'Habilitado' : 'Suspendido';
|
||||||
|
lblEstado.style.color = isActivo ? '#16a34a' : '#ef4444';
|
||||||
|
}
|
||||||
|
if (toggleTrack && toggleThumb) {
|
||||||
|
toggleTrack.style.background = isActivo ? '#16a34a' : '#ef4444';
|
||||||
|
toggleThumb.style.transform = isActivo ? 'translateX(20px)' : 'translateX(0px)';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.actualizarPreviewAdminSinpe = actualizarPreviewAdminSinpe;
|
window.actualizarPreviewAdminSinpe = actualizarPreviewAdminSinpe;
|
||||||
|
|
||||||
async function guardarAdminSinpeConfig() {
|
async function guardarAdminSinpeConfig() {
|
||||||
const inpTel = document.getElementById('inputAdminTelefonoSinpe');
|
const inpTel = document.getElementById('inputAdminTelefonoSinpe');
|
||||||
const inpTitular = document.getElementById('inputAdminTitularSinpe');
|
const inpTitular = document.getElementById('inputAdminTitularSinpe');
|
||||||
|
const chkActivo = document.getElementById('chkAdminSinpeActivo');
|
||||||
|
const txtMsg = document.getElementById('txtAdminSinpeMensajeSuspension');
|
||||||
const btn = document.getElementById('btnGuardarAdminSinpe');
|
const btn = document.getElementById('btnGuardarAdminSinpe');
|
||||||
const lblBtn = document.getElementById('lblBtnGuardarAdminSinpe');
|
const lblBtn = document.getElementById('lblBtnGuardarAdminSinpe');
|
||||||
|
|
||||||
let tel = inpTel ? inpTel.value.trim() : '';
|
let tel = inpTel ? inpTel.value.trim() : '';
|
||||||
const titular = inpTitular ? inpTitular.value.trim() : '';
|
const titular = inpTitular ? inpTitular.value.trim() : '';
|
||||||
|
const sinpeActivo = chkActivo ? chkActivo.checked : true;
|
||||||
|
const sinpeMensaje = txtMsg ? txtMsg.value.trim() : '';
|
||||||
|
|
||||||
if (!tel) {
|
if (!tel) {
|
||||||
alert('Por favor ingresa el número telefónico para SINPE Móvil.');
|
alert('Por favor ingresa el número telefónico para SINPE Móvil.');
|
||||||
@@ -6332,7 +6442,9 @@ async function guardarAdminSinpeConfig() {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
escuela_id: escId,
|
escuela_id: escId,
|
||||||
telefono_sinpe: tel,
|
telefono_sinpe: tel,
|
||||||
nombre_sinpe: titular
|
nombre_sinpe: titular,
|
||||||
|
sinpe_activo: sinpeActivo,
|
||||||
|
sinpe_mensaje_suspension: sinpeMensaje
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -6342,9 +6454,10 @@ async function guardarAdminSinpeConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (window.sounds) window.sounds.playCoin();
|
if (window.sounds) window.sounds.playCoin();
|
||||||
|
const estadoTxt = data.escuela.sinpe_activo ? 'HABILITADO (Recepción activa)' : 'SUSPENDIDO (Pausa técnica activa)';
|
||||||
await showAppAlert({
|
await showAppAlert({
|
||||||
title: '¡Datos SINPE Actualizados!',
|
title: '¡Datos SINPE Actualizados!',
|
||||||
message: `El número de cobro SINPE Móvil de tu soda se actualizó exitosamente en caliente.\n\n• Teléfono: ${data.escuela.telefono_sinpe}\n• Titular: ${data.escuela.nombre_sinpe}\n\nA partir de este momento, todos los padres de familia verán estos nuevos datos de transferencia en su aplicación.`,
|
message: `La configuración de SINPE Móvil se actualizó exitosamente en caliente.\n\n• Estado: ${estadoTxt}\n• Teléfono: ${data.escuela.telefono_sinpe}\n• Titular: ${data.escuela.nombre_sinpe}\n\nA partir de este momento, todos los padres de familia verán estos cambios reflejados en tiempo real.`,
|
||||||
type: 'success',
|
type: 'success',
|
||||||
confirmText: 'Entendido'
|
confirmText: 'Entendido'
|
||||||
});
|
});
|
||||||
@@ -6358,6 +6471,324 @@ async function guardarAdminSinpeConfig() {
|
|||||||
}
|
}
|
||||||
window.guardarAdminSinpeConfig = guardarAdminSinpeConfig;
|
window.guardarAdminSinpeConfig = guardarAdminSinpeConfig;
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// DIFUSIÓN DE AVISOS & BANNERS GLOBALES
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
function openModalCrearAviso() {
|
||||||
|
const modal = document.getElementById('modalCrearAviso');
|
||||||
|
if (modal) {
|
||||||
|
modal.style.display = 'flex';
|
||||||
|
const inp = document.getElementById('inputAvisoTitulo');
|
||||||
|
if (inp) { inp.value = ''; inp.focus(); }
|
||||||
|
const txt = document.getElementById('inputAvisoMensaje');
|
||||||
|
if (txt) txt.value = '';
|
||||||
|
const selTipo = document.getElementById('selectAvisoTipo');
|
||||||
|
if (selTipo) selTipo.value = 'info';
|
||||||
|
const selAud = document.getElementById('selectAvisoAudiencia');
|
||||||
|
if (selAud) selAud.value = 'todos';
|
||||||
|
const chkDesc = document.getElementById('chkAvisoDescartable');
|
||||||
|
if (chkDesc) chkDesc.checked = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.openModalCrearAviso = openModalCrearAviso;
|
||||||
|
|
||||||
|
function closeModalCrearAviso() {
|
||||||
|
const modal = document.getElementById('modalCrearAviso');
|
||||||
|
if (modal) modal.style.display = 'none';
|
||||||
|
}
|
||||||
|
window.closeModalCrearAviso = closeModalCrearAviso;
|
||||||
|
|
||||||
|
async function guardarNuevoAviso() {
|
||||||
|
const inpTitulo = document.getElementById('inputAvisoTitulo');
|
||||||
|
const txtMensaje = document.getElementById('inputAvisoMensaje');
|
||||||
|
const selTipo = document.getElementById('selectAvisoTipo');
|
||||||
|
const selAudiencia = document.getElementById('selectAvisoAudiencia');
|
||||||
|
const chkDesc = document.getElementById('chkAvisoDescartable');
|
||||||
|
const btn = document.getElementById('btnGuardarAviso');
|
||||||
|
|
||||||
|
const titulo = inpTitulo ? inpTitulo.value.trim() : '';
|
||||||
|
const mensaje = txtMensaje ? txtMensaje.value.trim() : '';
|
||||||
|
const tipo = selTipo ? selTipo.value : 'info';
|
||||||
|
const audiencia = selAudiencia ? selAudiencia.value : 'todos';
|
||||||
|
const descartable = chkDesc ? chkDesc.checked : true;
|
||||||
|
|
||||||
|
if (!titulo) {
|
||||||
|
alert('Ingresa un título para el aviso.');
|
||||||
|
if (inpTitulo) inpTitulo.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!mensaje) {
|
||||||
|
alert('Ingresa el mensaje del aviso.');
|
||||||
|
if (txtMensaje) txtMensaje.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const escId = (currentUser && currentUser.escuela_id) || 1;
|
||||||
|
const creador = (currentUser && (currentUser.nombre_completo || currentUser.nombre || currentUser.usuario)) || 'Administrador';
|
||||||
|
|
||||||
|
if (btn) btn.disabled = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/admin/avisos', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
titulo,
|
||||||
|
mensaje,
|
||||||
|
tipo,
|
||||||
|
audiencia,
|
||||||
|
escuela_id: escId,
|
||||||
|
descartable,
|
||||||
|
creado_por: creador
|
||||||
|
})
|
||||||
|
});
|
||||||
|
const data = await res.json();
|
||||||
|
if (!res.ok || !data.success) {
|
||||||
|
throw new Error(data.error || 'No se pudo publicar el aviso');
|
||||||
|
}
|
||||||
|
|
||||||
|
closeModalCrearAviso();
|
||||||
|
if (window.sounds) window.sounds.playCoin();
|
||||||
|
loadAdminAvisos();
|
||||||
|
cargarAvisosActivos();
|
||||||
|
if (typeof showToastNotification === 'function') {
|
||||||
|
showToastNotification('📢 Aviso publicado en tiempo real');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
alert('Error al publicar aviso: ' + err.message);
|
||||||
|
} finally {
|
||||||
|
if (btn) btn.disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.guardarNuevoAviso = guardarNuevoAviso;
|
||||||
|
|
||||||
|
async function loadAdminAvisos() {
|
||||||
|
const container = document.getElementById('adminAvisosTable');
|
||||||
|
const emptyMsg = document.getElementById('adminAvisosEmptyMsg');
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const escId = (currentUser && currentUser.escuela_id) || 1;
|
||||||
|
const res = await fetch(`/api/admin/avisos?escuela_id=${escId}`);
|
||||||
|
const data = await res.json();
|
||||||
|
const avisos = (data && data.avisos) || [];
|
||||||
|
|
||||||
|
if (avisos.length === 0) {
|
||||||
|
container.innerHTML = '';
|
||||||
|
if (emptyMsg) emptyMsg.style.display = 'block';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emptyMsg) emptyMsg.style.display = 'none';
|
||||||
|
|
||||||
|
const badgesTipo = {
|
||||||
|
info: { label: 'ℹ️ Info', bg: '#e0f2fe', color: '#0369a1' },
|
||||||
|
promo: { label: '🎉 Promo', bg: '#f3e8ff', color: '#7e22ce' },
|
||||||
|
alerta: { label: '⚠️ Alerta', bg: '#fef3c7', color: '#b45309' },
|
||||||
|
urgente: { label: '🚨 Urgente', bg: '#fee2e2', color: '#b91c1c' }
|
||||||
|
};
|
||||||
|
|
||||||
|
const labelsAudiencia = {
|
||||||
|
todos: '👥 Todos',
|
||||||
|
padres: '👨👩👧 Padres',
|
||||||
|
estudiantes: '🎒 Estudiantes',
|
||||||
|
pos: '🖥️ POS'
|
||||||
|
};
|
||||||
|
|
||||||
|
container.innerHTML = avisos.map(a => {
|
||||||
|
const tb = badgesTipo[a.tipo] || badgesTipo.info;
|
||||||
|
const aud = labelsAudiencia[a.audiencia] || a.audiencia;
|
||||||
|
const isActivo = a.activo === 1 || a.activo === true;
|
||||||
|
const descText = (a.descartable === 1 || a.descartable === true) ? 'Descartable' : 'Permanente';
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;">
|
||||||
|
<div style="flex: 1; min-width: 200px;">
|
||||||
|
<div style="display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap;">
|
||||||
|
<span style="background: ${tb.bg}; color: ${tb.color}; font-size: 0.70rem; font-weight: 800; padding: 2px 7px; border-radius: 6px;">${tb.label}</span>
|
||||||
|
<span style="background: var(--bg-main); border: 1px solid var(--border); color: var(--text-muted); font-size: 0.68rem; font-weight: 700; padding: 2px 6px; border-radius: 6px;">${aud}</span>
|
||||||
|
<span style="font-size: 0.68rem; color: var(--text-muted);">${descText}</span>
|
||||||
|
<strong style="color: var(--text-main); font-size: 0.88rem;">${escapeHtml(a.titulo)}</strong>
|
||||||
|
</div>
|
||||||
|
<p style="margin: 0; font-size: 0.78rem; color: var(--text-muted); line-height: 1.35;">${escapeHtml(a.mensaje)}</p>
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; align-items: center; gap: 10px;">
|
||||||
|
<button type="button" onclick="toggleAvisoEstado(${a.id}, ${!isActivo})" class="btn-saas" style="font-size: 0.74rem; font-weight: 800; padding: 5px 10px; border-radius: 8px; ${isActivo ? 'background: #dcfce7; color: #15803d; border: 1px solid #86efac;' : 'background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5;'}">
|
||||||
|
${isActivo ? '● Activo' : '○ Pausado'}
|
||||||
|
</button>
|
||||||
|
<button type="button" onclick="eliminarAvisoAdmin(${a.id})" style="background: none; border: none; cursor: pointer; color: #94a3b8; padding: 4px; border-radius: 6px;" title="Eliminar aviso" onmouseover="this.style.color='#ef4444'" onmouseout="this.style.color='#94a3b8'">
|
||||||
|
<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}).join('');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error cargando avisos admin:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.loadAdminAvisos = loadAdminAvisos;
|
||||||
|
|
||||||
|
async function toggleAvisoEstado(id, nuevoEstado) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/admin/avisos/${id}/estado`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ activo: nuevoEstado })
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
if (window.sounds) window.sounds.playTap();
|
||||||
|
loadAdminAvisos();
|
||||||
|
cargarAvisosActivos();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error cambiando estado aviso:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.toggleAvisoEstado = toggleAvisoEstado;
|
||||||
|
|
||||||
|
async function eliminarAvisoAdmin(id) {
|
||||||
|
if (!confirm('¿Seguro que deseas eliminar este aviso permanentemente?')) return;
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/admin/avisos/${id}`, { method: 'DELETE' });
|
||||||
|
if (res.ok) {
|
||||||
|
if (window.sounds) window.sounds.playTap();
|
||||||
|
loadAdminAvisos();
|
||||||
|
cargarAvisosActivos();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error eliminando aviso:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.eliminarAvisoAdmin = eliminarAvisoAdmin;
|
||||||
|
|
||||||
|
let dismissedAvisosIds = [];
|
||||||
|
try {
|
||||||
|
const stored = SafeStorage.getItem('sibopay_dismissed_avisos');
|
||||||
|
if (stored) dismissedAvisosIds = JSON.parse(stored);
|
||||||
|
} catch (e) {
|
||||||
|
dismissedAvisosIds = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function descartarAviso(id) {
|
||||||
|
if (!dismissedAvisosIds.includes(id)) {
|
||||||
|
dismissedAvisosIds.push(id);
|
||||||
|
try {
|
||||||
|
SafeStorage.setItem('sibopay_dismissed_avisos', JSON.stringify(dismissedAvisosIds));
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
const el = document.getElementById(`avisoBanner-${id}`);
|
||||||
|
if (el) {
|
||||||
|
el.style.transition = 'all 0.3s ease';
|
||||||
|
el.style.opacity = '0';
|
||||||
|
el.style.transform = 'translateY(-8px)';
|
||||||
|
setTimeout(() => { if (el) el.remove(); }, 300);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.descartarAviso = descartarAviso;
|
||||||
|
|
||||||
|
async function cargarAvisosActivos() {
|
||||||
|
try {
|
||||||
|
const escId = (currentUser && currentUser.escuela_id) || (currentStudent && currentStudent.escuela_id) || (currentParentChild && currentParentChild.escuela_id) || 1;
|
||||||
|
let rolAudiencia = 'todos';
|
||||||
|
if (currentUser) {
|
||||||
|
if (currentUser.rol === 'padre') rolAudiencia = 'padres';
|
||||||
|
else if (currentUser.rol === 'estudiante') rolAudiencia = 'estudiantes';
|
||||||
|
else if (currentUser.rol === 'cajero' || currentUser.rol === 'pos') rolAudiencia = 'pos';
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await fetch(`/api/avisos/activos?escuela_id=${escId}&audiencia=${rolAudiencia}`);
|
||||||
|
const data = await res.json();
|
||||||
|
const avisos = (data && data.avisos) || [];
|
||||||
|
|
||||||
|
// Filtrar descartados
|
||||||
|
const visibles = avisos.filter(a => {
|
||||||
|
const isDesc = a.descartable === 1 || a.descartable === true;
|
||||||
|
if (isDesc && dismissedAvisosIds.includes(a.id)) return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const estilosPorTipo = {
|
||||||
|
info: {
|
||||||
|
bg: '#eff6ff',
|
||||||
|
border: '#93c5fd',
|
||||||
|
titleColor: '#1e40af',
|
||||||
|
textColor: '#1e3a8a',
|
||||||
|
icon: 'ℹ️'
|
||||||
|
},
|
||||||
|
promo: {
|
||||||
|
bg: '#f5f3ff',
|
||||||
|
border: '#c4b5fd',
|
||||||
|
titleColor: '#6b21a8',
|
||||||
|
textColor: '#581c87',
|
||||||
|
icon: '🎉'
|
||||||
|
},
|
||||||
|
alerta: {
|
||||||
|
bg: '#fffbeb',
|
||||||
|
border: '#fde68a',
|
||||||
|
titleColor: '#92400e',
|
||||||
|
textColor: '#78350f',
|
||||||
|
icon: '⚠️'
|
||||||
|
},
|
||||||
|
urgente: {
|
||||||
|
bg: '#fff1f2',
|
||||||
|
border: '#fecdd3',
|
||||||
|
titleColor: '#9f1239',
|
||||||
|
textColor: '#881337',
|
||||||
|
icon: '🚨'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function renderBannerHtml(a) {
|
||||||
|
const st = estilosPorTipo[a.tipo] || estilosPorTipo.info;
|
||||||
|
const isDesc = a.descartable === 1 || a.descartable === true;
|
||||||
|
return `
|
||||||
|
<div id="avisoBanner-${a.id}" style="background: ${st.bg}; border: 1.5px solid ${st.border}; border-radius: 12px; padding: 10px 14px; display: flex; align-items: flex-start; gap: 10px; box-shadow: 0 2px 6px rgba(0,0,0,0.04); position: relative;">
|
||||||
|
<span style="font-size: 1.25rem; flex-shrink: 0; line-height: 1.2;">${st.icon}</span>
|
||||||
|
<div style="flex: 1; min-width: 0; padding-right: ${isDesc ? '22px' : '0'};">
|
||||||
|
<strong style="display: block; font-size: 0.86rem; color: ${st.titleColor}; line-height: 1.25; margin-bottom: 2px;">
|
||||||
|
${escapeHtml(a.titulo)}
|
||||||
|
</strong>
|
||||||
|
<span style="font-size: 0.78rem; color: ${st.textColor}; line-height: 1.35; display: block;">
|
||||||
|
${escapeHtml(a.mensaje)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
${isDesc ? `
|
||||||
|
<button type="button" onclick="descartarAviso(${a.id})" style="position: absolute; top: 8px; right: 8px; background: none; border: none; font-size: 1.05rem; cursor: pointer; color: ${st.titleColor}; line-height: 1; padding: 2px 5px; opacity: 0.7;" title="Cerrar aviso" onmouseover="this.style.opacity='1'" onmouseout="this.style.opacity='0.7'">
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
` : ''}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renderizar en contenedor de Padres
|
||||||
|
const parentContainer = document.getElementById('parentGlobalBannerContainer');
|
||||||
|
if (parentContainer) {
|
||||||
|
const avisosPadres = visibles.filter(a => a.audiencia === 'todos' || a.audiencia === 'padres');
|
||||||
|
parentContainer.innerHTML = avisosPadres.map(renderBannerHtml).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renderizar en contenedor de Estudiantes
|
||||||
|
const studentContainer = document.getElementById('studentGlobalBannerContainer');
|
||||||
|
if (studentContainer) {
|
||||||
|
const avisosEstudiantes = visibles.filter(a => a.audiencia === 'todos' || a.audiencia === 'estudiantes');
|
||||||
|
studentContainer.innerHTML = avisosEstudiantes.map(renderBannerHtml).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Renderizar en contenedor de POS (si existe)
|
||||||
|
const posContainer = document.getElementById('posGlobalBannerContainer');
|
||||||
|
if (posContainer) {
|
||||||
|
const avisosPos = visibles.filter(a => a.audiencia === 'todos' || a.audiencia === 'pos');
|
||||||
|
posContainer.innerHTML = avisosPos.map(renderBannerHtml).join('');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error cargando avisos activos:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.cargarAvisosActivos = cargarAvisosActivos;
|
||||||
|
|
||||||
async function guardarHorariosEscolares() {
|
async function guardarHorariosEscolares() {
|
||||||
const inpR1 = document.getElementById('inputAdminHoraRecreo1');
|
const inpR1 = document.getElementById('inputAdminHoraRecreo1');
|
||||||
const inpAlm = document.getElementById('inputAdminHoraAlmuerzo');
|
const inpAlm = document.getElementById('inputAdminHoraAlmuerzo');
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
await cargarHorariosPos();
|
await cargarHorariosPos();
|
||||||
// La cámara se activa bajo demanda al cobrar o identificar, NO al entrar
|
// La cámara se activa bajo demanda al cobrar o identificar, NO al entrar
|
||||||
initSSE();
|
initSSE();
|
||||||
|
cargarAvisosActivosPos();
|
||||||
initPistolScanner();
|
initPistolScanner();
|
||||||
initQuickProductEvents();
|
initQuickProductEvents();
|
||||||
|
|
||||||
@@ -2094,8 +2095,98 @@ function initSSE() {
|
|||||||
loadSinpeRequests();
|
loadSinpeRequests();
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Avisos globales en tiempo real en la terminal POS
|
||||||
|
sseSource.addEventListener('aviso_publicado', () => {
|
||||||
|
cargarAvisosActivosPos();
|
||||||
|
});
|
||||||
|
sseSource.addEventListener('aviso_estado_cambiado', () => {
|
||||||
|
cargarAvisosActivosPos();
|
||||||
|
});
|
||||||
|
sseSource.addEventListener('aviso_eliminado', () => {
|
||||||
|
cargarAvisosActivosPos();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// DIFUSIÓN DE AVISOS EN POS
|
||||||
|
// ==========================================
|
||||||
|
let dismissedAvisosPos = [];
|
||||||
|
try {
|
||||||
|
const stored = SafeStorage.getItem('sibopay_dismissed_avisos_pos');
|
||||||
|
if (stored) dismissedAvisosPos = JSON.parse(stored);
|
||||||
|
} catch (e) {
|
||||||
|
dismissedAvisosPos = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function descartarAvisoPos(id) {
|
||||||
|
if (!dismissedAvisosPos.includes(id)) {
|
||||||
|
dismissedAvisosPos.push(id);
|
||||||
|
try {
|
||||||
|
SafeStorage.setItem('sibopay_dismissed_avisos_pos', JSON.stringify(dismissedAvisosPos));
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
const el = document.getElementById(`posAvisoBanner-${id}`);
|
||||||
|
if (el) {
|
||||||
|
el.style.transition = 'all 0.3s ease';
|
||||||
|
el.style.opacity = '0';
|
||||||
|
el.style.transform = 'translateY(-8px)';
|
||||||
|
setTimeout(() => { if (el) el.remove(); }, 300);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.descartarAvisoPos = descartarAvisoPos;
|
||||||
|
|
||||||
|
async function cargarAvisosActivosPos() {
|
||||||
|
const container = document.getElementById('posGlobalBannerContainer');
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const escId = getPosEscuelaId() || 1;
|
||||||
|
const res = await fetch(`/api/avisos/activos?escuela_id=${escId}&audiencia=pos`);
|
||||||
|
const data = await res.json();
|
||||||
|
const avisos = (data && data.avisos) || [];
|
||||||
|
|
||||||
|
const visibles = avisos.filter(a => {
|
||||||
|
const isDesc = a.descartable === 1 || a.descartable === true;
|
||||||
|
if (isDesc && dismissedAvisosPos.includes(a.id)) return false;
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
const estilos = {
|
||||||
|
info: { bg: '#eff6ff', border: '#93c5fd', title: '#1e40af', text: '#1e3a8a', icon: 'ℹ️' },
|
||||||
|
promo: { bg: '#f5f3ff', border: '#c4b5fd', title: '#6b21a8', text: '#581c87', icon: '🎉' },
|
||||||
|
alerta: { bg: '#fffbeb', border: '#fde68a', title: '#92400e', text: '#78350f', icon: '⚠️' },
|
||||||
|
urgente: { bg: '#fff1f2', border: '#fecdd3', title: '#9f1239', text: '#881337', icon: '🚨' }
|
||||||
|
};
|
||||||
|
|
||||||
|
container.innerHTML = visibles.map(a => {
|
||||||
|
const st = estilos[a.tipo] || estilos.info;
|
||||||
|
const isDesc = a.descartable === 1 || a.descartable === true;
|
||||||
|
return `
|
||||||
|
<div id="posAvisoBanner-${a.id}" style="background: ${st.bg}; border: 1.5px solid ${st.border}; border-radius: 12px; padding: 10px 14px; display: flex; align-items: flex-start; gap: 10px; box-shadow: 0 2px 6px rgba(0,0,0,0.04); position: relative;">
|
||||||
|
<span style="font-size: 1.25rem; flex-shrink: 0; line-height: 1.2;">${st.icon}</span>
|
||||||
|
<div style="flex: 1; min-width: 0; padding-right: ${isDesc ? '22px' : '0'};">
|
||||||
|
<strong style="display: block; font-size: 0.86rem; color: ${st.title}; line-height: 1.25; margin-bottom: 2px;">
|
||||||
|
${escapeHtml(a.titulo)}
|
||||||
|
</strong>
|
||||||
|
<span style="font-size: 0.78rem; color: ${st.text}; line-height: 1.35; display: block;">
|
||||||
|
${escapeHtml(a.mensaje)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
${isDesc ? `
|
||||||
|
<button type="button" onclick="descartarAvisoPos(${a.id})" style="position: absolute; top: 8px; right: 8px; background: none; border: none; font-size: 1.05rem; cursor: pointer; color: ${st.title}; line-height: 1; padding: 2px 5px; opacity: 0.7;" title="Cerrar aviso" onmouseover="this.style.opacity='1'" onmouseout="this.style.opacity='0.7'">
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
` : ''}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}).join('');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error cargando avisos POS:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.cargarAvisosActivosPos = cargarAvisosActivosPos;
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// SISTEMA DE NOTIFICACIONES PUSH & EN-APP (RECARGAS SINPE)
|
// SISTEMA DE NOTIFICACIONES PUSH & EN-APP (RECARGAS SINPE)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
+4
-1
@@ -104,6 +104,9 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- BANNER DE AVISOS GLOBALES PARA POS -->
|
||||||
|
<div id="posGlobalBannerContainer" style="display: flex; flex-direction: column; gap: 8px; margin: 10px 14px 0 14px;"></div>
|
||||||
|
|
||||||
<div class="pos-layout">
|
<div class="pos-layout">
|
||||||
<!-- PANEL IZQUIERDO: CATÁLOGO TÁCTIL Y COLA DE PRE-ÓRDENES -->
|
<!-- PANEL IZQUIERDO: CATÁLOGO TÁCTIL Y COLA DE PRE-ÓRDENES -->
|
||||||
<div class="pos-catalog-pane">
|
<div class="pos-catalog-pane">
|
||||||
@@ -691,6 +694,6 @@
|
|||||||
<script src="/js/sounds.js?v=13.8"></script>
|
<script src="/js/sounds.js?v=13.8"></script>
|
||||||
<script src="/js/jsQR.js"></script>
|
<script src="/js/jsQR.js"></script>
|
||||||
<script src="/js/food-icons.js?v=1.1"></script>
|
<script src="/js/food-icons.js?v=1.1"></script>
|
||||||
<script src="/js/pos.js?v=14.0"></script>
|
<script src="/js/pos.js?v=20.5"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+4
-4
@@ -1,5 +1,5 @@
|
|||||||
// SiboPay PWA Service Worker v20.4 - Ultra Fast Startup & Stale-While-Revalidate
|
// SiboPay PWA Service Worker v20.5 - Ultra Fast Startup & Stale-While-Revalidate
|
||||||
const CACHE_NAME = 'sibopay-v20.4';
|
const CACHE_NAME = 'sibopay-v20.5';
|
||||||
const STATIC_ASSETS = [
|
const STATIC_ASSETS = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
@@ -11,8 +11,8 @@ const STATIC_ASSETS = [
|
|||||||
'/css/styles.css?v=19.9',
|
'/css/styles.css?v=19.9',
|
||||||
'/css/desktop.css?v=2.2',
|
'/css/desktop.css?v=2.2',
|
||||||
'/js/dialogs.js?v=19.4',
|
'/js/dialogs.js?v=19.4',
|
||||||
'/js/app.js?v=20.4',
|
'/js/app.js?v=20.5',
|
||||||
'/js/pos.js',
|
'/js/pos.js?v=20.5',
|
||||||
'/js/sounds.js?v=19.4',
|
'/js/sounds.js?v=19.4',
|
||||||
'/js/food-icons.js?v=19.4',
|
'/js/food-icons.js?v=19.4',
|
||||||
'/icons/icon-192.png',
|
'/icons/icon-192.png',
|
||||||
|
|||||||
+133
-17
@@ -127,6 +127,24 @@ function initDatabase() {
|
|||||||
try { db.exec("ALTER TABLE escuelas ADD COLUMN IF NOT EXISTS hora_recreo_1 VARCHAR(20) DEFAULT '09:30';"); } catch (_) {}
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN IF NOT EXISTS hora_recreo_1 VARCHAR(20) DEFAULT '09:30';"); } catch (_) {}
|
||||||
try { db.exec("ALTER TABLE escuelas ADD COLUMN IF NOT EXISTS hora_almuerzo VARCHAR(20) DEFAULT '11:45';"); } catch (_) {}
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN IF NOT EXISTS hora_almuerzo VARCHAR(20) DEFAULT '11:45';"); } catch (_) {}
|
||||||
try { db.exec("ALTER TABLE escuelas ADD COLUMN IF NOT EXISTS hora_recreo_2 VARCHAR(20) DEFAULT '13:45';"); } catch (_) {}
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN IF NOT EXISTS hora_recreo_2 VARCHAR(20) DEFAULT '13:45';"); } catch (_) {}
|
||||||
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN IF NOT EXISTS sinpe_activo BOOLEAN DEFAULT TRUE;"); } catch (_) {}
|
||||||
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN IF NOT EXISTS sinpe_mensaje_suspension TEXT DEFAULT 'Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica. Se reanudarán a la brevedad.';"); } catch (_) {}
|
||||||
|
try {
|
||||||
|
db.exec(`
|
||||||
|
CREATE TABLE IF NOT EXISTS avisos_globales (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
titulo VARCHAR(150) NOT NULL,
|
||||||
|
mensaje TEXT NOT NULL,
|
||||||
|
tipo VARCHAR(30) DEFAULT 'info',
|
||||||
|
audiencia VARCHAR(30) DEFAULT 'todos',
|
||||||
|
escuela_id INTEGER,
|
||||||
|
descartable INTEGER DEFAULT 1,
|
||||||
|
activo INTEGER DEFAULT 1,
|
||||||
|
creado_por VARCHAR(100),
|
||||||
|
creado_en TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
} catch (_) {}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -354,6 +372,24 @@ function initDatabase() {
|
|||||||
try { db.exec("ALTER TABLE escuelas ADD COLUMN hora_recreo_1 TEXT DEFAULT '09:30'"); } catch (e) {}
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN hora_recreo_1 TEXT DEFAULT '09:30'"); } catch (e) {}
|
||||||
try { db.exec("ALTER TABLE escuelas ADD COLUMN hora_almuerzo TEXT DEFAULT '11:45'"); } catch (e) {}
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN hora_almuerzo TEXT DEFAULT '11:45'"); } catch (e) {}
|
||||||
try { db.exec("ALTER TABLE escuelas ADD COLUMN hora_recreo_2 TEXT DEFAULT '13:45'"); } catch (e) {}
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN hora_recreo_2 TEXT DEFAULT '13:45'"); } catch (e) {}
|
||||||
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN sinpe_activo INTEGER DEFAULT 1"); } catch (e) {}
|
||||||
|
try { db.exec("ALTER TABLE escuelas ADD COLUMN sinpe_mensaje_suspension TEXT DEFAULT 'Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica. Se reanudarán a la brevedad.'"); } catch (e) {}
|
||||||
|
try {
|
||||||
|
db.exec(`
|
||||||
|
CREATE TABLE IF NOT EXISTS avisos_globales (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
titulo TEXT NOT NULL,
|
||||||
|
mensaje TEXT NOT NULL,
|
||||||
|
tipo TEXT DEFAULT 'info',
|
||||||
|
audiencia TEXT DEFAULT 'todos',
|
||||||
|
escuela_id INTEGER,
|
||||||
|
descartable INTEGER DEFAULT 1,
|
||||||
|
activo INTEGER DEFAULT 1,
|
||||||
|
creado_por TEXT,
|
||||||
|
creado_en DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
`);
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
// 8. Relación N:M Padres - Estudiantes
|
// 8. Relación N:M Padres - Estudiantes
|
||||||
try {
|
try {
|
||||||
@@ -630,6 +666,8 @@ const DEFAULTS_CONFIG = [
|
|||||||
{ clave: 'sinpe_monto_minimo', valor: '1000', categoria: 'finanzas', descripcion: 'Monto mínimo permitido para recargas por SINPE Móvil (CRC)' },
|
{ clave: 'sinpe_monto_minimo', valor: '1000', categoria: 'finanzas', descripcion: 'Monto mínimo permitido para recargas por SINPE Móvil (CRC)' },
|
||||||
{ clave: 'sinpe_monto_maximo', valor: '50000', categoria: 'finanzas', descripcion: 'Monto máximo de seguridad por transacción SINPE Móvil (CRC)' },
|
{ clave: 'sinpe_monto_maximo', valor: '50000', categoria: 'finanzas', descripcion: 'Monto máximo de seguridad por transacción SINPE Móvil (CRC)' },
|
||||||
{ clave: 'sinpe_montos_sugeridos', valor: '2000,3000,5000,10000', categoria: 'finanzas', descripcion: 'Botones de montos sugeridos para recarga rápida en la app' },
|
{ clave: 'sinpe_montos_sugeridos', valor: '2000,3000,5000,10000', categoria: 'finanzas', descripcion: 'Botones de montos sugeridos para recarga rápida en la app' },
|
||||||
|
{ clave: 'sinpe_habilitado_global', valor: '1', categoria: 'finanzas', descripcion: 'Interruptor maestro: Habilita o suspende recargas SINPE en todo el sistema (1=Habilitado, 0=Suspendido)' },
|
||||||
|
{ clave: 'sinpe_mensaje_suspension_global', valor: 'Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica. Se reanudarán a la brevedad.', categoria: 'finanzas', descripcion: 'Mensaje desplegado cuando las recargas SINPE están suspendidas globalmente' },
|
||||||
{ clave: 'estudiante_limite_diario_default', valor: '3000', categoria: 'estudiantes', descripcion: 'Límite de gasto diario por defecto asignado a nuevos estudiantes (CRC)' },
|
{ clave: 'estudiante_limite_diario_default', valor: '3000', categoria: 'estudiantes', descripcion: 'Límite de gasto diario por defecto asignado a nuevos estudiantes (CRC)' },
|
||||||
{ clave: 'estudiante_permitir_transferencias_default', valor: '1', categoria: 'estudiantes', descripcion: 'Permitir transferencias P2P a nuevos estudiantes por defecto (1=Sí, 0=No)' },
|
{ clave: 'estudiante_permitir_transferencias_default', valor: '1', categoria: 'estudiantes', descripcion: 'Permitir transferencias P2P a nuevos estudiantes por defecto (1=Sí, 0=No)' },
|
||||||
{ clave: 'permitir_transferencias_p2p', valor: '1', categoria: 'estudiantes', descripcion: 'Interruptor maestro: Habilita o desactiva transferencias P2P en todo el sistema (1=Sí, 0=No)' },
|
{ clave: 'permitir_transferencias_p2p', valor: '1', categoria: 'estudiantes', descripcion: 'Interruptor maestro: Habilita o desactiva transferencias P2P en todo el sistema (1=Sí, 0=No)' },
|
||||||
@@ -988,7 +1026,7 @@ function obtenerHorariosEscuela(escuelaId = 1) {
|
|||||||
|
|
||||||
function obtenerDatosEscuela(escuelaId = 1) {
|
function obtenerDatosEscuela(escuelaId = 1) {
|
||||||
try {
|
try {
|
||||||
const row = db.prepare('SELECT id, codigo, nombre, telefono_sinpe, nombre_sinpe, concesionario, hora_recreo_1, hora_almuerzo, hora_recreo_2, activo FROM escuelas WHERE id = ?').get(escuelaId || 1);
|
const row = db.prepare('SELECT id, codigo, nombre, telefono_sinpe, nombre_sinpe, concesionario, hora_recreo_1, hora_almuerzo, hora_recreo_2, activo, sinpe_activo, sinpe_mensaje_suspension FROM escuelas WHERE id = ?').get(escuelaId || 1);
|
||||||
if (row) {
|
if (row) {
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
@@ -1003,7 +1041,9 @@ function obtenerDatosEscuela(escuelaId = 1) {
|
|||||||
hora_recreo_1_fmt: formatTime12h(row.hora_recreo_1 || '09:30'),
|
hora_recreo_1_fmt: formatTime12h(row.hora_recreo_1 || '09:30'),
|
||||||
hora_almuerzo_fmt: formatTime12h(row.hora_almuerzo || '11:45'),
|
hora_almuerzo_fmt: formatTime12h(row.hora_almuerzo || '11:45'),
|
||||||
hora_recreo_2_fmt: formatTime12h(row.hora_recreo_2 || '13:45'),
|
hora_recreo_2_fmt: formatTime12h(row.hora_recreo_2 || '13:45'),
|
||||||
activo: row.activo
|
activo: row.activo,
|
||||||
|
sinpe_activo: row.sinpe_activo !== 0 && row.sinpe_activo !== false,
|
||||||
|
sinpe_mensaje_suspension: row.sinpe_mensaje_suspension || 'Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica. Se reanudarán a la brevedad.'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -1026,24 +1066,22 @@ function obtenerDatosEscuela(escuelaId = 1) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function actualizarSinpeEscuela(escuelaId = 1, { telefono_sinpe, nombre_sinpe, concesionario }) {
|
function actualizarSinpeEscuela(escuelaId = 1, { telefono_sinpe, nombre_sinpe, concesionario, sinpe_activo, sinpe_mensaje_suspension }) {
|
||||||
const tel = String(telefono_sinpe || '8888-8888').trim();
|
const tel = String(telefono_sinpe || '8888-8888').trim();
|
||||||
const nom = String(nombre_sinpe || '').trim();
|
const nom = String(nombre_sinpe || '').trim();
|
||||||
const conce = concesionario !== undefined ? String(concesionario).trim() : null;
|
const conce = concesionario !== undefined ? String(concesionario).trim() : null;
|
||||||
|
const activo = sinpe_activo !== undefined ? (sinpe_activo ? 1 : 0) : null;
|
||||||
|
const msgSuspension = sinpe_mensaje_suspension !== undefined ? String(sinpe_mensaje_suspension || '').trim() : null;
|
||||||
|
|
||||||
if (conce !== null) {
|
let setSql = 'telefono_sinpe = ?, nombre_sinpe = ?';
|
||||||
db.prepare(`
|
const params = [tel, nom];
|
||||||
UPDATE escuelas
|
|
||||||
SET telefono_sinpe = ?, nombre_sinpe = ?, concesionario = ?
|
if (conce !== null) { setSql += ', concesionario = ?'; params.push(conce); }
|
||||||
WHERE id = ?
|
if (activo !== null) { setSql += ', sinpe_activo = ?'; params.push(activo); }
|
||||||
`).run(tel, nom, conce, escuelaId || 1);
|
if (msgSuspension !== null) { setSql += ', sinpe_mensaje_suspension = ?'; params.push(msgSuspension); }
|
||||||
} else {
|
|
||||||
db.prepare(`
|
params.push(escuelaId || 1);
|
||||||
UPDATE escuelas
|
db.prepare(`UPDATE escuelas SET ${setSql} WHERE id = ?`).run(...params);
|
||||||
SET telefono_sinpe = ?, nombre_sinpe = ?
|
|
||||||
WHERE id = ?
|
|
||||||
`).run(tel, nom, escuelaId || 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return obtenerDatosEscuela(escuelaId || 1);
|
return obtenerDatosEscuela(escuelaId || 1);
|
||||||
}
|
}
|
||||||
@@ -2691,6 +2729,79 @@ function enriquecerEstudianteFinanzas(est) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// AVISOS GLOBALES / BANNERS DE DIFUSIÓN
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
function obtenerAvisosActivos(escuelaId = null, audiencia = null) {
|
||||||
|
try {
|
||||||
|
let q = 'SELECT * FROM avisos_globales WHERE activo = 1';
|
||||||
|
const params = [];
|
||||||
|
if (escuelaId) {
|
||||||
|
q += ' AND (escuela_id IS NULL OR escuela_id = ?)';
|
||||||
|
params.push(escuelaId);
|
||||||
|
}
|
||||||
|
if (audiencia && audiencia !== 'todos') {
|
||||||
|
q += ' AND (audiencia = ? OR audiencia = \'todos\')';
|
||||||
|
params.push(audiencia);
|
||||||
|
}
|
||||||
|
q += ' ORDER BY creado_en DESC';
|
||||||
|
return db.prepare(q).all(...params);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error obtenerAvisosActivos:', e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function obtenerTodosLosAvisos(escuelaId = null) {
|
||||||
|
try {
|
||||||
|
let q = 'SELECT * FROM avisos_globales WHERE 1=1';
|
||||||
|
const params = [];
|
||||||
|
if (escuelaId) {
|
||||||
|
q += ' AND (escuela_id IS NULL OR escuela_id = ?)';
|
||||||
|
params.push(escuelaId);
|
||||||
|
}
|
||||||
|
q += ' ORDER BY creado_en DESC LIMIT 100';
|
||||||
|
return db.prepare(q).all(...params);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error obtenerTodosLosAvisos:', e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function crearAviso({ titulo, mensaje, tipo = 'info', audiencia = 'todos', escuelaId = null, descartable = 1, creadoPor = null }) {
|
||||||
|
try {
|
||||||
|
const r = db.prepare(`
|
||||||
|
INSERT INTO avisos_globales (titulo, mensaje, tipo, audiencia, escuela_id, descartable, activo, creado_por)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, 1, ?)
|
||||||
|
`).run(titulo, mensaje, tipo, audiencia, escuelaId, descartable ? 1 : 0, creadoPor);
|
||||||
|
const id = r.lastInsertRowid || r.id;
|
||||||
|
return db.prepare('SELECT * FROM avisos_globales WHERE id = ?').get(id);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error crearAviso:', e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function actualizarEstadoAviso(avisoId, activo) {
|
||||||
|
try {
|
||||||
|
db.prepare('UPDATE avisos_globales SET activo = ? WHERE id = ?').run(activo ? 1 : 0, avisoId);
|
||||||
|
return db.prepare('SELECT * FROM avisos_globales WHERE id = ?').get(avisoId);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error actualizarEstadoAviso:', e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function eliminarAviso(avisoId) {
|
||||||
|
try {
|
||||||
|
return db.prepare('DELETE FROM avisos_globales WHERE id = ?').run(avisoId);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error eliminarAviso:', e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
db,
|
db,
|
||||||
initDatabase,
|
initDatabase,
|
||||||
@@ -2725,5 +2836,10 @@ module.exports = {
|
|||||||
vincularBancoAEstudianteDev,
|
vincularBancoAEstudianteDev,
|
||||||
obtenerConfiguraciones,
|
obtenerConfiguraciones,
|
||||||
guardarConfiguracion,
|
guardarConfiguracion,
|
||||||
guardarConfiguracionesMultiples
|
guardarConfiguracionesMultiples,
|
||||||
|
obtenerAvisosActivos,
|
||||||
|
obtenerTodosLosAvisos,
|
||||||
|
crearAviso,
|
||||||
|
actualizarEstadoAviso,
|
||||||
|
eliminarAviso
|
||||||
};
|
};
|
||||||
|
|||||||
+143
-8
@@ -43,7 +43,12 @@ const {
|
|||||||
rechazarSolicitudDev,
|
rechazarSolicitudDev,
|
||||||
vincularBancoAEstudianteDev,
|
vincularBancoAEstudianteDev,
|
||||||
obtenerConfiguraciones,
|
obtenerConfiguraciones,
|
||||||
guardarConfiguracionesMultiples
|
guardarConfiguracionesMultiples,
|
||||||
|
obtenerAvisosActivos,
|
||||||
|
obtenerTodosLosAvisos,
|
||||||
|
crearAviso,
|
||||||
|
actualizarEstadoAviso,
|
||||||
|
eliminarAviso
|
||||||
} = require('./db');
|
} = require('./db');
|
||||||
const { checkSinpeEmailsOnce, simularSinpeEmail } = require('./sinpeImapService');
|
const { checkSinpeEmailsOnce, simularSinpeEmail } = require('./sinpeImapService');
|
||||||
const { normalizarCodigoDetalle, parseSinpeEmail } = require('./sinpeParser');
|
const { normalizarCodigoDetalle, parseSinpeEmail } = require('./sinpeParser');
|
||||||
@@ -3571,31 +3576,37 @@ app.get('/api/admin/escuela/info', (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Modificar Teléfono y Titular de SINPE Móvil de la Escuela (Admin / Developer)
|
// Modificar Teléfono, Titular y Estado de suspensión de SINPE Móvil (Admin / Developer)
|
||||||
app.put('/api/admin/escuela/sinpe', (req, res) => {
|
app.put('/api/admin/escuela/sinpe', (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { escuela_id, telefono_sinpe, nombre_sinpe, concesionario } = req.body || {};
|
const { escuela_id, telefono_sinpe, nombre_sinpe, concesionario, sinpe_activo, sinpe_mensaje_suspension } = req.body || {};
|
||||||
if (!telefono_sinpe || !String(telefono_sinpe).trim()) {
|
if (!telefono_sinpe || !String(telefono_sinpe).trim()) {
|
||||||
return res.status(400).json({ error: 'El número de teléfono SINPE Móvil es obligatorio' });
|
return res.status(400).json({ error: 'El número de teléfono SINPE Móvil es obligatorio' });
|
||||||
}
|
}
|
||||||
const cleanTel = String(telefono_sinpe).trim();
|
const cleanTel = String(telefono_sinpe).trim();
|
||||||
const cleanNom = String(nombre_sinpe || '').trim();
|
const cleanNom = String(nombre_sinpe || '').trim();
|
||||||
|
const cleanMsg = sinpe_mensaje_suspension !== undefined ? String(sinpe_mensaje_suspension || '').trim() : undefined;
|
||||||
|
|
||||||
const escuelaId = escuela_id ? parseInt(escuela_id, 10) : 1;
|
const escuelaId = escuela_id ? parseInt(escuela_id, 10) : 1;
|
||||||
const actualizada = actualizarSinpeEscuela(escuelaId, {
|
const actualizada = actualizarSinpeEscuela(escuelaId, {
|
||||||
telefono_sinpe: cleanTel,
|
telefono_sinpe: cleanTel,
|
||||||
nombre_sinpe: cleanNom,
|
nombre_sinpe: cleanNom,
|
||||||
concesionario
|
concesionario,
|
||||||
|
sinpe_activo: sinpe_activo !== undefined ? sinpe_activo : undefined,
|
||||||
|
sinpe_mensaje_suspension: cleanMsg
|
||||||
});
|
});
|
||||||
|
|
||||||
// Notificar en tiempo real por SSE para que cualquier pantalla activa actualice los datos en caliente
|
// Notificar en tiempo real por SSE para que cualquier pantalla activa actualice los datos en caliente
|
||||||
broadcastEvent('escuela_sinpe_actualizado', {
|
broadcastEvent('escuela_sinpe_actualizado', {
|
||||||
escuela_id: escuelaId,
|
escuela_id: escuelaId,
|
||||||
telefono_sinpe: cleanTel,
|
telefono_sinpe: cleanTel,
|
||||||
nombre_sinpe: cleanNom
|
nombre_sinpe: cleanNom,
|
||||||
|
sinpe_activo: actualizada.sinpe_activo,
|
||||||
|
sinpe_mensaje_suspension: actualizada.sinpe_mensaje_suspension
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`[SINPE] 📲 Datos de cobro SINPE Móvil actualizados para Escuela #${escuelaId}: Tel ${cleanTel} | Titular "${cleanNom}"`);
|
const estadoLog = actualizada.sinpe_activo ? 'HABILITADO' : 'SUSPENDIDO';
|
||||||
|
console.log(`[SINPE] 📲 SINPE actualizado para Escuela #${escuelaId}: Tel ${cleanTel} | Titular "${cleanNom}" | Estado: ${estadoLog}`);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -3607,7 +3618,89 @@ app.put('/api/admin/escuela/sinpe', (req, res) => {
|
|||||||
res.status(500).json({ error: err.message });
|
res.status(500).json({ error: err.message });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 1. ESTUDIANTES Y QR
|
|
||||||
|
// ==========================================
|
||||||
|
// AVISOS GLOBALES / BROADCAST BANNERS
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
// Avisos activos (público: estudiantes, padres, POS)
|
||||||
|
app.get('/api/avisos/activos', (req, res) => {
|
||||||
|
try {
|
||||||
|
const escuelaId = req.query.escuela_id ? parseInt(req.query.escuela_id, 10) : null;
|
||||||
|
const audiencia = req.query.audiencia || null;
|
||||||
|
const avisos = obtenerAvisosActivos(escuelaId, audiencia);
|
||||||
|
res.json({ success: true, avisos });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Listar todos los avisos (admin/dev)
|
||||||
|
app.get('/api/admin/avisos', (req, res) => {
|
||||||
|
try {
|
||||||
|
const escuelaId = req.query.escuela_id ? parseInt(req.query.escuela_id, 10) : null;
|
||||||
|
const avisos = obtenerTodosLosAvisos(escuelaId);
|
||||||
|
res.json({ success: true, avisos });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Crear un aviso (admin/dev)
|
||||||
|
app.post('/api/admin/avisos', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { titulo, mensaje, tipo, audiencia, escuela_id, descartable, creado_por } = req.body || {};
|
||||||
|
if (!titulo || !mensaje) {
|
||||||
|
return res.status(400).json({ error: 'El título y el mensaje del aviso son obligatorios' });
|
||||||
|
}
|
||||||
|
const nuevoAviso = crearAviso({
|
||||||
|
titulo: String(titulo).trim(),
|
||||||
|
mensaje: String(mensaje).trim(),
|
||||||
|
tipo: tipo || 'info',
|
||||||
|
audiencia: audiencia || 'todos',
|
||||||
|
escuelaId: escuela_id ? parseInt(escuela_id, 10) : null,
|
||||||
|
descartable: descartable !== false && descartable !== 0 ? 1 : 0,
|
||||||
|
creadoPor: creado_por || null
|
||||||
|
});
|
||||||
|
|
||||||
|
broadcastEvent('aviso_publicado', nuevoAviso);
|
||||||
|
console.log(`[AVISOS] 📢 Nuevo aviso publicado: "${titulo}" → audiencia: ${audiencia || 'todos'}`);
|
||||||
|
|
||||||
|
res.json({ success: true, aviso: nuevoAviso });
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error creando aviso:', err);
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Cambiar estado activo/inactivo de un aviso (admin/dev)
|
||||||
|
app.put('/api/admin/avisos/:id/estado', (req, res) => {
|
||||||
|
try {
|
||||||
|
const avisoId = parseInt(req.params.id, 10);
|
||||||
|
const { activo } = req.body || {};
|
||||||
|
const avisoActualizado = actualizarEstadoAviso(avisoId, activo ? 1 : 0);
|
||||||
|
broadcastEvent('aviso_estado_cambiado', avisoActualizado);
|
||||||
|
res.json({ success: true, aviso: avisoActualizado });
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error actualizando estado de aviso:', err);
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Eliminar un aviso (admin/dev)
|
||||||
|
app.delete('/api/admin/avisos/:id', (req, res) => {
|
||||||
|
try {
|
||||||
|
const avisoId = parseInt(req.params.id, 10);
|
||||||
|
eliminarAviso(avisoId);
|
||||||
|
broadcastEvent('aviso_eliminado', { id: avisoId });
|
||||||
|
res.json({ success: true, id: avisoId });
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error eliminando aviso:', err);
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
// Listar todos los estudiantes
|
// Listar todos los estudiantes
|
||||||
@@ -3840,10 +3933,14 @@ app.post('/api/sinpe/generar-codigo', (req, res) => {
|
|||||||
let telefono_sinpe = '8888-8888';
|
let telefono_sinpe = '8888-8888';
|
||||||
let titular_sinpe = 'Soda Escolar';
|
let titular_sinpe = 'Soda Escolar';
|
||||||
let escuela_nombre = 'Soda Escolar';
|
let escuela_nombre = 'Soda Escolar';
|
||||||
|
let escuelaId = 1;
|
||||||
|
let escuelaSinpeActivo = true;
|
||||||
|
let escuelaMensajeSuspension = null;
|
||||||
|
|
||||||
if (estudiante_id) {
|
if (estudiante_id) {
|
||||||
const est = db.prepare(`
|
const est = db.prepare(`
|
||||||
SELECT e.id, esc.telefono_sinpe, esc.nombre_sinpe, esc.nombre as escuela_nombre
|
SELECT e.id, esc.id as esc_id, esc.telefono_sinpe, esc.nombre_sinpe, esc.nombre as escuela_nombre,
|
||||||
|
esc.sinpe_activo, esc.sinpe_mensaje_suspension
|
||||||
FROM estudiantes e
|
FROM estudiantes e
|
||||||
LEFT JOIN escuelas esc ON esc.id = e.escuela_id
|
LEFT JOIN escuelas esc ON esc.id = e.escuela_id
|
||||||
WHERE e.id = ?
|
WHERE e.id = ?
|
||||||
@@ -3852,9 +3949,25 @@ app.post('/api/sinpe/generar-codigo', (req, res) => {
|
|||||||
if (est.telefono_sinpe) telefono_sinpe = est.telefono_sinpe;
|
if (est.telefono_sinpe) telefono_sinpe = est.telefono_sinpe;
|
||||||
if (est.nombre_sinpe) titular_sinpe = est.nombre_sinpe;
|
if (est.nombre_sinpe) titular_sinpe = est.nombre_sinpe;
|
||||||
if (est.escuela_nombre) escuela_nombre = est.escuela_nombre;
|
if (est.escuela_nombre) escuela_nombre = est.escuela_nombre;
|
||||||
|
if (est.esc_id) escuelaId = est.esc_id;
|
||||||
|
escuelaSinpeActivo = est.sinpe_activo !== 0 && est.sinpe_activo !== false;
|
||||||
|
escuelaMensajeSuspension = est.sinpe_mensaje_suspension || null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verificar interruptor maestro global
|
||||||
|
const sinpeGlobalHabilitado = String(getConfig('sinpe_habilitado_global', '1')) === '1';
|
||||||
|
if (!sinpeGlobalHabilitado) {
|
||||||
|
const msgGlobal = getConfig('sinpe_mensaje_suspension_global', 'Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica.');
|
||||||
|
return res.json({ success: false, suspended: true, mensaje_suspension: msgGlobal });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verificar interruptor de la escuela
|
||||||
|
if (!escuelaSinpeActivo) {
|
||||||
|
const msgEsc = escuelaMensajeSuspension || 'Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica. Se reanudarán a la brevedad.';
|
||||||
|
return res.json({ success: false, suspended: true, mensaje_suspension: msgEsc });
|
||||||
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
codigo,
|
codigo,
|
||||||
@@ -3876,6 +3989,28 @@ app.post('/api/sinpe/solicitar', (req, res) => {
|
|||||||
if (isNaN(montoNum) || montoNum <= 0) {
|
if (isNaN(montoNum) || montoNum <= 0) {
|
||||||
return res.status(400).json({ error: 'Ingresa un monto válido mayor a ₡0' });
|
return res.status(400).json({ error: 'Ingresa un monto válido mayor a ₡0' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verificar interruptor maestro global
|
||||||
|
const sinpeGlobalHabilitado = String(getConfig('sinpe_habilitado_global', '1')) === '1';
|
||||||
|
if (!sinpeGlobalHabilitado) {
|
||||||
|
const msgGlobal = getConfig('sinpe_mensaje_suspension_global', 'Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica.');
|
||||||
|
return res.status(403).json({ error: msgGlobal, suspended: true, mensaje_suspension: msgGlobal });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verificar interruptor de la escuela del estudiante
|
||||||
|
const estRow = db.prepare(`
|
||||||
|
SELECT e.id, esc.sinpe_activo, esc.sinpe_mensaje_suspension
|
||||||
|
FROM estudiantes e LEFT JOIN escuelas esc ON esc.id = e.escuela_id
|
||||||
|
WHERE e.id = ?
|
||||||
|
`).get(parseInt(estudiante_id, 10));
|
||||||
|
if (estRow) {
|
||||||
|
const escuelaSinpeActivo = estRow.sinpe_activo !== 0 && estRow.sinpe_activo !== false;
|
||||||
|
if (!escuelaSinpeActivo) {
|
||||||
|
const msgEsc = estRow.sinpe_mensaje_suspension || 'Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica.';
|
||||||
|
return res.status(403).json({ error: msgEsc, suspended: true, mensaje_suspension: msgEsc });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const minSinpe = parseInt(getConfig('sinpe_monto_minimo', 1000), 10);
|
const minSinpe = parseInt(getConfig('sinpe_monto_minimo', 1000), 10);
|
||||||
const maxSinpe = parseInt(getConfig('sinpe_monto_maximo', 50000), 10);
|
const maxSinpe = parseInt(getConfig('sinpe_monto_maximo', 50000), 10);
|
||||||
if (montoNum < minSinpe) {
|
if (montoNum < minSinpe) {
|
||||||
|
|||||||
Reference in New Issue
Block a user