71 lines
2.4 KiB
C#
71 lines
2.4 KiB
C#
using CarServiceBusinessLogic.OfficePackage;
|
|
using CarServiceBusinessLogic.OfficePackage.HelperModels;
|
|
using CarServiceBusinessLogic.OfficePackage.Implements;
|
|
using CarServiceContracts.BindingModels;
|
|
using CarServiceContracts.BusinessLogicsContracts;
|
|
using CarServiceContracts.StorageContracts;
|
|
using CarServiceContracts.ViewModels;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace CarServiceBusinessLogic.BusinessLogics
|
|
{
|
|
public class ReportLogic : IReportLogic
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly IWorkStorage _workStorage;
|
|
private readonly IWorkPaymentStorage _workPaymentStorage;
|
|
private readonly AbstractSaveToWord _saveToWord;
|
|
private readonly AbstractSaveToExcel _saveToExcel;
|
|
private readonly AbstractSaveToPdf _saveToPdf;
|
|
|
|
public ReportLogic(ILogger<ReportLogic> logger, IWorkStorage workStorage, IWorkPaymentStorage workPaymentStorage, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel, AbstractSaveToPdf saveToPdf)
|
|
{
|
|
_logger = logger;
|
|
_workStorage = workStorage;
|
|
_workPaymentStorage = workPaymentStorage;
|
|
_saveToWord = saveToWord;
|
|
_saveToExcel = saveToExcel;
|
|
_saveToPdf = saveToPdf;
|
|
}
|
|
public List<ReportWorkWithRequestsViewModel> GetRequestsByWorks(ReportBindingModel model)
|
|
{
|
|
_logger.LogInformation("Reading requests by works");
|
|
return _workStorage.GetWorksWithRequest(new() { SelectedWorksIds = model.SelectedWorks });
|
|
}
|
|
public List<ReportWorksWithPaymentsViewModel> GetPayments(ReportBindingModel model)
|
|
{
|
|
_logger.LogInformation("Reading payments by works in requests");
|
|
return _workPaymentStorage.GetPaymentsByWorks(new() { DateFrom = model.DateFrom, DateTo = model.DateTo });
|
|
}
|
|
public void SaveRequestsToWordFile(ReportBindingModel model)
|
|
{
|
|
_saveToWord.CreateDoc(new WordInfo
|
|
{
|
|
FileName = model.FileName,
|
|
Title = "Список заявок",
|
|
WorksWithRequests = GetRequestsByWorks(model)
|
|
});
|
|
}
|
|
public void SaveRequestsToExcelFile(ReportBindingModel model)
|
|
{
|
|
_saveToExcel.CreateReport(new ExcelInfo
|
|
{
|
|
FileName = model.FileName,
|
|
Title = "Список заявок",
|
|
WorksWithRequests = GetRequestsByWorks(model)
|
|
});
|
|
}
|
|
public void SavePaymentsToPdfFile(ReportBindingModel model)
|
|
{
|
|
_saveToPdf.CreateDoc(new PdfInfo
|
|
{
|
|
FileName = model.FileName,
|
|
Title = "Список оплат",
|
|
DateFrom = model.DateFrom!.Value,
|
|
DateTo = model.DateTo!.Value,
|
|
Payments = GetPayments(model)
|
|
});
|
|
}
|
|
}
|
|
}
|