From 896b02f70dce5297e3f808a1ebdf9c8c9d08d5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B0=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A4=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Thu, 30 May 2024 10:16:46 +0400 Subject: [PATCH] =?UTF-8?q?=D1=85=D0=B5=D1=85=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 57 +++++------ .../MailWorker/MailKitWorker.cs | 4 +- .../AbstractSaveToPdfClientCaseHearing.cs | 4 +- .../AbstractSaveToPdfClients.cs | 31 ++++-- .../BindingModels/ReportBindingModel.cs | 3 +- .../ReportClientCaseHearingViewModel.cs | 2 +- .../ViewModels/ReportClientsViewModel.cs | 5 +- .../Controllers/ClientController.cs | 30 +++++- .../Controllers/HomeController.cs | 97 ++++++++++++++++++- .../Views/Client/SendMail.cshtml | 63 ++++++++++++ .../Views/Home/Clients.cshtml | 5 + .../Views/Home/Report.cshtml | 58 +++++++++++ .../Controllers/ReportExecutorController.cs | 22 ++++- 13 files changed, 334 insertions(+), 47 deletions(-) create mode 100644 LawFim/LawFirmExecutorApp/Views/Client/SendMail.cshtml create mode 100644 LawFim/LawFirmExecutorApp/Views/Home/Report.cshtml diff --git a/LawFim/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs b/LawFim/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs index d1bd6a1..ca6b105 100644 --- a/LawFim/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/LawFim/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs @@ -110,30 +110,32 @@ namespace LawFirmBusinessLogic.BusinessLogics DateTo = model.DateTo }); - foreach (CaseViewModel cas in cases) - { - foreach (VisitViewModel visit in visits) - { - foreach (int casId in cas.CaseClients.Keys) - { - if (visit.VisitClients.ContainsKey(casId)) - { - foreach (var clId in cas.CaseClients.Values) - { - list.Add(new ReportClientsViewModel - { - Id = casId, - FIO = clients.FirstOrDefault(x => x.Id == casId).FIO, - CaseName = cas.Name, - VisitDate = visit.VisitDate + foreach (ClientViewModel client in clients) + { + var record = new ReportClientsViewModel + { + FIO = client.FIO, + CaseName = new List(), + VisitDate = new List() + }; - }); - } - } - } - } - } - return list; + foreach (var cas in cases) + { + if (cas.CaseClients.ContainsKey(client.Id)) + { + record.CaseName.Add(cas.Name); + } + } + foreach (var vis in visits) + { + if (vis.VisitClients.ContainsKey(client.Id)) + { + record.VisitDate.Add(vis.VisitDate); + } + } + list.Add(record); + } + return list; } public List GetVisitLawyer(ReportVisitLawyerBindingModel model) @@ -256,14 +258,14 @@ namespace LawFirmBusinessLogic.BusinessLogics return list; } - public List GetCaseHearing(ReportClientCaseHearingBindingModel model) + public List GetClientCaseHearing(ReportClientCaseHearingBindingModel model) { var list = new List(); var clients = _clientStorage.GetFilteredList(new ClientSearchModel { Id = model.ClientId }); var cases = _caseStorage.GetFilteredList(new CaseSearchModel { ExecutorId = model.ExecutorId }); var hearings = _hearingStorage.GetFilteredList(new HearingSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); var visits = _visitStorage.GetFilteredList(new VisitSearchModel { ExecutorId = model.ExecutorId }); - foreach (ClientViewModel client in clients) + foreach (var client in clients) { var record = new ReportClientCaseHearingViewModel { @@ -274,7 +276,7 @@ namespace LawFirmBusinessLogic.BusinessLogics { if (cas.CaseClients.ContainsKey(client.Id)) { - record.Case.Add(new(cas.DateCreate, cas.Name)); + record.Case.Add(new(cas.Name, cas.CaseType)); } } foreach (var visit in visits) @@ -368,7 +370,7 @@ namespace LawFirmBusinessLogic.BusinessLogics Title = "Отчёт по делам и слушаниям по выбранным клиентам", DateFrom = model.DateFrom, DateTo = model.DateTo, - ClientCaseHearing = GetCaseHearing(model) + ClientCaseHearing = GetClientCaseHearing(model) }); } @@ -381,7 +383,6 @@ namespace LawFirmBusinessLogic.BusinessLogics DateFrom = model.DateFrom, DateTo = model.DateTo, CaseHearing = GetCaseHearing(model) - }); } } diff --git a/LawFim/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs b/LawFim/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs index 1beeeb0..05e4cab 100644 --- a/LawFim/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs +++ b/LawFim/LawFirmBusinessLogic/MailWorker/MailKitWorker.cs @@ -25,8 +25,8 @@ namespace LawFirmBusinessLogic.MailWorker objMailMessage.Body = info.Text; objMailMessage.SubjectEncoding = Encoding.UTF8; objMailMessage.BodyEncoding = Encoding.UTF8; - //Attachment attachment = new Attachment("E:\\reports\\pdf\\file.pdf", new ContentType(MediaTypeNames.Application.Pdf)); - Attachment attachment = new Attachment("D:\\CourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf)); + Attachment attachment = new Attachment("E:\\reports\\pdf\\file.pdf", new ContentType(MediaTypeNames.Application.Pdf)); + //Attachment attachment = new Attachment("D:\\CourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf)); objMailMessage.Attachments.Add(attachment); objSmtpClient.UseDefaultCredentials = false; diff --git a/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClientCaseHearing.cs b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClientCaseHearing.cs index ac192aa..6d5287c 100644 --- a/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClientCaseHearing.cs +++ b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClientCaseHearing.cs @@ -28,7 +28,7 @@ namespace LawFirmBusinessLogic.OfficePackages CreateTable(new List { "3cm", "5cm", "5cm" }); CreateRow(new PdfRowParameters { - Texts = new List { "Клиент", "Дело", "Дата начала дела" }, + Texts = new List { "Клиент", "Дело", "Тип" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); @@ -45,7 +45,7 @@ namespace LawFirmBusinessLogic.OfficePackages foreach (var cas in ch.Case) CreateRow(new PdfRowParameters { - Texts = new List { " ", cas.CaseName, cas.CaseDate.ToShortDateString() }, + Texts = new List { " ", cas.CaseName, cas.CaseType }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); diff --git a/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClients.cs b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClients.cs index 9a7075b..09d36bc 100644 --- a/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClients.cs +++ b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfClients.cs @@ -29,14 +29,31 @@ namespace LawFirmBusinessLogic.OfficePackages }); foreach (var client in info.Clients) { - CreateRow(new PdfRowParameters + CreateRow(new PdfRowParameters + { + Texts = new List { client.FIO, " ", " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach(var cas in client.CaseName) { - Texts = new List { client.Id.ToString(), client.FIO, - client.CaseName, client.VisitDate.ToString()}, - Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Left - }); - } + CreateRow(new PdfRowParameters + { + Texts = new List { " ", cas, " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + foreach (var vis in client.VisitDate) + { + CreateRow(new PdfRowParameters + { + Texts = new List { " ", " ", vis.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + } + } SavePdf(info); } diff --git a/LawFim/LawFirmContracts/BindingModels/ReportBindingModel.cs b/LawFim/LawFirmContracts/BindingModels/ReportBindingModel.cs index ed8c83a..428e3a1 100644 --- a/LawFim/LawFirmContracts/BindingModels/ReportBindingModel.cs +++ b/LawFim/LawFirmContracts/BindingModels/ReportBindingModel.cs @@ -12,5 +12,6 @@ namespace LawFirmContracts.BindingModels public DateTime? DateTo { get; set; } public int? ExecutorId { get; set; } //? public int? GuarantorId { get; set; } - } + public string? Email { get; set; } + } } diff --git a/LawFim/LawFirmContracts/ViewModels/ReportClientCaseHearingViewModel.cs b/LawFim/LawFirmContracts/ViewModels/ReportClientCaseHearingViewModel.cs index 3fa5931..3434bfc 100644 --- a/LawFim/LawFirmContracts/ViewModels/ReportClientCaseHearingViewModel.cs +++ b/LawFim/LawFirmContracts/ViewModels/ReportClientCaseHearingViewModel.cs @@ -3,7 +3,7 @@ public class ReportClientCaseHearingViewModel { public string ClientName { get; set; } = string.Empty; - public List<(DateTime CaseDate, string CaseName)> Case { get; set; } = new(); + public List<(string CaseName, string CaseType)> Case { get; set; } = new(); public List<(DateTime HearingDate, string Judge)> Hearing { get; set; } = new(); } } diff --git a/LawFim/LawFirmContracts/ViewModels/ReportClientsViewModel.cs b/LawFim/LawFirmContracts/ViewModels/ReportClientsViewModel.cs index 0c13102..9ca706e 100644 --- a/LawFim/LawFirmContracts/ViewModels/ReportClientsViewModel.cs +++ b/LawFim/LawFirmContracts/ViewModels/ReportClientsViewModel.cs @@ -2,9 +2,8 @@ { public class ReportClientsViewModel { - public int Id { get; set; } public string FIO { get; set; } = string.Empty; - public string CaseName { get; set; } = string.Empty; - public DateTime VisitDate { get; set; } // ? + public List CaseName { get; set; } = new List(); + public List VisitDate { get; set; } = new List(); } } diff --git a/LawFim/LawFirmExecutorApp/Controllers/ClientController.cs b/LawFim/LawFirmExecutorApp/Controllers/ClientController.cs index cc74aa9..17e40b0 100644 --- a/LawFim/LawFirmExecutorApp/Controllers/ClientController.cs +++ b/LawFim/LawFirmExecutorApp/Controllers/ClientController.cs @@ -132,5 +132,33 @@ namespace LawFirmExecutorApp.Controllers { return new PhysicalFileResult("E:\\reports\\excelclientsreport.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); } - } + + [HttpGet] + public IActionResult SendMail() + { + ViewBag.Clients = APIClient.GetRequest>($"api/client/getclientlist?executorid={APIClient.Executor.Id}"); + ViewBag.Report = new List(); + return View(); + } + + [HttpPost] + public void SendMail(DateTime dateFrom, DateTime dateTo, int clientId) + { + if (APIClient.Executor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/reportexecutor/mailsend", new ReportClientCaseHearingBindingModel + { + //FileName = "E:\\reports\\pdffile.pdf", + ExecutorId = APIClient.Executor.Id, + DateFrom = dateFrom, + DateTo = dateTo, + Email = APIClient.Executor.Email, + ClientId = clientId + }); + Response.Redirect("SendMail"); + + } + } } diff --git a/LawFim/LawFirmExecutorApp/Controllers/HomeController.cs b/LawFim/LawFirmExecutorApp/Controllers/HomeController.cs index e54eff7..31ee482 100644 --- a/LawFim/LawFirmExecutorApp/Controllers/HomeController.cs +++ b/LawFim/LawFirmExecutorApp/Controllers/HomeController.cs @@ -3,6 +3,7 @@ using LawFirmContracts.ViewModels; using LawFirmExecutorApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using System.Globalization; namespace LawFirmExecutorApp.Controllers { @@ -143,5 +144,99 @@ namespace LawFirmExecutorApp.Controllers { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } - } + + public IActionResult Report() + { + ViewBag.Report = new List(); + return View(); + } + + [HttpGet] + public string GetReport(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Executor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture); + string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture); + result = APIClient.GetRequest> + ($"api/reportexecutor/getconsultationhearingreport?datefrom={dateFromS}&dateto={dateToS}&executorid={APIClient.Executor.Id}")!; + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + + string table = ""; + table += "

