fix: total expenses internal - work good

This commit is contained in:
Angie 2025-08-03 19:45:58 +02:00
parent 37580788f3
commit 35c99a0e62
2 changed files with 17 additions and 5 deletions

View File

@ -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

View File

@ -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) {
<div class="border-t pt-2 font-bold">
<div class="flex justify-between">
<span>Total expenses internal:</span>
<span>${safeToFixed(report.totalExpensesInternal)}</span>
<span>${safeToFixed(totalExpensesInternal)}</span>
</div>
</div>
</div>
@ -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,