podzial dzienny

This commit is contained in:
Mateusz Gruszczyński
2025-09-17 21:53:28 +02:00
parent 92bc3e59ae
commit b386364cd6

View File

@@ -20,8 +20,18 @@ document.addEventListener("DOMContentLoaded", function () {
url += '&show_all=true';
}
if (startDate && endDate) {
url += `&start_date=${startDate}&end_date=${endDate}`;
// Jeśli zakres to custom, to wymuszamy przekazanie dat jako kompletny URL
if (range === 'custom' && startDate && endDate) {
url = `/expenses_data?range=custom&start_date=${startDate}&end_date=${endDate}`;
if (showAllCheckbox) {
url += showAllCheckbox.checked ? '&show_all=true' : '&show_all=false';
} else {
url += '&show_all=true';
}
} else {
if (startDate && endDate) {
url += `&start_date=${startDate}&end_date=${endDate}`;
}
}
if (window.selectedCategoryId) {
@@ -115,11 +125,16 @@ document.addEventListener("DOMContentLoaded", function () {
toggleBtn.addEventListener("click", function () {
categorySplit = !categorySplit;
// Znajdź aktualnie aktywny przycisk podziału czasu
let activeRange = 'currentmonth'; // domyślna wartość
const startDateInput = document.getElementById("startDate");
const endDateInput = document.getElementById("endDate");
const startDate = startDateInput ? startDateInput.value : null;
const endDate = endDateInput ? endDateInput.value : null;
// Wybierz zakres - przy daily ustawiamy range = 'custom', by respektować daty
let activeRange = 'currentmonth'; // default
if (document.getElementById('toggleDailySplit').classList.contains('btn-primary')) {
activeRange = 'daily';
activeRange = (startDate && endDate) ? 'custom' : 'daily';
} else if (document.getElementById('toggleMonthlySplit').classList.contains('btn-primary')) {
activeRange = 'monthly';
}
@@ -134,13 +149,6 @@ document.addEventListener("DOMContentLoaded", function () {
this.classList.add("btn-outline-warning");
}
// Pobierz wybrane daty
const startDateInput = document.getElementById("startDate");
const endDateInput = document.getElementById("endDate");
const startDate = startDateInput ? startDateInput.value : null;
const endDate = endDateInput ? endDateInput.value : null;
// Wywołaj loadExpenses z przekazaniem zakresu dat, jeśli jest ustawiony
if (startDate && endDate) {
loadExpenses(activeRange, startDate, endDate);
} else {
@@ -148,6 +156,7 @@ document.addEventListener("DOMContentLoaded", function () {
}
});
toggleBtn.textContent = "🔵 Pokaż całościowo";
toggleBtn.classList.remove("btn-outline-warning");
toggleBtn.classList.add("btn-outline-info");