Compare commits

...

3 Commits

22 changed files with 119 additions and 65 deletions

View File

@ -1,4 +1,5 @@
using FactoryBusinessLogic.OfficePackage;
using DocumentFormat.OpenXml.Office2010.Excel;
using FactoryBusinessLogic.OfficePackage;
using FactoryBusinessLogic.OfficePackage.HelperModels;
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts;
@ -23,14 +24,17 @@ namespace FactoryBusinessLogic.BusinessLogics
_saveToPdf = saveToPdf;
_saveToWord = saveToWord;
}
public List<PlanProductionProductReportViewModel> GetProductsByPlanProduction(List<PlanProductionSearchModel> plans)
public List<PlanProductionProductReportViewModel> GetProductsByPlanProduction(List<int> ids)
{
List<int> ids = plans.Select(x =>(int)x.Id).ToList();
return _planProduction.GetProducts(ids);
}
public List<WorkpieceTimeReportViewModel> GetWorkpieces(ClientSearchModel client, ReportBindingModel model)
{
return _workpieceStorage.GetWorkpiecesByPeriod(client, model);
var products = _planProduction.GetProducts(ids);
if (products.Any(x => x.Products == null))
{
foreach (var item in products)
{
item.Products ??= new();
}
}
return products;
}
public void SaveWorkpiecesToPdfFile(ClientSearchModel client, ReportBindingModel model)
{
@ -40,7 +44,6 @@ namespace FactoryBusinessLogic.BusinessLogics
Title = "Список заготовок",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Workpieces = GetWorkpieces(client, model)
});
}
public void SaveProductsToExcelFile(ReportBindingModel model, List<int> plans)

View File

@ -114,28 +114,8 @@ namespace FactoryBusinessLogic.OfficePackage
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
var phaseNames = workpiece.ExecutionPhases.Select(x => x.ExecutionPhaseName).ToList();
var machineNames = workpiece.Machines.Select(x => x.MachineName).ToList();
if (phaseNames.Count != machineNames.Count)
{
if (phaseNames.Count > machineNames.Count)
{
var diff = phaseNames.Count - machineNames.Count;
for (int i = 0; i < diff; i++)
{
machineNames.Add(string.Empty);
}
}
else
{
var diff = machineNames.Count - phaseNames.Count;
for (int i = 0; i < diff; i++)
{
phaseNames.Add(string.Empty);
}
}
}
var tupleList = machineNames.Zip(phaseNames, Tuple.Create);
foreach (var tuple in tupleList)
{

View File

@ -11,7 +11,7 @@ namespace FactoryContracts.BindingModels
public string ImplementerFIO { get; set; } = string.Empty;
public ExecutionPhaseStatus Status { get; set; } = ExecutionPhaseStatus.Неизвестен;
public int ClientId { get; set; }
public int PlanProductionId { get; set; }
public int? PlanProductionId { get; set; }
}

View File

@ -6,8 +6,7 @@ namespace FactoryContracts.BusinessLogicsContracts
{
public interface IWorkerReportLogic
{
List<PlanProductionProductReportViewModel> GetProductsByPlanProduction(List<PlanProductionSearchModel> plans);
List<WorkpieceTimeReportViewModel> GetWorkpieces(ClientSearchModel client, ReportBindingModel model);
List<PlanProductionProductReportViewModel> GetProductsByPlanProduction(List<int> plans);
void SaveProudctsToWordFile(ReportBindingModel model, List<int> plans);
void SaveProductsToExcelFile(ReportBindingModel model, List<int> plans);
void SaveWorkpiecesToPdfFile(ClientSearchModel client, ReportBindingModel model);

View File

@ -4,7 +4,8 @@
{
public int? Id { get; set; }
public int? ClientId { get; set; }
public int? WorkpieceId { get; set; }
public string? ExecutionPhaseName { get; set; }
public string? ExecutionPhaseName { get; set; }
}
}

View File

@ -4,6 +4,7 @@
{
public int? Id { get; set; }
public string? MachineName { get; set; }
public int WorkpieceId { get; set; }
public int ClientId { get; set; }
}
}

