From 56ebf0902ae03d504b9fc98e033a195cbbf2e955 Mon Sep 17 00:00:00 2001 From: ksenianeva <95441235+ksenianeva@users.noreply.github.com> Date: Fri, 7 Apr 2023 22:32:57 +0400 Subject: [PATCH] =?UTF-8?q?Reports=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=9F=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D1=89=D0=B8?= =?UTF-8?q?=D0=BA.=20=D0=A4=D0=B8=D0=BA=D1=81=20GetFilteredList()=20=D0=B2?= =?UTF-8?q?=20CurrencyPurchaseStorage.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20DateFrom=20=D0=B8=20DateTo=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=BE=D0=BE=D1=82=D0=B2=D0=B5=D1=82=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D1=83=D1=8E=D1=89=D1=83=D1=8E=20SearchModel.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportLogic.cs | 76 ++++++++++++++++++- .../BusinessLogicsContracts/IReportLogic.cs | 6 ++ .../CurrencyPurchaseSearchModel.cs | 2 + .../ReportCurrencyPurchasePaymentViewModel.cs | 15 ++++ .../ReportCurrencyTransferViewModel.cs | 15 ++++ .../Implements/CurrencyPurchaseStorage.cs | 15 +++- 6 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 Bank/BankContracts/ViewModels/ReportCurrencyPurchasePaymentViewModel.cs create mode 100644 Bank/BankContracts/ViewModels/ReportCurrencyTransferViewModel.cs diff --git a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs index becbd05..c4e1ee6 100644 --- a/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogics/ReportLogic.cs @@ -106,7 +106,62 @@ namespace BankBusinessLogic.BusinessLogics return list; } - public void SavePaymentPurchaseToExcel(List payments) + public List GetCurrencyTransfers(List currencies) + { + var list = new List(); + var payments = _paymentStorage.GetFullList(); + var transfers = _transferStorage.GetFullList(); + foreach(var currency in currencies) + { + var record = new ReportCurrencyTransferViewModel + { + CurrencyId = currency.Id, + CurrencyName = currency.Name, + Transfers = new List<(int TransferId, float Amount)>(), + }; + var paymentsId = new List(); + foreach(var payment in payments) + { + if (payment.CurrencyPayments.ContainsKey(currency.Id)) paymentsId.Add(payment.Id); + } + foreach(var transfer in transfers) + { + foreach(int paymentId in paymentsId) + { + if (paymentId == transfer.PaymentId) + { + record.Transfers.Add(new(transfer.Id, transfer.Amount)); + } + } + } + list.Add(record); + } + return list; + } + public List GetPurchasePayment(ReportBindingModel model) + { + var purchases = _currencyPurchaseStorage.GetFilteredList(new CurrencyPurchaseSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); + var list = new List(); + var payments = _paymentStorage.GetFullList(); + foreach (var purchase in purchases) + { + var record = new ReportCurrencyPurchasePaymentViewModel + { + CurrencyPurchaseId = purchase.Id, + PurchaseDate = purchase.PurchaseDate, + Payments = new List<(int PaymentId, string 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())); + } + list.Add(record); + } + return list; + } + + public void SavePaymentPurchaseToExcel(List payments) { var result = GetPaymentPurchase(payments); //создание файла будет реализовано в будующих версиях @@ -126,5 +181,22 @@ namespace BankBusinessLogic.BusinessLogics //создание файла будет реализовано в будующих версиях throw new NotImplementedException(); } - } + + public void SaveCurrencyTransfersToExcel(List currencies) + { + var report = GetCurrencyTransfers(currencies); + throw new NotImplementedException(); + } + + public void SaveCurrencyTransfersToWord(List currencies) + { + var report = GetCurrencyTransfers(currencies); + throw new NotImplementedException(); + } + public void 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 de36b50..1e1a3b5 100644 --- a/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/Bank/BankContracts/BusinessLogicsContracts/IReportLogic.cs @@ -15,5 +15,11 @@ namespace BankContracts.BusinessLogicsContracts void SavePaymentPurchaseToWord(List payments); void SavePaymentPurchaseToExcel(List payments); void SaveTransferPurchaseToPDF(ReportBindingModel model); + + List GetCurrencyTransfers(List currencies); + List GetPurchasePayment(ReportBindingModel model); + void SaveCurrencyTransfersToWord(List currencies); + void SaveCurrencyTransfersToExcel(List currencies); + void SavePurchasePaymentToPDF(ReportBindingModel model); } } diff --git a/Bank/BankContracts/SearchModels/CurrencyPurchaseSearchModel.cs b/Bank/BankContracts/SearchModels/CurrencyPurchaseSearchModel.cs index 14b8fee..75de05a 100644 --- a/Bank/BankContracts/SearchModels/CurrencyPurchaseSearchModel.cs +++ b/Bank/BankContracts/SearchModels/CurrencyPurchaseSearchModel.cs @@ -10,5 +10,7 @@ namespace BankContracts.SearchModels { public int? Id { get; set; } public int? BankOperatorId { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/Bank/BankContracts/ViewModels/ReportCurrencyPurchasePaymentViewModel.cs b/Bank/BankContracts/ViewModels/ReportCurrencyPurchasePaymentViewModel.cs new file mode 100644 index 0000000..e664a36 --- /dev/null +++ b/Bank/BankContracts/ViewModels/ReportCurrencyPurchasePaymentViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankContracts.ViewModels +{ + public class ReportCurrencyPurchasePaymentViewModel + { + public int CurrencyPurchaseId { get; set; } + public DateTime PurchaseDate { get; set; } + public List<(int PaymentId, string PaymentDate)> Payments { get; set; } = new(); + } +} diff --git a/Bank/BankContracts/ViewModels/ReportCurrencyTransferViewModel.cs b/Bank/BankContracts/ViewModels/ReportCurrencyTransferViewModel.cs new file mode 100644 index 0000000..66dcf0c --- /dev/null +++ b/Bank/BankContracts/ViewModels/ReportCurrencyTransferViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankContracts.ViewModels +{ + public class ReportCurrencyTransferViewModel + { + public int CurrencyId { get; set; } + public string CurrencyName { get; set; } = string.Empty; + public List<(int TransferId, float Amount)> Transfers { get; set; } = new(); + } +} diff --git a/Bank/BankDatabaseImplement/Implements/CurrencyPurchaseStorage.cs b/Bank/BankDatabaseImplement/Implements/CurrencyPurchaseStorage.cs index 029c5ad..0e50b36 100644 --- a/Bank/BankDatabaseImplement/Implements/CurrencyPurchaseStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/CurrencyPurchaseStorage.cs @@ -41,15 +41,26 @@ namespace BankDatabaseImplement.Implements public List GetFilteredList(CurrencyPurchaseSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) { return new(); } + if (model.DateFrom.HasValue && model.DateTo.HasValue) + { using var context = new BankDatabase(); - return context.CurrencyPurchases.Include(x => x.BankOperator).Include(x=>x.Currency) + return context.CurrencyPurchases.Include(x => x.BankOperator).Include(x => x.Currency) + .Where(x => x.PurchaseDate >= model.DateFrom && x.PurchaseDate <= model.DateTo) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + using var context = new BankDatabase(); + return context.CurrencyPurchases.Include(x => x.BankOperator).Include(x => x.Currency) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); + } } public List GetFullList()