Files
mapo-core/MP-TAB3/Components/TechSheet_ST_ObjCheck.razor.cs
2025-03-14 18:53:38 +01:00

228 lines
8.5 KiB
C#

using global::Microsoft.AspNetCore.Components;
using MP.Core.Objects;
using MP.Data.DbModels;
using MP.Data.Services;
namespace MP_TAB3.Components
{
public partial class TechSheet_ST_ObjCheck
{
#region Public Properties
[Parameter]
public string CodArticolo { get; set; } = "";
[Parameter]
public EventCallback<bool> E_Updated { get; set; }
[Parameter]
public int IdxOdl { get; set; } = 0;
#endregion Public Properties
#region Public Methods
public void checkInputData()
{
if (IdxOdl > 0)
{
var rawData = TabDServ.STAR_pendByOdl(IdxOdl);
showChecks = rawData.Count > 0;
}
else
{
showChecks = false;
}
}
#endregion Public Methods
#region Protected Properties
[Inject]
protected MessageService MServ { get; set; } = null!;
protected string ScanValue
{
get => "";
set
{
lastBCodeVal = value;
// processo input in async....
var pUpd = Task.Run(async () =>
{
await processInput();
});
pUpd.Wait();
}
}
[Inject]
protected SharedMemService SMServ { get; set; } = null!;
[Inject]
protected TabDataService TabDServ { get; set; } = null!;
#endregion Protected Properties
#region Protected Methods
protected override void OnParametersSet()
{
if (CodArticolo != codArticoloLast || IdxOdl != idxOdlLast)
{
codArticoloLast = CodArticolo;
idxOdlLast = IdxOdl;
checkInputData();
}
}
#endregion Protected Methods
#region Private Fields
private string codArticoloLast = "";
private int idxOdlLast = 0;
private string lastBCodeVal = "";
private string MessageCss = "";
private string MessageText = "";
private bool showChecks = false;
#endregion Private Fields
#region Private Properties
private string CognomeNome
{
get => MServ.CognomeNome;
}
#endregion Private Properties
#region Private Methods
/// <summary>
/// procedura pricipale decodifica Barcode
/// </summary>
private async Task processInput()
{
bool found = false;
bool batchOk = false;
List<ST_ActRow> tabRichieste = TabDServ.STAR_pendByOdl(IdxOdl);
List<AnagLottiArca> tabGiacenzeLotto = new List<AnagLottiArca>();
ST_ActRow? datiBatchCheck;
AnagLottiArca? datiLotto;
// per prima cosa recupero i valori "Pending" da leggere come candidati...
if (tabRichieste != null && tabRichieste.Count > 0)
{
// cerco per EQ come primo step...
var trovatoEq = tabRichieste.Where(x => x.CheckType == "EQ" && x.Value == lastBCodeVal);
if (trovatoEq != null && trovatoEq.Count() > 0)
{
// recupero record..
var datiEqCheck = trovatoEq.FirstOrDefault();
if (datiEqCheck != null)
{
// registro trovato
found = true;
MessageText = $"Parametro acquisito: {lastBCodeVal}";
MessageCss = "text-success";
// upsert controllo
await TabDServ.ST_CheckUpsert(IdxOdl, datiEqCheck.IdxST, datiEqCheck.Oggetto, datiEqCheck.Num, lastBCodeVal, lastBCodeVal, true, CognomeNome, false);
}
}
// se non trovato
if (!found)
{
// recupero record.. cercando in giacenza il LOTTO...
tabGiacenzeLotto = await TabDServ.LottoEsterno("", lastBCodeVal, "");
// controllo condizione tipo BATCH (speciale) - prima solo che CI SIA una
// richiesta di questo tipo
var trovatoBatch = tabRichieste.Where(x => x.CheckType == "BATCH");
if (trovatoBatch != null && trovatoBatch.Count() > 0)
{
datiBatchCheck = trovatoBatch.FirstOrDefault();
if (datiBatchCheck != null && tabGiacenzeLotto != null && tabGiacenzeLotto.Count > 0)
{
datiLotto = tabGiacenzeLotto.FirstOrDefault();
if (datiLotto != null)
{
// registro trovato
found = true;
// upsert controllo
await TabDServ.ST_CheckUpsert(IdxOdl, datiBatchCheck.IdxST, datiBatchCheck.Oggetto, datiBatchCheck.Num, lastBCodeVal, datiLotto.Cd_AR, true, CognomeNome, false);
// conto quanti check ci sono dopo, se calati --> ok altrimenti errore
var tabRichiestePost = TabDServ.STAR_pendByOdl(IdxOdl);
if (tabRichiestePost.Count < tabRichieste.Count)
{
MessageText = $"Lotto riconosciuto: {lastBCodeVal} --> {datiLotto.Cd_AR} | Articolo acquisito";
MessageCss = "text-success";
batchOk = true;
}
else
{
MessageText = $"Lotto: {lastBCodeVal} --> {datiLotto.Cd_AR} | Articolo NON richiesto";
MessageCss = "text-danger";
}
}
}
}
if (!batchOk)
{
var currDeroga = TabDServ.ST_DerogaGet(CognomeNome, tabRichieste[0].IdxST);
// ciclo tra TUTTE le richeiste attive
foreach (var item in tabRichieste)
{
// verifico EVENTUALI deroghe se deroga x gruppo/tipo/num corretto...
if (currDeroga.CanForce && item.CodGruppo == currDeroga.CodGruppo && item.CodTipo == currDeroga.CodTipo && item.Num == currDeroga.Num && item.Oggetto == currDeroga.Oggetto)
{
// ... forzo accettazione deroga
await TabDServ.ST_CheckUpsert(IdxOdl, item.IdxST, item.Oggetto, item.Num, lastBCodeVal, item.Value, true, CognomeNome, true);
MessageText = $"Lotto/articolo non valido: {lastBCodeVal} --> Forzato a valido per articolo {item.Value}";
MessageCss = "text-warning";
TabDServ.ST_DerogaSet(new StCheckOverride() { IdxST = item.IdxST, CanForce = false });
batchOk = true;
}
}
}
}
// se non trovato
if (!found)
{
if (tabGiacenzeLotto != null && tabGiacenzeLotto.Count > 0)
{
datiLotto = tabGiacenzeLotto.FirstOrDefault();
if (datiLotto != null)
{
MessageText = $"Lotto: {lastBCodeVal} --> {datiLotto.Cd_AR} | Articolo NON richiesto";
MessageCss = "text-danger";
}
}
else
{
MessageText = $"Parametro non riconosciuto: {lastBCodeVal}";
MessageCss = "text-secondary";
}
}
}
else
{
MessageText = $"Parametro non valido: {lastBCodeVal}";
MessageCss = "text-secondary";
}
// sistemo visualizzaizone componente
lastBCodeVal = "";
checkInputData();
// sollevo evento
await E_Updated.InvokeAsync(true);
}
#endregion Private Methods
}
}