From 35c99a0e627f35b001093ee85e2b3f7cf6d2d138 Mon Sep 17 00:00:00 2001 From: Angie Date: Sun, 3 Aug 2025 19:45:58 +0200 Subject: [PATCH] fix: total expenses internal - work good --- frontend/api.js | 4 ++-- frontend/script.js | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/api.js b/frontend/api.js index 375cc69..53652fb 100644 --- a/frontend/api.js +++ b/frontend/api.js @@ -1,8 +1,8 @@ //API -const API_BASE_URL = "http://195.209.214.159/api"; +// const API_BASE_URL = "http://195.209.214.159/api"; //API local -// const API_BASE_URL = "http://localhost:3001/api"; +const API_BASE_URL = "http://localhost:3001/api"; //SHARED diff --git a/frontend/script.js b/frontend/script.js index ce5427e..2e7135f 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -783,6 +783,14 @@ function showReportModal(report, isAdmin = false) { } } + let totalExpensesInternal = 0; + if (Array.isArray(expenses)) { + totalExpensesInternal = expenses.reduce( + (sum, e) => sum + (Number(e.amount) || 0), + 0 + ); + } + const modal = document.getElementById("reportViewModal"); const content = document.getElementById("reportViewContent"); const buttons = document.getElementById("reportModalButtons"); @@ -883,7 +891,7 @@ function showReportModal(report, isAdmin = false) {
Total expenses internal: - €${safeToFixed(report.totalExpensesInternal)} + €${safeToFixed(totalExpensesInternal)}
@@ -1450,7 +1458,7 @@ function updateTotals() { const totalIncome = income + cajaInicial; const cajaFinal = totalIncome - totalExpenses - envelope; - document.getElementById("totalIncome").value = totalIncome.toFixed(2); // <-- Add this line! + document.getElementById("totalIncome").value = totalIncome.toFixed(2); document.getElementById("cajaFinal").textContent = cajaFinal.toFixed(2); } @@ -1489,7 +1497,8 @@ document.getElementById("reportForm").addEventListener("submit", async (e) => { const totalIncomeValue = incomeValue + cajaInicialValue; const totalWagesValue = calculateTotalWages(); - const totalExpensesValue = calculateTotalExpenses() + totalWagesValue; + const totalExpensesInternalValue = calculateTotalExpenses(); + const totalExpensesValue = totalExpensesInternalValue + totalWagesValue; const finalCashValue = totalIncomeValue - totalExpensesValue - envelopeValue; const formData = { @@ -1501,6 +1510,9 @@ document.getElementById("reportForm").addEventListener("submit", async (e) => { wages: JSON.stringify(collectWages()), expenses: JSON.stringify(collectExpenses()), totalWages: isNaN(totalWagesValue) ? 0 : totalWagesValue, + totalExpensesInternal: isNaN(totalExpensesInternalValue) + ? 0 + : totalExpensesInternalValue, totalExpenses: isNaN(totalExpensesValue) ? 0 : totalExpensesValue, envelope: isNaN(envelopeValue) ? 0 : envelopeValue, finalCash: isNaN(finalCashValue) ? 0 : finalCashValue,