429 lines
14 KiB
C#
429 lines
14 KiB
C#
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.DTO;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace GPW.CORE.UI.Components
|
|
{
|
|
public partial class DayHoriz
|
|
{
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// record prima timbratura x
|
|
/// </summary>
|
|
protected DateTime FirstTimb = DateTime.Now;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Private Properties
|
|
|
|
private bool noData { get => DayDTO == null || DayDTO.ListRA == null || DayDTO.ListRA.Count == 0; }
|
|
|
|
private bool OkTemp
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
if (DayDTO != null && DayDTO.ListRilTemp != null)
|
|
{
|
|
answ = DayDTO.ListRilTemp.Count > 0;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private bool OkVC19
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
if (DayDTO != null && DayDTO.ListCheckC19 != null)
|
|
{
|
|
answ = DayDTO.ListCheckC19.Count > 0;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private Double oreComm
|
|
{
|
|
get
|
|
{
|
|
double answ = 0;
|
|
if (DayDTO != null && DayDTO.ListRA != null)
|
|
{
|
|
answ = (double)DayDTO.ListRA.Sum(x => x.OreTot);
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private Double oreLav
|
|
{
|
|
get
|
|
{
|
|
double answ = 0;
|
|
if (DayDTO != null && DayDTO.TimbrExpl != null && DayDTO.TimbrExpl.HLav != null)
|
|
{
|
|
answ = (double)DayDTO.TimbrExpl.HLav;
|
|
if (DayDTO.DtRif == DateTime.Today)
|
|
{
|
|
if (DayDTO.ListTimbr != null)
|
|
{
|
|
// aggiungo ultima timb fino ad adesso...
|
|
var lastIn = DayDTO.ListTimbr.Where(x => x.Entrata == true).OrderByDescending(x => x.DataOra).FirstOrDefault();
|
|
var lastOut = DayDTO.ListTimbr.Where(x => x.Entrata == false).OrderByDescending(x => x.DataOra).FirstOrDefault();
|
|
// se MANCA timb uscita finale...
|
|
if (lastIn != null)
|
|
{
|
|
if (lastOut == null || lastOut.DataOra < lastIn.DataOra)
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
answ += adesso.Subtract(lastIn.DataOra).TotalHours;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private int periodo
|
|
{
|
|
get
|
|
{
|
|
int answ = 1;
|
|
if (DayDTO != null)
|
|
{
|
|
answ = EndHour - StartHour;
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private decimal tempRil
|
|
{
|
|
get
|
|
{
|
|
decimal answ = 0;
|
|
if (OkTemp)
|
|
{
|
|
answ = DayDTO.ListRilTemp[0].TempRil;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
private string TotComm
|
|
{
|
|
get
|
|
{
|
|
TimeSpan tSpan = TimeSpan.FromHours(oreComm);
|
|
return $"{tSpan.Hours}h {tSpan.Minutes}'";
|
|
}
|
|
}
|
|
|
|
private string TotLav
|
|
{
|
|
get
|
|
{
|
|
TimeSpan tSpan = TimeSpan.FromHours(oreLav);
|
|
return $"{tSpan.Hours}h {tSpan.Minutes}'";
|
|
}
|
|
}
|
|
|
|
#endregion Private Properties
|
|
|
|
#region Public Properties
|
|
|
|
public string cssBadgeLav
|
|
{
|
|
get
|
|
{
|
|
string bCtr = "btn";
|
|
string answ = $"{bCtr}-light";
|
|
var deltaComm = oreComm - oreLav;
|
|
if (Math.Abs(deltaComm) < 0.5)
|
|
{
|
|
answ = $"{bCtr}-info";
|
|
}
|
|
else if (Math.Abs(deltaComm) < 1)
|
|
{
|
|
answ = $"{bCtr}-warning";
|
|
}
|
|
else
|
|
{
|
|
answ = $"{bCtr}-danger";
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
public string cssCheck
|
|
{
|
|
get => OkVC19 ? "text-success" : "text-secondary";
|
|
}
|
|
|
|
public string cssThermo
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
// verifico in base a ok temp o meno...
|
|
if (OkTemp)
|
|
{
|
|
// colore in base al valore...
|
|
var currTemp = tempRil;
|
|
if (currTemp != null)
|
|
{
|
|
if (currTemp >= (decimal)37.5)
|
|
{
|
|
answ = "text-danger";
|
|
}
|
|
else if (currTemp >= 37)
|
|
{
|
|
answ = "text-warning";
|
|
}
|
|
else
|
|
{
|
|
answ = "text-success";
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
answ = "text-secondary";
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
[Parameter]
|
|
public DailyDataDTO? DayDTO { get; set; }
|
|
|
|
[Parameter]
|
|
public bool EnableActionMenu { get; set; } = true;
|
|
|
|
[Parameter]
|
|
public int EndHour { get; set; }
|
|
|
|
[Parameter]
|
|
public int IdxDipSel { get; set; } = 0;
|
|
|
|
[Parameter]
|
|
public bool IsTitle { get; set; } = false;
|
|
|
|
[Parameter]
|
|
public EventCallback<RegAttivitaModel> ItemSelected { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<RegAttivitaModel> ItemUpdated { get; set; }
|
|
|
|
[Parameter]
|
|
public List<AnagFasiModel> ListFasi { get; set; } = null!;
|
|
|
|
[Parameter]
|
|
public EventCallback<List<TimbratureModel>?> PeriodSelected { get; set; }
|
|
|
|
[Parameter]
|
|
public EventCallback<DateTime> ReqTempList { get; set; }
|
|
|
|
[Parameter]
|
|
public int StartHour { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Private Methods
|
|
|
|
private List<CORE.Data.DbModels.RegAttivitaModel> ListRegAtt()
|
|
{
|
|
// init
|
|
DateTime currHour = DayDTO.DtRif.AddHours(StartHour);
|
|
DateTime lastHour = DayDTO.DtRif.AddHours(EndHour);
|
|
List<CORE.Data.DbModels.RegAttivitaModel> result = new List<CORE.Data.DbModels.RegAttivitaModel>();
|
|
// ciclo partendo dal primo evento ed aggiungendo eventuali periodi in testa / coda / intermedi
|
|
foreach (var item in DayDTO.ListRA)
|
|
{
|
|
// se evento > ora corrente --> aggiungo vuoto...
|
|
if (item.Inizio > currHour)
|
|
{
|
|
CORE.Data.DbModels.RegAttivitaModel? newItem = new CORE.Data.DbModels.RegAttivitaModel()
|
|
{
|
|
Inizio = currHour,
|
|
IdxFase = 0,
|
|
Descrizione = "-",
|
|
Fine = item.Inizio,
|
|
OreTot = (decimal)item.Inizio.Subtract(currHour).TotalHours
|
|
};
|
|
result.Add(newItem);
|
|
}
|
|
|
|
// ...altrimenti parto con lui...
|
|
result.Add(item);
|
|
currHour = item.Fine;
|
|
}
|
|
// se non sono in fondo --> aggiungo!
|
|
if (currHour < lastHour)
|
|
{
|
|
CORE.Data.DbModels.RegAttivitaModel? newItem = new CORE.Data.DbModels.RegAttivitaModel()
|
|
{
|
|
Inizio = currHour,
|
|
IdxFase = 0,
|
|
Descrizione = "-",
|
|
Fine = lastHour,
|
|
OreTot = (decimal)lastHour.Subtract(currHour).TotalHours
|
|
};
|
|
result.Add(newItem);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
private List<PeriodoDTO> ListTimb()
|
|
{
|
|
// init
|
|
List<PeriodoDTO> result = new List<PeriodoDTO>();
|
|
if (DayDTO != null)
|
|
{
|
|
// limiti estremi visualizzazione
|
|
DateTime currHour = DayDTO.DtRif.AddHours(StartHour);
|
|
DateTime lastHour = DayDTO.DtRif.AddHours(EndHour);
|
|
int idxTimb = 0;
|
|
if (DayDTO.ListTimbr != null)
|
|
{
|
|
// divido tra ingressi e uscite
|
|
var timbIN = DayDTO.ListTimbr.Where(x => x.Entrata == true).ToList();
|
|
var timbOUT = DayDTO.ListTimbr.Where(x => x.Entrata == false).ToList();
|
|
DateTime fineLav = currHour;
|
|
|
|
// sistemo la prima timbratura
|
|
if (timbIN.Count > 0)
|
|
{
|
|
var firstRec = timbIN.OrderBy(x => x.DataOra).FirstOrDefault();
|
|
if (firstRec != null)
|
|
{
|
|
FirstTimb = CORE.Data.Utils.DateRounded(firstRec.DataOra, 5, false);
|
|
}
|
|
}
|
|
|
|
// ciclo partendo dal primo evento timbratura IN ed aggiungendo eventuali periodi in testa / coda / intermedi
|
|
foreach (var item in timbIN)
|
|
{
|
|
bool isClosed = true;
|
|
// se evento > ora corrente --> aggiungo vuoto...
|
|
if (item.DataOra > currHour)
|
|
{
|
|
PeriodoDTO emptyPeriod = new PeriodoDTO()
|
|
{
|
|
Inizio = currHour,
|
|
Fine = item.DataOra,
|
|
Tipo = CORE.Data.TipoPeriodo.ND,
|
|
OreTot = (decimal)item.DataOra.Subtract(currHour).TotalHours,
|
|
IsClosed = true
|
|
};
|
|
result.Add(emptyPeriod);
|
|
}
|
|
|
|
// ...processo cercando uscita relativa oppure NOW
|
|
if (timbOUT.Count > idxTimb)
|
|
{
|
|
fineLav = timbOUT[idxTimb].DataOra;
|
|
}
|
|
else
|
|
{
|
|
DateTime adesso = DateTime.Now;
|
|
int minRound = ((int)Math.Floor((double)adesso.Minute / 5)) * 5;
|
|
fineLav = DateTime.Today.AddHours(adesso.Hour).AddMinutes(minRound);
|
|
isClosed = false;
|
|
}
|
|
PeriodoDTO workPeriod = new PeriodoDTO()
|
|
{
|
|
Inizio = item.DataOra,
|
|
Fine = fineLav,
|
|
Tipo = CORE.Data.TipoPeriodo.Lavoro,
|
|
OreTot = (decimal)fineLav.Subtract(item.DataOra).TotalHours,
|
|
IsClosed = isClosed
|
|
};
|
|
result.Add(workPeriod);
|
|
idxTimb++;
|
|
currHour = fineLav;
|
|
}
|
|
// se non sono in fondo --> aggiungo!
|
|
if (currHour < lastHour)
|
|
{
|
|
PeriodoDTO emptyPeriod = new PeriodoDTO()
|
|
{
|
|
Inizio = currHour,
|
|
Fine = lastHour,
|
|
Tipo = CORE.Data.TipoPeriodo.ND,
|
|
OreTot = (decimal)lastHour.Subtract(currHour).TotalHours,
|
|
IsClosed = true
|
|
};
|
|
result.Add(emptyPeriod);
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion Private Methods
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Indico item selezionato
|
|
/// </summary>
|
|
protected async void PeriodoSelected(PeriodoDTO selPeriodo)
|
|
{
|
|
if (DayDTO != null)
|
|
{
|
|
await PeriodSelected.InvokeAsync(DayDTO.ListTimbr);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indico item selezionato
|
|
/// </summary>
|
|
protected async void ReportCloned()
|
|
{
|
|
await ItemSelected.InvokeAsync(null);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indico item selezionato
|
|
/// </summary>
|
|
protected async void ReportSelected(RegAttivitaModel selRecord)
|
|
{
|
|
await ItemSelected.InvokeAsync(selRecord);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Indico item aggiornato
|
|
/// </summary>
|
|
protected async void ReportUpdated()
|
|
{
|
|
await ItemUpdated.InvokeAsync(null);
|
|
}
|
|
|
|
protected async void SelTemperature()
|
|
{
|
|
if (DayDTO != null)
|
|
{
|
|
await ReqTempList.InvokeAsync(DayDTO.DtRif);
|
|
}
|
|
}
|
|
|
|
protected async void SelTimbrature()
|
|
{
|
|
if (DayDTO != null)
|
|
{
|
|
await PeriodSelected.InvokeAsync(DayDTO.ListTimbr);
|
|
}
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
}
|
|
} |