Отчёты для роли Заказчик

This commit is contained in:
abazov73 2023-04-07 21:35:31 +04:00
parent b6ccb7eb37
commit b89974dd9f
7 changed files with 204 additions and 1 deletions

View File

@ -0,0 +1,130 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using BankContracts.StoragesContracts;
using BankContracts.ViewModels;
using BankContracts.SearchModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly ITransferStorage _transferStorage;
private readonly IPaymentStorage _paymentStorage;
private readonly ICurrencyPurchaseStorage _currencyPurchaseStorage;
private readonly ICurrencyStorage _currencyStorage;
public ReportLogic(ITransferStorage transferStorage, IPaymentStorage paymentStorage, ICurrencyPurchaseStorage currencyPurchaseStorage)
{
_transferStorage = transferStorage;
_paymentStorage = paymentStorage;
_currencyPurchaseStorage = currencyPurchaseStorage;
}
public List<ReportPaymentCurrencyPurchaseViewModel> GetPaymentPurchase(List<PaymentBindingModel> payments)
{
var list = new List<ReportPaymentCurrencyPurchaseViewModel>();
var currencies = _currencyStorage.GetFullList();
var currencyPurchases = _currencyPurchaseStorage.GetFullList();
foreach(var payment in payments)
{
var record = new ReportPaymentCurrencyPurchaseViewModel
{
PaymentId = payment.Id,
PaymentDate = payment.PaymentDate,
Purchases = new List<(int, float)>()
};
var foundCurrenciesId = new List<int>();
//находим валюты, привязанные к платежу
foreach (var currency in currencies)
{
if (payment.CurrencyPayments.ContainsKey(currency.Id)) foundCurrenciesId.Add(currency.Id);
}
//выбираем из всех закупок те, которые относятся к найденным валютам
foreach (var currencyPurchase in currencyPurchases)
{
foreach(var currencyId in foundCurrenciesId)
{
if (currencyPurchase.CurrencyId == currencyId)
{
record.Purchases.Add(new(currencyPurchase.Id, currencyPurchase.Amount));
break;
}
}
}
list.Add(record);
}
return list;
}
public List<ReportTransferCurrencyPurchaseViewModel> GetTransferPurchase(ReportBindingModel model)
{
var transfers = _transferStorage.GetFilteredList(new TransferSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo });
var currencies = _currencyStorage.GetFullList();
var currencyPurchases = _currencyPurchaseStorage.GetFullList();
var list = new List<ReportTransferCurrencyPurchaseViewModel>();
foreach (var transfer in transfers)
{
var record = new ReportTransferCurrencyPurchaseViewModel
{
TransferId = transfer.Id,
TransferDate = transfer.TransferDateTime,
Purchases = new List<(int, float)>()
};
var payment = _paymentStorage.GetElement(new PaymentSearchModel { Id = transfer.Id});
if (payment == null)
{
throw new InvalidOperationException("Платеж не был найден!");
}
var foundCurrenciesId = new List<int>();
//находим валюты, привязанные к платежу
foreach (var currency in currencies)
{
if (payment.CurrencyPayments.ContainsKey(currency.Id)) foundCurrenciesId.Add(currency.Id);
}
//выбираем из всех закупок те, которые относятся к найденным валютам
foreach (var currencyPurchase in currencyPurchases)
{
foreach (var currencyId in foundCurrenciesId)
{
if (currencyPurchase.CurrencyId == currencyId)
{
record.Purchases.Add(new(currencyPurchase.Id, currencyPurchase.Amount));
break;
}
}
}
}
return list;
}
public void SavePaymentPurchaseToExcel(List<PaymentBindingModel> payments)
{
var result = GetPaymentPurchase(payments);
//создание файла будет реализовано в будующих версиях
throw new NotImplementedException();
}
public void SavePaymentPurchaseToWord(List<PaymentBindingModel> payments)
{
var result = GetPaymentPurchase(payments);
//создание файла будет реализовано в будующих версиях
throw new NotImplementedException();
}
public void SaveTransferPurchaseToPDF(ReportBindingModel model)
{
var result = GetTransferPurchase(model);
//создание файла будет реализовано в будующих версиях
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankContracts.BindingModels
{
public class ReportBindingModel
{
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
}
}

View File

@ -0,0 +1,19 @@
using BankContracts.BindingModels;
using BankContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankContracts.BusinessLogicsContracts
{
public interface IReportLogic
{
List<ReportPaymentCurrencyPurchaseViewModel> GetPaymentPurchase(List<PaymentBindingModel> payments);
List<ReportTransferCurrencyPurchaseViewModel> GetTransferPurchase(ReportBindingModel model);
void SavePaymentPurchaseToWord(List<PaymentBindingModel> payments);
void SavePaymentPurchaseToExcel(List<PaymentBindingModel> payments);
void SaveTransferPurchaseToPDF(ReportBindingModel model);
}
}

View File

@ -10,5 +10,7 @@ namespace BankContracts.SearchModels
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? OperatorId { get; set; } public int? OperatorId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
} }
} }

View File

@ -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 ReportPaymentCurrencyPurchaseViewModel
{
public int PaymentId { get; set; }
public DateTime PaymentDate { get; set; }
public List<(int PurchaseId, float Amount)> Purchases { get; set; } = new();
}
}

View File

@ -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 ReportTransferCurrencyPurchaseViewModel
{
public int TransferId { get; set; }
public DateTime TransferDate { get; set; }
public List<(int PurchaseId, float Amount)> Purchases { get; set; } = new();
}
}

View File

@ -23,10 +23,18 @@ namespace BankDatabaseImplement.Implements
} }
public List<TransferViewModel> GetFilteredList(TransferSearchModel model) public List<TransferViewModel> GetFilteredList(TransferSearchModel model)
{ {
if (!model.Id.HasValue && !model.OperatorId.HasValue) if (!model.Id.HasValue && !model.OperatorId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue)
{ {
return new(); return new();
} }
if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
using var context = new BankDatabase();
return context.Transfers.Include(x => x.Payment).Include(x => x.OperatorId)
.Where(x => x.TransferDateTime >= model.DateFrom && x.TransferDateTime <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.OperatorId.HasValue) if (model.OperatorId.HasValue)
{ {
using var context = new BankDatabase(); using var context = new BankDatabase();