298 lines
9.7 KiB
C#
298 lines
9.7 KiB
C#
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.Services;
|
|
using GPW.CORE.WRKLOG.Components.Pages;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using static EgwCoreLib.Razor.Toggler;
|
|
|
|
namespace GPW.CORE.WRKLOG.Components.Compo
|
|
{
|
|
public partial class TimbrEditor
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> CloseReq { get; set; }
|
|
|
|
[Parameter]
|
|
public DateTime DataRif { get; set; }
|
|
|
|
[Parameter]
|
|
public bool IsPortrait { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> ItemReset { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> ItemUpdated { get; set; }
|
|
|
|
[Parameter]
|
|
public List<TimbratureModel> ListTimb { get; set; } = new List<TimbratureModel>();
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Fields
|
|
|
|
private SelectGlobalToggle ToggleData { get; set; } = new SelectGlobalToggle();
|
|
private void initToggler()
|
|
{
|
|
ToggleData = new SelectGlobalToggle()
|
|
{
|
|
leftString = "Entrata",
|
|
rightString = "Uscita",
|
|
placardCss = "bg-light border-light text-dark",
|
|
};
|
|
}
|
|
private async Task evToggled(SelectGlobalToggle newTogData)
|
|
{
|
|
ToggleData = newTogData;
|
|
IsUscita = ToggleData.isActive;
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
protected bool vetoUpd = false;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Protected Properties
|
|
|
|
protected bool IsUscita { get; set; } = false;
|
|
|
|
protected string txtMsgInOut
|
|
{
|
|
get => IsUscita ? "Uscita" : "Entrata";
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
protected async Task DoAdd()
|
|
{
|
|
// var accessorie / base
|
|
TimbratureModel currRecord = new TimbratureModel();
|
|
string remoteIp = "";
|
|
if (httpContextAccessor.HttpContext != null)
|
|
{
|
|
remoteIp = $"{httpContextAccessor.HttpContext.Connection?.RemoteIpAddress}";
|
|
}
|
|
if (ListTimbRich == null)
|
|
{
|
|
ListTimbRich = new List<TimbratureModel>();
|
|
}
|
|
|
|
// correzione datarif x evitare valori NON arrotondati...
|
|
DataRif = CORE.Data.Utils.DateRounded(DataRif.Date.AddHours(DataRif.Hour).AddMinutes(DataRif.Minute), 5, IsUscita);
|
|
|
|
// verifico se si trattasse di timbratura uscita da attivita' del giorno precedente...
|
|
if (IsUscita)
|
|
{
|
|
// se il giorno precedente NON fosse stato chiuso...
|
|
DateTime ieri = DataRif.Date.AddDays(-1);
|
|
List<TimbratureModel> ListTimbIeri = await GDataServ.TimbratureDay(ieri, AppMServ.IdxDipendente);
|
|
// cerco ultima, se fosse entrata...
|
|
if (ListTimbIeri != null && ListTimbIeri.Count > 0)
|
|
{
|
|
var isEntrata = false;
|
|
var ultima = ListTimbIeri.OrderByDescending(x => x.DataOra).FirstOrDefault();
|
|
if (ultima != null)
|
|
{
|
|
bool.TryParse($"{ultima.Entrata}", out isEntrata);
|
|
if (isEntrata)
|
|
{
|
|
// chiedo verifica
|
|
bool doSplit = await JSRuntime.InvokeAsync<bool>("confirm", "Sembra tu stia chiudendo un periodo iniziato in un giorno precedente, vuoi suddividere in set di timbrature per ogni giornata?");
|
|
|
|
// aggiungo chiusura alla timbratura di ieri alle 23.59
|
|
currRecord = new TimbratureModel()
|
|
{
|
|
Entrata = false,
|
|
Approv = false,
|
|
CodTipoTimb = "NoTim",
|
|
DataOra = ieri.AddDays(1).AddSeconds(-1),
|
|
IdxDipendente = AppMServ.IdxDipendente,
|
|
Ipv4 = $"{remoteIp}"
|
|
};
|
|
ListTimb.Add(currRecord);
|
|
ListTimbRich.Add(currRecord);
|
|
await GDataServ.TimbratureUpdate(currRecord);
|
|
|
|
// aggiungo apertura ad oggi
|
|
currRecord = new TimbratureModel()
|
|
{
|
|
Entrata = true,
|
|
Approv = false,
|
|
CodTipoTimb = "NoTim",
|
|
DataOra = ieri.AddDays(1),
|
|
IdxDipendente = AppMServ.IdxDipendente,
|
|
Ipv4 = $"{remoteIp}"
|
|
};
|
|
ListTimb.Add(currRecord);
|
|
ListTimbRich.Add(currRecord);
|
|
await GDataServ.TimbratureUpdate(currRecord);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
currRecord = new TimbratureModel()
|
|
{
|
|
Entrata = !IsUscita,
|
|
Approv = false,
|
|
CodTipoTimb = "NoTim",
|
|
DataOra = DataRif,
|
|
IdxDipendente = AppMServ.IdxDipendente,
|
|
Ipv4 = $"{remoteIp}"
|
|
};
|
|
|
|
// aggiungo alla lista...
|
|
ListTimb.Add(currRecord);
|
|
ListTimbRich.Add(currRecord);
|
|
// aggiorno
|
|
await GDataServ.TimbratureUpdate(currRecord);
|
|
await Task.Delay(1);
|
|
await ReloadData();
|
|
await Task.Delay(1);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indico item selezionato
|
|
/// </summary>
|
|
protected async void DoClose()
|
|
{
|
|
await CloseReq.InvokeAsync(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorno e riporto update
|
|
/// </summary>
|
|
protected async void DoDelete(TimbratureModel currRecord)
|
|
{
|
|
// chiedo verifica
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sicuro di voler eliminare la richiesta selezionata??"))
|
|
return;
|
|
|
|
// elimino dalla lista...
|
|
ListTimb.Remove(currRecord);
|
|
if (ListTimbAppr != null)
|
|
{
|
|
if (ListTimbAppr.Contains(currRecord))
|
|
{
|
|
ListTimbAppr.Remove(currRecord);
|
|
}
|
|
}
|
|
if (ListTimbRich != null)
|
|
{
|
|
if (ListTimbRich.Contains(currRecord))
|
|
{
|
|
ListTimbRich.Remove(currRecord);
|
|
}
|
|
}
|
|
|
|
// aggiorno
|
|
await GDataServ.TimbratureDelete(currRecord);
|
|
|
|
await Task.Delay(1);
|
|
|
|
await ReloadData();
|
|
|
|
await ItemUpdated.InvokeAsync(true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorno e riporto update
|
|
/// </summary>
|
|
protected async void DoUpdate(TimbratureModel currRecord)
|
|
{
|
|
// elimino da lista
|
|
ListTimb.Remove(currRecord);
|
|
|
|
// scambio
|
|
currRecord.Entrata = !currRecord.Entrata;
|
|
|
|
// aggiorno
|
|
await GDataServ.TimbratureUpdate(currRecord);
|
|
|
|
// ri-aggiungo in lista...
|
|
ListTimb.Add(currRecord);
|
|
|
|
await ReloadData();
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
initToggler();
|
|
await ReloadData();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await ReloadData();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Properties
|
|
|
|
[Inject]
|
|
private MessageService AppMServ { get; set; } = null!;
|
|
|
|
private string cssModule
|
|
{
|
|
get => IsPortrait ? "col-12" : "col-4";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Data-Ora di riferimento del blocco giornaliero corrente
|
|
/// </summary>
|
|
private string dataRifTimb
|
|
{
|
|
get => (ListTimb.FirstOrDefault()).DataOra.ToString("dddd, dd.MM.yyyy");
|
|
}
|
|
|
|
[Inject]
|
|
private GpwDataService GDataServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IHttpContextAccessor httpContextAccessor { get; set; } = null!;
|
|
|
|
[Inject]
|
|
private IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
private List<TimbratureModel>? ListTimbAppr { get; set; }
|
|
|
|
private List<TimbratureModel>? ListTimbRich { get; set; }
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
ListTimb = (ListTimb == null) ? new List<TimbratureModel>() : ListTimb;
|
|
|
|
// prendo primo record timbrature o oggi...
|
|
if (ListTimb.Count > 0)
|
|
{
|
|
var firstRec = ListTimb.FirstOrDefault();
|
|
if (firstRec != null)
|
|
{
|
|
DataRif = CORE.Data.Utils.DateRounded(firstRec.DataOra.Date.AddHours(adesso.Hour).AddMinutes(adesso.Minute), 5, false);
|
|
}
|
|
}
|
|
else if (DataRif > adesso.Date.AddDays(1).AddMinutes(-1))
|
|
{
|
|
DataRif = CORE.Data.Utils.DateRounded(DateTime.Today.AddHours(adesso.Hour).AddMinutes(adesso.Minute), 5, false);
|
|
}
|
|
await Task.Delay(1);
|
|
if (ListTimb != null)
|
|
{
|
|
ListTimbAppr = ListTimb.Where(x => x.Approv == true).OrderByDescending(x => x.DataOra).ToList();
|
|
ListTimbRich = ListTimb.Where(x => x.Approv == false).OrderByDescending(x => x.DataOra).ToList();
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |