122 lines
4.5 KiB
JavaScript
122 lines
4.5 KiB
JavaScript
|
|
const dateFromInput = document.getElementById("date-from-input");
|
|
const dateToInput = document.getElementById("date-to-input");
|
|
const generateButton = document.getElementById("generate-button");
|
|
const sendByMailButton = document.getElementById("send-by-mail-button");
|
|
const dateToSpan = document.getElementById("date-to-span");
|
|
const dateFromSpan = document.getElementById("date-from-span");
|
|
const dateFrom = new Date(dateFromInput.value);
|
|
const dateTo = new Date(dateToInput.value);
|
|
const reportModel = {
|
|
"DateFrom": dateFrom,
|
|
"DateTo": dateTo
|
|
};
|
|
const tbody = document.getElementById("tbody");
|
|
|
|
function sendByMail() {
|
|
$.ajax({
|
|
url: "/home/sendbymailstatusreport",
|
|
type: "POST",
|
|
contentType: "application/json",
|
|
data: JSON.stringify(reportModel)
|
|
}).done(() => {
|
|
alert("Отчет успешно отправлен на вашу почту!")
|
|
});
|
|
}
|
|
|
|
generateButton.addEventListener("click", () => {
|
|
const dateFrom = new Date(dateFromInput.value);
|
|
const dateTo = new Date(dateToInput.value);
|
|
const reportModel = {
|
|
"DateFrom": dateFrom,
|
|
"DateTo": dateTo
|
|
};
|
|
$.ajax({
|
|
url: "/home/getreport",
|
|
type: "POST",
|
|
contentType: "application/json",
|
|
data: JSON.stringify(reportModel)
|
|
}).done((data) => {
|
|
dateFromSpan.innerHTML = reportModel["DateFrom"].toLocaleDateString();
|
|
dateToSpan.innerHTML = reportModel["DateTo"].toLocaleDateString();
|
|
renderTable(data);
|
|
});
|
|
});
|
|
|
|
function populateTable(data) {
|
|
tbody.innerHTML = ""; // Clear the tbody before populating with new data
|
|
|
|
// Find the maximum length between dishes and alcohol drinks
|
|
let maxLength = 0;
|
|
data.forEach((item) => {
|
|
maxLength = Math.max(maxLength, item.hearings, 1);
|
|
});
|
|
|
|
// Loop through the data and create table rows
|
|
data.forEach((item) => {
|
|
const caseName = item.caseName;
|
|
const hearings = item.hearings;
|
|
const specialization = item.specialization;
|
|
|
|
for (let i = 0; i < maxLength; i++) {
|
|
// Create a new row for each product, but without the productNameCell for additional dishes or drinks
|
|
const row = document.createElement("tr");
|
|
|
|
if (i === 0) {
|
|
// Create the productNameCell and set the rowSpan attribute
|
|
const caseNameCell = document.createElement("td");
|
|
caseNameCell.textContent = caseName;
|
|
caseNameCell.rowSpan = maxLength; // Set the rowSpan to the maximum length
|
|
row.appendChild(caseNameCell);
|
|
}
|
|
|
|
if (i < hearings.length) {
|
|
// Create cells for dishes if available
|
|
const hearing = hearings[i];
|
|
const hearingId = hearing.hearingId;
|
|
const hearingDate = new Date(hearing.Date);
|
|
|
|
const hearingNumberCell = document.createElement("td");
|
|
hearingNumberCell.textContent = hearingId;
|
|
row.appendChild(hearingNumberCell);
|
|
|
|
const hearingDateCell = document.createElement("td");
|
|
if (hearing.dateCreate === null) {
|
|
hearingDateCell.textContent = ""
|
|
|
|
}
|
|
else {
|
|
hearingDateCell.textContent = formatDate(hearingDate); // Format the date
|
|
} row.appendChild(hearingDateCell);
|
|
} else {
|
|
// Create empty cells for dishes if not available
|
|
const emptyCell = document.createElement("td");
|
|
row.appendChild(emptyCell);
|
|
row.appendChild(emptyCell.cloneNode());
|
|
}
|
|
|
|
if (i < 1) {
|
|
// Create cells for alcohol drinks if available
|
|
const specialization = specialization;
|
|
const specializationId = specialization.specializationId;
|
|
|
|
const specializationNumberCell = document.createElement("td");
|
|
specializationNumberCell.textContent = specializationId;
|
|
row.appendChild(specializationNumberCell);
|
|
|
|
const specializationDateCell = document.createElement("td");
|
|
console.log(drink.dateCreate === null);
|
|
|
|
row.appendChild(specializationDateCell);
|
|
} else {
|
|
// Create empty cells for alcohol drinks if not available
|
|
const emptyCell = document.createElement("td");
|
|
row.appendChild(emptyCell);
|
|
row.appendChild(emptyCell.cloneNode());
|
|
}
|
|
|
|
tbody.appendChild(row);
|
|
}
|
|
});
|
|
}
|