feat(admin): agregar historial de movimientos y reversion de cargos y recargas con regla de 10 min para cajero
This commit is contained in:
+50
-3
@@ -10,7 +10,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="RecreoPay">
|
<meta name="apple-mobile-web-app-title" content="RecreoPay">
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
<link rel="stylesheet" href="/css/styles.css?v=8.6">
|
<link rel="stylesheet" href="/css/styles.css?v=8.7">
|
||||||
<style>
|
<style>
|
||||||
/* Transiciones suaves */
|
/* Transiciones suaves */
|
||||||
.fade-enter { animation: fadeIn 0.2s ease-in-out; }
|
.fade-enter { animation: fadeIn 0.2s ease-in-out; }
|
||||||
@@ -94,6 +94,10 @@
|
|||||||
<span style="font-size: 1.3rem;">👨🍳</span>
|
<span style="font-size: 1.3rem;">👨🍳</span>
|
||||||
<span>Admin Soda</span>
|
<span>Admin Soda</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="login-demo-btn" onclick="quickFillLogin('cajero', 'cajero123')">
|
||||||
|
<span style="font-size: 1.3rem;">🪙</span>
|
||||||
|
<span>Cajero</span>
|
||||||
|
</button>
|
||||||
<button type="button" class="login-demo-btn" onclick="quickFillLogin('padre', 'padre123')">
|
<button type="button" class="login-demo-btn" onclick="quickFillLogin('padre', 'padre123')">
|
||||||
<span style="font-size: 1.3rem;">👨👩👦</span>
|
<span style="font-size: 1.3rem;">👨👩👦</span>
|
||||||
<span>Padre</span>
|
<span>Padre</span>
|
||||||
@@ -175,6 +179,9 @@
|
|||||||
<button class="admin-tab-btn" id="btnTabAdminRecarga" onclick="switchAdminTab('recarga')">
|
<button class="admin-tab-btn" id="btnTabAdminRecarga" onclick="switchAdminTab('recarga')">
|
||||||
💵 Cargar Dinero Manual (Buscador y QR)
|
💵 Cargar Dinero Manual (Buscador y QR)
|
||||||
</button>
|
</button>
|
||||||
|
<button class="admin-tab-btn" id="btnTabAdminMovimientos" onclick="switchAdminTab('movimientos')">
|
||||||
|
📜 Movimientos y Reversiones
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- TAB 1: INVENTARIO Y STOCK -->
|
<!-- TAB 1: INVENTARIO Y STOCK -->
|
||||||
@@ -315,6 +322,46 @@
|
|||||||
<span>💰</span> Aplicar Recarga Inmediata
|
<span>💰</span> Aplicar Recarga Inmediata
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- TAB 4: MOVIMIENTOS Y REVERSIONES -->
|
||||||
|
<div id="adminTabContentMovimientos" class="admin-card" style="display: none; max-width: 900px; margin: 0 auto;">
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px;">
|
||||||
|
<div>
|
||||||
|
<h3 style="margin: 0; font-size: 1.2rem; font-weight: 900; color: var(--text-main); display: flex; align-items: center; gap: 8px;">
|
||||||
|
<span>📜</span> Movimientos y Reversiones
|
||||||
|
</h3>
|
||||||
|
<p style="margin: 3px 0 0 0; font-size: 0.78rem; color: var(--text-muted);">
|
||||||
|
Historial de recargas de monedero y cobros de meriendas. Permite anular o revertir transacciones erróneas.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<button type="button" onclick="loadAdminMovimientos()" style="padding: 8px 14px; background: #f1f5f9; color: #475569; border: 1.5px solid var(--border); border-radius: 10px; font-weight: 800; font-size: 0.8rem; cursor: pointer; display: flex; align-items: center; gap: 6px;">
|
||||||
|
<span>🔄</span> Actualizar
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- BARRA DE FILTROS Y BÚSQUEDA -->
|
||||||
|
<div style="display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; justify-content: space-between;">
|
||||||
|
<div style="display: flex; gap: 6px; background: #f1f5f9; padding: 4px; border-radius: 10px;">
|
||||||
|
<button type="button" class="mov-filter-btn active" id="btnFilterMovAll" onclick="setMovFilter('all')" style="padding: 7px 14px; border: none; border-radius: 8px; font-weight: 800; font-size: 0.78rem; cursor: pointer; background: white; color: #0284c7; box-shadow: 0 1px 3px rgba(0,0,0,0.08);">
|
||||||
|
Todos
|
||||||
|
</button>
|
||||||
|
<button type="button" class="mov-filter-btn" id="btnFilterMovRecargas" onclick="setMovFilter('recargas')" style="padding: 7px 14px; border: none; border-radius: 8px; font-weight: 700; font-size: 0.78rem; cursor: pointer; background: transparent; color: #64748b;">
|
||||||
|
💵 Recargas
|
||||||
|
</button>
|
||||||
|
<button type="button" class="mov-filter-btn" id="btnFilterMovCobros" onclick="setMovFilter('cobros')" style="padding: 7px 14px; border: none; border-radius: 8px; font-weight: 700; font-size: 0.78rem; cursor: pointer; background: transparent; color: #64748b;">
|
||||||
|
🥪 Cobros Mostrador
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<input type="text" id="inputSearchMovimientos" placeholder="🔍 Buscar por alumno, carné o detalle..." oninput="filterMovimientosUI(this.value)" style="flex: 1; min-width: 220px; max-width: 350px; padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--border); font-size: 0.85rem; box-sizing: border-box; background: var(--card-bg); color: var(--text-main);">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- LISTA DE MOVIMIENTOS -->
|
||||||
|
<div id="adminMovimientosList" style="display: flex; flex-direction: column; gap: 10px;">
|
||||||
|
<div style="text-align: center; color: var(--text-muted); padding: 30px; font-size: 0.88rem;">
|
||||||
|
Cargando movimientos...
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ========================================== -->
|
<!-- ========================================== -->
|
||||||
@@ -1164,8 +1211,8 @@
|
|||||||
</button>
|
</button>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<script src="/js/sounds.js?v=8.6"></script>
|
<script src="/js/sounds.js?v=8.7"></script>
|
||||||
<script src="/js/jsQR.js"></script>
|
<script src="/js/jsQR.js"></script>
|
||||||
<script src="/js/app.js?v=8.6"></script>
|
<script src="/js/app.js?v=8.7"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+284
-6
@@ -244,13 +244,16 @@ async function applyUserRoleSession() {
|
|||||||
|
|
||||||
if (viewLogin) viewLogin.style.display = 'none';
|
if (viewLogin) viewLogin.style.display = 'none';
|
||||||
|
|
||||||
if (currentUser.rol === 'admin') {
|
if (currentUser.rol === 'admin' || currentUser.rol === 'cajero') {
|
||||||
if (viewAdmin) viewAdmin.style.display = 'block';
|
if (viewAdmin) viewAdmin.style.display = 'block';
|
||||||
if (viewPadres) viewPadres.style.display = 'none';
|
if (viewPadres) viewPadres.style.display = 'none';
|
||||||
if (appContainer) appContainer.style.display = 'none';
|
if (appContainer) appContainer.style.display = 'none';
|
||||||
if (bottomNav) bottomNav.style.display = 'none';
|
if (bottomNav) bottomNav.style.display = 'none';
|
||||||
const adminNameEl = document.getElementById('adminLoggedName');
|
const adminNameEl = document.getElementById('adminLoggedName');
|
||||||
if (adminNameEl) adminNameEl.textContent = `${currentUser.nombre} (Administrador)`;
|
if (adminNameEl) {
|
||||||
|
const badgeRol = currentUser.rol === 'cajero' ? 'Cajero Soda' : 'Administrador';
|
||||||
|
adminNameEl.textContent = `${currentUser.nombre} (${badgeRol})`;
|
||||||
|
}
|
||||||
await loadAdminData();
|
await loadAdminData();
|
||||||
setupAdminSmartSearch();
|
setupAdminSmartSearch();
|
||||||
} else if (currentUser.rol === 'padre') {
|
} else if (currentUser.rol === 'padre') {
|
||||||
@@ -1510,8 +1513,12 @@ function initStudentSSE() {
|
|||||||
if (currentUser && currentUser.rol === 'padre') {
|
if (currentUser && currentUser.rol === 'padre') {
|
||||||
loadParentDashboard();
|
loadParentDashboard();
|
||||||
}
|
}
|
||||||
if (currentUser && currentUser.rol === 'admin') {
|
if (currentUser && (currentUser.rol === 'admin' || currentUser.rol === 'cajero')) {
|
||||||
loadAdminData();
|
loadAdminData();
|
||||||
|
const movTab = document.getElementById('adminTabContentMovimientos');
|
||||||
|
if (movTab && movTab.style.display !== 'none') {
|
||||||
|
loadAdminMovimientos();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
});
|
});
|
||||||
@@ -1526,7 +1533,7 @@ function initStudentSSE() {
|
|||||||
renderProducts();
|
renderProducts();
|
||||||
}
|
}
|
||||||
// Actualizar en admin
|
// Actualizar en admin
|
||||||
if (currentUser && currentUser.rol === 'admin') {
|
if (currentUser && (currentUser.rol === 'admin' || currentUser.rol === 'cajero')) {
|
||||||
const adminIdx = adminProducts.findIndex(p => p.id === prod.id);
|
const adminIdx = adminProducts.findIndex(p => p.id === prod.id);
|
||||||
if (adminIdx !== -1) {
|
if (adminIdx !== -1) {
|
||||||
adminProducts[adminIdx] = { ...adminProducts[adminIdx], ...prod };
|
adminProducts[adminIdx] = { ...adminProducts[adminIdx], ...prod };
|
||||||
@@ -1552,8 +1559,24 @@ function initStudentSSE() {
|
|||||||
if (currentUser && currentUser.rol === 'padre') {
|
if (currentUser && currentUser.rol === 'padre') {
|
||||||
loadParentDashboard();
|
loadParentDashboard();
|
||||||
}
|
}
|
||||||
if (currentUser && currentUser.rol === 'admin') {
|
if (currentUser && (currentUser.rol === 'admin' || currentUser.rol === 'cajero')) {
|
||||||
loadAdminData();
|
loadAdminData();
|
||||||
|
const movTab = document.getElementById('adminTabContentMovimientos');
|
||||||
|
if (movTab && movTab.style.display !== 'none') {
|
||||||
|
loadAdminMovimientos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
sse.addEventListener('movimiento_revertido', (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) {}
|
} catch (err) {}
|
||||||
});
|
});
|
||||||
@@ -2193,7 +2216,7 @@ async function confirmLinkValidatedChild() {
|
|||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
function switchAdminTab(tabName) {
|
function switchAdminTab(tabName) {
|
||||||
const tabs = ['inventario', 'estudiantes', 'recarga'];
|
const tabs = ['inventario', 'estudiantes', 'recarga', 'movimientos'];
|
||||||
tabs.forEach(t => {
|
tabs.forEach(t => {
|
||||||
const btn = document.getElementById(`btnTabAdmin${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
const btn = document.getElementById(`btnTabAdmin${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
||||||
const content = document.getElementById(`adminTabContent${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
const content = document.getElementById(`adminTabContent${t.charAt(0).toUpperCase() + t.slice(1)}`);
|
||||||
@@ -2201,6 +2224,10 @@ function switchAdminTab(tabName) {
|
|||||||
if (content) content.style.display = (t === tabName) ? 'block' : 'none';
|
if (content) content.style.display = (t === tabName) ? 'block' : 'none';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (tabName === 'movimientos') {
|
||||||
|
loadAdminMovimientos();
|
||||||
|
}
|
||||||
|
|
||||||
if (window.sounds) window.sounds.playTap();
|
if (window.sounds) window.sounds.playTap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2868,3 +2895,254 @@ async function submitAdminManualRecharge() {
|
|||||||
btn.innerHTML = '<span>💰</span> Aplicar Recarga Inmediata';
|
btn.innerHTML = '<span>💰</span> Aplicar Recarga Inmediata';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// HISTORIAL DE MOVIMIENTOS Y REVERSIONES (ADMIN / CAJERO)
|
||||||
|
// ==========================================
|
||||||
|
|
||||||
|
let adminMovimientosData = [];
|
||||||
|
let currentMovFilter = 'all';
|
||||||
|
|
||||||
|
async function loadAdminMovimientos() {
|
||||||
|
const container = document.getElementById('adminMovimientosList');
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
container.innerHTML = `
|
||||||
|
<div style="text-align: center; color: var(--text-muted); padding: 30px; font-size: 0.88rem;">
|
||||||
|
⏳ Cargando movimientos recientes...
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
const res = await fetch('/api/admin/movimientos?limit=100');
|
||||||
|
if (!res.ok) throw new Error('Error al cargar movimientos desde el servidor');
|
||||||
|
adminMovimientosData = await res.json();
|
||||||
|
renderAdminMovimientos();
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error cargando movimientos:', err);
|
||||||
|
container.innerHTML = `<div style="text-align: center; color: #ef4444; padding: 25px; font-weight: 700;">⚠️ Error al cargar el historial: ${err.message}</div>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setMovFilter(filter) {
|
||||||
|
currentMovFilter = filter;
|
||||||
|
const btnAll = document.getElementById('btnFilterMovAll');
|
||||||
|
const btnRecargas = document.getElementById('btnFilterMovRecargas');
|
||||||
|
const btnCobros = document.getElementById('btnFilterMovCobros');
|
||||||
|
|
||||||
|
[btnAll, btnRecargas, btnCobros].forEach(b => {
|
||||||
|
if (!b) return;
|
||||||
|
b.style.background = 'transparent';
|
||||||
|
b.style.color = '#64748b';
|
||||||
|
b.style.boxShadow = 'none';
|
||||||
|
b.style.fontWeight = '700';
|
||||||
|
});
|
||||||
|
|
||||||
|
const activeBtn = filter === 'recargas' ? btnRecargas : (filter === 'cobros' ? btnCobros : btnAll);
|
||||||
|
if (activeBtn) {
|
||||||
|
activeBtn.style.background = '#ffffff';
|
||||||
|
activeBtn.style.color = '#0284c7';
|
||||||
|
activeBtn.style.boxShadow = '0 1px 3px rgba(0,0,0,0.08)';
|
||||||
|
activeBtn.style.fontWeight = '800';
|
||||||
|
}
|
||||||
|
|
||||||
|
renderAdminMovimientos();
|
||||||
|
if (window.sounds) window.sounds.playTap();
|
||||||
|
}
|
||||||
|
|
||||||
|
function filterMovimientosUI() {
|
||||||
|
renderAdminMovimientos();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderAdminMovimientos() {
|
||||||
|
const container = document.getElementById('adminMovimientosList');
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
const searchInput = document.getElementById('inputSearchMovimientos');
|
||||||
|
const search = searchInput ? searchInput.value.toLowerCase().trim() : '';
|
||||||
|
|
||||||
|
let filtered = adminMovimientosData.filter(m => {
|
||||||
|
// Filtro por tipo
|
||||||
|
if (currentMovFilter === 'recargas') {
|
||||||
|
if (m.monto_colones <= 0 || m.tipo === 'compra_mostrador' || m.tipo === 'preorden') return false;
|
||||||
|
} else if (currentMovFilter === 'cobros') {
|
||||||
|
if (m.monto_colones >= 0 && (m.tipo === 'recarga_manual' || m.tipo === 'recarga_sinpe')) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filtro por texto de búsqueda
|
||||||
|
if (search) {
|
||||||
|
const matchName = (m.estudiante_nombre || '').toLowerCase().includes(search);
|
||||||
|
const matchCode = (m.codigo_estudiante || '').toLowerCase().includes(search);
|
||||||
|
const matchDesc = (m.descripcion || '').toLowerCase().includes(search);
|
||||||
|
const matchTicket = (m.codigo_orden || '').toLowerCase().includes(search);
|
||||||
|
if (!matchName && !matchCode && !matchDesc && !matchTicket) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (filtered.length === 0) {
|
||||||
|
container.innerHTML = `
|
||||||
|
<div style="text-align: center; color: var(--text-muted); padding: 35px 20px; background: #f8fafc; border-radius: 14px; border: 1.5px dashed var(--border);">
|
||||||
|
<span style="font-size: 2.2rem;">🔍</span>
|
||||||
|
<p style="margin: 8px 0 2px 0; font-weight: 800; font-size: 0.95rem; color: var(--text-main);">No se encontraron movimientos</p>
|
||||||
|
<span style="font-size: 0.78rem; color: var(--text-muted);">No hay registros que coincidan con el filtro o búsqueda actual.</span>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isCajero = currentUser && currentUser.rol === 'cajero';
|
||||||
|
|
||||||
|
container.innerHTML = filtered.map(m => {
|
||||||
|
const isPositive = m.monto_colones > 0;
|
||||||
|
const isRevertida = m.revertida === 1;
|
||||||
|
const isReversionOrRefund = m.tipo === 'reversion_recarga' || m.tipo === 'reembolso';
|
||||||
|
|
||||||
|
// Determinar badge de tipo
|
||||||
|
let tipoBadge = '';
|
||||||
|
if (m.tipo === 'recarga_manual') {
|
||||||
|
tipoBadge = `<span style="background: #dcfce7; color: #166534; font-size: 0.72rem; font-weight: 800; padding: 2px 8px; border-radius: 6px;">💵 RECARGA EFECTIVO</span>`;
|
||||||
|
} else if (m.tipo === 'recarga_sinpe') {
|
||||||
|
tipoBadge = `<span style="background: #e0f2fe; color: #0369a1; font-size: 0.72rem; font-weight: 800; padding: 2px 8px; border-radius: 6px;">📲 RECARGA SINPE</span>`;
|
||||||
|
} else if (m.tipo === 'compra_mostrador' || m.tipo === 'preorden') {
|
||||||
|
tipoBadge = `<span style="background: #fef3c7; color: #92400e; font-size: 0.72rem; font-weight: 800; padding: 2px 8px; border-radius: 6px;">🥪 COBRO SODA</span>`;
|
||||||
|
} else if (m.tipo === 'reversion_recarga') {
|
||||||
|
tipoBadge = `<span style="background: #f3e8ff; color: #6b21a8; font-size: 0.72rem; font-weight: 800; padding: 2px 8px; border-radius: 6px;">↩️ REVERSIÓN RECARGA</span>`;
|
||||||
|
} else if (m.tipo === 'reembolso') {
|
||||||
|
tipoBadge = `<span style="background: #f3e8ff; color: #6b21a8; font-size: 0.72rem; font-weight: 800; padding: 2px 8px; border-radius: 6px;">↩️ REEMBOLSO COMPRA</span>`;
|
||||||
|
} else {
|
||||||
|
tipoBadge = `<span style="background: #f1f5f9; color: #475569; font-size: 0.72rem; font-weight: 800; padding: 2px 8px; border-radius: 6px;">${m.tipo.toUpperCase()}</span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Formato de hora
|
||||||
|
let fechaHoraStr = m.fecha || '';
|
||||||
|
try {
|
||||||
|
const d = new Date(m.fecha.includes('Z') ? m.fecha : m.fecha.replace(' ', 'T') + 'Z');
|
||||||
|
fechaHoraStr = d.toLocaleTimeString('es-CR', { hour: '2-digit', minute: '2-digit' }) + ' • ' + d.toLocaleDateString('es-CR', { day: '2-digit', month: 'short' });
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
// Monto formateado
|
||||||
|
const absMonto = Math.abs(m.monto_colones);
|
||||||
|
const montoDisplay = isPositive ? `+₡${absMonto.toLocaleString('es-CR')}` : `-₡${absMonto.toLocaleString('es-CR')}`;
|
||||||
|
const montoColor = isPositive ? '#16a34a' : '#d97706';
|
||||||
|
|
||||||
|
// Regla de 10 min para Cajero
|
||||||
|
const minutos = parseFloat(m.minutos_transcurridos) || 0;
|
||||||
|
const canRevertTime = !isCajero || minutos <= 10;
|
||||||
|
|
||||||
|
// Botón de acción / Estado
|
||||||
|
let actionHtml = '';
|
||||||
|
if (isRevertida) {
|
||||||
|
actionHtml = `
|
||||||
|
<div style="text-align: right;">
|
||||||
|
<span style="display: inline-block; background: #fee2e2; color: #991b1b; padding: 5px 10px; border-radius: 8px; font-size: 0.74rem; font-weight: 900; border: 1px solid #fca5a5;">
|
||||||
|
⛔ REVERTIDO
|
||||||
|
</span>
|
||||||
|
<div style="font-size: 0.68rem; color: var(--text-muted); margin-top: 3px;">
|
||||||
|
${m.revertido_por_nombre ? `Por ${m.revertido_por_nombre}` : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
} else if (isReversionOrRefund) {
|
||||||
|
actionHtml = `
|
||||||
|
<span style="display: inline-block; background: #f1f5f9; color: #64748b; padding: 5px 10px; border-radius: 8px; font-size: 0.74rem; font-weight: 800;">
|
||||||
|
Ajuste
|
||||||
|
</span>
|
||||||
|
`;
|
||||||
|
} else if (!canRevertTime) {
|
||||||
|
actionHtml = `
|
||||||
|
<button type="button" disabled title="Han pasado más de 10 minutos. Esta reversión solo puede ser realizada por un Administrador." style="padding: 7px 12px; background: #e2e8f0; color: #94a3b8; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 0.74rem; font-weight: 800; cursor: not-allowed; display: flex; align-items: center; gap: 4px;">
|
||||||
|
⏳ Requiere Admin (+10m)
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
const cleanName = (m.estudiante_nombre || '').replace(/'/g, "\\'");
|
||||||
|
actionHtml = `
|
||||||
|
<button type="button" onclick="revertirMovimientoAdmin(${m.id}, ${absMonto}, '${cleanName}', '${m.tipo}')" style="padding: 7px 14px; background: #fee2e2; color: #b91c1c; border: 1.5px solid #f87171; border-radius: 8px; font-size: 0.78rem; font-weight: 900; cursor: pointer; display: flex; align-items: center; gap: 5px; transition: all 0.2s; box-shadow: 0 1px 3px rgba(239, 68, 68, 0.15);" onmouseover="this.style.background='#fca5a5'" onmouseout="this.style.background='#fee2e2'">
|
||||||
|
<span>↩️</span> Revertir
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div style="background: var(--card-bg); border: 1.5px solid ${isRevertida ? '#fecaca' : 'var(--border)'}; border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; opacity: ${isRevertida ? '0.75' : '1'}; transition: all 0.2s;">
|
||||||
|
<!-- INFO ESTUDIANTE Y MOVIMIENTO -->
|
||||||
|
<div style="display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1;">
|
||||||
|
<img src="${m.estudiante_foto || '/img/avatar_default.png'}" style="width: 44px; height: 44px; border-radius: 50%; border: 2px solid ${isPositive ? '#10b981' : '#f59e0b'}; object-fit: cover; background: white; flex-shrink: 0;">
|
||||||
|
<div style="min-width: 0;">
|
||||||
|
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 2px;">
|
||||||
|
${tipoBadge}
|
||||||
|
<span style="font-size: 0.72rem; color: var(--text-muted); font-weight: 700;">#${m.id} • ${fechaHoraStr}</span>
|
||||||
|
</div>
|
||||||
|
<strong style="font-size: 0.95rem; color: var(--text-main); display: block; word-break: break-word;">
|
||||||
|
${m.estudiante_nombre}
|
||||||
|
</strong>
|
||||||
|
<div style="font-size: 0.75rem; color: var(--text-muted); margin-top: 1px;">
|
||||||
|
${m.codigo_estudiante} • ${m.grado || ''} ${m.seccion ? '- ' + m.seccion : ''}
|
||||||
|
${m.codigo_orden ? `• Ticket: <strong>${m.codigo_orden}</strong>` : ''}
|
||||||
|
${m.descripcion ? `• <em>${m.descripcion}</em>` : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MONTO Y BOTÓN REVERTIR -->
|
||||||
|
<div style="display: flex; align-items: center; gap: 14px; flex-shrink: 0;">
|
||||||
|
<div style="text-align: right;">
|
||||||
|
<div style="font-size: 1.15rem; font-weight: 900; color: ${montoColor};">
|
||||||
|
${montoDisplay}
|
||||||
|
</div>
|
||||||
|
<div style="font-size: 0.68rem; color: var(--text-muted); font-weight: 700;">
|
||||||
|
Saldo: ₡${(m.saldo_posterior || 0).toLocaleString('es-CR')}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
${actionHtml}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function revertirMovimientoAdmin(transaccionId, monto, nombreEstudiante, tipo) {
|
||||||
|
const esRecarga = tipo.includes('recarga') || tipo === 'transferencia_recibida';
|
||||||
|
const accionTexto = esRecarga ? 'esta RECARGA errónea de dinero' : 'este COBRO de merienda';
|
||||||
|
const efectoTexto = esRecarga
|
||||||
|
? `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?`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!conf) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/admin/movimientos/${transaccionId}/revertir`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
usuario_id: currentUser ? currentUser.id : null,
|
||||||
|
usuario_rol: currentUser ? currentUser.rol : 'admin'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await res.json();
|
||||||
|
if (!res.ok) throw new Error(data.error);
|
||||||
|
|
||||||
|
if (window.sounds) window.sounds.playSuccess();
|
||||||
|
alert(`✅ Reversión Exitosa:\n${data.mensaje}`);
|
||||||
|
|
||||||
|
await loadAdminMovimientos();
|
||||||
|
await loadAdminData();
|
||||||
|
} catch (err) {
|
||||||
|
if (window.sounds) window.sounds.playError();
|
||||||
|
alert(`❌ No se pudo revertir el movimiento:\n${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+171
-3
@@ -138,6 +138,11 @@ function initDatabase() {
|
|||||||
`);
|
`);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
|
// 9. Auditoría de Reversiones de Cargos y Recargas
|
||||||
|
try { db.exec('ALTER TABLE transacciones_saldo ADD COLUMN revertida INTEGER DEFAULT 0'); } catch (e) {}
|
||||||
|
try { db.exec('ALTER TABLE transacciones_saldo ADD COLUMN revertido_por_usuario_id INTEGER REFERENCES usuarios(id)'); } catch (e) {}
|
||||||
|
try { db.exec('ALTER TABLE transacciones_saldo ADD COLUMN revertido_en DATETIME'); } catch (e) {}
|
||||||
|
|
||||||
seedInitialData();
|
seedInitialData();
|
||||||
seedUsuarios();
|
seedUsuarios();
|
||||||
}
|
}
|
||||||
@@ -151,10 +156,13 @@ function seedUsuarios() {
|
|||||||
// 1. Admin de la Soda
|
// 1. Admin de la Soda
|
||||||
insert.run('admin', 'admin123', 'admin', 'Administrador de la Soda', '+506 8888-7632', '[email protected]');
|
insert.run('admin', 'admin123', 'admin', 'Administrador de la Soda', '+506 8888-7632', '[email protected]');
|
||||||
|
|
||||||
// 2. Padre de Mateo
|
// 2. Cajero de la Soda
|
||||||
|
insert.run('cajero', 'cajero123', 'cajero', 'Cajero de la Soda', '+506 8888-0000', '[email protected]');
|
||||||
|
|
||||||
|
// 3. Padre de Mateo
|
||||||
const resPadre = insert.run('padre', 'padre123', 'padre', 'Carlos Alvarado (Papá)', '+506 8888-1122', '[email protected]');
|
const resPadre = insert.run('padre', 'padre123', 'padre', 'Carlos Alvarado (Papá)', '+506 8888-1122', '[email protected]');
|
||||||
|
|
||||||
// 3. Estudiantes
|
// 4. Estudiantes
|
||||||
const resMateo = insert.run('mateo', '1234', 'estudiante', 'Mateo Alvarado Castro', '', '');
|
const resMateo = insert.run('mateo', '1234', 'estudiante', 'Mateo Alvarado Castro', '', '');
|
||||||
const resSofia = insert.run('sofia', '1234', 'estudiante', 'Sofía Jiménez Morales', '', '');
|
const resSofia = insert.run('sofia', '1234', 'estudiante', 'Sofía Jiménez Morales', '', '');
|
||||||
|
|
||||||
@@ -163,6 +171,14 @@ function seedUsuarios() {
|
|||||||
db.prepare('UPDATE estudiantes SET usuario_id = ?, padre_usuario_id = ? WHERE id = 1').run(resMateo.lastInsertRowid, resPadre.lastInsertRowid);
|
db.prepare('UPDATE estudiantes SET usuario_id = ?, padre_usuario_id = ? WHERE id = 1').run(resMateo.lastInsertRowid, resPadre.lastInsertRowid);
|
||||||
db.prepare('UPDATE estudiantes SET usuario_id = ? WHERE id = 2').run(resSofia.lastInsertRowid);
|
db.prepare('UPDATE estudiantes SET usuario_id = ? WHERE id = 2').run(resSofia.lastInsertRowid);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
} else {
|
||||||
|
// Asegurar que el usuario cajero exista en bases de datos ya pobladas
|
||||||
|
try {
|
||||||
|
const cajero = db.prepare("SELECT id FROM usuarios WHERE username = 'cajero'").get();
|
||||||
|
if (!cajero) {
|
||||||
|
db.prepare("INSERT INTO usuarios (username, password_hash, rol, nombre, telefono, email) VALUES ('cajero', 'cajero123', 'cajero', 'Cajero de la Soda', '+506 8888-0000', '[email protected]')").run();
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,11 +648,163 @@ function transferenciaP2PTransaction({ emisorId, qrReceptor, receptorId, monto,
|
|||||||
return transaction();
|
return transaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reversión de un cargo o recarga errónea
|
||||||
|
* Rol cajero: solo permitido en los primeros 10 minutos
|
||||||
|
* Rol admin: permitido en cualquier momento
|
||||||
|
*/
|
||||||
|
function revertirTransaccionSaldoTransaction({ transaccionId, usuarioId, usuarioRol }) {
|
||||||
|
const transaction = db.transaction(() => {
|
||||||
|
// 1. Obtener la transacción original y los minutos transcurridos
|
||||||
|
const tx = db.prepare(`
|
||||||
|
SELECT t.*,
|
||||||
|
ROUND((strftime('%s', 'now') - strftime('%s', t.fecha)) / 60.0, 1) as minutos_transcurridos
|
||||||
|
FROM transacciones_saldo t
|
||||||
|
WHERE t.id = ?
|
||||||
|
`).get(transaccionId);
|
||||||
|
|
||||||
|
if (!tx) {
|
||||||
|
throw new Error('Transacción no encontrada en los registros');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx.revertida === 1) {
|
||||||
|
throw new Error('Esta transacción ya fue revertida previamente');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tx.tipo === 'reversion_recarga' || tx.tipo === 'reembolso') {
|
||||||
|
throw new Error('No es posible revertir una transacción que ya corresponde a una reversión o reembolso');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Control de tiempo según el rol (Cajero: <= 10 min, Admin: ilimitado)
|
||||||
|
const minutos = parseFloat(tx.minutos_transcurridos) || 0;
|
||||||
|
if (usuarioRol === 'cajero' && minutos > 10) {
|
||||||
|
throw new Error(`Han transcurrido ${Math.round(minutos)} minutos desde este movimiento. Un usuario con rol de Cajero solo puede revertir durante los primeros 10 minutos. Esta operación debe ser realizada por un Administrador.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Obtener el estudiante involucrado
|
||||||
|
const est = db.prepare('SELECT * FROM estudiantes WHERE id = ?').get(tx.estudiante_id);
|
||||||
|
if (!est) {
|
||||||
|
throw new Error('El estudiante asociado a este movimiento no fue encontrado');
|
||||||
|
}
|
||||||
|
|
||||||
|
let resultado = {};
|
||||||
|
|
||||||
|
// 4. Caso A: Reversión de Recarga de Dinero (monto positivo ingresado al monedero)
|
||||||
|
if (tx.monto_colones > 0 || tx.tipo === 'recarga_manual' || tx.tipo === 'recarga_sinpe' || tx.tipo === 'transferencia_recibida') {
|
||||||
|
const montoRevertir = Math.abs(tx.monto_colones);
|
||||||
|
const nuevoSaldo = est.saldo_colones - montoRevertir;
|
||||||
|
|
||||||
|
// Actualizar saldo del estudiante (puede quedar en negativo según la decisión acordada)
|
||||||
|
db.prepare('UPDATE estudiantes SET saldo_colones = ? WHERE id = ?').run(nuevoSaldo, est.id);
|
||||||
|
|
||||||
|
// Marcar transacción original como revertida
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE transacciones_saldo
|
||||||
|
SET revertida = 1, revertido_por_usuario_id = ?, revertido_en = CURRENT_TIMESTAMP
|
||||||
|
WHERE id = ?
|
||||||
|
`).run(usuarioId || null, tx.id);
|
||||||
|
|
||||||
|
// Registrar auditoría de reversión
|
||||||
|
db.prepare(`
|
||||||
|
INSERT INTO transacciones_saldo
|
||||||
|
(estudiante_id, tipo, monto_colones, saldo_previo, saldo_posterior, comprobante_sinpe, descripcion)
|
||||||
|
VALUES (?, 'reversion_recarga', ?, ?, ?, 'REVERSION', ?)
|
||||||
|
`).run(
|
||||||
|
est.id,
|
||||||
|
-montoRevertir,
|
||||||
|
est.saldo_colones,
|
||||||
|
nuevoSaldo,
|
||||||
|
`Reversión de recarga #${tx.id} (${tx.descripcion || 'Recarga'})`
|
||||||
|
);
|
||||||
|
|
||||||
|
resultado = {
|
||||||
|
exito: true,
|
||||||
|
tipo_operacion: 'reversion_recarga',
|
||||||
|
transaccion_id: tx.id,
|
||||||
|
estudiante_id: est.id,
|
||||||
|
nombre_completo: est.nombre_completo,
|
||||||
|
monto_revertido: montoRevertir,
|
||||||
|
saldo_anterior: est.saldo_colones,
|
||||||
|
saldo_nuevo: nuevoSaldo,
|
||||||
|
mensaje: `Se revirtió exitosamente la recarga de ₡${montoRevertir.toLocaleString('es-CR')} a ${est.nombre_completo}. Nuevo saldo: ₡${nuevoSaldo.toLocaleString('es-CR')}.`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// 5. Caso B: Reversión de Cobro de Mostrador / Compra de Merienda (monto debitado al alumno)
|
||||||
|
else {
|
||||||
|
const montoReembolso = Math.abs(tx.monto_colones);
|
||||||
|
const nuevoSaldo = est.saldo_colones + montoReembolso;
|
||||||
|
|
||||||
|
// Devolver saldo al estudiante
|
||||||
|
db.prepare('UPDATE estudiantes SET saldo_colones = ? WHERE id = ?').run(nuevoSaldo, est.id);
|
||||||
|
|
||||||
|
let productosRestaurados = [];
|
||||||
|
// Anular orden y devolver productos al inventario si tiene orden asociada
|
||||||
|
if (tx.orden_id) {
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE ordenes
|
||||||
|
SET estado = 'anulada', notas = COALESCE(notas || ' | ', '') || 'Revertida en caja/admin'
|
||||||
|
WHERE id = ?
|
||||||
|
`).run(tx.orden_id);
|
||||||
|
|
||||||
|
const detalles = db.prepare('SELECT producto_id, cantidad FROM orden_detalles WHERE orden_id = ?').all(tx.orden_id);
|
||||||
|
for (const det of detalles) {
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE productos
|
||||||
|
SET stock = stock + ?, disponible = 1
|
||||||
|
WHERE id = ? AND control_stock = 1
|
||||||
|
`).run(det.cantidad, det.producto_id);
|
||||||
|
|
||||||
|
productosRestaurados.push({ producto_id: det.producto_id, cantidad: det.cantidad });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Marcar transacción original como revertida
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE transacciones_saldo
|
||||||
|
SET revertida = 1, revertido_por_usuario_id = ?, revertido_en = CURRENT_TIMESTAMP
|
||||||
|
WHERE id = ?
|
||||||
|
`).run(usuarioId || null, tx.id);
|
||||||
|
|
||||||
|
// Registrar auditoría de reembolso
|
||||||
|
db.prepare(`
|
||||||
|
INSERT INTO transacciones_saldo
|
||||||
|
(estudiante_id, tipo, monto_colones, saldo_previo, saldo_posterior, orden_id, descripcion)
|
||||||
|
VALUES (?, 'reembolso', ?, ?, ?, ?, ?)
|
||||||
|
`).run(
|
||||||
|
est.id,
|
||||||
|
montoReembolso,
|
||||||
|
est.saldo_colones,
|
||||||
|
nuevoSaldo,
|
||||||
|
tx.orden_id || null,
|
||||||
|
`Reembolso por anulación de cobro #${tx.id} (${tx.descripcion || 'Compra mostrador'})`
|
||||||
|
);
|
||||||
|
|
||||||
|
resultado = {
|
||||||
|
exito: true,
|
||||||
|
tipo_operacion: 'reembolso_cobro',
|
||||||
|
transaccion_id: tx.id,
|
||||||
|
estudiante_id: est.id,
|
||||||
|
nombre_completo: est.nombre_completo,
|
||||||
|
monto_revertido: montoReembolso,
|
||||||
|
saldo_anterior: est.saldo_colones,
|
||||||
|
saldo_nuevo: nuevoSaldo,
|
||||||
|
productos_restaurados: productosRestaurados,
|
||||||
|
mensaje: `Se anuló el cobro de ₡${montoReembolso.toLocaleString('es-CR')} y se reintegró el dinero a ${est.nombre_completo}. Nuevo saldo: ₡${nuevoSaldo.toLocaleString('es-CR')}.`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultado;
|
||||||
|
});
|
||||||
|
|
||||||
|
return transaction();
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
db,
|
db,
|
||||||
initDatabase,
|
initDatabase,
|
||||||
debitoCompraTransaction,
|
debitoCompraTransaction,
|
||||||
recargaSaldoTransaction,
|
recargaSaldoTransaction,
|
||||||
crearOrdenCompleta,
|
crearOrdenCompleta,
|
||||||
transferenciaP2PTransaction
|
transferenciaP2PTransaction,
|
||||||
|
revertirTransaccionSaldoTransaction
|
||||||
};
|
};
|
||||||
|
|||||||
+70
-1
@@ -2,7 +2,7 @@ const express = require('express');
|
|||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const QRCode = require('qrcode');
|
const QRCode = require('qrcode');
|
||||||
const { db, initDatabase, debitoCompraTransaction, recargaSaldoTransaction, crearOrdenCompleta, transferenciaP2PTransaction } = require('./db');
|
const { db, initDatabase, debitoCompraTransaction, recargaSaldoTransaction, crearOrdenCompleta, transferenciaP2PTransaction, revertirTransaccionSaldoTransaction } = require('./db');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = process.env.PORT || 3030;
|
const PORT = process.env.PORT || 3030;
|
||||||
@@ -555,6 +555,75 @@ app.post('/api/admin/estudiantes/:id/recarga-manual', (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Listar historial de movimientos y transacciones con estado de reversión
|
||||||
|
app.get('/api/admin/movimientos', (req, res) => {
|
||||||
|
try {
|
||||||
|
const limit = parseInt(req.query.limit, 10) || 100;
|
||||||
|
const movimientos = db.prepare(`
|
||||||
|
SELECT
|
||||||
|
t.*,
|
||||||
|
ROUND((strftime('%s', 'now') - strftime('%s', t.fecha)) / 60.0, 1) as minutos_transcurridos,
|
||||||
|
e.nombre_completo as estudiante_nombre,
|
||||||
|
e.codigo_estudiante,
|
||||||
|
e.grado,
|
||||||
|
e.seccion,
|
||||||
|
e.foto_url as estudiante_foto,
|
||||||
|
e.saldo_colones as estudiante_saldo_actual,
|
||||||
|
u.nombre as revertido_por_nombre,
|
||||||
|
o.codigo_orden
|
||||||
|
FROM transacciones_saldo t
|
||||||
|
JOIN estudiantes e ON t.estudiante_id = e.id
|
||||||
|
LEFT JOIN usuarios u ON t.revertido_por_usuario_id = u.id
|
||||||
|
LEFT JOIN ordenes o ON t.orden_id = o.id
|
||||||
|
ORDER BY t.fecha DESC, t.id DESC
|
||||||
|
LIMIT ?
|
||||||
|
`).all(limit);
|
||||||
|
|
||||||
|
res.json(movimientos);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Revertir un movimiento (recarga o cobro erróneo)
|
||||||
|
app.post('/api/admin/movimientos/:id/revertir', (req, res) => {
|
||||||
|
try {
|
||||||
|
const transaccionId = parseInt(req.params.id, 10);
|
||||||
|
const { usuario_id, usuario_rol } = req.body;
|
||||||
|
|
||||||
|
if (!transaccionId || isNaN(transaccionId)) {
|
||||||
|
return res.status(400).json({ error: 'ID de transacción inválido' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const resultado = revertirTransaccionSaldoTransaction({
|
||||||
|
transaccionId,
|
||||||
|
usuarioId: usuario_id || null,
|
||||||
|
usuarioRol: usuario_rol || 'admin'
|
||||||
|
});
|
||||||
|
|
||||||
|
// Notificaciones en vivo (SSE) para reflejar saldo en portal de padres, PWA y terminal
|
||||||
|
broadcastEvent('saldo_actualizado', {
|
||||||
|
id: resultado.estudiante_id,
|
||||||
|
estudiante_id: resultado.estudiante_id,
|
||||||
|
saldo_colones: resultado.saldo_nuevo
|
||||||
|
});
|
||||||
|
broadcastEvent('estudiante_actualizado', {
|
||||||
|
id: resultado.estudiante_id,
|
||||||
|
estudiante_id: resultado.estudiante_id,
|
||||||
|
saldo_colones: resultado.saldo_nuevo
|
||||||
|
});
|
||||||
|
broadcastEvent('movimiento_revertido', resultado);
|
||||||
|
|
||||||
|
if (resultado.productos_restaurados && resultado.productos_restaurados.length > 0) {
|
||||||
|
broadcastEvent('inventario_actualizado', { motivo: 'reversion_orden' });
|
||||||
|
}
|
||||||
|
|
||||||
|
res.json(resultado);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(400).json({ error: error.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// 1. ESTUDIANTES Y QR
|
// 1. ESTUDIANTES Y QR
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
Reference in New Issue
Block a user