384 lines
11 KiB
C#
384 lines
11 KiB
C#
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.Services;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.JSInterop;
|
|
using NLog;
|
|
using static EgwCoreLib.Razor.Toggler;
|
|
|
|
namespace GPW.CORE.ADM.Components.Compo
|
|
{
|
|
public partial class RegRichieste
|
|
{
|
|
#region Public Properties
|
|
|
|
[Parameter]
|
|
public bool isLoading
|
|
{
|
|
get => loading;
|
|
set => loading = value;
|
|
}
|
|
|
|
[Parameter]
|
|
public int months { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<bool> ReportUpdate { get; set; }
|
|
|
|
[Parameter]
|
|
public bool ShowNeedConf { get; set; } = false;
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Protected Properties
|
|
|
|
[Inject]
|
|
protected MessageService AppMServ { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected GpwDataService GDataServ { get; set; } = null!;
|
|
|
|
protected int IdxDipendente { get; set; } = 0;
|
|
|
|
[Inject]
|
|
protected IJSRuntime JSRuntime { get; set; } = null!;
|
|
|
|
protected bool loading
|
|
{
|
|
get => _loading;
|
|
set
|
|
{
|
|
if (_loading != value)
|
|
{
|
|
_loading = value;
|
|
var pUpd = Task.Run(async () => await ReloadData());
|
|
pUpd.Wait();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
protected List<int> PageSizeListSpec = new List<int>() { 5, 10, 15, 20 };
|
|
|
|
#region Protected Methods
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
ToggleData = new SelectGlobalToggle()
|
|
{
|
|
leftString = "Da approvare",
|
|
rightString = "Tutti",
|
|
placardCss = "bg-dark border-dark text-light"
|
|
};
|
|
dtInizio = new DateTime(DateTime.Today.Year, 1, 1);
|
|
dtFine = dtInizio.AddYears(2);
|
|
currRecord.IdxDipendente = AppMServ.IdxDipendente;
|
|
CodGiust = "";
|
|
var rawGiust = await GDataServ.AnagGiust();
|
|
if (rawGiust != null)
|
|
{
|
|
ListGiust = rawGiust.Where(x => x.showReq).ToList();
|
|
}
|
|
// recupero preferenze utente...
|
|
await InitUserPref();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
currPage = 1;
|
|
await ReloadData();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
private void toggleEdit()
|
|
{
|
|
showAdd = !showAdd;
|
|
}
|
|
|
|
#region Private Fields
|
|
|
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
|
private string gridKey = "RegRichieste";
|
|
private bool isSendingData = false;
|
|
private List<AnagGiustModel>? ListGiust = null;
|
|
private List<RegRichiesteModel>? ListRecords = null;
|
|
private List<RegRichiesteModel>? SearchRecords = null;
|
|
|
|
/// <summary>
|
|
/// Numero giorni minimo per richiesta ferie
|
|
/// </summary>
|
|
private int NumDayFerieRichAntic = 14;
|
|
|
|
/// <summary>
|
|
/// NUmero giorni massimo per richiesta permessi
|
|
/// </summary>
|
|
private int NumDayPermMax = 21;
|
|
|
|
private int sendDataMaxVal = 100;
|
|
private int sendDataNextVal = 0;
|
|
private int sendDataVal = 0;
|
|
private bool showAdd = false;
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool _loading { get; set; } = false;
|
|
|
|
private string CodGiust
|
|
{
|
|
get => currRecord.CodGiust;
|
|
set
|
|
{
|
|
currRecord.CodGiust = value;
|
|
// imposto dataOra min/max da tipo cod Giust
|
|
if (value == "FER")
|
|
{
|
|
dtStart = minDate(value);
|
|
dtEnd = minDate(value);
|
|
}
|
|
else
|
|
{
|
|
int ora = DateTime.Now.Hour;
|
|
dtStart = minDate(value).AddHours(ora);
|
|
dtEnd = minDate(value).AddHours(ora + 4);
|
|
}
|
|
}
|
|
}
|
|
|
|
private int currPage { get; set; } = 1;
|
|
private RegRichiesteModel currRecord { get; set; } = new RegRichiesteModel();
|
|
|
|
private DateTime dtEnd
|
|
{
|
|
get => currRecord.DtEnd;
|
|
set
|
|
{
|
|
currRecord.DtEnd = value;
|
|
// verifico coerenza date...
|
|
if (dtStart > dtEnd)
|
|
{
|
|
dtStart = dtEnd;
|
|
}
|
|
}
|
|
}
|
|
|
|
private DateTime dtFine { get; set; } = DateTime.Today;
|
|
|
|
private DateTime dtInizio { get; set; } = DateTime.Today;
|
|
|
|
private DateTime dtStart
|
|
{
|
|
get => currRecord.DtStart;
|
|
set
|
|
{
|
|
currRecord.DtStart = value;
|
|
// verifico coerenza date...
|
|
if (dtEnd < dtStart)
|
|
{
|
|
dtEnd = dtStart;
|
|
}
|
|
}
|
|
}
|
|
|
|
private string NomeDip
|
|
{
|
|
get
|
|
{
|
|
string answ = "per cortesia";
|
|
if (AppMServ != null && AppMServ.RigaDip != null)
|
|
{
|
|
answ = $"{AppMServ.RigaDip.Nome}";
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private int numRecord { get; set; } = 10;
|
|
|
|
private int totalCount { get; set; } = 0;
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Private Methods
|
|
|
|
private async Task DoApprove(RegRichiesteModel selItem)
|
|
{
|
|
// chiedo verifica
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Confermi approvazione?"))
|
|
return;
|
|
|
|
await Task.Delay(1);
|
|
isSendingData = true;
|
|
sendDataVal = 0;
|
|
sendDataNextVal = 5;
|
|
await Task.Delay(1);
|
|
await InvokeAsync(StateHasChanged);
|
|
// effettuo insert...
|
|
sendDataVal = 5;
|
|
sendDataNextVal = 90;
|
|
await Task.Delay(1);
|
|
await GDataServ.RegRichiesteApprova(selItem);
|
|
sendDataVal = 100;
|
|
sendDataNextVal = 100;
|
|
await ReloadData();
|
|
await Task.Delay(1);
|
|
await ReportUpdate.InvokeAsync(true);
|
|
isSendingData = false;
|
|
}
|
|
|
|
private async Task DoEdit(RegRichiesteModel selItem)
|
|
{
|
|
// chiedo conferma se è scaduto..
|
|
if(selItem.DtStart < DateTime.Today)
|
|
{
|
|
if (!await JSRuntime.InvokeAsync<bool>("confirm", "Sei sicuro di voler modificare un record di una richiesta passata?"))
|
|
return;
|
|
}
|
|
|
|
currRecord = selItem;
|
|
showAdd = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// init valori da config
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task initConf()
|
|
{
|
|
// leggo conf standard giorni permessi/ferie
|
|
var sNumDayFerieRichAntic = await GDataServ.ConfigGetKey("NumDayFerieRichAntic");
|
|
if (sNumDayFerieRichAntic != null)
|
|
{
|
|
int.TryParse(sNumDayFerieRichAntic.valore, out NumDayFerieRichAntic);
|
|
}
|
|
var sNumDayPermMax = await GDataServ.ConfigGetKey("NumDayPermMax");
|
|
if (sNumDayPermMax != null)
|
|
{
|
|
int.TryParse(sNumDayPermMax.valore, out NumDayPermMax);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Init preferenze utente
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task InitUserPref()
|
|
{
|
|
try
|
|
{
|
|
numRecord = await AppMServ.NumRowGridGet(gridKey);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in InitUserPref{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Salva il record
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task DoSave()
|
|
{
|
|
isSendingData = true;
|
|
sendDataVal = 0;
|
|
sendDataNextVal = 5;
|
|
await Task.Delay(1);
|
|
// effettuo insert...
|
|
sendDataVal = 5;
|
|
sendDataNextVal = 90;
|
|
await Task.Delay(1);
|
|
await GDataServ.RegRichiesteUpsert(currRecord);
|
|
sendDataVal = 100;
|
|
sendDataNextVal = 100;
|
|
await Task.Delay(1);
|
|
showAdd = false;
|
|
await ReloadData();
|
|
await ReportUpdate.InvokeAsync(true);
|
|
isSendingData = false;
|
|
}
|
|
|
|
private DateTime maxDate(string codGiust)
|
|
{
|
|
DateTime answ = DateTime.Today.AddDays(NumDayPermMax);
|
|
switch (codGiust)
|
|
{
|
|
case "FER":
|
|
answ = new DateTime(answ.Year, answ.Month, 1).AddMonths(months);
|
|
break;
|
|
|
|
case "104":
|
|
case "PERM":
|
|
default:
|
|
DateTime.Today.AddDays(NumDayPermMax);
|
|
break;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private DateTime minDate(string codGiust)
|
|
{
|
|
DateTime answ = DateTime.Today;
|
|
switch (codGiust)
|
|
{
|
|
case "FER":
|
|
answ = DateTime.Today.AddDays(NumDayFerieRichAntic);
|
|
break;
|
|
|
|
case "104":
|
|
case "PERM":
|
|
default:
|
|
answ = DateTime.Today;
|
|
break;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
private SelectGlobalToggle ToggleData { get; set; } = new SelectGlobalToggle();
|
|
|
|
private async Task evToggled(SelectGlobalToggle newTogData)
|
|
{
|
|
ToggleData = newTogData;
|
|
await ReloadData();
|
|
}
|
|
|
|
|
|
private async Task ReloadData()
|
|
{
|
|
ListRecords = null;
|
|
await initConf();
|
|
await Task.Delay(1);
|
|
// carico richieste di TUTTI
|
|
SearchRecords = await GDataServ.RegRichiesteGetByDip(0, dtInizio, dtFine);
|
|
// filtro x tipo richieste...
|
|
if (ShowNeedConf)
|
|
{
|
|
SearchRecords = SearchRecords.Where(x => !x.Conf).ToList();
|
|
}
|
|
// conteggio!
|
|
totalCount = SearchRecords.Count;
|
|
// paginazione
|
|
ListRecords = SearchRecords
|
|
.Skip(numRecord * (currPage - 1))
|
|
.Take(numRecord)
|
|
.ToList();
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |