feat: configuracion de horarios escolares admin, reporte excel recargas sinpe y remocion enlaces footer
This commit is contained in:
+107
-9
@@ -684,6 +684,10 @@
|
|||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M16 22h2a2 2 0 0 0 2-2V7.5L14.5 2H6a2 2 0 0 0-2 2v3"/><path d="m3 12.5 3 3 6-6"/></svg>
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M16 22h2a2 2 0 0 0 2-2V7.5L14.5 2H6a2 2 0 0 0-2 2v3"/><path d="m3 12.5 3 3 6-6"/></svg>
|
||||||
<span>Movimientos & Reversiones</span>
|
<span>Movimientos & Reversiones</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button class="admin-tab-btn" id="btnTabAdminHorarios" onclick="switchAdminTab('horarios')">
|
||||||
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
||||||
|
<span>Horarios & Recreos</span>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- TAB 1: INVENTARIO Y STOCK -->
|
<!-- TAB 1: INVENTARIO Y STOCK -->
|
||||||
@@ -761,6 +765,38 @@
|
|||||||
<div id="adminSinpeRequestsList" style="display: flex; flex-direction: column; gap: 12px;">
|
<div id="adminSinpeRequestsList" style="display: flex; flex-direction: column; gap: 12px;">
|
||||||
<!-- Solicitudes SINPE pendientes cargadas dinámicamente -->
|
<!-- Solicitudes SINPE pendientes cargadas dinámicamente -->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- BARRA DE EXPORTACIÓN EXCEL DE RECARGAS SINPE -->
|
||||||
|
<div style="margin-top: 16px; padding: 14px; background: #f8fafc; border: 1.5px solid #e2e8f0; border-radius: 12px;">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; flex-wrap: wrap; gap: 8px;">
|
||||||
|
<strong style="font-size: 0.86rem; color: #0f172a; display: flex; align-items: center; gap: 6px;">
|
||||||
|
<span>📊 Exportar Reporte de Recargas / Depósitos (Excel)</span>
|
||||||
|
</strong>
|
||||||
|
<button type="button" onclick="descargarReporteRecargasExcel(true)" class="btn-saas btn-saas-outline" style="height: 28px; padding: 0 10px; font-size: 0.74rem; font-weight: 700; color: #0284c7; border-color: #bae6fd; background: #f0f9ff;" title="Descargar todas las recargas registradas sin filtro">
|
||||||
|
⬇️ Todo el Historial
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; gap: 8px; flex-wrap: wrap; align-items: center;">
|
||||||
|
<div style="display: flex; align-items: center; gap: 4px; font-size: 0.76rem; color: #64748b;">
|
||||||
|
<span>Desde:</span>
|
||||||
|
<input type="date" id="inputExportRecargasDesde" style="padding: 5px 8px; font-size: 0.78rem; border-radius: 6px; border: 1px solid #cbd5e1; outline: none; background: white;">
|
||||||
|
</div>
|
||||||
|
<div style="display: flex; align-items: center; gap: 4px; font-size: 0.76rem; color: #64748b;">
|
||||||
|
<span>Hasta:</span>
|
||||||
|
<input type="date" id="inputExportRecargasHasta" style="padding: 5px 8px; font-size: 0.78rem; border-radius: 6px; border: 1px solid #cbd5e1; outline: none; background: white;">
|
||||||
|
</div>
|
||||||
|
<select id="selectExportRecargasEstado" style="padding: 5px 8px; font-size: 0.78rem; border-radius: 6px; border: 1px solid #cbd5e1; outline: none; background: white;">
|
||||||
|
<option value="todos">Todos los Estados</option>
|
||||||
|
<option value="aprobado">Solo Aprobadas</option>
|
||||||
|
<option value="pendiente">Solo Pendientes</option>
|
||||||
|
<option value="rechazado">Solo Rechazadas</option>
|
||||||
|
</select>
|
||||||
|
<button type="button" onclick="descargarReporteRecargasExcel(false)" class="btn-saas btn-saas-primary" style="height: 32px; padding: 0 14px; font-size: 0.78rem; font-weight: 800; display: inline-flex; align-items: center; gap: 5px;">
|
||||||
|
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><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 Filtrado</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- SEPARADOR CON RECARGA EN EFECTIVO -->
|
<!-- SEPARADOR CON RECARGA EN EFECTIVO -->
|
||||||
@@ -949,6 +985,75 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- TAB 6: HORARIOS ESCOLARES (RECREOS Y ALMUERZO) -->
|
||||||
|
<div id="adminTabContentHorarios" class="admin-card" style="display: none; max-width: 780px; margin: 0 auto;">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
|
||||||
|
<div>
|
||||||
|
<h3 style="margin: 0; font-size: 1.15rem; font-weight: 900; color: var(--text-main);">
|
||||||
|
⏰ Horarios de Recreos y Almuerzo
|
||||||
|
</h3>
|
||||||
|
<p style="margin: 3px 0 0 0; font-size: 0.78rem; color: var(--text-muted);">
|
||||||
|
Configura los turnos específicos de tu escuela. Los pedidos anticipados de estudiantes y padres se agruparán bajo estos horarios.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="background: var(--bg-main); border: 1.5px solid var(--border); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 16px;">
|
||||||
|
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px;">
|
||||||
|
<!-- Primer Recreo -->
|
||||||
|
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.03);">
|
||||||
|
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
|
||||||
|
<span style="font-size: 1.3rem;">🔔</span>
|
||||||
|
<div>
|
||||||
|
<strong style="display: block; font-size: 0.90rem; color: var(--text-main);">1er Recreo</strong>
|
||||||
|
<span style="font-size: 0.72rem; color: var(--text-muted);">Turno de la Mañana</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label style="display: block; font-size: 0.74rem; font-weight: 700; color: var(--text-muted); margin-bottom: 5px;">Hora de Inicio:</label>
|
||||||
|
<input type="time" id="inputAdminHoraRecreo1" value="09:30" style="width: 100%; padding: 8px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 1.05rem; font-weight: 800; color: var(--text-main); background: var(--bg-main); outline: none; box-sizing: border-box;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Almuerzo -->
|
||||||
|
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.03);">
|
||||||
|
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
|
||||||
|
<span style="font-size: 1.3rem;">🍲</span>
|
||||||
|
<div>
|
||||||
|
<strong style="display: block; font-size: 0.90rem; color: var(--text-main);">Almuerzo</strong>
|
||||||
|
<span style="font-size: 0.72rem; color: var(--text-muted);">Comedor / Almuerzo</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label style="display: block; font-size: 0.74rem; font-weight: 700; color: var(--text-muted); margin-bottom: 5px;">Hora de Inicio:</label>
|
||||||
|
<input type="time" id="inputAdminHoraAlmuerzo" value="11:45" style="width: 100%; padding: 8px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 1.05rem; font-weight: 800; color: var(--text-main); background: var(--bg-main); outline: none; box-sizing: border-box;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Segundo Recreo -->
|
||||||
|
<div style="background: var(--card-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.03);">
|
||||||
|
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 10px;">
|
||||||
|
<span style="font-size: 1.3rem;">⏰</span>
|
||||||
|
<div>
|
||||||
|
<strong style="display: block; font-size: 0.90rem; color: var(--text-main);">2do Recreo</strong>
|
||||||
|
<span style="font-size: 0.72rem; color: var(--text-muted);">Turno de la Tarde</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<label style="display: block; font-size: 0.74rem; font-weight: 700; color: var(--text-muted); margin-bottom: 5px;">Hora de Inicio:</label>
|
||||||
|
<input type="time" id="inputAdminHoraRecreo2" value="13:45" style="width: 100%; padding: 8px 12px; border-radius: 8px; border: 1.5px solid var(--border); font-size: 1.05rem; font-weight: 800; color: var(--text-main); background: var(--bg-main); outline: none; box-sizing: border-box;">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="background: #e0f2fe; border: 1.5px solid #bae6fd; border-radius: 10px; padding: 12px 14px; font-size: 0.78rem; color: #0369a1; display: flex; align-items: center; gap: 10px;">
|
||||||
|
<span style="font-size: 1.2rem;">💡</span>
|
||||||
|
<span>Al presionar <strong>Guardar Horarios</strong>, los cambios se aplican automáticamente para padres y estudiantes en el selector de pedidos y para los cajeros en la terminal POS.</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px;">
|
||||||
|
<button type="button" onclick="guardarHorariosEscolares()" class="btn-saas btn-saas-primary" style="padding: 10px 24px; font-size: 0.88rem; font-weight: 800; display: inline-flex; align-items: center; gap: 6px; 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>
|
||||||
|
<span>Guardar Horarios</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ========================================== -->
|
<!-- ========================================== -->
|
||||||
@@ -1916,14 +2021,7 @@
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ENLACES DE ACCESO RÁPIDO PARA DEMO Y REVISIÓN -->
|
|
||||||
<div style="margin: 30px 16px; padding: 14px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 14px; font-size: 0.82rem; text-align: center;">
|
|
||||||
<p style="font-weight: 700; margin-bottom: 8px; color: var(--text-main);">Acceso Rápido del Sistema:</p>
|
|
||||||
<div style="display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;">
|
|
||||||
<a href="/pos.html" target="_blank" style="color: #0284c7; font-weight: 700; text-decoration: none; padding: 4px 10px; background: #e0f2fe; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px;"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="20" height="14" x="2" y="5" rx="2"/><line x1="2" x2="22" y1="10" y2="10"/></svg> Terminal Soda (Caja & QR)</a>
|
|
||||||
<a href="/carnet.html" target="_blank" style="color: #10b981; font-weight: 700; text-decoration: none; padding: 4px 10px; background: #d1fae5; border-radius: 8px; display: inline-flex; align-items: center; gap: 6px;"><svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 6 2 18 2 18 9"/><path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/><rect width="12" height="8" x="6" y="14"/></svg> Carnés Físicos para Imprimir</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- MODAL INMERSIVO: CÓDIGO QR PARA PRESENTAR EN LA SODA (DISEÑO SIBOPAY EXACTO) -->
|
<!-- MODAL INMERSIVO: CÓDIGO QR PARA PRESENTAR EN LA SODA (DISEÑO SIBOPAY EXACTO) -->
|
||||||
@@ -3179,6 +3277,6 @@
|
|||||||
<script src="/js/sounds.js?v=9.6"></script>
|
<script src="/js/sounds.js?v=9.6"></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/app.js?v=13.1"></script>
|
<script src="/js/app.js?v=13.2"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+164
-8
@@ -64,6 +64,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
applyCardTheme(getSavedCardTheme());
|
applyCardTheme(getSavedCardTheme());
|
||||||
}
|
}
|
||||||
checkHttpsEnvironment();
|
checkHttpsEnvironment();
|
||||||
|
cargarHorariosPublicos();
|
||||||
|
|
||||||
// Registrar Service Worker para PWA
|
// Registrar Service Worker para PWA
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
@@ -1312,14 +1313,57 @@ function normalizeMomentoKey(val) {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let currentSchoolHorarios = {
|
||||||
|
hora_recreo_1_fmt: '9:30 AM',
|
||||||
|
hora_almuerzo_fmt: '11:45 AM',
|
||||||
|
hora_recreo_2_fmt: '1:45 PM'
|
||||||
|
};
|
||||||
|
|
||||||
|
async function cargarHorariosPublicos() {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/escuela/horarios');
|
||||||
|
const data = await res.json();
|
||||||
|
if (data && data.horarios) {
|
||||||
|
currentSchoolHorarios = data.horarios;
|
||||||
|
window.schoolHorarios = data.horarios;
|
||||||
|
actualizarTextosHorariosPreordenes();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Error cargando horarios escolares:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function actualizarTextosHorariosPreordenes() {
|
||||||
|
const h = window.schoolHorarios || currentSchoolHorarios || {};
|
||||||
|
const r1Text = h.hora_recreo_1_fmt || '9:30 AM';
|
||||||
|
const almText = h.hora_almuerzo_fmt || '11:45 AM';
|
||||||
|
const r2Text = h.hora_recreo_2_fmt || '1:45 PM';
|
||||||
|
|
||||||
|
const select = document.getElementById('momentoEntregaSelect');
|
||||||
|
if (select) {
|
||||||
|
const prev = select.value;
|
||||||
|
select.innerHTML = `
|
||||||
|
<option value="recreo_1">🔔 1er Recreo de la Mañana (${r1Text})</option>
|
||||||
|
<option value="almuerzo">🍲 Hora de Almuerzo (${almText})</option>
|
||||||
|
<option value="recreo_2">⏰ 2do Recreo de la Tarde (${r2Text})</option>
|
||||||
|
`;
|
||||||
|
if (prev) select.value = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getMomentoBadge(val) {
|
function getMomentoBadge(val) {
|
||||||
const key = normalizeMomentoKey(val);
|
const key = normalizeMomentoKey(val);
|
||||||
|
const h = window.schoolHorarios || currentSchoolHorarios || {};
|
||||||
|
const r1Text = h.hora_recreo_1_fmt || '9:30 AM';
|
||||||
|
const almText = h.hora_almuerzo_fmt || '11:45 AM';
|
||||||
|
const r2Text = h.hora_recreo_2_fmt || '1:45 PM';
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'recreo_1':
|
case 'recreo_1':
|
||||||
return {
|
return {
|
||||||
key: 'recreo_1',
|
key: 'recreo_1',
|
||||||
title: '1er Recreo (9:30 AM)',
|
title: `1er Recreo (${r1Text})`,
|
||||||
full: '1er Recreo de la Mañana (9:30 AM)',
|
full: `1er Recreo de la Mañana (${r1Text})`,
|
||||||
icon: '🔔',
|
icon: '🔔',
|
||||||
bg: '#fffbeb',
|
bg: '#fffbeb',
|
||||||
border: '#f59e0b',
|
border: '#f59e0b',
|
||||||
@@ -1331,8 +1375,8 @@ function getMomentoBadge(val) {
|
|||||||
case 'almuerzo':
|
case 'almuerzo':
|
||||||
return {
|
return {
|
||||||
key: 'almuerzo',
|
key: 'almuerzo',
|
||||||
title: 'Almuerzo (11:45 AM)',
|
title: `Almuerzo (${almText})`,
|
||||||
full: 'Hora de Almuerzo (11:45 AM)',
|
full: `Hora de Almuerzo (${almText})`,
|
||||||
icon: '🍲',
|
icon: '🍲',
|
||||||
bg: '#f0fdf4',
|
bg: '#f0fdf4',
|
||||||
border: '#16a34a',
|
border: '#16a34a',
|
||||||
@@ -1344,8 +1388,8 @@ function getMomentoBadge(val) {
|
|||||||
case 'recreo_2':
|
case 'recreo_2':
|
||||||
return {
|
return {
|
||||||
key: 'recreo_2',
|
key: 'recreo_2',
|
||||||
title: '2do Recreo (1:45 PM)',
|
title: `2do Recreo (${r2Text})`,
|
||||||
full: '2do Recreo de la Tarde (1:45 PM)',
|
full: `2do Recreo de la Tarde (${r2Text})`,
|
||||||
icon: '⏰',
|
icon: '⏰',
|
||||||
bg: '#eef2ff',
|
bg: '#eef2ff',
|
||||||
border: '#6366f1',
|
border: '#6366f1',
|
||||||
@@ -1376,7 +1420,7 @@ function getMomentoBadge(val) {
|
|||||||
bg: '#f8fafc',
|
bg: '#f8fafc',
|
||||||
border: '#0284c7',
|
border: '#0284c7',
|
||||||
text: '#0369a1',
|
text: '#0369a1',
|
||||||
badgeBg: '#e0f2fe',
|
badgeBg: '#e0e7fe',
|
||||||
badgeColor: '#0369a1',
|
badgeColor: '#0369a1',
|
||||||
badgeBorder: '#bae6fd'
|
badgeBorder: '#bae6fd'
|
||||||
};
|
};
|
||||||
@@ -2649,6 +2693,25 @@ function initStudentSSE() {
|
|||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sse.addEventListener('horarios_actualizados', (e) => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(e.data);
|
||||||
|
if (data) {
|
||||||
|
currentSchoolHorarios = data;
|
||||||
|
window.schoolHorarios = data;
|
||||||
|
actualizarTextosHorariosPreordenes();
|
||||||
|
if (currentUser && currentUser.rol === 'admin') {
|
||||||
|
const inpR1 = document.getElementById('inputAdminHoraRecreo1');
|
||||||
|
const inpAlm = document.getElementById('inputAdminHoraAlmuerzo');
|
||||||
|
const inpR2 = document.getElementById('inputAdminHoraRecreo2');
|
||||||
|
if (inpR1) inpR1.value = currentSchoolHorarios.hora_recreo_1 || '09:30';
|
||||||
|
if (inpAlm) inpAlm.value = currentSchoolHorarios.hora_almuerzo || '11:45';
|
||||||
|
if (inpR2) inpR2.value = currentSchoolHorarios.hora_recreo_2 || '13:45';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sincronización en segundo plano: al volver a la pestaña/desbloquear el teléfono
|
// Sincronización en segundo plano: al volver a la pestaña/desbloquear el teléfono
|
||||||
@@ -4541,7 +4604,7 @@ async function confirmLinkValidatedChild() {
|
|||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
function switchAdminTab(tabName) {
|
function switchAdminTab(tabName) {
|
||||||
const tabs = ['inventario', 'estudiantes', 'recarga', 'movimientos', 'personal'];
|
const tabs = ['inventario', 'estudiantes', 'recarga', 'movimientos', 'personal', 'horarios'];
|
||||||
tabs.forEach(t => {
|
tabs.forEach(t => {
|
||||||
const btn = document.getElementById(`btnTabAdmin${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
const btn = document.getElementById(`btnTabAdmin${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
||||||
const content = document.getElementById(`adminTabContent${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
const content = document.getElementById(`adminTabContent${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
||||||
@@ -4558,11 +4621,101 @@ function switchAdminTab(tabName) {
|
|||||||
if (!adminSelectedStudent) {
|
if (!adminSelectedStudent) {
|
||||||
clearAdminSelectedStudent();
|
clearAdminSelectedStudent();
|
||||||
}
|
}
|
||||||
|
} else if (tabName === 'horarios') {
|
||||||
|
cargarHorariosAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.sounds) window.sounds.playTap();
|
if (window.sounds) window.sounds.playTap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function cargarHorariosAdmin() {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/escuela/horarios');
|
||||||
|
const data = await res.json();
|
||||||
|
if (data && data.horarios) {
|
||||||
|
currentSchoolHorarios = data.horarios;
|
||||||
|
window.schoolHorarios = data.horarios;
|
||||||
|
|
||||||
|
const inpR1 = document.getElementById('inputAdminHoraRecreo1');
|
||||||
|
const inpAlm = document.getElementById('inputAdminHoraAlmuerzo');
|
||||||
|
const inpR2 = document.getElementById('inputAdminHoraRecreo2');
|
||||||
|
|
||||||
|
if (inpR1) inpR1.value = currentSchoolHorarios.hora_recreo_1 || '09:30';
|
||||||
|
if (inpAlm) inpAlm.value = currentSchoolHorarios.hora_almuerzo || '11:45';
|
||||||
|
if (inpR2) inpR2.value = currentSchoolHorarios.hora_recreo_2 || '13:45';
|
||||||
|
|
||||||
|
actualizarTextosHorariosPreordenes();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error cargando horarios admin:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function guardarHorariosEscolares() {
|
||||||
|
const inpR1 = document.getElementById('inputAdminHoraRecreo1');
|
||||||
|
const inpAlm = document.getElementById('inputAdminHoraAlmuerzo');
|
||||||
|
const inpR2 = document.getElementById('inputAdminHoraRecreo2');
|
||||||
|
|
||||||
|
const hora1 = inpR1 ? inpR1.value : '09:30';
|
||||||
|
const alm = inpAlm ? inpAlm.value : '11:45';
|
||||||
|
const hora2 = inpR2 ? inpR2.value : '13:45';
|
||||||
|
|
||||||
|
if (!hora1 || !alm || !hora2) {
|
||||||
|
alert('Por favor especifica las horas de los 3 turnos (1er Recreo, Almuerzo y 2do Recreo)');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/admin/escuela/horarios', {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
escuela_id: 1,
|
||||||
|
hora_recreo_1: hora1,
|
||||||
|
hora_almuerzo: alm,
|
||||||
|
hora_recreo_2: hora2
|
||||||
|
})
|
||||||
|
});
|
||||||
|
const data = await res.json();
|
||||||
|
if (data.success && data.horarios) {
|
||||||
|
currentSchoolHorarios = data.horarios;
|
||||||
|
window.schoolHorarios = data.horarios;
|
||||||
|
actualizarTextosHorariosPreordenes();
|
||||||
|
if (window.sounds) window.sounds.playCoin();
|
||||||
|
alert(`✅ Horarios escolares guardados con éxito:\n• 1er Recreo: ${data.horarios.hora_recreo_1_fmt}\n• Almuerzo: ${data.horarios.hora_almuerzo_fmt}\n• 2do Recreo: ${data.horarios.hora_recreo_2_fmt}`);
|
||||||
|
} else {
|
||||||
|
alert('Error guardando horarios: ' + (data.error || 'Ocurrió un error inesperado'));
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
alert('Error al comunicarse con el servidor: ' + err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function descargarReporteRecargasExcel(descargarTodo = false) {
|
||||||
|
let url = '/api/admin/export/recargas.csv';
|
||||||
|
if (!descargarTodo) {
|
||||||
|
const desde = document.getElementById('inputExportRecargasDesde')?.value || '';
|
||||||
|
const hasta = document.getElementById('inputExportRecargasHasta')?.value || '';
|
||||||
|
const estado = document.getElementById('selectExportRecargasEstado')?.value || 'todos';
|
||||||
|
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (desde) params.append('desde', desde);
|
||||||
|
if (hasta) params.append('hasta', hasta);
|
||||||
|
if (estado && estado !== 'todos') params.append('estado', estado);
|
||||||
|
|
||||||
|
const qs = params.toString();
|
||||||
|
if (qs) url += '?' + qs;
|
||||||
|
}
|
||||||
|
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.target = '_blank';
|
||||||
|
link.download = '';
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}
|
||||||
|
|
||||||
async function loadAdminData() {
|
async function loadAdminData() {
|
||||||
try {
|
try {
|
||||||
// 1. Cargar resumen y métricas
|
// 1. Cargar resumen y métricas
|
||||||
@@ -4597,6 +4750,9 @@ async function loadAdminData() {
|
|||||||
|
|
||||||
// 5. Cargar solicitudes SINPE pendientes para badge y sección
|
// 5. Cargar solicitudes SINPE pendientes para badge y sección
|
||||||
loadAdminSinpeRequests();
|
loadAdminSinpeRequests();
|
||||||
|
|
||||||
|
// 6. Cargar horarios escolares para la pestaña de configuración
|
||||||
|
cargarHorariosAdmin();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error cargando datos de administración:', err);
|
console.error('Error cargando datos de administración:', err);
|
||||||
}
|
}
|
||||||
|
|||||||
+57
-6
@@ -101,6 +101,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
await loadCatalog();
|
await loadCatalog();
|
||||||
await loadPreOrders();
|
await loadPreOrders();
|
||||||
await loadSinpeRequests();
|
await loadSinpeRequests();
|
||||||
|
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();
|
||||||
initPistolScanner();
|
initPistolScanner();
|
||||||
@@ -1322,14 +1323,51 @@ function normalizeMomentoKey(val) {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let posSchoolHorarios = {
|
||||||
|
hora_recreo_1_fmt: '9:30 AM',
|
||||||
|
hora_almuerzo_fmt: '11:45 AM',
|
||||||
|
hora_recreo_2_fmt: '1:45 PM'
|
||||||
|
};
|
||||||
|
|
||||||
|
async function cargarHorariosPos() {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/escuela/horarios');
|
||||||
|
const data = await res.json();
|
||||||
|
if (data && data.horarios) {
|
||||||
|
posSchoolHorarios = data.horarios;
|
||||||
|
actualizarPillsHorariosPos();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Error cargando horarios en POS:', e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function actualizarPillsHorariosPos() {
|
||||||
|
const r1Btn = document.querySelector('#filterPillRecreo_1 span:first-child');
|
||||||
|
const almBtn = document.querySelector('#filterPillAlmuerzo span:first-child');
|
||||||
|
const r2Btn = document.querySelector('#filterPillRecreo_2 span:first-child');
|
||||||
|
|
||||||
|
const r1Text = posSchoolHorarios.hora_recreo_1_fmt || '9:30 AM';
|
||||||
|
const almText = posSchoolHorarios.hora_almuerzo_fmt || '11:45 AM';
|
||||||
|
const r2Text = posSchoolHorarios.hora_recreo_2_fmt || '1:45 PM';
|
||||||
|
|
||||||
|
if (r1Btn) r1Btn.textContent = `🔔 1er Recreo (${r1Text})`;
|
||||||
|
if (almBtn) almBtn.textContent = `🍲 Almuerzo (${almText})`;
|
||||||
|
if (r2Btn) r2Btn.textContent = `⏰ 2do Recreo (${r2Text})`;
|
||||||
|
}
|
||||||
|
|
||||||
function getMomentoBadge(val) {
|
function getMomentoBadge(val) {
|
||||||
const key = normalizeMomentoKey(val);
|
const key = normalizeMomentoKey(val);
|
||||||
|
const r1Text = posSchoolHorarios.hora_recreo_1_fmt || '9:30 AM';
|
||||||
|
const almText = posSchoolHorarios.hora_almuerzo_fmt || '11:45 AM';
|
||||||
|
const r2Text = posSchoolHorarios.hora_recreo_2_fmt || '1:45 PM';
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'recreo_1':
|
case 'recreo_1':
|
||||||
return {
|
return {
|
||||||
key: 'recreo_1',
|
key: 'recreo_1',
|
||||||
title: '1er Recreo (9:30 AM)',
|
title: `1er Recreo (${r1Text})`,
|
||||||
full: '1er Recreo de la Mañana (9:30 AM)',
|
full: `1er Recreo de la Mañana (${r1Text})`,
|
||||||
icon: '🔔',
|
icon: '🔔',
|
||||||
bg: '#fffbeb',
|
bg: '#fffbeb',
|
||||||
border: '#f59e0b',
|
border: '#f59e0b',
|
||||||
@@ -1341,8 +1379,8 @@ function getMomentoBadge(val) {
|
|||||||
case 'almuerzo':
|
case 'almuerzo':
|
||||||
return {
|
return {
|
||||||
key: 'almuerzo',
|
key: 'almuerzo',
|
||||||
title: 'Almuerzo (11:45 AM)',
|
title: `Almuerzo (${almText})`,
|
||||||
full: 'Hora de Almuerzo (11:45 AM)',
|
full: `Hora de Almuerzo (${almText})`,
|
||||||
icon: '🍲',
|
icon: '🍲',
|
||||||
bg: '#f0fdf4',
|
bg: '#f0fdf4',
|
||||||
border: '#16a34a',
|
border: '#16a34a',
|
||||||
@@ -1354,8 +1392,8 @@ function getMomentoBadge(val) {
|
|||||||
case 'recreo_2':
|
case 'recreo_2':
|
||||||
return {
|
return {
|
||||||
key: 'recreo_2',
|
key: 'recreo_2',
|
||||||
title: '2do Recreo (1:45 PM)',
|
title: `2do Recreo (${r2Text})`,
|
||||||
full: '2do Recreo de la Tarde (1:45 PM)',
|
full: `2do Recreo de la Tarde (${r2Text})`,
|
||||||
icon: '⏰',
|
icon: '⏰',
|
||||||
bg: '#eef2ff',
|
bg: '#eef2ff',
|
||||||
border: '#6366f1',
|
border: '#6366f1',
|
||||||
@@ -1802,6 +1840,19 @@ function initSSE() {
|
|||||||
loadCatalog();
|
loadCatalog();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sseSource.addEventListener('horarios_actualizados', (e) => {
|
||||||
|
try {
|
||||||
|
const data = JSON.parse(e.data);
|
||||||
|
if (data) {
|
||||||
|
posSchoolHorarios = data;
|
||||||
|
actualizarPillsHorariosPos();
|
||||||
|
renderPreOrdersList();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('Error en SSE horarios_actualizados:', err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
sseSource.addEventListener('cierre_caja_realizado', (e) => {
|
sseSource.addEventListener('cierre_caja_realizado', (e) => {
|
||||||
try {
|
try {
|
||||||
const res = JSON.parse(e.data);
|
const res = JSON.parse(e.data);
|
||||||
|
|||||||
+6
-2
@@ -283,7 +283,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<p style="font-size: 0.78rem; color: #64748b; margin: 3px 0 0 0;">Verifica que el dinero ingresó a la cuenta bancaria de la soda antes de aprobar la recarga.</p>
|
<p style="font-size: 0.78rem; color: #64748b; margin: 3px 0 0 0;">Verifica que el dinero ingresó a la cuenta bancaria de la soda antes de aprobar la recarga.</p>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div style="display: flex; gap: 8px; align-items: center;">
|
||||||
|
<a href="/api/admin/export/recargas.csv" target="_blank" class="btn-saas btn-saas-outline" style="height: 36px; padding: 0 12px; text-decoration: none; font-weight: 700; color: #0284c7; border-color: #bae6fd; background: #f0f9ff; display: inline-flex; align-items: center; gap: 6px;" title="Descargar reporte de todas las recargas SINPE en formato Excel">
|
||||||
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><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>Exportar Excel</span>
|
||||||
|
</a>
|
||||||
<button onclick="loadSinpeRequests()" class="btn-saas btn-saas-outline" style="height: 36px; padding: 0 12px;">
|
<button onclick="loadSinpeRequests()" class="btn-saas btn-saas-outline" style="height: 36px; padding: 0 12px;">
|
||||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M3 21v-5h5"/></svg>
|
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/><path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/><path d="M3 21v-5h5"/></svg>
|
||||||
<span>Refrescar</span>
|
<span>Refrescar</span>
|
||||||
@@ -581,6 +585,6 @@
|
|||||||
<script src="/js/sounds.js?v=8.6"></script>
|
<script src="/js/sounds.js?v=8.6"></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=13.1"></script>
|
<script src="/js/pos.js?v=13.2"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
// SiboPay PWA Service Worker v13.1 - Alta Velocidad & Despacho
|
// SiboPay PWA Service Worker v13.2 - Alta Velocidad & Despacho
|
||||||
const CACHE_NAME = 'sibopay-v13.1';
|
const CACHE_NAME = 'sibopay-v13.2';
|
||||||
const STATIC_ASSETS = [
|
const STATIC_ASSETS = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
|
|||||||
+75
-6
@@ -118,9 +118,15 @@ function initDatabase() {
|
|||||||
nombre_sinpe VARCHAR(150) DEFAULT 'Soda Central',
|
nombre_sinpe VARCHAR(150) DEFAULT 'Soda Central',
|
||||||
concesionario VARCHAR(150),
|
concesionario VARCHAR(150),
|
||||||
activo BOOLEAN DEFAULT TRUE,
|
activo BOOLEAN DEFAULT TRUE,
|
||||||
|
hora_recreo_1 VARCHAR(20) DEFAULT '09:30',
|
||||||
|
hora_almuerzo VARCHAR(20) DEFAULT '11:45',
|
||||||
|
hora_recreo_2 VARCHAR(20) DEFAULT '13:45',
|
||||||
creado_en TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
creado_en TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||||
);
|
);
|
||||||
`);
|
`);
|
||||||
|
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_recreo_2 VARCHAR(20) DEFAULT '13:45';"); } catch (_) {}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -312,6 +318,9 @@ function initDatabase() {
|
|||||||
try { db.exec('ALTER TABLE usuarios ADD COLUMN activo INTEGER DEFAULT 1'); } catch (e) {}
|
try { db.exec('ALTER TABLE usuarios ADD COLUMN activo INTEGER DEFAULT 1'); } catch (e) {}
|
||||||
try { db.exec('UPDATE usuarios SET activo = 1 WHERE activo IS NULL'); } catch (e) {}
|
try { db.exec('UPDATE usuarios SET activo = 1 WHERE activo IS NULL'); } catch (e) {}
|
||||||
try { db.exec("UPDATE ordenes SET estado = 'cancelado' WHERE estado = 'expirado'"); } catch (e) {}
|
try { db.exec("UPDATE ordenes SET estado = 'cancelado' WHERE estado = 'expirado'"); } 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_recreo_2 TEXT DEFAULT '13:45'"); } catch (e) {}
|
||||||
|
|
||||||
// 8. Relación N:M Padres - Estudiantes
|
// 8. Relación N:M Padres - Estudiantes
|
||||||
try {
|
try {
|
||||||
@@ -812,16 +821,73 @@ function recargaSaldoTransaction({ estudianteId, monto, comprobanteSinpe, descri
|
|||||||
return transaction();
|
return transaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatTime12h(timeStr) {
|
||||||
|
if (!timeStr) return '';
|
||||||
|
const parts = String(timeStr).split(':');
|
||||||
|
let h = parseInt(parts[0], 10);
|
||||||
|
const m = parts[1] || '00';
|
||||||
|
if (isNaN(h)) return timeStr;
|
||||||
|
const ampm = h >= 12 ? 'PM' : 'AM';
|
||||||
|
h = h % 12;
|
||||||
|
if (h === 0) h = 12;
|
||||||
|
return `${h}:${m} ${ampm}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function obtenerHorariosEscuela(escuelaId = 1) {
|
||||||
|
try {
|
||||||
|
const row = db.prepare('SELECT id, codigo, nombre, hora_recreo_1, hora_almuerzo, hora_recreo_2 FROM escuelas WHERE id = ?').get(escuelaId || 1);
|
||||||
|
if (row) {
|
||||||
|
return {
|
||||||
|
id: row.id,
|
||||||
|
nombre: row.nombre,
|
||||||
|
hora_recreo_1: row.hora_recreo_1 || '09:30',
|
||||||
|
hora_almuerzo: row.hora_almuerzo || '11:45',
|
||||||
|
hora_recreo_2: row.hora_recreo_2 || '13:45',
|
||||||
|
hora_recreo_1_fmt: formatTime12h(row.hora_recreo_1 || '09:30'),
|
||||||
|
hora_almuerzo_fmt: formatTime12h(row.hora_almuerzo || '11:45'),
|
||||||
|
hora_recreo_2_fmt: formatTime12h(row.hora_recreo_2 || '13:45')
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error obteniendo horarios escuela:', e);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
id: 1,
|
||||||
|
nombre: 'Soda Escolar Central',
|
||||||
|
hora_recreo_1: '09:30',
|
||||||
|
hora_almuerzo: '11:45',
|
||||||
|
hora_recreo_2: '13:45',
|
||||||
|
hora_recreo_1_fmt: '9:30 AM',
|
||||||
|
hora_almuerzo_fmt: '11:45 AM',
|
||||||
|
hora_recreo_2_fmt: '1:45 PM'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function actualizarHorariosEscuela(escuelaId = 1, { hora_recreo_1, hora_almuerzo, hora_recreo_2 }) {
|
||||||
|
const r1 = hora_recreo_1 || '09:30';
|
||||||
|
const alm = hora_almuerzo || '11:45';
|
||||||
|
const r2 = hora_recreo_2 || '13:45';
|
||||||
|
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE escuelas
|
||||||
|
SET hora_recreo_1 = ?, hora_almuerzo = ?, hora_recreo_2 = ?
|
||||||
|
WHERE id = ?
|
||||||
|
`).run(r1, alm, r2, escuelaId || 1);
|
||||||
|
|
||||||
|
return obtenerHorariosEscuela(escuelaId || 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Traduce y estandariza el código o texto de momento de entrega a una etiqueta humana amigable
|
* Traduce y estandariza el código o texto de momento de entrega a una etiqueta humana amigable
|
||||||
*/
|
*/
|
||||||
function formatMomentoLabel(momento) {
|
function formatMomentoLabel(momento, escuelaId = 1) {
|
||||||
const m = String(momento || '').toLowerCase().trim();
|
const m = String(momento || '').toLowerCase().trim();
|
||||||
if (m === 'recreo_1' || m.includes('1er') || m.includes('9:30')) return '1er Recreo (9:30 AM)';
|
const horarios = obtenerHorariosEscuela(escuelaId);
|
||||||
if (m === 'almuerzo' || m.includes('almuerzo') || m.includes('11:45')) return 'Almuerzo (11:45 AM)';
|
if (m === 'recreo_1' || m.includes('1er') || m.includes('9:30')) return `1er Recreo (${horarios.hora_recreo_1_fmt})`;
|
||||||
if (m === 'recreo_2' || m.includes('2do') || m.includes('1:45')) return '2do Recreo (1:45 PM)';
|
if (m === 'almuerzo' || m.includes('almuerzo') || m.includes('11:45')) return `Almuerzo (${horarios.hora_almuerzo_fmt})`;
|
||||||
|
if (m === 'recreo_2' || m.includes('2do') || m.includes('1:45')) return `2do Recreo (${horarios.hora_recreo_2_fmt})`;
|
||||||
if (m === 'inmediato' || m.includes('inmediato')) return 'Entrega Inmediata';
|
if (m === 'inmediato' || m.includes('inmediato')) return 'Entrega Inmediata';
|
||||||
return momento || '1er Recreo (9:30 AM)';
|
return momento || `1er Recreo (${horarios.hora_recreo_1_fmt})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1807,5 +1873,8 @@ module.exports = {
|
|||||||
expirarPreordenesVencidas,
|
expirarPreordenesVencidas,
|
||||||
cancelarPreorden,
|
cancelarPreorden,
|
||||||
despacharPreordenTransaction,
|
despacharPreordenTransaction,
|
||||||
enriquecerEstudianteFinanzas
|
enriquecerEstudianteFinanzas,
|
||||||
|
obtenerHorariosEscuela,
|
||||||
|
actualizarHorariosEscuela,
|
||||||
|
formatTime12h
|
||||||
};
|
};
|
||||||
|
|||||||
+135
-1
@@ -32,7 +32,10 @@ const {
|
|||||||
expirarPreordenesVencidas,
|
expirarPreordenesVencidas,
|
||||||
cancelarPreorden,
|
cancelarPreorden,
|
||||||
despacharPreordenTransaction,
|
despacharPreordenTransaction,
|
||||||
enriquecerEstudianteFinanzas
|
enriquecerEstudianteFinanzas,
|
||||||
|
obtenerHorariosEscuela,
|
||||||
|
actualizarHorariosEscuela,
|
||||||
|
formatTime12h
|
||||||
} = require('./db');
|
} = require('./db');
|
||||||
const { checkSinpeEmailsOnce, simularSinpeEmail } = require('./sinpeImapService');
|
const { checkSinpeEmailsOnce, simularSinpeEmail } = require('./sinpeImapService');
|
||||||
const { normalizarCodigoDetalle, parseSinpeEmail } = require('./sinpeParser');
|
const { normalizarCodigoDetalle, parseSinpeEmail } = require('./sinpeParser');
|
||||||
@@ -1928,6 +1931,137 @@ app.get('/api/admin/export/estudiantes.csv', (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Exportar Recargas y Depósitos SINPE a CSV / Excel
|
||||||
|
app.get('/api/admin/export/recargas.csv', (req, res) => {
|
||||||
|
try {
|
||||||
|
const escuelaId = req.query.escuela_id ? parseInt(req.query.escuela_id, 10) : null;
|
||||||
|
const { desde, hasta, estado } = req.query;
|
||||||
|
|
||||||
|
let query = `
|
||||||
|
SELECT s.id, s.creado_en, s.comprobante_sinpe, s.codigo_detalle, s.monto_colones, s.estado, s.notas,
|
||||||
|
e.codigo_estudiante, e.nombre_completo as estudiante_nombre, e.grado, e.seccion,
|
||||||
|
COALESCE(u.nombre, e.padre_nombre) as padre_nombre,
|
||||||
|
COALESCE(u.telefono, e.padre_telefono) as padre_telefono,
|
||||||
|
u_aprob.nombre as aprobado_por_nombre
|
||||||
|
FROM solicitudes_recarga_sinpe s
|
||||||
|
JOIN estudiantes e ON s.estudiante_id = e.id
|
||||||
|
LEFT JOIN usuarios u ON s.padre_usuario_id = u.id
|
||||||
|
LEFT JOIN usuarios u_aprob ON s.aprobado_por_usuario_id = u_aprob.id
|
||||||
|
WHERE 1=1
|
||||||
|
`;
|
||||||
|
const params = [];
|
||||||
|
|
||||||
|
if (escuelaId) {
|
||||||
|
query += ` AND (s.escuela_id = ? OR s.escuela_id IS NULL) `;
|
||||||
|
params.push(escuelaId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (desde && desde.trim()) {
|
||||||
|
query += ` AND s.creado_en >= ? `;
|
||||||
|
params.push(`${desde.trim()} 00:00:00`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasta && hasta.trim()) {
|
||||||
|
query += ` AND s.creado_en <= ? `;
|
||||||
|
params.push(`${hasta.trim()} 23:59:59`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (estado && estado.trim() && estado.trim() !== 'todos') {
|
||||||
|
query += ` AND s.estado = ? `;
|
||||||
|
params.push(estado.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
query += ` ORDER BY s.id DESC LIMIT 5000`;
|
||||||
|
|
||||||
|
const recargas = db.prepare(query).all(...params);
|
||||||
|
|
||||||
|
const headers = [
|
||||||
|
'ID Solicitud',
|
||||||
|
'Fecha y Hora',
|
||||||
|
'Comprobante SINPE',
|
||||||
|
'Código Verificación',
|
||||||
|
'Estudiante',
|
||||||
|
'Carné Estudiante',
|
||||||
|
'Grado y Sección',
|
||||||
|
'Padre / Tutor',
|
||||||
|
'Teléfono Padre',
|
||||||
|
'Monto (CRC)',
|
||||||
|
'Estado',
|
||||||
|
'Verificado Por',
|
||||||
|
'Notas'
|
||||||
|
];
|
||||||
|
|
||||||
|
const csvData = recargas.map(r => {
|
||||||
|
const fechaFmt = r.creado_en ? new Date(r.creado_en).toLocaleString('es-CR') : '';
|
||||||
|
const gradoSeccion = [r.grado, r.seccion].filter(Boolean).join(' - ') || 'N/A';
|
||||||
|
let estLabel = r.estado;
|
||||||
|
if (r.estado === 'aprobado') estLabel = 'Aprobada / Acreditada';
|
||||||
|
else if (r.estado === 'rechazado') estLabel = 'Rechazada';
|
||||||
|
else if (r.estado === 'pendiente') estLabel = 'Pendiente de Verificación';
|
||||||
|
|
||||||
|
return [
|
||||||
|
r.id,
|
||||||
|
fechaFmt,
|
||||||
|
r.comprobante_sinpe || '',
|
||||||
|
r.codigo_detalle || '',
|
||||||
|
r.estudiante_nombre || '',
|
||||||
|
r.codigo_estudiante || '',
|
||||||
|
gradoSeccion,
|
||||||
|
r.padre_nombre || 'Padre de Familia',
|
||||||
|
r.padre_telefono || '',
|
||||||
|
r.monto_colones || 0,
|
||||||
|
estLabel,
|
||||||
|
r.aprobado_por_nombre || (r.estado === 'aprobado' ? 'Sistema / Cajero' : ''),
|
||||||
|
r.notas || ''
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
const csvOutput = arrayToCsv(headers, csvData);
|
||||||
|
const dateTag = desde ? `${desde}_a_${hasta || desde}` : new Date().toISOString().slice(0, 10);
|
||||||
|
const filename = `recargas_sinpe_sibopay_${dateTag}.csv`;
|
||||||
|
res.setHeader('Content-Type', 'text/csv; charset=utf-8');
|
||||||
|
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
|
||||||
|
res.send(csvOutput);
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Obtener Horarios de Recreos y Almuerzo de la Escuela
|
||||||
|
app.get('/api/escuela/horarios', (req, res) => {
|
||||||
|
try {
|
||||||
|
const escuelaId = req.query.escuela_id ? parseInt(req.query.escuela_id, 10) : 1;
|
||||||
|
const horarios = obtenerHorariosEscuela(escuelaId);
|
||||||
|
res.json({ success: true, horarios });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Modificar Horarios de Recreos y Almuerzo de la Escuela (Admin)
|
||||||
|
app.put('/api/admin/escuela/horarios', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { escuela_id, hora_recreo_1, hora_almuerzo, hora_recreo_2 } = req.body;
|
||||||
|
const escuelaId = escuela_id ? parseInt(escuela_id, 10) : 1;
|
||||||
|
const actualizados = actualizarHorariosEscuela(escuelaId, {
|
||||||
|
hora_recreo_1,
|
||||||
|
hora_almuerzo,
|
||||||
|
hora_recreo_2
|
||||||
|
});
|
||||||
|
|
||||||
|
// Notificar en tiempo real por SSE
|
||||||
|
broadcastEvent('horarios_actualizados', actualizados);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
success: true,
|
||||||
|
message: 'Horarios escolares actualizados correctamente',
|
||||||
|
horarios: actualizados
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// 1. ESTUDIANTES Y QR
|
// 1. ESTUDIANTES Y QR
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
Reference in New Issue
Block a user