+ Límite diario alcanzado
+
+ Has consumido tu límite de gasto de hoy. Tu código QR está bloqueado para nuevas compras hasta la siguiente jornada.
+
+
+
+
@@ -1917,6 +1945,12 @@
MI CARNÉ SIBOPAY
+
+
+ 📦 Válido exclusivamente para retirar tu Pre-Orden en la soda.
+ Compras nuevas en mostrador bloqueadas por límite diario.
+
+
@@ -1971,13 +2005,18 @@
-
- Total a Rebajar de Saldo:
- ₡0
+
+
+ Total a Reservar (Monto Flotante):
+ ₡0
+
+
+ 🔒 El monto queda retenido y se rebajará definitivamente al retirar en la soda.
+
@@ -3083,6 +3122,17 @@
+
+
+
+ 6
+
+
+ No Canjeable por Dinero Real o Efectivo:
+ Los fondos recargados corresponden a créditos escolares exclusivos para consumo de alimentos en la soda. No pueden ser convertidos ni devueltos en dinero en efectivo bajo ninguna circunstancia.
+
+
+
diff --git a/public/js/app.js b/public/js/app.js
index 3c79bf3..ecb84c6 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -728,9 +728,32 @@ function updateStudentUI() {
applyCardTheme(getSavedCardTheme());
}
- // Saldo en colones
- document.getElementById('walletBalance').textContent = `₡${currentStudent.saldo_colones.toLocaleString('es-CR')}`;
- document.getElementById('balanceLabel').textContent = 'SALDO DISPONIBLE';
+ // Saldo total, retenido y disponible para gastar
+ const saldoTotal = (typeof currentStudent.saldo_total === 'number')
+ ? currentStudent.saldo_total
+ : (currentStudent.saldo_colones || 0);
+ const saldoRetenido = currentStudent.saldo_retenido || 0;
+ const saldoDisponible = (typeof currentStudent.saldo_disponible === 'number')
+ ? currentStudent.saldo_disponible
+ : Math.max(0, saldoTotal - saldoRetenido);
+
+ document.getElementById('walletBalance').textContent = `₡${saldoDisponible.toLocaleString('es-CR')}`;
+ document.getElementById('balanceLabel').textContent = saldoRetenido > 0 ? 'DISPONIBLE PARA GASTAR' : 'SALDO DISPONIBLE';
+
+ // Desglose transparente cuando hay monto retenido en pre-órdenes
+ const breakdownBox = document.getElementById('breakdownSaldoBox');
+ if (breakdownBox) {
+ if (saldoRetenido > 0) {
+ breakdownBox.style.display = 'block';
+ const lblTot = document.getElementById('lblSaldoTotalBreakdown');
+ if (lblTot) lblTot.textContent = `₡${saldoTotal.toLocaleString('es-CR')}`;
+ const lblRet = document.getElementById('lblSaldoRetenidoBreakdown');
+ if (lblRet) lblRet.textContent = `₡${saldoRetenido.toLocaleString('es-CR')}`;
+ } else {
+ breakdownBox.style.display = 'none';
+ }
+ }
+
const coin = document.getElementById('kidsCoinIcon');
if (coin) coin.style.display = 'none';
const qrBtn = document.getElementById('qrBtnText');
@@ -743,11 +766,30 @@ function updateStudentUI() {
const gastadoHoy = currentStudent.gastado_hoy || 0;
const disponibleHoy = (typeof currentStudent.disponible_hoy === 'number')
? currentStudent.disponible_hoy
- : Math.max(0, limiteDiario - gastadoHoy);
+ : Math.max(0, limiteDiario - gastadoHoy - saldoRetenido);
document.getElementById('dailyLimitText').textContent = `₡${limiteDiario.toLocaleString('es-CR')}`;
document.getElementById('dailyAvailableText').textContent = `Disponible hoy: ₡${disponibleHoy.toLocaleString('es-CR')}`;
+ const tienePreordenes = Boolean(currentStudent.tiene_preordenes_pendientes || (currentStudent.preordenes_pendientes_count > 0));
+ const qrBloqueadoPorLimite = disponibleHoy <= 0 && !tienePreordenes;
+
+ // Banner informativo si alcanzó su límite diario
+ const bannerLimitBlocked = document.getElementById('bannerQrDailyLimitBlocked');
+ if (bannerLimitBlocked) {
+ if (disponibleHoy <= 0) {
+ bannerLimitBlocked.style.display = 'flex';
+ const msgEl = document.getElementById('bannerQrDailyLimitMsg');
+ if (msgEl) {
+ msgEl.textContent = tienePreordenes
+ ? 'Has alcanzado tu límite diario de consumo. Tu código QR solo podrá ser escaneado en la soda para retirar tu Pre-Orden.'
+ : `Has alcanzado tu límite diario de ₡${limiteDiario.toLocaleString('es-CR')} asignado por tus padres. La generación del código QR para compras está bloqueada hasta mañana.`;
+ }
+ } else {
+ bannerLimitBlocked.style.display = 'none';
+ }
+ }
+
// Alerta de Tarjeta Bloqueada
const bannerBlocked = document.getElementById('bannerCardBlocked');
if (bannerBlocked) {
@@ -757,12 +799,29 @@ function updateStudentUI() {
if (currentStudent.tarjeta_bloqueada) {
btn.style.opacity = '0.45';
btn.style.pointerEvents = 'none';
+ } else if (qrBloqueadoPorLimite) {
+ btn.style.opacity = '0.55';
+ btn.style.filter = 'grayscale(0.85)';
+ btn.title = 'Límite diario alcanzado: no puedes generar QR para compras';
+ btn.style.pointerEvents = 'auto'; // Permitir clic para mostrar el mensaje explicativo
} else {
btn.style.opacity = '1';
+ btn.style.filter = 'none';
btn.style.pointerEvents = 'auto';
}
});
+ const pwaNavQr = document.getElementById('pwaNavQr');
+ if (pwaNavQr) {
+ if (qrBloqueadoPorLimite) {
+ pwaNavQr.style.opacity = '0.55';
+ pwaNavQr.title = 'Límite diario alcanzado';
+ } else {
+ pwaNavQr.style.opacity = '1';
+ pwaNavQr.title = '';
+ }
+ }
+
// Gray-out del botón Transferir cuando los padres lo desactivan
const btnCardTransfer = document.getElementById('btnCardTransfer');
const pwaNavTransfer = document.getElementById('pwaNavTransfer');
@@ -1362,7 +1421,7 @@ async function submitPreOrder() {
if (window.sounds) window.sounds.playSuccess();
- alert(`¡Pre-Orden confirmada con éxito!\n\n📋 Código de retiro: ${data.codigo_orden}\n⏰ Horario: ${momentoBadge.full}\n💰 Total rebajado: ₡${data.total_colones.toLocaleString('es-CR')}\n\nPodrás retirarla en la soda durante el recreo programado presentando tu carné QR.`);
+ alert(`¡Pre-Orden confirmada con éxito!\n\n📋 Código de retiro: ${data.codigo_orden}\n⏰ Horario: ${momentoBadge.full}\n🔒 Monto reservado (flotante): ₡${data.total_colones.toLocaleString('es-CR')}\n\nNota: Este saldo queda retenido y se rebajará formalmente en la soda al retirar tu pedido presentando tu carné QR.`);
// Limpiar carrito y recargar datos del estudiante o padre
cart = [];
@@ -1383,7 +1442,7 @@ async function submitPreOrder() {
alert(`No se pudo procesar: ${err.message}`);
} finally {
btn.disabled = false;
- btn.innerHTML = ' Confirmar y Pagar Pre-Orden';
+ btn.innerHTML = ' Confirmar Pre-Orden (Monto Flotante)';
}
}
@@ -1392,6 +1451,31 @@ async function submitPreOrder() {
// ==========================================
function openQrModal() {
+ if (currentStudent) {
+ const limiteDiario = currentStudent.limite_diario_colones || 0;
+ const gastadoHoy = currentStudent.gastado_hoy || 0;
+ const saldoRetenido = currentStudent.saldo_retenido || 0;
+ const disponibleHoy = (typeof currentStudent.disponible_hoy === 'number')
+ ? currentStudent.disponible_hoy
+ : Math.max(0, limiteDiario - gastadoHoy - saldoRetenido);
+
+ const tienePreordenes = Boolean(currentStudent.tiene_preordenes_pendientes || (currentStudent.preordenes_pendientes_count > 0));
+
+ // Si superó su límite diario y NO tiene pre-órdenes pendientes, bloquear apertura
+ if (disponibleHoy <= 0 && !tienePreordenes) {
+ if (window.sounds) window.sounds.playError();
+ alert(`⛔ Límite Diario Alcanzado\n\nHas consumido tu límite máximo diario de ₡${limiteDiario.toLocaleString('es-CR')} establecido por tus padres.\n\nNo es posible generar códigos QR para nuevas compras hasta la siguiente jornada escolar.`);
+ resetPwaNavActive();
+ return;
+ }
+
+ // Si tiene pre-órdenes pendientes pero agotó el límite diario de mostrador, mostrar aviso informativo
+ const preBanner = document.getElementById('qrPreorderOnlyBanner');
+ if (preBanner) {
+ preBanner.style.display = (disponibleHoy <= 0 && tienePreordenes) ? 'block' : 'none';
+ }
+ }
+
if (window.sounds) window.sounds.playScanChirp();
document.getElementById('modalQr').style.display = 'flex';
}
@@ -2717,10 +2801,13 @@ function renderParentDashboardView() {
${isBlocked ? 'BLOQUEADO' : ''}
-