2023-05-25 22:31:46 +04:00
|
|
|
|
using BlacksmithWorkshopBusinessLogic.OfficePackage;
|
|
|
|
|
using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using BlacksmithWorkshopBusinessLogic.OfficePackage.Implements;
|
|
|
|
|
using CarServiceContracts.BindingModels;
|
2023-04-07 19:57:21 +04:00
|
|
|
|
using CarServiceContracts.BusinessLogicsContracts;
|
|
|
|
|
using CarServiceContracts.StorageContracts;
|
|
|
|
|
using CarServiceContracts.ViewModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace CarServiceBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ReportLogic : IReportLogic
|
|
|
|
|
{
|
2023-04-08 14:02:29 +04:00
|
|
|
|
private readonly ILogger _logger;
|
2023-04-07 19:57:21 +04:00
|
|
|
|
private readonly IWorkStorage _workStorage;
|
2023-04-08 14:01:54 +04:00
|
|
|
|
private readonly IWorkPaymentStorage _workPaymentStorage;
|
2023-05-25 22:31:46 +04:00
|
|
|
|
private readonly AbstractSaveToWord _saveToWord;
|
2023-05-25 23:14:32 +04:00
|
|
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
2023-05-25 23:49:07 +04:00
|
|
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
2023-05-25 22:31:46 +04:00
|
|
|
|
|
2023-05-25 23:49:07 +04:00
|
|
|
|
public ReportLogic(ILogger<ReportLogic> logger, IWorkStorage workStorage, IWorkPaymentStorage workPaymentStorage, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel, AbstractSaveToPdf saveToPdf)
|
2023-04-07 19:57:21 +04:00
|
|
|
|
{
|
2023-04-08 14:02:29 +04:00
|
|
|
|
_logger = logger;
|
2023-04-07 19:57:21 +04:00
|
|
|
|
_workStorage = workStorage;
|
2023-04-08 14:01:54 +04:00
|
|
|
|
_workPaymentStorage = workPaymentStorage;
|
2023-05-25 22:31:46 +04:00
|
|
|
|
_saveToWord = saveToWord;
|
2023-05-25 23:14:32 +04:00
|
|
|
|
_saveToExcel = saveToExcel;
|
2023-05-25 23:49:07 +04:00
|
|
|
|
_saveToPdf = saveToPdf;
|
2023-04-07 19:57:21 +04:00
|
|
|
|
}
|
|
|
|
|
public List<ReportWorkWithRequestsViewModel> GetRequestsByWorks(ReportBindingModel model)
|
|
|
|
|
{
|
2023-04-08 14:02:29 +04:00
|
|
|
|
_logger.LogInformation("Reading requests by works");
|
2023-04-07 19:57:21 +04:00
|
|
|
|
return _workStorage.GetWorksWithRequest(new() { SelectedWorksIds = model.SelectedWorks });
|
|
|
|
|
}
|
2023-04-08 14:01:54 +04:00
|
|
|
|
public List<ReportWorksWithPaymentsViewModel> GetPayments(ReportBindingModel model)
|
|
|
|
|
{
|
2023-04-08 14:02:29 +04:00
|
|
|
|
_logger.LogInformation("Reading payments by works in requests");
|
2023-05-22 22:44:51 +04:00
|
|
|
|
return _workPaymentStorage.GetPaymentsByWorks(new() { DateFrom = model.DateFrom, DateTo = model.DateTo });
|
2023-04-08 14:01:54 +04:00
|
|
|
|
}
|
2023-05-25 23:14:32 +04:00
|
|
|
|
public void SaveRequestsToWordFile(ReportBindingModel model)
|
2023-04-07 19:57:21 +04:00
|
|
|
|
{
|
2023-05-25 22:31:46 +04:00
|
|
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заявок",
|
|
|
|
|
WorksWithRequests = GetRequestsByWorks(model)
|
|
|
|
|
});
|
2023-04-07 19:57:21 +04:00
|
|
|
|
}
|
2023-05-25 23:14:32 +04:00
|
|
|
|
public void SaveRequestsToExcelFile(ReportBindingModel model)
|
2023-04-07 19:57:21 +04:00
|
|
|
|
{
|
2023-05-25 23:14:32 +04:00
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список заявок",
|
|
|
|
|
WorksWithRequests = GetRequestsByWorks(model)
|
|
|
|
|
});
|
2023-04-07 19:57:21 +04:00
|
|
|
|
}
|
2023-05-25 23:49:07 +04:00
|
|
|
|
public void SavePaymentsToPdfFile(ReportBindingModel model)
|
2023-04-07 19:57:21 +04:00
|
|
|
|
{
|
2023-05-25 23:49:07 +04:00
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список оплат",
|
|
|
|
|
DateFrom = model.DateFrom!.Value,
|
|
|
|
|
DateTo = model.DateTo!.Value,
|
|
|
|
|
Payments = GetPayments(model)
|
|
|
|
|
});
|
2023-04-07 19:57:21 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|