127 lines
4.4 KiB
C#
127 lines
4.4 KiB
C#
using BankYouBankruptBusinessLogic.OfficePackage.HelperModels;
|
||
using BankYouBankruptBusinessLogic.OfficePackage;
|
||
using BankYouBankruptContracts.BindingModels;
|
||
using BankYouBankruptContracts.BusinessLogicsContracts;
|
||
using BankYouBankruptContracts.SearchModels;
|
||
using BankYouBankruptContracts.StoragesContracts;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using BankYouBankruptContracts.ViewModels.Client.Reports;
|
||
using BankYouBankruptContracts.ViewModels;
|
||
|
||
namespace BankYouBankruptBusinessLogic.BusinessLogics
|
||
{
|
||
public class ReportClientLogic : IReportClientLogic
|
||
{
|
||
private readonly ICreditingStorage _creditingStorage;
|
||
private readonly IDebitingStorage _debitingStorage;
|
||
private readonly ICardStorage _cardStorage;
|
||
private readonly IMoneyTransferStorage _moneyTransferStorage;
|
||
|
||
private readonly AbstractSaveToExcel _saveToExcel;
|
||
private readonly AbstractSaveToWordClient _saveToWord;
|
||
private readonly AbstractSaveToPdf _saveToPdf;
|
||
|
||
public ReportClientLogic(ICreditingStorage creditingStorage, IDebitingStorage debitingStorage,
|
||
AbstractSaveToExcel saveToExcel, AbstractSaveToWordClient saveToWord, AbstractSaveToPdf saveToPdf,
|
||
ICardStorage cardStorage, IMoneyTransferStorage moneyTransferStorage)
|
||
{
|
||
_creditingStorage = creditingStorage;
|
||
_debitingStorage = debitingStorage;
|
||
_cardStorage = cardStorage;
|
||
_moneyTransferStorage = moneyTransferStorage;
|
||
|
||
_saveToExcel = saveToExcel;
|
||
_saveToWord = saveToWord;
|
||
_saveToPdf = saveToPdf;
|
||
}
|
||
|
||
public List<ReportClientViewModel>? GetCrediting(ReportBindingModel model)
|
||
{
|
||
return _creditingStorage.GetFilteredList(new CreditingSearchModel
|
||
{
|
||
DateFrom = model.DateFrom,
|
||
DateTo = model.DateTo,
|
||
}).Select(x => new ReportClientViewModel
|
||
{
|
||
OperationId = x.Id,
|
||
CardNumber = x.CardNumber,
|
||
SumOperation = x.Sum,
|
||
DateComplite = x.DateOpen
|
||
}).ToList();
|
||
}
|
||
|
||
public List<ReportClientViewModel>? GetDebiting(ReportBindingModel model)
|
||
{
|
||
return _debitingStorage.GetFilteredList(new DebitingSearchModel
|
||
{
|
||
DateTo = model.DateFrom,
|
||
DateFrom = model.DateTo,
|
||
}).Select(x => new ReportClientViewModel
|
||
{
|
||
OperationId = x.Id,
|
||
CardNumber = x.CardNumber,
|
||
SumOperation = x.Sum,
|
||
DateComplite = x.DateClose
|
||
}).ToList();
|
||
}
|
||
|
||
public List<MoneyTransferViewModel>? GetMoneyTransfer(ReportBindingModel model)
|
||
{
|
||
var accountId = _cardStorage.GetElement(new CardSearchModel
|
||
{
|
||
Id = model.CardId
|
||
}).AccountId;
|
||
|
||
return _moneyTransferStorage.GetFilteredList(new MoneyTransferSearchModel
|
||
{
|
||
AccountPayeeId = accountId,
|
||
AccountSenderId = accountId
|
||
});
|
||
}
|
||
|
||
public void SaveToExcelFile(ReportBindingModel model)
|
||
{
|
||
_saveToExcel.CreateReport(new ExcelInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Список переводов денег",
|
||
MoneyTransfer = GetMoneyTransfer(model)
|
||
});
|
||
}
|
||
|
||
public void SaveToWordFile(ReportBindingModel model)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
//отчёт в формате PDF для клиента
|
||
public ReportClientViewModelForHTML SaveClientReportToPdfFile(ReportBindingModel model)
|
||
{
|
||
var listCreditings = GetCrediting(model);
|
||
var listDebitings = GetDebiting(model);
|
||
|
||
_saveToPdf.CreateDoc(new PdfInfo
|
||
{
|
||
FileName = model.FileName,
|
||
Title = "Отчёт по операциям с картами",
|
||
DateFrom = model.DateFrom!.Value,
|
||
DateTo = model.DateTo!.Value,
|
||
ReportCrediting = listCreditings,
|
||
ReportDebiting = listDebitings
|
||
});
|
||
|
||
//возврат полученных списков для отображения на вебе
|
||
return new ReportClientViewModelForHTML
|
||
{
|
||
ReportCrediting = listCreditings,
|
||
|
||
ReportDebiting = listDebitings
|
||
};
|
||
}
|
||
}
|
||
}
|