369 lines
12 KiB
C#
369 lines
12 KiB
C#
using EgwCoreLib.Razor;
|
|
using GPW.CORE.Data;
|
|
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.DTO;
|
|
using GPW.CORE.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using NLog;
|
|
|
|
namespace GPW.CORE.ADM.Components.Compo
|
|
{
|
|
public partial class ApprovTimbMan : IDisposable
|
|
{
|
|
#region Public Methods
|
|
|
|
public void Dispose()
|
|
{
|
|
AppMServ.EA_SearchUpdated -= AppMServ_EA_SearchUpdated;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected GpwDataService GDataServ { get; set; } = null!;
|
|
|
|
protected int IdxDipSel { get; set; } = 0;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected string CssCheckSel(string uid)
|
|
{
|
|
return ListUidSel.Contains(uid) ? "btn-info" : "btn-secondary opacity-50";
|
|
}
|
|
|
|
protected async Task DoApprove(TimbratureModel selItem)
|
|
{
|
|
isLoading = true;
|
|
// se non si tratta di una timbratura "last second"...
|
|
if (selItem.DataOra.Hour != 23 && selItem.DataOra.Minute != 59 && selItem.DataOra.Second != 59)
|
|
{
|
|
// arrotondo ingresso/uscita ai 5 minuti secondo sia entrata o uscita...
|
|
var dtTimb = Utils.DateRounded(selItem.DataOra, 5, !(selItem.Entrata ?? false));
|
|
selItem.DataOra = dtTimb;
|
|
}
|
|
// indico approvato
|
|
selItem.Approv = true;
|
|
// salvo!
|
|
bool fatto = await GDataServ.TimbratureUpdate(selItem);
|
|
//bool fatto = await GDataServ.TimbratureUpdateRound(selItem);
|
|
if (fatto)
|
|
{
|
|
await ReloadData();
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private bool legacyMode = false;
|
|
|
|
protected List<TimbratureDTO> ListSelected
|
|
{
|
|
get => ListRecords != null ? ListRecords.Where(x => x.Selected).ToList() : new List<TimbratureDTO>();
|
|
}
|
|
|
|
protected async Task DoApproveSel()
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", $"Sicuro di voler approvare i {ListUidSel.Count} record selezionati?"))
|
|
return;
|
|
|
|
isLoading = true;
|
|
await InvokeAsync(StateHasChanged);
|
|
int numProc = 0;
|
|
if (legacyMode)
|
|
{
|
|
foreach (var item in ListRecords)
|
|
{
|
|
// se selezionato...
|
|
if (ListUidSel.Contains(item.UID))
|
|
{
|
|
// se non si tratta di una timbratura "last second"...
|
|
if (item.DataOra.Hour != 23 && item.DataOra.Minute != 59 && item.DataOra.Second != 59)
|
|
{
|
|
// arrotondo ingresso/uscita ai 5 minuti secondo sia entrata o uscita...
|
|
var dtTimb = Utils.DateRounded(item.DataOra, 5, !(item.Entrata ?? false));
|
|
item.DataOra = dtTimb;
|
|
}
|
|
// indico approvato
|
|
item.Approv = true;
|
|
// salvo!
|
|
bool fatto = await GDataServ.TimbratureUpdate(item);
|
|
if (fatto)
|
|
{
|
|
numProc++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
foreach (var item in ListSelected)
|
|
{
|
|
// se non si tratta di una timbratura "last second"...
|
|
if (item.DataOra.Hour != 23 && item.DataOra.Minute != 59 && item.DataOra.Second != 59)
|
|
{
|
|
// arrotondo ingresso/uscita ai 5 minuti secondo sia entrata o uscita...
|
|
var dtTimb = Utils.DateRounded(item.DataOra, 5, !(item.Entrata ?? false));
|
|
item.DataOra = dtTimb;
|
|
}
|
|
// indico approvato
|
|
item.Approv = true;
|
|
// salvo!
|
|
bool fatto = await GDataServ.TimbratureUpdate(item, false);
|
|
if (fatto)
|
|
{
|
|
numProc++;
|
|
}
|
|
}
|
|
// svuoto cache
|
|
allSel = false;
|
|
}
|
|
if (numProc > 0)
|
|
{
|
|
await GDataServ.FlushRedisCache();
|
|
await ReloadData();
|
|
}
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected async void DoDelete(TimbratureModel selItem)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare il record?"))
|
|
return;
|
|
|
|
isLoading = true;
|
|
bool fatto = await GDataServ.TimbratureDelete(selItem);
|
|
if (fatto)
|
|
{
|
|
await ReloadData();
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected async void DoExchange(TimbratureModel selItem)
|
|
{
|
|
isLoading = true;
|
|
selItem.Entrata = !selItem.Entrata;
|
|
bool fatto = await GDataServ.TimbratureUpdate(selItem);
|
|
if (fatto)
|
|
{
|
|
await ReloadData();
|
|
}
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
protected async Task ForceReload(bool force)
|
|
{
|
|
ListUidSel = new List<string>();
|
|
await ReloadData();
|
|
}
|
|
|
|
protected string IconCheckSel(string uid)
|
|
{
|
|
return ListUidSel.Contains(uid) ? "fa-circle" : "fa-circle";
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
CurrSearch = "";
|
|
AppMServ.SearchVal = "";
|
|
AppMServ.EA_SearchUpdated += AppMServ_EA_SearchUpdated;
|
|
numRecord = await AppMServ.NumRowGridGet(gridKey);
|
|
var rawList = await GDataServ.DipendentiGetAll();
|
|
ListDipendenti = rawList.Where(x => (x.Attivo ?? false)).ToList();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
protected void SelectAll()
|
|
{
|
|
if (ListRecords != null)
|
|
{
|
|
ListUidSel = ListRecords.Select(x => x.UID).ToList();
|
|
}
|
|
}
|
|
|
|
protected async Task SetNumRec(int newNum)
|
|
{
|
|
numRecord = newNum;
|
|
currPage = 1;
|
|
await AppMServ.NumRowGridSet(gridKey, newNum);
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected async Task SetPage(int newNum)
|
|
{
|
|
currPage = newNum;
|
|
await InvokeAsync(ReloadData);
|
|
}
|
|
|
|
protected async Task SortRequested(Sorter.SortCallBack e)
|
|
{
|
|
sortField = e.ParamName;
|
|
sortAsc = e.IsAscending;
|
|
await ReloadData();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua toggle selezione globale delle righe mostrateGpwDataService gDataServprivate async Task ReloadData
|
|
/// </summary>
|
|
protected void ToggleSelection()
|
|
{
|
|
allSel = !allSel;
|
|
foreach (var item in ListRecords)
|
|
{
|
|
item.Selected = allSel;
|
|
}
|
|
}
|
|
protected bool HasRowSelected
|
|
{
|
|
get => ListRecords != null && ListRecords.Count(x => x.Selected) > 0;
|
|
//get => ListRecords != null && ListRecords.Where(x => x.Selected).Count() > 0;
|
|
}
|
|
|
|
protected async void ToggleUid(string uid)
|
|
{
|
|
if (ListUidSel.Contains(uid))
|
|
{
|
|
ListUidSel.Remove(uid);
|
|
}
|
|
else
|
|
{
|
|
ListUidSel.Add(uid);
|
|
}
|
|
await ReloadData();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private bool allSel = false;
|
|
private string gridKey = "ApprovTimbMan";
|
|
private bool sortAsc = true;
|
|
private string sortField = "";
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private int currPage { get; set; } = 1;
|
|
private string CurrSearch { get; set; } = "";
|
|
private bool filtDip { get; set; } = false;
|
|
|
|
private bool isLoading { get; set; } = false;
|
|
private List<DipendentiModel> ListDipendenti { get; set; } = new List<DipendentiModel>();
|
|
|
|
private List<TimbratureDTO>? ListRecords { get; set; } = null;
|
|
private List<string> ListUidSel { get; set; } = new List<string>();
|
|
private int numRecord { get; set; } = 10;
|
|
private List<TimbratureDTO>? SearchRecords { get; set; } = null;
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async void AppMServ_EA_SearchUpdated()
|
|
{
|
|
CurrSearch = AppMServ.SearchVal;
|
|
await ReloadData();
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
currPage = 1;
|
|
isLoading = true;
|
|
ListRecords = null;
|
|
try
|
|
{
|
|
var rawData = await GDataServ.TimbratureRichieste();
|
|
SearchRecords = rawData
|
|
.Where(x => (IdxDipSel == 0 || x.IdxDipendente == IdxDipSel))
|
|
.Select(x => new TimbratureDTO(x))
|
|
.ToList();
|
|
#if false
|
|
// verifico filtro per IdxDip
|
|
if (IdxDipSel > 0)
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => x.IdxDipendente == IdxDipSel).ToList();
|
|
}
|
|
#endif
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error($"Eccezione in recupero dati{Environment.NewLine}{ex}");
|
|
}
|
|
totalCount = SearchRecords.Count;
|
|
SortTable();
|
|
isLoading = false;
|
|
}
|
|
|
|
private void SortTable()
|
|
{
|
|
if (SearchRecords != null)
|
|
{
|
|
// se ho ordinamento riordino...
|
|
if (!string.IsNullOrEmpty(sortField))
|
|
{
|
|
switch (sortField)
|
|
{
|
|
case "Dipendente":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.DipNav.Abbrev).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.DipNav.Abbrev).ToList();
|
|
}
|
|
break;
|
|
|
|
case "DataOra":
|
|
if (sortAsc)
|
|
{
|
|
SearchRecords = SearchRecords.OrderBy(x => x.DataOra).ToList();
|
|
}
|
|
else
|
|
{
|
|
SearchRecords = SearchRecords.OrderByDescending(x => x.DataOra).ToList();
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// filtro x display
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
else
|
|
{
|
|
ListRecords = new List<TimbratureDTO>();
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |