diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs index 0f83ae5..04b9bd2 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -20,16 +20,18 @@ namespace ComputerShopBusinessLogic.BusinessLogics private readonly ISupplyStorage _supplyStorage; private readonly IAssemblyStorage _assemblyStorage; private readonly IEquipmentReceivingStorage _receivingStorage; + private readonly IPurchaseStorage _purchaseStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(IComponentStorage componentStorage, IAssemblyStorage assemblyStorage, IEquipmentReceivingStorage receivingStorage, ISupplyStorage supplyStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + public ReportLogic(IComponentStorage componentStorage, IAssemblyStorage assemblyStorage, IEquipmentReceivingStorage receivingStorage, ISupplyStorage supplyStorage, IPurchaseStorage purchaseStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _componentStorage = componentStorage; _assemblyStorage = assemblyStorage; _receivingStorage = receivingStorage; _supplyStorage = supplyStorage; + _purchaseStorage = purchaseStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; @@ -87,6 +89,32 @@ namespace ComputerShopBusinessLogic.BusinessLogics return result; } + public List GetPurchaseSupply(ReportBindingModel model) + { + var result = new List(); + var purchases = _purchaseStorage.GetFilteredList(new() + { + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + foreach(var purchase in purchases) + { + var supplies = _supplyStorage.GetFilteredList(new() + { + ComponentId = purchase.ComponentId + }); + foreach( var supply in supplies) + { + result.Add(new() + { + Purchase = purchase, + Supply = supply + }); + } + } + return result; + } + public void SaveReceivingComponentsToWordFile(ReportBindingModel model) { if (model.Ids != null) @@ -120,7 +148,14 @@ namespace ComputerShopBusinessLogic.BusinessLogics { throw new ArgumentException("Дата окончания не задана"); } - + _saveToPdf.CreateDoc(new PdfInfoProvider + { + FileName = model.FileName, + Title = "Связанные закупки и поставки", + SupplyPurchases = GetPurchaseSupply(model), + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); } public List GetPurchaseReceiving() @@ -128,11 +163,6 @@ namespace ComputerShopBusinessLogic.BusinessLogics throw new NotImplementedException(); } - public List GetPurchaseSupply() - { - throw new NotImplementedException(); - } - public void SaveOrdersToPdfFile(ReportBindingModel model) { throw new NotImplementedException(); diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 2d7eb0d..64df9e8 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -21,7 +21,7 @@ namespace ComputerShopBusinessLogic.OfficePackage }); CreateParagraph(new PdfParagraph { - Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Text = $"с {info.DateFrom.ToString()} по {info.DateTo.ToString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/PdfInfoProvider.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/PdfInfoProvider.cs index 3d7cd56..7206049 100644 --- a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/PdfInfoProvider.cs +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/PdfInfoProvider.cs @@ -11,8 +11,8 @@ namespace ComputerShopBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = "F:\\ReportsCourseWork\\pdffile.pdf"; public string Title { get; set; } = string.Empty; - public DateTime DateFrom { get; set; } - public DateTime DateTo { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } public List SupplyPurchases { get; set; } = new(); } } diff --git a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs index 14e22da..14ad97f 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs +++ b/ComputerShopProvider/ComputerShopClientApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using ComputerShopClientApp.Models; using ComputerShopContracts.BindingModels; +using ComputerShopContracts.BusinessLogicContracts; using ComputerShopContracts.SearchModels; using ComputerShopContracts.ViewModels; using Microsoft.AspNetCore.Components; @@ -13,10 +14,12 @@ namespace ComputerShopClientApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; + private readonly IReportLogic _report; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IReportLogic report) { _logger = logger; + _report = report; } public IActionResult Index() @@ -149,6 +152,98 @@ namespace ComputerShopClientApp.Controllers } } + [HttpGet] + public IActionResult ReportPdf() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View("ReportPdf"); + } + [HttpGet] + public string GetPurchasesReport(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + result = _report.GetPurchaseSupply(new ReportBindingModel + { + 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 += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + table += ""; + foreach (var report in result) + { + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + table += ""; + } + table += "
ID закупкиНазвание компонентаДата создание закупкиДата создания поставкиСтатус поставки
{report.Purchase.Id.ToString()}{report.Purchase.ComponentName}{report.Purchase.DateCreate.ToShortDateString()}{report.Supply.DateCreate.ToShortDateString()}{report.Supply.Status.ToString()}
"; + return table; + } + + [HttpPost] + public void ReportPdf(DateTime dateFrom, DateTime dateTo, string clientEmail) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + //if (string.IsNullOrEmpty(clientEmail)) + //{ + // throw new Exception("Email пуст"); + //} + APIClient.PostRequest("api/report/CreatePdfReport", new ReportBindingModel + { + DateFrom = dateFrom, + DateTo = dateTo, + }); + //APIClient.PostRequest("api/report/SendPdfToMail", new MailSendInfoBindingModel + //{ + // MailAddress = organiserEmail, + // Subject = "Отчет по участникам (pdf)", + // Text = "Отчет по участникам с " + dateFrom.ToShortDateString() + " до " + dateTo.ToShortDateString() + //}); + Response.Redirect("GetPdfFile"); + } + [HttpGet] public IActionResult Enter() { diff --git a/ComputerShopProvider/ComputerShopClientApp/Program.cs b/ComputerShopProvider/ComputerShopClientApp/Program.cs index f702b1c..c870214 100644 --- a/ComputerShopProvider/ComputerShopClientApp/Program.cs +++ b/ComputerShopProvider/ComputerShopClientApp/Program.cs @@ -1,6 +1,21 @@ +using ComputerShopBusinessLogic.BusinessLogics; +using ComputerShopBusinessLogic.OfficePackage; +using ComputerShopBusinessLogic.OfficePackage.Implements; using ComputerShopClientApp; +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.StorageContracts; +using ComputerShopDatabaseImplement.Implements; var builder = WebApplication.CreateBuilder(args); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); // Add services to the container. builder.Services.AddControllersWithViews(); diff --git a/ComputerShopProvider/ComputerShopClientApp/Views/Home/ReportPdf.cshtml b/ComputerShopProvider/ComputerShopClientApp/Views/Home/ReportPdf.cshtml new file mode 100644 index 0000000..58e7bdc --- /dev/null +++ b/ComputerShopProvider/ComputerShopClientApp/Views/Home/ReportPdf.cshtml @@ -0,0 +1,73 @@ +@using ComputerShopContracts.ViewModels + +@{ + ViewData["Title"] = "ReportPdf"; +} + +
+

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

+
+ +
+ @{ +
+ + +
+ + +
+
+
+
+
+
+
+
+
+
+
+
+ } +
+ +@section Scripts { + +} \ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IReportLogic.cs b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IReportLogic.cs index b7b3eb6..0b3b537 100644 --- a/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IReportLogic.cs +++ b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IReportLogic.cs @@ -13,7 +13,7 @@ namespace ComputerShopContracts.BusinessLogicContracts /// Получение списка компонент с указанием, в каких изделиях используются List GetPurchaseReceiving(); - List GetPurchaseSupply(); + List GetPurchaseSupply(ReportBindingModel model); public List GetComponentReceivings(List ids); @@ -24,5 +24,6 @@ namespace ComputerShopContracts.BusinessLogicContracts void SaveOrdersToPdfFile(ReportBindingModel model); void SaveReceivingComponentsToWordFile(ReportBindingModel model); void SaveReceivingComponentsToXmlFile(ReportBindingModel model); + void SavePurchaseSuppliesToPdfFile(ReportBindingModel model); } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/PurchaseStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/PurchaseStorage.cs index 72c9e3f..b15d669 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/PurchaseStorage.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/PurchaseStorage.cs @@ -30,11 +30,17 @@ namespace ComputerShopDatabaseImplement.Implements public List GetFilteredList(PurchaseSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) { return new(); } using var context = new ComputerShopDatabase(); + if (model.DateFrom.HasValue && model.DateTo.HasValue) + return context.Purchases + .Include(x => x.Component) + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); if (model.ClientId.HasValue) { return context.Purchases diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/ReportController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/ReportController.cs index 51859f2..e8fa6a2 100644 --- a/ComputerShopProvider/ComputerShopRestApi/Controllers/ReportController.cs +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/ReportController.cs @@ -43,4 +43,22 @@ public class ReportController : Controller throw; } } + [HttpPost] + public void CreatePdfReport(ReportBindingModel model) + { + try + { + _reportLogic.SavePurchaseSuppliesToPdfFile(new ReportBindingModel + { + DateFrom = model.DateFrom, + DateTo = model.DateTo, + FileName = "F:\\ReportsCourseWork\\pdffile.pdf", + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } } \ No newline at end of file