feat: campos de entrada escrita para limite de gasto diario y recargas SINPE en portal de padres
This commit is contained in:
+60
-22
@@ -206,37 +206,75 @@
|
||||
<button onclick="toggleParentPanel(false)" style="background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #64748b;">✕</button>
|
||||
</div>
|
||||
|
||||
<!-- RECARGA SINPE MÓVIL -->
|
||||
<div style="background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 12px; padding: 14px; margin-bottom: 16px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px; margin-bottom: 8px;">
|
||||
<span style="font-size: 1.4rem;">📱</span>
|
||||
<div>
|
||||
<strong style="color: #166534; font-size: 0.95rem;">Recarga por SINPE Móvil</strong>
|
||||
<p style="font-size: 0.75rem; color: #15803d;">Número de la Soda: <strong>8888-SODA (7632)</strong></p>
|
||||
<!-- RECARGA SINPE MÓVIL (MONTO ESCRITO Y ACCESOS RÁPIDOS) -->
|
||||
<div style="background: #f0fdf4; border: 1.5px solid #86efac; border-radius: 14px; padding: 14px; margin-bottom: 16px;">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<span style="font-size: 1.4rem;">📱</span>
|
||||
<div>
|
||||
<strong style="color: #166534; font-size: 0.95rem;">Recarga por SINPE Móvil</strong>
|
||||
<p style="font-size: 0.74rem; color: #15803d;">Número de la Soda: <strong>8888-SODA (7632)</strong></p>
|
||||
</div>
|
||||
</div>
|
||||
<span style="font-size: 0.7rem; color: #166534; background: #dcfce7; font-weight: 800; padding: 2px 8px; border-radius: 6px;">Acreditación Inmediata</span>
|
||||
</div>
|
||||
|
||||
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px;">
|
||||
<button onclick="quickSinpeRecharge(2000)" style="padding: 8px; background: white; border: 1px solid #86efac; border-radius: 8px; font-weight: 700; color: #166534; cursor: pointer;">+ ₡2.000</button>
|
||||
<button onclick="quickSinpeRecharge(5000)" style="padding: 8px; background: white; border: 1px solid #86efac; border-radius: 8px; font-weight: 700; color: #166534; cursor: pointer;">+ ₡5.000</button>
|
||||
<label style="display: block; font-size: 0.78rem; font-weight: 800; color: #166534; margin-bottom: 4px;">
|
||||
Escribe el monto a recargar:
|
||||
</label>
|
||||
<div style="position: relative; margin-bottom: 8px;">
|
||||
<span style="position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-weight: 900; color: #166534; font-size: 1.1rem;">₡</span>
|
||||
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputCustomSinpe" placeholder="Ej: 3000" style="width: 100%; padding: 10px 10px 10px 30px; border-radius: 10px; border: 1.5px solid #86efac; font-size: 1.15rem; font-weight: 900; color: #166534; background: white;">
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 6px;">
|
||||
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputCustomSinpe" placeholder="Otro monto (₡)" style="flex: 1; padding: 8px; border-radius: 8px; border: 1px solid #cbd5e1; font-weight: 600;">
|
||||
<button onclick="customSinpeRecharge()" style="padding: 8px 14px; background: #166534; color: white; border: none; border-radius: 8px; font-weight: 700; cursor: pointer;">Recargar</button>
|
||||
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px;">
|
||||
<button type="button" onclick="setWrittenRechargeAmount(1000)" style="padding: 7px 4px; background: white; border: 1px solid #86efac; border-radius: 8px; font-weight: 800; font-size: 0.76rem; color: #166534; cursor: pointer;">₡1.000</button>
|
||||
<button type="button" onclick="setWrittenRechargeAmount(2000)" style="padding: 7px 4px; background: white; border: 1px solid #86efac; border-radius: 8px; font-weight: 800; font-size: 0.76rem; color: #166534; cursor: pointer;">₡2.000</button>
|
||||
<button type="button" onclick="setWrittenRechargeAmount(5000)" style="padding: 7px 4px; background: white; border: 1px solid #86efac; border-radius: 8px; font-weight: 800; font-size: 0.76rem; color: #166534; cursor: pointer;">₡5.000</button>
|
||||
<button type="button" onclick="setWrittenRechargeAmount(10000)" style="padding: 7px 4px; background: white; border: 1px solid #86efac; border-radius: 8px; font-weight: 800; font-size: 0.76rem; color: #166534; cursor: pointer;">₡10.000</button>
|
||||
</div>
|
||||
|
||||
<button type="button" onclick="customSinpeRecharge()" style="width: 100%; padding: 12px; background: linear-gradient(135deg, #16a34a, #15803d); color: white; border: none; border-radius: 10px; font-weight: 900; font-size: 0.95rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 4px 10px rgba(22, 163, 74, 0.3);">
|
||||
<span>📲</span> Aplicar Recarga de Saldo
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- CONFIGURACIÓN DE LÍMITE DIARIO -->
|
||||
<div style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 12px; padding: 14px; margin-bottom: 16px;">
|
||||
<label style="display: block; font-size: 0.85rem; font-weight: 800; color: #1e293b; margin-bottom: 6px;">
|
||||
Límite de Gasto Máximo Diario: <span id="lblParentDailyLimit" style="color: #0284c7; font-weight: 900;">₡3.000</span>
|
||||
<!-- CONFIGURACIÓN DE LÍMITE DIARIO (ESCRITO Y DESLIZABLE) -->
|
||||
<div style="background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 14px; padding: 14px; margin-bottom: 16px;">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;">
|
||||
<div>
|
||||
<strong style="font-size: 0.88rem; color: #0f172a; display: block;">🛡️ Límite de Gasto Máximo Diario</strong>
|
||||
<span style="font-size: 0.72rem; color: #64748b;">Monto máximo que el alumno puede gastar por día</span>
|
||||
</div>
|
||||
<span id="lblParentDailyLimit" style="font-size: 1rem; color: #0284c7; font-weight: 900; background: #e0f2fe; padding: 3px 8px; border-radius: 8px;">₡3.000</span>
|
||||
</div>
|
||||
|
||||
<label style="display: block; font-size: 0.76rem; font-weight: 800; color: #334155; margin-bottom: 4px;">
|
||||
Escribe el monto del límite diario:
|
||||
</label>
|
||||
<input type="range" id="rangeDailyLimit" min="1000" max="6000" step="500" value="3000" oninput="onDailyLimitSlider(this.value)" style="width: 100%;">
|
||||
<div style="display: flex; justify-content: space-between; font-size: 0.72rem; color: #64748b; margin-top: 4px;">
|
||||
<span>₡1.000 / día</span>
|
||||
<span>₡3.500</span>
|
||||
<span>₡6.000 / día</span>
|
||||
<div style="display: flex; gap: 6px; margin-bottom: 10px;">
|
||||
<div style="position: relative; flex: 1;">
|
||||
<span style="position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-weight: 900; color: #0284c7; font-size: 1rem;">₡</span>
|
||||
<input type="tel" inputmode="numeric" pattern="[0-9]*" id="inputCustomDailyLimit" placeholder="Ej: 3000" oninput="onCustomDailyLimitInput(this.value)" style="width: 100%; padding: 9px 10px 9px 28px; border-radius: 8px; border: 1.5px solid #cbd5e1; font-size: 1rem; font-weight: 800; color: #0f172a; background: white;">
|
||||
</div>
|
||||
<button type="button" onclick="saveCustomDailyLimit()" style="padding: 9px 14px; background: #0284c7; color: white; border: none; border-radius: 8px; font-weight: 800; font-size: 0.8rem; cursor: pointer; white-space: nowrap;">
|
||||
💾 Guardar
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- ACCESOS RÁPIDOS DE LÍMITES COMUNES -->
|
||||
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 8px;">
|
||||
<button type="button" onclick="setWrittenDailyLimit(1500)" style="padding: 5px 2px; background: white; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 0.72rem; font-weight: 700; color: #334155; cursor: pointer;">₡1.500</button>
|
||||
<button type="button" onclick="setWrittenDailyLimit(2500)" style="padding: 5px 2px; background: white; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 0.72rem; font-weight: 700; color: #334155; cursor: pointer;">₡2.500</button>
|
||||
<button type="button" onclick="setWrittenDailyLimit(3500)" style="padding: 5px 2px; background: white; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 0.72rem; font-weight: 700; color: #334155; cursor: pointer;">₡3.500</button>
|
||||
<button type="button" onclick="setWrittenDailyLimit(5000)" style="padding: 5px 2px; background: white; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 0.72rem; font-weight: 700; color: #334155; cursor: pointer;">₡5.000</button>
|
||||
</div>
|
||||
|
||||
<input type="range" id="rangeDailyLimit" min="1000" max="10000" step="500" value="3000" oninput="onDailyLimitSlider(this.value)" style="width: 100%;">
|
||||
<div style="display: flex; justify-content: space-between; font-size: 0.7rem; color: #64748b; margin-top: 2px;">
|
||||
<span>₡1.000 min</span>
|
||||
<span>Deslizar para ajustar</span>
|
||||
<span>₡10.000 max</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
+89
-7
@@ -141,6 +141,10 @@ function updateStudentUI() {
|
||||
// Panel de Padres sliders y valores
|
||||
document.getElementById('lblParentDailyLimit').textContent = `₡${currentStudent.limite_diario_colones.toLocaleString('es-CR')}`;
|
||||
document.getElementById('rangeDailyLimit').value = currentStudent.limite_diario_colones;
|
||||
const inputWrittenLimit = document.getElementById('inputCustomDailyLimit');
|
||||
if (inputWrittenLimit) {
|
||||
inputWrittenLimit.value = currentStudent.limite_diario_colones;
|
||||
}
|
||||
|
||||
const chkTransfer = document.getElementById('chkParentAllowTransfer');
|
||||
if (chkTransfer) {
|
||||
@@ -412,15 +416,25 @@ function toggleParentPanel(show, e) {
|
||||
document.getElementById('modalPadres').style.display = show ? 'flex' : 'none';
|
||||
}
|
||||
|
||||
function setWrittenRechargeAmount(monto) {
|
||||
const input = document.getElementById('inputCustomSinpe');
|
||||
if (input) {
|
||||
input.value = monto;
|
||||
input.focus();
|
||||
}
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
}
|
||||
|
||||
async function quickSinpeRecharge(monto) {
|
||||
await doSinpeRecharge(monto);
|
||||
}
|
||||
|
||||
async function customSinpeRecharge() {
|
||||
const val = parseInt(document.getElementById('inputCustomSinpe').value, 10);
|
||||
if (!val || val <= 0) return alert('Ingresa un monto válido en colones');
|
||||
const input = document.getElementById('inputCustomSinpe');
|
||||
const val = parseInt(input.value, 10);
|
||||
if (!val || val <= 0) return alert('Por favor escribe un monto válido a recargar en colones.');
|
||||
await doSinpeRecharge(val);
|
||||
document.getElementById('inputCustomSinpe').value = '';
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
async function doSinpeRecharge(monto) {
|
||||
@@ -450,18 +464,86 @@ async function doSinpeRecharge(monto) {
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// CONTROL DE LÍMITE DIARIO ESCRITO Y SLIDER
|
||||
// ==========================================
|
||||
|
||||
function onCustomDailyLimitInput(val) {
|
||||
const num = parseInt(val, 10);
|
||||
if (!isNaN(num) && num >= 0) {
|
||||
document.getElementById('lblParentDailyLimit').textContent = `₡${num.toLocaleString('es-CR')}`;
|
||||
const slider = document.getElementById('rangeDailyLimit');
|
||||
if (slider && num >= 1000 && num <= 10000) {
|
||||
slider.value = num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function setWrittenDailyLimit(val) {
|
||||
const input = document.getElementById('inputCustomDailyLimit');
|
||||
if (input) input.value = val;
|
||||
onCustomDailyLimitInput(val);
|
||||
await saveCustomDailyLimit(val);
|
||||
}
|
||||
|
||||
async function saveCustomDailyLimit(customVal) {
|
||||
let val = customVal;
|
||||
if (val === undefined) {
|
||||
const input = document.getElementById('inputCustomDailyLimit');
|
||||
val = parseInt(input.value, 10);
|
||||
}
|
||||
|
||||
if (isNaN(val) || val < 0) {
|
||||
return alert('Por favor escribe un monto válido para el límite diario.');
|
||||
}
|
||||
|
||||
if (!currentStudent) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/estudiantes/${currentStudent.id}/limite`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ limite_diario_colones: val })
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
currentStudent.limite_diario_colones = val;
|
||||
document.getElementById('lblParentDailyLimit').textContent = `₡${val.toLocaleString('es-CR')}`;
|
||||
document.getElementById('dailyLimitText').textContent = `₡${val.toLocaleString('es-CR')}`;
|
||||
|
||||
const slider = document.getElementById('rangeDailyLimit');
|
||||
if (slider && val >= 1000 && val <= 10000) {
|
||||
slider.value = val;
|
||||
}
|
||||
|
||||
const input = document.getElementById('inputCustomDailyLimit');
|
||||
if (input) input.value = val;
|
||||
|
||||
if (window.sounds) window.sounds.playSuccess();
|
||||
alert(`✅ Límite diario actualizado a ₡${val.toLocaleString('es-CR')} para ${currentStudent.nombre_completo.split(' ')[0]}`);
|
||||
await selectStudent(currentStudent.id);
|
||||
}
|
||||
} catch (e) {
|
||||
alert('Error guardando el límite diario: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function onDailyLimitSlider(val) {
|
||||
document.getElementById('lblParentDailyLimit').textContent = `₡${parseInt(val, 10).toLocaleString('es-CR')}`;
|
||||
const num = parseInt(val, 10);
|
||||
document.getElementById('lblParentDailyLimit').textContent = `₡${num.toLocaleString('es-CR')}`;
|
||||
|
||||
const input = document.getElementById('inputCustomDailyLimit');
|
||||
if (input) input.value = num;
|
||||
|
||||
if (!currentStudent) return;
|
||||
|
||||
try {
|
||||
await fetch(`/api/estudiantes/${currentStudent.id}/limite`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ limite_diario_colones: parseInt(val, 10) })
|
||||
body: JSON.stringify({ limite_diario_colones: num })
|
||||
});
|
||||
// Actualizar UI sutilmente
|
||||
currentStudent.limite_diario_colones = parseInt(val, 10);
|
||||
currentStudent.limite_diario_colones = num;
|
||||
document.getElementById('dailyLimitText').textContent = `₡${currentStudent.limite_diario_colones.toLocaleString('es-CR')}`;
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user