diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/ReportCashierLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/ReportCashierLogic.cs index c083ea1..498ab2d 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/ReportCashierLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/ReportCashierLogic.cs @@ -95,8 +95,11 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics } //Сохранение заказов в файл-Pdf - public void SaveAccountsToPdfFile(ReportBindingModel model) + public ReportCashierViewModelForHTML SaveAccountsToPdfFile(ReportBindingModel model) { + var listMoneyTransfers = GetMoneyTransfers(model); + var listCashWithdrawals = GetCashWithrawals(model); + _saveToPdf.CreateDoc(new PdfInfo { ForClient = false, @@ -105,9 +108,17 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics Title = "Отчёт по операциям начислений и переводов между счетами", DateFrom = model.DateFrom!.Value, DateTo = model.DateTo!.Value, - ReportMoneyTransfer = GetMoneyTransfers(model), - ReportCashWithdrawal = GetCashWithrawals(model) + ReportMoneyTransfer = listMoneyTransfers, + ReportCashWithdrawal = listCashWithdrawals }); + + //возврат полученных списков для отображения на вебе + return new ReportCashierViewModelForHTML + { + ReportCashWithdrawal = listCashWithdrawals, + + ReportMoneyTransfer = listMoneyTransfers + }; } } } diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/ReportClientLogic.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/ReportClientLogic.cs index c2a2eef..bf86b0d 100644 --- a/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/ReportClientLogic.cs +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/BusinessLogics/ReportClientLogic.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using BankYouBankruptContracts.ViewModels.Client.Reports; +using BankYouBankruptContracts.ViewModels; namespace BankYouBankruptBusinessLogic.BusinessLogics { @@ -84,17 +85,28 @@ namespace BankYouBankruptBusinessLogic.BusinessLogics } //отчёт в формате PDF для клиента - public void SaveClientReportToPdfFile(ReportBindingModel model) + public ReportClientViewModelForHTML SaveClientReportToPdfFile(ReportBindingModel model) { + var listCreditings = GetCrediting(model); + var listDebitings = GetDebiting(model); + _saveToPdf.CreateDoc(new PdfInfo { FileName = model.FileName, Title = "Отчёт по операциям с картами", DateFrom = model.DateFrom!.Value, DateTo = model.DateTo!.Value, - ReportCrediting = GetCrediting(model), - ReportDebiting = GetDebiting(model) + ReportCrediting = listCreditings, + ReportDebiting = listDebitings }); + + //возврат полученных списков для отображения на вебе + return new ReportClientViewModelForHTML + { + ReportCrediting = listCreditings, + + ReportDebiting = listDebitings + }; } } } diff --git a/BankYouBankrupt/BankYouBankruptBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/BankYouBankrupt/BankYouBankruptBusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..ba95273 --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,191 @@ +using BankYouBankruptBusinessLogic.OfficePackage.HelperEnums; +using BankYouBankruptBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankYouBankruptBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdf + { + //публичный метод создания документа. Описание методов ниже + public void CreateDoc(PdfInfo info) + { + if(info.ForClient) + { + CreateDocClient(info); + } + else + { + CreateDocCashier(info); + } + } + + #region Отчёт для клиента + + public void CreateDocClient(PdfInfo info) + { + CreatePdf(info); + + CreateParagraph(new PdfParagraph + { + Text = info.Title + $"\nот {DateTime.Now.ToShortDateString()}", + + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + CreateParagraph(new PdfParagraph + { + Text = $"Расчётный период: с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + //параграф с отчётом на пополнения + CreateParagraph(new PdfParagraph { Text = "Отчёт по пополнениям", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "3cm", "3cm", "5cm", "5cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер операции", "Номер карты", "Сумма", "Дата операции" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var report in info.ReportCrediting) + { + CreateRow(new PdfRowParameters + { + Texts = new List { report.OperationId.ToString(), report.CardNumber, report.SumOperation.ToString(), report.DateComplite.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + //подсчёт суммы операций на пополнение + CreateParagraph(new PdfParagraph { Text = $"Итоговая сумма поступлений за период: {info.ReportCrediting.Sum(x => x.SumOperation)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + + //отчёт с отчётом на снятие + CreateParagraph(new PdfParagraph { Text = "Отчёт по снятиям", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "3cm", "3cm", "5cm", "5cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер операции", "Номер карты", "Сумма", "Дата операции" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var report in info.ReportDebiting) + { + CreateRow(new PdfRowParameters + { + Texts = new List { report.OperationId.ToString(), report.CardNumber, report.SumOperation.ToString(), report.DateComplite.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + //подсчёт суммы операций на пополнение + CreateParagraph(new PdfParagraph { Text = $"Итоговая сумма снятий за период: {info.ReportDebiting.Sum(x => x.SumOperation)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + + SavePdf(info); + } + + #endregion + + #region Отчёт для кассира + + //создание отчёта для кассира + public void CreateDocCashier(PdfInfo info) + { + CreatePdf(info); + + CreateParagraph(new PdfParagraph + { + Text = info.Title + $"\nот {DateTime.Now.ToShortDateString()}\nФИО клиента: {info.FullClientName}", + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + CreateParagraph(new PdfParagraph + { + Text = $"Расчётный период: с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + //параграф с отчётом по выдаче наличных с карт + CreateParagraph(new PdfParagraph { Text = "Отчёт по выдаче наличных со счёта", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "3.5cm", "3.5cm", "5cm", "5cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер операции", "Номер счёта", "Сумма операции", "Дата операции" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var report in info.ReportCashWithdrawal) + { + CreateRow(new PdfRowParameters + { + Texts = new List { report.OperationId.ToString(), report.AccountPayeeNumber, report.SumOperation.ToString(), report.DateComplite.ToShortDateString(), }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итоговая сумма снятий за период: {info.ReportCashWithdrawal.Sum(x => x.SumOperation)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + + //параграф с отчётом по переводу денег со счёта на счёт + CreateParagraph(new PdfParagraph { Text = "Отчёт по денежным переводам между счетами", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "3cm", "3cm", "3cm", "4cm", "4cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер операции", "Номер счёта отправителя", "Номер счёта получателя", "Сумма операции", "Дата операции" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var report in info.ReportMoneyTransfer) + { + CreateRow(new PdfRowParameters + { + Texts = new List { report.OperationId.ToString(), report.AccountSenderNumber, report.AccountPayeeNumber, report.SumOperation.ToString(), report.DateComplite.ToShortDateString(), }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итоговая сумма переводов за период: {info.ReportMoneyTransfer.Sum(x => x.SumOperation)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + + SavePdf(info); + } + + #endregion + + /// Создание pdf-файла + protected abstract void CreatePdf(PdfInfo info); + + /// Создание параграфа с текстом + protected abstract void CreateParagraph(PdfParagraph paragraph); + + /// Создание таблицы + protected abstract void CreateTable(List columns); + + /// Создание и заполнение строки + protected abstract void CreateRow(PdfRowParameters rowParameters); + + /// Сохранение файла + protected abstract void SavePdf(PdfInfo info); + } +} diff --git a/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs b/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs index 504fba4..b4035b6 100644 --- a/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs +++ b/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs @@ -275,67 +275,9 @@ namespace BankYouBankruptClientApp.Controllers DateTo = dateTo }); - PdfLoadViewModel support = APIClient.GetRequest($"api/Report/LoadReport?whoRequested={bool.TrueString}"); - - - - /*PdfDocument doc = new PdfDocument(); - - doc.LoadFromBytes(support.bytes); - - support.document = doc;*/ - - - - //return File(support.bytes, "application/pdf", "support.pdf") - - /*/Create PDF Document - PdfDocument document = new PdfDocument(); - - //You will have to add Page in PDF Document - PdfPage page = document.AddPage(); - - //For drawing in PDF Page you will nedd XGraphics Object - XGraphics gfx = XGraphics.FromPdfPage(page); - - //For Test you will have to define font to be used - XFont font = new XFont("Verdana", 20, XFontStyle.Bold); - - //Finally use XGraphics & font object to draw text in PDF Page - gfx.DrawString("My First PDF Document", font, XBrushes.Black, - - new XRect(0, 0, page.Width, page.Height), XStringFormats.Center); - - //Specify file name of the PDF file - string filename = "FirstPDFDocument.pdf"; - - //Save PDF File - document.Save(filename); - - //Load PDF File for viewing - Process.Start(filename);*/ - - - - /*MemoryStream stream = new MemoryStream(support.bytes); - PdfDocument document = PdfReader.Open(stream, PdfDocumentOpenMode.Import); - support.document = document.Save(stream, false);*/ - - //ViewBag.ReportFile = File(support.bytes, "application/pdf"); - - ViewBag.ReportFile = new FileContentResult(support.bytes, "application/pdf"); - - //ViewBag.ReportFile = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location).ToString(); - return View(); } - /*[HttpPost] - public object LoadReport() - { - return null; - }*/ - #endregion #region Получение отчета по картам diff --git a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/CreateReport.cshtml b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/CreateReport.cshtml index 138a83b..cd8ccf4 100644 --- a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/CreateReport.cshtml +++ b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/CreateReport.cshtml @@ -25,25 +25,5 @@
-

