2023-04-07 21:35:31 +04:00
|
|
|
|
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;
|
2023-05-19 23:50:03 +04:00
|
|
|
|
using BankBusinessLogic.OfficePackage;
|
|
|
|
|
using BankBusinessLogic.OfficePackage.HelperModels;
|
2023-04-07 21:35:31 +04:00
|
|
|
|
|
|
|
|
|
namespace BankBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly ITransferStorage _transferStorage;
|
|
|
|
|
private readonly IPaymentStorage _paymentStorage;
|
|
|
|
|
private readonly ICurrencyPurchaseStorage _currencyPurchaseStorage;
|
|
|
|
|
private readonly ICurrencyStorage _currencyStorage;
|
|
|
|
|
|
2023-05-19 19:00:15 +04:00
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
2023-05-19 22:30:05 +04:00
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
2023-05-19 19:00:15 +04:00
|
|
|
|
|
2023-05-19 22:30:05 +04:00
|
|
|
|
public ReportLogic(ITransferStorage transferStorage, IPaymentStorage paymentStorage, ICurrencyStorage currencyStorage, ICurrencyPurchaseStorage currencyPurchaseStorage, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel, AbstractSaveToPdf saveToPdf)
|
2023-04-07 21:35:31 +04:00
|
|
|
|
{
|
|
|
|
|
_transferStorage = transferStorage;
|
|
|
|
|
_paymentStorage = paymentStorage;
|
2023-05-19 19:00:15 +04:00
|
|
|
|
_currencyStorage = currencyStorage;
|
2023-04-07 21:35:31 +04:00
|
|
|
|
_currencyPurchaseStorage = currencyPurchaseStorage;
|
2023-05-19 19:00:15 +04:00
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToExcel = saveToExcel;
|
2023-05-19 22:30:05 +04:00
|
|
|
|
_saveToPdf = saveToPdf;
|
2023-04-07 21:35:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2023-05-19 22:30:05 +04:00
|
|
|
|
Purchases = new List<CurrencyPurchaseViewModel>()
|
2023-04-07 21:35:31 +04:00
|
|
|
|
};
|
2023-05-19 22:30:05 +04:00
|
|
|
|
var payment = _paymentStorage.GetElement(new PaymentSearchModel { Id = transfer.PaymentId});
|
2023-04-07 21:35:31 +04:00
|
|
|
|
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)
|
|
|
|
|
{
|
2023-05-19 22:30:05 +04:00
|
|
|
|
record.Purchases.Add(currencyPurchase);
|
2023-04-07 21:35:31 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-07 22:34:52 +04:00
|
|
|
|
list.Add(record);
|
2023-04-07 21:35:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 22:32:57 +04:00
|
|
|
|
public List<ReportCurrencyTransferViewModel> GetCurrencyTransfers(List<CurrencyBindingModel> currencies)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<ReportCurrencyTransferViewModel>();
|
|
|
|
|
var payments = _paymentStorage.GetFullList();
|
|
|
|
|
var transfers = _transferStorage.GetFullList();
|
|
|
|
|
foreach(var currency in currencies)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportCurrencyTransferViewModel
|
|
|
|
|
{
|
|
|
|
|
CurrencyId = currency.Id,
|
|
|
|
|
CurrencyName = currency.Name,
|
2023-05-20 03:30:06 +04:00
|
|
|
|
Transfers = new List<TransferViewModel>(),
|
2023-04-07 22:32:57 +04:00
|
|
|
|
};
|
|
|
|
|
var paymentsId = new List<int>();
|
|
|
|
|
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)
|
|
|
|
|
{
|
2023-05-20 03:30:06 +04:00
|
|
|
|
record.Transfers.Add(transfer);
|
2023-04-07 22:32:57 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
list.Add(record);
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
public List<ReportCurrencyPurchasePaymentViewModel> GetPurchasePayment(ReportBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
var purchases = _currencyPurchaseStorage.GetFilteredList(new CurrencyPurchaseSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo });
|
|
|
|
|
var list = new List<ReportCurrencyPurchasePaymentViewModel>();
|
|
|
|
|
var payments = _paymentStorage.GetFullList();
|
|
|
|
|
foreach (var purchase in purchases)
|
|
|
|
|
{
|
|
|
|
|
var record = new ReportCurrencyPurchasePaymentViewModel
|
|
|
|
|
{
|
|
|
|
|
CurrencyPurchaseId = purchase.Id,
|
|
|
|
|
PurchaseDate = purchase.PurchaseDate,
|
2023-05-20 03:30:06 +04:00
|
|
|
|
CurrencyName = purchase.CurrencyName,
|
2023-04-07 22:32:57 +04:00
|
|
|
|
Payments = new List<(int PaymentId, string PaymentDate)>(),
|
|
|
|
|
};
|
|
|
|
|
var paymentsId = new List<int>();
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 19:00:15 +04:00
|
|
|
|
public MemoryStream SavePaymentPurchaseToExcel(ReportBindingModel model, List<PaymentBindingModel> payments)
|
2023-04-07 21:35:31 +04:00
|
|
|
|
{
|
|
|
|
|
var result = GetPaymentPurchase(payments);
|
2023-05-19 19:00:15 +04:00
|
|
|
|
return _saveToExcel.CreateOperatorReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
Title = "Отчёт о выплатах",
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Payments = result
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-04-07 21:35:31 +04:00
|
|
|
|
|
2023-05-19 19:00:15 +04:00
|
|
|
|
public MemoryStream SavePaymentPurchaseToWord(ReportBindingModel model, List<PaymentBindingModel> payments)
|
2023-04-07 21:35:31 +04:00
|
|
|
|
{
|
|
|
|
|
var result = GetPaymentPurchase(payments);
|
2023-05-19 19:00:15 +04:00
|
|
|
|
return _saveToWord.CreateOperatorDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
Title = "Отчёт о выплатах",
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Payments = result
|
|
|
|
|
});
|
2023-04-07 21:35:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 22:30:05 +04:00
|
|
|
|
public MemoryStream SaveTransferPurchaseToPDF(ReportBindingModel model)
|
2023-04-07 21:35:31 +04:00
|
|
|
|
{
|
2023-05-19 22:30:05 +04:00
|
|
|
|
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Отсутствуют даты для отчёта!");
|
|
|
|
|
}
|
2023-04-07 21:35:31 +04:00
|
|
|
|
var result = GetTransferPurchase(model);
|
2023-05-19 22:30:05 +04:00
|
|
|
|
return _saveToPdf.CreateOperatorDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
Title = "Отчёт о зачислениях",
|
|
|
|
|
DateFrom = model.DateFrom.Value,
|
|
|
|
|
DateTo = model.DateTo.Value,
|
|
|
|
|
Transfers = result
|
|
|
|
|
});
|
2023-04-07 21:35:31 +04:00
|
|
|
|
}
|
2023-04-07 22:32:57 +04:00
|
|
|
|
|
2023-05-20 04:36:30 +04:00
|
|
|
|
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<CurrencyBindingModel> currencies)
|
2023-04-07 22:32:57 +04:00
|
|
|
|
{
|
|
|
|
|
var report = GetCurrencyTransfers(currencies);
|
2023-05-20 04:36:30 +04:00
|
|
|
|
return _saveToExcel.CreateBankOperatorReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
Title = "Отчёт по валютам",
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Currencies = report
|
|
|
|
|
});
|
2023-04-07 22:32:57 +04:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-20 04:36:30 +04:00
|
|
|
|
public MemoryStream SaveCurrencyTransfersToWord(ReportBindingModel model, List<CurrencyBindingModel> currencies)
|
2023-04-07 22:32:57 +04:00
|
|
|
|
{
|
|
|
|
|
var report = GetCurrencyTransfers(currencies);
|
2023-05-20 04:36:30 +04:00
|
|
|
|
return _saveToWord.CreateBankOperatorDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
Title = "Отчёт по валютам",
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Currencies = report
|
|
|
|
|
});
|
2023-04-07 22:32:57 +04:00
|
|
|
|
}
|
2023-05-20 04:36:30 +04:00
|
|
|
|
public MemoryStream SavePurchasePaymentToPDF(ReportBindingModel model)
|
2023-04-07 22:32:57 +04:00
|
|
|
|
{
|
|
|
|
|
var report = GetPurchasePayment(model);
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-07 21:35:31 +04:00
|
|
|
|
}
|