подправил отчеты
This commit is contained in:
parent
f186f1dc67
commit
cdf1ca5e9f
@ -20,17 +20,19 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
private readonly IRepairStorage _repairStorage;
|
||||
private readonly IWorkStorage _workStorage;
|
||||
private readonly ICarStorage _carStorage;
|
||||
private readonly IDefectStorage _defectStorage;
|
||||
private readonly AbstractSaveToExcelExecutor _saveToExcel;
|
||||
private readonly AbstractSaveToWordExecutor _saveToWord;
|
||||
private readonly AbstractSaveToPdfExecutor _saveToPdf;
|
||||
|
||||
public ExecutorReportLogic(ITechnicalWorkStorage technicalWorkStorage, IRepairStorage repairStorage, IWorkStorage workStorage, ICarStorage carStorage,
|
||||
public ExecutorReportLogic(ITechnicalWorkStorage technicalWorkStorage, IRepairStorage repairStorage, IWorkStorage workStorage, ICarStorage carStorage, IDefectStorage defectStorage,
|
||||
AbstractSaveToExcelExecutor saveToExcel, AbstractSaveToWordExecutor saveToWord, AbstractSaveToPdfExecutor saveToPdf)
|
||||
{
|
||||
_techWorkStorage = technicalWorkStorage;
|
||||
_repairStorage = repairStorage;
|
||||
_workStorage = workStorage;
|
||||
_carStorage = carStorage;
|
||||
_defectStorage = defectStorage;
|
||||
_saveToExcel = saveToExcel;
|
||||
_saveToWord = saveToWord;
|
||||
_saveToPdf = saveToPdf;
|
||||
@ -42,7 +44,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
|
||||
List<ReportWorksViewModel> allList = new List<ReportWorksViewModel>();
|
||||
|
||||
double price = 0;
|
||||
|
||||
|
||||
var works = _workStorage.GetFullList();
|
||||
List<CarViewModel> cars = new List<CarViewModel>();
|
||||
@ -60,6 +62,7 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
|
||||
foreach(var car in cars)
|
||||
{
|
||||
double price = 0;
|
||||
var rec = new ReportWorksViewModel
|
||||
{
|
||||
CarNumber = car.CarNumber,
|
||||
@ -96,6 +99,9 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
ExecutorId = model.ExecutorId,
|
||||
});
|
||||
|
||||
List<DefectViewModel> defectList = _defectStorage.GetFullList();
|
||||
|
||||
|
||||
foreach(var techWork in techWorkList)
|
||||
{
|
||||
foreach(var car in techWork.TechnicalWorkCars.Values)
|
||||
@ -108,25 +114,31 @@ namespace ServiceStationBusinessLogic.BusinessLogics
|
||||
TechnicalWorkDate = techWork.DateStartWork,
|
||||
TechnicalWorkPrice = techWork.WorkPrice,
|
||||
});
|
||||
List<DefectViewModel> defects = new();
|
||||
foreach (var defect in defectList)
|
||||
{
|
||||
if (defect.DefectCars.ContainsKey(car.Id))
|
||||
{
|
||||
defects.Add(defect);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(var defect in defects)
|
||||
{
|
||||
//if (defect.RepairId.HasValue)
|
||||
//{
|
||||
var repair = _repairStorage.GetElement(new RepairSearchModel { Id = 1 });
|
||||
allList.Add(new ReportCarsViewModel
|
||||
{
|
||||
RepairName = repair.RepairName,
|
||||
RepairStartDate = repair.RepairStartDate,
|
||||
RepairPrice = repair.RepairPrice,
|
||||
});
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
return allList;
|
||||
}
|
||||
|
||||
|
@ -16,11 +16,11 @@ namespace ServiceStationBusinessLogic.OfficePackage
|
||||
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAligment = PdfParagraphAlignmentType.Center });
|
||||
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAligment = PdfParagraphAlignmentType.Center });
|
||||
|
||||
CreateTable(new List<string> { "3cm", "2cm", "2cm", "3cm", "2cm", "3cm", "3cm", "2cm" });
|
||||
CreateTable(new List<string> { "3cm", "2cm", "2cm", "3cm", "2cm", "3cm", "2cm" });
|
||||
|
||||
CreateRow( new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { "Номер машины", "Марка машины", "Тип ТО", "Дата ТО", "Цена ТО", "Название ремонта", "Дата ремонта", "Цена ремонта" },
|
||||
Texts = new List<string> { "Номер машины", "Марка машины", "Тип ТО", "Дата ТО", "Цена ТО", "Название ремонта", "Цена ремонта" },
|
||||
Style = "NormalTitle",
|
||||
ParagraphAligment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
@ -34,8 +34,8 @@ namespace ServiceStationBusinessLogic.OfficePackage
|
||||
}
|
||||
CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = new List<string> { car.CarNumber, car.CarBrand, car.WorkType, car.TechnicalWorkDate.Value.ToShortDateString(), car.TechnicalWorkPrice.ToString(),
|
||||
isRepair is true ? car.RepairName : "", isRepair is true ? car.RepairStartDate.Value.ToShortDateString() : "", isRepair is true ? car.RepairPrice.ToString() : "" },
|
||||
Texts = new List<string> { car.CarNumber, car.CarBrand, car.WorkType, isRepair is true ? "" : car.TechnicalWorkDate.Value.ToShortDateString(), isRepair is true ? "" : car.TechnicalWorkPrice.ToString(),
|
||||
isRepair is true ? car.RepairName : "", isRepair is true ? car.RepairPrice.ToString() : "" },
|
||||
Style = "Normal",
|
||||
ParagraphAligment = PdfParagraphAlignmentType.Center
|
||||
});
|
||||
|
@ -32,7 +32,7 @@ namespace ServiceStationDatabaseImplement.Implements
|
||||
if (string.IsNullOrEmpty(model.RepairName) && !model.GuarantorId.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) return new();
|
||||
using var context = new ServiceStationDatabase();
|
||||
|
||||
if(model.DateTo.HasValue && model.DateTo.HasValue && model.GuarantorId.HasValue)
|
||||
if(model.DateTo.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
return context.Repairs
|
||||
.Include(x => x.SpareParts)
|
||||
|
@ -36,7 +36,7 @@ namespace ServiceStationDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new ServiceStationDatabase();
|
||||
|
||||
if(model.DateTo.HasValue && model.DateTo.HasValue && model.ExecutorId.HasValue)
|
||||
if(model.DateTo.HasValue && model.DateTo.HasValue)
|
||||
{
|
||||
return context.TechnicalWorks
|
||||
.Include(x => x.Cars)
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceStationContracts.BindingModels;
|
||||
using ServiceStationContracts.BusinessLogicsContracts;
|
||||
using ServiceStationContracts.SearchModels;
|
||||
using ServiceStationContracts.ViewModels;
|
||||
using ServiceStationExecutorApp.Models;
|
||||
@ -11,10 +12,12 @@ namespace ServiceStationExecutorApp.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
private readonly IExecutorReportLogic _report;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
public HomeController(ILogger<HomeController> logger, IExecutorReportLogic executorReportLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_report = executorReportLogic;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@ -436,24 +439,21 @@ namespace ServiceStationExecutorApp.Controllers
|
||||
{
|
||||
return RedirectToAction("Enter");
|
||||
}
|
||||
var technicalWork = new TechnicalWorkViewModel
|
||||
return View(Tuple.Create(APIExecutor.GetRequest<List<TechnicalWorkViewModel>>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"),
|
||||
APIExecutor.GetRequest<List<WorkViewModel>>("api/main/getworks")));
|
||||
}
|
||||
[HttpPost]
|
||||
public void BindingTechnicalWorkToWork(int technicalWork, int work)
|
||||
{
|
||||
if (APIExecutor.Executor == null)
|
||||
{
|
||||
Id = 1,
|
||||
WorkType = "type1",
|
||||
WorkPrice = 1000.0,
|
||||
DateStartWork = DateTime.Now,
|
||||
ExecutorId = 1
|
||||
};
|
||||
var work = new WorkViewModel
|
||||
throw new Exception("Авторизироваться не забыли?");
|
||||
}
|
||||
APIExecutor.PostRequest("api/main/updatework", new WorkBindingModel
|
||||
{
|
||||
Id = 1,
|
||||
WorkName = "work1",
|
||||
WorkPrice = 1000.0,
|
||||
Status = ServiceStationDataModels.Enums.WorkStatus.Принята
|
||||
};
|
||||
List<WorkViewModel> works = new();
|
||||
works.Add(work);
|
||||
return View(Tuple.Create(APIExecutor.GetRequest<List<TechnicalWorkViewModel>>($"api/main/gettechnicalworklist?executorId={APIExecutor.Executor.Id}"), works));
|
||||
Id = work,
|
||||
TechnicalWorkId = technicalWork
|
||||
});
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult ListWorkToFile()
|
||||
@ -547,6 +547,65 @@ namespace ServiceStationExecutorApp.Controllers
|
||||
Response.Redirect("GetPdfFile");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public string GetCarsReport(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIExecutor.Executor == null)
|
||||
{
|
||||
throw new Exception("Авторизироваться не забыли?");
|
||||
}
|
||||
List<ReportCarsViewModel> cars;
|
||||
try
|
||||
{
|
||||
cars = _report.GetCars(new ReportExecutorBindingModel
|
||||
{
|
||||
ExecutorId = APIExecutor.Executor.Id,
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания отчета");
|
||||
throw;
|
||||
}
|
||||
string table = "";
|
||||
table += "<h2>Предварительный отчет</h2>";
|
||||
table += "<table class=\"table\">";
|
||||
table += "<thead class=\"thead-dark\">";
|
||||
table += "<tr>";
|
||||
table += "<th scope=\"col\">Номер машины</th>";
|
||||
table += "<th scope=\"col\">Марка машины</th>";
|
||||
table += "<th scope=\"col\">Тип ТО</th>";
|
||||
table += "<th scope=\"col\">Дата ТО</th>";
|
||||
table += "<th scope=\"col\">Цена ТО</th>";
|
||||
table += "<th scope=\"col\">Название ремонта</th>";
|
||||
table += "<th scope=\"col\">Цена ремонта</th>";
|
||||
table += "</tr>";
|
||||
table += "</thead>";
|
||||
foreach(var car in cars)
|
||||
{
|
||||
bool isRepair = true;
|
||||
if (car.RepairPrice == 0)
|
||||
{
|
||||
isRepair = false;
|
||||
}
|
||||
table += "<tbody>";
|
||||
table += "<tr>";
|
||||
table += $"<td>{car.CarNumber}</td>";
|
||||
table += $"<td>{car.CarBrand}</td>";
|
||||
table += $"<td>{car.WorkType}</td>";
|
||||
table += $"<td>{(isRepair ? string.Empty : car.TechnicalWorkDate)}</td>";
|
||||
table += $"<td>{(isRepair ? string.Empty : car.TechnicalWorkPrice)}</td>";
|
||||
table += $"<td>{(isRepair ? car.RepairName : string.Empty)}</td>";
|
||||
table += $"<td>{(isRepair ? car.RepairPrice : string.Empty)}</td>";
|
||||
table += "</tr>";
|
||||
table += "</tbody>";
|
||||
}
|
||||
table += "</table>";
|
||||
return table;
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
|
@ -1,7 +1,23 @@
|
||||
using ServiceStationBusinessLogic.BusinessLogics;
|
||||
using ServiceStationBusinessLogic.OfficePackage;
|
||||
using ServiceStationBusinessLogic.OfficePackage.Implements;
|
||||
using ServiceStationContracts.BusinessLogicsContracts;
|
||||
using ServiceStationContracts.StoragesContracts;
|
||||
using ServiceStationDatabaseImplement.Implements;
|
||||
using ServiceStationExecutorApp;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddTransient<IExecutorReportLogic, ExecutorReportLogic>();
|
||||
builder.Services.AddTransient<IDefectStorage, DefectStorage>();
|
||||
builder.Services.AddTransient<ITechnicalWorkStorage, TechnicalWorkStorage>();
|
||||
builder.Services.AddTransient<IRepairStorage, RepairStorage>();
|
||||
builder.Services.AddTransient<IWorkStorage, WorkStorage>();
|
||||
builder.Services.AddTransient<ICarStorage, CarStorage>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcelExecutor, SaveToExcelExecutor>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdfExecutor, SaveToPdfExecutor>();
|
||||
builder.Services.AddTransient<AbstractSaveToWordExecutor, SaveToWordExecutor>();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
|
@ -11,7 +11,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ServiceStationBusinessLogic\ServiceStationBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\ServiceStationContracts\ServiceStationContracts.csproj" />
|
||||
<ProjectReference Include="..\ServiceStationDatabaseImplement\ServiceStationDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -32,6 +32,29 @@
|
||||
</form>
|
||||
<div>
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4 mx-auto"><button type="button" id="demonstrate" class="btn btn-secondary">Показать</button></div>
|
||||
<div class="col-4 mx-auto"><button type="button" id="view" class="btn btn-secondary">Показать</button></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts{
|
||||
<script>
|
||||
function table() {
|
||||
var dateFrom = $('#dateFrom').val();
|
||||
var dateTo = $('#dateTo').val();
|
||||
if (dateFrom && dateTo) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/GetCarsReport",
|
||||
data: { dateFrom: dateFrom, dateTo: dateTo },
|
||||
success: function (result) {
|
||||
if (result != null) {
|
||||
$('#report').html(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
table();
|
||||
$('#view').on('click', (e) => table());
|
||||
</script>
|
||||
}
|
@ -370,6 +370,20 @@ namespace ServiceStationRestApi.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<WorkViewModel>? GetWorks()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _wlogic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка работ");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<WorkViewModel>? GetWorkList(int guarantorId)
|
||||
{
|
||||
|
@ -18,6 +18,8 @@ builder.Services.AddTransient<IDefectStorage, DefectStorage>();
|
||||
builder.Services.AddTransient<IExecutorStorage, ExecutorStorage>();
|
||||
builder.Services.AddTransient<ITechnicalWorkStorage, TechnicalWorkStorage>();
|
||||
|
||||
builder.Services.AddTransient<IGuarantorStorage, GuarantorStorage>();
|
||||
builder.Services.AddTransient<ISparePartStorage, SparePartStorage>();
|
||||
builder.Services.AddTransient<IRepairStorage, RepairStorage>();
|
||||
builder.Services.AddTransient<IWorkStorage, WorkStorage>();
|
||||
|
||||
@ -27,6 +29,11 @@ builder.Services.AddTransient<IExecutorLogic, ExecutorLogic>();
|
||||
builder.Services.AddTransient<ITechnicalWorkLogic, TechnicalWorkLogic>();
|
||||
builder.Services.AddTransient<IExecutorReportLogic, ExecutorReportLogic>();
|
||||
|
||||
builder.Services.AddTransient<ISparePartLogic, SparePartLogic>();
|
||||
builder.Services.AddTransient<IGuarantorLogic, GuarantorLogic>();
|
||||
builder.Services.AddTransient<IWorkLogic, WorkLogic>();
|
||||
builder.Services.AddTransient<IRepairLogic, RepairLogic>();
|
||||
|
||||
builder.Services.AddTransient<AbstractSaveToExcelExecutor, SaveToExcelExecutor>();
|
||||
builder.Services.AddTransient<AbstractSaveToWordExecutor, SaveToWordExecutor>();
|
||||
builder.Services.AddTransient<AbstractSaveToPdfExecutor, SaveToPdfExecutor>();
|
||||
|
Loading…
Reference in New Issue
Block a user