Предварительный отчет

"; + table += "
"; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + foreach (var client in result) + { + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + foreach (var cons in client.CaseName) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += ""; + } + foreach (var hear in client.VisitDate) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += ""; + } + table += ""; + } + table += "
КлиентЦена консультацииДата консультацииСудДата слушания
{client.FIO}
{cons}
{hear}
"; + table += "
"; + return table; + } + + [HttpPost] + public void Report(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Executor == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/reportexecutor/mailsend", new ReportBindingModel + { + FileName = "D:\\CourseWork\\pdfConsultationHearingsReport.pdf", + ExecutorId = APIClient.Executor.Id, + DateFrom = dateFrom, + DateTo = dateTo, + Email = APIClient.Executor.Email + + }); + Response.Redirect("Report"); + + } + } } \ No newline at end of file diff --git a/LawFim/LawFirmExecutorApp/Views/Client/SendMail.cshtml b/LawFim/LawFirmExecutorApp/Views/Client/SendMail.cshtml new file mode 100644 index 0000000..7926e68 --- /dev/null +++ b/LawFim/LawFirmExecutorApp/Views/Client/SendMail.cshtml @@ -0,0 +1,63 @@ +@{ + ViewData["Title"] = "SendMail"; +} + +
+
+

Отправка на почту отчета по клиентам с расшифровкой по слушаниям и делам

