2024-05-28 22:40:54 +04:00
|
|
|
|
using ServiceStationBusinessLogic.OfficePackage;
|
|
|
|
|
using ServiceStationBusinessLogic.OfficePackage.HelperModels;
|
|
|
|
|
using ServiceStationContracts.BindingModels;
|
2024-05-01 15:02:44 +04:00
|
|
|
|
using ServiceStationContracts.BusinessLogicsContracts;
|
|
|
|
|
using ServiceStationContracts.SearchModels;
|
|
|
|
|
using ServiceStationContracts.StoragesContracts;
|
|
|
|
|
using ServiceStationContracts.ViewModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ServiceStationBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class GuarantorReportLogic : IGuarantorReportLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IDefectStorage _defectStorage;
|
|
|
|
|
private readonly ISparePartStorage _sparepartStorage;
|
|
|
|
|
private readonly IRepairStorage _repairStorage;
|
|
|
|
|
private readonly ITechnicalWorkStorage _techWorkStorage;
|
2024-05-28 22:40:54 +04:00
|
|
|
|
private readonly AbstractSaveToExcelGuarantor _saveToExcel;
|
|
|
|
|
private readonly AbstractSaveToWordGuarantor _saveToWord;
|
|
|
|
|
private readonly AbstractSaveToPdfGuarantor _saveToPdf;
|
2024-05-01 15:02:44 +04:00
|
|
|
|
|
2024-05-28 22:40:54 +04:00
|
|
|
|
public GuarantorReportLogic(IDefectStorage defectStorage, ISparePartStorage sparepartStorage, IRepairStorage repairStorage, ITechnicalWorkStorage techWorkStorage, AbstractSaveToExcelGuarantor saveToExcel, AbstractSaveToPdfGuarantor saveToPdf, AbstractSaveToWordGuarantor saveToWord)
|
2024-05-01 15:02:44 +04:00
|
|
|
|
{
|
|
|
|
|
_defectStorage = defectStorage;
|
|
|
|
|
_sparepartStorage = sparepartStorage;
|
|
|
|
|
_repairStorage = repairStorage;
|
|
|
|
|
_techWorkStorage = techWorkStorage;
|
2024-05-28 22:40:54 +04:00
|
|
|
|
_saveToExcel = saveToExcel;
|
|
|
|
|
_saveToWord = saveToWord;
|
|
|
|
|
_saveToPdf = saveToPdf;
|
2024-05-01 15:02:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ReportDefectsViewModel> GetDefects(List<int> Ids)
|
|
|
|
|
{
|
|
|
|
|
if (Ids == null) return new List<ReportDefectsViewModel>();
|
|
|
|
|
|
|
|
|
|
List<ReportDefectsViewModel> allList = new List<ReportDefectsViewModel>();
|
|
|
|
|
|
2024-05-28 22:40:54 +04:00
|
|
|
|
double price = 0;
|
|
|
|
|
|
2024-05-01 15:02:44 +04:00
|
|
|
|
var defects = _defectStorage.GetFullList();
|
|
|
|
|
List<SparePartViewModel> spareparts = new List<SparePartViewModel>();
|
|
|
|
|
foreach (var sparepartId in Ids)
|
|
|
|
|
{
|
|
|
|
|
var sparepart = _sparepartStorage.GetElement(new SparePartSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = sparepartId,
|
|
|
|
|
});
|
|
|
|
|
if (sparepart != null)
|
|
|
|
|
{
|
|
|
|
|
spareparts.Add(sparepart);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var sparepart in spareparts)
|
|
|
|
|
{
|
|
|
|
|
var rec = new ReportDefectsViewModel
|
|
|
|
|
{
|
|
|
|
|
SparePartName = sparepart.SparePartName,
|
|
|
|
|
DefectsInfo = new List<(string, double)>()
|
|
|
|
|
};
|
|
|
|
|
foreach (var defect in defects)
|
|
|
|
|
{
|
|
|
|
|
var repair = _repairStorage.GetElement(new RepairSearchModel
|
|
|
|
|
{
|
|
|
|
|
Id = defect.RepairId,
|
|
|
|
|
});
|
|
|
|
|
foreach (var repSpareParts in repair.RepairSpareParts.Values)
|
|
|
|
|
{
|
|
|
|
|
if (repSpareParts.Id == sparepart.Id)
|
|
|
|
|
{
|
|
|
|
|
rec.DefectsInfo.Add(new(defect.DefectType, defect.DefectPrice));
|
2024-05-28 22:40:54 +04:00
|
|
|
|
price += defect.DefectPrice;
|
2024-05-01 15:02:44 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-28 22:40:54 +04:00
|
|
|
|
rec.FullPrice = price;
|
2024-05-01 15:02:44 +04:00
|
|
|
|
allList.Add(rec);
|
|
|
|
|
}
|
|
|
|
|
return allList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ReportSparePartsViewModel> GetSpareParts(ReportGuarantorBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
List<ReportSparePartsViewModel> allList = new List<ReportSparePartsViewModel>();
|
|
|
|
|
|
|
|
|
|
List<RepairViewModel> repairList = _repairStorage.GetFilteredList(new RepairSearchModel
|
|
|
|
|
{
|
|
|
|
|
DateFrom = model.DateFrom,
|
|
|
|
|
DateTo = model.DateTo,
|
2024-05-28 22:40:54 +04:00
|
|
|
|
GuarantorId = model.GuarantorId,
|
2024-05-01 15:02:44 +04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
foreach (var repair in repairList)
|
|
|
|
|
{
|
|
|
|
|
foreach (var sparepart in repair.RepairSpareParts.Values)
|
|
|
|
|
{
|
|
|
|
|
allList.Add(new ReportSparePartsViewModel
|
|
|
|
|
{
|
|
|
|
|
SparePartName = sparepart.SparePartName,
|
|
|
|
|
SparePartPrice = sparepart.SparePartPrice,
|
|
|
|
|
RepairName = repair.RepairName,
|
|
|
|
|
RepairStartDate = repair.RepairStartDate,
|
|
|
|
|
RepairPrice = repair.RepairPrice,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<TechnicalWorkViewModel> techWorkList = _techWorkStorage.GetFilteredList(new TechnicalWorkSearchModel
|
|
|
|
|
{
|
|
|
|
|
DateFrom = model.DateFrom,
|
|
|
|
|
DateTo = model.DateTo,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
foreach (var techWork in techWorkList)
|
|
|
|
|
{
|
|
|
|
|
allList.Add(new ReportSparePartsViewModel
|
|
|
|
|
{
|
|
|
|
|
WorkType = techWork.WorkType,
|
|
|
|
|
TechnicalWorkDate = techWork.DateStartWork,
|
|
|
|
|
TechnicalWorkPrice = techWork.WorkPrice,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return allList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveDefectsToWordFile(ReportGuarantorBindingModel model)
|
|
|
|
|
{
|
2024-05-28 22:40:54 +04:00
|
|
|
|
_saveToWord.CreateDoc(new WordInfoGuarantor
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список неисправностей",
|
|
|
|
|
DefectsBySparePart = GetDefects(model.Ids!)
|
|
|
|
|
});
|
2024-05-01 15:02:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveDefectsToExcelFile(ReportGuarantorBindingModel model)
|
|
|
|
|
{
|
2024-05-28 22:40:54 +04:00
|
|
|
|
_saveToExcel.CreateReport(new ExcelInfoGuarantor
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список работ",
|
|
|
|
|
DefectsBySparePart = GetDefects(model.Ids!)
|
|
|
|
|
});
|
2024-05-01 15:02:44 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveSparePartsToPdfFile(ReportGuarantorBindingModel model)
|
|
|
|
|
{
|
2024-05-28 22:40:54 +04:00
|
|
|
|
if (model.DateFrom == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Дата начала не задана");
|
|
|
|
|
}
|
|
|
|
|
if (model.DateTo == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Дата окончания не задана");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_saveToPdf.CreateDoc(new PdfInfoGuarantor
|
|
|
|
|
{
|
|
|
|
|
FileName = model.FileName,
|
|
|
|
|
Title = "Список запчастей",
|
|
|
|
|
DateFrom = model.DateFrom.Value,
|
|
|
|
|
DateTo = model.DateTo.Value,
|
|
|
|
|
SpareParts = GetSpareParts(model)
|
|
|
|
|
});
|
2024-05-01 15:02:44 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|