2024-05-27 21:44:16 +04:00
|
|
|
|
using ServiceStationBusinessLogic.OfficePackage;
|
|
|
|
|
using ServiceStationBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using ServiceStationContracts.BindingModels;
|
2024-04-30 23:27:38 +04:00
|
|
|
|
using ServiceStationContracts.BusinessLogicsContracts;
|
2024-05-01 00:14:31 +04:00
|
|
|
|
using ServiceStationContracts.SearchModels;
|
|
|
|
|
using ServiceStationContracts.StoragesContracts;
|
2024-04-30 23:27:38 +04:00
|
|
|
|
using ServiceStationContracts.ViewModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ServiceStationBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class ExecutorReportLogic : IExecutorReportLogic
|
|
|
|
|
{
|
2024-05-01 00:14:31 +04:00
|
|
|
|
|
|
|
|
|
private readonly ITechnicalWorkStorage _techWorkStorage;
|
|
|
|
|
private readonly IRepairStorage _repairStorage;
|
2024-05-01 01:14:12 +04:00
|
|
|
|
private readonly IWorkStorage _workStorage;
|
|
|
|
|
private readonly ICarStorage _carStorage;
|
2024-05-27 21:44:16 +04:00
|
|
|
|
private readonly AbstractSaveToExcelExecutor _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWordExecutor _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdfExecutor _saveToPdf;
|
2024-05-01 01:14:12 +04:00
|
|
|
|
|
2024-05-27 21:44:16 +04:00
|
|
|
|
public ExecutorReportLogic(ITechnicalWorkStorage technicalWorkStorage, IRepairStorage repairStorage, IWorkStorage workStorage, ICarStorage carStorage,
|
|
|
|
|
AbstractSaveToExcelExecutor saveToExcel, AbstractSaveToWordExecutor saveToWord, AbstractSaveToPdfExecutor saveToPdf)
|
2024-05-01 01:14:12 +04:00
|
|
|
|
{
|
|
|
|
|
_techWorkStorage = technicalWorkStorage;
|
|
|
|
|
_repairStorage = repairStorage;
|
|
|
|
|
_workStorage = workStorage;
|
|
|
|
|
_carStorage = carStorage;
|
2024-05-27 21:44:16 +04:00
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
2024-05-01 01:14:12 +04:00
|
|
|
|
}
|
2024-05-01 00:14:31 +04:00
|
|
|
|
|
2024-04-30 23:27:38 +04:00
|
|
|
|
public List<ReportWorksViewModel> GetWorks(List<int> Ids)
|
|
|
|
|
{
|
2024-05-01 01:14:12 +04:00
|
|
|
|
if(Ids == null) return new List<ReportWorksViewModel>();
|
|
|
|
|
|
|
|
|
|
List<ReportWorksViewModel> allList = new List<ReportWorksViewModel>();
|
|
|
|
|
|
2024-05-27 21:44:16 +04:00
|
|
|
|
double price = 0;
|
|
|
|
|
|
2024-05-01 01:14:12 +04:00
|
|
|
|
var works = _workStorage.GetFullList();
|
|
|
|
|
List<CarViewModel> cars = new List<CarViewModel>();
|
|
|
|
|
foreach (var carId in Ids)
|
|
|
|
|
{
|
|
|
|
|
var car = _carStorage.GetElement(new CarSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = carId,
|
|
|
|
|
});
|
|
|
|
|
if(car != null)
|
|
|
|
|
{
|
|
|
|
|
cars.Add(car);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach(var car in cars)
|
|
|
|
|
{
|
|
|
|
|
var rec = new ReportWorksViewModel
|
|
|
|
|
{
|
|
|
|
|
CarNumber = car.CarNumber,
|
|
|
|
|
WorksInfo = new List<(string, double)>()
|
|
|
|
|
};
|
|
|
|
|
foreach(var work in works)
|
|
|
|
|
{
|
|
|
|
|
var techWork = _techWorkStorage.GetElement(new TechnicalWorkSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = work.TechnicalWorkId,
|
|
|
|
|
});
|
|
|
|
|
foreach(var techCars in techWork.TechnicalWorkCars.Values)
|
|
|
|
|
{
|
|
|
|
|
if(techCars.Id == car.Id)
|
|
|
|
|
{
|
|
|
|
|
rec.WorksInfo.Add(new(work.WorkName, work.WorkPrice));
|
2024-05-27 21:44:16 +04:00
|
|
|
|
price += work.WorkPrice;
|
2024-05-01 01:14:12 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-27 21:44:16 +04:00
|
|
|
|
rec.FullPrice = price;
|
2024-05-01 01:14:12 +04:00
|
|
|
|
allList.Add(rec);
|
|
|
|
|
}
|
|
|
|
|
return allList;
|
2024-04-30 23:27:38 +04:00
|
|
|
|
}
|
2024-05-01 14:20:56 +04:00
|
|
|
|
public List<ReportCarsViewModel> GetCars(ReportExecutorBindingModel model)
|
2024-04-30 23:27:38 +04:00
|
|
|
|
{
|
2024-05-01 00:14:31 +04:00
|
|
|
|
List<ReportCarsViewModel> allList = new List<ReportCarsViewModel>();
|
|
|
|
|
|
|
|
|
|
List<TechnicalWorkViewModel> techWorkList = _techWorkStorage.GetFilteredList(new TechnicalWorkSearchModel
|
|
|
|
|
{
|
|
|
|
|
DateFrom = model.DateFrom,
|
|
|
|
|
DateTo = model.DateTo,
|
2024-05-27 21:44:16 +04:00
|
|
|
|
ExecutorId = model.ExecutorId,
|
2024-05-01 00:14:31 +04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
foreach(var techWork in techWorkList)
|
|
|
|
|
{
|
|
|
|
|
foreach(var car in techWork.TechnicalWorkCars.Values)
|
|
|
|
|
{
|
|
|
|
|
allList.Add(new ReportCarsViewModel
|
|
|
|
|
{
|
|
|
|
|
CarNumber = car.CarNumber,
|
|
|
|
|
CarBrand = car.CarBrand,
|
|
|
|
|
WorkType = techWork.WorkType,
|
|
|
|
|
TechnicalWorkDate = techWork.DateStartWork,
|
|
|
|
|
TechnicalWorkPrice = techWork.WorkPrice,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-01 01:14:12 +04:00
|
|
|
|
|
|
|
|
|
List<RepairViewModel> repairList = _repairStorage.GetFilteredList(new RepairSearchModel
|
|
|
|
|
{
|
|
|
|
|
DateFrom = model.DateFrom,
|
|
|
|
|
DateTo = model.DateTo,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
foreach(var repair in repairList)
|
|
|
|
|
{
|
|
|
|
|
allList.Add(new ReportCarsViewModel
|
|
|
|
|
{
|
|
|
|
|
RepairName = repair.RepairName,
|
|
|
|
|
RepairStartDate = repair.RepairStartDate,
|
|
|
|
|
RepairPrice = repair.RepairPrice,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 00:14:31 +04:00
|
|
|
|
return allList;
|
2024-04-30 23:27:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 14:20:56 +04:00
|
|
|
|
public void SaveWorkByCarsWordFile(ReportExecutorBindingModel model)
|
2024-04-30 23:27:38 +04:00
|
|
|
|
{
|
2024-05-27 21:44:16 +04:00
|
|
|
|
_saveToWord.CreateDoc(new WordInfoExecutor
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список работ",
|
|
|
|
|
WorksByCar = GetWorks(model.Ids!)
|
|
|
|
|
});
|
2024-04-30 23:27:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 14:20:56 +04:00
|
|
|
|
public void SaveTechWorkAndRepairsByCarsToPdfFile(ReportExecutorBindingModel model)
|
2024-04-30 23:27:38 +04:00
|
|
|
|
{
|
2024-05-27 21:44:16 +04:00
|
|
|
|
if(model.DateFrom == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Дата начала не задана");
|
|
|
|
|
}
|
|
|
|
|
if(model.DateTo == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Дата окончания не задана");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfoExecutor
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список машин",
|
|
|
|
|
DateFrom = model.DateFrom.Value,
|
|
|
|
|
DateTo = model.DateTo.Value,
|
|
|
|
|
Cars = GetCars(model)
|
|
|
|
|
});
|
2024-04-30 23:27:38 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-01 14:20:56 +04:00
|
|
|
|
public void SaveWorkByCarsToExcelFile(ReportExecutorBindingModel model)
|
2024-04-30 23:27:38 +04:00
|
|
|
|
{
|
2024-05-27 21:44:16 +04:00
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfoExecutor
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список работ",
|
|
|
|
|
WorksByCar = GetWorks(model.Ids!)
|
|
|
|
|
});
|
2024-04-30 23:27:38 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|