From f58d2ab04cdbfaf13cb363906e7afac73895947e Mon Sep 17 00:00:00 2001 From: Piotr Kus Date: Sat, 24 May 2025 21:47:32 +0200 Subject: [PATCH] * Further improvements of Warehouse view * Fixed issue with not saving Products updates --- FaKrosnoApi/Controllers/WzHeaderController.cs | 10 ++ .../Services/ProductService.cs | 17 ++- .../Components/Pages/Warehouse.razor | 116 +++++++++++++----- .../Components/Pages/WarehousePackList.razor | 54 ++++++-- OrdersManagement/Services/WarehouseService.cs | 8 ++ .../Services/IWzHeaderService.cs | 1 + .../Services/WzHeaderService.cs | 7 ++ .../SytelineSaAppDbContext.cs | 4 +- 8 files changed, 173 insertions(+), 44 deletions(-) diff --git a/FaKrosnoApi/Controllers/WzHeaderController.cs b/FaKrosnoApi/Controllers/WzHeaderController.cs index 13155dc..9ab9496 100644 --- a/FaKrosnoApi/Controllers/WzHeaderController.cs +++ b/FaKrosnoApi/Controllers/WzHeaderController.cs @@ -24,6 +24,16 @@ public class WzHeaderController(IWzHeaderService service, IMaterialTransactionSe return Ok(materialTransactions); } + [HttpGet("all-wz-headers")] + public async Task>> GetHeadersByCustomerNumber( + [FromQuery] string customerNumber, [FromQuery] int customerSequence) + { + IEnumerable wzHeaders = + await service.GetByCustomerNumber(customerNumber, customerSequence); + + return Ok(wzHeaders.OrderByDescending(x => x.CreatedDate)); + } + [HttpPost] public async Task CreateHeader([FromBody] WzHeaderDto wzHeader) { diff --git a/FaKrosnoEfDataModel/Services/ProductService.cs b/FaKrosnoEfDataModel/Services/ProductService.cs index 1788ea3..5b97f18 100644 --- a/FaKrosnoEfDataModel/Services/ProductService.cs +++ b/FaKrosnoEfDataModel/Services/ProductService.cs @@ -5,12 +5,9 @@ using Microsoft.EntityFrameworkCore; namespace FaKrosnoEfDataModel.Services; -public class ProductService : ServiceBase, IProductService +public class ProductService(FaKrosnoDbContext context, IMapper mapper) + : ServiceBase(context, mapper), IProductService { - public ProductService(FaKrosnoDbContext context, IMapper mapper) : base(context, mapper) - { - } - public async Task> GetEntities() { IList products = (await GetAll()).ToList(); @@ -22,9 +19,10 @@ public class ProductService : ServiceBase, IProductService { IList recipients = (await Context.Recipients.ToListAsync()).Select(x => Mapper.Map(x)).ToList(); + IList purchasers = (await Context.Purchasers.ToListAsync()).Select(x => Mapper.Map(x)).ToList(); IList products = (await GetAll()).ToList(); - IEnumerable productDtos = products.Where(x => x?.FaIdx == indexName); + IEnumerable productDtos = products.Where(x => x.FaIdx == indexName).ToList(); foreach (ProductDto productDto in productDtos) { @@ -35,6 +33,13 @@ public class ProductService : ServiceBase, IProductService productDto.Recipient = recipient; productDto.RecipientName = recipient.RecipientDesc; } + + PurchaserDto? purchaser = purchasers.FirstOrDefault(x => x.ID == productDto.Recipient.PurchaserID); + + if (purchaser != null) + { + productDto.Recipient.Purchaser = purchaser; + } } return productDtos; diff --git a/OrdersManagement/Components/Pages/Warehouse.razor b/OrdersManagement/Components/Pages/Warehouse.razor index c9a85de..51be593 100644 --- a/OrdersManagement/Components/Pages/Warehouse.razor +++ b/OrdersManagement/Components/Pages/Warehouse.razor @@ -1,5 +1,6 @@ @page "/Warehouse" +@using Blazored.LocalStorage @using Syncfusion.Blazor.Cards @using Syncfusion.Blazor.Grids @using SytelineSaAppEfDataModel.Dtos @@ -10,6 +11,7 @@ @inject WarehouseService WarehouseService @inject NavigationManager NavigationManager +@inject ILocalStorageService LocalStorage
@@ -18,36 +20,66 @@
Klient
- + @if (_isVisible) { -
Dokumenty WZ
- - - - - - - - - - - - - - - + + +
Dokumenty WZ
+
+ + + + + + + + + + + + + + + + + +
+ + +
Packling Listy
+
+ + + + + + + + + + + + +
}
@@ -58,19 +90,32 @@ @code { private SfGrid _grid; + private SfGrid _wzHeadersGrid; private IEnumerable _clients = new List(); private IEnumerable _materialTransactions = new List(); private IEnumerable _dataSource = new List(); + private IEnumerable _wzHeaders = new List(); private WzClientDto? _selectedClient; - bool _isVisible = false; - + private WzHeaderDto? _selectedHeader; + private SfDropDownList _dropdown; + private bool _isVisible; + protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { _clients = await WarehouseService.GetAllClientsAsync(); + _clients = _clients.Where(x => x.Name.Equals("MEYLE", StringComparison.OrdinalIgnoreCase)); + + var savedClientId = await LocalStorage.GetItemAsync("SelectedClientId"); + + if (savedClientId != null && _clients.FirstOrDefault(c => c.ID == savedClientId) is {} savedClient) + { + await OnValueChange(new ChangeEventArgs() { Value = savedClient.ID }); + } + StateHasChanged(); } } @@ -79,10 +124,18 @@ { if (args.Value.HasValue) { - _selectedClient = args.ItemData; + _selectedClient = args.ItemData ?? _clients.FirstOrDefault(x => x.ID == args.Value); + + if (_selectedClient == null) { return; } + _isVisible = true; _materialTransactions = await WarehouseService.GetAllClientWzsAsync(_selectedClient.CustomerNumber, _selectedClient.CustomerSequence ?? 0); _dataSource = _materialTransactions.GroupBy(x => x.MTGroupNum).Select(x => x.First()).ToList(); + _wzHeaders = await WarehouseService.GetAllClientWzHeadersAsync(_selectedClient.CustomerNumber, _selectedClient.CustomerSequence ?? 0); + + await LocalStorage.SetItemAsync("SelectedClientId", _selectedClient.ID); + + _dropdown.Value = _selectedClient.ID; } else { @@ -93,6 +146,13 @@ StateHasChanged(); } + private void OnRowDoubleClick(RecordDoubleClickEventArgs obj) + { + Guid headerId = obj.RowData.ID; + + NavigationManager.NavigateTo("/Warehouse/PackList/" + headerId); + } + private async Task CreatePackingList() { var selectedRecords = await _grid.GetSelectedRecordsAsync(); diff --git a/OrdersManagement/Components/Pages/WarehousePackList.razor b/OrdersManagement/Components/Pages/WarehousePackList.razor index 587a72f..88f29de 100644 --- a/OrdersManagement/Components/Pages/WarehousePackList.razor +++ b/OrdersManagement/Components/Pages/WarehousePackList.razor @@ -3,6 +3,7 @@ @using Syncfusion.Blazor.Grids @using SytelineSaAppEfDataModel.Dtos @using Syncfusion.Blazor.Navigations +@using Syncfusion.Blazor.Popups @inject WarehouseService WarehouseService @@ -13,13 +14,13 @@ + AllowFiltering="true" + AllowPaging="true" + AllowSorting="true" + AllowSelection="true" + TValue="WzRowMeyleDto" + DataSource="@_wzRowsMeyle" + EnableAdaptiveUI="true"> + + + + + @if (_isValid) + { +

Packing List został wygenerowany i wysłany!

+ } + else + { +

Błąd: Nie Wszystkie linie mają wypełniony NUMER PALETY.
Packing List nie zostanie wygenerowany!

+ } +
+
+ + + +
+ FA Krosno Manager © @(DateTime.Now.Year) @@ -71,6 +91,15 @@ private SfGrid _grid; private IEnumerable _wzRowsMeyle { get; set; } = new List(); + private bool _isValid; + + private bool Visibility { get; set; } + + private void HideModal() + { + Visibility = false; + } + protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) @@ -99,6 +128,15 @@ private async Task ExportXls() { - await WarehouseService.GenerateXlsForMeyleAsync(WzHeader); + int count = _wzRowsMeyle.Count(x => x.PalletNumber == null); + + _isValid = count == 0; + + if (_isValid) + { + await WarehouseService.GenerateXlsForMeyleAsync(WzHeader); + } + + Visibility = true; } } \ No newline at end of file diff --git a/OrdersManagement/Services/WarehouseService.cs b/OrdersManagement/Services/WarehouseService.cs index 2d2f8e0..f9c8ac4 100644 --- a/OrdersManagement/Services/WarehouseService.cs +++ b/OrdersManagement/Services/WarehouseService.cs @@ -21,6 +21,14 @@ public class WarehouseService(IHttpClientFactory httpClientFactory) return await response.Content.ReadFromJsonAsync>(); } + public async Task> GetAllClientWzHeadersAsync(string customerNumber, int customerSequence) + { + var response = await _httpClient.GetAsync( + $"api/WzHeader/all-wz-headers?customerNumber={customerNumber}&customerSequence={customerSequence}"); + response.EnsureSuccessStatusCode(); + return await response.Content.ReadFromJsonAsync>(); + } + public async Task CreateWzHeaderAsync(WzHeaderDto wzHeader) { var response = await _httpClient.PostAsJsonAsync("api/WzHeader", wzHeader); diff --git a/SytelineSaAppEfDataModel/Services/IWzHeaderService.cs b/SytelineSaAppEfDataModel/Services/IWzHeaderService.cs index 6235e2b..cecf78a 100644 --- a/SytelineSaAppEfDataModel/Services/IWzHeaderService.cs +++ b/SytelineSaAppEfDataModel/Services/IWzHeaderService.cs @@ -5,6 +5,7 @@ namespace SytelineSaAppEfDataModel.Services; public interface IWzHeaderService { Task> GetAll(); + Task> GetByCustomerNumber(string customerNumber, int customerSequence); Task CreateHeader(WzHeaderDto wzHeader); Task GetById(Guid id); } \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/WzHeaderService.cs b/SytelineSaAppEfDataModel/Services/WzHeaderService.cs index 2b4461c..28718f2 100644 --- a/SytelineSaAppEfDataModel/Services/WzHeaderService.cs +++ b/SytelineSaAppEfDataModel/Services/WzHeaderService.cs @@ -12,6 +12,13 @@ public class WzHeaderService(SytelineSaAppDbContext context, IMapper mapper) : I return await context.WzHeaders.Select(x => mapper.Map(x)).ToListAsync(); } + public async Task> GetByCustomerNumber(string customerNumber, int customerSequence) + { + return await context.WzHeaders.Include(x => x.Client) + .Where(x => x.Client.CustomerNumber == customerNumber && x.Client.CustomerSequence == customerSequence) + .Select(x => mapper.Map(x)).ToListAsync(); + } + public async Task CreateHeader(WzHeaderDto wzHeader) { var entity = mapper.Map(wzHeader); diff --git a/SytelineSaAppEfDataModel/SytelineSaAppDbContext.cs b/SytelineSaAppEfDataModel/SytelineSaAppDbContext.cs index 557aaf4..9ce067d 100644 --- a/SytelineSaAppEfDataModel/SytelineSaAppDbContext.cs +++ b/SytelineSaAppEfDataModel/SytelineSaAppDbContext.cs @@ -899,7 +899,7 @@ namespace SytelineSaAppEfDataModel entity.Property(e => e.CreatedDate) .HasColumnName("CreatedDate") - .HasColumnType("timestamp") + .HasColumnType("DateTime") .IsRowVersion(); // Relationship @@ -931,7 +931,7 @@ namespace SytelineSaAppEfDataModel entity.Property(e => e.CreatedDate) .HasColumnName("CreatedDate") - .HasColumnType("timestamp") + .HasColumnType("DateTime") .IsRowVersion(); entity.Property(e => e.Name)