From 4055ce842651c357ec3defbb408f00a26a90b4aa Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 2 Feb 2024 19:38:42 +0100 Subject: [PATCH] Prima versione deposit/pickup da verificare --- .../Controllers/TenantController.cs | 62 +++-- MagMan.Data.Tenant/Services/TenantService.cs | 58 ++++ MagMan.UI/Components/CodeReader.razor | 60 +++++ MagMan.UI/Components/CodeReader.razor.cs | 255 ++++++++++++++++++ MagMan.UI/MagMan.UI.csproj | 2 +- MagMan.UI/Pages/AdminArea.razor.cs | 2 +- MagMan.UI/Pages/Deposit.razor | 14 + MagMan.UI/Pages/Pickup.razor | 15 ++ MagMan.UI/Shared/NavMenu.razor | 10 + MagMan.UI/appsettings.json | 3 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 13 files changed, 466 insertions(+), 21 deletions(-) create mode 100644 MagMan.UI/Components/CodeReader.razor create mode 100644 MagMan.UI/Components/CodeReader.razor.cs create mode 100644 MagMan.UI/Pages/Deposit.razor create mode 100644 MagMan.UI/Pages/Pickup.razor diff --git a/MagMan.Data.Tenant/Controllers/TenantController.cs b/MagMan.Data.Tenant/Controllers/TenantController.cs index 94ac111..94f90b8 100644 --- a/MagMan.Data.Tenant/Controllers/TenantController.cs +++ b/MagMan.Data.Tenant/Controllers/TenantController.cs @@ -89,7 +89,6 @@ namespace MagMan.Data.Tenant.Controllers { dbResult = dbCtx .DbSetItems - //.Where(x => CustomerId == 0 || x.CustomerID == CustomerId) .Include(c => c.MaterialNav) .OrderBy(x => x.MatId) .ToList(); @@ -121,6 +120,32 @@ namespace MagMan.Data.Tenant.Controllers return dbResult; } + /// + /// Elenco Items gestiti a magazzino dato Materiale + /// + /// Stringa connessione (variabile x cliente) + /// QrCode/Dtmx cercato + /// + public RawItemModel ItemGetByQr(string connString, string qrCode) + { + RawItemModel? dbResult = new RawItemModel(); + using (MagManContext dbCtx = new MagManContext(connString)) + { + var rawList = dbCtx + .DbSetItems + .Include(m => m.MaterialNav) + .ToList(); + dbResult = rawList + .Where(x => x.ItemDtmx == qrCode) + .FirstOrDefault(); + if (dbResult == null) + { + dbResult = new RawItemModel(); + } + } + return dbResult; + } + /// /// Aggiunge/Modifica un item in magazzino /// @@ -148,21 +173,28 @@ namespace MagMan.Data.Tenant.Controllers .FirstOrDefault(); if (currData != null) { - MovMagModel recMovMag = new MovMagModel() - { - DtRec = DateTime.Now, - RawItemId = rec2upd.RawItemId, - QtyRec = deltaQty, - UserId = userId, - Note = deltaQty > 0 ? "M01+: Rettifica Inventariale" : "M01-: Rettifica Inventariale" - }; - dbCtx.DbSetMovMag.Add(recMovMag); - + // calcolo variazione currData.QtyAvail += deltaQty; - dbCtx.Entry(currData).State = EntityState.Modified; + // salvo SOLO SE è >=0,,, + if (currData.QtyAvail >= 0) + { + MovMagModel recMovMag = new MovMagModel() + { + DtRec = DateTime.Now, + RawItemId = rec2upd.RawItemId, + QtyRec = deltaQty, + UserId = userId, + Note = deltaQty > 0 ? "M01+: Rettifica Inventariale" : "M01-: Rettifica Inventariale" + }; + // registro movimento + dbCtx.DbSetMovMag.Add(recMovMag); + // registro modifica RawItem + dbCtx.Entry(currData).State = EntityState.Modified; + // salvo il tutto + dbCtx.SaveChanges(); + done = true; + } } - dbCtx.SaveChanges(); - done = true; } catch (Exception exc) { @@ -916,7 +948,7 @@ namespace MagMan.Data.Tenant.Controllers * */ var currData = dbCtx .DbSetResources - .Where(x => rec2upd.ResourceId > 0 && x.ResourceId == rec2upd.ResourceId) + .Where(x => rec2upd.ResourceId > 0 && x.ResourceId == rec2upd.ResourceId) .FirstOrDefault(); // aggiorno diff --git a/MagMan.Data.Tenant/Services/TenantService.cs b/MagMan.Data.Tenant/Services/TenantService.cs index 777beef..20b9c53 100644 --- a/MagMan.Data.Tenant/Services/TenantService.cs +++ b/MagMan.Data.Tenant/Services/TenantService.cs @@ -2,6 +2,7 @@ using MagMan.Core.DTO; using MagMan.Data.Tenant.Controllers; using MagMan.Data.Tenant.DbModels; +using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using NLog; @@ -231,6 +232,62 @@ namespace MagMan.Data.Tenant.Services return fatto; } + /// + /// Ricerca item da QrCode + /// + /// Key di riferimento + /// QrCode/Dtmx cercato + /// + public async Task ItemGetByQr(int nKey, string QrCode) + { + RawItemModel? dbResult = new RawItemModel(); + string cacheKey = $"{Const.rKeyConfig}:{nKey}:{QrCode}"; + string source = "DB"; + string cString = ConnString(nKey); + try + { + string currKey = $"{Const.rKeyConfig}:{nKey}:ItemByQr:{QrCode}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject(rawData); + if (tempResult == null) + { + dbResult = new RawItemModel(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.ItemGetByQr(cString, QrCode); + if (dbResult != null && dbResult.ItemDtmx.ToUpper() == QrCode.ToUpper()) + { + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + } + if (dbResult == null) + { + dbResult = new RawItemModel(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ItemGetByQr | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Error during ItemGetByQr:{Environment.NewLine}{exc}"); + } + return dbResult; + } + + /// /// Update record Item + refresh cache /// @@ -1039,6 +1096,7 @@ namespace MagMan.Data.Tenant.Services return newId; } + #endregion Public Methods #region Private Fields diff --git a/MagMan.UI/Components/CodeReader.razor b/MagMan.UI/Components/CodeReader.razor new file mode 100644 index 0000000..1e0609c --- /dev/null +++ b/MagMan.UI/Components/CodeReader.razor @@ -0,0 +1,60 @@ +@Title + +
+
+
+
+

@Title

+
+
+ @if (processing) + { + ...working... + } + +
+
+
+
+
+
+ +
+ @if (!string.IsNullOrEmpty(lastCmd)) + { +
+ @if (IsPickup || IsDeposit) + { + + } +
+ } +
+ @if (!string.IsNullOrEmpty(alertMessage)) + { +
+ @alertMsg +
+ } + @if (!string.IsNullOrEmpty(lastMessage)) + { +
+ @lastMsg +
+ } +
+
+
+
+ + diff --git a/MagMan.UI/Components/CodeReader.razor.cs b/MagMan.UI/Components/CodeReader.razor.cs new file mode 100644 index 0000000..4237a1c --- /dev/null +++ b/MagMan.UI/Components/CodeReader.razor.cs @@ -0,0 +1,255 @@ +// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this +// file to you under the MIT license. +using Microsoft.AspNetCore.Components.Authorization; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using MagMan.Core.Services; + +namespace MagMan.UI.Components +{ + public partial class CodeReader : IDisposable + { + #region Public Properties + + [Parameter] + public bool IsDeposit { get; set; } = true; + + [Parameter] + public bool IsPickup { get; set; } = true; + + [Parameter] + public string Title { get; set; } = "Pick/Deposit"; + + #endregion Public Properties + + #region Public Methods + + public void Dispose() + { + AppMService.EA_CustomerSel -= AppMService_EA_CustomerSel; + AppMService.EA_KeySel -= AppMService_EA_KeySel; + } + + public async Task SetFocusAsync() + { + //await CodeInput.FocusAsync(JSRuntime); + await CodeInput.FocusAsync(true); + } + + #endregion Public Methods + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } = null!; + + protected string currUserId + { + get + { + string userName = ""; + var authState = AuthStateProvider.GetAuthenticationStateAsync().Result; + var user = authState.User; + if (user != null && user.Identity != null) + { + if (user.Identity.IsAuthenticated) + { + userName = $"{user.Identity.Name}"; + } + else + { + userName = "N.A."; + } + } + + return userName; + } + } + + #endregion Protected Properties + + #region Protected Methods + + protected async Task ConfirmOperation() + { + //if (!await JSRuntime.InvokeAsync("confirm", "Confirm operation?")) + // return; + + int qtyMov = 0; + if (IsPickup) + { + qtyMov = -1; + } + else if (IsDeposit) + { + qtyMov = 1; + } + if (qtyMov != 0) + { + if (currRecord != null) + { + await TService.ItemModQty(KeyNum, currRecord, qtyMov, currUserId); + alertMessage = ""; + lastCmd = ""; + if (currRecord.MaterialNav != null) + { + lastMessage = $"

Operation Confirmed!

{qtyMov} x {currRecord.MaterialNav.MatCode} {currRecord.MaterialNav.MatDesc}
{currRecord.LMm:N3}x{currRecord.WMm:N3}x{currRecord.HMm:N3}
"; + } + else + { + lastMessage = $"

Operation Confirmed!

{qtyMov} x ND ???
{currRecord.LMm:N3}x{currRecord.WMm:N3}x{currRecord.HMm:N3}
"; + } + } + await Task.Delay(1); + StateHasChanged(); + await Task.Delay(scanOpDelay); + await ReloadData(); + await SetFocusAsync(); + } + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await SetFocusAsync(); + } + } + + protected override async Task OnInitializedAsync() + { + string rawConf = Configuration["OptConf:ScanOpDelay"]; + if (rawConf != null) + { + int.TryParse(rawConf, out scanOpDelay); + } + KeyNum = AppMService.KeyNum; + AppMService.EA_CustomerSel += AppMService_EA_CustomerSel; + AppMService.EA_KeySel += AppMService_EA_KeySel; + await ReloadData(); + } + + protected async Task processInput(string newVal) + { + processing = true; + alertMessage = ""; + lastMessage = ""; + var remnRecord = await TService.ItemGetByQr(KeyNum, newVal); + if (remnRecord != null && remnRecord.MatId > 0 && remnRecord.ItemDtmx == newVal) + { + currRecord = remnRecord; + lastCmd = newVal; + if (remnRecord.MaterialNav != null) + { + lastMessage = $"{remnRecord.MaterialNav.MatCode} {remnRecord.MaterialNav.MatDesc}
{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.HMm:N3}
"; + } + else + { + lastMessage = $"ND ???
{remnRecord.LMm:N3}x{remnRecord.WMm:N3}x{remnRecord.HMm:N3}
"; + } + } + else + { + alertMessage = $"Error: code {newVal} not valid / not found"; + lastCmd = ""; + } + + processing = false; + } + + protected async Task Reset() + { + await ReloadData(); + await SetFocusAsync(); + } + + #endregion Protected Methods + + #region Private Fields + + private string alertMessage = ""; + + private ElementReference CodeInput; + + private RawItemModel? currRecord = null; + + private string lastCmd = ""; + + private string lastMessage = ""; + + private bool processing = false; + + private int scanOpDelay = 5000; + + #endregion Private Fields + + #region Private Properties + + private MarkupString alertMsg { get => (MarkupString)alertMessage; } + + [Inject] + private AuthenticationStateProvider AuthStateProvider { get; set; } = null!; + + [Inject] + private IConfiguration Configuration { get; set; } = null!; + + private int CustomerID { get; set; } = 0; + + private string inputValue + { + get + { + return ""; + } + set + { + var pUpd = Task.Run(async () => + { + await processInput(value.Trim()); + }); + pUpd.Wait(); + } + } + + [Inject] + private IJSRuntime JSRuntime { get; set; } = null!; + + private int KeyNum { get; set; } = 0; + + private MarkupString lastMsg { get => (MarkupString)lastMessage; } + + [Inject] + private TenantService TService { get; set; } = null!; + + #endregion Private Properties + + #region Private Methods + + private async void AppMService_EA_CustomerSel() + { + CustomerID = AppMService.CustomerID; + //await Task.Delay(1); + await InvokeAsync(StateHasChanged); + } + + private async void AppMService_EA_KeySel() + { + KeyNum = AppMService.KeyNum; + //await Task.Delay(1); + await InvokeAsync(StateHasChanged); + } + + private async Task ReloadData() + { + currRecord = null; + alertMessage = ""; + lastMessage = ""; + lastCmd = ""; + await Task.Delay(1); + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MagMan.UI/MagMan.UI.csproj b/MagMan.UI/MagMan.UI.csproj index dc557d2..a55e7d5 100644 --- a/MagMan.UI/MagMan.UI.csproj +++ b/MagMan.UI/MagMan.UI.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.2402.0211 + 1.0.2402.0219 enable enable true diff --git a/MagMan.UI/Pages/AdminArea.razor.cs b/MagMan.UI/Pages/AdminArea.razor.cs index 43d653d..302fc45 100644 --- a/MagMan.UI/Pages/AdminArea.razor.cs +++ b/MagMan.UI/Pages/AdminArea.razor.cs @@ -37,7 +37,7 @@ namespace MagMan.UI.Pages protected override void OnInitialized() { AppMService.ShowSearch = false; - AppMService.ShowCustomers = false; + AppMService.ShowCustomers = true; AppMService.PageName = "Admin Area"; AppMService.PageIcon = "fa-solid fa-building pr-2"; AppMService.EA_CustomerSel += AppMService_EA_CustomerSel; diff --git a/MagMan.UI/Pages/Deposit.razor b/MagMan.UI/Pages/Deposit.razor new file mode 100644 index 0000000..edd4d53 --- /dev/null +++ b/MagMan.UI/Pages/Deposit.razor @@ -0,0 +1,14 @@ +@page "/Deposit" +@inject MessageService AppMService + + + +@code { + protected override void OnInitialized() + { + AppMService.ShowSearch = false; + AppMService.ShowCustomers = true; + AppMService.PageName = "Deposit"; + AppMService.PageIcon = "fa-solid fa-upload pr-2"; + } +} diff --git a/MagMan.UI/Pages/Pickup.razor b/MagMan.UI/Pages/Pickup.razor new file mode 100644 index 0000000..51e06ff --- /dev/null +++ b/MagMan.UI/Pages/Pickup.razor @@ -0,0 +1,15 @@ +@page "/PickUp" +@inject MessageService AppMService + + + +@code { + + protected override void OnInitialized() + { + AppMService.ShowSearch = false; + AppMService.ShowCustomers = true; + AppMService.PageName = "Pickup"; + AppMService.PageIcon = "fa-solid fa-download pr-2"; + } +} diff --git a/MagMan.UI/Shared/NavMenu.razor b/MagMan.UI/Shared/NavMenu.razor index 8d63bc6..2a8f232 100644 --- a/MagMan.UI/Shared/NavMenu.razor +++ b/MagMan.UI/Shared/NavMenu.razor @@ -56,6 +56,16 @@ Magazzino + +