diff --git a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs index e11fba6..ecc2735 100644 --- a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs @@ -211,18 +211,44 @@ namespace BankBusinessLogic.BusinessLogics }); } - public void SaveCurrencyTransfersToExcel(List currencies) + public MemoryStream SaveCurrencyTransferToPDF(ReportBindingModel model) { - var report = GetCurrencyTransfers(currencies); - throw new NotImplementedException(); + 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 void SaveCurrencyTransfersToWord(List currencies) + public MemoryStream SaveCurrencyTransfersToExcel(ReportBindingModel model, List currencies) { var report = GetCurrencyTransfers(currencies); - throw new NotImplementedException(); + return _saveToExcel.CreateBankOperatorReport(new ExcelInfo + { + Title = "Отчёт по валютам", + FileName = model.FileName, + Currencies = report + }); } - public void SavePurchasePaymentToPDF(ReportBindingModel model) + + public MemoryStream SaveCurrencyTransfersToWord(ReportBindingModel model, List currencies) + { + var report = GetCurrencyTransfers(currencies); + return _saveToWord.CreateBankOperatorDoc(new WordInfo + { + Title = "Отчёт по валютам", + FileName = model.FileName, + Currencies = report + }); + } + public MemoryStream SavePurchasePaymentToPDF(ReportBindingModel model) { var report = GetPurchasePayment(model); throw new NotImplementedException(); diff --git a/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs b/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs index ccda09c..0be4876 100644 --- a/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs @@ -18,8 +18,8 @@ namespace BankContracts.BusinessLogicsContracts List GetCurrencyTransfers(List currencies); List GetPurchasePayment(ReportBindingModel model); - void SaveCurrencyTransfersToWord(List currencies); - void SaveCurrencyTransfersToExcel(List currencies); - void SavePurchasePaymentToPDF(ReportBindingModel model); + MemoryStream SaveCurrencyTransfersToWord(ReportBindingModel model, List currencies); + MemoryStream SaveCurrencyTransfersToExcel(ReportBindingModel model, List currencies); + MemoryStream SavePurchasePaymentToPDF(ReportBindingModel model); } } diff --git a/Bank/BankOperatorApp/Controllers/HomeController.cs b/Bank/BankOperatorApp/Controllers/HomeController.cs index 7bc8f06..ecf6c33 100644 --- a/Bank/BankOperatorApp/Controllers/HomeController.cs +++ b/Bank/BankOperatorApp/Controllers/HomeController.cs @@ -16,17 +16,19 @@ namespace BankOperatorApp.Controllers private readonly IBankOperatorLogic _bankOperatorLogic; private readonly ICreditProgramLogic _creditProgramLogic; private readonly ICurrencyLogic _currencyLogic; - private ICurrencyPurchaseLogic _currencyPurchaseLogic; + private readonly ICurrencyPurchaseLogic _currencyPurchaseLogic; + private readonly IReportLogic _reportLogic; public HomeController(ILogger logger, IBankOperatorLogic bankOperatorLogic, ICreditProgramLogic creditProgramLogic, ICurrencyLogic currencyLogic, - ICurrencyPurchaseLogic currencyPurchaseLogic) + ICurrencyPurchaseLogic currencyPurchaseLogic, IReportLogic reportLogic) { _logger = logger; _bankOperatorLogic = bankOperatorLogic; _creditProgramLogic = creditProgramLogic; _currencyLogic = currencyLogic; _currencyPurchaseLogic = currencyPurchaseLogic; + _reportLogic = reportLogic; } public IActionResult Index() @@ -239,5 +241,50 @@ namespace BankOperatorApp.Controllers return View(_currencyPurchaseLogic.ReadList(new CurrencyPurchaseSearchModel { BankOperatorId = APIClient.BankOperator.Id })); } + + [HttpGet] + public IActionResult CurrencyReport() + { + if (APIClient.BankOperator == null) + { + Response.WriteAsync($""); + return Redirect("/Home/Enter"); + } + ViewBag.Currencies = _currencyLogic.ReadList(null); + return View(); + } + + [HttpPost] + public IActionResult CurrencyReport(List currencies, string doctype) + { + List currencyBindings = new List(); + foreach (int currencyId in currencies) + { + var currencyView = _currencyLogic.ReadElement + (new CurrencySearchModel { Id = currencyId }); + if (currencyView != null) currencyBindings.Add(new CurrencyBindingModel + { + Id = currencyView.Id, + BankOperatorId = currencyView.BankOperatorId, + Name = currencyView.Name, + }); + } + if (doctype.Equals("word")) + { + MemoryStream list = _reportLogic.SaveCurrencyTransfersToWord + (new ReportBindingModel { FileName = "test" }, currencyBindings); + return File(list, "application/vnd.openxmlformats-officedocument." + + "wordprocessingml.document", "testDoc.docx"); + } + else + { + MemoryStream list = _reportLogic.SaveCurrencyTransfersToExcel + (new ReportBindingModel { FileName = "test" }, currencyBindings); + return File(list, "application/vnd.openxmlformats-officedocument." + + "spreadsheetml.sheet", "testExcel.xlsx"); + } + } } } \ No newline at end of file diff --git a/Bank/BankOperatorApp/Program.cs b/Bank/BankOperatorApp/Program.cs index eabc8de..ff83d86 100644 --- a/Bank/BankOperatorApp/Program.cs +++ b/Bank/BankOperatorApp/Program.cs @@ -4,6 +4,8 @@ using BankContracts.StoragesContracts; using BankDatabaseImplement.Implements; using BankContracts.BindingModels; using BankOperatorApp; +using BankBusinessLogic.OfficePackage.Implements; +using BankBusinessLogic.OfficePackage; var builder = WebApplication.CreateBuilder(args); @@ -19,11 +21,16 @@ 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(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllersWithViews(); diff --git a/Bank/BankOperatorApp/Views/Home/CurrencyReport.cshtml b/Bank/BankOperatorApp/Views/Home/CurrencyReport.cshtml new file mode 100644 index 0000000..1afa1c5 --- /dev/null +++ b/Bank/BankOperatorApp/Views/Home/CurrencyReport.cshtml @@ -0,0 +1,28 @@ +@{ + ViewData["Title"] = "CurrencyReport"; +} +
+

Создание валюты

+
+
+
+
Валюты:
+
+ +
+
+
+
Word
+ @Html.RadioButton("doctype", "word", true) + +
+
+
Excel
+ @Html.RadioButton("doctype", "excel") +
+
+
+
+
+
\ No newline at end of file diff --git a/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml b/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml index 6212d5c..414b99e 100644 --- a/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml +++ b/Bank/BankOperatorApp/Views/Shared/_Layout.cshtml @@ -27,6 +27,8 @@