Corregir buscador y vinculacion de estudiantes en modal de deposito SINPE con normalizacion de acentos y endpoint dedicado
This commit is contained in:
+10
-7
@@ -3966,9 +3966,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="margin-bottom: 16px;">
|
<div style="margin-bottom: 16px;">
|
||||||
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); display: block; margin-bottom: 5px;">Buscar Estudiante Beneficiario: *</label>
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px;">
|
||||||
<input type="text" id="devVincularEstudianteSearch" placeholder="Escribe el nombre del alumno o carné..." oninput="filtrarEstudiantesParaVincular()" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.86rem; font-weight: 700; box-sizing: border-box; margin-bottom: 6px;">
|
<label style="font-size: 0.82rem; font-weight: 800; color: var(--text-main); margin: 0;">Buscar Estudiante Beneficiario: *</label>
|
||||||
<select id="devVincularEstudianteSelect" required size="5" style="width: 100%; padding: 6px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-size: 0.82rem; font-weight: 600;">
|
<span id="devVincularCountBadge" style="font-size: 0.74rem; color: #0284c7; font-weight: 800;"></span>
|
||||||
|
</div>
|
||||||
|
<input type="text" id="devVincularEstudianteSearch" placeholder="Escribe el nombre del alumno, grado o carné (ej: Sofía, Mateo)..." oninput="filtrarEstudiantesParaVincular()" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--bg-main); color: var(--text-main); font-size: 0.86rem; font-weight: 700; box-sizing: border-box; margin-bottom: 6px;">
|
||||||
|
<select id="devVincularEstudianteSelect" required size="6" style="width: 100%; min-height: 150px; padding: 6px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-size: 0.82rem; font-weight: 600;">
|
||||||
<!-- Opciones inyectadas -->
|
<!-- Opciones inyectadas -->
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -4537,10 +4540,10 @@
|
|||||||
</button>
|
</button>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<script src="/js/dialogs.js?v=19.0"></script>
|
<script src="/js/dialogs.js?v=19.1"></script>
|
||||||
<script src="/js/sounds.js?v=19.0"></script>
|
<script src="/js/sounds.js?v=19.1"></script>
|
||||||
<script src="/js/jsQR.js" defer></script>
|
<script src="/js/jsQR.js" defer></script>
|
||||||
<script src="/js/food-icons.js?v=19.0" defer></script>
|
<script src="/js/food-icons.js?v=19.1" defer></script>
|
||||||
<script src="/js/app.js?v=19.0"></script>
|
<script src="/js/app.js?v=19.1"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+53
-13
@@ -10440,9 +10440,17 @@ async function abrirModalVincularBancoDev(bancoTxId) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Limpiar campos de búsqueda previa
|
||||||
|
const searchInput = document.getElementById('devVincularEstudianteSearch');
|
||||||
|
if (searchInput) searchInput.value = '';
|
||||||
|
const inputNotas = document.getElementById('devVincularNotas');
|
||||||
|
if (inputNotas) inputNotas.value = '';
|
||||||
|
|
||||||
|
modal.style.display = 'flex';
|
||||||
|
|
||||||
// Cargar estudiantes para selector
|
// Cargar estudiantes para selector
|
||||||
await cargarEstudiantesParaVinculacion();
|
await cargarEstudiantesParaVinculacion();
|
||||||
modal.style.display = 'flex';
|
if (searchInput) searchInput.focus();
|
||||||
}
|
}
|
||||||
window.abrirModalVincularBancoDev = abrirModalVincularBancoDev;
|
window.abrirModalVincularBancoDev = abrirModalVincularBancoDev;
|
||||||
|
|
||||||
@@ -10456,14 +10464,19 @@ async function cargarEstudiantesParaVinculacion() {
|
|||||||
const select = document.getElementById('devVincularEstudianteSelect');
|
const select = document.getElementById('devVincularEstudianteSelect');
|
||||||
if (!select) return;
|
if (!select) return;
|
||||||
|
|
||||||
if (devCachedEstudiantesList.length === 0) {
|
select.innerHTML = '<option disabled>Cargando lista de estudiantes del sistema...</option>';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/admin/estudiantes');
|
let res = await fetch('/api/developer/estudiantes/buscar');
|
||||||
|
if (!res.ok) {
|
||||||
|
res = await fetch('/api/estudiantes');
|
||||||
|
}
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (res.ok && Array.isArray(data)) {
|
if (Array.isArray(data)) {
|
||||||
devCachedEstudiantesList = data;
|
devCachedEstudiantesList = data;
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
|
console.error('Error cargando estudiantes para vinculación:', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
filtrarEstudiantesParaVincular();
|
filtrarEstudiantesParaVincular();
|
||||||
@@ -10472,21 +10485,48 @@ async function cargarEstudiantesParaVinculacion() {
|
|||||||
function filtrarEstudiantesParaVincular() {
|
function filtrarEstudiantesParaVincular() {
|
||||||
const searchInput = document.getElementById('devVincularEstudianteSearch');
|
const searchInput = document.getElementById('devVincularEstudianteSearch');
|
||||||
const select = document.getElementById('devVincularEstudianteSelect');
|
const select = document.getElementById('devVincularEstudianteSelect');
|
||||||
|
const countBadge = document.getElementById('devVincularCountBadge');
|
||||||
if (!select) return;
|
if (!select) return;
|
||||||
|
|
||||||
const query = (searchInput?.value || '').toLowerCase().trim();
|
const normalizeStr = str => (str || '')
|
||||||
|
.normalize("NFD")
|
||||||
|
.replace(/[\u0300-\u036f]/g, "")
|
||||||
|
.toLowerCase()
|
||||||
|
.trim();
|
||||||
|
|
||||||
|
const rawQuery = (searchInput?.value || '').trim();
|
||||||
|
const query = normalizeStr(rawQuery);
|
||||||
|
|
||||||
const filtered = devCachedEstudiantesList.filter(e => {
|
const filtered = devCachedEstudiantesList.filter(e => {
|
||||||
if (!query) return true;
|
if (!query) return true;
|
||||||
return (e.nombre_completo || '').toLowerCase().includes(query) ||
|
return normalizeStr(e.nombre_completo).includes(query) ||
|
||||||
(e.codigo_estudiante || '').toLowerCase().includes(query) ||
|
normalizeStr(e.codigo_estudiante).includes(query) ||
|
||||||
(e.padre_nombre || '').toLowerCase().includes(query);
|
normalizeStr(e.padre_nombre).includes(query) ||
|
||||||
|
normalizeStr(e.padre_telefono).includes(query) ||
|
||||||
|
normalizeStr(e.grado).includes(query) ||
|
||||||
|
normalizeStr(e.seccion).includes(query) ||
|
||||||
|
normalizeStr(e.escuela_nombre).includes(query);
|
||||||
});
|
});
|
||||||
|
|
||||||
select.innerHTML = filtered.map(e => `
|
if (countBadge) {
|
||||||
<option value="${e.id}">
|
countBadge.textContent = `${filtered.length} estudiante(s)`;
|
||||||
${e.nombre_completo} · ${e.grado || ''} ${e.seccion || ''} (${e.codigo_estudiante || 'ID ' + e.id}) - Saldo actual: ₡${(e.saldo_colones || 0).toLocaleString('es-CR')}
|
}
|
||||||
|
|
||||||
|
if (filtered.length === 0) {
|
||||||
|
select.innerHTML = `<option disabled value="" style="padding: 10px; color: #ef4444; font-weight: 700;">⚠️ No se encontró ningún estudiante con "${rawQuery}"</option>`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
select.innerHTML = filtered.map(e => {
|
||||||
|
const escBadge = e.escuela_nombre ? ` [${e.escuela_nombre}]` : '';
|
||||||
|
const carnet = e.codigo_estudiante ? ` · ${e.codigo_estudiante}` : '';
|
||||||
|
const saldo = Number(e.saldo_colones || 0).toLocaleString('es-CR');
|
||||||
|
return `
|
||||||
|
<option value="${e.id}" style="padding: 8px 10px; font-weight: 700; border-bottom: 1px solid var(--border);">
|
||||||
|
${e.nombre_completo}${carnet} (${e.grado || ''} ${e.seccion || ''})${escBadge} - Saldo: ₡${saldo}
|
||||||
</option>
|
</option>
|
||||||
`).join('');
|
`;
|
||||||
|
}).join('');
|
||||||
|
|
||||||
if (filtered.length > 0) {
|
if (filtered.length > 0) {
|
||||||
select.selectedIndex = 0;
|
select.selectedIndex = 0;
|
||||||
|
|||||||
+7
-7
@@ -1,5 +1,5 @@
|
|||||||
// SiboPay PWA Service Worker v19.0 - Ultra Fast Startup & Stale-While-Revalidate
|
// SiboPay PWA Service Worker v19.1 - Ultra Fast Startup & Stale-While-Revalidate
|
||||||
const CACHE_NAME = 'sibopay-v19.0';
|
const CACHE_NAME = 'sibopay-v19.1';
|
||||||
const STATIC_ASSETS = [
|
const STATIC_ASSETS = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
@@ -8,13 +8,13 @@ const STATIC_ASSETS = [
|
|||||||
'/pistola.html',
|
'/pistola.html',
|
||||||
'/carnet.html',
|
'/carnet.html',
|
||||||
'/manifest.json',
|
'/manifest.json',
|
||||||
'/css/styles.css?v=19.0',
|
'/css/styles.css?v=19.1',
|
||||||
'/css/desktop.css?v=2.2',
|
'/css/desktop.css?v=2.2',
|
||||||
'/js/dialogs.js?v=19.0',
|
'/js/dialogs.js?v=19.1',
|
||||||
'/js/app.js?v=19.0',
|
'/js/app.js?v=19.1',
|
||||||
'/js/pos.js',
|
'/js/pos.js',
|
||||||
'/js/sounds.js?v=19.0',
|
'/js/sounds.js?v=19.1',
|
||||||
'/js/food-icons.js?v=19.0',
|
'/js/food-icons.js?v=19.1',
|
||||||
'/icons/icon-192.png',
|
'/icons/icon-192.png',
|
||||||
'/icons/icon-512.png',
|
'/icons/icon-512.png',
|
||||||
'/img/sibopay-emblem.png',
|
'/img/sibopay-emblem.png',
|
||||||
|
|||||||
@@ -2421,6 +2421,36 @@ app.post('/api/developer/estudiantes/importar-masivo', (req, res) => {
|
|||||||
// BUSCADOR UNIVERSAL Y AUDITORÍA SINPE (DEVELOPER)
|
// BUSCADOR UNIVERSAL Y AUDITORÍA SINPE (DEVELOPER)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
|
// 0. Listar / Buscar estudiantes para developer y admin
|
||||||
|
app.get(['/api/admin/estudiantes', '/api/developer/estudiantes/buscar'], (req, res) => {
|
||||||
|
try {
|
||||||
|
const q = (req.query.q || '').trim();
|
||||||
|
const escuelaId = req.query.escuela_id ? parseInt(req.query.escuela_id, 10) : null;
|
||||||
|
let sql = `
|
||||||
|
SELECT e.id, e.nombre_completo, e.codigo_estudiante, e.grado, e.seccion,
|
||||||
|
e.saldo_colones, e.escuela_id, e.padre_nombre, e.padre_telefono,
|
||||||
|
esc.nombre as escuela_nombre, esc.codigo as escuela_codigo
|
||||||
|
FROM estudiantes e
|
||||||
|
LEFT JOIN escuelas esc ON esc.id = e.escuela_id
|
||||||
|
WHERE e.activo = 1
|
||||||
|
`;
|
||||||
|
const params = [];
|
||||||
|
if (escuelaId) {
|
||||||
|
sql += ' AND e.escuela_id = ?';
|
||||||
|
params.push(escuelaId);
|
||||||
|
}
|
||||||
|
if (q) {
|
||||||
|
sql += ' AND (e.nombre_completo LIKE ? OR e.codigo_estudiante LIKE ? OR e.padre_nombre LIKE ? OR e.padre_telefono LIKE ?)';
|
||||||
|
params.push(`%${q}%`, `%${q}%`, `%${q}%`, `%${q}%`);
|
||||||
|
}
|
||||||
|
sql += ' ORDER BY e.nombre_completo ASC LIMIT 200';
|
||||||
|
const list = db.prepare(sql).all(...params);
|
||||||
|
res.json(list);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 1. Buscador universal multicriterio
|
// 1. Buscador universal multicriterio
|
||||||
app.get('/api/developer/sinpe/buscar', (req, res) => {
|
app.get('/api/developer/sinpe/buscar', (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user