feat(sinpe): trazabilidad de transferencias SINPE rechazadas en movimientos y reversiones
This commit is contained in:
@@ -774,6 +774,9 @@
|
|||||||
<button type="button" class="mov-filter-btn" id="btnFilterMovCobros" onclick="setMovFilter('cobros')" style="padding: 6px 12px; border: none; border-radius: 7px; font-weight: 700; font-size: 0.78rem; cursor: pointer; background: transparent; color: #64748b; white-space: nowrap;">
|
<button type="button" class="mov-filter-btn" id="btnFilterMovCobros" onclick="setMovFilter('cobros')" style="padding: 6px 12px; border: none; border-radius: 7px; font-weight: 700; font-size: 0.78rem; cursor: pointer; background: transparent; color: #64748b; white-space: nowrap;">
|
||||||
Cobros
|
Cobros
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="mov-filter-btn" id="btnFilterMovRechazados" onclick="setMovFilter('rechazados')" style="padding: 6px 12px; border: none; border-radius: 7px; font-weight: 700; font-size: 0.78rem; cursor: pointer; background: transparent; color: #64748b; white-space: nowrap;">
|
||||||
|
Rechazados
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<input type="text" id="inputSearchMovimientos" placeholder="Buscar por alumno, carné o detalle..." oninput="filterMovimientosUI(this.value)" style="flex: 1; min-width: 180px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.85rem; box-sizing: border-box; background: var(--card-bg); color: var(--text-main); outline: none;">
|
<input type="text" id="inputSearchMovimientos" placeholder="Buscar por alumno, carné o detalle..." oninput="filterMovimientosUI(this.value)" style="flex: 1; min-width: 180px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); font-size: 0.85rem; box-sizing: border-box; background: var(--card-bg); color: var(--text-main); outline: none;">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+76
-22
@@ -1406,10 +1406,14 @@ function renderParentHistory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.innerHTML = currentStudent.transacciones.map(t => {
|
container.innerHTML = currentStudent.transacciones.map(t => {
|
||||||
const esPositivo = t.monto_colones > 0;
|
const isSinpeRechazado = t.tipo === 'sinpe_rechazado' || t.tipo === 'recarga_rechazada';
|
||||||
const color = esPositivo ? '#166534' : '#0f172a';
|
const esPositivo = t.monto_colones > 0 && !isSinpeRechazado;
|
||||||
const signo = esPositivo ? '+' : '';
|
const color = isSinpeRechazado ? '#be123c' : (esPositivo ? '#166534' : '#0f172a');
|
||||||
const fecha = new Date(t.fecha).toLocaleDateString('es-CR', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
const signo = isSinpeRechazado ? '' : (esPositivo ? '+' : '');
|
||||||
|
let fecha = t.fecha;
|
||||||
|
try {
|
||||||
|
fecha = new Date(t.fecha).toLocaleDateString('es-CR', { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<div style="display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #f1f5f9;">
|
<div style="display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #f1f5f9;">
|
||||||
@@ -1417,8 +1421,8 @@ function renderParentHistory() {
|
|||||||
<div style="font-weight: 700; color: ${color};">${t.descripcion || t.tipo}</div>
|
<div style="font-weight: 700; color: ${color};">${t.descripcion || t.tipo}</div>
|
||||||
<div style="font-size: 0.7rem; color: #94a3b8;">${fecha}</div>
|
<div style="font-size: 0.7rem; color: #94a3b8;">${fecha}</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="font-weight: 800; color: ${esPositivo ? '#10b981' : '#ef4444'};">
|
<div style="font-weight: 800; color: ${isSinpeRechazado ? '#be123c' : (esPositivo ? '#10b981' : '#ef4444')};">
|
||||||
${signo}₡${Math.abs(t.monto_colones).toLocaleString('es-CR')}
|
${isSinpeRechazado ? '₡' + Math.abs(t.monto_colones).toLocaleString('es-CR') + ' (Rechazado)' : signo + '₡' + Math.abs(t.monto_colones).toLocaleString('es-CR')}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@@ -2337,6 +2341,30 @@ function initStudentSSE() {
|
|||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sse.addEventListener('movimiento_registrado', (e) => {
|
||||||
|
try {
|
||||||
|
if (currentUser && (currentUser.rol === 'admin' || currentUser.rol === 'cajero')) {
|
||||||
|
loadAdminData();
|
||||||
|
const movTab = document.getElementById('adminTabContentMovimientos');
|
||||||
|
if (movTab && movTab.style.display !== 'none') {
|
||||||
|
loadAdminMovimientos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
sse.addEventListener('sinpe_rechazado', (e) => {
|
||||||
|
try {
|
||||||
|
if (currentUser && (currentUser.rol === 'admin' || currentUser.rol === 'cajero')) {
|
||||||
|
loadAdminData();
|
||||||
|
const movTab = document.getElementById('adminTabContentMovimientos');
|
||||||
|
if (movTab && movTab.style.display !== 'none') {
|
||||||
|
loadAdminMovimientos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {}
|
||||||
|
});
|
||||||
|
|
||||||
sse.addEventListener('disenos_actualizados', async () => {
|
sse.addEventListener('disenos_actualizados', async () => {
|
||||||
try {
|
try {
|
||||||
await loadCardDesigns();
|
await loadCardDesigns();
|
||||||
@@ -4970,8 +4998,9 @@ function setMovFilter(filter) {
|
|||||||
const btnAll = document.getElementById('btnFilterMovAll');
|
const btnAll = document.getElementById('btnFilterMovAll');
|
||||||
const btnRecargas = document.getElementById('btnFilterMovRecargas');
|
const btnRecargas = document.getElementById('btnFilterMovRecargas');
|
||||||
const btnCobros = document.getElementById('btnFilterMovCobros');
|
const btnCobros = document.getElementById('btnFilterMovCobros');
|
||||||
|
const btnRechazados = document.getElementById('btnFilterMovRechazados');
|
||||||
|
|
||||||
[btnAll, btnRecargas, btnCobros].forEach(b => {
|
[btnAll, btnRecargas, btnCobros, btnRechazados].forEach(b => {
|
||||||
if (!b) return;
|
if (!b) return;
|
||||||
b.style.background = 'transparent';
|
b.style.background = 'transparent';
|
||||||
b.style.color = '#64748b';
|
b.style.color = '#64748b';
|
||||||
@@ -4979,10 +5008,10 @@ function setMovFilter(filter) {
|
|||||||
b.style.fontWeight = '700';
|
b.style.fontWeight = '700';
|
||||||
});
|
});
|
||||||
|
|
||||||
const activeBtn = filter === 'recargas' ? btnRecargas : (filter === 'cobros' ? btnCobros : btnAll);
|
const activeBtn = filter === 'recargas' ? btnRecargas : (filter === 'cobros' ? btnCobros : (filter === 'rechazados' ? btnRechazados : btnAll));
|
||||||
if (activeBtn) {
|
if (activeBtn) {
|
||||||
activeBtn.style.background = '#ffffff';
|
activeBtn.style.background = '#ffffff';
|
||||||
activeBtn.style.color = '#0284c7';
|
activeBtn.style.color = filter === 'rechazados' ? '#e11d48' : '#0284c7';
|
||||||
activeBtn.style.boxShadow = '0 1px 3px rgba(0,0,0,0.08)';
|
activeBtn.style.boxShadow = '0 1px 3px rgba(0,0,0,0.08)';
|
||||||
activeBtn.style.fontWeight = '800';
|
activeBtn.style.fontWeight = '800';
|
||||||
}
|
}
|
||||||
@@ -5005,9 +5034,11 @@ function renderAdminMovimientos() {
|
|||||||
let filtered = adminMovimientosData.filter(m => {
|
let filtered = adminMovimientosData.filter(m => {
|
||||||
// Filtro por tipo
|
// Filtro por tipo
|
||||||
if (currentMovFilter === 'recargas') {
|
if (currentMovFilter === 'recargas') {
|
||||||
if (m.monto_colones <= 0 || m.tipo === 'compra_mostrador' || m.tipo === 'preorden') return false;
|
if (m.monto_colones <= 0 || m.tipo === 'compra_mostrador' || m.tipo === 'preorden' || m.tipo === 'sinpe_rechazado' || m.tipo === 'recarga_rechazada') return false;
|
||||||
} else if (currentMovFilter === 'cobros') {
|
} else if (currentMovFilter === 'cobros') {
|
||||||
if (m.monto_colones >= 0 && (m.tipo === 'recarga_manual' || m.tipo === 'recarga_sinpe')) return false;
|
if (m.monto_colones >= 0 && (m.tipo === 'recarga_manual' || m.tipo === 'recarga_sinpe' || m.tipo === 'sinpe_rechazado' || m.tipo === 'recarga_rechazada')) return false;
|
||||||
|
} else if (currentMovFilter === 'rechazados') {
|
||||||
|
if (m.tipo !== 'sinpe_rechazado' && m.tipo !== 'recarga_rechazada') return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filtro por texto de búsqueda
|
// Filtro por texto de búsqueda
|
||||||
@@ -5036,7 +5067,8 @@ function renderAdminMovimientos() {
|
|||||||
const isCajero = currentUser && currentUser.rol === 'cajero';
|
const isCajero = currentUser && currentUser.rol === 'cajero';
|
||||||
|
|
||||||
container.innerHTML = filtered.map(m => {
|
container.innerHTML = filtered.map(m => {
|
||||||
const isPositive = m.monto_colones > 0;
|
const isSinpeRechazado = m.tipo === 'sinpe_rechazado' || m.tipo === 'recarga_rechazada';
|
||||||
|
const isPositive = m.monto_colones > 0 && !isSinpeRechazado;
|
||||||
const isRevertida = m.revertida === 1;
|
const isRevertida = m.revertida === 1;
|
||||||
const isReversionOrRefund = m.tipo === 'reversion_recarga' || m.tipo === 'reembolso';
|
const isReversionOrRefund = m.tipo === 'reversion_recarga' || m.tipo === 'reembolso';
|
||||||
|
|
||||||
@@ -5046,6 +5078,8 @@ function renderAdminMovimientos() {
|
|||||||
tipoBadge = `<span style="background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; font-size: 0.7rem; font-weight: 800; padding: 3px 8px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="6" width="20" height="12" rx="2"/><circle cx="12" cy="12" r="2"/></svg> Recarga Efectivo</span>`;
|
tipoBadge = `<span style="background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; font-size: 0.7rem; font-weight: 800; padding: 3px 8px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="6" width="20" height="12" rx="2"/><circle cx="12" cy="12" r="2"/></svg> Recarga Efectivo</span>`;
|
||||||
} else if (m.tipo === 'recarga_sinpe') {
|
} else if (m.tipo === 'recarga_sinpe') {
|
||||||
tipoBadge = `<span style="background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; font-size: 0.7rem; font-weight: 800; padding: 3px 8px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="5" y="2" width="14" height="20" rx="2" ry="2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg> Recarga SINPE</span>`;
|
tipoBadge = `<span style="background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; font-size: 0.7rem; font-weight: 800; padding: 3px 8px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="5" y="2" width="14" height="20" rx="2" ry="2"/><line x1="12" y1="18" x2="12.01" y2="18"/></svg> Recarga SINPE</span>`;
|
||||||
|
} else if (isSinpeRechazado) {
|
||||||
|
tipoBadge = `<span style="background: #fff1f2; color: #be123c; border: 1.5px solid #fecdd3; font-size: 0.7rem; font-weight: 900; padding: 3px 8px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg> SINPE Rechazado</span>`;
|
||||||
} else if (m.tipo === 'compra_mostrador' || m.tipo === 'preorden') {
|
} else if (m.tipo === 'compra_mostrador' || m.tipo === 'preorden') {
|
||||||
tipoBadge = `<span style="background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; font-size: 0.7rem; font-weight: 800; padding: 3px 8px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/></svg> Cobro Soda</span>`;
|
tipoBadge = `<span style="background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; font-size: 0.7rem; font-weight: 800; padding: 3px 8px; border-radius: 6px; display: inline-flex; align-items: center; gap: 4px;"><svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/></svg> Cobro Soda</span>`;
|
||||||
} else if (m.tipo === 'reversion_recarga') {
|
} else if (m.tipo === 'reversion_recarga') {
|
||||||
@@ -5063,15 +5097,29 @@ function renderAdminMovimientos() {
|
|||||||
fechaHoraStr = d.toLocaleTimeString('es-CR', { hour: '2-digit', minute: '2-digit' }) + ' • ' + d.toLocaleDateString('es-CR', { day: '2-digit', month: 'short' });
|
fechaHoraStr = d.toLocaleTimeString('es-CR', { hour: '2-digit', minute: '2-digit' }) + ' • ' + d.toLocaleDateString('es-CR', { day: '2-digit', month: 'short' });
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
// Monto formateado: Estilo sutil idéntico a "Revertir" / "Revertido" (rojo suave) y verde suave
|
// Monto formateado
|
||||||
const absMonto = Math.abs(m.monto_colones);
|
const absMonto = Math.abs(m.monto_colones);
|
||||||
const montoDisplay = isPositive ? `+₡${absMonto.toLocaleString('es-CR')}` : `-₡${absMonto.toLocaleString('es-CR')}`;
|
let montoDisplay = '';
|
||||||
const montoColor = isPositive ? '#166534' : '#991b1b';
|
let montoColor = '';
|
||||||
const montoBg = isPositive ? '#f0fdf4' : '#fef2f2';
|
let montoBg = '';
|
||||||
const montoBorder = isPositive ? '#bbf7d0' : '#fecaca';
|
let montoBorder = '';
|
||||||
const montoIcon = isPositive
|
let montoIcon = '';
|
||||||
? '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="5 12 12 5 19 12"/></svg>'
|
|
||||||
: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="19 12 12 19 5 12"/></svg>';
|
if (isSinpeRechazado) {
|
||||||
|
montoDisplay = `₡${absMonto.toLocaleString('es-CR')} (Rechazado)`;
|
||||||
|
montoColor = '#be123c';
|
||||||
|
montoBg = '#fff1f2';
|
||||||
|
montoBorder = '#fecdd3';
|
||||||
|
montoIcon = '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>';
|
||||||
|
} else {
|
||||||
|
montoDisplay = isPositive ? `+₡${absMonto.toLocaleString('es-CR')}` : `-₡${absMonto.toLocaleString('es-CR')}`;
|
||||||
|
montoColor = isPositive ? '#166534' : '#991b1b';
|
||||||
|
montoBg = isPositive ? '#f0fdf4' : '#fef2f2';
|
||||||
|
montoBorder = isPositive ? '#bbf7d0' : '#fecaca';
|
||||||
|
montoIcon = isPositive
|
||||||
|
? '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="5 12 12 5 19 12"/></svg>'
|
||||||
|
: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><polyline points="19 12 12 19 5 12"/></svg>';
|
||||||
|
}
|
||||||
|
|
||||||
// Regla de 10 min para Cajero
|
// Regla de 10 min para Cajero
|
||||||
const minutos = parseFloat(m.minutos_transcurridos) || 0;
|
const minutos = parseFloat(m.minutos_transcurridos) || 0;
|
||||||
@@ -5088,6 +5136,12 @@ function renderAdminMovimientos() {
|
|||||||
${m.revertido_por_nombre ? `<span style="font-size: 0.68rem; color: var(--text-muted); font-weight: 700;">(${m.revertido_por_nombre})</span>` : ''}
|
${m.revertido_por_nombre ? `<span style="font-size: 0.68rem; color: var(--text-muted); font-weight: 700;">(${m.revertido_por_nombre})</span>` : ''}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
} else if (isSinpeRechazado) {
|
||||||
|
actionHtml = `
|
||||||
|
<span style="display: inline-flex; align-items: center; gap: 4px; background: #fff1f2; color: #be123c; border: 1px solid #fecdd3; padding: 4px 10px; border-radius: 7px; font-size: 0.72rem; font-weight: 800;">
|
||||||
|
<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg> Denegado
|
||||||
|
</span>
|
||||||
|
`;
|
||||||
} else if (isReversionOrRefund) {
|
} else if (isReversionOrRefund) {
|
||||||
actionHtml = `
|
actionHtml = `
|
||||||
<span style="display: inline-flex; align-items: center; background: rgba(100, 116, 139, 0.12); color: var(--text-muted); padding: 4px 10px; border-radius: 7px; font-size: 0.72rem; font-weight: 800;">
|
<span style="display: inline-flex; align-items: center; background: rgba(100, 116, 139, 0.12); color: var(--text-muted); padding: 4px 10px; border-radius: 7px; font-size: 0.72rem; font-weight: 800;">
|
||||||
@@ -5128,7 +5182,7 @@ function renderAdminMovimientos() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<div class="admin-mov-card" style="background: ${isRevertida ? 'rgba(254, 242, 242, 0.45)' : 'var(--card-bg)'}; border: 1.5px solid ${isRevertida ? '#fecaca' : 'var(--border)'}; border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; opacity: ${isRevertida ? '0.85' : '1'}; transition: all 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.03);">
|
<div class="admin-mov-card" style="background: ${isRevertida ? 'rgba(254, 242, 242, 0.45)' : (isSinpeRechazado ? 'rgba(255, 241, 242, 0.35)' : 'var(--card-bg)')}; border: 1.5px solid ${isRevertida ? '#fecaca' : (isSinpeRechazado ? '#fecdd3' : 'var(--border)')}; border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; opacity: ${isRevertida ? '0.85' : '1'}; transition: all 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.03);">
|
||||||
|
|
||||||
<!-- FILA SUPERIOR: BADGE Y FECHA -->
|
<!-- FILA SUPERIOR: BADGE Y FECHA -->
|
||||||
<div style="display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 8px; flex-wrap: wrap;">
|
<div style="display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 8px; flex-wrap: wrap;">
|
||||||
@@ -5171,7 +5225,7 @@ function renderAdminMovimientos() {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<span style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700;">
|
<span style="font-size: 0.74rem; color: var(--text-muted); font-weight: 700;">
|
||||||
Saldo posterior: <strong style="color: var(--text-main); font-weight: 800;">₡${(m.saldo_posterior || 0).toLocaleString('es-CR')}</strong>
|
${isSinpeRechazado ? 'Saldo sin cambios:' : 'Saldo posterior:'} <strong style="color: var(--text-main); font-weight: 800;">₡${(m.saldo_posterior || 0).toLocaleString('es-CR')}</strong>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div style="flex-shrink: 0;">
|
<div style="flex-shrink: 0;">
|
||||||
|
|||||||
+77
-4
@@ -183,8 +183,15 @@ function initDatabase() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error creando push_subscriptions en PostgreSQL:', e);
|
console.error('Error creando push_subscriptions en PostgreSQL:', e);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
db.exec('ALTER TABLE transacciones_saldo ADD COLUMN IF NOT EXISTS revertida INTEGER DEFAULT 0;');
|
||||||
|
db.exec('ALTER TABLE transacciones_saldo ADD COLUMN IF NOT EXISTS revertido_por_usuario_id INTEGER REFERENCES usuarios(id);');
|
||||||
|
db.exec('ALTER TABLE transacciones_saldo ADD COLUMN IF NOT EXISTS revertido_en TIMESTAMP;');
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
seedUsuarios();
|
seedUsuarios();
|
||||||
seedDisenosTarjetas();
|
seedDisenosTarjetas();
|
||||||
|
migrarTrazabilidadSinpeRechazadas();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,11 +414,54 @@ function initDatabase() {
|
|||||||
`);
|
`);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
|
migrarTrazabilidadSinpeRechazadas();
|
||||||
seedInitialData();
|
seedInitialData();
|
||||||
seedUsuarios();
|
seedUsuarios();
|
||||||
seedDisenosTarjetas();
|
seedDisenosTarjetas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function migrarTrazabilidadSinpeRechazadas() {
|
||||||
|
try {
|
||||||
|
const rechazadasSinMov = db.prepare(`
|
||||||
|
SELECT s.*, e.saldo_colones as saldo_actual
|
||||||
|
FROM solicitudes_recarga_sinpe s
|
||||||
|
JOIN estudiantes e ON s.estudiante_id = e.id
|
||||||
|
WHERE s.estado = 'rechazada'
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM transacciones_saldo t
|
||||||
|
WHERE t.tipo = 'sinpe_rechazado'
|
||||||
|
AND t.estudiante_id = s.estudiante_id
|
||||||
|
AND (t.comprobante_sinpe = s.comprobante_sinpe OR (s.codigo_detalle IS NOT NULL AND t.comprobante_sinpe = s.codigo_detalle))
|
||||||
|
)
|
||||||
|
`).all();
|
||||||
|
|
||||||
|
if (rechazadasSinMov && rechazadasSinMov.length > 0) {
|
||||||
|
console.log(`[Trazabilidad SINPE] Sincronizando ${rechazadasSinMov.length} solicitudes rechazadas previas en transacciones_saldo...`);
|
||||||
|
for (const r of rechazadasSinMov) {
|
||||||
|
const motivoRechazo = r.notas || 'Comprobante no verificado en cuenta';
|
||||||
|
const comp = r.comprobante_sinpe || r.codigo_detalle || 'N/A';
|
||||||
|
const fechaTx = r.procesado_en || r.creado_en || new Date().toISOString();
|
||||||
|
db.prepare(`
|
||||||
|
INSERT INTO transacciones_saldo
|
||||||
|
(estudiante_id, tipo, monto_colones, saldo_previo, saldo_posterior, comprobante_sinpe, descripcion, fecha)
|
||||||
|
VALUES (?, 'sinpe_rechazado', ?, ?, ?, ?, ?, ?)
|
||||||
|
`).run(
|
||||||
|
r.estudiante_id,
|
||||||
|
r.monto_colones,
|
||||||
|
r.saldo_actual || 0,
|
||||||
|
r.saldo_actual || 0,
|
||||||
|
r.comprobante_sinpe || r.codigo_detalle || 'SINPE-RECHAZADO',
|
||||||
|
`SINPE Rechazado: ${motivoRechazo} (Comprobante #${comp})`,
|
||||||
|
fechaTx
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log('[Trazabilidad SINPE] Sincronización retroactiva completada con éxito.');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Migración trazabilidad sinpe rechazadas:', e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function seedUsuarios() {
|
function seedUsuarios() {
|
||||||
const res = db.prepare('SELECT COUNT(*) as count FROM usuarios').get();
|
const res = db.prepare('SELECT COUNT(*) as count FROM usuarios').get();
|
||||||
const count = res ? Number(res.count) : 0;
|
const count = res ? Number(res.count) : 0;
|
||||||
@@ -1016,8 +1066,8 @@ function revertirTransaccionSaldoTransaction({ transaccionId, usuarioId, usuario
|
|||||||
throw new Error('Esta transacción ya fue revertida previamente');
|
throw new Error('Esta transacción ya fue revertida previamente');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx.tipo === 'reversion_recarga' || tx.tipo === 'reembolso') {
|
if (tx.tipo === 'reversion_recarga' || tx.tipo === 'reembolso' || tx.tipo === 'sinpe_rechazado') {
|
||||||
throw new Error('No es posible revertir una transacción que ya corresponde a una reversión o reembolso');
|
throw new Error('No es posible revertir una transacción que fue rechazada o que ya corresponde a una reversión o reembolso');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Control de tiempo según el rol (Cajero: <= 10 min, Admin: ilimitado)
|
// 2. Control de tiempo según el rol (Cajero: <= 10 min, Admin: ilimitado)
|
||||||
@@ -1346,17 +1396,40 @@ function procesarSolicitudRecargaSinpe({ solicitudId, accion, usuarioId, motivo
|
|||||||
estudiante_nombre: resultadoSaldo.nombre
|
estudiante_nombre: resultadoSaldo.nombre
|
||||||
};
|
};
|
||||||
} else if (accion === 'rechazar') {
|
} else if (accion === 'rechazar') {
|
||||||
|
const est = db.prepare('SELECT * FROM estudiantes WHERE id = ?').get(sol.estudiante_id);
|
||||||
|
const saldoActual = est ? est.saldo_colones : 0;
|
||||||
|
const motivoRechazo = motivo || 'Comprobante no verificado en cuenta';
|
||||||
|
|
||||||
db.prepare(`
|
db.prepare(`
|
||||||
UPDATE solicitudes_recarga_sinpe
|
UPDATE solicitudes_recarga_sinpe
|
||||||
SET estado = 'rechazada', aprobado_por_usuario_id = ?, procesado_en = CURRENT_TIMESTAMP, notas = ?
|
SET estado = 'rechazada', aprobado_por_usuario_id = ?, procesado_en = CURRENT_TIMESTAMP, notas = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
`).run(usuarioId || null, motivo || 'Comprobante no verificado en cuenta', solicitudId);
|
`).run(usuarioId || null, motivoRechazo, solicitudId);
|
||||||
|
|
||||||
|
// Registrar en transacciones_saldo para trazabilidad en Movimientos y Reversiones
|
||||||
|
const compLabel = sol.comprobante_sinpe || (sol.codigo_detalle ? `Cód: ${sol.codigo_detalle}` : 'N/A');
|
||||||
|
const descTrazabilidad = `SINPE Rechazado: ${motivoRechazo} (Comprobante #${compLabel})`;
|
||||||
|
|
||||||
|
db.prepare(`
|
||||||
|
INSERT INTO transacciones_saldo
|
||||||
|
(estudiante_id, tipo, monto_colones, saldo_previo, saldo_posterior, comprobante_sinpe, descripcion)
|
||||||
|
VALUES (?, 'sinpe_rechazado', ?, ?, ?, ?, ?)
|
||||||
|
`).run(
|
||||||
|
sol.estudiante_id,
|
||||||
|
sol.monto_colones,
|
||||||
|
saldoActual,
|
||||||
|
saldoActual,
|
||||||
|
sol.comprobante_sinpe || (sol.codigo_detalle ? `Cód: ${sol.codigo_detalle}` : 'SINPE-RECHAZADO'),
|
||||||
|
descTrazabilidad
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
solicitud_id: solicitudId,
|
solicitud_id: solicitudId,
|
||||||
estado: 'rechazada',
|
estado: 'rechazada',
|
||||||
estudiante_id: sol.estudiante_id,
|
estudiante_id: sol.estudiante_id,
|
||||||
monto: sol.monto_colones
|
monto: sol.monto_colones,
|
||||||
|
estudiante_nombre: est ? est.nombre_completo : 'Estudiante',
|
||||||
|
motivo: motivoRechazo
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Acción no válida (usar aprobar o rechazar)');
|
throw new Error('Acción no válida (usar aprobar o rechazar)');
|
||||||
|
|||||||
@@ -2094,8 +2094,11 @@ app.post('/api/sinpe/procesar', (req, res) => {
|
|||||||
broadcastEvent('recarga_exitosa', resultado);
|
broadcastEvent('recarga_exitosa', resultado);
|
||||||
broadcastEvent('estudiante_actualizado', { id: resultado.estudiante_id, saldo_colones: resultado.saldo_nuevo });
|
broadcastEvent('estudiante_actualizado', { id: resultado.estudiante_id, saldo_colones: resultado.saldo_nuevo });
|
||||||
broadcastEvent('saldo_actualizado', { id: resultado.estudiante_id, saldo_colones: resultado.saldo_nuevo });
|
broadcastEvent('saldo_actualizado', { id: resultado.estudiante_id, saldo_colones: resultado.saldo_nuevo });
|
||||||
|
} else if (resultado.estado === 'rechazada') {
|
||||||
|
broadcastEvent('sinpe_rechazado', resultado);
|
||||||
}
|
}
|
||||||
broadcastEvent('solicitud_sinpe_procesada', resultado);
|
broadcastEvent('solicitud_sinpe_procesada', resultado);
|
||||||
|
broadcastEvent('movimiento_registrado', resultado);
|
||||||
|
|
||||||
res.json({ success: true, resultado });
|
res.json({ success: true, resultado });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user