220 lines
7.3 KiB
C#
220 lines
7.3 KiB
C#
using BankYouBankruptBusinessLogic.MailWorker;
|
||
using BankYouBankruptBusinessLogic.OfficePackage;
|
||
using BankYouBankruptBusinessLogic.OfficePackage.HelperModels;
|
||
using BankYouBankruptContracts.BindingModels;
|
||
using BankYouBankruptContracts.BusinessLogicsContracts;
|
||
using BankYouBankruptContracts.SearchModels;
|
||
using BankYouBankruptContracts.StoragesContracts;
|
||
using BankYouBankruptContracts.ViewModels;
|
||
using BankYouBankruptContracts.ViewModels.Client.Default;
|
||
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;
|
||
private readonly IClientStorage _clientStorage;
|
||
private readonly IDebitingStorage _debitingStorage;
|
||
private readonly ICardStorage _cardStorage;
|
||
|
||
private readonly AbstractSaveToExcel _saveToExcel;
|
||
private readonly AbstractSaveToWord _saveToWord;
|
||
private readonly AbstractSaveToPdf _saveToPdf;
|
||
|
||
private readonly MailKitWorker _mailKitWorker;
|
||
|
||
//инициализируем поля класса через контейнер
|
||
public ReportCashierLogic(IMoneyTransferStorage moneyTransferStorage, ICashWithdrawalStorage cashWithdrawalStorage,
|
||
IClientStorage clientStorage, AbstractSaveToExcel saveToExcel,
|
||
AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf,
|
||
IDebitingStorage debitingStorage, ICardStorage cardStorage, MailKitWorker mailKitWorker)
|
||
{
|
||
_moneyTransferStorage = moneyTransferStorage;
|
||
_cashWithdrawalStorage = cashWithdrawalStorage;
|
||
|
||
_saveToExcel = saveToExcel;
|
||
_saveToWord = saveToWord;
|
||
_saveToPdf = saveToPdf;
|
||
_clientStorage = clientStorage;
|
||
_debitingStorage = debitingStorage;
|
||
_cardStorage = cardStorage;
|
||
|
||
_mailKitWorker = mailKitWorker;
|
||
}
|
||
|
||
//формирование списка переводов между счетами за период
|
||
public List<ReportCashierViewModel>? GetMoneyTransfers(ReportBindingModel model)
|
||
{
|
||
return _moneyTransferStorage.GetFilteredList(new MoneyTransferSearchModel { ClientId = model.ClientId, DateFrom = model.DateFrom, DateTo = model.DateTo})
|
||
.Select(x => new ReportCashierViewModel
|
||
{
|
||
OperationId = x.Id,
|
||
DateComplite = x.DateOperation,
|
||
AccountPayeeNumber = x.AccountPayeeNumber,
|
||
AccountSenderNumber = x.AccountSenderNumber,
|
||
SumOperation = x.Sum
|
||
})
|
||
.ToList();
|
||
}
|
||
|
||
//формирование списка выдаци наличных со счёта за период
|
||
public List<ReportCashierViewModel>? GetCashWithrawals(ReportBindingModel model)
|
||
{
|
||
return _cashWithdrawalStorage.GetFilteredList(new CashWithdrawalSearchModel { ClientId = model.ClientId, DateFrom = model.DateFrom, DateTo = model.DateTo })
|
||
.Select(x => new ReportCashierViewModel
|
||
{
|
||
OperationId = x.Id,
|
||
DebitingId = x.DebitingId,
|
||
AccountPayeeNumber = x.AccountNumber,
|
||
DateComplite = x.DateOperation,
|
||
SumOperation = x.Sum
|
||
})
|
||
.ToList();
|
||
}
|
||
|
||
//формирование списка выдаци наличных со счёта за период
|
||
public List<DebitingViewModel>? GetDebitings(ReportBindingModel model)
|
||
{
|
||
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
|
||
{
|
||
CardId = index
|
||
});
|
||
|
||
totalList.AddRange(result);
|
||
}
|
||
|
||
return totalList;
|
||
}
|
||
|
||
//формирование полного имени клиента для отчёта
|
||
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)
|
||
{
|
||
_saveToWord.CreateDoc(new WordInfo
|
||
{
|
||
FileName = model.FileName,
|
||
|
||
Title = "Заявки на снятия со счёта",
|
||
|
||
Debiting = GetDebitings(model)
|
||
}, OfficeOperationEnum.Для_кассира);
|
||
|
||
byte[] word = System.IO.File.ReadAllBytes("../BankYouBankruptRestAPI/Отчёт по зявкам на снятие.docx");
|
||
|
||
File.Delete("../BankYouBankruptRestAPI/Отчёт по зявкам на снятие.docx");
|
||
|
||
_mailKitWorker.SendMailAsync(new()
|
||
{
|
||
MailAddress = model.Email,
|
||
Subject = "Отчёт по счетам",
|
||
Text = $"Отчёт по состоянию на {DateTime.Now.ToString()}",
|
||
File = word,
|
||
Role = model.Role,
|
||
TypeDoc = TypeDocEnum.WORD
|
||
});
|
||
}
|
||
|
||
//Сохранение заготовок с указаеним изделий в файл-Excel
|
||
public void SaveAccountsToExcelFile(ReportBindingModel model)
|
||
{
|
||
_saveToExcel.CreateReport(new ExcelInfo
|
||
{
|
||
FileName = model.FileName,
|
||
|
||
Title = "Заявки на счёт",
|
||
|
||
Debiting = GetDebitings(model)
|
||
}, OfficeOperationEnum.Для_кассира);
|
||
|
||
byte[] excel = System.IO.File.ReadAllBytes("../BankYouBankruptRestAPI/Отчёт по зявкам на снятие.xlsx");
|
||
|
||
File.Delete("../BankYouBankruptRestAPI/Отчёт по зявкам на снятие.xlsx");
|
||
|
||
_mailKitWorker.SendMailAsync(new()
|
||
{
|
||
MailAddress = model.Email,
|
||
Subject = "Отчёт по счетам",
|
||
Text = $"Отчёт по состоянию на {DateTime.Now.ToString()}",
|
||
File = excel,
|
||
Role = model.Role,
|
||
TypeDoc = TypeDocEnum.EXCEL
|
||
});
|
||
}
|
||
|
||
//Сохранение заказов в файл-Pdf
|
||
public ReportCashierViewModelForHTML SaveAccountsToPdfFile(ReportBindingModel model)
|
||
{
|
||
var listMoneyTransfers = GetMoneyTransfers(model);
|
||
var listCashWithdrawals = GetCashWithrawals(model);
|
||
|
||
_saveToPdf.CreateDoc(new PdfInfo
|
||
{
|
||
ForClient = false,
|
||
FileName = model.FileName,
|
||
FullClientName = GetFullName(model),
|
||
Title = "Отчёт по операциям списаний со счёта и переводов между счетами",
|
||
DateFrom = model.DateFrom!.Value,
|
||
DateTo = model.DateTo!.Value,
|
||
ReportMoneyTransfer = listMoneyTransfers,
|
||
ReportCashWithdrawal = listCashWithdrawals
|
||
});
|
||
|
||
byte[] pdf = System.IO.File.ReadAllBytes("../BankYouBankruptRestAPI/Отчёт_по_счетам.pdf");
|
||
|
||
File.Delete("../BankYouBankruptRestAPI/Отчёт_по_счетам.pdf");
|
||
|
||
_mailKitWorker.SendMailAsync(new()
|
||
{
|
||
MailAddress = model.Email,
|
||
Subject = "Отчёт по счетам",
|
||
Text = $"За период с {model.DateFrom} " +
|
||
$"по {model.DateTo}.",
|
||
File = pdf,
|
||
Role = model.Role,
|
||
TypeDoc = TypeDocEnum.PDF
|
||
});
|
||
|
||
//возврат полученных списков для отображения на вебе
|
||
return new ReportCashierViewModelForHTML
|
||
{
|
||
ReportCashWithdrawal = listCashWithdrawals,
|
||
|
||
ReportMoneyTransfer = listMoneyTransfers
|
||
};
|
||
}
|
||
}
|
||
}
|