View File

@ -9,7 +9,6 @@ namespace FactoryContracts.StoragesContracts
List<WorkpieceViewModel> GetFullList();
List<WorkpieceViewModel> GetFilteredList(WorkpieceSearchModel model);
List<WorkpieceTimeReportViewModel> GetWorkpiecesByPeriod(ClientSearchModel client, ReportBindingModel model);
WorkpieceViewModel? GetElement(WorkpieceSearchModel model);

View File

@ -9,7 +9,7 @@ namespace FactoryContracts.ViewModels
public int Id { get; set; }
public int ClientId { get; set; }
public int PlanProductionId { get; set; }
public int? PlanProductionId { get; set; }
[DisplayName("ФИО исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty;

View File

@ -3,7 +3,7 @@
public class WorkpieceTimeReportViewModel
{
public string WorkpieceName { get; set; } = string.Empty;
public List<ExecutionPhaseViewModel> ExecutionPhases { get; set; } = new();
public List<MachineViewModel> Machines { get; set; } = new();
public List<string> ExecutionPhases { get; set; } = new();
public List<string> Machines { get; set; } = new();
}
}

View File

@ -9,6 +9,6 @@ namespace FactoryDataModels.Models
string ImplementerFIO { get; }
ExecutionPhaseStatus Status { get; }
int ClientId { get; }
int PlanProductionId { get; }
int? PlanProductionId { get; }
}
}

View File