Просмотр отчёта в формате pdf

- -

Unable to display PDF file. Download instead.

-
- - - \ No newline at end of file diff --git a/BankYouBankrupt/BankYouBankruptContracts/BusinessLogicsContracts/IReportCashierLogic.cs b/BankYouBankrupt/BankYouBankruptContracts/BusinessLogicsContracts/IReportCashierLogic.cs index b884af5..b0f36fc 100644 --- a/BankYouBankrupt/BankYouBankruptContracts/BusinessLogicsContracts/IReportCashierLogic.cs +++ b/BankYouBankrupt/BankYouBankruptContracts/BusinessLogicsContracts/IReportCashierLogic.cs @@ -20,7 +20,7 @@ namespace BankYouBankruptContracts.BusinessLogicsContracts //Сохранение отчёта по счетам в файл-Excel void SaveAccountsToExcelFile(ReportBindingModel model); - //Сохранение отчёта по счетам в файл-Pdf - void SaveAccountsToPdfFile(ReportBindingModel model); + //Сохранение отчёта по счетам в файл-Pdf + ReportCashierViewModelForHTML SaveAccountsToPdfFile(ReportBindingModel model); } } diff --git a/BankYouBankrupt/BankYouBankruptContracts/BusinessLogicsContracts/IReportClientLogic.cs b/BankYouBankrupt/BankYouBankruptContracts/BusinessLogicsContracts/IReportClientLogic.cs index 3cf9a60..b040377 100644 --- a/BankYouBankrupt/BankYouBankruptContracts/BusinessLogicsContracts/IReportClientLogic.cs +++ b/BankYouBankrupt/BankYouBankruptContracts/BusinessLogicsContracts/IReportClientLogic.cs @@ -1,5 +1,6 @@ using BankYouBankruptContracts.BindingModels; using BankYouBankruptContracts.SearchModels; +using BankYouBankruptContracts.ViewModels; using BankYouBankruptContracts.ViewModels.Client.Reports; using System; using System.Collections.Generic; @@ -25,7 +26,7 @@ namespace BankYouBankruptContracts.BusinessLogicsContracts void SaveDebitingToExcelFile(ReportBindingModel model); - //Сохранение отчёта по картам в файл-Pdf - void SaveClientReportToPdfFile(ReportBindingModel model); + //Сохранение отчёта по картам в файл-Pdf + ReportClientViewModelForHTML SaveClientReportToPdfFile(ReportBindingModel model); } } diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/PdfLoadViewModel.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/PdfLoadViewModel.cs deleted file mode 100644 index 2f8ca6b..0000000 --- a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/PdfLoadViewModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using PdfSharp.Pdf; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BankYouBankruptContracts.ViewModels -{ - //для возврата pdf на страницу - public class PdfLoadViewModel - { - public byte[] bytes { get; set; } - - public PdfDocument document { get; set; } - } -} diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCashierViewModel.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCashierViewModel.cs index 4fd210c..227de7e 100644 --- a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCashierViewModel.cs +++ b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCashierViewModel.cs @@ -8,7 +8,6 @@ namespace BankYouBankruptContracts.ViewModels { public class ReportCashierViewModel { - public int OperationId { get; set; } public int DebitingId { get; set; } diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCashierViewModelForHTML.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCashierViewModelForHTML.cs new file mode 100644 index 0000000..c215ab9 --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCashierViewModelForHTML.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankYouBankruptContracts.ViewModels +{ + public class ReportCashierViewModelForHTML + { + //перечень переводов со счёта на счёт + public List ReportMoneyTransfer { get; set; } = new(); + + //перечень зачислений денежных средств на карту (т. е. на её счёт) + public List ReportCashWithdrawal { get; set; } = new(); + } +} diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientViewModelForHTML.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientViewModelForHTML.cs new file mode 100644 index 0000000..60a4d28 --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientViewModelForHTML.cs @@ -0,0 +1,18 @@ +using BankYouBankruptContracts.ViewModels.Client.Reports; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankYouBankruptContracts.ViewModels +{ + public class ReportClientViewModelForHTML + { + //перечень заказов за указанный период для вывода/сохранения + public List ReportCrediting { get; set; } = new(); + + //перечень заказов за указанный период для вывода/сохранения + public List ReportDebiting { get; set; } = new(); + } +} diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/ReportController.cs b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/ReportController.cs index 51d4361..cde358e 100644 --- a/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/ReportController.cs +++ b/BankYouBankrupt/BankYouBankruptRestAPI/Controllers/ReportController.cs @@ -36,11 +36,11 @@ namespace BankYouBankruptRestAPI.Controllers //метод генерации отчёта за период по картам клиента [HttpPost] - public void CreateClientReport(ReportSupportBindingModel model) + public ReportClientViewModelForHTML CreateClientReport(ReportSupportBindingModel model) { try { - _reportClientLogic.SaveClientReportToPdfFile(new ReportBindingModel + return _reportClientLogic.SaveClientReportToPdfFile(new ReportBindingModel { FileName = "Отчёт_по_картам.pdf", DateFrom = model.DateFrom, @@ -56,11 +56,11 @@ namespace BankYouBankruptRestAPI.Controllers //метод генерации отчёта по всем счетм клиентов [HttpPost] - public void CreateCashierReport(ReportSupportBindingModel model) + public ReportCashierViewModelForHTML CreateCashierReport(ReportSupportBindingModel model) { try { - _reportCashierLogic.SaveAccountsToPdfFile(new ReportBindingModel + return _reportCashierLogic.SaveAccountsToPdfFile(new ReportBindingModel { FileName = "Отчёт_по_счетам.pdf", ClientId = model.ClientId, @@ -74,23 +74,5 @@ namespace BankYouBankruptRestAPI.Controllers throw; } } - - [HttpGet] - public PdfLoadViewModel LoadReport(bool whoRequested) - { - try - { - PdfLoadViewModel model = new PdfLoadViewModel(); - - model.bytes = _reportLoad.LoadFile(whoRequested); - - return model; - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка входа в систему"); - throw; - } - } } } diff --git a/BankYouBankrupt/BankYouBankruptRestAPI/Отчёт_по_картам.pdf b/BankYouBankrupt/BankYouBankruptRestAPI/Отчёт_по_картам.pdf new file mode 100644 index 0000000..2ad1474 Binary files /dev/null and b/BankYouBankrupt/BankYouBankruptRestAPI/Отчёт_по_картам.pdf differ