fix(balance): actualizacion de saldo y disponible hoy en tiempo real via SSE y correccion de zona horaria local
This commit is contained in:
@@ -1840,3 +1840,15 @@ body.dark-mode .selected-student-banner {
|
||||
border-color: #38bdf8;
|
||||
}
|
||||
|
||||
/* Animación de actualización de saldo y disponible en tiempo real */
|
||||
@keyframes balancePulseHighlight {
|
||||
0% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(56, 189, 248, 0)); }
|
||||
35% { transform: scale(1.08); filter: drop-shadow(0 0 10px rgba(56, 189, 248, 0.9)); color: #0284c7; }
|
||||
100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(56, 189, 248, 0)); }
|
||||
}
|
||||
|
||||
.balance-updated {
|
||||
animation: balancePulseHighlight 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<meta name="apple-mobile-web-app-title" content="RecreoPay">
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<link rel="stylesheet" href="/css/styles.css?v=8.4">
|
||||
<link rel="stylesheet" href="/css/styles.css?v=8.5">
|
||||
<style>
|
||||
/* Transiciones suaves */
|
||||
.fade-enter { animation: fadeIn 0.2s ease-in-out; }
|
||||
@@ -1098,8 +1098,8 @@
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<script src="/js/sounds.js?v=8.4"></script>
|
||||
<script src="/js/sounds.js?v=8.5"></script>
|
||||
<script src="/js/jsQR.js"></script>
|
||||
<script src="/js/app.js?v=8.4"></script>
|
||||
<script src="/js/app.js?v=8.5"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+120
-6
@@ -390,9 +390,15 @@ function updateStudentUI() {
|
||||
const transferBtn = document.getElementById('transferBtnText');
|
||||
if (transferBtn) transferBtn.textContent = 'Transferir ⚡';
|
||||
|
||||
// Límite diario
|
||||
document.getElementById('dailyLimitText').textContent = `₡${currentStudent.limite_diario_colones.toLocaleString('es-CR')}`;
|
||||
document.getElementById('dailyAvailableText').textContent = `Disponible hoy: ₡${currentStudent.disponible_hoy.toLocaleString('es-CR')}`;
|
||||
// Límite diario y disponible hoy
|
||||
const limiteDiario = currentStudent.limite_diario_colones || 0;
|
||||
const gastadoHoy = currentStudent.gastado_hoy || 0;
|
||||
const disponibleHoy = (typeof currentStudent.disponible_hoy === 'number')
|
||||
? currentStudent.disponible_hoy
|
||||
: Math.max(0, limiteDiario - gastadoHoy);
|
||||
|
||||
document.getElementById('dailyLimitText').textContent = `₡${limiteDiario.toLocaleString('es-CR')}`;
|
||||
document.getElementById('dailyAvailableText').textContent = `Disponible hoy: ₡${disponibleHoy.toLocaleString('es-CR')}`;
|
||||
|
||||
// Alerta de Tarjeta Bloqueada
|
||||
const bannerBlocked = document.getElementById('bannerCardBlocked');
|
||||
@@ -1384,17 +1390,106 @@ async function onToggleAllowTransfer(checked) {
|
||||
}
|
||||
}
|
||||
|
||||
function triggerBalancePulse() {
|
||||
const el = document.getElementById('walletBalance');
|
||||
if (el) {
|
||||
el.classList.remove('balance-updated');
|
||||
void el.offsetWidth;
|
||||
el.classList.add('balance-updated');
|
||||
}
|
||||
const dispEl = document.getElementById('dailyAvailableText');
|
||||
if (dispEl) {
|
||||
dispEl.classList.remove('balance-updated');
|
||||
void dispEl.offsetWidth;
|
||||
dispEl.classList.add('balance-updated');
|
||||
}
|
||||
}
|
||||
|
||||
// SSE en tiempo real para eventos de la soda y monederos
|
||||
function initStudentSSE() {
|
||||
const sse = new EventSource('/api/events');
|
||||
|
||||
// Cobro inmediato en caja / pre-orden realizada
|
||||
sse.addEventListener('nueva_orden', (e) => {
|
||||
try {
|
||||
const data = JSON.parse(e.data);
|
||||
const estId = data.estudiante_id || (data.financiero && data.financiero.estudiante && data.financiero.estudiante.id);
|
||||
|
||||
// Si el estudiante en pantalla fue a quien se le cobró
|
||||
if (currentStudent && currentStudent.id === estId) {
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
|
||||
if (data.financiero && data.financiero.estudiante) {
|
||||
const f = data.financiero.estudiante;
|
||||
currentStudent.saldo_colones = f.saldo_nuevo;
|
||||
currentStudent.gastado_hoy = f.gastado_hoy;
|
||||
currentStudent.disponible_hoy = (typeof f.disponible_hoy === 'number')
|
||||
? f.disponible_hoy
|
||||
: Math.max(0, (f.limite_diario || currentStudent.limite_diario_colones || 0) - (f.gastado_hoy || 0));
|
||||
updateStudentUI();
|
||||
triggerBalancePulse();
|
||||
}
|
||||
selectStudent(currentStudent.id);
|
||||
}
|
||||
|
||||
// Si es padre de este estudiante
|
||||
if (currentUser && currentUser.rol === 'padre') {
|
||||
loadParentDashboard();
|
||||
}
|
||||
|
||||
// Si es admin
|
||||
if (currentUser && currentUser.rol === 'admin') {
|
||||
loadAdminData();
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Error en SSE nueva_orden:', err);
|
||||
}
|
||||
});
|
||||
|
||||
// Saldo actualizado (débito, recarga, ajuste de límite)
|
||||
sse.addEventListener('saldo_actualizado', (e) => {
|
||||
try {
|
||||
const data = JSON.parse(e.data);
|
||||
const estId = data.estudiante_id || data.id;
|
||||
|
||||
if (currentStudent && currentStudent.id === estId) {
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
if (typeof data.saldo_colones === 'number') currentStudent.saldo_colones = data.saldo_colones;
|
||||
if (typeof data.disponible_hoy === 'number') currentStudent.disponible_hoy = data.disponible_hoy;
|
||||
if (typeof data.gastado_hoy === 'number') currentStudent.gastado_hoy = data.gastado_hoy;
|
||||
updateStudentUI();
|
||||
triggerBalancePulse();
|
||||
selectStudent(currentStudent.id);
|
||||
}
|
||||
|
||||
if (currentUser && currentUser.rol === 'padre') {
|
||||
loadParentDashboard();
|
||||
}
|
||||
if (currentUser && currentUser.rol === 'admin') {
|
||||
loadAdminData();
|
||||
}
|
||||
} catch (err) {}
|
||||
});
|
||||
|
||||
sse.addEventListener('transferencia_realizada', (e) => {
|
||||
try {
|
||||
const data = JSON.parse(e.data);
|
||||
if (currentStudent && data.receptor.id === currentStudent.id) {
|
||||
if (currentStudent && data.receptor && data.receptor.id === currentStudent.id) {
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
alert(`🔔 ¡Te pasaron plata!\n${data.emisor.nombre} te transfirió ₡${data.monto.toLocaleString('es-CR')}.\nMotivo: ${data.motivo}`);
|
||||
selectStudent(currentStudent.id);
|
||||
triggerBalancePulse();
|
||||
} else if (currentStudent && data.emisor && data.emisor.id === currentStudent.id) {
|
||||
if (typeof data.emisor.saldo_nuevo === 'number') {
|
||||
currentStudent.saldo_colones = data.emisor.saldo_nuevo;
|
||||
updateStudentUI();
|
||||
triggerBalancePulse();
|
||||
}
|
||||
selectStudent(currentStudent.id);
|
||||
}
|
||||
|
||||
if (currentUser && currentUser.rol === 'padre') {
|
||||
loadParentDashboard();
|
||||
}
|
||||
} catch (err) {}
|
||||
});
|
||||
@@ -1402,10 +1497,19 @@ function initStudentSSE() {
|
||||
sse.addEventListener('recarga_exitosa', (e) => {
|
||||
try {
|
||||
const data = JSON.parse(e.data);
|
||||
if (currentStudent && data.estudiante_id === currentStudent.id) {
|
||||
const estId = data.estudiante_id || data.id;
|
||||
if (currentStudent && currentStudent.id === estId) {
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
if (typeof data.saldo_nuevo === 'number') {
|
||||
currentStudent.saldo_colones = data.saldo_nuevo;
|
||||
updateStudentUI();
|
||||
triggerBalancePulse();
|
||||
}
|
||||
selectStudent(currentStudent.id);
|
||||
}
|
||||
if (currentUser && currentUser.rol === 'padre') {
|
||||
loadParentDashboard();
|
||||
}
|
||||
if (currentUser && currentUser.rol === 'admin') {
|
||||
loadAdminData();
|
||||
}
|
||||
@@ -1435,9 +1539,19 @@ function initStudentSSE() {
|
||||
sse.addEventListener('estudiante_actualizado', (e) => {
|
||||
try {
|
||||
const data = JSON.parse(e.data);
|
||||
if (currentStudent && currentStudent.id === data.id) {
|
||||
const estId = data.id || data.estudiante_id;
|
||||
if (currentStudent && currentStudent.id === estId) {
|
||||
if (typeof data.saldo_colones === 'number') currentStudent.saldo_colones = data.saldo_colones;
|
||||
if (typeof data.disponible_hoy === 'number') currentStudent.disponible_hoy = data.disponible_hoy;
|
||||
if (typeof data.gastado_hoy === 'number') currentStudent.gastado_hoy = data.gastado_hoy;
|
||||
if (typeof data.limite_diario_colones === 'number') currentStudent.limite_diario_colones = data.limite_diario_colones;
|
||||
updateStudentUI();
|
||||
triggerBalancePulse();
|
||||
selectStudent(currentStudent.id);
|
||||
}
|
||||
if (currentUser && currentUser.rol === 'padre') {
|
||||
loadParentDashboard();
|
||||
}
|
||||
if (currentUser && currentUser.rol === 'admin') {
|
||||
loadAdminData();
|
||||
}
|
||||
|
||||
@@ -974,4 +974,28 @@ function initSSE() {
|
||||
sseSource.addEventListener('orden_actualizada', () => {
|
||||
loadPreOrders();
|
||||
});
|
||||
|
||||
sseSource.addEventListener('estudiante_actualizado', (e) => {
|
||||
try {
|
||||
const data = JSON.parse(e.data);
|
||||
const estId = data.id || data.estudiante_id;
|
||||
if (scannedStudent && scannedStudent.id === estId) {
|
||||
if (typeof data.saldo_colones === 'number') scannedStudent.saldo_colones = data.saldo_colones;
|
||||
if (typeof data.disponible_hoy === 'number') scannedStudent.disponible_hoy = data.disponible_hoy;
|
||||
renderScannedStudent();
|
||||
}
|
||||
} catch (err) {}
|
||||
});
|
||||
|
||||
sseSource.addEventListener('saldo_actualizado', (e) => {
|
||||
try {
|
||||
const data = JSON.parse(e.data);
|
||||
const estId = data.id || data.estudiante_id;
|
||||
if (scannedStudent && scannedStudent.id === estId) {
|
||||
if (typeof data.saldo_colones === 'number') scannedStudent.saldo_colones = data.saldo_colones;
|
||||
if (typeof data.disponible_hoy === 'number') scannedStudent.disponible_hoy = data.disponible_hoy;
|
||||
renderScannedStudent();
|
||||
}
|
||||
} catch (err) {}
|
||||
});
|
||||
}
|
||||
|
||||
+2
-2
@@ -318,8 +318,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/js/sounds.js?v=8.3"></script>
|
||||
<script src="/js/sounds.js?v=8.5"></script>
|
||||
<script src="/js/jsQR.js"></script>
|
||||
<script src="/js/pos.js?v=8.3"></script>
|
||||
<script src="/js/pos.js?v=8.5"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user