feat: trazabilidad detallada en rechazos SINPE, modales en la app y formato Excel con columnas separadas

This commit is contained in:
unknown
2026-10-08 12:23:57 -06:00
parent 6f0cb55658
commit e7d1d86978
8 changed files with 768 additions and 69 deletions
+169
View File
@@ -5856,4 +5856,173 @@ body.dark-mode .limit-preset-pill:hover {
border-color: #38bdf8;
}
/* ========================================================
SISTEMA GLOBAL DE MODALES Y DIÁLOGOS DE LA APLICACIÓN (EN LUGAR DEL NAVEGADOR)
======================================================== */
.app-dialog-backdrop {
position: fixed;
inset: 0;
background: rgba(15, 23, 42, 0.75);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
display: flex;
align-items: center;
justify-content: center;
z-index: 999999;
padding: 16px;
opacity: 0;
visibility: hidden;
transition: opacity 0.2s ease, visibility 0.2s ease;
box-sizing: border-box;
}
.app-dialog-backdrop.active {
opacity: 1;
visibility: visible;
}
.app-dialog-card {
background: var(--card-bg, #ffffff);
color: var(--text-main, #0f172a);
border: 1px solid var(--border, #e2e8f0);
border-radius: 20px;
padding: 24px 22px;
max-width: 420px;
width: 100%;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
transform: scale(0.92);
transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
text-align: center;
box-sizing: border-box;
}
.app-dialog-backdrop.active .app-dialog-card {
transform: scale(1);
}
.app-dialog-icon {
width: 56px;
height: 56px;
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 1.8rem;
margin-bottom: 14px;
}
.app-dialog-icon.success {
background: #dcfce7;
color: #166534;
border: 2px solid #86efac;
}
.app-dialog-icon.error, .app-dialog-icon.danger {
background: #fee2e2;
color: #991b1b;
border: 2px solid #fca5a5;
}
.app-dialog-icon.warning {
background: #fef3c7;
color: #92400e;
border: 2px solid #fde68a;
}
.app-dialog-icon.info {
background: #e0f2fe;
color: #0369a1;
border: 2px solid #7dd3fc;
}
.app-dialog-icon.question {
background: #eef2ff;
color: #4338ca;
border: 2px solid #c7d2fe;
}
.app-dialog-title {
font-size: 1.15rem;
font-weight: 900;
color: var(--text-main, #0f172a);
margin: 0 0 8px 0;
line-height: 1.3;
}
.app-dialog-message {
font-size: 0.88rem;
color: var(--text-muted, #475569);
line-height: 1.5;
margin: 0 0 20px 0;
white-space: pre-line;
word-break: break-word;
}
.app-dialog-actions {
display: flex;
gap: 10px;
justify-content: center;
}
.app-dialog-btn {
flex: 1;
min-height: 42px;
border-radius: 12px;
font-weight: 800;
font-size: 0.90rem;
cursor: pointer;
display: inline-flex;
align-items: center;
justify-content: center;
transition: all 0.15s ease;
border: none;
padding: 0 16px;
}
.app-dialog-btn-primary {
background: #0284c7;
color: #ffffff;
}
.app-dialog-btn-primary:hover {
background: #0369a1;
}
.app-dialog-btn-success {
background: #16a34a;
color: #ffffff;
}
.app-dialog-btn-success:hover {
background: #15803d;
}
.app-dialog-btn-danger {
background: #dc2626;
color: #ffffff;
}
.app-dialog-btn-danger:hover {
background: #b91c1c;
}
.app-dialog-btn-secondary {
background: #f1f5f9;
color: #475569;
border: 1px solid #cbd5e1;
}
.app-dialog-btn-secondary:hover {
background: #e2e8f0;
color: #1e293b;
}
/* Opciones seleccionables del modal de rechazo SINPE */
.sinpe-reject-option:hover {
border-color: #cbd5e1 !important;
background: #f8fafc;
}
.sinpe-reject-option:has(input:checked) {
border-color: #ef4444 !important;
background: #fef2f2 !important;
color: #991b1b !important;
}
+92 -2
View File
@@ -12,7 +12,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="SiboPay">
<meta name="mobile-web-app-capable" content="yes">
<link rel="stylesheet" href="/css/styles.css?v=13.0">
<link rel="stylesheet" href="/css/styles.css?v=13.4">
<link rel="stylesheet" href="/css/desktop.css?v=2.2">
<style>
/* Transiciones suaves */
@@ -3247,6 +3247,95 @@
</button>
</div>
</div>
<!-- MODAL: RECHAZAR RECARGA SINPE CON MOTIVO Y TRAZABILIDAD -->
<div class="modal-qr-backdrop" id="modalRechazarSinpe" style="display: none; z-index: 99999;" onclick="cerrarModalRechazoSinpe(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: left; padding: 22px; border-radius: 18px;">
<!-- Encabezado -->
<div style="display: flex; align-items: center; justify-content: space-between; border-bottom: 1.5px solid var(--border, #e2e8f0); padding-bottom: 10px; margin-bottom: 14px;">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1.3rem;">🚫</span>
<div>
<h3 style="margin: 0; font-size: 1.05rem; font-weight: 900; color: #991b1b;">Rechazar Recarga SINPE</h3>
<span style="font-size: 0.72rem; color: var(--text-muted, #64748b);">Trazabilidad detallada para la soda y el padre</span>
</div>
</div>
<button type="button" onclick="cerrarModalRechazoSinpe()" style="background: none; border: none; font-size: 1.3rem; color: var(--text-muted, #64748b); cursor: pointer; padding: 4px;">✕</button>
</div>
<!-- Resumen de Solicitud -->
<div style="background: rgba(148, 163, 184, 0.08); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: 0.80rem; line-height: 1.45;">
<div style="display: flex; justify-content: space-between;">
<span style="color: var(--text-muted, #64748b);">Estudiante:</span>
<strong id="rechazoSinpeEstudiante" style="color: var(--text-main, #0f172a);">-</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 3px;">
<span style="color: var(--text-muted, #64748b);">Monto Solicitado:</span>
<strong id="rechazoSinpeMonto" style="color: #0284c7; font-size: 0.92rem;">₡0</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 3px;">
<span style="color: var(--text-muted, #64748b);">Comprobante / Cód:</span>
<strong id="rechazoSinpeComprobante" style="color: var(--text-main, #334155);">-</strong>
</div>
</div>
<!-- Motivo de Rechazo (Opciones Rápidas) -->
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: var(--text-main, #0f172a); margin-bottom: 6px;">
Selecciona el motivo del rechazo:
</label>
<div style="display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px;">
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="fondos_no_recibidos" checked onchange="toggleSinpeRejectInputs()">
<span>🚫 Fondos no recibidos en cuenta bancaria</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="monto_no_coincide" onchange="toggleSinpeRejectInputs()">
<span>⚠️ Monto no coincide con comprobante</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="comprobante_invalido" onchange="toggleSinpeRejectInputs()">
<span>📄 Comprobante falso, duplicado o ilegible</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="telefono_no_coincide" onchange="toggleSinpeRejectInputs()">
<span>📱 Teléfono o destinatario no coincide</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid var(--border, #e2e8f0); border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155);">
<input type="radio" name="sinpeRejectReason" value="otro" onchange="toggleSinpeRejectInputs()">
<span>✏️ Otro motivo personalizado</span>
</label>
</div>
<!-- Campo de Monto Real cuando el monto no coincide -->
<div id="sinpeRejectMontoContainer" style="display: none; background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 10px; margin-bottom: 12px;">
<label style="display: block; font-size: 0.75rem; font-weight: 800; color: #92400e; margin-bottom: 4px;">
¿De cuánto era realmente el SINPE recibido? (₡):
</label>
<input type="number" id="sinpeRejectMontoReal" placeholder="Ej: 1000" style="width: 100%; height: 36px; padding: 0 10px; border: 1.5px solid #fcd34d; border-radius: 8px; font-size: 0.88rem; font-weight: 800; color: #92400e; box-sizing: border-box;" oninput="updateSinpeRejectPreview()">
<span id="sinpeRejectMontoPreview" style="display: block; font-size: 0.72rem; color: #b45309; margin-top: 4px; font-weight: 600;">
Se intentaron recargar ₡0 pero el SINPE fue de ₡0
</span>
</div>
<!-- Notas o detalles adicionales -->
<div style="margin-bottom: 16px;">
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: var(--text-muted, #64748b); margin-bottom: 4px;">
Detalle u observación adicional (opcional):
</label>
<input type="text" id="sinpeRejectNotasExtra" placeholder="Ej: Fondos no figuran en estado bancario al corte" style="width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border, #cbd5e1); border-radius: 8px; font-size: 0.80rem; box-sizing: border-box;">
</div>
<!-- Botones de Acción -->
<div style="display: flex; gap: 8px; justify-content: flex-end;">
<button type="button" onclick="cerrarModalRechazoSinpe()" class="btn-saas btn-saas-outline" style="height: 36px; padding: 0 14px; font-weight: 700;">
Cancelar
</button>
<button type="button" id="btnConfirmarRechazoSinpe" onclick="confirmarRechazoSinpeModal()" class="btn-saas" style="height: 36px; padding: 0 16px; background: #dc2626; color: #ffffff; border: 1px solid #dc2626; font-weight: 800;">
Confirmar Rechazo
</button>
</div>
</div>
</div>
@@ -3274,9 +3363,10 @@
</button>
</nav>
<script src="/js/dialogs.js?v=13.4"></script>
<script src="/js/sounds.js?v=9.6"></script>
<script src="/js/jsQR.js"></script>
<script src="/js/food-icons.js?v=1.1"></script>
<script src="/js/app.js?v=13.2"></script>
<script src="/js/app.js?v=13.4"></script>
</body>
</html>
+67 -35
View File
@@ -342,7 +342,12 @@ async function handleRegisterPadreSubmit(event) {
localStorage.setItem('recreopay_user', JSON.stringify(currentUser));
if (window.sounds) window.sounds.playSuccess();
alert(`¡Bienvenido(a) a SiboPay, ${data.user.nombre}! Tu cuenta de padre fue creada exitosamente.`);
await showAppAlert({
title: '¡Bienvenido(a) a SiboPay!',
message: `Hola ${data.user.nombre}, tu cuenta de padre fue creada exitosamente.\n\nYa puedes vincular a tus hijos, asignar límites diarios y realizar recargas por SINPE Móvil de forma segura.`,
type: 'success',
confirmText: 'Entrar a mi Panel'
});
await applyUserRoleSession();
} catch (err) {
if (errorMsg) {
@@ -5736,6 +5741,7 @@ async function loadAdminSinpeRequests() {
if (!res.ok) throw new Error(data.error);
const solicitudes = data.solicitudes || [];
window.cachedAdminSinpeRequests = solicitudes;
if (tabBadge) {
if (solicitudes.length > 0) {
@@ -5859,7 +5865,12 @@ async function loadAdminSinpeRequests() {
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?');
const ok = await showAppConfirm({
title: 'Aprobar Recarga SINPE',
message: '¿Confirmas que verificaste el comprobante y el dinero ya ingresó a la cuenta bancaria de la soda?',
type: 'question',
confirmText: 'Sí, Aprobar'
});
if (!ok) return;
try {
@@ -5876,37 +5887,59 @@ async function procesarSinpeAdmin(solicitudId, accion) {
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')}.`);
await showAppAlert({
title: '¡Recarga Aprobada!',
message: `Se acreditaron ₡${data.resultado.monto.toLocaleString('es-CR')} al estudiante ${data.resultado.estudiante_nombre}.\nNuevo saldo: ₡${data.resultado.saldo_nuevo.toLocaleString('es-CR')}.`,
type: 'success'
});
loadAdminSinpeRequests();
await loadAdminData();
} catch (err) {
if (window.sounds) window.sounds.playError();
alert(`Error al aprobar recarga: ${err.message}`);
showAppAlert({
title: 'Error al Aprobar',
message: err.message,
type: 'error'
});
}
} else if (accion === 'rechazar') {
const motivo = prompt('Motivo del rechazo de la recarga:', 'Comprobante no coincide o fondos no recibidos');
if (motivo === null) return;
const sol = (window.cachedAdminSinpeRequests || []).find(s => s.id === solicitudId) || {};
abrirModalRechazoSinpe({
id: solicitudId,
estudiante_nombre: sol.estudiante_nombre,
monto_colones: sol.monto_colones,
comprobante: sol.comprobante_sinpe || sol.codigo_detalle,
onConfirm: async (motivo) => {
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);
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}`);
}
await showAppAlert({
title: 'Recarga Rechazada',
message: 'La solicitud de recarga ha sido rechazada y su motivo ha quedado guardado para trazabilidad.',
type: 'warning'
});
loadAdminSinpeRequests();
await loadAdminData();
} catch (err) {
showAppAlert({
title: 'Error al Rechazar',
message: err.message,
type: 'error'
});
}
}
});
}
}
@@ -6173,8 +6206,8 @@ function renderAdminMovimientos() {
${m.codigo_orden ? `<span style="background: rgba(2, 132, 199, 0.1); color: #0284c7; padding: 1px 6px; border-radius: 4px; font-weight: 800; font-size: 0.7rem;">Ticket: ${m.codigo_orden}</span>` : ''}
</div>
${m.descripcion ? `
<div style="font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; background: rgba(148, 163, 184, 0.08); padding: 3px 8px; border-radius: 6px; line-height: 1.35; display: inline-block;">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="margin-right: 4px; vertical-align: -2px;"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>${m.descripcion}
<div style="font-size: 0.74rem; color: ${isSinpeRechazado ? '#991b1b' : 'var(--text-muted)'}; margin-top: 4px; background: ${isSinpeRechazado ? '#fff1f2' : 'rgba(148, 163, 184, 0.08)'}; border: ${isSinpeRechazado ? '1px solid #fecdd3' : 'none'}; padding: ${isSinpeRechazado ? '4px 9px' : '3px 8px'}; border-radius: 6px; line-height: 1.35; display: inline-block; font-weight: ${isSinpeRechazado ? '700' : 'normal'};">
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="${isSinpeRechazado ? '#e11d48' : 'currentColor'}" stroke-width="${isSinpeRechazado ? '2.5' : '2'}" style="margin-right: 4px; vertical-align: -2px;">${isSinpeRechazado ? '<circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/>' : '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/>'}</svg>${isSinpeRechazado ? '<strong style="color: #be123c;">Motivo del Rechazo:</strong> ' : ''}${m.descripcion.replace(/^SINPE Rechazado:\s*/, '')}
</div>
` : ''}
</div>
@@ -6210,13 +6243,12 @@ async function revertirMovimientoAdmin(transaccionId, monto, nombreEstudiante, t
? `Se restarán ₡${monto.toLocaleString('es-CR')} del monedero del estudiante.`
: `Se devolverán ₡${monto.toLocaleString('es-CR')} al monedero del estudiante y se restaurará el stock de los productos.`;
const conf = confirm(
`¿Estás seguro de revertir ${accionTexto}?\n\n` +
`• Alumno: ${nombreEstudiante}\n` +
`• Monto: ₡${monto.toLocaleString('es-CR')}\n\n` +
`${efectoTexto}\n\n` +
`¿Deseas continuar con la reversión?`
);
const conf = await showAppConfirm({
title: 'Confirmar Reversión',
message: `¿Estás seguro de revertir ${accionTexto}?\n\n• Alumno: ${nombreEstudiante}\n• Monto: ₡${monto.toLocaleString('es-CR')}\n\n${efectoTexto}`,
type: 'danger',
confirmText: 'Sí, Revertir'
});
if (!conf) return;
+286
View File
@@ -0,0 +1,286 @@
// ========================================================
// SISTEMA GLOBAL DE MODALES Y DIÁLOGOS DE SIBOPAY
// Reemplaza window.alert y window.confirm por modales integrados de la página
// ========================================================
(function() {
function ensureDialogDom() {
let backdrop = document.getElementById('appGlobalDialogBackdrop');
if (!backdrop) {
backdrop = document.createElement('div');
backdrop.id = 'appGlobalDialogBackdrop';
backdrop.className = 'app-dialog-backdrop';
backdrop.innerHTML = `
<div class="app-dialog-card" onclick="event.stopPropagation()">
<div class="app-dialog-icon info" id="appGlobalDialogIcon">ℹ️</div>
<h3 class="app-dialog-title" id="appGlobalDialogTitle">Aviso</h3>
<p class="app-dialog-message" id="appGlobalDialogMessage"></p>
<div class="app-dialog-actions" id="appGlobalDialogActions">
<button type="button" class="app-dialog-btn app-dialog-btn-primary" id="appGlobalDialogBtnConfirm">Entendido</button>
</div>
</div>
`;
document.body.appendChild(backdrop);
// Cerrar con Escape o confirmar con Enter
document.addEventListener('keydown', (e) => {
if (!backdrop.classList.contains('active')) return;
if (e.key === 'Escape') {
const cancelBtn = document.getElementById('appGlobalDialogBtnCancel');
if (cancelBtn) {
cancelBtn.click();
} else {
const confirmBtn = document.getElementById('appGlobalDialogBtnConfirm');
if (confirmBtn) confirmBtn.click();
}
} else if (e.key === 'Enter') {
const confirmBtn = document.getElementById('appGlobalDialogBtnConfirm');
if (confirmBtn) confirmBtn.click();
}
});
}
return backdrop;
}
function showAppAlert(options) {
return new Promise((resolve) => {
const opts = typeof options === 'string' ? { message: options } : (options || {});
const backdrop = ensureDialogDom();
const iconEl = document.getElementById('appGlobalDialogIcon');
const titleEl = document.getElementById('appGlobalDialogTitle');
const msgEl = document.getElementById('appGlobalDialogMessage');
const actionsEl = document.getElementById('appGlobalDialogActions');
let type = opts.type || 'info';
let title = opts.title;
let icon = 'ℹ️';
// Auto-detección por contenido si es alerta genérica
const msgLower = (opts.message || '').toLowerCase();
if (!opts.type) {
if (msgLower.includes('éxito') || msgLower.includes('aprobada') || msgLower.includes('guardad') || msgLower.includes('bienvenido') || msgLower.includes('confirmad')) {
type = 'success';
} else if (msgLower.includes('error') || msgLower.includes('falló') || msgLower.includes('rechazad') || msgLower.includes('denegad')) {
type = 'error';
} else if (msgLower.includes('atención') || msgLower.includes('cuidado') || msgLower.includes('límite') || msgLower.includes('bloquead')) {
type = 'warning';
}
}
if (type === 'success') icon = '✅';
else if (type === 'error' || type === 'danger') icon = '🚫';
else if (type === 'warning') icon = '⚠️';
else if (type === 'question') icon = '❓';
else icon = 'ℹ️';
if (!title) {
if (type === 'success') title = '¡Operación Exitosa!';
else if (type === 'error' || type === 'danger') title = 'Aviso del Sistema';
else if (type === 'warning') title = 'Atención';
else title = 'Información';
}
iconEl.className = `app-dialog-icon ${type}`;
iconEl.textContent = icon;
titleEl.textContent = title;
msgEl.textContent = opts.message || '';
const btnConfirmText = opts.confirmText || 'Entendido';
const btnClass = type === 'success' ? 'app-dialog-btn-success' : (type === 'error' || type === 'danger' ? 'app-dialog-btn-danger' : 'app-dialog-btn-primary');
actionsEl.innerHTML = `
<button type="button" class="app-dialog-btn ${btnClass}" id="appGlobalDialogBtnConfirm">${btnConfirmText}</button>
`;
const confirmBtn = document.getElementById('appGlobalDialogBtnConfirm');
confirmBtn.onclick = () => {
backdrop.classList.remove('active');
resolve(true);
};
backdrop.classList.add('active');
setTimeout(() => confirmBtn.focus(), 50);
});
}
function showAppConfirm(options) {
return new Promise((resolve) => {
const opts = typeof options === 'string' ? { message: options } : (options || {});
const backdrop = ensureDialogDom();
const iconEl = document.getElementById('appGlobalDialogIcon');
const titleEl = document.getElementById('appGlobalDialogTitle');
const msgEl = document.getElementById('appGlobalDialogMessage');
const actionsEl = document.getElementById('appGlobalDialogActions');
const isDanger = Boolean(opts.danger || opts.type === 'danger' || (opts.message || '').toLowerCase().includes('eliminar') || (opts.message || '').toLowerCase().includes('revertir'));
const type = isDanger ? 'danger' : (opts.type || 'question');
const icon = isDanger ? '⚠️' : '❓';
const title = opts.title || (isDanger ? '¿Confirmar Acción?' : 'Confirmación Requerida');
iconEl.className = `app-dialog-icon ${type}`;
iconEl.textContent = icon;
titleEl.textContent = title;
msgEl.textContent = opts.message || '';
const btnConfirmText = opts.confirmText || (isDanger ? 'Sí, continuar' : 'Confirmar');
const btnCancelText = opts.cancelText || 'Cancelar';
const btnClass = isDanger ? 'app-dialog-btn-danger' : 'app-dialog-btn-primary';
actionsEl.innerHTML = `
<button type="button" class="app-dialog-btn app-dialog-btn-secondary" id="appGlobalDialogBtnCancel">${btnCancelText}</button>
<button type="button" class="app-dialog-btn ${btnClass}" id="appGlobalDialogBtnConfirm">${btnConfirmText}</button>
`;
const confirmBtn = document.getElementById('appGlobalDialogBtnConfirm');
const cancelBtn = document.getElementById('appGlobalDialogBtnCancel');
confirmBtn.onclick = () => {
backdrop.classList.remove('active');
resolve(true);
};
cancelBtn.onclick = () => {
backdrop.classList.remove('active');
resolve(false);
};
backdrop.classList.add('active');
setTimeout(() => confirmBtn.focus(), 50);
});
}
// Exportar globalmente
window.showAppAlert = showAppAlert;
window.showAppConfirm = showAppConfirm;
// Interceptar window.alert nativo para que cualquier alerta existente se convierta en modal de la app
window.alert = function(msg) {
return showAppAlert(msg);
};
// ========================================================
// LÓGICA DEL MODAL DE RECHAZO DE SINPE (COMPARTIDO POS & ADMIN)
// ========================================================
let currentSinpeRejectData = null;
window.abrirModalRechazoSinpe = function({ id, estudiante_nombre, monto_colones, comprobante, onConfirm }) {
currentSinpeRejectData = {
id,
estudiante_nombre: estudiante_nombre || 'Estudiante',
monto_colones: Number(monto_colones || 0),
comprobante: comprobante || 'N/A',
onConfirm
};
const modal = document.getElementById('modalRechazarSinpe');
if (!modal) return;
const estEl = document.getElementById('rechazoSinpeEstudiante');
const montoEl = document.getElementById('rechazoSinpeMonto');
const compEl = document.getElementById('rechazoSinpeComprobante');
const realInput = document.getElementById('sinpeRejectMontoReal');
const notasInput = document.getElementById('sinpeRejectNotasExtra');
if (estEl) estEl.textContent = currentSinpeRejectData.estudiante_nombre;
if (montoEl) montoEl.textContent = `₡${currentSinpeRejectData.monto_colones.toLocaleString('es-CR')}`;
if (compEl) compEl.textContent = currentSinpeRejectData.comprobante;
if (realInput) realInput.value = '';
if (notasInput) notasInput.value = '';
const firstRadio = document.querySelector('input[name="sinpeRejectReason"][value="fondos_no_recibidos"]');
if (firstRadio) firstRadio.checked = true;
window.toggleSinpeRejectInputs();
modal.style.display = 'flex';
};
window.cerrarModalRechazoSinpe = function(event) {
if (event && event.target && event.target !== document.getElementById('modalRechazarSinpe')) {
return;
}
const modal = document.getElementById('modalRechazarSinpe');
if (modal) modal.style.display = 'none';
currentSinpeRejectData = null;
};
window.toggleSinpeRejectInputs = function() {
const selected = document.querySelector('input[name="sinpeRejectReason"]:checked');
const container = document.getElementById('sinpeRejectMontoContainer');
if (!container || !selected) return;
if (selected.value === 'monto_no_coincide') {
container.style.display = 'block';
window.updateSinpeRejectPreview();
const input = document.getElementById('sinpeRejectMontoReal');
if (input) setTimeout(() => input.focus(), 50);
} else {
container.style.display = 'none';
}
};
window.updateSinpeRejectPreview = function() {
const preview = document.getElementById('sinpeRejectMontoPreview');
const inputReal = document.getElementById('sinpeRejectMontoReal');
if (!currentSinpeRejectData || !preview || !inputReal) return;
const solicitado = currentSinpeRejectData.monto_colones || 0;
const real = Number(inputReal.value || 0);
preview.textContent = `Se intentaron recargar ₡${solicitado.toLocaleString('es-CR')} pero el SINPE fue de ₡${real.toLocaleString('es-CR')}`;
};
window.confirmarRechazoSinpeModal = async function() {
if (!currentSinpeRejectData) return;
const selected = document.querySelector('input[name="sinpeRejectReason"]:checked');
const val = selected ? selected.value : 'fondos_no_recibidos';
const notasExtra = (document.getElementById('sinpeRejectNotasExtra')?.value || '').trim();
const solicitado = currentSinpeRejectData.monto_colones || 0;
let motivoFinal = '';
if (val === 'fondos_no_recibidos') {
motivoFinal = 'Fondos no recibidos en cuenta bancaria';
if (notasExtra) motivoFinal += ` (${notasExtra})`;
} else if (val === 'monto_no_coincide') {
const inputReal = document.getElementById('sinpeRejectMontoReal');
const real = Number(inputReal?.value || 0);
if (!inputReal?.value || real <= 0) {
showAppAlert({
title: 'Monto requerido',
message: 'Por favor ingresa de cuánto era el monto que figuró en el SINPE recibido.',
type: 'warning'
});
inputReal?.focus();
return;
}
motivoFinal = `Monto no coincide: Se intentaron recargar ₡${solicitado.toLocaleString('es-CR')} pero el SINPE recibido fue de ₡${real.toLocaleString('es-CR')}`;
if (notasExtra) motivoFinal += ` - ${notasExtra}`;
} else if (val === 'comprobante_invalido') {
motivoFinal = 'Comprobante falso, duplicado o ilegible';
if (notasExtra) motivoFinal += ` (${notasExtra})`;
} else if (val === 'telefono_no_coincide') {
motivoFinal = 'Teléfono o destinatario no coincide con la cuenta de la soda';
if (notasExtra) motivoFinal += ` (${notasExtra})`;
} else if (val === 'otro') {
if (!notasExtra) {
showAppAlert({
title: 'Detalle requerido',
message: 'Por favor escribe el motivo específico del rechazo.',
type: 'warning'
});
document.getElementById('sinpeRejectNotasExtra')?.focus();
return;
}
motivoFinal = notasExtra;
}
const modal = document.getElementById('modalRechazarSinpe');
if (modal) modal.style.display = 'none';
if (typeof currentSinpeRejectData.onConfirm === 'function') {
const fn = currentSinpeRejectData.onConfirm;
currentSinpeRejectData = null;
await fn(motivoFinal);
}
};
})();
+52 -24
View File
@@ -2237,6 +2237,7 @@ async function loadSinpeRequests() {
if (!res.ok) throw new Error(data.error);
const solicitudes = data.solicitudes || [];
window.cachedSinpeRequests = solicitudes;
if (badge) {
if (solicitudes.length > 0) {
@@ -2351,7 +2352,12 @@ async function loadSinpeRequests() {
async function procesarSinpePos(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?');
const ok = await showAppConfirm({
title: 'Aprobar Recarga SINPE',
message: '¿Confirmas que verificaste el comprobante y el dinero ya ingresó a la cuenta bancaria de la soda?',
type: 'question',
confirmText: 'Sí, Aprobar'
});
if (!ok) return;
try {
@@ -2368,35 +2374,57 @@ async function procesarSinpePos(solicitudId, accion) {
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')}.`);
await showAppAlert({
title: '¡Recarga Aprobada!',
message: `Se acreditaron ₡${data.resultado.monto.toLocaleString('es-CR')} al estudiante ${data.resultado.estudiante_nombre}.\nNuevo saldo: ₡${data.resultado.saldo_nuevo.toLocaleString('es-CR')}.`,
type: 'success'
});
loadSinpeRequests();
} catch (err) {
if (window.sounds) window.sounds.playError();
alert(`Error al aprobar recarga: ${err.message}`);
showAppAlert({
title: 'Error al Aprobar',
message: err.message,
type: 'error'
});
}
} else if (accion === 'rechazar') {
const motivo = prompt('Motivo del rechazo de la recarga:', 'Comprobante no coincide o fondos no recibidos');
if (motivo === null) return; // cancelado por usuario
const sol = (window.cachedSinpeRequests || []).find(s => s.id === solicitudId) || {};
abrirModalRechazoSinpe({
id: solicitudId,
estudiante_nombre: sol.estudiante_nombre,
monto_colones: sol.monto_colones,
comprobante: sol.comprobante_sinpe || sol.codigo_detalle,
onConfirm: async (motivo) => {
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: null
})
});
const data = await res.json();
if (!res.ok) throw new Error(data.error);
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: null
})
});
const data = await res.json();
if (!res.ok) throw new Error(data.error);
alert('La solicitud de recarga ha sido rechazada.');
loadSinpeRequests();
} catch (err) {
alert(`Error al rechazar recarga: ${err.message}`);
}
await showAppAlert({
title: 'Recarga Rechazada',
message: 'La solicitud de recarga ha sido rechazada y su motivo ha quedado guardado para trazabilidad.',
type: 'warning'
});
loadSinpeRequests();
} catch (err) {
showAppAlert({
title: 'Error al Rechazar',
message: err.message,
type: 'error'
});
}
}
});
}
}
+94 -2
View File
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SiboPay POS - Terminal de Mostrador y Despacho</title>
<link rel="icon" type="image/png" href="/img/sibopay-emblem.png">
<link rel="stylesheet" href="/css/styles.css?v=13.3">
<link rel="stylesheet" href="/css/styles.css?v=13.4">
<style>
/* Estilos específicos de terminal de alta velocidad */
.student-badge-scanned {
@@ -582,9 +582,101 @@
<!-- CONTENEDOR DE TICKET TÉRMICO OCULTO EN PANTALLA (VISIBLE EN IMPRESIÓN 58mm / 80mm) -->
<div id="posThermalReceipt" style="display: none;"></div>
<!-- MODAL: RECHAZAR RECARGA SINPE CON MOTIVO Y TRAZABILIDAD -->
<div class="modal-qr-backdrop" id="modalRechazarSinpe" style="display: none; z-index: 99999;" onclick="cerrarModalRechazoSinpe(event)">
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: left; padding: 22px; border-radius: 18px;">
<!-- Encabezado -->
<div style="display: flex; align-items: center; justify-content: space-between; border-bottom: 1.5px solid var(--border, #e2e8f0); padding-bottom: 10px; margin-bottom: 14px;">
<div style="display: flex; align-items: center; gap: 8px;">
<span style="font-size: 1.3rem;">🚫</span>
<div>
<h3 style="margin: 0; font-size: 1.05rem; font-weight: 900; color: #991b1b;">Rechazar Recarga SINPE</h3>
<span style="font-size: 0.72rem; color: #64748b;">Trazabilidad detallada para la soda y el padre</span>
</div>
</div>
<button type="button" onclick="cerrarModalRechazoSinpe()" style="background: none; border: none; font-size: 1.3rem; color: #64748b; cursor: pointer; padding: 4px;">✕</button>
</div>
<!-- Resumen de Solicitud -->
<div style="background: rgba(148, 163, 184, 0.08); border: 1px solid #e2e8f0; border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: 0.80rem; line-height: 1.45;">
<div style="display: flex; justify-content: space-between;">
<span style="color: #64748b;">Estudiante:</span>
<strong id="rechazoSinpeEstudiante" style="color: #0f172a;">-</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 3px;">
<span style="color: #64748b;">Monto Solicitado:</span>
<strong id="rechazoSinpeMonto" style="color: #0284c7; font-size: 0.92rem;">₡0</strong>
</div>
<div style="display: flex; justify-content: space-between; margin-top: 3px;">
<span style="color: #64748b;">Comprobante / Cód:</span>
<strong id="rechazoSinpeComprobante" style="color: #334155;">-</strong>
</div>
</div>
<!-- Motivo de Rechazo (Opciones Rápidas) -->
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: #0f172a; margin-bottom: 6px;">
Selecciona el motivo del rechazo:
</label>
<div style="display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px;">
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid #e2e8f0; border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: #334155;">
<input type="radio" name="sinpeRejectReason" value="fondos_no_recibidos" checked onchange="toggleSinpeRejectInputs()">
<span>🚫 Fondos no recibidos en cuenta bancaria</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid #e2e8f0; border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: #334155;">
<input type="radio" name="sinpeRejectReason" value="monto_no_coincide" onchange="toggleSinpeRejectInputs()">
<span>⚠️ Monto no coincide con comprobante</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid #e2e8f0; border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: #334155;">
<input type="radio" name="sinpeRejectReason" value="comprobante_invalido" onchange="toggleSinpeRejectInputs()">
<span>📄 Comprobante falso, duplicado o ilegible</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid #e2e8f0; border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: #334155;">
<input type="radio" name="sinpeRejectReason" value="telefono_no_coincide" onchange="toggleSinpeRejectInputs()">
<span>📱 Teléfono o destinatario no coincide</span>
</label>
<label class="sinpe-reject-option" style="display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1.5px solid #e2e8f0; border-radius: 9px; cursor: pointer; font-size: 0.78rem; font-weight: 700; color: #334155;">
<input type="radio" name="sinpeRejectReason" value="otro" onchange="toggleSinpeRejectInputs()">
<span>✏️ Otro motivo personalizado</span>
</label>
</div>
<!-- Campo de Monto Real cuando el monto no coincide -->
<div id="sinpeRejectMontoContainer" style="display: none; background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: 10px; margin-bottom: 12px;">
<label style="display: block; font-size: 0.75rem; font-weight: 800; color: #92400e; margin-bottom: 4px;">
¿De cuánto era realmente el SINPE recibido? (₡):
</label>
<input type="number" id="sinpeRejectMontoReal" placeholder="Ej: 1000" style="width: 100%; height: 36px; padding: 0 10px; border: 1.5px solid #fcd34d; border-radius: 8px; font-size: 0.88rem; font-weight: 800; color: #92400e; box-sizing: border-box;" oninput="updateSinpeRejectPreview()">
<span id="sinpeRejectMontoPreview" style="display: block; font-size: 0.72rem; color: #b45309; margin-top: 4px; font-weight: 600;">
Se intentaron recargar ₡0 pero el SINPE fue de ₡0
</span>
</div>
<!-- Notas o detalles adicionales -->
<div style="margin-bottom: 16px;">
<label style="display: block; font-size: 0.75rem; font-weight: 700; color: #64748b; margin-bottom: 4px;">
Detalle u observación adicional (opcional):
</label>
<input type="text" id="sinpeRejectNotasExtra" placeholder="Ej: Fondos no figuran en estado bancario al corte" style="width: 100%; height: 36px; padding: 0 10px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 0.80rem; box-sizing: border-box;">
</div>
<!-- Botones de Acción -->
<div style="display: flex; gap: 8px; justify-content: flex-end;">
<button type="button" onclick="cerrarModalRechazoSinpe()" class="btn-saas btn-saas-outline" style="height: 36px; padding: 0 14px; font-weight: 700;">
Cancelar
</button>
<button type="button" id="btnConfirmarRechazoSinpe" onclick="confirmarRechazoSinpeModal()" class="btn-saas" style="height: 36px; padding: 0 16px; background: #dc2626; color: #ffffff; border: 1px solid #dc2626; font-weight: 800;">
Confirmar Rechazo
</button>
</div>
</div>
</div>
<script src="/js/dialogs.js?v=13.4"></script>
<script src="/js/sounds.js?v=8.6"></script>
<script src="/js/jsQR.js"></script>
<script src="/js/food-icons.js?v=1.1"></script>
<script src="/js/pos.js?v=13.3"></script>
<script src="/js/pos.js?v=13.4"></script>
</body>
</html>
+3 -2
View File
@@ -1,5 +1,5 @@
// SiboPay PWA Service Worker v13.3 - Alta Velocidad & Despacho
const CACHE_NAME = 'sibopay-v13.3';
// SiboPay PWA Service Worker v13.4 - Modales en app, Trazabilidad & Reportes Excel
const CACHE_NAME = 'sibopay-v13.4';
const STATIC_ASSETS = [
'/',
'/index.html',
@@ -9,6 +9,7 @@ const STATIC_ASSETS = [
'/manifest.json',
'/css/styles.css',
'/css/desktop.css',
'/js/dialogs.js',
'/js/app.js',
'/js/pos.js',
'/js/sounds.js',