From e1f780ea11bd8303ed168336f7fae04c91a50dc4 Mon Sep 17 00:00:00 2001 From: Naiel <109038805+naielv@users.noreply.github.com> Date: Wed, 25 Feb 2026 14:25:12 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20A=C3=B1adir=20estad=C3=ADsticas=20de=20?= =?UTF-8?q?ingresos,=20gastos=20y=20mensajes=20sin=20leer=20en=20la=20p?= =?UTF-8?q?=C3=A1gina=20de=20inicio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app_modules.js | 2 +- src/config.js | 6 + src/page/index.js | 279 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+), 1 deletion(-) diff --git a/src/app_modules.js b/src/app_modules.js index acaf01e..b89ed4d 100644 --- a/src/app_modules.js +++ b/src/app_modules.js @@ -1261,7 +1261,7 @@ function TS_IndexElement( }); document.getElementById(filter_tr).innerHTML = 'Filtrando por: ' + Object.entries(filters) .map(([key, value]) => `${key}`) - .join(', ') + ' - Limpiar filtros'; + .join(', ') + ' - Limpiar filtros'; } function searchInData(data, searchValue, config) { if (filters) { diff --git a/src/config.js b/src/config.js index 0e8dc36..cd3fc00 100644 --- a/src/config.js +++ b/src/config.js @@ -138,3 +138,9 @@ function TS_SayTTS(msg) { } } catch { console.warn('TTS error'); } } + +function createElementFromHTML(htmlString) { + var div = document.createElement('div'); + div.innerHTML = htmlString.trim(); + return div.firstChild; +} \ No newline at end of file diff --git a/src/page/index.js b/src/page/index.js index 90ee77f..942b5c4 100644 --- a/src/page/index.js +++ b/src/page/index.js @@ -3,17 +3,296 @@ PAGES.index = { Title: 'Inicio', icon: 'static/appico/house.png', index: function () { + var div_stats = safeuuid(); + container.innerHTML = html`

¡Hola, ${SUB_LOGGED_IN_DETAILS.Nombre}!
Bienvenidx a %%TITLE%%

Tienes ${parseFloat(SUB_LOGGED_IN_DETAILS.Monedero_Balance).toPrecision(2)} € en el monedero.

+
Utiliza el menú superior para abrir un modulo

`; + + if (checkRole('pagos')) { + var total_ingresos = safeuuid(); + var total_gastos = safeuuid(); + var balance_total = safeuuid(); + var total_ingresos_srcel = html` +
+ Pagos
+

Total Ingresos

+
+ 0.00€ +
+
+ `; + var total_gastos_srcel = html` +
+ Pagos
+

Total Gastos

+
+ 0.00€ +
+
+ `; + var balance_total_srcel = html` +
+ Pagos
+

Balance Total

+
+ 0.00€ +
+
+ `; + document.getElementById(div_stats).appendChild(createElementFromHTML(total_ingresos_srcel)); + document.getElementById(div_stats).appendChild(createElementFromHTML(total_gastos_srcel)); + document.getElementById(div_stats).appendChild(createElementFromHTML(balance_total_srcel)); + + let totalData = { + ingresos: {}, + gastos: {}, + }; + + EventListeners.DB.push( + DB.map('pagos', (data, key) => { + function applyData(row) { + if (!row || typeof row !== 'object') { + delete totalData.ingresos[key]; + delete totalData.gastos[key]; + } else { + const monto = parseFloat(row.Monto || 0) || 0; + const tipo = row.Tipo; + + if (tipo === 'Ingreso') { + if (row.Origen != 'Promo Bono') { + totalData.gastos[key] = 0; + totalData.ingresos[key] = monto; + } + } else if (tipo === 'Gasto') { + totalData.ingresos[key] = 0; + totalData.gastos[key] = monto; + } else { + totalData.ingresos[key] = 0; + totalData.gastos[key] = 0; + } + } + + const totalIngresos = Object.values(totalData.ingresos).reduce((a, b) => a + b, 0); + const totalGastos = Object.values(totalData.gastos).reduce((a, b) => a + b, 0); + + document.getElementById(total_ingresos).innerText = totalIngresos.toFixed(2) + '€'; + document.getElementById(total_gastos).innerText = totalGastos.toFixed(2) + '€'; + } + + if (typeof data == 'string') { + TS_decrypt(data, SECRET, (decoded) => { + applyData(decoded); + }); + } else { + applyData(data); + } + }) + ); + + EventListeners.Interval.push( + setInterval(() => { + var balanceReal = 0; + Object.values(SC_Personas).forEach((persona) => { + balanceReal += parseFloat(persona.Monedero_Balance || 0); + }); + document.getElementById(balance_total).innerText = balanceReal.toFixed(2) + '€'; + document.getElementById(balance_total).style.color = + balanceReal >= 0 ? 'white' : '#ffcccc'; + }, 1000) + ); + } + + if (checkRole('mensajes')) { + var mensajes_sin_leer = safeuuid(); + var mensajes_sin_leer_srcel = html` +
+ Mensajes
+

Sin leer

+
+ 0 +
+
+ `; + document.getElementById(div_stats).appendChild(createElementFromHTML(mensajes_sin_leer_srcel)); + + var unreadById = {}; + + EventListeners.DB.push( + DB.map('mensajes', (data, key) => { + function applyUnread(row) { + if (!row || typeof row !== 'object') { + delete unreadById[key]; + } else { + var estado = String(row.Estado || '').trim().toLowerCase(); + var isRead = estado === 'leido' || estado === 'leído'; + unreadById[key] = isRead ? 0 : 1; + } + + var totalUnread = Object.values(unreadById).reduce((a, b) => a + b, 0); + document.getElementById(mensajes_sin_leer).innerText = String(totalUnread); + } + + if (typeof data == 'string') { + TS_decrypt(data, SECRET, (decoded) => { + applyUnread(decoded); + }); + } else { + applyUnread(data); + } + }) + ); + } + + if (checkRole('supercafe')) { + var comandas_en_deuda = safeuuid(); + var comandas_en_deuda_srcel = html` +
+ SuperCafé
+

Comandas en deuda

+
+ 0 +
+
+ `; + document.getElementById(div_stats).appendChild(createElementFromHTML(comandas_en_deuda_srcel)); + + var deudaById = {}; + + EventListeners.DB.push( + DB.map('supercafe', (data, key) => { + function applyDeuda(row) { + if (!row || typeof row !== 'object') { + delete deudaById[key]; + } else { + var estado = String(row.Estado || '').trim().toLowerCase(); + deudaById[key] = estado === 'deuda' ? 1 : 0; + } + + var totalDeuda = Object.values(deudaById).reduce((a, b) => a + b, 0); + document.getElementById(comandas_en_deuda).innerText = String(totalDeuda); + } + + if (typeof data == 'string') { + TS_decrypt(data, SECRET, (decoded) => { + applyDeuda(decoded); + }); + } else { + applyDeuda(data); + } + }) + ); + } + + if (checkRole('materiales')) { + var materiales_comprar = safeuuid(); + var materiales_revisar = safeuuid(); + + var materiales_comprar_srcel = html` +
+ Almacén
+

Por comprar

+
+ 0 +
+
+ `; + + var materiales_revisar_srcel = html` +
+ Almacén
+

Por revisar

+
+ 0 +
+
+ `; + + document.getElementById(div_stats).appendChild(createElementFromHTML(materiales_comprar_srcel)); + document.getElementById(div_stats).appendChild(createElementFromHTML(materiales_revisar_srcel)); + + var comprarById = {}; + var revisarById = {}; + + EventListeners.DB.push( + DB.map('materiales', (data, key) => { + function applyMaterialStats(row) { + if (!row || typeof row !== 'object') { + delete comprarById[key]; + delete revisarById[key]; + } else { + var cantidad = parseFloat(row.Cantidad); + var cantidadMinima = parseFloat(row.Cantidad_Minima); + var lowStock = !isNaN(cantidad) && !isNaN(cantidadMinima) && cantidad < cantidadMinima; + comprarById[key] = lowStock ? 1 : 0; + + var revision = String(row.Revision || '?').trim(); + var needsReview = false; + + if (revision === '?' || revision === '' || revision === '-') { + needsReview = true; + } else { + var match = revision.match(/^(\d{4})-(\d{2})-(\d{2})$/); + if (!match) { + needsReview = true; + } else { + var y = parseInt(match[1], 10); + var m = parseInt(match[2], 10) - 1; + var d = parseInt(match[3], 10); + var revisionMs = Date.UTC(y, m, d); + var now = new Date(); + var todayMs = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()); + var diffDays = Math.floor((todayMs - revisionMs) / 86400000); + needsReview = diffDays >= 90; + } + } + + revisarById[key] = needsReview ? 1 : 0; + } + + var totalComprar = Object.values(comprarById).reduce((a, b) => a + b, 0); + var totalRevisar = Object.values(revisarById).reduce((a, b) => a + b, 0); + + document.getElementById(materiales_comprar).innerText = String(totalComprar); + document.getElementById(materiales_revisar).innerText = String(totalRevisar); + } + + if (typeof data == 'string') { + TS_decrypt(data, SECRET, (decoded) => { + applyMaterialStats(decoded); + }); + } else { + applyMaterialStats(data); + } + }) + ); + } }, edit: function (mid) { switch (mid) {