From da1eae8ca91d29a1d3ba9fa788cfe74622228f62 Mon Sep 17 00:00:00 2001 From: Piotr Kus Date: Thu, 8 May 2025 20:44:20 +0200 Subject: [PATCH] * Added new Controllers to API * Added methods to get WZs for specific client --- FaKrosnoApi/Controllers/WzClientController.cs | 17 ++++ FaKrosnoApi/Controllers/WzHeaderController.cs | 26 +++++ FaKrosnoApi/Program.cs | 5 +- .../Components/Pages/Warehouse.razor | 96 ++++++++----------- OrdersManagement/Program.cs | 1 + OrdersManagement/Services/WarehouseService.cs | 21 ++++ .../Services/IMaterialTransactionService.cs | 1 + .../Services/MaterialTransactionService.cs | 17 ++++ 8 files changed, 125 insertions(+), 59 deletions(-) create mode 100644 FaKrosnoApi/Controllers/WzClientController.cs create mode 100644 FaKrosnoApi/Controllers/WzHeaderController.cs create mode 100644 OrdersManagement/Services/WarehouseService.cs diff --git a/FaKrosnoApi/Controllers/WzClientController.cs b/FaKrosnoApi/Controllers/WzClientController.cs new file mode 100644 index 0000000..2e0e653 --- /dev/null +++ b/FaKrosnoApi/Controllers/WzClientController.cs @@ -0,0 +1,17 @@ +using Microsoft.AspNetCore.Mvc; +using SytelineSaAppEfDataModel.Dtos; +using SytelineSaAppEfDataModel.Services; + +namespace FaKrosnoApi.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class WzClientController(IWzClientService service) : Controller +{ + [HttpGet] + public async Task>> GetAll() + { + IEnumerable wzClients = await service.GetAll(); + return Ok(wzClients); + } +} \ No newline at end of file diff --git a/FaKrosnoApi/Controllers/WzHeaderController.cs b/FaKrosnoApi/Controllers/WzHeaderController.cs new file mode 100644 index 0000000..1fb947e --- /dev/null +++ b/FaKrosnoApi/Controllers/WzHeaderController.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; +using SytelineSaAppEfDataModel.Dtos; +using SytelineSaAppEfDataModel.Services; + +namespace FaKrosnoApi.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class WzHeaderController(IWzHeaderService service, IMaterialTransactionService materialTransactionService) : Controller +{ + [HttpGet] + public async Task>> GetAll() + { + IEnumerable wzHeaders = await service.GetAll(); + return Ok(wzHeaders); + } + + [HttpGet("by-customer-number")] + public async Task>> GetByCustomerNumber( + [FromQuery] string customerNumber, [FromQuery] int customerSequence) + { + IEnumerable materialTransactions = + await materialTransactionService.GetByCustomerNumber(customerNumber, customerSequence); + return Ok(materialTransactions); + } +} \ No newline at end of file diff --git a/FaKrosnoApi/Program.cs b/FaKrosnoApi/Program.cs index d0e531f..b4d5d9a 100644 --- a/FaKrosnoApi/Program.cs +++ b/FaKrosnoApi/Program.cs @@ -65,7 +65,7 @@ builder.Services.AddOpenApiDocument(config => In = OpenApiSecurityApiKeyLocation.Header, Description = "Wprowadź token JWT w formacie: Bearer {token}" }); - + config.OperationProcessors.Add(new OperationSecurityScopeProcessor("Bearer")); }); @@ -100,6 +100,9 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddHostedService(); diff --git a/OrdersManagement/Components/Pages/Warehouse.razor b/OrdersManagement/Components/Pages/Warehouse.razor index 2023ffe..74081f0 100644 --- a/OrdersManagement/Components/Pages/Warehouse.razor +++ b/OrdersManagement/Components/Pages/Warehouse.razor @@ -2,6 +2,9 @@ @using Syncfusion.Blazor.Cards @using Syncfusion.Blazor.Grids +@using SytelineSaAppEfDataModel.Dtos + +@inject WarehouseService WarehouseService
@@ -9,63 +12,34 @@

Dokumenty WZ na Magazynie

