diff --git a/FaKrosnoApi/Controllers/CustomerOrdersController.cs b/FaKrosnoApi/Controllers/CustomerOrdersController.cs index 39fa4a3..ab7cd69 100644 --- a/FaKrosnoApi/Controllers/CustomerOrdersController.cs +++ b/FaKrosnoApi/Controllers/CustomerOrdersController.cs @@ -22,5 +22,19 @@ namespace FaKrosnoApi.Controllers CustomerOrderDto? scheduleOrder = await service.GetByOrderNumber(customerOrderNumber); return scheduleOrder != null ? Ok(scheduleOrder) : NotFound(); } + + [HttpGet("by-co-number")] + public async Task> GetByCoNumber([FromQuery] string customerOrderNumber) + { + CustomerOrderDto? scheduleOrder = await service.GetByCoNumber(customerOrderNumber); + return scheduleOrder != null ? Ok(scheduleOrder) : NotFound(); + } + + [HttpGet("items-by-co-number")] + public async Task> GetItemsByCoNumber([FromQuery] string customerOrderNumber) + { + var customerOrderLineItems = await service.GetItemsByCoNumber(customerOrderNumber); + return customerOrderLineItems != null ? Ok(customerOrderLineItems) : NotFound(); + } } } diff --git a/FaKrosnoApi/Controllers/HangfireJobsController.cs b/FaKrosnoApi/Controllers/HangfireJobsController.cs index d2e754e..b016636 100644 --- a/FaKrosnoApi/Controllers/HangfireJobsController.cs +++ b/FaKrosnoApi/Controllers/HangfireJobsController.cs @@ -17,154 +17,154 @@ public class HangfireJobsController( ITaskSchedulerService service) : Controller { - public async Task>> GetJobsToRun() - { - IList jobsToRun = new List(); - - using (IStorageConnection? connection = jobStorage.GetConnection()) - { - IList? recurringJobs = connection.GetRecurringJobs(); - IList? taskSchedulers = (await service.GetTaskSchedulers()).ToList(); - - foreach (var recurringJob in recurringJobs) - { - TaskSchedulerDto? taskScheduler = taskSchedulers?.FirstOrDefault(ts => ts.Name == recurringJob.Id); - - if (taskScheduler != null) - { - jobsToRun.Add(new JobModel(recurringJob.Id, recurringJob.Cron, taskScheduler.Path, - recurringJob.LastExecution, recurringJob.NextExecution, recurringJob.Job)); - } - } - } - - return Ok(jobsToRun); - } - - [HttpPost("run")] - public async Task RunJobs() - { - var jobsToRun = (await GetJobsToRun()).Value?.ToList(); - - if (jobsToRun == null || jobsToRun.Count == 0) - { - return BadRequest("Nie udało się pobrać zadań do uruchomienia."); - } - - foreach (var job in jobsToRun) - { - if (!string.IsNullOrEmpty(job.Path)) - { - recurringJobManager.AddOrUpdate(job.JobId, () => RunConsoleApplication(job.Path), job.Cron, - new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); - } - } - - return Ok("Zadania zostały zaplanowane do uruchamiania zgodnie z ich CRON."); - } - - [HttpPost("add")] - public async Task AddTask([FromBody] TaskSchedulerDto taskSchedulerDto) - { - var taskScheduler = new OrdersManagementDataModel.Entities.TaskScheduler - { - Name = taskSchedulerDto.Name, - Path = taskSchedulerDto.Path, - CronOptions = taskSchedulerDto.CronOptions, - CreateDate = DateTime.UtcNow - }; - - int result = await service.AddTaskScheduler(taskSchedulerDto); - - if (result == 0) - { - return BadRequest("Nie udało się dodać zadania."); - } - - recurringJobManager.AddOrUpdate(taskScheduler.Name, () => RunConsoleApplication(taskScheduler.Path), - taskScheduler.CronOptions, new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); - - return Ok("Zadanie zostało dodane."); - } - - [HttpPost("delete")] - public async Task DeleteTask([FromBody] TaskSchedulerDto taskSchedulerDto) - { - int result = await service.DeleteTaskScheduler(taskSchedulerDto.RowPointer); - - if (result == 0) - { - return BadRequest("Nie udało się usunąć zadania."); - } - - recurringJobManager.RemoveIfExists(taskSchedulerDto.Name); - - return Ok("Zadanie zostało usunięte."); - } - - [HttpGet] - public async Task>> GetTasks() - { - var tasks = await service.GetTaskSchedulers(); - - foreach (TaskSchedulerDto taskSchedulerDto in tasks) - { - var job = GetJob(taskSchedulerDto.Name); - taskSchedulerDto.LastExecution = job?.LastExecution; - taskSchedulerDto.NextExecution = job?.NextExecution; - } - - return Ok(tasks); - } - - [HttpGet("by-name")] - public async Task> GetTaskSchedulerByTaskName([FromQuery] string name) - { - var taskSchedulerDto = await service.GetTaskSchedulerByTaskName(name); - - if (taskSchedulerDto == null) return NotFound(); - - var job = GetJob(taskSchedulerDto.Name); - taskSchedulerDto.LastExecution = job?.LastExecution; - taskSchedulerDto.NextExecution = job?.NextExecution; - - return Ok(taskSchedulerDto); - } - - private RecurringJobDto? GetJob(string jobId) - { - using IStorageConnection? connection = jobStorage.GetConnection(); - IList? recurringJobs = connection.GetRecurringJobs(); - return recurringJobs.FirstOrDefault(x => x.Id == jobId); - } - - public void RunConsoleApplication(string pathToApp) - { - try - { - var process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = pathToApp, - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true, - WorkingDirectory = Path.GetDirectoryName(pathToApp) - } - }; - process.Start(); - string output = process.StandardOutput.ReadToEnd(); - string error = process.StandardError.ReadToEnd(); - process.WaitForExit(); - - Console.WriteLine($"Output: {output}"); - Console.WriteLine($"Error: {error}"); - } - catch (Exception ex) - { - Console.WriteLine($"Error executing console application: {ex.Message}"); - } - } + // public async Task>> GetJobsToRun() + // { + // IList jobsToRun = new List(); + // + // using (IStorageConnection? connection = jobStorage.GetConnection()) + // { + // IList? recurringJobs = connection.GetRecurringJobs(); + // IList? taskSchedulers = (await service.GetTaskSchedulers()).ToList(); + // + // foreach (var recurringJob in recurringJobs) + // { + // TaskSchedulerDto? taskScheduler = taskSchedulers?.FirstOrDefault(ts => ts.Name == recurringJob.Id); + // + // if (taskScheduler != null) + // { + // jobsToRun.Add(new JobModel(recurringJob.Id, recurringJob.Cron, taskScheduler.Path, + // recurringJob.LastExecution, recurringJob.NextExecution, recurringJob.Job)); + // } + // } + // } + // + // return Ok(jobsToRun); + // } + // + // [HttpPost("run")] + // public async Task RunJobs() + // { + // var jobsToRun = (await GetJobsToRun()).Value?.ToList(); + // + // if (jobsToRun == null || jobsToRun.Count == 0) + // { + // return BadRequest("Nie udało się pobrać zadań do uruchomienia."); + // } + // + // foreach (var job in jobsToRun) + // { + // if (!string.IsNullOrEmpty(job.Path)) + // { + // recurringJobManager.AddOrUpdate(job.JobId, () => RunConsoleApplication(job.Path), job.Cron, + // new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); + // } + // } + // + // return Ok("Zadania zostały zaplanowane do uruchamiania zgodnie z ich CRON."); + // } + // + // [HttpPost("add")] + // public async Task AddTask([FromBody] TaskSchedulerDto taskSchedulerDto) + // { + // var taskScheduler = new OrdersManagementDataModel.Entities.TaskScheduler + // { + // Name = taskSchedulerDto.Name, + // Path = taskSchedulerDto.Path, + // CronOptions = taskSchedulerDto.CronOptions, + // CreateDate = DateTime.UtcNow + // }; + // + // int result = await service.AddTaskScheduler(taskSchedulerDto); + // + // if (result == 0) + // { + // return BadRequest("Nie udało się dodać zadania."); + // } + // + // recurringJobManager.AddOrUpdate(taskScheduler.Name, () => RunConsoleApplication(taskScheduler.Path), + // taskScheduler.CronOptions, new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); + // + // return Ok("Zadanie zostało dodane."); + // } + // + // [HttpPost("delete")] + // public async Task DeleteTask([FromBody] TaskSchedulerDto taskSchedulerDto) + // { + // int result = await service.DeleteTaskScheduler(taskSchedulerDto.RowPointer); + // + // if (result == 0) + // { + // return BadRequest("Nie udało się usunąć zadania."); + // } + // + // recurringJobManager.RemoveIfExists(taskSchedulerDto.Name); + // + // return Ok("Zadanie zostało usunięte."); + // } + // + // [HttpGet] + // public async Task>> GetTasks() + // { + // var tasks = await service.GetTaskSchedulers(); + // + // foreach (TaskSchedulerDto taskSchedulerDto in tasks) + // { + // var job = GetJob(taskSchedulerDto.Name); + // taskSchedulerDto.LastExecution = job?.LastExecution; + // taskSchedulerDto.NextExecution = job?.NextExecution; + // } + // + // return Ok(tasks); + // } + // + // [HttpGet("by-name")] + // public async Task> GetTaskSchedulerByTaskName([FromQuery] string name) + // { + // var taskSchedulerDto = await service.GetTaskSchedulerByTaskName(name); + // + // if (taskSchedulerDto == null) return NotFound(); + // + // var job = GetJob(taskSchedulerDto.Name); + // taskSchedulerDto.LastExecution = job?.LastExecution; + // taskSchedulerDto.NextExecution = job?.NextExecution; + // + // return Ok(taskSchedulerDto); + // } + // + // private RecurringJobDto? GetJob(string jobId) + // { + // using IStorageConnection? connection = jobStorage.GetConnection(); + // IList? recurringJobs = connection.GetRecurringJobs(); + // return recurringJobs.FirstOrDefault(x => x.Id == jobId); + // } + // + // public void RunConsoleApplication(string pathToApp) + // { + // try + // { + // var process = new Process + // { + // StartInfo = new ProcessStartInfo + // { + // FileName = pathToApp, + // UseShellExecute = false, + // RedirectStandardOutput = true, + // RedirectStandardError = true, + // CreateNoWindow = true, + // WorkingDirectory = Path.GetDirectoryName(pathToApp) + // } + // }; + // process.Start(); + // string output = process.StandardOutput.ReadToEnd(); + // string error = process.StandardError.ReadToEnd(); + // process.WaitForExit(); + // + // Console.WriteLine($"Output: {output}"); + // Console.WriteLine($"Error: {error}"); + // } + // catch (Exception ex) + // { + // Console.WriteLine($"Error executing console application: {ex.Message}"); + // } + // } } \ No newline at end of file diff --git a/FaKrosnoApi/Controllers/ItemCustController.cs b/FaKrosnoApi/Controllers/ItemCustController.cs new file mode 100644 index 0000000..f5c6ddd --- /dev/null +++ b/FaKrosnoApi/Controllers/ItemCustController.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Mvc; +using SytelineSaAppEfDataModel.Dtos; +using SytelineSaAppEfDataModel.Services; + +namespace FaKrosnoApi.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class ItemCustController(IItemCustService service) : Controller +{ + public async Task> GetItem([FromQuery] string itemNumber, [FromQuery] string customerNumber) + { + ItemCustDto item = await service.GetItem(itemNumber, customerNumber); + return item != null ? Ok(item) : NotFound(); + } +} \ No newline at end of file diff --git a/FaKrosnoApi/Controllers/WzRowMeyleController.cs b/FaKrosnoApi/Controllers/WzRowMeyleController.cs index db04ee2..6ee43f5 100644 --- a/FaKrosnoApi/Controllers/WzRowMeyleController.cs +++ b/FaKrosnoApi/Controllers/WzRowMeyleController.cs @@ -26,4 +26,23 @@ public class WzRowMeyleController(IWzRowMeyleService service) : Controller await service.CreateRows(rows); return CreatedAtAction(nameof(GetAll), new { count = rows.Count() }, rows); } + + [HttpGet("by-wz-header-id")] + public async Task>> GetByWzHeaderId(Guid wzHeaderId) + { + IEnumerable wzRows = await service.GetByWzHeaderId(wzHeaderId); + return Ok(wzRows); + } + + [HttpPut] + public async Task UpdateRows([FromBody] IEnumerable rows) + { + if (rows == null || !rows.Any()) + { + return BadRequest("No rows provided."); + } + + await service.UpdateRows(rows); + return NoContent(); + } } \ No newline at end of file diff --git a/FaKrosnoApi/Program.cs b/FaKrosnoApi/Program.cs index 309804f..b7288ad 100644 --- a/FaKrosnoApi/Program.cs +++ b/FaKrosnoApi/Program.cs @@ -69,19 +69,19 @@ builder.Services.AddOpenApiDocument(config => config.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer")); }); -builder.Services.AddHangfire(config => config - .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) - .UseSimpleAssemblyNameTypeSerializer() - .UseRecommendedSerializerSettings() - .UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions - { - CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), - SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), - QueuePollInterval = TimeSpan.Zero, - UseRecommendedIsolationLevel = true, - DisableGlobalLocks = true - })); -builder.Services.AddHangfireServer(); +// builder.Services.AddHangfire(config => config +// .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) +// .UseSimpleAssemblyNameTypeSerializer() +// .UseRecommendedSerializerSettings() +// .UseSqlServerStorage(builder.Configuration.GetConnectionString("OrdersManagementConnection"), new SqlServerStorageOptions +// { +// CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), +// SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), +// QueuePollInterval = TimeSpan.Zero, +// UseRecommendedIsolationLevel = true, +// DisableGlobalLocks = true +// })); +// builder.Services.AddHangfireServer(); builder.Services.AddAutoMapper(typeof(FaKrosnoMappingProfile), typeof(SytelineSaAppMappingProfile), typeof(OrdersManagementMappingProfile)); @@ -104,6 +104,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddHostedService(); @@ -119,6 +120,6 @@ app.UseAuthorization(); app.MapControllers(); -app.UseHangfireDashboard(); +// app.UseHangfireDashboard(); app.Run(); diff --git a/OrdersManagement/Components/Pages/Warehouse.razor b/OrdersManagement/Components/Pages/Warehouse.razor index baacf4e..c9a85de 100644 --- a/OrdersManagement/Components/Pages/Warehouse.razor +++ b/OrdersManagement/Components/Pages/Warehouse.razor @@ -9,6 +9,7 @@ @using Syncfusion.Blazor.Navigations @inject WarehouseService WarehouseService +@inject NavigationManager NavigationManager
@@ -30,12 +31,10 @@ AllowSorting="true" AllowSelection="true" TValue="MaterialTransactionDto" - DataSource="@_materialTransactions" + DataSource="@_dataSource" EnableAdaptiveUI="true"> - - @@ -48,7 +47,6 @@ - @* *@ } @@ -60,10 +58,11 @@ @code { private SfGrid _grid; - IEnumerable _clients = new List(); - IEnumerable _materialTransactions = new List(); + private IEnumerable _clients = new List(); + private IEnumerable _materialTransactions = new List(); + private IEnumerable _dataSource = new List(); - WzClientDto? _selectedClient; + private WzClientDto? _selectedClient; bool _isVisible = false; @@ -83,6 +82,7 @@ _selectedClient = args.ItemData; _isVisible = true; _materialTransactions = await WarehouseService.GetAllClientWzsAsync(_selectedClient.CustomerNumber, _selectedClient.CustomerSequence ?? 0); + _dataSource = _materialTransactions.GroupBy(x => x.MTGroupNum).Select(x => x.First()).ToList(); } else { @@ -110,17 +110,29 @@ { case "MEYLE": IList rows = new List(); - foreach (MaterialTransactionDto materialTransactionDto in selectedRecords) + IList materialTransactions = _materialTransactions.Where(x => selectedRecords.Any(y => y.MTGroupNum == x.MTGroupNum)).ToList(); + + foreach (MaterialTransactionDto materialTransactionDto in materialTransactions) { + CustomerOrderDto customerOrder = await WarehouseService.GetCustomerOrder(materialTransactionDto.RefNum ?? string.Empty); + ItemCustDto item = await WarehouseService.GetItem(materialTransactionDto.Item ?? string.Empty, customerOrder.CustNum); + rows.Add(new WzRowMeyleDto { ID = Guid.NewGuid(), Quantity = Math.Abs((int?)materialTransactionDto.Qty ?? 0), - //ItemNumber = + ItemNumber = item.CustItem, + OrderNumber = customerOrder.CustPo, + WzNumber = materialTransactionDto.MTGroupNum ?? string.Empty, + FK_Header = wzHeader.ID }); } + + await WarehouseService.CreateWzRowsMeyleAsync(rows); break; } + + NavigationManager.NavigateTo("/Warehouse/PackList/" + wzHeader.ID); } } } \ No newline at end of file diff --git a/OrdersManagement/Components/Pages/WarehousePackList.razor b/OrdersManagement/Components/Pages/WarehousePackList.razor index 89ae813..b0b72a5 100644 --- a/OrdersManagement/Components/Pages/WarehousePackList.razor +++ b/OrdersManagement/Components/Pages/WarehousePackList.razor @@ -1,7 +1,104 @@ -@page "/Warehouse/PackList" +@page "/Warehouse/PackList/{WzHeader:guid}" +@using Syncfusion.Blazor.Cards +@using Syncfusion.Blazor.Grids +@using SytelineSaAppEfDataModel.Dtos +@using Syncfusion.Blazor.Navigations -

WarehousePackList

+@inject WarehouseService WarehouseService + +
+ + +

Packing List

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + FA Krosno Manager © @(DateTime.Now.Year) + +
+
@code { + [Parameter] public Guid WzHeader { get; set; } + + private SfGrid _grid; + private IEnumerable _wzRowsMeyle { get; set; } = new List(); + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + _wzRowsMeyle = await WarehouseService.GetWzRowsByWzHeaderId(WzHeader); + StateHasChanged(); + } + } + private async Task SaveChanges() + { + await _grid.EndEditAsync(); + } + + private async Task OnBatchSave(BeforeBatchSaveArgs obj) + { + var changes = obj.BatchChanges; + var changedRecords = changes.ChangedRecords; + + await WarehouseService.UpdateWzRowsMeyleAsync(changedRecords); + + _wzRowsMeyle = await WarehouseService.GetWzRowsByWzHeaderId(WzHeader); + StateHasChanged(); + await _grid.Refresh(); + } + + private async Task ExportXls() + { + await _grid.ExportToExcelAsync(); + } } \ No newline at end of file diff --git a/OrdersManagement/Services/WarehouseService.cs b/OrdersManagement/Services/WarehouseService.cs index 63d841e..0998fe8 100644 --- a/OrdersManagement/Services/WarehouseService.cs +++ b/OrdersManagement/Services/WarehouseService.cs @@ -31,13 +31,53 @@ public class WarehouseService(IHttpClientFactory httpClientFactory) } } - public async Task CreateWzRowMeyleAsync(IEnumerable wzRowMeyles) + public async Task CreateWzRowsMeyleAsync(IEnumerable wzRowMeyles) { - var response = await _httpClient.PostAsJsonAsync("api/WzRowMeyle", wzRowMeyles); - response.EnsureSuccessStatusCode(); - if (response.StatusCode != System.Net.HttpStatusCode.Created) + if (wzRowMeyles == null || !wzRowMeyles.Any()) { - throw new Exception("Failed to create WzRowMeyle"); + throw new ArgumentException("No rows provided to create."); } + + var response = await _httpClient.PostAsJsonAsync("api/WzRowMeyle", wzRowMeyles); + if (!response.IsSuccessStatusCode) + { + var errorContent = await response.Content.ReadAsStringAsync(); + throw new HttpRequestException($"Failed to create WzRowMeyle: {response.StatusCode}, Content: {errorContent}"); + } + + } + + public async Task GetCustomerOrder(string customerOrderNumber) + { + var response = await _httpClient.GetAsync( + $"api/CustomerOrders/by-co-number/?customerOrderNumber={customerOrderNumber}"); + response.EnsureSuccessStatusCode(); + return await response.Content.ReadFromJsonAsync(); + } + + public async Task GetItem(string itemNumber, string customerNumber) + { + var response = await _httpClient.GetAsync( + $"api/ItemCust?itemNumber={itemNumber}&customerNumber={customerNumber}"); + response.EnsureSuccessStatusCode(); + return await response.Content.ReadFromJsonAsync(); + } + + public async Task> GetWzRowsByWzHeaderId(Guid wzHeaderId) + { + var response = await _httpClient.GetAsync($"api/WzRowMeyle/by-wz-header-id?wzHeaderId={wzHeaderId}"); + response.EnsureSuccessStatusCode(); + return await response.Content.ReadFromJsonAsync>(); + } + + public async Task UpdateWzRowsMeyleAsync(IEnumerable wzRowsMeyle) + { + if (wzRowsMeyle == null || !wzRowsMeyle.Any()) + { + throw new ArgumentException("No rows provided to update."); + } + + var response = await _httpClient.PutAsJsonAsync("api/WzRowMeyle", wzRowsMeyle); + response.EnsureSuccessStatusCode(); } } \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Dtos/ItemCustDto.cs b/SytelineSaAppEfDataModel/Dtos/ItemCustDto.cs new file mode 100644 index 0000000..5b479e6 --- /dev/null +++ b/SytelineSaAppEfDataModel/Dtos/ItemCustDto.cs @@ -0,0 +1,30 @@ +namespace SytelineSaAppEfDataModel.Dtos; + +public class ItemCustDto +{ + public string Item { get; set; } + public string CustNum { get; set; } + public int CustItemSeq { get; set; } + public string CustItem { get; set; } + public int? PurchYtd { get; set; } + public decimal? OrderYtd { get; set; } + public decimal? ShipYtd { get; set; } + public decimal? OrderPtd { get; set; } + public string UM { get; set; } + public int? DuePeriod { get; set; } + public byte NoteExistsFlag { get; set; } + public DateTime RecordDate { get; set; } + public Guid RowPointer { get; set; } + public string CreatedBy { get; set; } + public string UpdatedBy { get; set; } + public DateTime CreateDate { get; set; } + public byte InWorkflow { get; set; } + public int? Rank { get; set; } + public string EndUser { get; set; } + public string Uf_FKR_CustItem2 { get; set; } + public string Uf_KOD_EAN13 { get; set; } + public string Uf_Paleta_BROSE { get; set; } + public string Uf_Pojemnik_BROSE { get; set; } + public string Uf_Paleta_BROSE_Pokrywa { get; set; } + public string Uf_RewizjaRysunku { get; set; } +} \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Dtos/WzRowMeyleDto.cs b/SytelineSaAppEfDataModel/Dtos/WzRowMeyleDto.cs index 69f4b3a..c53f11c 100644 --- a/SytelineSaAppEfDataModel/Dtos/WzRowMeyleDto.cs +++ b/SytelineSaAppEfDataModel/Dtos/WzRowMeyleDto.cs @@ -9,5 +9,5 @@ public class WzRowMeyleDto public int? Quantity { get; set; } public int? PalletNumber { get; set; } public string WzNumber { get; set; } - public string PartNumber { get; set; } + public string? PartNumber { get; set; } } \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Entities/ItemCust.cs b/SytelineSaAppEfDataModel/Entities/ItemCust.cs new file mode 100644 index 0000000..bc897ea --- /dev/null +++ b/SytelineSaAppEfDataModel/Entities/ItemCust.cs @@ -0,0 +1,30 @@ +namespace SytelineSaAppEfDataModel.Entities; + +public class ItemCust +{ + public string Item { get; set; } + public string CustNum { get; set; } + public int CustItemSeq { get; set; } + public string CustItem { get; set; } + public int? PurchYtd { get; set; } + public decimal? OrderYtd { get; set; } + public decimal? ShipYtd { get; set; } + public decimal? OrderPtd { get; set; } + public string UM { get; set; } + public int? DuePeriod { get; set; } + public byte NoteExistsFlag { get; set; } + public DateTime RecordDate { get; set; } + public Guid RowPointer { get; set; } + public string CreatedBy { get; set; } + public string UpdatedBy { get; set; } + public DateTime CreateDate { get; set; } + public byte InWorkflow { get; set; } + public int? Rank { get; set; } + public string EndUser { get; set; } + public string Uf_FKR_CustItem2 { get; set; } + public string Uf_KOD_EAN13 { get; set; } + public string Uf_Paleta_BROSE { get; set; } + public string Uf_Pojemnik_BROSE { get; set; } + public string Uf_Paleta_BROSE_Pokrywa { get; set; } + public string Uf_RewizjaRysunku { get; set; } +} \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Entities/WzRowMeyle.cs b/SytelineSaAppEfDataModel/Entities/WzRowMeyle.cs index 044d965..dfeaffd 100644 --- a/SytelineSaAppEfDataModel/Entities/WzRowMeyle.cs +++ b/SytelineSaAppEfDataModel/Entities/WzRowMeyle.cs @@ -9,7 +9,7 @@ public class WzRowMeyle public int? Quantity { get; set; } public int? PalletNumber { get; set; } public string WzNumber { get; set; } - public string PartNumber { get; set; } + public string? PartNumber { get; set; } // Navigation property public WzHeader Header { get; set; } diff --git a/SytelineSaAppEfDataModel/MappingProfile.cs b/SytelineSaAppEfDataModel/MappingProfile.cs index 9063798..3c86434 100644 --- a/SytelineSaAppEfDataModel/MappingProfile.cs +++ b/SytelineSaAppEfDataModel/MappingProfile.cs @@ -23,6 +23,7 @@ namespace SytelineSaAppEfDataModel CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); + CreateMap().ReverseMap(); } } } diff --git a/SytelineSaAppEfDataModel/Services/CustomerOrderService.cs b/SytelineSaAppEfDataModel/Services/CustomerOrderService.cs index 616ec7b..246325b 100644 --- a/SytelineSaAppEfDataModel/Services/CustomerOrderService.cs +++ b/SytelineSaAppEfDataModel/Services/CustomerOrderService.cs @@ -1,9 +1,4 @@ using AutoMapper; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using SytelineSaAppEfDataModel.Dtos; @@ -22,7 +17,7 @@ namespace SytelineSaAppEfDataModel.Services .Where(x => x.RowPointer == orderNumber) .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); if (customerOrder == null) return null; - + customerOrder.CustomerOrderLines = await context.CustomerOrderLines .Where(x => x.CoNum == customerOrder.CoNum) .Select(x => mapper.Map(x)).ToListAsync(); @@ -33,14 +28,50 @@ namespace SytelineSaAppEfDataModel.Services .Where(x => x.CoNum == customerOrder.CoNum && x.CoLine == customerOrderLine.CoLine) .Select(x => mapper.Map(x)).ToListAsync(); } - + IList ediCustomerOrderTranslates = await context.EdiCustomerOrderTranslates .Where(x => x.CoCoNum == customerOrder.CoNum) .Select(x => mapper.Map(x)).ToListAsync(); - + customerOrder.EdiCustomerOrderTranslates = ediCustomerOrderTranslates; return customerOrder; } + + public async Task GetByCoNumber(string orderNumber) + { + CustomerOrderDto? customerOrder = await context.CustomerOrders + .Where(x => x.CoNum == orderNumber) + .Select(x => mapper.Map(x)).FirstOrDefaultAsync(); + if (customerOrder == null) return null; + + customerOrder.CustomerOrderLines = await context.CustomerOrderLines + .Where(x => x.CoNum == customerOrder.CoNum) + .Select(x => mapper.Map(x)).ToListAsync(); + + foreach (CustomerOrderLineDto customerOrderLine in customerOrder.CustomerOrderLines) + { + customerOrderLine.CustomerOrderLineItems = await context.CustomerOrderLineItems + .Where(x => x.CoNum == customerOrder.CoNum && x.CoLine == customerOrderLine.CoLine) + .Select(x => mapper.Map(x)).ToListAsync(); + } + + IList ediCustomerOrderTranslates = await context.EdiCustomerOrderTranslates + .Where(x => x.CoCoNum == customerOrder.CoNum) + .Select(x => mapper.Map(x)).ToListAsync(); + + customerOrder.EdiCustomerOrderTranslates = ediCustomerOrderTranslates; + + return customerOrder; + } + + public async Task?> GetItemsByCoNumber(string customerOrderNumber) + { + List customerOrderLineItems = await context.CustomerOrderLineItems + .Where(x => x.CoNum == customerOrderNumber) + .Select(x => mapper.Map(x)).ToListAsync(); + + return customerOrderLineItems; + } } -} +} \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/ICustomerOrderService.cs b/SytelineSaAppEfDataModel/Services/ICustomerOrderService.cs index 5db216a..55ca634 100644 --- a/SytelineSaAppEfDataModel/Services/ICustomerOrderService.cs +++ b/SytelineSaAppEfDataModel/Services/ICustomerOrderService.cs @@ -11,5 +11,7 @@ namespace SytelineSaAppEfDataModel.Services { Task> GetAll(); Task GetByOrderNumber(Guid orderNumber); + Task GetByCoNumber(string orderNumber); + Task?> GetItemsByCoNumber(string customerOrderNumber); } } diff --git a/SytelineSaAppEfDataModel/Services/IItemCustService.cs b/SytelineSaAppEfDataModel/Services/IItemCustService.cs new file mode 100644 index 0000000..37dc032 --- /dev/null +++ b/SytelineSaAppEfDataModel/Services/IItemCustService.cs @@ -0,0 +1,8 @@ +using SytelineSaAppEfDataModel.Dtos; + +namespace SytelineSaAppEfDataModel.Services; + +public interface IItemCustService +{ + Task GetItem(string itemNumber, string customerNumber); +} \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/IWzRowMeyleService.cs b/SytelineSaAppEfDataModel/Services/IWzRowMeyleService.cs index 65d1dc5..47ff117 100644 --- a/SytelineSaAppEfDataModel/Services/IWzRowMeyleService.cs +++ b/SytelineSaAppEfDataModel/Services/IWzRowMeyleService.cs @@ -6,4 +6,6 @@ public interface IWzRowMeyleService { Task> GetAll(); Task CreateRows(IEnumerable rows); + Task> GetByWzHeaderId(Guid wzHeaderId); + Task UpdateRows(IEnumerable rows); } \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/ItemCustService.cs b/SytelineSaAppEfDataModel/Services/ItemCustService.cs new file mode 100644 index 0000000..9877609 --- /dev/null +++ b/SytelineSaAppEfDataModel/Services/ItemCustService.cs @@ -0,0 +1,17 @@ +using AutoMapper; +using SytelineSaAppEfDataModel.Dtos; + +namespace SytelineSaAppEfDataModel.Services; + +public class ItemCustService(SytelineSaAppDbContext context, IMapper mapper) : IItemCustService +{ + public Task GetItem(string itemNumber, string customerNumber) + { + var item = context.ItemCusts + .FirstOrDefault(x => x.Item == itemNumber && x.CustNum == customerNumber); + + return item == null + ? Task.FromResult(null) + : Task.FromResult(mapper.Map(item)); + } +} \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/WzRowMeyleService.cs b/SytelineSaAppEfDataModel/Services/WzRowMeyleService.cs index 4684adf..a0f11e3 100644 --- a/SytelineSaAppEfDataModel/Services/WzRowMeyleService.cs +++ b/SytelineSaAppEfDataModel/Services/WzRowMeyleService.cs @@ -18,4 +18,19 @@ public class WzRowMeyleService(SytelineSaAppDbContext context, IMapper mapper) : await context.WzRowsMeyle.AddRangeAsync(entities); await context.SaveChangesAsync(); } + + public async Task> GetByWzHeaderId(Guid wzHeaderId) + { + return await context.WzRowsMeyle + .Where(x => x.FK_Header == wzHeaderId) + .Select(x => mapper.Map(x)) + .ToListAsync(); + } + + public async Task UpdateRows(IEnumerable rows) + { + var entities = mapper.Map>(rows); + context.WzRowsMeyle.UpdateRange(entities); + await context.SaveChangesAsync(); + } } \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/SytelineSaAppDbContext.cs b/SytelineSaAppEfDataModel/SytelineSaAppDbContext.cs index 15ff01f..557aaf4 100644 --- a/SytelineSaAppEfDataModel/SytelineSaAppDbContext.cs +++ b/SytelineSaAppEfDataModel/SytelineSaAppDbContext.cs @@ -25,6 +25,8 @@ namespace SytelineSaAppEfDataModel public DbSet WzHeaders { get; set; } public DbSet WzRowsMeyle { get; set; } + + public DbSet ItemCusts { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var configuration = new ConfigurationBuilder() @@ -990,6 +992,149 @@ namespace SytelineSaAppEfDataModel .HasForeignKey(e => e.FK_Header) .HasConstraintName("wz_rows_meyle_wz_header_ID_fk"); }); + + modelBuilder.Entity(entity => + { + entity.ToTable("itemcust"); + + entity.HasKey(e => new { e.Item, e.CustNum, e.CustItemSeq }); + + entity.Property(e => e.Item) + .HasColumnName("item") + .HasMaxLength(60) + .IsRequired(); + + entity.Property(e => e.CustNum) + .HasColumnName("cust_num") + .HasMaxLength(14) + .IsRequired(); + + entity.Property(e => e.CustItemSeq) + .HasColumnName("cust_item_seq") + .HasColumnType("int") + .HasDefaultValueSql("1"); + + entity.Property(e => e.CustItem) + .HasColumnName("cust_item") + .HasMaxLength(60) + .IsRequired(false); + + entity.Property(e => e.PurchYtd) + .HasColumnName("purch_ytd") + .HasDefaultValueSql("0") + .IsRequired(false); + + entity.Property(e => e.OrderYtd) + .HasColumnName("order_ytd") + .HasDefaultValueSql("0") + .IsRequired(false); + + entity.Property(e => e.ShipYtd) + .HasColumnName("ship_ytd") + .HasDefaultValueSql("0") + .IsRequired(false); + + entity.Property(e => e.OrderPtd) + .HasColumnName("order_ptd") + .HasDefaultValueSql("0") + .IsRequired(false); + + entity.Property(e => e.UM) + .HasColumnName("u_m") + .HasMaxLength(6) + .IsRequired(false); + + entity.Property(e => e.DuePeriod) + .HasColumnName("due_period") + .HasColumnType("smallint") + .IsRequired(false); + + entity.Property(e => e.NoteExistsFlag) + .HasColumnName("NoteExistsFlag") + .HasColumnType("tinyint") + .HasDefaultValueSql("0"); + + entity.Property(e => e.RecordDate) + .HasColumnName("RecordDate") + .HasDefaultValueSql("getdate()"); + + entity.Property(e => e.RowPointer) + .HasColumnName("RowPointer") + .HasColumnType("uniqueidentifier") + .HasDefaultValueSql("newid()"); + + entity.Property(e => e.CreatedBy) + .HasColumnName("CreatedBy") + .HasMaxLength(60) + .HasDefaultValueSql("suser_sname()"); + + entity.Property(e => e.UpdatedBy) + .HasColumnName("UpdatedBy") + .HasMaxLength(60) + .HasDefaultValueSql("suser_sname()"); + + entity.Property(e => e.CreateDate) + .HasColumnName("CreateDate") + .HasDefaultValueSql("getdate()"); + + entity.Property(e => e.InWorkflow) + .HasColumnName("InWorkflow") + .HasColumnType("tinyint") + .HasDefaultValueSql("0"); + + entity.Property(e => e.Rank) + .HasColumnName("rank") + .HasColumnType("int") + .IsRequired(false); + + entity.Property(e => e.EndUser) + .HasColumnName("end_user") + .HasMaxLength(60) + .IsRequired(false); + + entity.Property(e => e.Uf_FKR_CustItem2) + .HasColumnName("Uf_FKR_CustItem2") + .HasMaxLength(30) + .IsRequired(false); + + entity.Property(e => e.Uf_KOD_EAN13) + .HasColumnName("Uf_KOD_EAN13") + .HasMaxLength(13) + .IsRequired(false); + + entity.Property(e => e.Uf_Paleta_BROSE) + .HasColumnName("Uf_Paleta_BROSE") + .HasMaxLength(20) + .IsRequired(false); + + entity.Property(e => e.Uf_Pojemnik_BROSE) + .HasColumnName("Uf_Pojemnik_BROSE") + .HasMaxLength(20) + .IsRequired(false); + + entity.Property(e => e.Uf_Paleta_BROSE_Pokrywa) + .HasColumnName("Uf_Paleta_BROSE_Pokrywa") + .HasMaxLength(30) + .IsRequired(false); + + entity.Property(e => e.Uf_RewizjaRysunku) + .HasColumnName("Uf_RewizjaRysunku") + .HasMaxLength(20) + .IsRequired(false); + + // Indexes + entity.HasIndex(e => new { e.CustNum, e.Item, e.CustItemSeq }) + .HasDatabaseName("IX_itemcust_custitem") + .IsUnique(); + + entity.HasIndex(e => new { e.CustNum, e.Item, e.CustItem }) + .HasDatabaseName("IX_itemcust_custitemci") + .IsUnique(); + + entity.HasIndex(e => e.RowPointer) + .HasDatabaseName("IX_itemcust_RowPointer") + .IsUnique(); + }); } } }