feat(student): autorecarga sinpe y presupuesto personal para alumnos autoadministrados v20.8
This commit is contained in:
+193
-6
@@ -3212,14 +3212,34 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- BANNER DE LÍMITE DIARIO Y DISPONIBILIDAD (SÓLO LECTURA INFORMATIVA PARA EL ESTUDIANTE) -->
|
||||
<div class="daily-limit-badge" id="dailyLimitBadge" style="cursor: default;" title="Límite diario establecido por tus padres">
|
||||
<!-- ACCIONES RÁPIDAS DEL MONEDERO DEL ESTUDIANTE (AUTORECARGA SINPE Y PRESUPUESTO) -->
|
||||
<div class="wallet-student-quick-actions" id="walletStudentQuickActions" style="display: flex; gap: 8px; margin: 0 auto 12px auto; max-width: 440px; width: calc(100% - 24px); box-sizing: border-box;">
|
||||
<button type="button" class="btn-wallet-quick-action" id="btnStudentSinpeRecharge" onclick="abrirModalRecargaSinpeEstudiante()" style="flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 12px; background: linear-gradient(135deg, #0284c7, #0369a1); border: none; border-radius: 12px; color: #ffffff; font-weight: 800; font-size: 0.8rem; cursor: pointer; box-shadow: 0 4px 12px rgba(2, 132, 199, 0.22); transition: transform 0.15s ease;">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="20" x="5" y="2" rx="2" ry="2"/><line x1="12" x2="12.01" y1="18" y2="18"/></svg>
|
||||
<span>Recargar SINPE</span>
|
||||
</button>
|
||||
<button type="button" class="btn-wallet-quick-action" id="btnStudentPresupuesto" onclick="abrirModalPresupuestoPersonal()" style="flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 12px; background: var(--card-bg, #ffffff); border: 1.5px solid var(--border, #cbd5e1); border-radius: 12px; color: var(--text-main, #0f172a); font-weight: 800; font-size: 0.8rem; cursor: pointer; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); transition: transform 0.15s ease;">
|
||||
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#0284c7" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m10 15 5-3-5-3v6Z"/></svg>
|
||||
<span id="btnStudentPresupuestoLabel">Mi Presupuesto</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- BANNER DE LÍMITE DIARIO Y DISPONIBILIDAD (INTERACTIVO PARA ESTUDIANTES) -->
|
||||
<div class="daily-limit-badge" id="dailyLimitBadge" style="cursor: pointer; flex-direction: column; align-items: stretch; gap: 5px; margin: 0 auto 14px auto; max-width: 440px; width: calc(100% - 24px); box-sizing: border-box;" onclick="handleDailyLimitBadgeClick()" title="Toca para ver o ajustar tu presupuesto">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
|
||||
<div>
|
||||
<span>Límite diario fijado: </span>
|
||||
<span id="dailyLimitBadgeTitle">Límite diario fijado: </span>
|
||||
<strong id="dailyLimitText">₡0</strong>
|
||||
</div>
|
||||
<div style="font-size: 0.76rem; color: var(--text-muted);" id="dailyAvailableText">
|
||||
Disponible hoy: ₡0
|
||||
<span id="dailyLimitEditHint" style="font-size: 0.72rem; color: #0284c7; font-weight: 800; background: #e0f2fe; padding: 2px 8px; border-radius: 6px; display: none;">🎯 Ajustar</span>
|
||||
</div>
|
||||
<div style="font-size: 0.76rem; color: var(--text-muted); display: flex; justify-content: space-between; align-items: center; width: 100%;">
|
||||
<span id="dailyAvailableText">Disponible hoy: ₡0</span>
|
||||
<span id="dailyGastadoText" style="font-size: 0.72rem; color: #64748b;">Gastado hoy: ₡0</span>
|
||||
</div>
|
||||
<!-- Barra de progreso visual del presupuesto para el estudiante -->
|
||||
<div id="studentBudgetProgressBarContainer" style="display: none; width: 100%; height: 6px; background: #e2e8f0; border-radius: 6px; overflow: hidden; margin-top: 2px;">
|
||||
<div id="studentBudgetProgressBar" style="width: 0%; height: 100%; background: #10b981; border-radius: 6px; transition: width 0.3s ease, background 0.3s ease;"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5292,6 +5312,173 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL: AUTORECARGA DE SALDO CON SINPE MÓVIL PARA ESTUDIANTES -->
|
||||
<div class="modal-qr-backdrop modal-sinpe-backdrop" id="modalRecargaSinpeEstudiante" style="display: none;" onclick="handleModalRecargaSinpeEstudianteBackdrop(event)">
|
||||
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; width: 92%; padding: 22px 20px; border-radius: 22px; box-shadow: 0 20px 40px rgba(0,0,0,0.25); text-align: left; background: var(--card-bg, #ffffff); max-height: 90vh; overflow-y: auto; box-sizing: border-box;">
|
||||
|
||||
<!-- Encabezado con Botón Cerrar -->
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; border-bottom: 1.5px solid var(--border, #e2e8f0); padding-bottom: 10px;">
|
||||
<div style="display: flex; align-items: center; gap: 10px;">
|
||||
<div style="width: 40px; height: 40px; border-radius: 12px; background: #e0f2fe; display: flex; align-items: center; justify-content: center; font-size: 1.25rem;">
|
||||
📲
|
||||
</div>
|
||||
<div>
|
||||
<h3 style="margin: 0; font-size: 1.1rem; font-weight: 800; color: var(--text-main, #0f172a);">Recargar con SINPE</h3>
|
||||
<span style="font-size: 0.74rem; color: var(--text-muted, #64748b);">Acredita saldo a tu monedero escolar</span>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onclick="cerrarModalRecargaSinpeEstudiante()" style="background: none; border: none; font-size: 1.4rem; color: #94a3b8; cursor: pointer; padding: 4px; line-height: 1;" title="Cerrar">✕</button>
|
||||
</div>
|
||||
|
||||
<!-- Banner si SINPE suspendido en la escuela -->
|
||||
<div id="studentSinpeSuspendedBanner" style="display: none; background: #fef2f2; border: 1.5px solid #fecaca; border-radius: 12px; padding: 10px 12px; font-size: 0.8rem; color: #991b1b; margin-bottom: 12px;">
|
||||
⚠️ <span id="studentSinpeSuspendedMsg">Las recargas SINPE se encuentran temporalmente en pausa técnica.</span>
|
||||
</div>
|
||||
|
||||
<div id="studentSinpeFormContainer">
|
||||
<!-- PASO 1: DATOS BANCARIOS DE LA SODA -->
|
||||
<div style="background: linear-gradient(135deg, #0284c7, #0369a1); border-radius: 16px; padding: 14px 16px; color: #ffffff; margin-bottom: 14px; box-shadow: 0 4px 14px rgba(2, 132, 199, 0.25);">
|
||||
<div style="font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.8px; opacity: 0.88; margin-bottom: 4px;">Envía tu SINPE Móvil al número:</div>
|
||||
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px;">
|
||||
<div style="font-size: 1.45rem; font-weight: 900; letter-spacing: 1px;" id="studentSinpeNumeroDisplay">8888-8888</div>
|
||||
<button type="button" id="btnCopiarTelSinpeEstudiante" onclick="copiarTelefonoSinpeEstudiante()" style="background: rgba(255,255,255,0.22); border: 1px solid rgba(255,255,255,0.35); color: #fff; padding: 6px 12px; border-radius: 8px; font-size: 0.75rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 5px; backdrop-filter: blur(4px);">
|
||||
<span id="lblCopiarTelSinpeEstudiante">📋 Copiar</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div style="border-top: 1px solid rgba(255,255,255,0.2); padding-top: 8px; display: flex; flex-direction: column; gap: 3px; font-size: 0.75rem; opacity: 0.95;">
|
||||
<div>Titular: <strong id="studentSinpeTitularDisplay">Soda Escolar</strong></div>
|
||||
<div>Escuela: <span id="studentSinpeEscuelaDisplay">Centro Educativo</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- PASO 2: CÓDIGO DE DETALLE PARA EL BANCO -->
|
||||
<div style="background: #f8fafc; border: 1.5px dashed #cbd5e1; border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between;">
|
||||
<div>
|
||||
<span style="font-size: 0.7rem; color: #64748b; font-weight: 700; text-transform: uppercase; display: block;">Código de Detalle (Motivo SINPE):</span>
|
||||
<strong id="studentSinpeCodigoDisplay" style="font-family: monospace; font-size: 1.05rem; color: #0284c7; letter-spacing: 1px;">SIBO-CARGANDO</strong>
|
||||
</div>
|
||||
<button type="button" id="btnCopiarCodSinpeEstudiante" onclick="copiarCodigoSinpeEstudiante()" style="background: #e0f2fe; border: 1px solid #bae6fd; color: #0284c7; padding: 6px 10px; border-radius: 8px; font-size: 0.74rem; font-weight: 800; cursor: pointer;">
|
||||
<span id="lblCopiarCodSinpeEstudiante">Copiar</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- PASO 3: MONTO A RECARGAR -->
|
||||
<div style="margin-bottom: 12px;">
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155); margin-bottom: 6px;">
|
||||
1. ¿Cuánto transferiste? (Monto en Colones)
|
||||
</label>
|
||||
|
||||
<!-- Botones rápidos de monto -->
|
||||
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px;">
|
||||
<button type="button" class="btn-monto-quick" onclick="setStudentSinpeMonto(1000)" style="padding: 7px 4px; border-radius: 8px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); font-size: 0.78rem; font-weight: 800; color: var(--text-main, #334155); cursor: pointer;">₡1.000</button>
|
||||
<button type="button" class="btn-monto-quick" onclick="setStudentSinpeMonto(2000)" style="padding: 7px 4px; border-radius: 8px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); font-size: 0.78rem; font-weight: 800; color: var(--text-main, #334155); cursor: pointer;">₡2.000</button>
|
||||
<button type="button" class="btn-monto-quick" onclick="setStudentSinpeMonto(3000)" style="padding: 7px 4px; border-radius: 8px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); font-size: 0.78rem; font-weight: 800; color: var(--text-main, #334155); cursor: pointer;">₡3.000</button>
|
||||
<button type="button" class="btn-monto-quick" onclick="setStudentSinpeMonto(5000)" style="padding: 7px 4px; border-radius: 8px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); font-size: 0.78rem; font-weight: 800; color: var(--text-main, #334155); cursor: pointer;">₡5.000</button>
|
||||
</div>
|
||||
|
||||
<input type="number" id="inputStudentSinpeMonto" min="500" step="500" placeholder="Escribe el monto en colones (ej. 2500)" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); color: var(--text-main, #0f172a); font-size: 0.92rem; font-weight: 700; box-sizing: border-box;">
|
||||
</div>
|
||||
|
||||
<!-- PASO 4: NÚMERO DE COMPROBANTE -->
|
||||
<div style="margin-bottom: 16px;">
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155); margin-bottom: 6px;">
|
||||
2. Número de Comprobante / Referencia Bancaria
|
||||
</label>
|
||||
<input type="text" id="inputStudentSinpeComprobante" placeholder="Ej. 123456789 (del SMS o app del banco)" style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); color: var(--text-main, #0f172a); font-size: 0.92rem; font-weight: 700; box-sizing: border-box;">
|
||||
<span style="display: block; font-size: 0.7rem; color: #64748b; margin-top: 4px;">Asegúrate de ingresar el número que te brindó tu banco al completar el SINPE.</span>
|
||||
</div>
|
||||
|
||||
<!-- BOTÓN PRINCIPAL DE ENVÍO -->
|
||||
<button type="button" id="btnEnviarRecargaSinpeEstudiante" onclick="enviarRecargaSinpeEstudiante()" class="btn-saas btn-saas-primary" style="width: 100%; height: 44px; font-size: 0.92rem; font-weight: 800; border-radius: 12px; justify-content: center; cursor: pointer;">
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
|
||||
<span id="btnEnviarRecargaSinpeEstudianteTxt">Validar y Recargar Saldo</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL: PRESUPUESTO PERSONAL / CONTROL DE GASTOS PARA ESTUDIANTES -->
|
||||
<div class="modal-qr-backdrop modal-sinpe-backdrop" id="modalPresupuestoEstudiante" style="display: none;" onclick="handleModalPresupuestoEstudianteBackdrop(event)">
|
||||
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; width: 92%; padding: 22px 20px; border-radius: 22px; box-shadow: 0 20px 40px rgba(0,0,0,0.25); text-align: left; background: var(--card-bg, #ffffff); max-height: 90vh; overflow-y: auto; box-sizing: border-box;">
|
||||
|
||||
<!-- Encabezado con Botón Cerrar -->
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; border-bottom: 1.5px solid var(--border, #e2e8f0); padding-bottom: 10px;">
|
||||
<div style="display: flex; align-items: center; gap: 10px;">
|
||||
<div style="width: 40px; height: 40px; border-radius: 12px; background: #fef3c7; display: flex; align-items: center; justify-content: center; font-size: 1.25rem;">
|
||||
🎯
|
||||
</div>
|
||||
<div>
|
||||
<h3 style="margin: 0; font-size: 1.1rem; font-weight: 800; color: var(--text-main, #0f172a);">Mi Presupuesto Diario</h3>
|
||||
<span style="font-size: 0.74rem; color: var(--text-muted, #64748b);">Controla tus gastos diarios del recreo</span>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" onclick="cerrarModalPresupuestoEstudiante()" style="background: none; border: none; font-size: 1.4rem; color: #94a3b8; cursor: pointer; padding: 4px; line-height: 1;" title="Cerrar">✕</button>
|
||||
</div>
|
||||
|
||||
<!-- TARJETA RESUMEN DE PROGRESO DE HOY -->
|
||||
<div style="background: var(--bg-main, #f8fafc); border: 1.5px solid var(--border, #e2e8f0); border-radius: 16px; padding: 14px 16px; margin-bottom: 14px;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
|
||||
<span style="font-size: 0.76rem; font-weight: 700; color: var(--text-muted, #64748b); text-transform: uppercase;">Consumo de hoy:</span>
|
||||
<strong id="modalPresupuestoPorcentaje" style="font-size: 0.88rem; color: #10b981; font-weight: 800;">0%</strong>
|
||||
</div>
|
||||
|
||||
<!-- Barra de progreso visual -->
|
||||
<div style="width: 100%; height: 10px; background: #e2e8f0; border-radius: 10px; overflow: hidden; margin-bottom: 10px;">
|
||||
<div id="modalPresupuestoBar" style="width: 0%; height: 100%; background: #10b981; border-radius: 10px; transition: width 0.3s ease, background 0.3s ease;"></div>
|
||||
</div>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 0.8rem;">
|
||||
<div style="background: var(--card-bg, #ffffff); padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border, #e2e8f0);">
|
||||
<span style="display: block; font-size: 0.7rem; color: var(--text-muted, #64748b);">Gastado hoy</span>
|
||||
<strong id="modalPresupuestoGastado" style="font-size: 0.95rem; color: var(--text-main, #334155);">₡0</strong>
|
||||
</div>
|
||||
<div style="background: var(--card-bg, #ffffff); padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border, #e2e8f0);">
|
||||
<span style="display: block; font-size: 0.7rem; color: var(--text-muted, #64748b);">Disponible hoy</span>
|
||||
<strong id="modalPresupuestoDisponible" style="font-size: 0.95rem; color: #0284c7;">₡0</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECCIÓN DE CONFIGURACIÓN DE META DIARIA -->
|
||||
<div id="studentPresupuestoEditorSection">
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 700; color: var(--text-main, #334155); margin-bottom: 6px;">
|
||||
Fija o ajusta tu meta diaria de consumo:
|
||||
</label>
|
||||
|
||||
<!-- Botones rápidos de presupuesto -->
|
||||
<div id="studentPresupuestoQuickButtons" style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px;">
|
||||
<button type="button" class="btn-budget-quick" onclick="setStudentBudgetMonto(1500)" style="padding: 7px 4px; border-radius: 8px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); font-size: 0.78rem; font-weight: 800; color: var(--text-main, #334155); cursor: pointer;">₡1.500</button>
|
||||
<button type="button" class="btn-budget-quick" onclick="setStudentBudgetMonto(2000)" style="padding: 7px 4px; border-radius: 8px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); font-size: 0.78rem; font-weight: 800; color: var(--text-main, #334155); cursor: pointer;">₡2.000</button>
|
||||
<button type="button" class="btn-budget-quick" onclick="setStudentBudgetMonto(3000)" style="padding: 7px 4px; border-radius: 8px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); font-size: 0.78rem; font-weight: 800; color: var(--text-main, #334155); cursor: pointer;">₡3.000</button>
|
||||
<button type="button" class="btn-budget-quick" onclick="setStudentBudgetMonto(5000)" style="padding: 7px 4px; border-radius: 8px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); font-size: 0.78rem; font-weight: 800; color: var(--text-main, #334155); cursor: pointer;">₡5.000</button>
|
||||
</div>
|
||||
|
||||
<div style="position: relative; margin-bottom: 12px;">
|
||||
<input type="number" id="inputStudentPresupuestoMonto" min="500" step="500" placeholder="Escribe tu límite diario en colones..." style="width: 100%; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--border, #cbd5e1); background: var(--bg-main, #ffffff); color: var(--text-main, #0f172a); font-size: 0.95rem; font-weight: 700; box-sizing: border-box;">
|
||||
</div>
|
||||
|
||||
<!-- MENSAJE EDUCATIVO -->
|
||||
<div style="background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 12px; padding: 10px 12px; font-size: 0.74rem; color: #065f46; line-height: 1.4; margin-bottom: 14px;">
|
||||
💡 <strong>Tip financiero:</strong> Fijar un presupuesto voluntario te ayuda a no gastar todo tu saldo en un solo recreo y asegurar tus meriendas toda la semana escolar.
|
||||
</div>
|
||||
|
||||
<!-- AVISO SI ES CONTROLADO POR PADRES -->
|
||||
<div id="modalPresupuestoParentLockedNotice" style="display: none; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 12px; padding: 10px 12px; font-size: 0.75rem; color: #1e40af; margin-bottom: 14px;">
|
||||
ℹ️ <strong>Control Parental:</strong> Este límite fue establecido por tu encargado de familia. Si necesitas modificarlo, coordina con él o ella para que lo actualice desde su portal.
|
||||
</div>
|
||||
|
||||
<!-- BOTÓN GUARDAR -->
|
||||
<button type="button" id="btnGuardarPresupuestoEstudiante" onclick="guardarPresupuestoPersonalEstudiante()" class="btn-saas btn-saas-primary" style="width: 100%; height: 44px; font-size: 0.92rem; font-weight: 800; border-radius: 12px; justify-content: center; cursor: pointer;">
|
||||
Guardar Presupuesto
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MODAL: RECHAZAR RECARGA SINPE CON MOTIVO Y TRAZABILIDAD -->
|
||||
<div class="modal-qr-backdrop" id="modalRechazarSinpe" style="display: none; z-index: 99999;">
|
||||
<div class="modal-qr-card" onclick="event.stopPropagation()" style="max-width: 440px; text-align: left; padding: 22px; border-radius: 18px;">
|
||||
@@ -5480,6 +5667,6 @@
|
||||
<script src="/js/sounds.js?v=19.4"></script>
|
||||
<script src="/js/jsQR.js" defer></script>
|
||||
<script src="/js/food-icons.js?v=19.4" defer></script>
|
||||
<script src="/js/app.js?v=20.7"></script>
|
||||
<script src="/js/app.js?v=20.8"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+464
-30
@@ -1167,6 +1167,45 @@ function updateStudentUI() {
|
||||
? currentStudent.disponible_hoy
|
||||
: Math.max(0, limiteDiario - gastadoHoy - saldoRetenido);
|
||||
|
||||
const isSelfManaged = !currentStudent.padre_usuario_id;
|
||||
const badgeTitleEl = document.getElementById('dailyLimitBadgeTitle');
|
||||
const editHintEl = document.getElementById('dailyLimitEditHint');
|
||||
const badgeEl = document.getElementById('dailyLimitBadge');
|
||||
const gastadoEl = document.getElementById('dailyGastadoText');
|
||||
const progressContainer = document.getElementById('studentBudgetProgressBarContainer');
|
||||
const progressBar = document.getElementById('studentBudgetProgressBar');
|
||||
const btnPresupuestoLabel = document.getElementById('btnStudentPresupuestoLabel');
|
||||
|
||||
if (badgeTitleEl) {
|
||||
badgeTitleEl.textContent = isSelfManaged ? 'Mi Presupuesto Diario: ' : 'Límite diario fijado: ';
|
||||
}
|
||||
if (btnPresupuestoLabel) {
|
||||
btnPresupuestoLabel.textContent = isSelfManaged ? 'Mi Presupuesto' : 'Ver Presupuesto';
|
||||
}
|
||||
if (editHintEl) {
|
||||
editHintEl.style.display = isSelfManaged ? 'inline-block' : 'none';
|
||||
}
|
||||
if (badgeEl) {
|
||||
badgeEl.title = isSelfManaged ? 'Toca para ajustar tu meta diaria de gasto' : 'Límite diario establecido por tus padres';
|
||||
}
|
||||
if (gastadoEl) {
|
||||
gastadoEl.textContent = `Gastado hoy: ₡${gastadoHoy.toLocaleString('es-CR')}`;
|
||||
}
|
||||
|
||||
// Barra de progreso del presupuesto
|
||||
if (progressContainer && progressBar) {
|
||||
progressContainer.style.display = 'block';
|
||||
const pct = limiteDiario > 0 ? Math.min(100, Math.round((gastadoHoy / limiteDiario) * 100)) : 0;
|
||||
progressBar.style.width = `${pct}%`;
|
||||
if (pct >= 100) {
|
||||
progressBar.style.background = '#ef4444';
|
||||
} else if (pct >= 70) {
|
||||
progressBar.style.background = '#f59e0b';
|
||||
} else {
|
||||
progressBar.style.background = '#10b981';
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('dailyLimitText').textContent = `₡${limiteDiario.toLocaleString('es-CR')}`;
|
||||
document.getElementById('dailyAvailableText').textContent = `Disponible hoy: ₡${disponibleHoy.toLocaleString('es-CR')}`;
|
||||
|
||||
@@ -1182,7 +1221,9 @@ function updateStudentUI() {
|
||||
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.`;
|
||||
: (isSelfManaged
|
||||
? `Has consumido tu presupuesto diario de ₡${limiteDiario.toLocaleString('es-CR')}. Si necesitas realizar más compras hoy, puedes ajustar tu presupuesto personal tocando "Mi Presupuesto".`
|
||||
: `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';
|
||||
@@ -2037,6 +2078,25 @@ async function submitPreOrder() {
|
||||
cantidad: item.cantidad
|
||||
}));
|
||||
|
||||
// Verificación preventiva de presupuesto personal para alumnos autoadministrados
|
||||
const totalCart = cart.reduce((acc, it) => acc + (it.product.precio_colones * it.cantidad), 0);
|
||||
const limiteDiario = targetStudent.limite_diario_colones || 0;
|
||||
const gastadoHoy = targetStudent.gastado_hoy || 0;
|
||||
const retenido = targetStudent.saldo_retenido || 0;
|
||||
const disponibleHoy = Math.max(0, limiteDiario - gastadoHoy - retenido);
|
||||
|
||||
if (limiteDiario > 0 && totalCart > disponibleHoy) {
|
||||
const isSelfManaged = !targetStudent.padre_usuario_id;
|
||||
if (isSelfManaged && (!currentUser || currentUser.rol === 'estudiante')) {
|
||||
const respAjustar = confirm(`⚠️ Aviso de Presupuesto Personal:\n\nEste pedido suma ₡${totalCart.toLocaleString('es-CR')} y tu presupuesto disponible para hoy es de ₡${disponibleHoy.toLocaleString('es-CR')}.\n\nComo estudiante independiente, ¿deseas ajustar tu presupuesto diario personal antes de realizar este pedido?`);
|
||||
if (respAjustar) {
|
||||
closeCartModal();
|
||||
abrirModalPresupuestoPersonal();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const btn = document.getElementById('btnConfirmarOrden');
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Procesando en la soda...';
|
||||
@@ -2623,10 +2683,11 @@ function toggleParentPanel(show, e) {
|
||||
}
|
||||
|
||||
function openDailyLimitEditor() {
|
||||
// SEGURIDAD: Los estudiantes no pueden modificar su límite diario
|
||||
if (!currentUser || currentUser.rol === 'estudiante') {
|
||||
if (currentUser && currentUser.rol === 'estudiante') {
|
||||
abrirModalPresupuestoPersonal();
|
||||
return;
|
||||
}
|
||||
if (!currentUser) return;
|
||||
toggleParentPanel(true);
|
||||
setTimeout(() => {
|
||||
const input = document.getElementById('inputCustomDailyLimit');
|
||||
@@ -5266,19 +5327,32 @@ async function executeParentSinpeRecharge() {
|
||||
`;
|
||||
}
|
||||
|
||||
currentSinpePollingData = {
|
||||
await ejecutarSondeoValidacionSinpe({
|
||||
studentId: currentParentChild.id,
|
||||
studentName: currentParentChild.nombre_completo,
|
||||
monto,
|
||||
codigo,
|
||||
comprobante
|
||||
comprobante,
|
||||
isStudentMode: false,
|
||||
btn
|
||||
});
|
||||
}
|
||||
|
||||
async function ejecutarSondeoValidacionSinpe({ studentId, studentName, monto, codigo, comprobante, isStudentMode, btn }) {
|
||||
currentSinpePollingData = {
|
||||
studentId,
|
||||
studentName,
|
||||
monto,
|
||||
codigo,
|
||||
comprobante,
|
||||
isStudentMode: Boolean(isStudentMode)
|
||||
};
|
||||
|
||||
// Abrir modal con estado LOADING (sin barra ni contador de segundos)
|
||||
showSinpeModal('loading', {
|
||||
studentName: currentParentChild.nombre_completo,
|
||||
monto: monto,
|
||||
codigo: codigo
|
||||
studentName,
|
||||
monto,
|
||||
codigo
|
||||
});
|
||||
|
||||
const pollIntervalMs = 3000; // Consulta cada 3 segundos
|
||||
@@ -5320,8 +5394,8 @@ async function executeParentSinpeRecharge() {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
estudiante_id: currentParentChild.id,
|
||||
padre_usuario_id: currentUser ? currentUser.id : null,
|
||||
estudiante_id: studentId,
|
||||
padre_usuario_id: currentUser && currentUser.rol === 'padre' ? currentUser.id : null,
|
||||
monto,
|
||||
codigo,
|
||||
comprobante: comprobante || null
|
||||
@@ -5359,28 +5433,47 @@ async function executeParentSinpeRecharge() {
|
||||
if (verifiedData && verifiedData.verificado) {
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
|
||||
const baseSaldo = (currentParentChild && currentParentChild.id === studentId)
|
||||
? (currentParentChild.saldo_colones || 0)
|
||||
: ((currentStudent && currentStudent.id === studentId) ? (currentStudent.saldo_colones || 0) : 0);
|
||||
|
||||
const nuevoSaldo = typeof verifiedData.saldo_nuevo === 'number'
|
||||
? verifiedData.saldo_nuevo
|
||||
: (currentParentChild.saldo_colones + monto);
|
||||
: (baseSaldo + monto);
|
||||
|
||||
if (currentParentChild && currentParentChild.id === studentId) {
|
||||
currentParentChild.saldo_colones = nuevoSaldo;
|
||||
renderActiveChildDetails(currentParentChild);
|
||||
}
|
||||
if (currentStudent && currentStudent.id === studentId) {
|
||||
currentStudent.saldo_colones = nuevoSaldo;
|
||||
updateStudentUI();
|
||||
}
|
||||
|
||||
if (inputMonto) inputMonto.value = '';
|
||||
if (inputComp) inputComp.value = '';
|
||||
const inputParentMonto = document.getElementById('inputParentSinpeMonto');
|
||||
const inputParentComp = document.getElementById('inputParentSinpeComprobante');
|
||||
if (inputParentMonto) inputParentMonto.value = '';
|
||||
if (inputParentComp) inputParentComp.value = '';
|
||||
|
||||
const inputStudentMonto = document.getElementById('inputStudentSinpeMonto');
|
||||
const inputStudentComp = document.getElementById('inputStudentSinpeComprobante');
|
||||
if (inputStudentMonto) inputStudentMonto.value = '';
|
||||
if (inputStudentComp) inputStudentComp.value = '';
|
||||
|
||||
showSinpeModal('success', {
|
||||
studentName: currentParentChild.nombre_completo,
|
||||
monto: monto,
|
||||
studentName,
|
||||
monto,
|
||||
banco: verifiedData.banco || 'Bancario',
|
||||
comprobante: verifiedData.comprobante || verifiedData.codigo || codigo,
|
||||
codigo: codigo,
|
||||
nuevoSaldo: nuevoSaldo
|
||||
codigo,
|
||||
nuevoSaldo
|
||||
});
|
||||
|
||||
if (currentParentChild && currentParentChild.id === studentId) {
|
||||
await loadParentSinpeRequests(currentParentChild.id);
|
||||
clearSinpeSession();
|
||||
obtenerNuevoCodigoSinpe();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5402,9 +5495,9 @@ async function executeParentSinpeRecharge() {
|
||||
// ============================================
|
||||
if (window.sounds) window.sounds.playTap();
|
||||
showSinpeModal('timeout', {
|
||||
studentName: currentParentChild.nombre_completo,
|
||||
monto: monto,
|
||||
codigo: codigo
|
||||
studentName,
|
||||
monto,
|
||||
codigo
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
@@ -5418,12 +5511,17 @@ async function executeParentSinpeRecharge() {
|
||||
} finally {
|
||||
if (btn) {
|
||||
btn.disabled = false;
|
||||
if (isStudentMode) {
|
||||
const btnTxt = document.getElementById('btnEnviarRecargaSinpeEstudianteTxt');
|
||||
if (btnTxt) btnTxt.textContent = 'Validar y Recargar Saldo';
|
||||
} else {
|
||||
btn.innerHTML = `
|
||||
<svg width="17" height="17" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.3" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
|
||||
<span id="btnParentValidarSinpeText">Validar SINPE</span>
|
||||
`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function retrySinpeWaitMore() {
|
||||
@@ -5505,22 +5603,36 @@ async function retrySinpeWaitMore() {
|
||||
|
||||
if (verifiedData && verifiedData.verificado) {
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
|
||||
const baseSaldo = (currentParentChild && currentParentChild.id === studentId)
|
||||
? (currentParentChild.saldo_colones || 0)
|
||||
: ((currentStudent && currentStudent.id === studentId) ? (currentStudent.saldo_colones || 0) : 0);
|
||||
|
||||
const nuevoSaldo = typeof verifiedData.saldo_nuevo === 'number'
|
||||
? verifiedData.saldo_nuevo
|
||||
: ((currentParentChild ? currentParentChild.saldo_colones : 0) + monto);
|
||||
: (baseSaldo + monto);
|
||||
|
||||
if (currentParentChild) {
|
||||
if (currentParentChild && currentParentChild.id === studentId) {
|
||||
currentParentChild.saldo_colones = nuevoSaldo;
|
||||
renderActiveChildDetails(currentParentChild);
|
||||
}
|
||||
if (currentStudent && currentStudent.id === studentId) {
|
||||
currentStudent.saldo_colones = nuevoSaldo;
|
||||
updateStudentUI();
|
||||
}
|
||||
|
||||
const inputMonto = document.getElementById('inputParentSinpeMonto');
|
||||
const inputComp = document.getElementById('inputParentSinpeComprobante');
|
||||
if (inputMonto) inputMonto.value = '';
|
||||
if (inputComp) inputComp.value = '';
|
||||
|
||||
const inputStudentMonto = document.getElementById('inputStudentSinpeMonto');
|
||||
const inputStudentComp = document.getElementById('inputStudentSinpeComprobante');
|
||||
if (inputStudentMonto) inputStudentMonto.value = '';
|
||||
if (inputStudentComp) inputStudentComp.value = '';
|
||||
|
||||
showSinpeModal('success', {
|
||||
studentName: studentName || (currentParentChild ? currentParentChild.nombre_completo : ''),
|
||||
studentName: studentName || (currentParentChild ? currentParentChild.nombre_completo : (currentStudent ? currentStudent.nombre_completo : '')),
|
||||
monto,
|
||||
banco: verifiedData.banco || 'Bancario',
|
||||
comprobante: verifiedData.comprobante || verifiedData.codigo || codigo,
|
||||
@@ -5528,11 +5640,11 @@ async function retrySinpeWaitMore() {
|
||||
nuevoSaldo
|
||||
});
|
||||
|
||||
if (currentParentChild) {
|
||||
if (currentParentChild && currentParentChild.id === studentId) {
|
||||
await loadParentSinpeRequests(currentParentChild.id);
|
||||
}
|
||||
clearSinpeSession();
|
||||
obtenerNuevoCodigoSinpe();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5574,11 +5686,13 @@ async function confirmSinpeSendManualReview() {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
estudiante_id: studentId,
|
||||
padre_usuario_id: currentUser ? currentUser.id : null,
|
||||
padre_usuario_id: currentUser && currentUser.rol === 'padre' ? currentUser.id : null,
|
||||
monto,
|
||||
comprobante: comprobante || `SINPE-${codigo}`,
|
||||
codigo_detalle: codigo,
|
||||
notas: `Portal de Padres - Código: ${codigo}`
|
||||
notas: (currentUser && currentUser.rol === 'padre')
|
||||
? `Portal de Padres - Código: ${codigo}`
|
||||
: `Autorecarga estudiante: ${studentName || ''}`
|
||||
})
|
||||
});
|
||||
} catch (solErr) {
|
||||
@@ -5590,19 +5704,339 @@ async function confirmSinpeSendManualReview() {
|
||||
if (inputMonto) inputMonto.value = '';
|
||||
if (inputComp) inputComp.value = '';
|
||||
|
||||
const inputStudentMonto = document.getElementById('inputStudentSinpeMonto');
|
||||
const inputStudentComp = document.getElementById('inputStudentSinpeComprobante');
|
||||
if (inputStudentMonto) inputStudentMonto.value = '';
|
||||
if (inputStudentComp) inputStudentComp.value = '';
|
||||
|
||||
showSinpeModal('pending', {
|
||||
studentName: studentName || (currentParentChild ? currentParentChild.nombre_completo : ''),
|
||||
studentName: studentName || (currentParentChild ? currentParentChild.nombre_completo : (currentStudent ? currentStudent.nombre_completo : '')),
|
||||
monto,
|
||||
codigo
|
||||
});
|
||||
|
||||
if (currentParentChild) {
|
||||
if (currentParentChild && currentParentChild.id === studentId) {
|
||||
await loadParentSinpeRequests(currentParentChild.id);
|
||||
}
|
||||
clearSinpeSession();
|
||||
obtenerNuevoCodigoSinpe();
|
||||
}
|
||||
if (currentStudent && currentStudent.id === studentId) {
|
||||
updateStudentUI();
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// AUTORECARGA SINPE PARA ESTUDIANTES AUTOADMINISTRADOS
|
||||
// ==========================================
|
||||
let currentStudentSinpeCode = null;
|
||||
|
||||
async function abrirModalRecargaSinpeEstudiante() {
|
||||
if (!currentStudent) return;
|
||||
const modal = document.getElementById('modalRecargaSinpeEstudiante');
|
||||
if (!modal) return;
|
||||
|
||||
const numEl = document.getElementById('studentSinpeNumeroDisplay');
|
||||
const titEl = document.getElementById('studentSinpeTitularDisplay');
|
||||
const escEl = document.getElementById('studentSinpeEscuelaDisplay');
|
||||
const codEl = document.getElementById('studentSinpeCodigoDisplay');
|
||||
const bannerSusp = document.getElementById('studentSinpeSuspendedBanner');
|
||||
const msgSusp = document.getElementById('studentSinpeSuspendedMsg');
|
||||
const formBox = document.getElementById('studentSinpeFormContainer');
|
||||
|
||||
if (codEl) codEl.textContent = 'GENERANDO...';
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/sinpe/generar-codigo', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ estudiante_id: currentStudent.id })
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.suspended) {
|
||||
if (bannerSusp) bannerSusp.style.display = 'block';
|
||||
if (msgSusp && data.mensaje_suspension) msgSusp.textContent = data.mensaje_suspension;
|
||||
if (formBox) {
|
||||
formBox.style.opacity = '0.4';
|
||||
formBox.style.pointerEvents = 'none';
|
||||
}
|
||||
} else {
|
||||
if (bannerSusp) bannerSusp.style.display = 'none';
|
||||
if (formBox) {
|
||||
formBox.style.opacity = '1';
|
||||
formBox.style.pointerEvents = 'auto';
|
||||
}
|
||||
}
|
||||
|
||||
if (numEl && data.telefono_sinpe) numEl.textContent = data.telefono_sinpe;
|
||||
if (titEl && data.titular_sinpe) titEl.textContent = data.titular_sinpe;
|
||||
if (escEl && data.escuela_nombre) escEl.textContent = data.escuela_nombre;
|
||||
|
||||
currentStudentSinpeCode = data.codigo || `SIBO-${currentStudent.codigo_estudiante || ''}`;
|
||||
if (codEl) codEl.textContent = currentStudentSinpeCode;
|
||||
|
||||
} catch (e) {
|
||||
console.warn('Error cargando datos SINPE para estudiante:', e);
|
||||
currentStudentSinpeCode = `SIBO-${currentStudent.codigo_estudiante || ''}`;
|
||||
if (codEl) codEl.textContent = currentStudentSinpeCode;
|
||||
}
|
||||
|
||||
const inpMonto = document.getElementById('inputStudentSinpeMonto');
|
||||
const inpComp = document.getElementById('inputStudentSinpeComprobante');
|
||||
if (inpMonto) inpMonto.value = '';
|
||||
if (inpComp) inpComp.value = '';
|
||||
|
||||
modal.style.display = 'flex';
|
||||
if (window.sounds) window.sounds.playTap();
|
||||
}
|
||||
|
||||
function cerrarModalRecargaSinpeEstudiante() {
|
||||
const modal = document.getElementById('modalRecargaSinpeEstudiante');
|
||||
if (modal) modal.style.display = 'none';
|
||||
}
|
||||
|
||||
function handleModalRecargaSinpeEstudianteBackdrop(event) {
|
||||
if (event && event.target && event.target.id === 'modalRecargaSinpeEstudiante') {
|
||||
cerrarModalRecargaSinpeEstudiante();
|
||||
}
|
||||
}
|
||||
|
||||
function copiarTelefonoSinpeEstudiante() {
|
||||
const tel = (document.getElementById('studentSinpeNumeroDisplay')?.textContent || '').trim();
|
||||
if (!tel) return;
|
||||
|
||||
const lbl = document.getElementById('lblCopiarTelSinpeEstudiante');
|
||||
const onDone = () => {
|
||||
if (window.sounds) window.sounds.playTap();
|
||||
if (lbl) lbl.textContent = '¡Copiado! ✓';
|
||||
setTimeout(() => { if (lbl) lbl.textContent = '📋 Copiar'; }, 2000);
|
||||
};
|
||||
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(tel.replace(/\D/g, '')).then(onDone).catch(() => fallbackCopyText(tel.replace(/\D/g, ''), onDone));
|
||||
} else {
|
||||
fallbackCopyText(tel.replace(/\D/g, ''), onDone);
|
||||
}
|
||||
}
|
||||
|
||||
function copiarCodigoSinpeEstudiante() {
|
||||
const cod = currentStudentSinpeCode || (document.getElementById('studentSinpeCodigoDisplay')?.textContent || '').trim();
|
||||
if (!cod || cod.includes('GENERANDO')) return;
|
||||
|
||||
const lbl = document.getElementById('lblCopiarCodSinpeEstudiante');
|
||||
const onDone = () => {
|
||||
if (window.sounds) window.sounds.playTap();
|
||||
if (lbl) lbl.textContent = '¡Copiado! ✓';
|
||||
setTimeout(() => { if (lbl) lbl.textContent = 'Copiar'; }, 2000);
|
||||
};
|
||||
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(cod).then(onDone).catch(() => fallbackCopyText(cod, onDone));
|
||||
} else {
|
||||
fallbackCopyText(cod, onDone);
|
||||
}
|
||||
}
|
||||
|
||||
function setStudentSinpeMonto(monto) {
|
||||
const inp = document.getElementById('inputStudentSinpeMonto');
|
||||
if (inp) {
|
||||
inp.value = monto;
|
||||
inp.focus();
|
||||
}
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
}
|
||||
|
||||
async function enviarRecargaSinpeEstudiante() {
|
||||
if (!currentStudent) return;
|
||||
const bannerSusp = document.getElementById('studentSinpeSuspendedBanner');
|
||||
if (bannerSusp && bannerSusp.style.display !== 'none') {
|
||||
alert('Las recargas por SINPE Móvil se encuentran temporalmente en pausa técnica en esta sede.');
|
||||
return;
|
||||
}
|
||||
|
||||
const inpMonto = document.getElementById('inputStudentSinpeMonto');
|
||||
const inpComp = document.getElementById('inputStudentSinpeComprobante');
|
||||
const monto = parseInt(inpMonto ? inpMonto.value : 0, 10);
|
||||
const comprobante = inpComp ? inpComp.value.trim() : '';
|
||||
const codigo = currentStudentSinpeCode || `SIBO-${currentStudent.codigo_estudiante || ''}`;
|
||||
|
||||
if (isNaN(monto) || monto <= 0) {
|
||||
alert('Por favor ingresa un monto válido mayor a ₡0 para procesar tu recarga SINPE.');
|
||||
if (inpMonto) inpMonto.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!comprobante) {
|
||||
alert('Por favor escribe el número de comprobante o referencia que te brindó el banco.');
|
||||
if (inpComp) inpComp.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
const btn = document.getElementById('btnEnviarRecargaSinpeEstudiante');
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
const btnTxt = document.getElementById('btnEnviarRecargaSinpeEstudianteTxt');
|
||||
if (btnTxt) btnTxt.textContent = 'Validando con el banco...';
|
||||
}
|
||||
|
||||
cerrarModalRecargaSinpeEstudiante();
|
||||
|
||||
await ejecutarSondeoValidacionSinpe({
|
||||
studentId: currentStudent.id,
|
||||
studentName: currentStudent.nombre_completo,
|
||||
monto,
|
||||
codigo,
|
||||
comprobante,
|
||||
isStudentMode: true,
|
||||
btn
|
||||
});
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// PRESUPUESTO PERSONAL / CONTROL DE GASTOS PARA ESTUDIANTES
|
||||
// ==========================================
|
||||
function abrirModalPresupuestoPersonal() {
|
||||
if (!currentStudent) return;
|
||||
const modal = document.getElementById('modalPresupuestoEstudiante');
|
||||
if (!modal) return;
|
||||
|
||||
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 pct = limiteDiario > 0 ? Math.min(100, Math.round((gastadoHoy / limiteDiario) * 100)) : 0;
|
||||
|
||||
const gastadoEl = document.getElementById('modalPresupuestoGastado');
|
||||
const dispEl = document.getElementById('modalPresupuestoDisponible');
|
||||
const pctEl = document.getElementById('modalPresupuestoPorcentaje');
|
||||
const barEl = document.getElementById('modalPresupuestoBar');
|
||||
const inputEl = document.getElementById('inputStudentPresupuestoMonto');
|
||||
const lockedNotice = document.getElementById('modalPresupuestoParentLockedNotice');
|
||||
const quickButtons = document.getElementById('studentPresupuestoQuickButtons');
|
||||
const btnGuardar = document.getElementById('btnGuardarPresupuestoEstudiante');
|
||||
|
||||
if (gastadoEl) gastadoEl.textContent = `₡${gastadoHoy.toLocaleString('es-CR')}`;
|
||||
if (dispEl) dispEl.textContent = `₡${disponibleHoy.toLocaleString('es-CR')}`;
|
||||
if (pctEl) pctEl.textContent = `${pct}%`;
|
||||
if (barEl) {
|
||||
barEl.style.width = `${pct}%`;
|
||||
if (pct >= 100) {
|
||||
barEl.style.background = '#ef4444';
|
||||
if (pctEl) pctEl.style.color = '#ef4444';
|
||||
} else if (pct >= 70) {
|
||||
barEl.style.background = '#f59e0b';
|
||||
if (pctEl) pctEl.style.color = '#f59e0b';
|
||||
} else {
|
||||
barEl.style.background = '#10b981';
|
||||
if (pctEl) pctEl.style.color = '#10b981';
|
||||
}
|
||||
}
|
||||
|
||||
if (inputEl) inputEl.value = limiteDiario;
|
||||
|
||||
const isSelfManaged = !currentStudent.padre_usuario_id;
|
||||
if (isSelfManaged) {
|
||||
if (lockedNotice) lockedNotice.style.display = 'none';
|
||||
if (quickButtons) quickButtons.style.display = 'grid';
|
||||
if (btnGuardar) btnGuardar.style.display = 'flex';
|
||||
if (inputEl) inputEl.disabled = false;
|
||||
} else {
|
||||
if (lockedNotice) lockedNotice.style.display = 'block';
|
||||
if (quickButtons) quickButtons.style.display = 'none';
|
||||
if (btnGuardar) btnGuardar.style.display = 'none';
|
||||
if (inputEl) inputEl.disabled = true;
|
||||
}
|
||||
|
||||
modal.style.display = 'flex';
|
||||
if (window.sounds) window.sounds.playTap();
|
||||
}
|
||||
|
||||
function cerrarModalPresupuestoEstudiante() {
|
||||
const modal = document.getElementById('modalPresupuestoEstudiante');
|
||||
if (modal) modal.style.display = 'none';
|
||||
}
|
||||
|
||||
function handleModalPresupuestoEstudianteBackdrop(event) {
|
||||
if (event && event.target && event.target.id === 'modalPresupuestoEstudiante') {
|
||||
cerrarModalPresupuestoEstudiante();
|
||||
}
|
||||
}
|
||||
|
||||
function setStudentBudgetMonto(monto) {
|
||||
const inputEl = document.getElementById('inputStudentPresupuestoMonto');
|
||||
if (inputEl) {
|
||||
inputEl.value = monto;
|
||||
inputEl.focus();
|
||||
}
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
}
|
||||
|
||||
async function guardarPresupuestoPersonalEstudiante() {
|
||||
if (!currentStudent) return;
|
||||
const inputEl = document.getElementById('inputStudentPresupuestoMonto');
|
||||
const val = parseInt(inputEl ? inputEl.value : 0, 10);
|
||||
|
||||
if (isNaN(val) || val < 500) {
|
||||
alert('Por favor ingresa un presupuesto válido (mínimo ₡500).');
|
||||
if (inputEl) inputEl.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
const btn = document.getElementById('btnGuardarPresupuestoEstudiante');
|
||||
if (btn) {
|
||||
btn.disabled = true;
|
||||
btn.textContent = 'Guardando meta...';
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/estudiantes/${currentStudent.id}/limite`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ limite_diario_colones: val })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Error al actualizar presupuesto');
|
||||
|
||||
currentStudent.limite_diario_colones = val;
|
||||
currentStudent.disponible_hoy = Math.max(0, val - (currentStudent.gastado_hoy || 0) - (currentStudent.saldo_retenido || 0));
|
||||
|
||||
updateStudentUI();
|
||||
cerrarModalPresupuestoEstudiante();
|
||||
|
||||
if (window.sounds) window.sounds.playSuccess();
|
||||
alert(`🎯 ¡Presupuesto Actualizado!\n\nTu meta diaria de gasto ahora es de ₡${val.toLocaleString('es-CR')}.\n\nPodrás monitorear tu barra de consumo en tu monedero escolar.`);
|
||||
} catch (err) {
|
||||
if (window.sounds) window.sounds.playError();
|
||||
alert(`No se pudo guardar el presupuesto: ${err.message}`);
|
||||
} finally {
|
||||
if (btn) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = 'Guardar Presupuesto';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleDailyLimitBadgeClick() {
|
||||
abrirModalPresupuestoPersonal();
|
||||
}
|
||||
|
||||
window.abrirModalRecargaSinpeEstudiante = abrirModalRecargaSinpeEstudiante;
|
||||
window.cerrarModalRecargaSinpeEstudiante = cerrarModalRecargaSinpeEstudiante;
|
||||
window.handleModalRecargaSinpeEstudianteBackdrop = handleModalRecargaSinpeEstudianteBackdrop;
|
||||
window.copiarTelefonoSinpeEstudiante = copiarTelefonoSinpeEstudiante;
|
||||
window.copiarCodigoSinpeEstudiante = copiarCodigoSinpeEstudiante;
|
||||
window.setStudentSinpeMonto = setStudentSinpeMonto;
|
||||
window.enviarRecargaSinpeEstudiante = enviarRecargaSinpeEstudiante;
|
||||
window.abrirModalPresupuestoPersonal = abrirModalPresupuestoPersonal;
|
||||
window.cerrarModalPresupuestoEstudiante = cerrarModalPresupuestoEstudiante;
|
||||
window.handleModalPresupuestoEstudianteBackdrop = handleModalPresupuestoEstudianteBackdrop;
|
||||
window.setStudentBudgetMonto = setStudentBudgetMonto;
|
||||
window.guardarPresupuestoPersonalEstudiante = guardarPresupuestoPersonalEstudiante;
|
||||
window.handleDailyLimitBadgeClick = handleDailyLimitBadgeClick;
|
||||
|
||||
async function loadParentSinpeRequests(studentId) {
|
||||
const box = document.getElementById('parentSinpePendingBox');
|
||||
const list = document.getElementById('parentSinpePendingList');
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
// SiboPay PWA Service Worker v20.7 - Ultra Fast Startup & Stale-While-Revalidate
|
||||
const CACHE_NAME = 'sibopay-v20.7';
|
||||
// SiboPay PWA Service Worker v20.8 - Ultra Fast Startup & Stale-While-Revalidate
|
||||
const CACHE_NAME = 'sibopay-v20.8';
|
||||
const STATIC_ASSETS = [
|
||||
'/',
|
||||
'/index.html',
|
||||
@@ -11,7 +11,7 @@ const STATIC_ASSETS = [
|
||||
'/css/styles.css?v=19.9',
|
||||
'/css/desktop.css?v=2.2',
|
||||
'/js/dialogs.js?v=19.4',
|
||||
'/js/app.js?v=20.7',
|
||||
'/js/app.js?v=20.8',
|
||||
'/js/pos.js?v=20.5',
|
||||
'/js/sounds.js?v=19.4',
|
||||
'/js/food-icons.js?v=19.4',
|
||||
|
||||
Reference in New Issue
Block a user