fix: exportacion directa sin popup-blocker, enlace window global, cache buster v12.2 y carga masiva robusta
This commit is contained in:
+11
-6
@@ -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">
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
<link rel="stylesheet" href="/css/styles.css?v=11.3">
|
<link rel="stylesheet" href="/css/styles.css?v=12.2">
|
||||||
<link rel="stylesheet" href="/css/desktop.css?v=2.2">
|
<link rel="stylesheet" href="/css/desktop.css?v=2.2">
|
||||||
<style>
|
<style>
|
||||||
/* Transiciones suaves */
|
/* Transiciones suaves */
|
||||||
@@ -520,9 +520,14 @@
|
|||||||
Importa decenas o cientos de estudiantes en segundos. Puedes subir un archivo <code>.csv</code> o pegar las celdas directamente copiadas desde Microsoft Excel o Google Sheets.
|
Importa decenas o cientos de estudiantes en segundos. Puedes subir un archivo <code>.csv</code> o pegar las celdas directamente copiadas desde Microsoft Excel o Google Sheets.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" onclick="descargarPlantillaCsvEstudiantes()" class="dev-action-btn" style="padding: 8px 14px; font-size: 0.80rem; display: inline-flex; align-items: center; gap: 6px;">
|
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
||||||
<span>📥 Descargar Plantilla Ejemplo (.CSV)</span>
|
<button type="button" onclick="cargarEjemploImportacionDev()" class="dev-action-btn" style="padding: 8px 14px; font-size: 0.80rem; display: inline-flex; align-items: center; gap: 6px; background: #e0f2fe; color: #0284c7; border: 1.5px solid #bae6fd; font-weight: 800;" title="Pega 3 estudiantes de muestra para probar la herramienta de inmediato">
|
||||||
</button>
|
<span>⚡ Cargar Datos de Ejemplo</span>
|
||||||
|
</button>
|
||||||
|
<button type="button" onclick="descargarPlantillaCsvEstudiantes()" class="dev-action-btn" style="padding: 8px 14px; font-size: 0.80rem; display: inline-flex; align-items: center; gap: 6px;">
|
||||||
|
<span>📥 Descargar Plantilla (.CSV)</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Paso 1: Seleccionar Escuela Destino -->
|
<!-- Paso 1: Seleccionar Escuela Destino -->
|
||||||
@@ -531,7 +536,7 @@
|
|||||||
1. Selecciona la Escuela / Sede de Destino: *
|
1. Selecciona la Escuela / Sede de Destino: *
|
||||||
</label>
|
</label>
|
||||||
<select id="devImportEscuelaSelect" style="width: 100%; max-width: 420px; padding: 10px 14px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-weight: 700; font-size: 0.90rem;">
|
<select id="devImportEscuelaSelect" style="width: 100%; max-width: 420px; padding: 10px 14px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card-bg); color: var(--text-main); font-weight: 700; font-size: 0.90rem;">
|
||||||
<!-- Cargado dinámicamente -->
|
<option value="1">Soda Escolar Central (ESC01)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -3138,6 +3143,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=11.2"></script>
|
<script src="/js/app.js?v=12.2"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+146
-26
@@ -67,7 +67,8 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
|
|
||||||
// Registrar Service Worker para PWA
|
// Registrar Service Worker para PWA
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('/sw.js?v=8.5').then(reg => {
|
navigator.serviceWorker.register('/sw.js?v=12.2').then(reg => {
|
||||||
|
reg.update().catch(() => {});
|
||||||
if ('Notification' in window && Notification.permission === 'granted') {
|
if ('Notification' in window && Notification.permission === 'granted') {
|
||||||
subscribeDeviceToWebPush().catch(() => {});
|
subscribeDeviceToWebPush().catch(() => {});
|
||||||
}
|
}
|
||||||
@@ -7685,6 +7686,44 @@ async function ejecutarBackupManualDev() {
|
|||||||
function descargarBackupDev(filename) {
|
function descargarBackupDev(filename) {
|
||||||
window.location.href = `/api/developer/backups/descargar/${filename}`;
|
window.location.href = `/api/developer/backups/descargar/${filename}`;
|
||||||
}
|
}
|
||||||
|
window.descargarBackupDev = descargarBackupDev;
|
||||||
|
window.cargarBackupsDev = cargarBackupsDev;
|
||||||
|
window.ejecutarBackupManualDev = ejecutarBackupManualDev;
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// DESCARGA DIRECTA DE ARCHIVOS (ANTI POPUP-BLOCKER)
|
||||||
|
// ==========================================
|
||||||
|
async function descargarArchivoDirecto(url, defaultFilename) {
|
||||||
|
try {
|
||||||
|
const res = await fetch(url);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error(`El servidor respondió con código ${res.status}`);
|
||||||
|
}
|
||||||
|
const blob = await res.blob();
|
||||||
|
const blobUrl = window.URL.createObjectURL(blob);
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = blobUrl;
|
||||||
|
link.download = defaultFilename || 'reporte.csv';
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
setTimeout(() => {
|
||||||
|
if (link.parentNode) link.parentNode.removeChild(link);
|
||||||
|
window.URL.revokeObjectURL(blobUrl);
|
||||||
|
}, 250);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error al descargar archivo blob, usando fallback directo:', err);
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = defaultFilename || 'reporte.csv';
|
||||||
|
link.target = '_blank';
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
setTimeout(() => {
|
||||||
|
if (link.parentNode) link.parentNode.removeChild(link);
|
||||||
|
}, 250);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
window.descargarArchivoDirecto = descargarArchivoDirecto;
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// CARGA MASIVA DE ESTUDIANTES (DEVELOPER)
|
// CARGA MASIVA DE ESTUDIANTES (DEVELOPER)
|
||||||
@@ -7697,21 +7736,41 @@ async function cargarEscuelasSelectImportacion() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/developer/escuelas');
|
const res = await fetch('/api/developer/escuelas');
|
||||||
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
||||||
const escuelas = await res.json();
|
const escuelas = await res.json();
|
||||||
select.innerHTML = escuelas.map(e => `
|
if (Array.isArray(escuelas) && escuelas.length > 0) {
|
||||||
<option value="${e.id}">${escapeHtml(e.nombre)} (${escapeHtml(e.codigo)})</option>
|
select.innerHTML = escuelas.map(e => `
|
||||||
`).join('');
|
<option value="${e.id}">${escapeHtml(e.nombre)} (${escapeHtml(e.codigo || 'Sede')})</option>
|
||||||
|
`).join('');
|
||||||
|
} else {
|
||||||
|
select.innerHTML = '<option value="1">Soda Escolar Central (ESC01)</option>';
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error cargando escuelas para importación:', err);
|
console.error('Error cargando escuelas para importación:', err);
|
||||||
|
if (select.children.length === 0) {
|
||||||
|
select.innerHTML = '<option value="1">Soda Escolar Central (ESC01)</option>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window.cargarEscuelasSelectImportacion = cargarEscuelasSelectImportacion;
|
||||||
|
|
||||||
|
function cargarEjemploImportacionDev() {
|
||||||
|
const txt = document.getElementById('devImportTextarea');
|
||||||
|
if (!txt) return;
|
||||||
|
txt.value = `Nombre Completo\tGrado\tSección\tSaldo Inicial\tAlergias\tTeléfono Padre
|
||||||
|
Santiago Morales Castro\t5to\t5-B\t3000\tLactosa\t8888-1234
|
||||||
|
Valeria Solano Gómez\t3ro\t3-A\t5000\tNinguna\t8765-4321
|
||||||
|
Mateo Alvarado Pérez\t2do\t2-A\t1500\tManí\t8333-2211`;
|
||||||
|
analizarDatosImportacionDev();
|
||||||
|
}
|
||||||
|
window.cargarEjemploImportacionDev = cargarEjemploImportacionDev;
|
||||||
|
|
||||||
function descargarPlantillaCsvEstudiantes() {
|
function descargarPlantillaCsvEstudiantes() {
|
||||||
const headers = ['Nombre Completo', 'Grado', 'Seccion', 'Saldo Inicial', 'Alergias', 'Telefono Padre'];
|
const headers = ['Nombre Completo', 'Grado', 'Seccion', 'Saldo Inicial', 'Alergias', 'Telefono Padre'];
|
||||||
const sampleRows = [
|
const sampleRows = [
|
||||||
['Santiago Morales Castro', '5to', '5-B', '3000', 'Lactosa', '8888-1234'],
|
['Santiago Morales Castro', '5to', '5-B', '3000', 'Lactosa', '8888-1234'],
|
||||||
['Valeria Solano Gómez', '3ro', '3-A', '5000', 'Ninguna', '8765-4321'],
|
['Valeria Solano Gómez', '3ro', '3-A', '5000', 'Ninguna', '8765-4321'],
|
||||||
['Mateo Alvarado Pérez', '2do', '2-A', '0', 'Maní', '8333-2211']
|
['Mateo Alvarado Pérez', '2do', '2-A', '1500', 'Maní', '8333-2211']
|
||||||
];
|
];
|
||||||
const csvContent = '\uFEFF' + [headers.join(','), ...sampleRows.map(r => r.map(c => `"${c}"`).join(','))].join('\r\n');
|
const csvContent = '\uFEFF' + [headers.join(','), ...sampleRows.map(r => r.map(c => `"${c}"`).join(','))].join('\r\n');
|
||||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||||
@@ -7721,9 +7780,12 @@ function descargarPlantillaCsvEstudiantes() {
|
|||||||
a.download = 'plantilla_estudiantes_sibopay.csv';
|
a.download = 'plantilla_estudiantes_sibopay.csv';
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
a.click();
|
a.click();
|
||||||
document.body.removeChild(a);
|
setTimeout(() => {
|
||||||
URL.revokeObjectURL(url);
|
if (a.parentNode) a.parentNode.removeChild(a);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}, 250);
|
||||||
}
|
}
|
||||||
|
window.descargarPlantillaCsvEstudiantes = descargarPlantillaCsvEstudiantes;
|
||||||
|
|
||||||
function handleDevImportFile(event) {
|
function handleDevImportFile(event) {
|
||||||
const file = event.target.files && event.target.files[0];
|
const file = event.target.files && event.target.files[0];
|
||||||
@@ -7740,6 +7802,7 @@ function handleDevImportFile(event) {
|
|||||||
};
|
};
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
}
|
}
|
||||||
|
window.handleDevImportFile = handleDevImportFile;
|
||||||
|
|
||||||
function analizarDatosImportacionDev() {
|
function analizarDatosImportacionDev() {
|
||||||
const textarea = document.getElementById('devImportTextarea');
|
const textarea = document.getElementById('devImportTextarea');
|
||||||
@@ -7763,23 +7826,34 @@ function analizarDatosImportacionDev() {
|
|||||||
|
|
||||||
let delimiter = '\t';
|
let delimiter = '\t';
|
||||||
if (line.includes('\t')) delimiter = '\t';
|
if (line.includes('\t')) delimiter = '\t';
|
||||||
else if (line.includes(',')) delimiter = ',';
|
|
||||||
else if (line.includes(';')) delimiter = ';';
|
else if (line.includes(';')) delimiter = ';';
|
||||||
|
else if (line.includes(',')) delimiter = ',';
|
||||||
|
|
||||||
const cols = line.split(delimiter).map(c => c.trim().replace(/^["']|["']$/g, ''));
|
const cols = line.split(delimiter).map(c => c.trim().replace(/^["']|["']$/g, ''));
|
||||||
if (cols.length === 0 || !cols[0]) continue;
|
if (cols.length === 0 || !cols[0]) continue;
|
||||||
|
|
||||||
const firstColLower = cols[0].toLowerCase();
|
// Saltar encabezados
|
||||||
if (i === 0 && (firstColLower.includes('nombre') || firstColLower.includes('alumno') || firstColLower.includes('estudiante'))) {
|
const firstColLower = (cols[0] || '').toLowerCase();
|
||||||
|
const secondColLower = (cols[1] || '').toLowerCase();
|
||||||
|
if (i === 0 && (firstColLower.includes('nombre') || firstColLower.includes('alumno') || firstColLower.includes('estudiante') || secondColLower.includes('nombre'))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nombre = cols[0];
|
// Detectar si la primera columna es un número secuencial (1, 2, 3...)
|
||||||
const grado = cols[1] || 'General';
|
let offset = 0;
|
||||||
const seccion = cols[2] || 'A';
|
if (cols.length > 1 && /^\d+$/.test(cols[0]) && isNaN(cols[1])) {
|
||||||
const saldo = parseInt(cols[3] || 0, 10) || 0;
|
offset = 1;
|
||||||
const alergias = cols[4] || 'Ninguna conocida';
|
}
|
||||||
const tel = cols[5] || '';
|
|
||||||
|
const nombre = cols[offset + 0] || '';
|
||||||
|
if (!nombre || nombre.length < 2) continue;
|
||||||
|
|
||||||
|
const grado = cols[offset + 1] || 'General';
|
||||||
|
const seccion = cols[offset + 2] || 'A';
|
||||||
|
const saldoRaw = String(cols[offset + 3] || '0').replace(/[^\d]/g, '');
|
||||||
|
const saldo = parseInt(saldoRaw, 10) || 0;
|
||||||
|
const alergias = cols[offset + 4] || 'Ninguna conocida';
|
||||||
|
const tel = cols[offset + 5] || '';
|
||||||
|
|
||||||
parsedStudentsToImport.push({
|
parsedStudentsToImport.push({
|
||||||
nombre_completo: nombre,
|
nombre_completo: nombre,
|
||||||
@@ -7792,7 +7866,7 @@ function analizarDatosImportacionDev() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parsedStudentsToImport.length === 0) {
|
if (parsedStudentsToImport.length === 0) {
|
||||||
alert('No se detectaron alumnos válidos en el texto ingresado.');
|
alert('No se detectaron alumnos válidos en el texto ingresado. Asegúrate de incluir al menos los nombres de los estudiantes.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7811,8 +7885,12 @@ function analizarDatosImportacionDev() {
|
|||||||
`).join('');
|
`).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previewBox) previewBox.style.display = 'block';
|
if (previewBox) {
|
||||||
|
previewBox.style.display = 'block';
|
||||||
|
try { previewBox.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } catch (e) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
window.analizarDatosImportacionDev = analizarDatosImportacionDev;
|
||||||
|
|
||||||
async function ejecutarImportacionMasivaDev() {
|
async function ejecutarImportacionMasivaDev() {
|
||||||
if (!parsedStudentsToImport || parsedStudentsToImport.length === 0) {
|
if (!parsedStudentsToImport || parsedStudentsToImport.length === 0) {
|
||||||
@@ -7860,10 +7938,16 @@ async function ejecutarImportacionMasivaDev() {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('devImportPreviewBox').style.display = 'none';
|
const previewBox = document.getElementById('devImportPreviewBox');
|
||||||
document.getElementById('devImportTextarea').value = '';
|
if (previewBox) previewBox.style.display = 'none';
|
||||||
|
const txt = document.getElementById('devImportTextarea');
|
||||||
|
if (txt) txt.value = '';
|
||||||
parsedStudentsToImport = [];
|
parsedStudentsToImport = [];
|
||||||
|
|
||||||
|
// Recargar usuarios/estudiantes en las demás vistas
|
||||||
|
if (typeof loadDevUsuarios === 'function') loadDevUsuarios();
|
||||||
|
if (typeof loadAdminData === 'function') loadAdminData();
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (window.sounds) window.sounds.playError();
|
if (window.sounds) window.sounds.playError();
|
||||||
if (resultMsg) {
|
if (resultMsg) {
|
||||||
@@ -7880,19 +7964,55 @@ async function ejecutarImportacionMasivaDev() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window.ejecutarImportacionMasivaDev = ejecutarImportacionMasivaDev;
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// EXPORTACIÓN A EXCEL / CSV (ADMIN SODA)
|
// EXPORTACIÓN A EXCEL / CSV (ADMIN SODA)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
function exportarVentasCsv() {
|
async function exportarVentasCsv() {
|
||||||
const escuelaId = (window.currentAdminUser && window.currentAdminUser.escuela_id) || '';
|
const btn = document.querySelector('[onclick*="exportarVentasCsv"]');
|
||||||
window.open(`/api/admin/export/ventas.csv${escuelaId ? '?escuela_id=' + escuelaId : ''}`, '_blank');
|
const origHtml = btn ? btn.innerHTML : '';
|
||||||
|
if (btn) {
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.innerHTML = '<span>⏳ Generando...</span>';
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const escuelaId = (currentUser && currentUser.escuela_id) || '';
|
||||||
|
const url = `/api/admin/export/ventas.csv${escuelaId ? '?escuela_id=' + escuelaId : ''}`;
|
||||||
|
await descargarArchivoDirecto(url, `ventas_sibopay_${new Date().toISOString().slice(0, 10)}.csv`);
|
||||||
|
} catch (err) {
|
||||||
|
alert('Error al exportar ventas: ' + err.message);
|
||||||
|
} finally {
|
||||||
|
if (btn) {
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerHTML = origHtml;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
window.exportarVentasCsv = exportarVentasCsv;
|
||||||
|
|
||||||
function exportarEstudiantesCsv() {
|
async function exportarEstudiantesCsv() {
|
||||||
const escuelaId = (window.currentAdminUser && window.currentAdminUser.escuela_id) || '';
|
const btn = document.querySelector('[onclick*="exportarEstudiantesCsv"]');
|
||||||
window.open(`/api/admin/export/estudiantes.csv${escuelaId ? '?escuela_id=' + escuelaId : ''}`, '_blank');
|
const origHtml = btn ? btn.innerHTML : '';
|
||||||
|
if (btn) {
|
||||||
|
btn.disabled = true;
|
||||||
|
btn.innerHTML = '<span>⏳ Generando...</span>';
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const escuelaId = (currentUser && currentUser.escuela_id) || '';
|
||||||
|
const url = `/api/admin/export/estudiantes.csv${escuelaId ? '?escuela_id=' + escuelaId : ''}`;
|
||||||
|
await descargarArchivoDirecto(url, `estudiantes_sibopay_${new Date().toISOString().slice(0, 10)}.csv`);
|
||||||
|
} catch (err) {
|
||||||
|
alert('Error al exportar estudiantes: ' + err.message);
|
||||||
|
} finally {
|
||||||
|
if (btn) {
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.innerHTML = origHtml;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
window.exportarEstudiantesCsv = exportarEstudiantesCsv;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -90,7 +90,8 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
|
|
||||||
// Registrar Service Worker para Notificaciones PWA
|
// Registrar Service Worker para Notificaciones PWA
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.register('/sw.js?v=8.5').then(() => {
|
navigator.serviceWorker.register('/sw.js?v=12.2').then((reg) => {
|
||||||
|
reg.update().catch(() => {});
|
||||||
if ('Notification' in window && Notification.permission === 'granted') {
|
if ('Notification' in window && Notification.permission === 'granted') {
|
||||||
subscribeDeviceToWebPush().catch(() => {});
|
subscribeDeviceToWebPush().catch(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
// SiboPay PWA Service Worker v12.0 - Alta Velocidad & Despacho
|
// SiboPay PWA Service Worker v12.2 - Alta Velocidad & Despacho
|
||||||
const CACHE_NAME = 'sibopay-v12.0';
|
const CACHE_NAME = 'sibopay-v12.2';
|
||||||
const STATIC_ASSETS = [
|
const STATIC_ASSETS = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
|
|||||||
Reference in New Issue
Block a user