From 382d456610281561d8ebfdf0afd126935c182ca2 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Fri, 19 May 2023 22:30:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D1=87=D1=91=D1=82=20=D0=B2=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B5=20pdf=20(=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=B2=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=B0=D0=BD=D1=82=20=D1=81=20=D1=84=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=BE=D0=BC)=20=D0=B4=D0=BB=D1=8F=20"=D0=97=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D1=87=D0=B8=D0=BA=D0=B0"=20+=20=D1=83=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B7=D0=B0=D1=87=D0=B8=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 25 ++++++++---- .../OfficePackage/AbstractSaveToPdf.cs | 38 +++++++++++------- .../OfficePackage/Implements/SaveToPdf.cs | 11 +++++- .../BusinessLogicsContracts/IReportLogic.cs | 2 +- ...ReportTransferCurrencyPurchaseViewModel.cs | 2 +- .../OperatorApp/Controllers/HomeController.cs | 39 ++++++++++++++----- Bank/OperatorApp/Views/Home/Transfers.cshtml | 5 +++ .../Views/Home/TransfersReport.cshtml | 25 ++++++++++++ Bank/OperatorApp/Views/Shared/_Layout.cshtml | 7 +++- 9 files changed, 118 insertions(+), 36 deletions(-) create mode 100644 Bank/OperatorApp/Views/Home/TransfersReport.cshtml diff --git a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs index e9df4f3..493d72c 100644 --- a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs @@ -22,8 +22,9 @@ namespace BankBusinessLogic.BusinessLogics private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToExcel _saveToExcel; + private readonly AbstractSaveToPdf _saveToPdf; - public ReportLogic(ITransferStorage transferStorage, IPaymentStorage paymentStorage, ICurrencyStorage currencyStorage, ICurrencyPurchaseStorage currencyPurchaseStorage, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel) + public ReportLogic(ITransferStorage transferStorage, IPaymentStorage paymentStorage, ICurrencyStorage currencyStorage, ICurrencyPurchaseStorage currencyPurchaseStorage, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel, AbstractSaveToPdf saveToPdf) { _transferStorage = transferStorage; _paymentStorage = paymentStorage; @@ -31,6 +32,7 @@ namespace BankBusinessLogic.BusinessLogics _currencyPurchaseStorage = currencyPurchaseStorage; _saveToWord = saveToWord; _saveToExcel = saveToExcel; + _saveToPdf = saveToPdf; } public List GetPaymentPurchase(List payments) @@ -84,9 +86,9 @@ namespace BankBusinessLogic.BusinessLogics { TransferId = transfer.Id, TransferDate = transfer.TransferDateTime, - Purchases = new List<(int, float)>() + Purchases = new List() }; - var payment = _paymentStorage.GetElement(new PaymentSearchModel { Id = transfer.Id}); + var payment = _paymentStorage.GetElement(new PaymentSearchModel { Id = transfer.PaymentId}); if (payment == null) { throw new InvalidOperationException("Платеж не был найден!"); @@ -104,7 +106,7 @@ namespace BankBusinessLogic.BusinessLogics { if (currencyPurchase.CurrencyId == currencyId) { - record.Purchases.Add(new(currencyPurchase.Id, currencyPurchase.Amount)); + record.Purchases.Add(currencyPurchase); break; } } @@ -192,11 +194,20 @@ namespace BankBusinessLogic.BusinessLogics }); } - public void SaveTransferPurchaseToPDF(ReportBindingModel model) + public MemoryStream SaveTransferPurchaseToPDF(ReportBindingModel model) { + if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + { + throw new InvalidOperationException("Отсутствуют даты для отчёта!"); + } var result = GetTransferPurchase(model); - //создание файла будет реализовано в будующих версиях - throw new NotImplementedException(); + return _saveToPdf.CreateOperatorDoc(new PdfInfo + { + Title = "Отчёт о зачислениях", + DateFrom = model.DateFrom.Value, + DateTo = model.DateTo.Value, + Transfers = result + }); } public void SaveCurrencyTransfersToExcel(List currencies) diff --git a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 1deb529..2039bb3 100644 --- a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -10,33 +10,41 @@ namespace ConfectioneryBusinessLogic.OfficePackage { public abstract class AbstractSaveToPdf { - public void CreateOperatorDoc(PdfInfo info) + public MemoryStream CreateOperatorDoc(PdfInfo info) { CreatePdf(info); CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "3cm" }); + CreateTable(new List { "4cm", "3cm", "3cm", "2cm", "3cm", "3cm" }); CreateRow(new PdfRowParameters { - Texts = new List { "Номер", "Дата заказа", "Изделие", "Статус", "Сумма" }, + Texts = new List { "Номер зачисления", "Дата зачисления", "Номер закупки", "Сумма", "Валюта", "Дата закупки" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - //foreach (var order in info.Orders) - //{ - // CreateRow(new PdfRowParameters - // { - // Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.PastryName, order.Status, order.Sum.ToString() }, - // Style = "Normal", - // ParagraphAlignment = PdfParagraphAlignmentType.Left - // }); - //} - //CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); + foreach (var transfer in info.Transfers) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "Зачисление №" + transfer.TransferId, transfer.TransferDate.ToShortDateString(), "", "", "", "" }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + foreach(var purchase in transfer.Purchases) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "", "", "Закупка №" + purchase.Id, purchase.Amount.ToString(), purchase.CurrencyName.ToString(), purchase.PurchaseDate.ToShortDateString()}, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + } - //SavePdf(info); + return SavePdf(); } /// @@ -69,6 +77,6 @@ namespace ConfectioneryBusinessLogic.OfficePackage /// Сохранение файла /// /// - protected abstract void SavePdf(PdfInfo info); + protected abstract MemoryStream SavePdf(); } } diff --git a/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToPdf.cs index 9e0f3ab..ebef09f 100644 --- a/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/Bank/BankBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -106,14 +106,21 @@ namespace ConfectioneryBusinessLogic.OfficePackage.Implements } } - protected override void SavePdf(PdfInfo info) + protected override MemoryStream SavePdf() { var renderer = new PdfDocumentRenderer(true) { Document = _document }; renderer.RenderDocument(); - renderer.PdfDocument.Save(info.FileName); + + MemoryStream stream = new MemoryStream(); + + renderer.PdfDocument.Save(stream, false); + + stream.Seek(0, SeekOrigin.Begin); + + return stream; } } } diff --git a/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs b/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs index e450b9c..ccda09c 100644 --- a/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs @@ -14,7 +14,7 @@ namespace BankContracts.BusinessLogicsContracts List GetTransferPurchase(ReportBindingModel model); MemoryStream SavePaymentPurchaseToWord(ReportBindingModel model, List payments); MemoryStream SavePaymentPurchaseToExcel(ReportBindingModel model, List payments); - void SaveTransferPurchaseToPDF(ReportBindingModel model); + MemoryStream SaveTransferPurchaseToPDF(ReportBindingModel model); List GetCurrencyTransfers(List currencies); List GetPurchasePayment(ReportBindingModel model); diff --git a/Bank/BankContracts/ViewModels/ReportTransferCurrencyPurchaseViewModel.cs b/Bank/BankContracts/ViewModels/ReportTransferCurrencyPurchaseViewModel.cs index e65bab4..629d096 100644 --- a/Bank/BankContracts/ViewModels/ReportTransferCurrencyPurchaseViewModel.cs +++ b/Bank/BankContracts/ViewModels/ReportTransferCurrencyPurchaseViewModel.cs @@ -10,6 +10,6 @@ namespace BankContracts.ViewModels { public int TransferId { get; set; } public DateTime TransferDate { get; set; } - public List<(int PurchaseId, float Amount)> Purchases { get; set; } = new(); + public List Purchases { get; set; } = new(); } } diff --git a/Bank/OperatorApp/Controllers/HomeController.cs b/Bank/OperatorApp/Controllers/HomeController.cs index d7a618c..4657410 100644 --- a/Bank/OperatorApp/Controllers/HomeController.cs +++ b/Bank/OperatorApp/Controllers/HomeController.cs @@ -36,7 +36,7 @@ namespace OperatorApp.Controllers { return Redirect("~/Home/Enter"); } - return View(_dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id})); + return View(_dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id })); } [HttpGet] @@ -97,7 +97,7 @@ namespace OperatorApp.Controllers { throw new Exception("Введите логин и пароль"); } - APIClient.Operator = _operatorLogic.ReadElement(new OperatorSearchModel { Login = login, Password = password}); + APIClient.Operator = _operatorLogic.ReadElement(new OperatorSearchModel { Login = login, Password = password }); if (APIClient.Operator == null) { throw new Exception("Неверный логин/пароль"); @@ -155,12 +155,12 @@ namespace OperatorApp.Controllers { return Redirect("~/Home/Enter"); } - return View(_paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id})); + return View(_paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id })); } [HttpGet] public IActionResult CreatePayment() { - ViewBag.Deals = _dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id}); + ViewBag.Deals = _dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id }); return View(); } [HttpPost] @@ -173,7 +173,7 @@ namespace OperatorApp.Controllers Dictionary DealPayments = new(); foreach (int id in deals) { - var deal = _dealLogic.ReadElement(new DealSearchModel { Id = id}); + var deal = _dealLogic.ReadElement(new DealSearchModel { Id = id }); if (deal != null) DealPayments.Add(deal.Id, deal); } _paymentLogic.Create(new PaymentBindingModel { OperatorId = APIClient.Operator.Id, DealPayments = DealPayments, }); @@ -182,7 +182,7 @@ namespace OperatorApp.Controllers [HttpGet] public IActionResult Payment(int id) { - return View(_paymentLogic.ReadElement(new PaymentSearchModel { Id = id})); + return View(_paymentLogic.ReadElement(new PaymentSearchModel { Id = id })); } [HttpGet] public IActionResult Transfers() @@ -211,9 +211,18 @@ namespace OperatorApp.Controllers throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - _transferLogic.Create(new TransferBindingModel { OperatorId = APIClient.Operator.Id, Amount = (float)Convert.ToDouble(amount), PaymentId = payment}); + _transferLogic.Create(new TransferBindingModel { OperatorId = APIClient.Operator.Id, Amount = (float)Convert.ToDouble(amount), PaymentId = payment }); Response.Redirect("Transfers"); } + public void DeleteTransfer(int id) + { + if (APIClient.Operator == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + _transferLogic.Delete(new TransferBindingModel { Id = id }); + Response.Redirect("/Home/Transfers"); + } [HttpGet] public IActionResult PaymentsReport() @@ -244,8 +253,8 @@ namespace OperatorApp.Controllers } //if (word) //{ - MemoryStream list = _reportLogic.SavePaymentPurchaseToWord(new ReportBindingModel { FileName = "test" }, paymentBindings); - return File(list, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "testDoc.docx"); + MemoryStream list = _reportLogic.SavePaymentPurchaseToWord(new ReportBindingModel { FileName = "test" }, paymentBindings); + return File(list, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "testDoc.docx"); //} //else //{ @@ -253,5 +262,17 @@ namespace OperatorApp.Controllers // return File(list, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "testExcel.xlsx"); //} } + + [HttpGet] + public IActionResult TransfersReport() + { + return View(new ReportBindingModel()); + } + [HttpPost] + public IActionResult TransfersReport(DateTime dateFrom, DateTime dateTo) + { + MemoryStream report = _reportLogic.SaveTransferPurchaseToPDF(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo }); + return File(report, "application/pdf", "test.pdf"); + } } } \ No newline at end of file diff --git a/Bank/OperatorApp/Views/Home/Transfers.cshtml b/Bank/OperatorApp/Views/Home/Transfers.cshtml index 71a73fe..e7cd555 100644 --- a/Bank/OperatorApp/Views/Home/Transfers.cshtml +++ b/Bank/OperatorApp/Views/Home/Transfers.cshtml @@ -37,6 +37,8 @@ Номер выплаты + + @@ -55,6 +57,9 @@ @Html.DisplayFor(modelItem => item.PaymentId) + + Удалить + } diff --git a/Bank/OperatorApp/Views/Home/TransfersReport.cshtml b/Bank/OperatorApp/Views/Home/TransfersReport.cshtml new file mode 100644 index 0000000..806205b --- /dev/null +++ b/Bank/OperatorApp/Views/Home/TransfersReport.cshtml @@ -0,0 +1,25 @@ +@using BankContracts.BindingModels +@model ReportBindingModel + +@{ + ViewData["Title"] = "TransfersReport"; +} +
+

Создание отчёта

+
+
+
+
C:
+
+ @Html.EditorFor(x => x.DateFrom, new { htmlAttributes = new { @class = "form-control my-3", @type = "date", @name="DateFrom", @required="true", @id="DateFrom" } }) +
+
По:
+
+ @Html.EditorFor(x => x.DateTo, new { htmlAttributes = new { @class = "form-control my-3", @type = "date", @name="DateTo", @required="true", @id="DateTo" } }) +
+
+
+
+
+
+
\ No newline at end of file diff --git a/Bank/OperatorApp/Views/Shared/_Layout.cshtml b/Bank/OperatorApp/Views/Shared/_Layout.cshtml index 1bc1cc4..887959a 100644 --- a/Bank/OperatorApp/Views/Shared/_Layout.cshtml +++ b/Bank/OperatorApp/Views/Shared/_Layout.cshtml @@ -8,6 +8,8 @@ + +
@@ -39,7 +41,10 @@ Регистрация +