diff --git a/public/js/app.js b/public/js/app.js
index 16b6cfa..25de4ce 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -2148,6 +2148,9 @@ function initStudentSSE() {
sse.addEventListener('solicitud_sinpe_procesada', (e) => {
try {
+ if (currentUser && ['admin', 'cajero', 'personal', 'dev', 'soda'].includes(currentUser.rol)) {
+ loadAdminSinpeRequests();
+ }
if (currentUser && currentUser.rol === 'padre') {
if (currentParentChild) {
loadParentSinpeRequests(currentParentChild.id);
@@ -2241,6 +2244,9 @@ function initStudentSSE() {
tag: `sinpe-${sol.id || Date.now()}`,
data: { url: '/pos.html?tab=sinpe' }
});
+
+ // 3. Refrescar solicitudes en panel admin si está abierto
+ loadAdminSinpeRequests();
}
if (currentUser && currentUser.rol === 'padre') {
@@ -3730,6 +3736,7 @@ function switchAdminTab(tabName) {
} else if (tabName === 'personal') {
loadAdminStaff();
} else if (tabName === 'recarga') {
+ loadAdminSinpeRequests();
if (!adminSelectedStudent) {
clearAdminSelectedStudent();
}
@@ -3769,6 +3776,9 @@ async function loadAdminData() {
categories = dataCat.categorias;
}
}
+
+ // 5. Cargar solicitudes SINPE pendientes para badge y sección
+ loadAdminSinpeRequests();
} catch (err) {
console.error('Error cargando datos de administración:', err);
}
@@ -4732,6 +4742,200 @@ async function submitAdminManualRecharge() {
}
}
+// ==========================================
+// APROBACIÓN MANUAL DE RECARGAS SINPE EN PANEL ADMIN
+// ==========================================
+
+async function loadAdminSinpeRequests() {
+ const list = document.getElementById('adminSinpeRequestsList');
+ const tabBadge = document.getElementById('badgeAdminTabSinpeCount');
+ const countBadge = document.getElementById('adminSinpeCountBadge');
+ if (!list) return;
+
+ try {
+ let url = '/api/sinpe/solicitudes?estado=pendiente';
+ if (currentUser && currentUser.escuela_id) {
+ url += `&escuela_id=${currentUser.escuela_id}`;
+ }
+
+ const res = await fetch(url);
+ const data = await res.json();
+ if (!res.ok) throw new Error(data.error);
+
+ const solicitudes = data.solicitudes || [];
+
+ if (tabBadge) {
+ if (solicitudes.length > 0) {
+ tabBadge.textContent = solicitudes.length;
+ tabBadge.style.display = 'inline-block';
+ } else {
+ tabBadge.style.display = 'none';
+ }
+ }
+
+ if (countBadge) {
+ if (solicitudes.length > 0) {
+ countBadge.textContent = solicitudes.length;
+ countBadge.style.display = 'inline-block';
+ } else {
+ countBadge.style.display = 'none';
+ }
+ }
+
+ if (solicitudes.length === 0) {
+ list.innerHTML = `
+
+
✨
+
No hay recargas SINPE pendientes
+
Todas las recargas reportadas por los padres han sido procesadas.
+
+ `;
+ return;
+ }
+
+ list.innerHTML = solicitudes.map(s => {
+ const fecha = new Date(s.creado_en).toLocaleString('es-CR', {
+ day: '2-digit',
+ month: 'short',
+ hour: '2-digit',
+ minute: '2-digit'
+ });
+
+ return `
+
+
+
+
+
+
+ ${getStudentInitials(s.estudiante_nombre)}
+
+
+
+ ${escapeHtml(s.estudiante_nombre)}
+
+
+ ${escapeHtml(s.estudiante_grado || 'Estudiante')} ${s.estudiante_seccion ? '• Sección ' + escapeHtml(s.estudiante_seccion) : ''}
+
+
+
+
+
+
+ +₡${s.monto_colones.toLocaleString('es-CR')}
+
+
+ ⏳ Por Verificar
+
+
+
+
+
+
+
+ Código:
+
+ ${escapeHtml(s.codigo_detalle || '-')}
+
+
+
+
+ Comprobante:
+
+ #${escapeHtml(s.comprobante_sinpe || '-')}
+
+
+
+
+ Reportado:
+ ${fecha}
+
+
+
+ Saldo Actual:
+ ₡${(s.estudiante_saldo || 0).toLocaleString('es-CR')}
+
+
+
+ ${s.notas ? `
+
+ 💬
+ Detalle: ${escapeHtml(s.notas)}
+
+ ` : ''}
+
+
+
+
+
+
+
+ `;
+ }).join('');
+ } catch (err) {
+ console.error('Error cargando solicitudes SINPE en panel admin:', err);
+ }
+}
+
+async function procesarSinpeAdmin(solicitudId, accion) {
+ if (accion === 'aprobar') {
+ const ok = confirm('¿Confirmas que verificaste el comprobante y el dinero ya ingresó a la cuenta bancaria de la soda?');
+ if (!ok) return;
+
+ try {
+ const res = await fetch('/api/sinpe/procesar', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ solicitud_id: solicitudId,
+ accion: 'aprobar',
+ usuario_id: currentUser ? currentUser.id : null
+ })
+ });
+ const data = await res.json();
+ if (!res.ok) throw new Error(data.error);
+
+ if (window.sounds) window.sounds.playCoin();
+ alert(`¡Recarga Aprobada!\nSe acreditaron ₡${data.resultado.monto.toLocaleString('es-CR')} al estudiante ${data.resultado.estudiante_nombre}.\nNuevo saldo: ₡${data.resultado.saldo_nuevo.toLocaleString('es-CR')}.`);
+ loadAdminSinpeRequests();
+ await loadAdminData();
+ } catch (err) {
+ if (window.sounds) window.sounds.playError();
+ alert(`Error al aprobar recarga: ${err.message}`);
+ }
+ } else if (accion === 'rechazar') {
+ const motivo = prompt('Motivo del rechazo de la recarga:', 'Comprobante no coincide o fondos no recibidos');
+ if (motivo === null) return;
+
+ try {
+ const res = await fetch('/api/sinpe/procesar', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ solicitud_id: solicitudId,
+ accion: 'rechazar',
+ motivo: motivo || 'Rechazado por la soda',
+ usuario_id: currentUser ? currentUser.id : null
+ })
+ });
+ const data = await res.json();
+ if (!res.ok) throw new Error(data.error);
+
+ alert('La solicitud de recarga ha sido rechazada.');
+ loadAdminSinpeRequests();
+ await loadAdminData();
+ } catch (err) {
+ alert(`Error al rechazar recarga: ${err.message}`);
+ }
+ }
+}
+
// ==========================================
// HISTORIAL DE MOVIMIENTOS Y REVERSIONES (ADMIN / CAJERO)
// ==========================================
diff --git a/public/js/pos.js b/public/js/pos.js
index 4d3594d..80096bc 100644
--- a/public/js/pos.js
+++ b/public/js/pos.js
@@ -1738,41 +1738,77 @@ async function loadSinpeRequests() {
});
return `
-
-
-
-
+
+
+
+
+
+
${getStudentInitials(s.estudiante_nombre)}
-
${s.estudiante_nombre}
-
- ${s.estudiante_grado || ''} ${s.estudiante_seccion ? '• Sec. ' + s.estudiante_seccion : ''}
+
+ ${s.estudiante_nombre}
-
- Reportado: ${fecha}
+
+ ${s.estudiante_grado || 'Estudiante'} ${s.estudiante_seccion ? '• Sección ' + s.estudiante_seccion : ''}
-
+
+₡${s.monto_colones.toLocaleString('es-CR')}
-
- Comp:
#${s.comprobante_sinpe}
+
+ ⏳ Por Verificar
-
-