diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs index 7493913..2965211 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ReportLogic.cs @@ -188,19 +188,12 @@ namespace LawFirmBusinessLogic.BusinessLogics public List GetConsultationHearing(ReportBindingModel model) { var list = new List(); - var lawyers = _lawyerStorage.GetFullList(); - var consultations = _consultationStorage.GetFullList(); - var visits = _visitStorage.GetFilteredList(new VisitSearchModel - { - - DateFrom - = model.DateFrom, - DateTo = model.DateTo - }); + var lawyers = _lawyerStorage.GetFilteredList(new LawyerSearchModel { CompanyId = model.CompanyId}); + var consultations = _consultationStorage.GetFilteredList(new ConsultationSearchModel { CompanyId = model.CompanyId }); var hearings = _hearingStorage.GetFilteredList(new HearingSearchModel { - DateFrom - = model.DateFrom, + CompanyId = model.CompanyId, + DateFrom = model.DateFrom, DateTo = model.DateTo }); foreach (LawyerViewModel lawyer in lawyers) @@ -215,17 +208,9 @@ namespace LawFirmBusinessLogic.BusinessLogics foreach (var consultation in consultations) { - if (consultation.ConsultationLawyers.ContainsKey(lawyer.Id)) { - - foreach (var visit in visits) - { - if (visit.ConsultationId == consultation.Id) - { - record.Consultation.Add(new(consultation.Id, consultation.Cost)); - } - - - } + if (consultation.ConsultationLawyers.ContainsKey(lawyer.Id)) + { + record.Consultation.Add(new(consultation.Id, consultation.Cost)); } } foreach(var hearing in hearings) @@ -234,7 +219,6 @@ namespace LawFirmBusinessLogic.BusinessLogics { record.Hearing.Add(new(hearing.HearingDate, hearing.Court)); } - } list.Add(record); } diff --git a/LawFirm/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfConsultationHearing.cs b/LawFirm/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfConsultationHearing.cs index 2dbf6b6..30aebb3 100644 --- a/LawFirm/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfConsultationHearing.cs +++ b/LawFirm/LawFirmBusinessLogic/OfficePackages/AbstractSaveToPdfConsultationHearing.cs @@ -16,18 +16,16 @@ namespace LawFirmBusinessLogic.OfficePackages CreateParagraph(new PdfParagraph { Text = info.Title, - Style = - "NormalTitle", + Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); CreateParagraph(new PdfParagraph { Text = $"с{info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", - Style - = "Normal", + Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "5cm", "3cm", "4cm" }); + CreateTable(new List { "3cm", "5cm", "5cm" }); CreateRow(new PdfRowParameters { Texts = new List { "Юрист", "Номер консультации", "Цена консультации" }, @@ -37,23 +35,29 @@ namespace LawFirmBusinessLogic.OfficePackages foreach (var ch in info.ConsultationHearing) { + CreateRow(new PdfRowParameters + { + Texts = new List { ch.LawyerName, " ", " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + + }); foreach (var cons in ch.Consultation) CreateRow(new PdfRowParameters { - Texts = new List { ch.LawyerName, cons.Id.ToString(), cons.Price.ToString()}, + Texts = new List {" ", cons.Id.ToString(), cons.Price.ToString()}, Style = "Normal", - ParagraphAlignment = PdfParagraphAlignmentType.Left + ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateParagraph(new PdfParagraph + CreateRow(new PdfRowParameters { - Text = $"Итого: {ch.Consultation.Count}\t", + Texts = new List { " ", " ", "Итого: " + ch.Consultation.Count.ToString() }, Style = "Normal", - ParagraphAlignment = - PdfParagraphAlignmentType.Rigth + ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); } - CreateTable(new List { "2cm", "3cm", "6cm", "3cm" }); + CreateTable(new List { "3cm", "5cm", "5cm"}); CreateRow(new PdfRowParameters { Texts = new List { "Юрист", "Суд", "Дата слушания" }, @@ -62,19 +66,25 @@ namespace LawFirmBusinessLogic.OfficePackages }); foreach (var ch in info.ConsultationHearing) { + CreateRow(new PdfRowParameters + { + Texts = new List {ch.LawyerName, " ", " " }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + + }); foreach (var hear in ch.Hearing) CreateRow(new PdfRowParameters { - Texts = new List { ch.LawyerName, hear.Court, hear.HearingDate.ToShortDateString() }, + Texts = new List { " ", hear.Court, hear.HearingDate.ToShortDateString() }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); - CreateParagraph(new PdfParagraph + CreateRow(new PdfRowParameters { - Text = $"Итого: {ch.Hearing.Count}\t", + Texts = new List { " ", " ", "Итого: " + ch.Hearing.Count.ToString()}, Style = "Normal", - ParagraphAlignment = - PdfParagraphAlignmentType.Rigth + ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); } diff --git a/LawFirm/LawFirmClientApp/Controllers/ReportController.cs b/LawFirm/LawFirmClientApp/Controllers/ReportController.cs index cb004f5..5a4fe8b 100644 --- a/LawFirm/LawFirmClientApp/Controllers/ReportController.cs +++ b/LawFirm/LawFirmClientApp/Controllers/ReportController.cs @@ -64,6 +64,5 @@ namespace LawFirmClientApp.Controllers return View(APIClient.GetRequest>($"api/report/getclientsreport?datefrom={dateFrom}&dateTo={dateTo}&companyId={APIClient.User.CompanyId}")); } - } } diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs index 1b6c029..dfd108f 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IReportLogic.cs @@ -12,21 +12,16 @@ namespace LawFirmContracts.BusinessLogicContracts { List GetClientsHearing(ReportBindingModel model); - List GetGetClients(ReportBindingModel model); - List GetVisitLawyer(ReportBindingModel model); List GetConsultationHearing(ReportBindingModel model); void SaveClientsHearingToWordFile(ReportBindingModel model); - void SaveClientsHearingToExcelFile(ReportBindingModel model); - void SaveVisitLawyerToWordFile(ReportBindingModel model); void SaveVisitLawyerToExcelFile(ReportBindingModel model); void SaveConsultationHearingToPdfFile(ReportBindingModel model); - void SaveClientsToPdfFile(ReportBindingModel model); } diff --git a/LawFirm/LawFirmDatabaseImplement/Implements/HearingStorage.cs b/LawFirm/LawFirmDatabaseImplement/Implements/HearingStorage.cs index f873fcf..79e420c 100644 --- a/LawFirm/LawFirmDatabaseImplement/Implements/HearingStorage.cs +++ b/LawFirm/LawFirmDatabaseImplement/Implements/HearingStorage.cs @@ -1,4 +1,5 @@ -using LawFirmContracts.BindingModels; +using DocumentFormat.OpenXml.InkML; +using LawFirmContracts.BindingModels; using LawFirmContracts.SearchModels; using LawFirmContracts.StoragesContracts; using LawFirmContracts.ViewModels; @@ -18,7 +19,9 @@ namespace LawFirmDatabaseImplement.Implements { using var context = new LawFirmDatabase(); return context.Hearings - .ToList() + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) + .ToList() .Select(x => x.GetViewModel) .Select(y => { y.CaseName = context.Cases.FirstOrDefault(x => x.Id == y.CaseId).Name; return y; }).ToList(); } @@ -29,11 +32,25 @@ namespace LawFirmDatabaseImplement.Implements { return new(); } + if (model.CompanyId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) + { + using var context = new LawFirmDatabase(); + return context.Hearings + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) + .Where(x => x.CompanyId == model.CompanyId && x.HearingDate >= model.DateFrom && x.HearingDate <= model.DateTo) + .ToList() + .Select(x => x.GetViewModel) + .Select(y => { y.CaseName = context.Cases.FirstOrDefault(x => x.Id == y.CaseId).Name; return y; }) + .ToList(); + } if (model.CompanyId.HasValue) { using var context = new LawFirmDatabase(); return context.Hearings - .Where(x => x.CompanyId == model.CompanyId) + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) + .Where(x => x.CompanyId == model.CompanyId) .ToList() .Select(x => x.GetViewModel) .Select(y => { y.CaseName = context.Cases.FirstOrDefault(x => x.Id == y.CaseId).Name; return y; }) @@ -43,6 +60,8 @@ namespace LawFirmDatabaseImplement.Implements { using var context = new LawFirmDatabase(); return context.Hearings + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) .Where(x => x.Id == model.Id) .ToList() .Select(x => x.GetViewModel) @@ -53,6 +72,8 @@ namespace LawFirmDatabaseImplement.Implements { using var context = new LawFirmDatabase(); return context.Hearings + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) .Where(x => x.HearingDate >= model.DateFrom && x.HearingDate <= model.DateTo) .ToList() .Select(x => x.GetViewModel).Select(y => { y.CaseName = context.Cases.FirstOrDefault(x => x.Id == y.CaseId).Name; return y; }) @@ -67,6 +88,8 @@ namespace LawFirmDatabaseImplement.Implements } using var context = new LawFirmDatabase(); return AccessHearingStorage(context.Hearings + .Include(x => x.Lawyers) + .ThenInclude(x => x.Lawyer) .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.CompanyId.HasValue && x.CompanyId == model.CompanyId)) @@ -104,7 +127,7 @@ namespace LawFirmDatabaseImplement.Implements } catch { - transaction.Rollback(); + throw; } } diff --git a/LawFirm/LawFirmDatabaseImplement/Implements/VisitStorage.cs b/LawFirm/LawFirmDatabaseImplement/Implements/VisitStorage.cs index 6c81105..c61e3a8 100644 --- a/LawFirm/LawFirmDatabaseImplement/Implements/VisitStorage.cs +++ b/LawFirm/LawFirmDatabaseImplement/Implements/VisitStorage.cs @@ -31,7 +31,16 @@ namespace LawFirmDatabaseImplement.Implements { return new(); } - if (model.CompanyId.HasValue) + if (model.CompanyId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue) + { + using var context = new LawFirmDatabase(); + return context.Visits + .Include(x => x.Clients).ThenInclude(x => x.Client) + .Where(x => x.CompanyId == model.CompanyId && x.VisitDate >= model.DateFrom && x.VisitDate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.CompanyId.HasValue) { using var context = new LawFirmDatabase(); return context.Visits diff --git a/LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs b/LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs index 57b0036..e7794a4 100644 --- a/LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs +++ b/LawFirm/LawFirmDatabaseImplement/LawFirmDatabase.cs @@ -17,11 +17,11 @@ namespace LawFirmDatabaseImplement if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-ON2V3BB\SQLEXPRESS;Initial Catalog=LawFirmDatabase; - Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + // optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-ON2V3BB\SQLEXPRESS;Initial Catalog=LawFirmDatabase; + //Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); - /* optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-7A1PHA0\SQLEXPRESS;Initial Catalog=LawFirmDatabase; - Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");*/ + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-7A1PHA0\SQLEXPRESS;Initial Catalog=LawFirmDatabase; + Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/LawFirm/LawFirmDatabaseImplement/Models/Hearing.cs b/LawFirm/LawFirmDatabaseImplement/Models/Hearing.cs index b42246e..9df264e 100644 --- a/LawFirm/LawFirmDatabaseImplement/Models/Hearing.cs +++ b/LawFirm/LawFirmDatabaseImplement/Models/Hearing.cs @@ -32,9 +32,11 @@ namespace LawFirmDatabaseImplement.Models { if (_hearingLawyers == null) { - _hearingLawyers = Lawyers - .ToDictionary(recPC => recPC.LawyerId, recPC => recPC.Lawyer as ILawyerModel); - } + using var context = new LawFirmDatabase(); + _hearingLawyers = Lawyers + .ToDictionary(x => x.LawyerId, x => (context.Lawyers + .FirstOrDefault(y => y.Id == x.LawyerId) as ILawyerModel)); + } return _hearingLawyers; } } @@ -109,7 +111,7 @@ namespace LawFirmDatabaseImplement.Models } context.SaveChanges(); } - _hearingLawyers = null; + _hear = null; } } diff --git a/LawFirm/LawFirmManagerApp/Controllers/ConsultationController.cs b/LawFirm/LawFirmManagerApp/Controllers/ConsultationController.cs index ebd707e..c779084 100644 --- a/LawFirm/LawFirmManagerApp/Controllers/ConsultationController.cs +++ b/LawFirm/LawFirmManagerApp/Controllers/ConsultationController.cs @@ -4,7 +4,7 @@ using LawFirmContracts.ViewModels; using LawFirmManagerApp; using Microsoft.AspNetCore.Mvc; -namespace LawFirmClientApp.Controllers +namespace LawFirmManagerApp.Controllers { public class ConsultationController : Controller { diff --git a/LawFirm/LawFirmManagerApp/Controllers/HearingController.cs b/LawFirm/LawFirmManagerApp/Controllers/HearingController.cs index 392046a..db4e583 100644 --- a/LawFirm/LawFirmManagerApp/Controllers/HearingController.cs +++ b/LawFirm/LawFirmManagerApp/Controllers/HearingController.cs @@ -4,7 +4,7 @@ using LawFirmContracts.ViewModels; using LawFirmManagerApp; using Microsoft.AspNetCore.Mvc; -namespace LawFirmClientApp.Controllers +namespace LawFirmManagerApp.Controllers { public class HearingController : Controller { diff --git a/LawFirm/LawFirmManagerApp/Controllers/HomeController.cs b/LawFirm/LawFirmManagerApp/Controllers/HomeController.cs index fa3ec50..5f5002f 100644 --- a/LawFirm/LawFirmManagerApp/Controllers/HomeController.cs +++ b/LawFirm/LawFirmManagerApp/Controllers/HomeController.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc; using System.Diagnostics; using LawFirmContracts.SearchModels; -namespace LawFirmClientApp.Controllers +namespace LawFirmManagerApp.Controllers { public class HomeController : Controller { diff --git a/LawFirm/LawFirmManagerApp/Controllers/LawyerController.cs b/LawFirm/LawFirmManagerApp/Controllers/LawyerController.cs index c51458e..f23c66e 100644 --- a/LawFirm/LawFirmManagerApp/Controllers/LawyerController.cs +++ b/LawFirm/LawFirmManagerApp/Controllers/LawyerController.cs @@ -3,7 +3,7 @@ using LawFirmContracts.SearchModels; using LawFirmManagerApp; using Microsoft.AspNetCore.Mvc; -namespace LawFirmClientApp.Controllers +namespace LawFirmManagerApp.Controllers { public class LawyerController : Controller { diff --git a/LawFirm/LawFirmManagerApp/Controllers/ReportController.cs b/LawFirm/LawFirmManagerApp/Controllers/ReportController.cs index ac4a2f7..1d8e23e 100644 --- a/LawFirm/LawFirmManagerApp/Controllers/ReportController.cs +++ b/LawFirm/LawFirmManagerApp/Controllers/ReportController.cs @@ -1,40 +1,47 @@ using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; using LawFirmContracts.ViewModels; using LawFirmManagerApp; using Microsoft.AspNetCore.Mvc; -namespace LawFirmClientApp.Controllers +namespace LawFirmManagerApp.Controllers { public class ReportController : Controller { - - /*[HttpGet] - public void CreateReportClients(DateTime dateFrom, DateTime dateTo) + [HttpPost] + public void LoadReportConsultHear(DateTime dateFrom, DateTime dateTo) { if (APIClient.User == null) { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + Redirect("~/Home/Enter"); } - APIClient.GetRequest>($"api/report/getclientsreport", new ReportBindingModel + APIClient.PostRequest($"api/report/saveconsultationhearingtopdffile", new ReportBindingModel { DateFrom = dateFrom, - DateTo = dateTo - - - - Response.Redirect("CreateReportClients"); - }*/ + DateTo = dateTo, + CompanyId = APIClient.User.CompanyId + }); + } [HttpGet] - - public IActionResult CreateReportClients(DateTime dateFrom, DateTime dateTo) + public IActionResult LoadReportConsultHear(DateTime dateFrom, DateTime dateTo, string a) { if (APIClient.User == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/report/getclientsreport?datefrom={dateFrom}&dateTo={dateTo}&companyId={APIClient.User.CompanyId}")); + return View(APIClient.GetRequest>($"api/report/getconsultationhearing?datefrom={dateFrom}&dateTo={dateTo}&companyId={APIClient.User.CompanyId}")); + } + [HttpGet] + public IActionResult CreateReportConsultHear(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.User == null) + { + return Redirect("~/Home/EnterManager"); + } + + return View(APIClient.GetRequest>($"api/report/getconsultationhearing?datefrom={dateFrom}&dateTo={dateTo}&companyId={APIClient.User.CompanyId}")); } diff --git a/LawFirm/LawFirmManagerApp/Program.cs b/LawFirm/LawFirmManagerApp/Program.cs index d17fde9..b6cbd47 100644 --- a/LawFirm/LawFirmManagerApp/Program.cs +++ b/LawFirm/LawFirmManagerApp/Program.cs @@ -3,9 +3,6 @@ using LawFirmDatabaseImplement.Implements; using LawFirmManagerApp; var builder = WebApplication.CreateBuilder(args); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); // Add services to the container. diff --git a/LawFirm/LawFirmManagerApp/Views/Report/CreateReportConsultHear.cshtml b/LawFirm/LawFirmManagerApp/Views/Report/CreateReportConsultHear.cshtml new file mode 100644 index 0000000..a0d7a45 --- /dev/null +++ b/LawFirm/LawFirmManagerApp/Views/Report/CreateReportConsultHear.cshtml @@ -0,0 +1,175 @@ +@using LawFirmContracts.ViewModels; + +@model List +@{ + ViewData["Title"] = "Отчёт"; + Layout = "~/Views/Shared/_LayoutManager.cshtml"; +} + + + +
+

Отчёт по слушаниям и консультациям

+
+
+ @{ +
+ + + + +
+
От
+ + + +
+
+
До
+ + + +
+ +
+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + @foreach (var cons in item.Consultation) + { + + + + + + } + + + + + + } + +
+ Юрист + + Номер консультации + + Цена консультации +
@item.LawyerName
+ @cons.Id + + @cons.Price +
Итого: @item.Consultation.Count
+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + @foreach (var hear in item.Hearing) + { + + + + + + } + + + + + + } + +
+ Юрист + + Суд + + Дата Слушания +
@item.LawyerName
+ @Html.DisplayFor(modelItem => hear.Court) + + @Html.DisplayFor(modelItem => hear.HearingDate) +
Итого: @item.Hearing.Count
+ } +
+ + \ No newline at end of file diff --git a/LawFirm/LawFirmManagerApp/Views/Shared/_LayoutManager.cshtml b/LawFirm/LawFirmManagerApp/Views/Shared/_LayoutManager.cshtml index defdd1e..ff9ef04 100644 --- a/LawFirm/LawFirmManagerApp/Views/Shared/_LayoutManager.cshtml +++ b/LawFirm/LawFirmManagerApp/Views/Shared/_LayoutManager.cshtml @@ -31,7 +31,9 @@ - + diff --git a/LawFirm/LawFirmRestApi/Controllers/ReportController.cs b/LawFirm/LawFirmRestApi/Controllers/ReportController.cs index 42a931f..06d3831 100644 --- a/LawFirm/LawFirmRestApi/Controllers/ReportController.cs +++ b/LawFirm/LawFirmRestApi/Controllers/ReportController.cs @@ -41,6 +41,27 @@ namespace LawFirmRestApi.Controllers throw; } } + [HttpPost] + public void SaveConsultationHearingToPdfFile(ReportBindingModel report) + { + try + { + _reportLogic.SaveConsultationHearingToPdfFile(new ReportBindingModel + { + DateFrom = report.DateFrom, + DateTo = report.DateTo, + FileName = "C:\\Users\\xarla\\OneDrive\\Документы\\Отчёты_по_юрфирме\\pdfreport.pdf", + LawyerId = report.LawyerId, + CompanyId = report.CompanyId, + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpGet] public List GetClientsReport(DateTime dateFrom, DateTime dateTo, int companyId) { @@ -54,6 +75,19 @@ namespace LawFirmRestApi.Controllers throw; } } + [HttpGet] + public List GetConsultationHearing(DateTime dateFrom, DateTime dateTo, int companyId) + { + try + { + return _reportLogic.GetConsultationHearing(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo, CompanyId = companyId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } } }