From 8ab81c3e5e8b8e9369acd1546ff68eb059d174a9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 Oct 2026 11:10:45 -0600 Subject: [PATCH] feat(pos): cancelacion automatica en cierre de caja y 5pm, filtro de canceladas y contador a cero --- public/index.html | 2 +- public/js/app.js | 20 ++++++++-- public/js/pos.js | 96 +++++++++++++++++++++++++++++++---------------- public/pos.html | 11 ++++-- public/sw.js | 4 +- server/db.js | 7 ++-- 6 files changed, 94 insertions(+), 46 deletions(-) diff --git a/public/index.html b/public/index.html index f8c5fc2..09c09e8 100644 --- a/public/index.html +++ b/public/index.html @@ -3179,6 +3179,6 @@ - + diff --git a/public/js/app.js b/public/js/app.js index 3047963..731b540 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -67,7 +67,7 @@ document.addEventListener('DOMContentLoaded', async () => { // Registrar Service Worker para PWA if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('/sw.js?v=13.0').then(reg => { + navigator.serviceWorker.register('/sw.js?v=13.1').then(reg => { reg.update().catch(() => {}); if ('Notification' in window && Notification.permission === 'granted') { subscribeDeviceToWebPush().catch(() => {}); @@ -3189,14 +3189,19 @@ async function loadActiveChildHistory(studentId) { const isPreorden = o.tipo_orden === 'preorden'; const badge = getMomentoBadge(o.momento_entrega); + const isCanceled = o.estado === 'cancelado' || o.estado === 'expirado'; + const isDelivered = o.estado === 'entregado'; + return `
-
${itemsStr}
+
${itemsStr}
${fecha} • - ${o.estado === 'entregado' ? 'Entregado' : 'Pendiente de retiro'} + + ${isDelivered ? 'Entregado' : (isCanceled ? '🚫 Cancelado (No retirado • Saldo liberado)' : 'Pendiente de retiro')} + ${isPreorden ? ` ${badge.icon} ${badge.title} @@ -3204,7 +3209,14 @@ async function loadActiveChildHistory(studentId) { ` : ''}
- -₡${(o.total_colones || 0).toLocaleString('es-CR')} + ${isCanceled ? ` +
+ ₡${(o.total_colones || 0).toLocaleString('es-CR')} + Liberado +
+ ` : ` + -₡${(o.total_colones || 0).toLocaleString('es-CR')} + `}
`; }).join(''); diff --git a/public/js/pos.js b/public/js/pos.js index 2bf5860..6139117 100644 --- a/public/js/pos.js +++ b/public/js/pos.js @@ -90,7 +90,7 @@ document.addEventListener('DOMContentLoaded', async () => { // Registrar Service Worker para Notificaciones PWA if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('/sw.js?v=13.0').then((reg) => { + navigator.serviceWorker.register('/sw.js?v=13.1').then((reg) => { reg.update().catch(() => {}); if ('Notification' in window && Notification.permission === 'granted') { subscribeDeviceToWebPush().catch(() => {}); @@ -1401,8 +1401,9 @@ function filterPreOrdersByMomento(key) { function renderPreOrdersList() { const orders = cachedPreOrders || []; - // Conteo total de pendientes - const pendingOrders = orders.filter(o => o.estado !== 'entregado' && o.estado !== 'cancelado'); + // Órdenes activas pendientes de entrega + const pendingOrders = orders.filter(o => o.estado !== 'entregado' && o.estado !== 'cancelado' && o.estado !== 'expirado'); + const canceledOrders = orders.filter(o => o.estado === 'cancelado' || o.estado === 'expirado'); const countTodosPending = pendingOrders.length; const badgeCount = document.getElementById('badgePreordenesCount'); @@ -1421,17 +1422,20 @@ function renderPreOrdersList() { const elR1 = document.getElementById('countFilterRecreo1'); const elAlm = document.getElementById('countFilterAlmuerzo'); const elR2 = document.getElementById('countFilterRecreo2'); + const elCanceladas = document.getElementById('countFilterCanceladas'); if (elTodos) elTodos.textContent = countTodosPending; if (elR1) elR1.textContent = countR1; if (elAlm) elAlm.textContent = countAlm; if (elR2) elR2.textContent = countR2; + if (elCanceladas) elCanceladas.textContent = canceledOrders.length; // Actualizar clase activa en los botones de filtro const pillMap = { 'todos': 'filterPillTodos', 'recreo_1': 'filterPillRecreo_1', 'almuerzo': 'filterPillAlmuerzo', - 'recreo_2': 'filterPillRecreo_2' + 'recreo_2': 'filterPillRecreo_2', + 'canceladas': 'filterPillCanceladas' }; Object.keys(pillMap).forEach(k => { const btn = document.getElementById(pillMap[k]); @@ -1439,17 +1443,33 @@ function renderPreOrdersList() { }); // Filtrar según botón seleccionado - let filtered = orders; - if (currentPreOrderFilter !== 'todos') { - filtered = orders.filter(o => normalizeMomentoKey(o.momento_entrega) === currentPreOrderFilter); + let filtered = []; + if (currentPreOrderFilter === 'canceladas') { + filtered = canceledOrders; + } else if (currentPreOrderFilter === 'todos') { + // Por defecto en la cola de mostrador sólo mostramos las órdenes pendientes activas + filtered = pendingOrders; + } else { + filtered = pendingOrders.filter(o => normalizeMomentoKey(o.momento_entrega) === currentPreOrderFilter); } const list = document.getElementById('preOrdersList'); if (!list) return; if (filtered.length === 0) { + if (currentPreOrderFilter === 'canceladas') { + list.innerHTML = ` +
+ ✅ + No hay pre-órdenes canceladas +

Las órdenes no retiradas que se cancelen por Cierre de Caja o a las 5:00 PM aparecerán aquí con su monto liberado.

+
+ `; + return; + } + const filterNames = { - 'todos': 'para hoy', + 'todos': 'pendientes por entregar', 'recreo_1': 'para el 1er Recreo (9:30 AM)', 'almuerzo': 'para el Almuerzo (11:45 AM)', 'recreo_2': 'para el 2do Recreo (1:45 PM)' @@ -1457,7 +1477,7 @@ function renderPreOrdersList() { list.innerHTML = `
🥪 - No hay pre-órdenes registradas ${filterNames[currentPreOrderFilter] || ''} + No hay pre-órdenes ${filterNames[currentPreOrderFilter] || 'pendientes'}

Las órdenes programadas para este horario aparecerán aquí automáticamente.

`; @@ -1469,34 +1489,38 @@ function renderPreOrdersList() { const items = Array.isArray(ord.items) ? ord.items : []; const itemsList = items.map(i => `${i.cantidad}× ${i.nombre}`).join(' • '); const badge = getMomentoBadge(ord.momento_entrega); + const isCanceled = ord.estado === 'cancelado' || ord.estado === 'expirado'; + const isDelivered = ord.estado === 'entregado'; return ` -
- -
+
+ +
- ${badge.icon} + ${isCanceled ? '🚫' : badge.icon}
- ALISTAR PARA: - ${badge.full} + ${isCanceled ? 'ESTADO:' : 'ALISTAR PARA:'} + ${isCanceled ? 'Pre-orden Cancelada (No Retirada)' : badge.full}
- ${ord.estado === 'entregado' - ? 'Entregado' - : 'Pendiente Alistar' + ${isCanceled + ? 'Cancelada' + : isDelivered + ? 'Entregado' + : 'Pendiente Alistar' }
-
+
${getStudentInitials(ord.estudiante_nombre)}
- ${ord.estudiante_nombre} + ${ord.estudiante_nombre} ${ord.grado} • ${ord.seccion}
@@ -1510,24 +1534,36 @@ function renderPreOrdersList() {
- ${ord.notas ? ` + ${ord.observaciones ? ` +
+ ℹ️ ${ord.observaciones} +
+ ` : (ord.notas ? `
📝 Nota del pedido: ${ord.notas}
- ` : ''} + ` : '')}
- - ${itemsList} + + ${itemsList}
diff --git a/public/pos.html b/public/pos.html index 1161d6f..0a53288 100644 --- a/public/pos.html +++ b/public/pos.html @@ -245,10 +245,9 @@
- -
+
+
@@ -578,6 +581,6 @@ - + diff --git a/public/sw.js b/public/sw.js index 05f91c4..ca9c9b4 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,5 +1,5 @@ -// SiboPay PWA Service Worker v13.0 - Alta Velocidad & Despacho -const CACHE_NAME = 'sibopay-v13.0'; +// SiboPay PWA Service Worker v13.1 - Alta Velocidad & Despacho +const CACHE_NAME = 'sibopay-v13.1'; const STATIC_ASSETS = [ '/', '/index.html', diff --git a/server/db.js b/server/db.js index 54ae863..af8e98d 100644 --- a/server/db.js +++ b/server/db.js @@ -311,6 +311,7 @@ function initDatabase() { try { db.exec('UPDATE productos SET stock = 10 WHERE stock IS NULL'); } catch (e) {} try { db.exec('ALTER TABLE usuarios ADD COLUMN activo INTEGER DEFAULT 1'); } catch (e) {} try { db.exec('UPDATE usuarios SET activo = 1 WHERE activo IS NULL'); } catch (e) {} + try { db.exec("UPDATE ordenes SET estado = 'cancelado' WHERE estado = 'expirado'"); } catch (e) {} // 8. Relación N:M Padres - Estudiantes try { @@ -1623,7 +1624,7 @@ function expirarPreordenesVencidas({ motivo = 'tiempo_limite', escuelaId = null const stmtUpdateOrden = db.prepare(` UPDATE ordenes - SET estado = 'expirado', observaciones = COALESCE(observaciones || ' | ', '') || ? + SET estado = 'cancelado', observaciones = COALESCE(observaciones || ' | ', '') || ? WHERE id = ? `); @@ -1639,8 +1640,8 @@ function expirarPreordenesVencidas({ motivo = 'tiempo_limite', escuelaId = null for (const ord of vencidas) { const obs = motivo === 'cierre_caja' - ? 'Expirado por Cierre de Caja del turno' - : 'Expirado automáticamente a las 5:00 PM por no retiro'; + ? 'Cancelada por Cierre de Caja del turno (saldo liberado al estudiante)' + : 'Cancelada automáticamente a las 5:00 PM por no retiro (saldo liberado al estudiante)'; stmtUpdateOrden.run(obs, ord.id); liberadoColones += ord.total_colones;