+
+ +
+
+
Юрист:
+
+ +
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+ +
+
+ +@section Scripts { + +} \ No newline at end of file diff --git a/LawFim/LawFirmExecutorApp/Views/Home/Clients.cshtml b/LawFim/LawFirmExecutorApp/Views/Home/Clients.cshtml index d1d2ea5..7da9235 100644 --- a/LawFim/LawFirmExecutorApp/Views/Home/Clients.cshtml +++ b/LawFim/LawFirmExecutorApp/Views/Home/Clients.cshtml @@ -75,6 +75,11 @@ + +
+ +
+ } \ No newline at end of file diff --git a/LawFim/LawFirmExecutorApp/Views/Home/Report.cshtml b/LawFim/LawFirmExecutorApp/Views/Home/Report.cshtml new file mode 100644 index 0000000..0ca2b94 --- /dev/null +++ b/LawFim/LawFirmExecutorApp/Views/Home/Report.cshtml @@ -0,0 +1,58 @@ +@{ + ViewData["Title"] = "Report"; +} + +
+
+

Отчет по клиентам за период

+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+ +
+
+
+ +@section Scripts { + +} \ No newline at end of file diff --git a/LawFim/LawFirmRestApi/Controllers/ReportExecutorController.cs b/LawFim/LawFirmRestApi/Controllers/ReportExecutorController.cs index 1c338cd..b47f0b1 100644 --- a/LawFim/LawFirmRestApi/Controllers/ReportExecutorController.cs +++ b/LawFim/LawFirmRestApi/Controllers/ReportExecutorController.cs @@ -42,6 +42,26 @@ namespace LawFirmRestApi.Controllers } } [HttpPost] + public void SaveCaseHearingToPdfFile(ReportClientCaseHearingBindingModel report) + { + try + { + _reportLogic.SaveClientCaseHearingToPdfFile(new ReportClientCaseHearingBindingModel + { + DateFrom = report.DateFrom, + DateTo = report.DateTo, + FileName = "E:\\reports\\pdfClientCaseHearingsReport.pdf", + ExecutorId = report.ExecutorId, + ClientId = report.ClientId, + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] public void SaveClientsWordFile(ReportBindingModel report) { try @@ -76,7 +96,7 @@ namespace LawFirmRestApi.Controllers { DateFrom = report.DateFrom, DateTo = report.DateTo, - FileName = report.FileName, + FileName = "E:\\reports\\file.pdf", ExecutorId = report.ExecutorId, ClientId = report.ClientId, Email = report.Email,