- - - - @{ - var order = context as EdiCustomerOrderDto; - - -
-
- Numer zamówienia EDI: @order?.CustomerOrderNumber
- Numer zamówienia Klienta: @order?.CustomerPoNumber
- Numer klienta: @order?.CustomerNumber
- Klient: @order?.CustomerName
- Numer odbiorcy: @(order?.CustomerSequence?.ToString() ?? "N/A")
- Data otrzymania: @(order?.RecivedDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Wysłano do Syteline?: @((order?.Posted?.ToString() ?? "0") == "0" ? "NIE" : "TAK")
- Data wysyłki do Syteline: @(order?.PostedDate?.ToString("dd.MM.yyyy") ?? "N/A")
- Data zamówienia: @(order?.OrderDate?.ToString("dd.MM.yyyy") ?? "N/A")
-
-
- Cena: @(order?.Price?.ToString("F2") ?? "N/A")
- Waga: @(order?.Weight?.ToString("F2") ?? "N/A")
- Magazyn: @order?.Warehouse
- Gate: @order?.Gate
- Kod odbiorcy: @order?.RecipientCode
- Kod wysyłającego: @order?.SenderCode
- Kod sprzedawcy: @order?.SellerCode
- Kod kupującego: @order?.BuyerCode
- Typ dokumentu: @order?.DocType
-
-
-
-
- } -
-
- - - - - - - - - - - - - -
+ @* *@ + @* *@ + @* *@ + @* @{ *@ + @* } *@ + @* *@ + @* *@ + @* *@ + @* $1$ #1# *@ + @* $1$ #1# *@ + @* $1$ #1# *@ + @* $1$ #1# *@ + @* $1$ #1# *@ + @* $1$ #1# *@ + @* $1$ #1# *@ + @* *@ + @* *@ + @* *@ + @* *@ + @* $1$ #1# *@ + @* *@
FA Krosno Manager © @(DateTime.Now.Year) @@ -74,5 +48,11 @@
@code { - + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + IEnumerable task = await WarehouseService.GetAllClientWzsAsync("K005531", 0); + } + } } \ No newline at end of file diff --git a/OrdersManagement/Program.cs b/OrdersManagement/Program.cs index 2a820f3..04c31b1 100644 --- a/OrdersManagement/Program.cs +++ b/OrdersManagement/Program.cs @@ -52,6 +52,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); var app = builder.Build(); diff --git a/OrdersManagement/Services/WarehouseService.cs b/OrdersManagement/Services/WarehouseService.cs new file mode 100644 index 0000000..656b549 --- /dev/null +++ b/OrdersManagement/Services/WarehouseService.cs @@ -0,0 +1,21 @@ +using SytelineSaAppEfDataModel.Dtos; + +namespace OrdersManagement.Services; + +public class WarehouseService +{ + private readonly HttpClient _httpClient; + + public WarehouseService(IHttpClientFactory httpClientFactory) + { + _httpClient = httpClientFactory.CreateClient("FaKrosnoApi"); + } + + public async Task> GetAllClientWzsAsync(string customerNumber, int customerSequence) + { + var response = await _httpClient.GetAsync( + $"api/WzHeader/by-customer-number?customerNumber={customerNumber}&customerSequence={customerSequence}"); + response.EnsureSuccessStatusCode(); + return await response.Content.ReadFromJsonAsync>(); + } +} \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/IMaterialTransactionService.cs b/SytelineSaAppEfDataModel/Services/IMaterialTransactionService.cs index 9050da6..78535cb 100644 --- a/SytelineSaAppEfDataModel/Services/IMaterialTransactionService.cs +++ b/SytelineSaAppEfDataModel/Services/IMaterialTransactionService.cs @@ -9,4 +9,5 @@ public interface IMaterialTransactionService Task> GetByWzNumbers(ISet wzNumbers); Task> GetByOrderNumber(string orderNumber); Task> GetOrderNumbersByWz(ISet wzNumbers); + Task> GetByCustomerNumber(string customerNumber, int customerSequence); } \ No newline at end of file diff --git a/SytelineSaAppEfDataModel/Services/MaterialTransactionService.cs b/SytelineSaAppEfDataModel/Services/MaterialTransactionService.cs index a2e9fb8..4cdff57 100644 --- a/SytelineSaAppEfDataModel/Services/MaterialTransactionService.cs +++ b/SytelineSaAppEfDataModel/Services/MaterialTransactionService.cs @@ -66,4 +66,21 @@ public class MaterialTransactionService(SytelineSaAppDbContext context, IMapper return result.Select(x => mapper.Map(x)); } + + public async Task> GetByCustomerNumber(string customerNumber, int customerSequence) + { + IList coNumbers = await context.CustomerOrders + .Where(x => x.CustNum == customerNumber && x.CustSeq == customerSequence && (x.Stat == "P" || x.Stat == "O")) + .Select(x => x.CoNum).ToListAsync(); + + List result = new List(); + + foreach (string coNumber in coNumbers) + { + IEnumerable materialTransactions = await GetByOrderNumber(coNumber); + result.AddRange(materialTransactions); + } + + return result.OrderByDescending(x => x.CreateDate); + } } \ No newline at end of file