178 lines
5.6 KiB
C#
Raw Normal View History

using BankYouBankruptBusinessLogic.OfficePackage;
using BankYouBankruptBusinessLogic.OfficePackage.HelperModels;
using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.BusinessLogicsContracts;
using BankYouBankruptContracts.SearchModels;
using BankYouBankruptContracts.StoragesContracts;
using BankYouBankruptContracts.ViewModels;
2023-05-19 21:05:26 +04:00
using BankYouBankruptContracts.ViewModels.Client.Default;
2023-05-19 20:41:17 +04:00
using BankYouBankruptDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankYouBankruptBusinessLogic.BusinessLogics
{
public class ReportCashierLogic : IReportCashierLogic
{
private readonly IMoneyTransferStorage _moneyTransferStorage;
private readonly ICashWithdrawalStorage _cashWithdrawalStorage;
2023-05-18 14:45:28 +04:00
private readonly IClientStorage _clientStorage;
2023-05-19 21:05:26 +04:00
private readonly IDebitingStorage _debitingStorage;
private readonly ICardStorage _cardStorage;
2023-05-19 13:04:22 +04:00
private readonly AbstractSaveToExcel _saveToExcel;
2023-05-19 23:32:09 +04:00
private readonly AbstractSaveToWord _saveToWord;
2023-05-19 13:04:22 +04:00
private readonly AbstractSaveToPdf _saveToPdf;
//инициализируем поля класса через контейнер
public ReportCashierLogic(IMoneyTransferStorage moneyTransferStorage, ICashWithdrawalStorage cashWithdrawalStorage,
2023-05-19 13:04:22 +04:00
IClientStorage clientStorage, AbstractSaveToExcel saveToExcel,
2023-05-19 23:32:09 +04:00
AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf,
2023-05-19 21:05:26 +04:00
IDebitingStorage debitingStorage, ICardStorage cardStorage)
{
_moneyTransferStorage = moneyTransferStorage;
_cashWithdrawalStorage = cashWithdrawalStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
2023-05-18 14:45:28 +04:00
_clientStorage = clientStorage;
2023-05-19 21:05:26 +04:00
_debitingStorage = debitingStorage;
_cardStorage = cardStorage;
}
//формирование списка переводов между счетами за период
public List<ReportCashierViewModel>? GetMoneyTransfers(ReportBindingModel model)
{
2023-05-18 14:45:28 +04:00
return _moneyTransferStorage.GetFilteredList(new MoneyTransferSearchModel { ClientId = model.ClientId, DateFrom = model.DateFrom, DateTo = model.DateTo})
.Select(x => new ReportCashierViewModel
{
OperationId = x.Id,
2023-04-04 23:30:30 +04:00
DateComplite = x.DateOperation,
AccountPayeeNumber = x.AccountPayeeNumber,
AccountSenderNumber = x.AccountSenderNumber,
SumOperation = x.Sum
})
.ToList();
}
//формирование списка выдаци наличных со счёта за период
public List<ReportCashierViewModel>? GetCashWithrawals(ReportBindingModel model)
{
2023-05-18 14:45:28 +04:00
return _cashWithdrawalStorage.GetFilteredList(new CashWithdrawalSearchModel { ClientId = model.ClientId, DateFrom = model.DateFrom, DateTo = model.DateTo })
2023-04-04 23:30:30 +04:00
.Select(x => new ReportCashierViewModel
{
OperationId = x.Id,
DebitingId = x.DebitingId,
AccountPayeeNumber = x.AccountNumber,
2023-04-04 23:30:30 +04:00
DateComplite = x.DateOperation,
SumOperation = x.Sum
})
.ToList();
}
2023-05-19 20:40:03 +04:00
//формирование списка выдаци наличных со счёта за период
2023-05-19 21:05:26 +04:00
public List<DebitingViewModel>? GetDebitings(ReportBindingModel model)
2023-05-19 20:40:03 +04:00
{
2023-05-19 21:05:26 +04:00
List<int> CardIdList = new();
var list = _cardStorage.GetFilteredList(new CardSearchModel
{
AccountId = model.AccountId
});
foreach(var index in list)
{
CardIdList.Add(index.Id);
}
List<DebitingViewModel> totalList = new();
foreach(var index in CardIdList)
{
var result = _debitingStorage.GetFilteredList(new DebitingSearchModel
2023-05-19 20:40:03 +04:00
{
2023-05-19 21:05:26 +04:00
CardId = index
});
totalList.AddRange(result);
}
return totalList;
2023-05-19 20:40:03 +04:00
}
2023-05-18 14:45:28 +04:00
//формирование полного имени клиента для отчёта
public string GetFullName(ReportBindingModel model)
{
var client = _clientStorage.GetElement(new ClientSearchModel
{
Id = model.ClientId
});
return client.Surname + " " + client.Name + " " + client.Patronymic;
}
//Сохранение мороженных в файл-Word
public void SaveAccountsToWordFile(ReportBindingModel model)
{
2023-05-19 23:32:09 +04:00
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Заявки на снятия со счёта",
Debiting = GetDebitings(model)
}, OfficeOperationEnum.Дляассира);
}
//Сохранение заготовок с указаеним изделий в файл-Excel
public void SaveAccountsToExcelFile(ReportBindingModel model)
{
2023-05-19 20:40:03 +04:00
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Заявки на счёт",
2023-05-19 21:05:26 +04:00
Debiting = GetDebitings(model)
2023-05-19 23:32:09 +04:00
}, OfficeOperationEnum.Дляассира);
}
//Сохранение заказов в файл-Pdf
2023-05-18 23:52:40 +04:00
public ReportCashierViewModelForHTML SaveAccountsToPdfFile(ReportBindingModel model)
{
2023-05-18 23:52:40 +04:00
var listMoneyTransfers = GetMoneyTransfers(model);
var listCashWithdrawals = GetCashWithrawals(model);
_saveToPdf.CreateDoc(new PdfInfo
{
ForClient = false,
FileName = model.FileName,
2023-05-18 14:45:28 +04:00
FullClientName = GetFullName(model),
Title = "Отчёт по операциям начислений и переводов между счетами",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
2023-05-18 23:52:40 +04:00
ReportMoneyTransfer = listMoneyTransfers,
ReportCashWithdrawal = listCashWithdrawals
});
2023-05-18 23:52:40 +04:00
//возврат полученных списков для отображения на вебе
return new ReportCashierViewModelForHTML
{
ReportCashWithdrawal = listCashWithdrawals,
ReportMoneyTransfer = listMoneyTransfers
};
}
}
}