@ -23,7 +23,10 @@ namespace FactoryDatabaseImplement.Implements
{
using var context = new FactoryDatabase();
return context.ExecutionPhases
if (model.WorkpieceId.HasValue)
return context.ExecutionPhases.Where(x => x.PlanProductionId.HasValue).Include(x => x.PlanProduction).Where(x => x.PlanProduction.Workpieces.FirstOrDefault(y => y.WorkpieceId == model.WorkpieceId) != null).Select(x => x.GetViewModel).ToList();
return context.ExecutionPhases
.Include(x => x.Client)
.Include(x => x.PlanProduction)
.Where(x => x.ExecutionPhaseName.Contains(model.ExecutionPhaseName) || (x.ClientId == model.ClientId))

View File

@ -23,7 +23,10 @@ namespace FactoryDatabaseImplement.Implements
public List<MachineViewModel> GetFilteredList(MachineSearchModel model)
{
using var context = new FactoryDatabase();
if (!string.IsNullOrEmpty(model.MachineName))
if (model.WorkpieceId.HasValue)
return context.Machines.Include(x => x.PlanProductions).Where(x => x.PlanProduction.Workpieces.FirstOrDefault(y => y.WorkpieceId == model.WorkpieceId) != null).Select(x => x.GetViewModel).ToList();
if (!string.IsNullOrEmpty(model.MachineName))
{
return context.Machines
.Include(x => x.Client)

View File

@ -133,6 +133,7 @@ namespace FactoryDatabaseImplement.Implements
ProductionName = plan.ProductionName,
Products = context.WorkpieceProducts
.Include(x => x.Product)
.Include(x => x.Workpiece)
.Where(product => plan.Id == product.Product.Id)
.Select(x => x.Product.GetViewModel)
.ToList()

View File

@ -9,19 +9,6 @@ namespace FactoryDatabaseImplement.Implements
{
public class WorkpieceStorage : IWorkpieceStorage
{
public List<WorkpieceTimeReportViewModel> GetWorkpiecesByPeriod(ClientSearchModel client, ReportBindingModel model)
{
using var context = new FactoryDatabase();
return context.Workpieces
.Include(x => x.Client)
// not sure if its true
.Where(x => x.ClientId == client.Id && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => new WorkpieceTimeReportViewModel()
{
WorkpieceName = x.WorkpieceName,
})
.ToList();
}
public List<WorkpieceViewModel> GetFullList()
{
using var context = new FactoryDatabase();

View File

@ -15,8 +15,8 @@ namespace FactoryDatabaseImplement.Models
public virtual Client Client { get; private set; }
[Required]
public int PlanProductionId { get; private set; }
public virtual PlanProduction PlanProduction { get; private set; } = null!;
public int? PlanProductionId { get; private set; }
public virtual PlanProduction? PlanProduction { get; private set; } = null!;
[Required]
public string ExecutionPhaseName { get; private set; } = string.Empty;

View File

@ -1,6 +1,8 @@
using DocumentFormat.OpenXml.Office2010.Excel;
using FactoryBusinessLogic.BusinessLogics;
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts;
using FactoryContracts.SearchModels;
using FactoryContracts.ViewModels;
using FactoryDatabaseImplement.Models;
using FactoryDataModels.Enums;
@ -229,7 +231,29 @@ namespace FactoryWorkerApp.Controllers
return View();
}
[HttpGet]
[HttpGet]
public IActionResult GetByPlans()
{
if (!IsLoggedIn)
{
return Redirect("Index");
}
ViewBag.plans = _logic.GetPlanProductions(Client.user!.Id);
return View();
}
[HttpGet]
public IActionResult ProductProductionReport(List<int> plans)
{
if (!IsLoggedIn)
{
return Redirect("Index");
}
var report = _workerReportLogic.GetProductsByPlanProduction(plans);
return View(report);
}
[HttpGet]
public IActionResult WorkpieceTimeChoose()
{
if (!IsLoggedIn)
@ -253,7 +277,7 @@ namespace FactoryWorkerApp.Controllers
HttpContext.Session.SetString("StartDate", startDate.ToString());
HttpContext.Session.SetString("EndDate", endDate.ToString());
return RedirectToAction("DetailTimeReport");
return RedirectToAction("WorkpieceTimeReport");
}
[HttpGet]
@ -264,12 +288,12 @@ namespace FactoryWorkerApp.Controllers
var startDate = DateTime.Parse(startDateStr);
var endDate = DateTime.Parse(endDateStr).AddDays(1);
//var values = _logic.GetTimeReport(startDate, endDate, UserId);
var values = _logic.GetWorkpieceTime(startDate, endDate, Client.user.Id);
ViewBag.StartDate = startDate;
ViewBag.EndDate = endDate;
return View();
return View(values);
}

View File

@ -3,6 +3,8 @@ using FactoryBusinessLogic.BusinessLogics;
using FactoryContracts.StoragesContracts;
using FactoryDatabaseImplement.Implements;
using FactoryWorkerApp;
using FactoryBusinessLogic.OfficePackage;
using FactoryBusinessLogic.OfficePackage.Implements;
var builder = WebApplication.CreateBuilder(args);
@ -19,6 +21,7 @@ builder.Services.AddTransient<IExecutionPhaseStorage, ExecutionPhaseStorage>();
builder.Services.AddTransient<IMachineStorage, MachineStorage>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<IWorkerReportLogic, WorkerReportLogic>();
builder.Services.AddTransient<IWorkpieceLogic, WorkpieceLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<IPlanProductionLogic, PlanProductionLogic>();
@ -26,6 +29,10 @@ builder.Services.AddTransient<IExecutionPhaseLogic, ExecutionPhaseLogic>();
builder.Services.AddTransient<IMachineLogic, MachineLogic>();
builder.Services.AddTransient<WorkerLogic>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);

View File

@ -0,0 +1,21 @@
@using FactoryContracts.ViewModels
@model List<MachinePeriodReportViewModel>
@{
ViewData["Title"] = "Подготовка к созданию отчета по планам";
}
<div class="text-center">
<h1 class="display-4">Список изделий по планам производства</h1>
</div>
<form asp-controller="Home" asp-action="ProductProductionReport" method="get">
<div class="row">Выберите планы</div>
<div class="row">
<div class="col-4">Планы:</div>
<select name="plans" class="form-control border border-dark rounded" multiple size="5" asp-items="@(new SelectList(ViewBag.plans, "Id", "ProductionName"))">
</select>
</div>
<button type="submit" class="btn btn-primary">Создать отчёт</button>
</form>

View File

@ -33,7 +33,7 @@
<ul>
@foreach (var plan in planProduction.Products)
{
<li>@plan</li>
<li>@plan.ProductName</li>
}
</ul>
</td>

View File

@ -5,7 +5,7 @@
<div class="text-center">
<h1 class="display-4">Выберите тип отчета</h1>
<div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ProductProductionReport">Отчет изделий по производствам</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="GetByPlans">Отчет изделий по производствам</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="WorkpieceDateReport">Отчет по заготовкам по датам</a>
</div>
</div>

View File

@ -64,7 +64,7 @@
var formData = $('#TimeReportWeb').serialize();
$.post('/Home/TimeReportWeb', formData, function (response) {
window.location.href = '/Home/DetailTimeReport';
window.location.href = '/Home/WorkpieceTimeReport';
}).fail(function () {
alert('Произошла ошибка при создании отчета.');
});

View File

@ -1,4 +1,5 @@
using DocumentFormat.OpenXml.ExtendedProperties;
using FactoryBusinessLogic.BusinessLogics;
using FactoryBusinessLogic.OfficePackage;
using FactoryContracts.BindingModels;
using FactoryContracts.BusinessLogicsContracts;
@ -15,10 +16,11 @@ namespace FactoryWorkerApp
private readonly IPlanProductionLogic _planProductionLogic;
private readonly IProductLogic _productLogic;
private readonly IExecutionPhaseLogic _executionPhaseLogic;
private readonly IMachineLogic _machineLogic;
private readonly IWorkerReportLogic _workerReport;
public WorkerLogic(ILogger<WorkerLogic> logger, IClientLogic clientLogic, IWorkpieceLogic workpieceLogic, IPlanProductionLogic planProductionLogic, IExecutionPhaseLogic executionPhaseLogic, IProductLogic productLogic, IWorkerReportLogic reportLogic)
public WorkerLogic(ILogger<WorkerLogic> logger, IClientLogic clientLogic, IWorkpieceLogic workpieceLogic, IPlanProductionLogic planProductionLogic, IExecutionPhaseLogic executionPhaseLogic, IProductLogic productLogic, IWorkerReportLogic reportLogic, IMachineLogic machineLogic)
{
_logger = logger;
_clientLogic = clientLogic;
@ -27,6 +29,7 @@ namespace FactoryWorkerApp
_executionPhaseLogic = executionPhaseLogic;
_productLogic = productLogic;
_workerReport = reportLogic;
_machineLogic = machineLogic;
}
public ClientViewModel? Login(string login, string password)
@ -111,6 +114,28 @@ namespace FactoryWorkerApp
{
return _productLogic.ReadList(null);
}
public List<WorkpieceTimeReportViewModel>? GetWorkpieceTime(DateTime? startDate, DateTime? endDate, int ClientId)
{
var workpieces = _workpieceLogic.ReadList(new() { DateFrom = startDate, DateTo = endDate, ClientId = ClientId });
if (workpieces == null)
return new();
List<WorkpieceTimeReportViewModel> detailTimeReports = new List<WorkpieceTimeReportViewModel>();
foreach (var i in workpieces)
{
WorkpieceTimeReportViewModel report = new();
var workpiece = _workpieceLogic.ReadElement(new() { Id = i.Id });
report.WorkpieceName = workpiece!.WorkpieceName;
var phases = _executionPhaseLogic.ReadList(new() { WorkpieceId = i.Id });
if (phases != null)
report.ExecutionPhases = phases.Select(w => w.ExecutionPhaseName).ToList();
var machines = _machineLogic.ReadList(new() { WorkpieceId = i.Id });
if (machines != null)
report.Machines = machines.Select(w => w.MachineName).ToList();
detailTimeReports.Add(report);
}
return detailTimeReports;
}
}
}