From a1a7f499968d26d38f4f4ead54c63a18a531f544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Thu, 25 May 2023 01:59:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=8B=D1=82=D0=B0=D0=BB=D1=81=D1=8F=20?= =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C=20=D0=BE=D1=82=D1=87?= =?UTF-8?q?=D0=B5=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportCustomerLogic.cs | 47 ++++++- .../OfficePackage/PdfBuilderCustomer.cs | 22 ++-- .../SearchModels/CaseSearchModel.cs | 4 + .../SearchModels/HearingSearchModel.cs | 3 + .../StoragesContracts/ICaseStorage.cs | 4 + .../ReportHearingSpecializationViewModel.cs | 8 +- .../Controllers/HomeController.cs | 19 +++ .../wwwroot/js/Report/reportpdf.js | 122 +++++++++++++++++- .../Implements/CaseStorage.cs | 38 ++++++ .../Implements/HearingStorage.cs | 9 ++ .../Controllers/ReportCustomerController.cs | 15 +++ 11 files changed, 274 insertions(+), 17 deletions(-) diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs index 77f317c..2908914 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs @@ -40,6 +40,11 @@ namespace CaseAccountingBusinessLogic.BusinessLogics } public List GetHearingSpecialization(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + /*public List GetHearingSpecialization(ReportBindingModel model) { var result = _hearingStorage .GetFilteredList(new HearingSearchModel { UserId = model.UserId }) @@ -56,7 +61,7 @@ namespace CaseAccountingBusinessLogic.BusinessLogics }) .ToList(); return result; - } + }*/ public List GetLawyersHearing(List lawyers) { @@ -109,6 +114,44 @@ namespace CaseAccountingBusinessLogic.BusinessLogics throw new NotImplementedException(); } + /*public List GetHearingSpecialization(ReportBindingModel model) + { + var hearings = _hearingStorage.GetFilteredList(new HearingSearchModel + { + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + + var casesIds = hearings.Select(x => x.CaseId).ToList(); + + var cases = _caseStorage.GetFullList().Where(x => casesIds.Contains(x.Id)); + + List specializations = new List(); + + foreach (var _case in cases) + { + specializations.Add(_specializationStorage.GetElement(new SpecializationSearchModel { Id = _case.Id })); + } + + *//*var reportRecords = new List(); + + foreach (var _case in cases) + { + ReportHearingSpecializationViewModel reportData = new ReportHearingSpecializationViewModel(); + reportData.Name = _case.Name; + + var hearings = _caseStorage.GetCaseHearing(new() { Id = _case.Id }); + + var specialization = _caseStorage.GetCaseSpecialization(new() { Id = _case.Id }); + + reportData.hearings = hearings; + reportData.Specialization = specialization.Name; + reportRecords.Add(reportData); + }*//* + + //return reportRecords; + }*/ + /*public void SendByMailStatusReport(ReportBindingModel reportModel) { byte[] file = _pdfBuilder.GetHearingSpecializationReportFile(new() @@ -116,7 +159,7 @@ namespace CaseAccountingBusinessLogic.BusinessLogics Title = "Отчет по слушаниям", DateFrom = reportModel.DateFrom, DateTo = reportModel.DateTo, - //Records = GetHearingLawyer(reportModel) + Records = GetHearingSpecialization(reportModel) }); _mailSender.SendMailAsync(new() { diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/PdfBuilderCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/PdfBuilderCustomer.cs index 1e0c2a8..8349fac 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/PdfBuilderCustomer.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/PdfBuilderCustomer.cs @@ -136,25 +136,26 @@ namespace CaseAccountingBusinessLogic.OfficePackage ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "4cm", "5cm", "3cm", "3cm" }); + CreateTable(new List { "4cm", "2cm", "4cm", "2cm", "4cm" }); CreateRow(new PdfRowParameters { - Texts = new List { "Номер слушания", "Дело", "Дата проведения", "Юрист" }, + Texts = new List { "Продукт", "Блюдо", "Дата заказа", "Напиток", "Дата заказа" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); foreach (var record in data.Records) { - List<> casesAndLawyes = record.CaseLawyers; - int recordHeight = casesAndLawyes.Count + 1; + List hearings = record.hearings; + string specialization = record.Specialization; + int recordHeight = Math.Max(hearings.Count + 1, 1); for (int i = 0; i < recordHeight; i++) { - List cellsData = new() { "", "", "", "" }; + List cellsData = new() { "", "", "", "", "" }; if (i == 0) { - cellsData[0] = record.Hearing; + cellsData[0] = record.Information; CreateRow(new PdfRowParameters { Texts = cellsData, @@ -164,12 +165,13 @@ namespace CaseAccountingBusinessLogic.OfficePackage continue; } int k = i - 1; - if (k < casesAndLawyes.Count) + if (k < hearings.Count) { - cellsData[1] = casesAndLawyes[k].Case; - cellsData[2] = casesAndLawyes[k].Date.ToString("yyyy-MM-dd"); - cellsData[3] = casesAndLawyes[k].Lawyer; + cellsData[1] = hearings[k].Id.ToString(); + cellsData[2] = hearings[k].Date.ToString(); } + cellsData[3] = specialization; + CreateRow(new PdfRowParameters { Texts = cellsData, diff --git a/CaseAccounting/CaseAccountingContracts/SearchModels/CaseSearchModel.cs b/CaseAccounting/CaseAccountingContracts/SearchModels/CaseSearchModel.cs index 7aded38..8a53018 100644 --- a/CaseAccounting/CaseAccountingContracts/SearchModels/CaseSearchModel.cs +++ b/CaseAccounting/CaseAccountingContracts/SearchModels/CaseSearchModel.cs @@ -21,5 +21,9 @@ namespace CaseAccountingContracts.SearchModels public int? SpecializationId { get; set; } public int? UserId { get; set; } + + public DateTime? DateFrom { get; set; } + + public DateTime? DateTo { get; set; } } } diff --git a/CaseAccounting/CaseAccountingContracts/SearchModels/HearingSearchModel.cs b/CaseAccounting/CaseAccountingContracts/SearchModels/HearingSearchModel.cs index c425761..0fac904 100644 --- a/CaseAccounting/CaseAccountingContracts/SearchModels/HearingSearchModel.cs +++ b/CaseAccounting/CaseAccountingContracts/SearchModels/HearingSearchModel.cs @@ -15,5 +15,8 @@ namespace CaseAccountingContracts.SearchModels public int? CaseId { get; set; } public int? UserId { get; set; } + + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs index 280f367..0293c21 100644 --- a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs +++ b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs @@ -18,6 +18,10 @@ namespace CaseAccountingContracts.StoragesContracts CaseViewModel? Update(CaseBindingModel model); CaseViewModel? Delete(CaseBindingModel model); + List GetCaseHearing(CaseSearchModel model); + + SpecializationViewModel GetCaseSpecialization(SpecializationSearchModel model); + List GetCaseMTM(int lawyerId); List? GetSpecializationCases(); } diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportHearingSpecializationViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportHearingSpecializationViewModel.cs index 115fd5f..cb2a971 100644 --- a/CaseAccounting/CaseAccountingContracts/ViewModels/ReportHearingSpecializationViewModel.cs +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/ReportHearingSpecializationViewModel.cs @@ -9,10 +9,10 @@ namespace CaseAccountingContracts.ViewModels { public class ReportHearingSpecializationViewModel { - public string Information { get; set; } = string.Empty; - - public DateTime Date { get; set; } - public string Specialization { get; set; } = string.Empty; + + public string Name { get; set; } = string.Empty; + + public List hearings { get; set; } = new(); } } diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs index c26dbf7..559d4dd 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs @@ -117,5 +117,24 @@ namespace CaseAccountingCustomerView.Controllers { return View(); } + + public IActionResult GetReport() + { + return View(); + } + + [HttpPost] + public List? GetReport([FromBody] ReportBindingModel reportModel) + { + if (APIUser.User == null) + { + return new(); + } + reportModel.UserId = APIUser.User.Id; + reportModel.UserEmail = APIUser.User.Login; + List? list = APIUser.PostRequestWithResult> + ("api/reportcustomer/getreportdata", reportModel); + return list; + } } } \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportpdf.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportpdf.js index 5f28270..b75a2e1 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportpdf.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportpdf.js @@ -1 +1,121 @@ - \ No newline at end of file + +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); + } + }); +} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs index 37811e4..265afc5 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs @@ -110,6 +110,15 @@ namespace CaseAccountingDataBaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + else if (model.DateFrom != null && model.DateTo != null) + { + return context.Cases + .Include(x => x.Specialization) + .Include(x => x.User) + .Where(x => x.Date >= model.DateFrom && x.Date <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } else { return new(); @@ -202,5 +211,34 @@ namespace CaseAccountingDataBaseImplement.Implements return result; } + + public List GetCaseHearing(CaseSearchModel model) + { + if (model == null) + { + return new(); + } + using var context = new CaseAccountingDatabase(); + var hearing = context.Hearings. + Where(x => x.CaseId == model.Id). + Select(x => x.GetViewModel). + ToList(); + return hearing; + } + + + public SpecializationViewModel GetCaseSpecialization(SpecializationSearchModel model) + { + if (model == null) + { + return new(); + } + using var context = new CaseAccountingDatabase(); + var specialization = context.Specializations. + FirstOrDefault(x => x.Id == model.Id)?. + GetViewModel; + return specialization; + } + } } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/HearingStorage.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/HearingStorage.cs index 114a79a..08e4d92 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/HearingStorage.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/HearingStorage.cs @@ -83,6 +83,15 @@ namespace CaseAccountingDataBaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + else if (model.DateFrom != null && model.DateTo != null) + { + return context.Hearings + .Include(x => x.Case) + .Include(x => x.User) + .Where(x => x.Date <= model.DateTo && x.Date >= model.DateFrom) + .Select(x => x.GetViewModel) + .ToList(); + } else { return new(); diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/ReportCustomerController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/ReportCustomerController.cs index ad6e11d..c4569cb 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/ReportCustomerController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/ReportCustomerController.cs @@ -1,5 +1,6 @@ using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.BusinessLogicContracts; +using CaseAccountingContracts.ViewModels; using Microsoft.AspNetCore.Mvc; namespace CaseAccountingRestApi.Controllers @@ -21,5 +22,19 @@ namespace CaseAccountingRestApi.Controllers byte[] file = reportLogic.SaveListFile(listModel); return file; } + + + [HttpPost] + public List GetReportData(ReportBindingModel reportModel) + { + var list = reportLogic.GetHearingSpecialization(reportModel); + return list; + } + + [HttpPost] + public void SendByMailStatusReport(ReportBindingModel reportModel) + { + reportLogic.SendByMailStatusReport(reportModel); + } } }