feat: permitir cancelacion de ordenes a padres y alumnos con liberacion inmediata de saldo
This commit is contained in:
@@ -6973,4 +6973,97 @@ body.dark-mode .danger-zone-box {
|
||||
}
|
||||
}
|
||||
|
||||
/* ============================================================
|
||||
TARJETAS Y BOTONES DE CANCELACIÓN DE ÓRDENES (PADRES Y ALUMNOS)
|
||||
============================================================ */
|
||||
.active-order-card {
|
||||
background: var(--card-bg, #ffffff);
|
||||
border: 1px solid var(--border, #e2e8f0);
|
||||
border-radius: 14px;
|
||||
padding: 12px 14px;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
|
||||
transition: transform 0.15s ease, box-shadow 0.15s ease;
|
||||
}
|
||||
|
||||
body.dark-mode .active-order-card {
|
||||
background: #1e293b;
|
||||
border-color: #334155;
|
||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.active-order-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.active-order-items {
|
||||
font-size: 0.82rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-main, #0f172a);
|
||||
margin-bottom: 8px;
|
||||
line-height: 1.35;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.active-order-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px dashed var(--border, #e2e8f0);
|
||||
}
|
||||
|
||||
body.dark-mode .active-order-footer {
|
||||
border-top-color: #334155;
|
||||
}
|
||||
|
||||
.btn-cancel-order-action {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 0.76rem;
|
||||
font-weight: 800;
|
||||
cursor: pointer;
|
||||
border: 1.5px solid #fecaca;
|
||||
background: #fef2f2;
|
||||
color: #b91c1c;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.btn-cancel-order-action:hover:not(:disabled) {
|
||||
background: #fee2e2;
|
||||
border-color: #f87171;
|
||||
color: #991b1b;
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.btn-cancel-order-action:active:not(:disabled) {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
|
||||
.btn-cancel-order-action:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
body.dark-mode .btn-cancel-order-action {
|
||||
background: rgba(239, 68, 68, 0.12);
|
||||
border-color: rgba(239, 68, 68, 0.35);
|
||||
color: #fca5a5;
|
||||
}
|
||||
|
||||
body.dark-mode .btn-cancel-order-action:hover:not(:disabled) {
|
||||
background: rgba(239, 68, 68, 0.24);
|
||||
border-color: rgba(239, 68, 68, 0.6);
|
||||
color: #fecaca;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+42
-4
@@ -11,9 +11,9 @@
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
||||
<meta name="apple-mobile-web-app-title" content="SiboPay">
|
||||
<link rel="preload" href="/css/styles.css?v=19.6" as="style">
|
||||
<link rel="preload" href="/js/app.js?v=19.6" as="script">
|
||||
<link rel="stylesheet" href="/css/styles.css?v=19.6">
|
||||
<link rel="preload" href="/css/styles.css?v=19.7" as="style">
|
||||
<link rel="preload" href="/js/app.js?v=19.7" as="script">
|
||||
<link rel="stylesheet" href="/css/styles.css?v=19.7">
|
||||
<link rel="stylesheet" href="/css/desktop.css?v=2.2">
|
||||
<style>
|
||||
/* Transiciones suaves */
|
||||
@@ -1879,6 +1879,23 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- WIDGET DE ÓRDENES ACTIVAS DEL HIJO -->
|
||||
<div id="parentSummaryActiveOrdersSection" style="display: none; background: #f0f9ff; border: 1.5px solid #bae6fd; border-radius: 16px; padding: 16px; margin-bottom: 18px; box-shadow: 0 2px 8px rgba(2, 132, 199, 0.06);">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; border-bottom: 1px dashed #bae6fd; padding-bottom: 8px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<span style="font-size: 1.2rem;">🥪</span>
|
||||
<div>
|
||||
<strong style="font-size: 0.88rem; color: #0369a1; display: block; font-weight: 800;">Pedidos Activos de tu Hijo</strong>
|
||||
<span style="font-size: 0.7rem; color: #0284c7;">Pre-órdenes en curso en la soda</span>
|
||||
</div>
|
||||
</div>
|
||||
<span id="parentSummaryActiveCountBadge" style="background: #0284c7; color: white; border-radius: 20px; padding: 2px 9px; font-size: 0.72rem; font-weight: 800;">0 activos</span>
|
||||
</div>
|
||||
<div id="parentSummaryActiveOrdersList" style="display: flex; flex-direction: column; gap: 10px;">
|
||||
<!-- Inyectado dinámicamente -->
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Atajos Rápidos -->
|
||||
<h4 style="font-size: 0.85rem; font-weight: 900; color: var(--text-main); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px;">Acciones Rápidas</h4>
|
||||
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px;">
|
||||
@@ -2686,6 +2703,27 @@
|
||||
<strong>Atención médica:</strong> <span id="allergyText"></span>
|
||||
</div>
|
||||
|
||||
<!-- ÓRDENES ACTIVAS Y PRE-ÓRDENES PENDIENTES DEL ESTUDIANTE -->
|
||||
<section id="studentActiveOrdersSection" class="student-active-orders-section" style="display: none; margin: 0 16px 14px 16px;">
|
||||
<div style="background: var(--card-bg, #ffffff); border: 1.5px solid #bae6fd; border-radius: 16px; padding: 14px 16px; box-shadow: 0 3px 12px rgba(2, 132, 199, 0.08);">
|
||||
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; border-bottom: 1px dashed var(--border, #e2e8f0); padding-bottom: 8px;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<div style="width: 32px; height: 32px; border-radius: 10px; background: rgba(2, 132, 199, 0.12); display: flex; align-items: center; justify-content: center; font-size: 1.1rem;">
|
||||
🥪
|
||||
</div>
|
||||
<div>
|
||||
<strong style="font-size: 0.88rem; color: #0284c7; display: block; font-weight: 800;">Tus Pedidos Activos</strong>
|
||||
<span style="font-size: 0.7rem; color: var(--text-muted);">Pendientes de retirar en la soda</span>
|
||||
</div>
|
||||
</div>
|
||||
<span id="studentActiveOrdersCountBadge" style="background: #0284c7; color: white; border-radius: 20px; padding: 2px 9px; font-size: 0.72rem; font-weight: 800;">0 activos</span>
|
||||
</div>
|
||||
<div id="studentActiveOrdersList" style="display: flex; flex-direction: column; gap: 10px;">
|
||||
<!-- Inyectado dinámicamente -->
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- BUSCADOR INTELIGENTE DEL MENÚ PARA ESTUDIANTES Y PADRES -->
|
||||
<div class="menu-smart-search-section" id="menuSmartSearchSection">
|
||||
<div class="menu-smart-search-box">
|
||||
@@ -4905,6 +4943,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=19.4"></script>
|
||||
<script src="/js/app.js?v=19.7"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+330
-1
@@ -959,6 +959,151 @@ function updateStudentUI() {
|
||||
}
|
||||
|
||||
renderParentHistory();
|
||||
loadStudentActiveOrders();
|
||||
}
|
||||
|
||||
// Modal de confirmación defensivo con soporte para showAppConfirm
|
||||
async function appConfirmPrompt(title, message, confirmText = 'Sí, Cancelar') {
|
||||
if (typeof window.showAppConfirm === 'function') {
|
||||
return await window.showAppConfirm({
|
||||
title,
|
||||
message,
|
||||
confirmText,
|
||||
cancelText: 'Volver',
|
||||
danger: true
|
||||
});
|
||||
}
|
||||
return window.confirm(`${title}\n\n${message}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Carga y renderiza los pedidos activos del estudiante actual
|
||||
*/
|
||||
async function loadStudentActiveOrders() {
|
||||
const container = document.getElementById('studentActiveOrdersSection');
|
||||
const list = document.getElementById('studentActiveOrdersList');
|
||||
const countBadge = document.getElementById('studentActiveOrdersCountBadge');
|
||||
if (!container || !list) return;
|
||||
|
||||
if (!currentStudent || !currentStudent.id) {
|
||||
container.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/ordenes?estudiante_id=${currentStudent.id}&estado=activos`);
|
||||
if (!res.ok) throw new Error('Error al consultar pedidos activos');
|
||||
const ordenes = await res.json();
|
||||
|
||||
if (!Array.isArray(ordenes) || ordenes.length === 0) {
|
||||
container.style.display = 'none';
|
||||
list.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
container.style.display = 'block';
|
||||
if (countBadge) {
|
||||
countBadge.textContent = `${ordenes.length} activo${ordenes.length === 1 ? '' : 's'}`;
|
||||
}
|
||||
|
||||
list.innerHTML = ordenes.map(o => {
|
||||
const itemsStr = (o.items && o.items.length > 0)
|
||||
? o.items.map(it => `${it.cantidad}x ${it.nombre}`).join(', ')
|
||||
: 'Pre-orden escolar';
|
||||
const badge = getMomentoBadge(o.momento_entrega);
|
||||
const codigo = o.codigo_orden || `ORD-${o.id}`;
|
||||
|
||||
let estadoLabel = '⏳ Pendiente en cocina';
|
||||
let estadoColor = '#f59e0b';
|
||||
if (o.estado === 'en_preparacion') {
|
||||
estadoLabel = '👨🍳 En preparación';
|
||||
estadoColor = '#0284c7';
|
||||
} else if (o.estado === 'listo') {
|
||||
estadoLabel = '✅ Listo para retirar';
|
||||
estadoColor = '#10b981';
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="active-order-card">
|
||||
<div class="active-order-header">
|
||||
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;">
|
||||
<strong style="font-size: 0.85rem; color: var(--text-main);">${codigo}</strong>
|
||||
<span style="background: ${badge.badgeBg}; color: ${badge.badgeColor}; border: 1px solid ${badge.badgeBorder}; padding: 1px 7px; border-radius: 6px; font-weight: 800; font-size: 0.7rem;">
|
||||
${badge.icon} ${badge.title}
|
||||
</span>
|
||||
<span style="font-size: 0.72rem; color: ${estadoColor}; font-weight: 800;">
|
||||
${estadoLabel}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="active-order-items">${itemsStr}</div>
|
||||
<div class="active-order-footer">
|
||||
<span style="font-size: 0.82rem; font-weight: 800; color: #0284c7;">
|
||||
Total: ₡${(o.total_colones || 0).toLocaleString('es-CR')} <small style="font-size: 0.68rem; color: var(--text-muted); font-weight: 600;">(Retenido)</small>
|
||||
</span>
|
||||
<button type="button" class="btn-cancel-order-action" onclick="cancelarOrdenEstudiante(${o.id}, '${codigo}', ${o.total_colones || 0})">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>
|
||||
<span>Cancelar Pedido</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
} catch (err) {
|
||||
console.warn('Error en loadStudentActiveOrders:', err);
|
||||
container.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Permite al estudiante cancelar su pedido activo y liberar saldo de inmediato
|
||||
*/
|
||||
async function cancelarOrdenEstudiante(ordenId, codigoOrden, monto) {
|
||||
const montoFmt = `₡${(monto || 0).toLocaleString('es-CR')}`;
|
||||
const ok = await appConfirmPrompt(
|
||||
'¿Cancelar Pedido?',
|
||||
`¿Deseas cancelar tu pedido ${codigoOrden} de ${montoFmt}? Tu dinero retenido volverá a estar disponible de inmediato para realizar otra compra.`,
|
||||
'Sí, Cancelar Pedido'
|
||||
);
|
||||
if (!ok) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/ordenes/${ordenId}/cancelar`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
usuario_rol: 'estudiante',
|
||||
estudiante_id: currentStudent ? currentStudent.id : undefined,
|
||||
motivo: 'Cancelada por el estudiante desde la app'
|
||||
})
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Error al cancelar el pedido');
|
||||
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
await showAppAlert({
|
||||
title: '¡Pedido Cancelado!',
|
||||
message: `Tu pedido ${codigoOrden} fue cancelado exitosamente. Tus ${montoFmt} ya están disponibles en tu saldo.`,
|
||||
type: 'success'
|
||||
});
|
||||
|
||||
if (currentStudent && currentStudent.id) {
|
||||
const freshRes = await fetch(`/api/estudiantes/${currentStudent.id}`);
|
||||
if (freshRes.ok) {
|
||||
currentStudent = await freshRes.json();
|
||||
updateStudentUI();
|
||||
triggerBalancePulse();
|
||||
}
|
||||
await loadStudentActiveOrders();
|
||||
}
|
||||
} catch (err) {
|
||||
await showAppAlert({
|
||||
title: 'Error',
|
||||
message: `No se pudo cancelar el pedido: ${err.message}`,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setAppMode(mode, playSound = false) {
|
||||
@@ -1598,9 +1743,11 @@ async function submitPreOrder() {
|
||||
await loadParentDashboard();
|
||||
if (currentParentChild) {
|
||||
await loadActiveChildHistory(currentParentChild.id);
|
||||
await loadParentActiveOrders(currentParentChild.id);
|
||||
}
|
||||
} else if (currentStudent) {
|
||||
await selectStudent(currentStudent.id);
|
||||
await loadStudentActiveOrders();
|
||||
}
|
||||
} catch (err) {
|
||||
alert(`No se pudo procesar: ${err.message}`);
|
||||
@@ -3023,11 +3170,16 @@ function initStudentSSE() {
|
||||
triggerBalancePulse();
|
||||
}
|
||||
fetch(`/api/estudiantes/${estId}`).then(r => r.json()).then(s => { if (s && currentStudent && currentStudent.id === s.id) { currentStudent = s; updateStudentUI(); } }).catch(()=>{});
|
||||
loadStudentActiveOrders();
|
||||
}
|
||||
|
||||
// Si es padre de este estudiante
|
||||
if (currentUser && currentUser.rol === 'padre') {
|
||||
loadParentDashboard();
|
||||
if (currentParentChild) {
|
||||
loadParentActiveOrders(currentParentChild.id);
|
||||
loadActiveChildHistory(currentParentChild.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Si es admin
|
||||
@@ -3039,6 +3191,46 @@ function initStudentSSE() {
|
||||
}
|
||||
});
|
||||
|
||||
// Orden cancelada (desde app de estudiante, portal de padres o mostrador)
|
||||
sse.addEventListener('orden_cancelada', (e) => {
|
||||
try {
|
||||
if (currentStudent) {
|
||||
loadStudentActiveOrders();
|
||||
fetch(`/api/estudiantes/${currentStudent.id}`)
|
||||
.then(r => r.json())
|
||||
.then(s => { if (s && currentStudent && currentStudent.id === s.id) { currentStudent = s; updateStudentUI(); } })
|
||||
.catch(()=>{});
|
||||
}
|
||||
if (currentUser && currentUser.rol === 'padre') {
|
||||
loadParentDashboard();
|
||||
if (currentParentChild) {
|
||||
loadParentActiveOrders(currentParentChild.id);
|
||||
loadActiveChildHistory(currentParentChild.id);
|
||||
}
|
||||
}
|
||||
if (currentUser && ['admin', 'cajero', 'personal', 'dev', 'soda'].includes(currentUser.rol)) {
|
||||
loadAdminData();
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Error en SSE orden_cancelada:', err);
|
||||
}
|
||||
});
|
||||
|
||||
// Orden actualizada (cambio de estado en cocina o mostrador)
|
||||
sse.addEventListener('orden_actualizada', (e) => {
|
||||
try {
|
||||
if (currentStudent) {
|
||||
loadStudentActiveOrders();
|
||||
}
|
||||
if (currentUser && currentUser.rol === 'padre') {
|
||||
if (currentParentChild) {
|
||||
loadParentActiveOrders(currentParentChild.id);
|
||||
loadActiveChildHistory(currentParentChild.id);
|
||||
}
|
||||
}
|
||||
} catch (err) {}
|
||||
});
|
||||
|
||||
// Saldo actualizado (débito, recarga, ajuste de límite)
|
||||
sse.addEventListener('saldo_actualizado', (e) => {
|
||||
try {
|
||||
@@ -3628,6 +3820,8 @@ function openParentSubView(viewKey, shouldScroll = true) {
|
||||
loadParentSinpeRequests(currentParentChild.id);
|
||||
} else if (viewKey === 'historial' && currentParentChild) {
|
||||
loadActiveChildHistory(currentParentChild.id);
|
||||
} else if (viewKey === 'resumen' && currentParentChild) {
|
||||
loadParentActiveOrders(currentParentChild.id);
|
||||
} else if (viewKey === 'credenciales') {
|
||||
updateParentQrSecurityCardUI();
|
||||
}
|
||||
@@ -4074,6 +4268,7 @@ function renderActiveChildDetails(child) {
|
||||
|
||||
loadActiveChildHistory(child.id);
|
||||
loadParentSinpeRequests(child.id);
|
||||
loadParentActiveOrders(child.id);
|
||||
}
|
||||
|
||||
async function loadActiveChildHistory(studentId) {
|
||||
@@ -4101,6 +4296,7 @@ async function loadActiveChildHistory(studentId) {
|
||||
|
||||
const isCanceled = o.estado === 'cancelado' || o.estado === 'expirado';
|
||||
const isDelivered = o.estado === 'entregado';
|
||||
const isActive = !isCanceled && !isDelivered;
|
||||
|
||||
return `
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px dashed var(--border);">
|
||||
@@ -4110,13 +4306,18 @@ async function loadActiveChildHistory(studentId) {
|
||||
<span>${fecha}</span>
|
||||
<span>•</span>
|
||||
<span style="color: ${isDelivered ? '#10b981' : (isCanceled ? '#ef4444' : '#f59e0b')}; font-weight: 700;">
|
||||
${isDelivered ? 'Entregado' : (isCanceled ? '🚫 Cancelado (No retirado • Saldo liberado)' : 'Pendiente de retiro')}
|
||||
${isDelivered ? 'Entregado' : (isCanceled ? '🚫 Cancelado (Saldo liberado)' : 'Pendiente de retiro')}
|
||||
</span>
|
||||
${isPreorden ? `
|
||||
<span style="background: ${badge.badgeBg}; color: ${badge.badgeColor}; border: 1px solid ${badge.badgeBorder}; padding: 1px 7px; border-radius: 6px; font-weight: 800; font-size: 0.7rem;">
|
||||
${badge.icon} ${badge.title}
|
||||
</span>
|
||||
` : ''}
|
||||
${isActive ? `
|
||||
<button type="button" class="btn-cancel-order-action" onclick="cancelarOrdenPadre(${o.id}, '${o.codigo_orden || 'ORD-' + o.id}', ${o.total_colones || 0})" style="padding: 2px 8px; font-size: 0.68rem; margin-left: 4px;" title="Cancelar pedido y liberar saldo">
|
||||
🚫 Cancelar Orden
|
||||
</button>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
${isCanceled ? `
|
||||
@@ -4135,6 +4336,134 @@ async function loadActiveChildHistory(studentId) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Carga y renderiza las órdenes activas del hijo en el Resumen Principal de Padres
|
||||
*/
|
||||
async function loadParentActiveOrders(studentId) {
|
||||
const container = document.getElementById('parentSummaryActiveOrdersSection');
|
||||
const list = document.getElementById('parentSummaryActiveOrdersList');
|
||||
const countBadge = document.getElementById('parentSummaryActiveCountBadge');
|
||||
if (!container || !list) return;
|
||||
|
||||
if (!studentId) {
|
||||
container.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/ordenes?estudiante_id=${studentId}&estado=activos`);
|
||||
if (!res.ok) throw new Error('Error al cargar órdenes activas');
|
||||
const ordenes = await res.json();
|
||||
|
||||
if (!Array.isArray(ordenes) || ordenes.length === 0) {
|
||||
container.style.display = 'none';
|
||||
list.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
container.style.display = 'block';
|
||||
if (countBadge) {
|
||||
countBadge.textContent = `${ordenes.length} activo${ordenes.length === 1 ? '' : 's'}`;
|
||||
}
|
||||
|
||||
list.innerHTML = ordenes.map(o => {
|
||||
const itemsStr = (o.items && o.items.length > 0)
|
||||
? o.items.map(it => `${it.cantidad}x ${it.nombre}`).join(', ')
|
||||
: 'Pedido escolar';
|
||||
const badge = getMomentoBadge(o.momento_entrega);
|
||||
const fecha = o.creado_en ? new Date(o.creado_en).toLocaleDateString('es-CR', { hour: '2-digit', minute: '2-digit' }) : '';
|
||||
const codigo = o.codigo_orden || `ORD-${o.id}`;
|
||||
|
||||
let estadoLabel = '⏳ Pendiente en cocina';
|
||||
let estadoColor = '#f59e0b';
|
||||
if (o.estado === 'en_preparacion') {
|
||||
estadoLabel = '👨🍳 En preparación';
|
||||
estadoColor = '#0284c7';
|
||||
} else if (o.estado === 'listo') {
|
||||
estadoLabel = '✅ Listo para retirar';
|
||||
estadoColor = '#10b981';
|
||||
}
|
||||
|
||||
return `
|
||||
<div class="active-order-card">
|
||||
<div class="active-order-header">
|
||||
<div style="display: flex; align-items: center; gap: 6px; flex-wrap: wrap;">
|
||||
<strong style="font-size: 0.85rem; color: var(--text-main);">${codigo}</strong>
|
||||
<span style="background: ${badge.badgeBg}; color: ${badge.badgeColor}; border: 1px solid ${badge.badgeBorder}; padding: 1px 7px; border-radius: 6px; font-weight: 800; font-size: 0.7rem;">
|
||||
${badge.icon} ${badge.title}
|
||||
</span>
|
||||
<span style="font-size: 0.72rem; color: ${estadoColor}; font-weight: 800;">
|
||||
${estadoLabel}
|
||||
</span>
|
||||
</div>
|
||||
<span style="font-size: 0.72rem; color: var(--text-muted);">${fecha}</span>
|
||||
</div>
|
||||
<div class="active-order-items">${itemsStr}</div>
|
||||
<div class="active-order-footer">
|
||||
<span style="font-size: 0.82rem; font-weight: 800; color: #0284c7;">
|
||||
Total: ₡${(o.total_colones || 0).toLocaleString('es-CR')} <small style="font-size: 0.68rem; color: var(--text-muted); font-weight: 600;">(Retenido)</small>
|
||||
</span>
|
||||
<button type="button" class="btn-cancel-order-action" onclick="cancelarOrdenPadre(${o.id}, '${codigo}', ${o.total_colones || 0})">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>
|
||||
<span>Cancelar Orden</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}).join('');
|
||||
} catch (err) {
|
||||
console.warn('Error en loadParentActiveOrders:', err);
|
||||
container.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Permite al padre de familia cancelar una orden de su hijo y liberar saldo
|
||||
*/
|
||||
async function cancelarOrdenPadre(ordenId, codigoOrden, monto) {
|
||||
const montoFmt = `₡${(monto || 0).toLocaleString('es-CR')}`;
|
||||
const ok = await appConfirmPrompt(
|
||||
'¿Cancelar Orden?',
|
||||
`¿Deseas cancelar el pedido ${codigoOrden} de ${montoFmt}? El monto retenido se liberará de inmediato al saldo disponible de tu hijo.`,
|
||||
'Sí, Cancelar Orden'
|
||||
);
|
||||
if (!ok) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/ordenes/${ordenId}/cancelar`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
usuario_rol: 'padre',
|
||||
estudiante_id: currentParentChild ? currentParentChild.id : undefined,
|
||||
motivo: 'Cancelada por el padre desde el portal familiar'
|
||||
})
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Error al cancelar la orden');
|
||||
|
||||
if (window.sounds) window.sounds.playCoin();
|
||||
await showAppAlert({
|
||||
title: '¡Orden Cancelada!',
|
||||
message: `El pedido ${codigoOrden} fue cancelado exitosamente. Se liberaron ${montoFmt} al saldo disponible de tu hijo.`,
|
||||
type: 'success'
|
||||
});
|
||||
|
||||
if (currentParentChild) {
|
||||
await loadParentDashboard();
|
||||
await loadActiveChildHistory(currentParentChild.id);
|
||||
await loadParentActiveOrders(currentParentChild.id);
|
||||
}
|
||||
} catch (err) {
|
||||
await showAppAlert({
|
||||
title: 'Error',
|
||||
message: `No se pudo cancelar la orden: ${err.message}`,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let currentSinpeCode = '';
|
||||
|
||||
// ==========================================
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
// SiboPay PWA Service Worker v19.6 - Ultra Fast Startup & Stale-While-Revalidate
|
||||
const CACHE_NAME = 'sibopay-v19.6';
|
||||
// SiboPay PWA Service Worker v19.7 - Ultra Fast Startup & Stale-While-Revalidate
|
||||
const CACHE_NAME = 'sibopay-v19.7';
|
||||
const STATIC_ASSETS = [
|
||||
'/',
|
||||
'/index.html',
|
||||
@@ -8,10 +8,10 @@ const STATIC_ASSETS = [
|
||||
'/pistola.html',
|
||||
'/carnet.html',
|
||||
'/manifest.json',
|
||||
'/css/styles.css?v=19.4',
|
||||
'/css/styles.css?v=19.7',
|
||||
'/css/desktop.css?v=2.2',
|
||||
'/js/dialogs.js?v=19.4',
|
||||
'/js/app.js?v=19.4',
|
||||
'/js/app.js?v=19.7',
|
||||
'/js/pos.js',
|
||||
'/js/sounds.js?v=19.4',
|
||||
'/js/food-icons.js?v=19.4',
|
||||
|
||||
Reference in New Issue
Block a user