feat: add possibility create a report with choice of the date, change of the date and shop for today's report for the worker

This commit is contained in:
Angie 2025-08-05 14:13:30 +02:00
parent c644419ed8
commit 60b1b4b15a
3 changed files with 85 additions and 9 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
@ -353,7 +353,18 @@ async function updateReport(reportId, data) {
},
body: JSON.stringify(data),
});
// handler for duplicates error before parsing
if (res.status === 409) {
showNotification(
"Отчет за этот магазин и дату уже был отправлен этим пользователем.",
"error"
);
return { success: false, error: "Дубликат отчета" };
}
const result = await res.json();
if (res.ok && result.updated) {
showNotification("Отчет обновлен!", "success");
hideModal("reportViewModal");

View File

@ -109,6 +109,27 @@
<!-- Форма отчета -->
<div class="container mx-auto p-6">
<form id="reportForm" class="bg-white rounded-lg shadow-xl p-6">
<!-- Дата отчета -->
<div class="mb-6">
<label class="block text-gray-700 text-sm font-bold mb-2">
<i class="fas fa-calendar-alt mr-2"></i>Дата отчета *
</label>
<input
type="date"
id="reportDate"
class="form-input w-full px-3 py-2 rounded-lg"
required
/>
</div>
<div
id="dateEditWarning"
class="hidden mt-2 text-yellow-800 bg-yellow-100 rounded px-4 py-2 text-sm"
>
<i class="fas fa-exclamation-triangle mr-2"></i>
Внимание: изменение даты отчета может повлиять на доступность
редактирования.
</div>
<!-- Выбор магазина -->
<div class="mb-6">
<label class="block text-gray-700 text-sm font-bold mb-2">

View File

@ -1117,6 +1117,28 @@ function fillFormWithReport(report) {
report.cajaInicial || report.initialCash || 0;
document.getElementById("envelope").value = report.envelope;
document.getElementById("displayTotalIncome").value = report.totalIncome;
// document.getElementById("reportDate").value =
// report.reportDate || report.date || "";
// --- Deal with date change tooltip ---
// Set the date value
const dateInput = document.getElementById("reportDate");
const originalDate = report.reportDate || report.date || "";
dateInput.value = originalDate;
// Store the original date for later check
dateInput.dataset.originalDate = originalDate;
// Hide warning by default
document.getElementById("dateEditWarning").classList.add("hidden");
// Set up change listener
dateInput.oninput = function () {
if (dateInput.value && dateInput.value !== dateInput.dataset.originalDate) {
document.getElementById("dateEditWarning").classList.remove("hidden");
} else {
document.getElementById("dateEditWarning").classList.add("hidden");
}
};
// --- Parse wages/expenses if they are string ---
let wages = report.wages;
@ -1456,18 +1478,23 @@ function safeToFixed(value, digits = 2) {
}
function upsertTodaysReport(report) {
const today =
report.reportDate || report.date || new Date().toISOString().split("T")[0];
const today = new Date().toISOString().split("T")[0];
const storeId = String(report.storeId);
appState.todaysReports = (appState.todaysReports || []).filter(
(r) =>
appState.todaysReports = (appState.todaysReports || []).filter((r) => {
return (
!(r.id === report.id) &&
!(
String(r.storeId) === storeId &&
(r.reportDate || r.date) === today &&
(r.userId == report.userId || r.username === report.username)
)
);
appState.todaysReports.push(report);
);
});
// Add again only if the edited report is for today
if ((report.reportDate || report.date) === today) {
appState.todaysReports.push(report);
}
}
// save report as user-worker
@ -1488,7 +1515,11 @@ document.getElementById("reportForm").addEventListener("submit", async (e) => {
const formData = {
storeId: parseInt(document.getElementById("storeSelect").value),
reportDate: new Date().toISOString().split("T")[0],
// reportDate: new Date().toISOString().split("T")[0],
reportDate:
document.getElementById("reportDate").value ||
new Date().toISOString().split("T")[0],
income: isNaN(incomeValue) ? 0 : incomeValue,
initialCash: isNaN(cajaInicialValue) ? 0 : cajaInicialValue,
totalIncome: isNaN(totalIncomeValue) ? 0 : totalIncomeValue,
@ -1561,6 +1592,19 @@ function resetReportForm() {
document.getElementById("totalWages").textContent = "0.00";
document.getElementById("totalExpensesInternal").textContent = "0.00";
document.getElementById("cajaFinal").textContent = "0.00";
// today
const today = new Date().toISOString().split("T")[0];
// left date blank
document.getElementById("reportDate").value = "";
document.getElementById("reportDate").setAttribute("max", today);
// OR
// Set date field to today and restrict to today or earlier
// document.getElementById("reportDate").value = today;
// document.getElementById("reportDate").setAttribute("max", today);
//clean tooltip about changing date on the report
document.getElementById("dateEditWarning").classList.add("hidden");
}
// Отчет за сегодня для пользователя