From acaa63c004863230644cb7c5cf6a514db2e514f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=BD=D0=B0=20=D0=97=D0=B0=D0=B1=D1=80=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D0=BD=D0=B0?= Date: Fri, 3 May 2024 23:07:11 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D1=87=D1=91=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogicHeadwaiter.cs | 14 ++- .../AbstractSaveToPdfHeadwaiter.cs | 4 +- .../ViewModels/ReportLunchesViewModel.cs | 7 +- .../Controllers/HomeController.cs | 102 +++++++++++++++++- Hotel/HotelHeadwaiterApp/Program.cs | 1 + .../Views/Home/ListLunchesToPdfFile.cshtml | 60 +++++++++++ 6 files changed, 175 insertions(+), 13 deletions(-) create mode 100644 Hotel/HotelHeadwaiterApp/Views/Home/ListLunchesToPdfFile.cshtml diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs index a70257a..bafdc18 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs @@ -5,6 +5,7 @@ using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.StoragesContracts; using HotelContracts.ViewModels; +using HotelDataBaseImplement.Models; namespace HotelBusinessLogic.BusinessLogics { @@ -14,16 +15,18 @@ namespace HotelBusinessLogic.BusinessLogics private readonly ILunchStorage _lunchStorage; private readonly IMealPlanStorage _mealPlanStorage; private readonly IConferenceBookingStorage _conferenceBookingStorage; + private readonly IConferenceStorage _conferenceStorage; private readonly AbstractSaveToExcelHeadwaiter _saveToExcel; private readonly AbstractSaveToWordHeadwaitre _saveToWord; private readonly AbstractSaveToPdfHeadwaiter _saveToPdf; - public ReportLogicHeadwaiter(IRoomStorage roomStorage, ILunchStorage lunchStorage, IMealPlanStorage mealPlanStorage, IConferenceBookingStorage conferenceBookingStorage, AbstractSaveToExcelHeadwaiter saveToExcel, AbstractSaveToWordHeadwaitre saveToWord, AbstractSaveToPdfHeadwaiter saveToPdf) + public ReportLogicHeadwaiter(IRoomStorage roomStorage, ILunchStorage lunchStorage, IMealPlanStorage mealPlanStorage, IConferenceBookingStorage conferenceBookingStorage, IConferenceStorage conferenceStorage, AbstractSaveToExcelHeadwaiter saveToExcel, AbstractSaveToWordHeadwaitre saveToWord, AbstractSaveToPdfHeadwaiter saveToPdf) { _roomStorage = roomStorage; _lunchStorage = lunchStorage; _mealPlanStorage = mealPlanStorage; _conferenceBookingStorage = conferenceBookingStorage; + _conferenceStorage = conferenceStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; @@ -106,17 +109,20 @@ namespace HotelBusinessLogic.BusinessLogics DateTo = model.DateTo }); + var conferenced = _conferenceStorage.GetFullList(); + foreach (var conferenceBooking in listConferenceBookings) { foreach (var mp in conferenceBooking.ConferenceBookingLunches.Values) { + var conferenceId = conferenceBooking.ConferenceId; + var conference = conferenced.FirstOrDefault(dp => dp.Id == conferenceId); listAll.Add(new ReportLunchesViewModel { LunchName = mp.LunchName, LunchPrice = mp.LunchPrice, - NameHall = conferenceBooking.NameHall, - BookingDate = conferenceBooking.BookingDate - + ConferenceName = conference.ConferenceName, + StartDate = conference.StartDate }); } } diff --git a/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToPdfHeadwaiter.cs b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToPdfHeadwaiter.cs index 07b8ba0..8858de6 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToPdfHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToPdfHeadwaiter.cs @@ -23,7 +23,7 @@ namespace HotelBusinessLogic.OfficePackage CreateTable(new List { "3cm", "3cm", "3cm", "4cm", "4cm" }); CreateRow(new PdfRowParameters { - Texts = new List { "Обед", "Комната", "Цена комнаты", "Бронирование", "Дата брони" }, + Texts = new List { "Обед", "Комната", "Цена комнаты", "Конференцияя", "Дата" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); @@ -37,7 +37,7 @@ namespace HotelBusinessLogic.OfficePackage } CreateRow(new PdfRowParameters { - Texts = new List { lunch.LunchName.ToString(), lunch.RoomName, IsCost is true ? lunch.RoomPrice.ToString() : string.Empty, lunch.NameHall, lunch.BookingDate?.ToShortDateString() ?? string.Empty }, + Texts = new List { lunch.LunchName.ToString(), lunch.RoomName, IsCost is true ? lunch.RoomPrice.ToString() : string.Empty, lunch.ConferenceName, lunch.StartDate?.ToShortDateString() ?? string.Empty }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); diff --git a/Hotel/HotelContracts/ViewModels/ReportLunchesViewModel.cs b/Hotel/HotelContracts/ViewModels/ReportLunchesViewModel.cs index f21d3b9..dc44b74 100644 --- a/Hotel/HotelContracts/ViewModels/ReportLunchesViewModel.cs +++ b/Hotel/HotelContracts/ViewModels/ReportLunchesViewModel.cs @@ -4,11 +4,10 @@ { public int Id { get; set; } public string RoomName { get; set; } = string.Empty; - public string NameHall { get; set; } = string.Empty; - public DateTime? BookingDate { get; set; } + public double RoomPrice { get; set; } + public string ConferenceName { get; set; } = string.Empty; + public DateTime? StartDate { get; set; } public string LunchName { get; set; } = string.Empty; public double LunchPrice { get; set; } - public double RoomPrice { get; set; } - public string RoomFrame { get; set; } = string.Empty; } } diff --git a/Hotel/HotelHeadwaiterApp/Controllers/HomeController.cs b/Hotel/HotelHeadwaiterApp/Controllers/HomeController.cs index a4968f3..795c009 100644 --- a/Hotel/HotelHeadwaiterApp/Controllers/HomeController.cs +++ b/Hotel/HotelHeadwaiterApp/Controllers/HomeController.cs @@ -2,6 +2,7 @@ using DocumentFormat.OpenXml.Office2010.Excel; using HostrelHeadwaiterApp; using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.ViewModels; using HotelDataBaseImplement.Models; @@ -16,10 +17,12 @@ namespace HotelHeadwaiterApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; + private readonly IReportHeadwaiterLogic _report; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IReportHeadwaiterLogic report) { _logger = logger; + _report = report; } public IActionResult Index() @@ -608,11 +611,104 @@ namespace HotelHeadwaiterApp.Controllers [HttpGet] public IActionResult GetExcelFile() { - return new PhysicalFileResult("C:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + return new PhysicalFileResult("C:\\Reports\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); } + public IActionResult GetPdfFile() + { + return new PhysicalFileResult("C:\\ReportsCourseWork\\pdffile.pdf", "application/pdf"); + } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [HttpGet] + public IActionResult ListLunchesToPdfFile() + { + if (APIClient.Headwaiter == null) + { + return Redirect("~/Home/Enter"); + } + return View("ListLunchesToPdfFile"); + } + + [HttpPost] + public void ListLunchesToPdfFile(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/report/CreateHeadwaiterReportToPdfFile", new ReportHeadwaiterBindingModel + { + DateFrom = dateFrom, + DateTo = dateTo, + HeadwaiterId = APIClient.Headwaiter.Id + }); + Response.Redirect("ListLunchesToPdfFile"); + } + + [HttpGet] + public string GetLunchesReport(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + result = _report.GetLunches(new ReportHeadwaiterBindingModel + { + HeadwaiterId = APIClient.Headwaiter.Id, + DateFrom = dateFrom, + DateTo = dateTo + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + double sum = 0; + string table = ""; + table += "

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

"; + table += "
"; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + foreach (var report in result) + { + bool IsCost = true; + if (report.RoomPrice == 0) + { + IsCost = false; + } + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + table += ""; + sum += report.RoomPrice; + } + table += ""; + table += $""; + table += ""; + table += "
ОбедИмя комнатыЦена комнатыКонференцияДата
{report.LunchName}{report.RoomName}{(IsCost ? report.RoomPrice.ToString() : string.Empty)}{report.ConferenceName}{report.StartDate?.ToShortDateString()}
Итого:{sum}
"; + table += "
"; + return table; + } + + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); diff --git a/Hotel/HotelHeadwaiterApp/Program.cs b/Hotel/HotelHeadwaiterApp/Program.cs index 281a58d..c4de88f 100644 --- a/Hotel/HotelHeadwaiterApp/Program.cs +++ b/Hotel/HotelHeadwaiterApp/Program.cs @@ -11,6 +11,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); diff --git a/Hotel/HotelHeadwaiterApp/Views/Home/ListLunchesToPdfFile.cshtml b/Hotel/HotelHeadwaiterApp/Views/Home/ListLunchesToPdfFile.cshtml new file mode 100644 index 0000000..b21764b --- /dev/null +++ b/Hotel/HotelHeadwaiterApp/Views/Home/ListLunchesToPdfFile.cshtml @@ -0,0 +1,60 @@ +@using HotelContracts.ViewModels + +@{ + ViewData["Title"] = "ListLunchesToPdfFile"; +} + +
+
+

Отчет по обедам за период

+
+ +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+
+
+ +
+
+ +
+
+
+ +@section Scripts { + +} \ No newline at end of file