From da7cfb966896753facea3df2de3ff9f2241cdb64 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 17 Apr 2026 12:07:08 +0200 Subject: [PATCH] Spostamento servizi warehouse + inserimento prime funzioni calcolo fabbisogni --- .../DataServiceCollectionExtensions.cs | 3 + .../Repository/Warehouse/IMatReqRepository.cs | 7 ++ .../Repository/Warehouse/MatReqRepository.cs | 13 +++ .../Warehouse/IMatReqService.cs | 9 +- .../Services/Warehouse/MatReqService.cs | 93 +++++++++++++++++++ .../Services/Warehouse/_Using.cs | 1 + .../Warehouse/MatReqService.cs | 46 --------- Lux.API/Lux.API.csproj | 2 +- .../Components/Compo/Order/OrderRowMan.razor | 3 + .../Compo/Order/OrderRowMan.razor.cs | 21 +++++ Lux.UI/GlobalUsings.cs | 1 + Lux.UI/Lux.UI.csproj | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 15 files changed, 153 insertions(+), 54 deletions(-) rename EgwCoreLib.Lux.Data/{ => Services}/Warehouse/IMatReqService.cs (80%) create mode 100644 EgwCoreLib.Lux.Data/Services/Warehouse/MatReqService.cs create mode 100644 EgwCoreLib.Lux.Data/Services/Warehouse/_Using.cs delete mode 100644 EgwCoreLib.Lux.Data/Warehouse/MatReqService.cs diff --git a/EgwCoreLib.Lux.Data/DataServiceCollectionExtensions.cs b/EgwCoreLib.Lux.Data/DataServiceCollectionExtensions.cs index 5d3d2e18..8aea8210 100644 --- a/EgwCoreLib.Lux.Data/DataServiceCollectionExtensions.cs +++ b/EgwCoreLib.Lux.Data/DataServiceCollectionExtensions.cs @@ -8,6 +8,7 @@ using EgwCoreLib.Lux.Data.Services.Job; using EgwCoreLib.Lux.Data.Services.Production; using EgwCoreLib.Lux.Data.Services.Sales; using EgwCoreLib.Lux.Data.Services.Utils; +using EgwCoreLib.Lux.Data.Services.Warehouse; using Microsoft.Extensions.DependencyInjection.Extensions; namespace EgwCoreLib.Lux.Data @@ -39,6 +40,7 @@ namespace EgwCoreLib.Lux.Data services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); + services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); @@ -71,6 +73,7 @@ namespace EgwCoreLib.Lux.Data services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); + services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); services.TryAddScoped(); diff --git a/EgwCoreLib.Lux.Data/Repository/Warehouse/IMatReqRepository.cs b/EgwCoreLib.Lux.Data/Repository/Warehouse/IMatReqRepository.cs index 6d930d05..baa248e9 100644 --- a/EgwCoreLib.Lux.Data/Repository/Warehouse/IMatReqRepository.cs +++ b/EgwCoreLib.Lux.Data/Repository/Warehouse/IMatReqRepository.cs @@ -22,6 +22,13 @@ /// Record da eliminare Task DeleteAsync(MatReqModel entity); + /// + /// Elimina un set di record MatReq dato OrderRowId. + /// + /// ID dell'OrderRow relativo + /// forza cancellazione anche per già ordinati + Task DeleteByOrderRowAsync(int orderRowId, bool force = false); + /// /// Recupera un record MatReq specifico per ID. /// diff --git a/EgwCoreLib.Lux.Data/Repository/Warehouse/MatReqRepository.cs b/EgwCoreLib.Lux.Data/Repository/Warehouse/MatReqRepository.cs index c41c5d4e..af8c8f6c 100644 --- a/EgwCoreLib.Lux.Data/Repository/Warehouse/MatReqRepository.cs +++ b/EgwCoreLib.Lux.Data/Repository/Warehouse/MatReqRepository.cs @@ -30,6 +30,19 @@ return await dbCtx.SaveChangesAsync() > 0; } + /// + public async Task DeleteByOrderRowAsync(int orderRowId, bool force = false) + { + await using var dbCtx = await CreateContextAsync(); + // registro eliminazione diretta dei record eliminabilii... + var list2del = await dbCtx + .DbSetMaterialReq + .Where(x => x.OrderRowID == orderRowId && (!x.Processed || force)) + .ExecuteDeleteAsync(); + + return await dbCtx.SaveChangesAsync() > 0; + } + /// public async Task GetByIdAsync(int recId) { diff --git a/EgwCoreLib.Lux.Data/Warehouse/IMatReqService.cs b/EgwCoreLib.Lux.Data/Services/Warehouse/IMatReqService.cs similarity index 80% rename from EgwCoreLib.Lux.Data/Warehouse/IMatReqService.cs rename to EgwCoreLib.Lux.Data/Services/Warehouse/IMatReqService.cs index bd43a826..2afcdd91 100644 --- a/EgwCoreLib.Lux.Data/Warehouse/IMatReqService.cs +++ b/EgwCoreLib.Lux.Data/Services/Warehouse/IMatReqService.cs @@ -1,4 +1,4 @@ -namespace EgwCoreLib.Lux.Data.Warehouse +namespace EgwCoreLib.Lux.Data.Services.Warehouse { public interface IMatReqService { @@ -47,11 +47,14 @@ #endif /// - /// Genera un set di MatReq da una lista di ID di RigheOrdine + /// Riconcilia i fabbisogni x un set di RigheOrdine: + /// - verifica ogni riga d'orine e le relative BOM + /// - verifica eventuali fabbisogni presenti (tiene se ordinati, elimina se solo promessi) + /// - genera un set di record fabbisogni (MatReq) per garantire evazione BOM /// /// Lista OrderRow da processare /// - Task UpsertManyAsync(List ListOrderRow); + Task ReconcileOrderRowsAsync(List ListOrderRow, bool forceReset = false); #endregion Public Methods } diff --git a/EgwCoreLib.Lux.Data/Services/Warehouse/MatReqService.cs b/EgwCoreLib.Lux.Data/Services/Warehouse/MatReqService.cs new file mode 100644 index 00000000..12824046 --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Warehouse/MatReqService.cs @@ -0,0 +1,93 @@ +namespace EgwCoreLib.Lux.Data.Services.Warehouse +{ + public class MatReqService : BaseServ, IMatReqService + { + #region Public Constructors + + public MatReqService( + IConfiguration config, + IConnectionMultiplexer redis, + IMatReqRepository repo) : base(config, redis) + { + _className = "MatReq"; + _repo = repo; + } + + /// + public async Task ReconcileOrderRowsAsync(List ListOrderRow, bool forceReset = false) + { + return await TraceAsync($"{_className}.ReconcileOrderRowsAsync", async (activity) => + { + List listaSpesa = new(); + // ciclo sulle righe x trasformare BOM in fabbisogni... + foreach (var currItem in ListOrderRow) + { + var newReq = await GetFabbisogniAsync(currItem, forceReset); + listaSpesa.AddRange(newReq); + } + + bool success = await _repo.AddManyAsync(listaSpesa); + + activity?.SetTag("db.operation", "ReconcileOrderRowsAsync"); + + if (success) + { + await ClearCacheAsync($"{_redisBaseKey}:{_className}:*"); + } + + return success; + }); + } + + /// + /// Genera un set di record fabbisogni da un item (RigaOrdine) + /// + /// Singolo record OrderModel + /// + private async Task> GetFabbisogniAsync(OrderRowModel currItem, bool forceReset) + { + List newReqList = new(); + + /*-------------------------------------------------- + * Calcolo fabbisogni x rigaOrine (Item) + * - elimina ogni fabbisogno precedente (DOVREBBE tenere se confermati/ordinati) + * - genera un nuovo set di fabbisogni x ogni riga della BOM dell'ITEM + *--------------------------------------------------*/ + + // eliminazione preliminare... + await _repo.DeleteByOrderRowAsync(currItem.OrderRowID, forceReset); + + // leggo l'elenco attuale dei fabbisogni presenti + var currMatReqList = await _repo.GetFiltAsync(null, currItem.OrderRowID, null, null); + + // ogni riga a 1..n BOM --> per ogni riga BOM 1 fabbisogno... + foreach (var bomItem in currItem.ListBOM) + { + // valorizzo inizialmente come record intero + MatReqModel newReq = new MatReqModel() + { + OrderRowID = currItem.OrderRowID, + Inserted = DateTime.Now, + ItemID = bomItem.ItemID, + Processed = false, + Qty = bomItem.Qty + }; + // cerco nei fabbisogni... + var cMatReq = currMatReqList.FirstOrDefault(x => x.OrderRowID == currItem.OrderRowID && x.ItemID == bomItem.ItemID); + // se trovato --> genera per differenza + if (cMatReq != null) + { + newReq.Qty -= cMatReq.Qty; + } + newReqList.Add(newReq); + } + return newReqList; + } + + + #endregion Public Constructors + + private readonly string _className; + private readonly IMatReqRepository _repo; + } +} diff --git a/EgwCoreLib.Lux.Data/Services/Warehouse/_Using.cs b/EgwCoreLib.Lux.Data/Services/Warehouse/_Using.cs new file mode 100644 index 00000000..5726103b --- /dev/null +++ b/EgwCoreLib.Lux.Data/Services/Warehouse/_Using.cs @@ -0,0 +1 @@ +global using EgwCoreLib.Lux.Data.Repository.Warehouse; \ No newline at end of file diff --git a/EgwCoreLib.Lux.Data/Warehouse/MatReqService.cs b/EgwCoreLib.Lux.Data/Warehouse/MatReqService.cs deleted file mode 100644 index aca9a46f..00000000 --- a/EgwCoreLib.Lux.Data/Warehouse/MatReqService.cs +++ /dev/null @@ -1,46 +0,0 @@ -using EgwCoreLib.Lux.Data.Services; - -namespace EgwCoreLib.Lux.Data.Warehouse -{ - public class MatReqService : BaseServ, IMatReqService - { - #region Public Constructors - - public MatReqService( - IConfiguration config, - IConnectionMultiplexer redis, - IMatReqService repo) : base(config, redis) - { - _className = "MatReq"; - _repo = repo; - } - - /// - public async Task UpsertManyAsync(List ListOrderRow) - { - return await TraceAsync($"{_className}.UpsertManyAsync", async (activity) => - { - // per prima cosa costruisco un elenco di tutte le BOM richieste per ogn OrderRowmodel.. - List> listBom = ListOrderRow.Select(x => x.ListBOM).ToList(); - - bool success = false; - //bool success = await _repo.UpsertFromBomAsync(bomList); - - activity?.SetTag("db.operation", "UpsertManyAsync"); - - if (success) - { - await ClearCacheAsync($"{_redisBaseKey}:{_className}:*"); - } - - return success; - }); - } - - - #endregion Public Constructors - - private readonly string _className; - private readonly IMatReqService _repo; - } -} diff --git a/Lux.API/Lux.API.csproj b/Lux.API/Lux.API.csproj index dc2f2913..0559ef84 100644 --- a/Lux.API/Lux.API.csproj +++ b/Lux.API/Lux.API.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 1.1.2604.1710 + 1.1.2604.1712 diff --git a/Lux.UI/Components/Compo/Order/OrderRowMan.razor b/Lux.UI/Components/Compo/Order/OrderRowMan.razor index 95bfa4b8..96b6582c 100644 --- a/Lux.UI/Components/Compo/Order/OrderRowMan.razor +++ b/Lux.UI/Components/Compo/Order/OrderRowMan.razor @@ -248,6 +248,9 @@ else @fSize(item.Original.FileSize) } +
  • + +
  • diff --git a/Lux.UI/Components/Compo/Order/OrderRowMan.razor.cs b/Lux.UI/Components/Compo/Order/OrderRowMan.razor.cs index a5235420..ebbecf7b 100644 --- a/Lux.UI/Components/Compo/Order/OrderRowMan.razor.cs +++ b/Lux.UI/Components/Compo/Order/OrderRowMan.razor.cs @@ -334,6 +334,9 @@ namespace Lux.UI.Components.Compo.Order [Inject] private IDataLayerServices DLService { get; set; } = null!; + [Inject] + private IMatReqService MRService { get; set; } = null!; + [Inject] private IEnvirParamService EPService { get; set; } = null!; @@ -781,6 +784,20 @@ namespace Lux.UI.Components.Compo.Order isLoading = false; } + private async Task DoGenFabbisogni(OrderRowModel curRec) + { + + if (!await JSRuntime.InvokeAsync("confirm", $"Confermi di voler generare i fabbisogni per la riga d'ordine indicata?")) + return; + + // chiamo procedura creazione fabbisogni... + List listReq = new(); + listReq.Add(curRec); + await MRService.ReconcileOrderRowsAsync(listReq); + await ReloadDataAsync(); + UpdateTable(); + } + /// /// Edit del file: /// - abilitazione fileUpload @@ -837,6 +854,10 @@ namespace Lux.UI.Components.Compo.Order UpdateTable(); isLoading = false; await EC_Updated.InvokeAsync(true); + //await InvokeAsync(async () => + //{ + // await EC_Updated.InvokeAsync(true); + //}); } /// diff --git a/Lux.UI/GlobalUsings.cs b/Lux.UI/GlobalUsings.cs index e795d71e..6b281258 100644 --- a/Lux.UI/GlobalUsings.cs +++ b/Lux.UI/GlobalUsings.cs @@ -19,6 +19,7 @@ global using EgwCoreLib.Lux.Data.Services.Job; global using EgwCoreLib.Lux.Data.Services.Production; global using EgwCoreLib.Lux.Data.Services.Sales; global using EgwCoreLib.Lux.Data.Services.Utils; +global using EgwCoreLib.Lux.Data.Services.Warehouse; global using EgwCoreLib.Utils; global using Microsoft.AspNetCore.Components; global using Microsoft.AspNetCore.Components.Authorization; diff --git a/Lux.UI/Lux.UI.csproj b/Lux.UI/Lux.UI.csproj index 5e448996..e10f0991 100644 --- a/Lux.UI/Lux.UI.csproj +++ b/Lux.UI/Lux.UI.csproj @@ -5,7 +5,7 @@ enable enable aspnet-Lux.UI-a758c101-a2f4-4e38-977d-1c4887dbbd50 - 1.1.2604.1710 + 1.1.2604.1712 diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 62830896..bc469541 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ LUX - Web Windows MES -

    Versione: 1.1.2604.1710

    +

    Versione: 1.1.2604.1712


    Note di rilascio:
    • diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index d82ca31d..08e5bd4a 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.1.2604.1710 +1.1.2604.1712 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index 3d1a0614..cff9563b 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.1.2604.1710 + 1.1.2604.1712 http://nexus.steamware.net/repository/SWS/GPW/stable/GPW.UI.zip http://nexus.steamware.net/repository/SWS/GPW/stable/ChangeLog.html false