diff --git a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs index ecc2735..48689ea 100644 --- a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs @@ -161,12 +161,12 @@ namespace BankBusinessLogic.BusinessLogics CurrencyPurchaseId = purchase.Id, PurchaseDate = purchase.PurchaseDate, CurrencyName = purchase.CurrencyName, - Payments = new List<(int PaymentId, string PaymentDate)>(), + Payments = new List<(int PaymentId, DateTime PaymentDate)>(), }; var paymentsId = new List(); foreach (var payment in payments) { - if (payment.CurrencyPayments.ContainsKey(purchase.CurrencyId)) record.Payments.Add(new(payment.Id, payment.PaymentDate.ToString())); + if (payment.CurrencyPayments.ContainsKey(purchase.CurrencyId)) record.Payments.Add(new(payment.Id, payment.PaymentDate)); } list.Add(record); } @@ -211,23 +211,8 @@ namespace BankBusinessLogic.BusinessLogics }); } - public MemoryStream SaveCurrencyTransferToPDF(ReportBindingModel model) - { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) - { - throw new InvalidOperationException("Отсутствуют даты для отчёта!"); - } - var result = GetTransferPurchase(model); - return _saveToPdf.CreateBankOperatorDoc(new PdfInfo - { - Title = "Отчёт по закупкам", - DateFrom = model.DateFrom.Value, - DateTo = model.DateTo.Value, - Transfers = result - }); - } - - public MemoryStream SaveCurrencyTransfersToExcel(ReportBindingModel model, List currencies) + public MemoryStream SaveCurrencyTransfersToExcel(ReportBindingModel model, + List currencies) { var report = GetCurrencyTransfers(currencies); return _saveToExcel.CreateBankOperatorReport(new ExcelInfo @@ -250,8 +235,19 @@ namespace BankBusinessLogic.BusinessLogics } public MemoryStream SavePurchasePaymentToPDF(ReportBindingModel model) { + if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + { + throw new InvalidOperationException("Отсутствуют даты для отчёта!"); + } var report = GetPurchasePayment(model); - throw new NotImplementedException(); + return _saveToPdf.CreateBankOperatorDoc(new PdfInfo + { + Title = "Отчёт по закупкам", + DateFrom = model.DateFrom.Value, + DateTo = model.DateTo.Value, + CurrencyPurchases = report + }); + } } } diff --git a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 555a904..a34238c 100644 --- a/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/Bank/BankBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -52,6 +52,52 @@ namespace BankBusinessLogic.OfficePackage return SavePdf(); } + + public MemoryStream CreateBankOperatorDoc(PdfInfo info) + { + if (info.CurrencyPurchases == null) + { + throw new ArgumentNullException("Данные для отчёта не найдены!", nameof(info.CurrencyPurchases)); + } + + 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 { "4cm", "3cm", "2cm", "3cm", "3cm"}); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер закупки", "Дата выплаты", "Валюта", "Номер выплаты", "Дата закупки" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var purchase in info.CurrencyPurchases) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "Закупка №" + purchase.CurrencyPurchaseId, + purchase.PurchaseDate.ToShortDateString(), purchase.CurrencyName, + "",""}, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + foreach (var payment in purchase.Payments) + { + CreateRow(new PdfRowParameters + { + Texts = new List { "", "", "", "Выплата № " + payment.PaymentId, + payment.PaymentDate.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + } + + return SavePdf(); + } + /// /// Создание doc-файла /// diff --git a/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index fc8f070..9808f46 100644 --- a/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/Bank/BankBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -18,5 +18,6 @@ namespace BankBusinessLogic.OfficePackage.HelperModels public DateTime DateTo { get; set; } public List? Transfers { get; set; } = new(); + public List? CurrencyPurchases { get; set; } = new(); } } diff --git a/Bank/BankContracts/ViewModels/ReportCurrencyPurchasePaymentViewModel.cs b/Bank/BankContracts/ViewModels/ReportCurrencyPurchasePaymentViewModel.cs index 316a92b..1c6b821 100644 --- a/Bank/BankContracts/ViewModels/ReportCurrencyPurchasePaymentViewModel.cs +++ b/Bank/BankContracts/ViewModels/ReportCurrencyPurchasePaymentViewModel.cs @@ -11,6 +11,6 @@ namespace BankContracts.ViewModels public int CurrencyPurchaseId { get; set; } public DateTime PurchaseDate { get; set; } public string CurrencyName { get; set; } - public List<(int PaymentId, string PaymentDate)> Payments { get; set; } = new(); + public List<(int PaymentId, DateTime PaymentDate)> Payments { get; set; } = new(); } } diff --git a/Bank/BankOperatorApp/Controllers/HomeController.cs b/Bank/BankOperatorApp/Controllers/HomeController.cs index ecf6c33..99e7adf 100644 --- a/Bank/BankOperatorApp/Controllers/HomeController.cs +++ b/Bank/BankOperatorApp/Controllers/HomeController.cs @@ -7,6 +7,7 @@ using BankContracts.BusinessLogicsContracts; using BankContracts.SearchModels; using BankDataModels.Models; using BankBusinessLogic.BusinessLogics; +using BankBusinessLogic.MailWorker; namespace BankOperatorApp.Controllers { @@ -18,10 +19,12 @@ namespace BankOperatorApp.Controllers private readonly ICurrencyLogic _currencyLogic; private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic; private readonly IReportLogic _reportLogic; + private readonly AbstractMailWorker _mailWorker; + public HomeController(ILogger logger, IBankOperatorLogic bankOperatorLogic, ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic, - ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic) + ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic, AbstractMailWorker mailWorker) { _logger = logger; _bankOperatorLogic = bankOperatorLogic; @@ -29,6 +32,7 @@ namespace BankOperatorApp.Controllers _currencyLogic = currencyLogic; _currencyPurchaseLogic = currencyPurchaseLogic; _reportLogic = reportLogic; + _mailWorker = mailWorker; } public IActionResult Index() @@ -286,5 +290,59 @@ namespace BankOperatorApp.Controllers "spreadsheetml.sheet", "testExcel.xlsx"); } } + + + [HttpGet] + public IActionResult CurrencyPurchasePaymentsReport() + { + if (APIClient.BankOperator == null) + { + Response.WriteAsync($""); + return Redirect("/Home/Enter"); + } + return View(new ReportBindingModel()); + } + [HttpPost] + public IActionResult CurrencyPurchasePaymentsReport(DateTime dateFrom, + DateTime dateTo, string reptype, string email, string fileName) + { + if (APIClient.BankOperator == null) + { + Response.WriteAsync($""); + return Redirect("/Home/Enter"); + } + if (reptype.Equals("onForm")) + { + ViewBag.DateFrom = dateFrom.ToShortDateString(); + ViewBag.DateTo = dateTo.ToShortDateString(); + return View("ViewReport", _reportLogic.GetPurchasePayment(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo })); + } + MemoryStream report = _reportLogic.SavePurchasePaymentToPDF(new ReportBindingModel + { DateFrom = dateFrom, DateTo = dateTo }); + try + { + if (string.IsNullOrEmpty(fileName)) fileName = "report"; + fileName = fileName.Replace(".", string.Empty); + if (!fileName.EndsWith(".pdf")) fileName += ".pdf"; + _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + Subject = "Отчёт по закупкам", + Text = "Для оператора " + APIClient.BankOperator.LastName + APIClient.BankOperator.FirstName, + MailAddress = email, + FileName = fileName, + Attachment = report + }); + Response.WriteAsync($""); + return Redirect("/"); + } + catch (Exception ex) + { + Response.WriteAsync($""); + return Redirect("/"); + } + } } } \ No newline at end of file diff --git a/Bank/BankOperatorApp/Program.cs b/Bank/BankOperatorApp/Program.cs index ff83d86..f0dbb15 100644 --- a/Bank/BankOperatorApp/Program.cs +++ b/Bank/BankOperatorApp/Program.cs @@ -6,6 +6,7 @@ using BankContracts.BindingModels; using BankOperatorApp; using BankBusinessLogic.OfficePackage.Implements; using BankBusinessLogic.OfficePackage; +using BankBusinessLogic.MailWorker; var builder = WebApplication.CreateBuilder(args); @@ -24,6 +25,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddSingleton(); builder.Services.AddTransient(); @@ -35,6 +37,24 @@ builder.Services.AddTransient(); builder.Services.AddControllersWithViews(); var app = builder.Build(); +try +{ + var mailSender = app.Services.GetService(); + mailSender?.MailConfig(new MailConfigBindingModel + { + MailLogin = builder.Configuration["MailLogin"] ?? string.Empty, + MailPassword = builder.Configuration["MailPassword"] ?? string.Empty, + SmtpClientHost = builder.Configuration["SmtpClientHost"] ?? string.Empty, + SmtpClientPort = Convert.ToInt32(builder.Configuration["SmtpClientPort"]), + PopHost = builder.Configuration["PopHost"] ?? string.Empty, + PopPort = Convert.ToInt32(builder.Configuration["PopPort"]) + }); +} +catch (Exception ex) +{ + var logger = app.Services.GetService(); + logger?.LogError(ex, " "); +} // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) diff --git a/Bank/BankOperatorApp/Views/Home/CurrencyPurchasePaymentsReport.cshtml b/Bank/BankOperatorApp/Views/Home/CurrencyPurchasePaymentsReport.cshtml new file mode 100644 index 0000000..e48bbed --- /dev/null +++ b/Bank/BankOperatorApp/Views/Home/CurrencyPurchasePaymentsReport.cshtml @@ -0,0 +1,48 @@ +@using BankContracts.BindingModels +@model ReportBindingModel + +@{ + ViewData["Title"] = "CurrencyPurchasePaymentReport"; +} +
+

Создание списка

+
+
+
+
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" } }) +
+
+

Вывести на:

+
+
На форму
+ @Html.RadioButton("reptype", "onForm", true) +
+
+
На почту (.pdf)
+ @Html.RadioButton("reptype", "pdf") +
+
+
email:
+
+
+
+
Имя файла (необязательно):
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml b/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml index 414b99e..0f4ddb8 100644 --- a/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml +++ b/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml @@ -27,8 +27,11 @@ +