1978 lines
78 KiB
C#
1978 lines
78 KiB
C#
using EgwCoreLib.Utils;
|
|
using GPW.CORE.Data.DbModels;
|
|
using GPW.CORE.Data.DTO;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using NLog;
|
|
|
|
namespace GPW.CORE.Data.Controllers
|
|
{
|
|
public class GPWController : IDisposable
|
|
{
|
|
#region Public Constructors
|
|
|
|
public GPWController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Recupera l'elenco Clienti (tutti)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagClientiModel> AnagClientiAll()
|
|
{
|
|
// init dati necessari
|
|
List<AnagClientiModel> dbResult = new List<AnagClientiModel>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set...
|
|
dbResult = localDbCtx
|
|
.DbSetAnagClienti
|
|
.OrderBy(x => x.RagSociale)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagClientiAll:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cerca un device dato il suo secret
|
|
/// </summary>
|
|
/// <param name="devSecret"></param>
|
|
/// <returns></returns>
|
|
public AnagDeviceModel? AnagDeviceByKey(string devSecret)
|
|
{
|
|
// init dati necessari
|
|
AnagDeviceModel? dbResult = new AnagDeviceModel();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set...
|
|
dbResult = localDbCtx
|
|
.DbSetAnagDevices
|
|
.Where(x => x.DeviceSecret == devSecret)
|
|
.FirstOrDefault();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagDeviceByKey:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Crea un record device
|
|
/// </summary>
|
|
/// <param name="newRecord"></param>
|
|
/// <returns></returns>
|
|
public bool AnagDeviceInsert(AnagDeviceModel newRecord)
|
|
{
|
|
// init dati necessari
|
|
bool done = false;
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
localDbCtx
|
|
.DbSetAnagDevices
|
|
.Add(newRecord);
|
|
// ora salvo!
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagDeviceInsert:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Crea un record device
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
/// <returns></returns>
|
|
public bool AnagDeviceUpdate(AnagDeviceModel currItem)
|
|
{
|
|
// init dati necessari
|
|
bool done = false;
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
if (currItem.IdxDevice == 0)
|
|
{
|
|
localDbCtx.Entry(currItem).State = EntityState.Added;
|
|
}
|
|
else
|
|
{
|
|
// recupero vecchio
|
|
var oldRec = localDbCtx
|
|
.DbSetAnagDevices
|
|
.Where(x => x.IdxDevice == currItem.IdxDevice)
|
|
.FirstOrDefault();
|
|
if (oldRec != null)
|
|
{
|
|
oldRec.LastIpv4 = currItem.LastIpv4;
|
|
oldRec.DataOraLastSeen = DateTime.Now;
|
|
oldRec.Description = currItem.Description;
|
|
oldRec.ScreenSize = currItem.ScreenSize;
|
|
localDbCtx
|
|
.DbSetAnagDevices
|
|
.Update(oldRec);
|
|
}
|
|
// altrimenti aggiungo
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetAnagDevices
|
|
.Update(currItem);
|
|
}
|
|
}
|
|
// ora salvo!
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagDeviceUpdate:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera l'elenco delle fasi (tutte)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagFasiModel> AnagFasiAll(bool onlyActive)
|
|
{
|
|
// init dati necessari
|
|
List<AnagFasiModel> dbResult = new List<AnagFasiModel>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set...
|
|
dbResult = localDbCtx
|
|
.DbSetAnagFasi
|
|
.Where(x => (x.ProgettoNav != null && x.ProgettoNav.Attivo == true) && (((bool)x.Attivo == true && onlyActive == true) || !onlyActive))
|
|
.Include(p => p.ProgettoNav)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagFasiAll:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera singola fase
|
|
/// </summary>
|
|
/// <param name="idxFase"></param>
|
|
/// <returns></returns>
|
|
public AnagFasiModel AnagFasiByKey(int idxFase)
|
|
{
|
|
// init dati necessari
|
|
AnagFasiModel dbResult = new AnagFasiModel();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set...
|
|
var searchRecord = localDbCtx
|
|
.DbSetAnagFasi
|
|
.Where(x => x.IdxFase == idxFase)
|
|
.Include(p => p.ProgettoNav)
|
|
.FirstOrDefault();
|
|
if (searchRecord != null)
|
|
{
|
|
dbResult = searchRecord;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagFasiByKey:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco fasi dato chiave progetto
|
|
/// </summary>
|
|
/// <param name="idxProj"></param>
|
|
/// <returns></returns>
|
|
public List<AnagFasiModel> AnagFasiByProj(int idxProj)
|
|
{
|
|
// init dati necessari
|
|
List<AnagFasiModel> dbResult = new List<AnagFasiModel>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set...
|
|
dbResult = localDbCtx
|
|
.DbSetAnagFasi
|
|
.Where(x => x.IdxProgetto == idxProj)
|
|
.Include(p => p.ProgettoNav)
|
|
.OrderBy(x => x.CodFase)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagFasiByProj:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco Giustificativi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<AnagGiustModel> AnagGiust()
|
|
{
|
|
// init dati necessari
|
|
List<AnagGiustModel> dbResult = new List<AnagGiustModel>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set...
|
|
dbResult = localDbCtx
|
|
.DbSetAnagGiust
|
|
.OrderBy(x => x.codGiust)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagGiust:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<AnagGruppiModel> AnagGruppiAll()
|
|
{
|
|
// init dati necessari
|
|
List<AnagGruppiModel> dbResult = new List<AnagGruppiModel>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set...
|
|
dbResult = localDbCtx
|
|
.DbSetAnagGruppi
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagGruppiAll:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<AnagGruppiModel> AnagGruppiUser(int idxDipendente)
|
|
{
|
|
// init dati necessari
|
|
List<AnagGruppiModel> dbResult = new List<AnagGruppiModel>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set...
|
|
dbResult = localDbCtx
|
|
.DbSetAnagGruppi
|
|
.Where(x => x.Dipendenti2GruppiNav.Contains(new Dipendenti2GruppiModel() { IdxDipendente = idxDipendente, Gruppo = x.Gruppo }))
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagGruppiUser:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<AnagKeyValueModel> AnagKeyValGetAll()
|
|
{
|
|
List<AnagKeyValueModel> dbResult = new List<AnagKeyValueModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetAnagKeyValue
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dati orario del dipendente indicato
|
|
/// </summary>
|
|
/// <param name="idxProj"></param>
|
|
/// <returns></returns>
|
|
public AnagOrariModel AnagOrarioByDip(int idxDip)
|
|
{
|
|
AnagOrariModel? dbResult = new AnagOrariModel();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set....
|
|
dbResult = localDbCtx
|
|
.DbSetAnagOrari
|
|
.Where(x => x.DipendentiNav.Count > 0 && x.DipendentiNav.First().IdxDipendente == idxDip)
|
|
.FirstOrDefault();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagOrarioByDip:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new AnagOrariModel();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tabella setup dati orari - elenco completo
|
|
/// </summary>
|
|
/// <param name="idxProj"></param>
|
|
/// <returns></returns>
|
|
public List<AnagOrariModel> AnagOrarioGetAll()
|
|
{
|
|
List<AnagOrariModel> dbResult = new List<AnagOrariModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set....
|
|
dbResult = localDbCtx
|
|
.DbSetAnagOrari
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagOrarioGetAll:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new List<AnagOrariModel>();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<AnagProgettiModel> AnagProjAll(bool onlyActive)
|
|
{
|
|
// init dati necessari
|
|
List<AnagProgettiModel> dbResult = new List<AnagProgettiModel>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set....
|
|
dbResult = localDbCtx
|
|
.DbSetAnagProgetti
|
|
.Where(x => ((bool)(x.Attivo ?? false) == true && onlyActive == true) || !onlyActive)
|
|
.Include(c => c.ClienteNav)
|
|
.Include(g => g.GruppiNav)
|
|
.OrderBy(x => x.NomeProj)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in AnagProjAll:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Vista dati per FASE con totalizzaizone ore budget/real
|
|
/// </summary>
|
|
/// <param name="idxFase"></param>
|
|
/// <returns></returns>
|
|
public CalcOreFasiModel CalcOreFase(int idxFase)
|
|
{
|
|
CalcOreFasiModel dbResult = new CalcOreFasiModel();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
var parIdxFase = new SqlParameter("@idxFase", idxFase);
|
|
|
|
var rawResult = localDbCtx
|
|
.DbSetCalcOreFasi
|
|
.FromSqlRaw("EXEC stp_AF_getByIdxFase_Child @idxFase", parIdxFase)
|
|
.ToList();
|
|
if (rawResult != null && rawResult.Count > 0)
|
|
{
|
|
dbResult = rawResult[0];
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Vista dati per progetto con totalizzaizone ore budget/real
|
|
/// </summary>
|
|
/// <param name="idxProj"></param>
|
|
/// <returns></returns>
|
|
public CalcOreProgettiModel CalcOreProj(int idxProj)
|
|
{
|
|
CalcOreProgettiModel dbResult = new CalcOreProgettiModel();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
var idxProgetto = new SqlParameter("@idxProgetto", idxProj);
|
|
|
|
var rawResult = localDbCtx
|
|
.DbSetCalcOreProj
|
|
.FromSqlRaw("EXEC stp_AP_getByIdxPrj @idxProgetto", idxProgetto)
|
|
.ToList();
|
|
if (rawResult != null && rawResult.Count > 0)
|
|
{
|
|
dbResult = rawResult[0];
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista chiusure aziendali dato periodo
|
|
/// </summary>
|
|
/// <param name="dtStart"></param>
|
|
/// <param name="dtEnd"></param>
|
|
/// <returns></returns>
|
|
public List<CalFesteFerieModel> CalFestFeriePeriodo(DateTime dtStart, DateTime dtEnd)
|
|
{
|
|
List<CalFesteFerieModel> dbResult = new List<CalFesteFerieModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetCalFesteFerie
|
|
.Where(x => x.data >= dtStart && x.data <= dtEnd)
|
|
.OrderBy(x => x.data)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera l'elenco dei Rilievi temperatura nel periodo indicato x dipendente
|
|
/// </summary>
|
|
/// <param name="idxDipendente">Dipendente interessato</param>
|
|
/// <param name="dtInizio">Data di riferimento (ultima/corrente)</param>
|
|
/// <param name="dtFine">NUm settimane precedenti da recuperare</param>
|
|
/// <returns></returns>
|
|
public List<CheckVc19Model> CheckVC19List(int idxDipendente, DateTime dtInizio, DateTime dtFine)
|
|
{
|
|
// init dati necessari
|
|
List<CheckVc19Model> dbResult = new List<CheckVc19Model>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetCheckVc19
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DtCheck && x.DtCheck <= dtFine)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista configurazione
|
|
/// </summary>
|
|
/// <param name="dtStart"></param>
|
|
/// <param name="dtEnd"></param>
|
|
/// <returns></returns>
|
|
public List<ConfigModel> ConfigGetAll()
|
|
{
|
|
List<ConfigModel> dbResult = new List<ConfigModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetConfig
|
|
.OrderBy(x => x.chiave)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Recupera l'elenco delle ultime attività inserite da un dipendente
|
|
/// </summary>
|
|
/// <param name="idxDipendente">Dipendente interessato</param>
|
|
/// <param name="numRec">Num record da recuperare</param>
|
|
/// <returns></returns>
|
|
public List<RegAttivitaModel> UserLastRec(int idxDipendente, int numRec)
|
|
{
|
|
List<RegAttivitaModel> listRec = new List<RegAttivitaModel>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
listRec = localDbCtx
|
|
.DbSetRegAttivita
|
|
.Where(x => x.IdxDipendente == idxDipendente)
|
|
.Include(a => a.FasiNav).ThenInclude(p => p.ProgettoNav).ThenInclude(c => c.ClienteNav)
|
|
.OrderByDescending(x => x.IdxRa)
|
|
.Take(numRec)
|
|
.AsNoTracking()
|
|
.ToList();
|
|
}
|
|
return listRec;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera l'elenco dei dettagli giornalieri attività di un dipendente, dato periodo riferimento
|
|
/// </summary>
|
|
/// <param name="idxDipendente">Dipendente interessato</param>
|
|
/// <param name="dtInizio">Data di riferimento (ultima/corrente)</param>
|
|
/// <param name="dtFine">NUm settimane precedenti da recuperare</param>
|
|
/// <returns></returns>
|
|
public List<DailyDataDTO> DailyDetails(int idxDipendente, DateTime dtInizio, DateTime dtFine)
|
|
{
|
|
// init dati necessari
|
|
List<DailyDataDTO> dbResult = new List<DailyDataDTO>();
|
|
List<TimbratureExplModel> rawTimbExp = new List<TimbratureExplModel>();
|
|
List<TimbratureModel> rawTimbr = new List<TimbratureModel>();
|
|
List<RegAttivitaModel> rawRegAtt = new List<RegAttivitaModel>();
|
|
List<RilievoTempModel> rawRilTemp = new List<RilievoTempModel>();
|
|
List<CheckVc19Model> rawCheckC19 = new List<CheckVc19Model>();
|
|
|
|
// fermate/festività/ferie
|
|
List<CalFesteFerieModel> rawFermateAz = new List<CalFesteFerieModel>();
|
|
List<RegMalattieModel> rawMalattie = new List<RegMalattieModel>();
|
|
List<RegRichiesteModel> rawRichDip = new List<RegRichiesteModel>();
|
|
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
// recupero intero set dati timbrature e attività....
|
|
rawTimbExp = localDbCtx
|
|
.DbSetTimbratureExpl
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DataLav && x.DataLav <= dtFine)
|
|
.ToList();
|
|
|
|
rawTimbr = localDbCtx
|
|
.DbSetTimbrature
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DataOra && x.DataOra <= dtFine.AddDays(1))
|
|
.ToList();
|
|
|
|
rawRegAtt = localDbCtx
|
|
.DbSetRegAttivita
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.Inizio && x.Inizio <= dtFine.AddDays(1))
|
|
.Include(a => a.FasiNav).ThenInclude(p => p.ProgettoNav).ThenInclude(c => c.ClienteNav)
|
|
.ToList();
|
|
|
|
rawRilTemp = localDbCtx
|
|
.DbSetRilievoTemp
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DtRilievo && x.DtRilievo <= dtFine.AddDays(1))
|
|
.ToList();
|
|
|
|
rawCheckC19 = localDbCtx
|
|
.DbSetCheckVc19
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DtCheck && x.DtCheck <= dtFine.AddDays(1))
|
|
.ToList();
|
|
|
|
// recupero fermate e malattie/permessi del dipendente...
|
|
rawFermateAz = localDbCtx
|
|
.DbSetCalFesteFerie
|
|
.Where(x => x.data >= dtInizio && x.data <= dtFine)
|
|
.ToList();
|
|
rawMalattie = localDbCtx
|
|
.DbSetRegMalattie
|
|
.Where(x => (x.DtInizio >= dtInizio && x.DtInizio <= dtFine) || (x.DtInizio.AddDays(x.NumGG) >= dtInizio.AddDays(x.NumGG) && x.DtInizio <= dtFine))
|
|
.ToList();
|
|
rawRichDip = localDbCtx
|
|
.DbSetRegRichieste
|
|
.Where(x => (idxDipendente == 0 || x.IdxDipendente == idxDipendente) && ((x.DtStart >= dtInizio && x.DtStart <= dtFine) || (x.DtStart <= dtInizio && dtFine <= x.DtEnd) || (x.DtEnd >= dtInizio && x.DtEnd <= dtFine)))
|
|
.ToList();
|
|
|
|
// calcolo intervallo date...
|
|
int numDays = dtFine.Subtract(dtInizio).Days;
|
|
|
|
// x ogni giorno scompongo il set di info...
|
|
for (int i = 0; i <= numDays; i++)
|
|
{
|
|
DateTime thisDay = dtInizio.AddDays(i);
|
|
DailyDataDTO currDayDto = new DailyDataDTO()
|
|
{
|
|
IdxDipendente = idxDipendente,
|
|
DtRif = thisDay,
|
|
ListRA = rawRegAtt
|
|
.Where(x => thisDay <= x.Inizio && x.Inizio < thisDay.AddDays(1))
|
|
.OrderBy(x => x.Inizio)
|
|
.ToList(),
|
|
ListTimbr = rawTimbr
|
|
.Where(x => thisDay <= x.DataOra && x.DataOra < thisDay.AddDays(1))
|
|
.OrderBy(x => x.DataOra)
|
|
.ToList(),
|
|
TimbrExpl = rawTimbExp
|
|
.Where(x => thisDay == x.DataLav)
|
|
.FirstOrDefault(),
|
|
ListRilTemp = rawRilTemp
|
|
.Where(x => thisDay <= x.DtRilievo && x.DtRilievo < thisDay.AddDays(1))
|
|
.ToList(),
|
|
ListCheckC19 = rawCheckC19
|
|
.Where(x => thisDay <= x.DtCheck && x.DtCheck < thisDay.AddDays(1))
|
|
.ToList(),
|
|
ListFermateAzienda = rawFermateAz
|
|
.Where(x => thisDay == x.data)
|
|
.ToList(),
|
|
ListMalattie = rawMalattie
|
|
.Where(x => thisDay >= x.DtInizio && thisDay <= x.DtInizio.AddDays(x.NumGG))
|
|
.ToList(),
|
|
ListFerieDip = rawRichDip
|
|
.Where(x => x.CodGiust == "FER" && (thisDay >= x.DtStart && thisDay <= x.DtEnd))
|
|
.ToList(),
|
|
ListRichiesteDip = rawRichDip
|
|
.Where(x => x.CodGiust != "FER" && (thisDay.Date == x.DtStart.Date))
|
|
.ToList()
|
|
};
|
|
|
|
dbResult.Add(currDayDto);
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera l'elenco dei dettaglio giornaliero attività di tutti i dipendenti, dato giorno riferimento
|
|
/// </summary>
|
|
/// <param name="dtRif">Data di riferimento</param>
|
|
/// <returns></returns>
|
|
public List<DailyDataDTO> DailyDetailAllDip(DateTime dtRif)
|
|
{
|
|
//resetto valoredtRif a giornata (mezzanotte)
|
|
dtRif = dtRif.Date;
|
|
// init dati necessari
|
|
List<DailyDataDTO> dbResult = new List<DailyDataDTO>();
|
|
List<TimbratureExplModel> rawTimbExp = new List<TimbratureExplModel>();
|
|
List<TimbratureModel> rawTimbr = new List<TimbratureModel>();
|
|
List<RegAttivitaModel> rawRegAtt = new List<RegAttivitaModel>();
|
|
List<RilievoTempModel> rawRilTemp = new List<RilievoTempModel>();
|
|
List<CheckVc19Model> rawCheckC19 = new List<CheckVc19Model>();
|
|
|
|
// fermate/festività/ferie
|
|
List<CalFesteFerieModel> rawFermateAz = new List<CalFesteFerieModel>();
|
|
List<RegMalattieModel> rawMalattie = new List<RegMalattieModel>();
|
|
List<RegRichiesteModel> rawRichDip = new List<RegRichiesteModel>();
|
|
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
// recupero intero set dati timbrature e attività....
|
|
rawTimbExp = localDbCtx
|
|
.DbSetTimbratureExpl
|
|
.Where(x => dtRif == x.DataLav)
|
|
.ToList();
|
|
|
|
rawTimbr = localDbCtx
|
|
.DbSetTimbrature
|
|
.Where(x => dtRif == x.DataOra.Date)
|
|
.ToList();
|
|
|
|
rawRegAtt = localDbCtx
|
|
.DbSetRegAttivita
|
|
.Where(x => dtRif == x.Inizio.Date)
|
|
.Include(a => a.FasiNav).ThenInclude(p => p.ProgettoNav).ThenInclude(c => c.ClienteNav)
|
|
.ToList();
|
|
|
|
rawRilTemp = localDbCtx
|
|
.DbSetRilievoTemp
|
|
.Where(x => dtRif <= x.DtRilievo.Date)
|
|
.ToList();
|
|
|
|
rawCheckC19 = localDbCtx
|
|
.DbSetCheckVc19
|
|
.Where(x => dtRif <= x.DtCheck.Date)
|
|
.ToList();
|
|
|
|
// recupero fermate e malattie/permessi del dipendente...
|
|
rawFermateAz = localDbCtx
|
|
.DbSetCalFesteFerie
|
|
.Where(x => x.data == dtRif)
|
|
.ToList();
|
|
rawMalattie = localDbCtx
|
|
.DbSetRegMalattie
|
|
.Where(x => x.DtInizio.Date <= dtRif && x.DtInizio.AddDays(x.NumGG) >= dtRif)
|
|
.ToList();
|
|
rawRichDip = localDbCtx
|
|
.DbSetRegRichieste
|
|
.Where(x => x.DtStart.Date <= dtRif && x.DtEnd >= dtRif)
|
|
.ToList();
|
|
|
|
// calcolo elenco DIP
|
|
List<int> listDip = rawTimbExp.Select(x => x.IdxDipendente).Distinct().ToList();
|
|
|
|
// x ogni giorno scompongo il set di info...
|
|
foreach (var idxDip in listDip)
|
|
{
|
|
DailyDataDTO currDayDto = new DailyDataDTO()
|
|
{
|
|
IdxDipendente = idxDip,
|
|
DtRif = dtRif,
|
|
ListRA = rawRegAtt
|
|
.Where(x => x.IdxDipendente == idxDip)
|
|
.OrderBy(x => x.Inizio)
|
|
.ToList(),
|
|
ListTimbr = rawTimbr
|
|
.Where(x => x.IdxDipendente == idxDip)
|
|
.OrderBy(x => x.DataOra)
|
|
.ToList(),
|
|
TimbrExpl = rawTimbExp
|
|
.Where(x => x.IdxDipendente == idxDip)
|
|
.FirstOrDefault(),
|
|
ListRilTemp = rawRilTemp
|
|
.Where(x => x.IdxDipendente == idxDip)
|
|
.ToList(),
|
|
ListCheckC19 = rawCheckC19
|
|
.Where(x => x.IdxDipendente == idxDip)
|
|
.ToList(),
|
|
ListFermateAzienda = rawFermateAz,
|
|
ListMalattie = rawMalattie
|
|
.Where(x => x.IdxDipendente == idxDip)
|
|
.ToList(),
|
|
ListFerieDip = rawRichDip
|
|
.Where(x => x.IdxDipendente == idxDip)
|
|
.ToList(),
|
|
ListRichiesteDip = rawRichDip
|
|
.Where(x => x.IdxDipendente == idxDip)
|
|
.ToList()
|
|
};
|
|
|
|
dbResult.Add(currDayDto);
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public bool DbForceMigrate()
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
localDbCtx.DbForceMigrate();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in DbForceMigrate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera record anomalie dipendenti
|
|
/// </summary>
|
|
/// <param name="inizio"></param>
|
|
/// <param name="fine"></param>
|
|
/// <param name="notOkApp"></param>
|
|
/// <param name="notOkTim"></param>
|
|
/// <param name="notOkLav"></param>
|
|
/// <returns></returns>
|
|
public List<DipendendiAndAnomalie> DipAndAnomGetAll(DateTime inizio, DateTime fine, bool notOkApp, bool notOkTim, bool notOkLav)
|
|
{
|
|
List<DipendendiAndAnomalie> dbResult = new List<DipendendiAndAnomalie>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
SqlParameter parInizio = new SqlParameter("@inizio", inizio);
|
|
SqlParameter parFine = new SqlParameter("@fine", fine);
|
|
SqlParameter parNotOkApp = new SqlParameter("@notOkApp", notOkApp);
|
|
SqlParameter parNotOkTim = new SqlParameter("@notOkTim", notOkTim);
|
|
SqlParameter parNotOkLav = new SqlParameter("@notOkLav", notOkLav);
|
|
|
|
var rawResult = localDbCtx
|
|
.DbSetDipAndAnom
|
|
.FromSqlRaw("EXEC stp_DipendentiAndAnomalie @inizio,@fine,@notOkApp,@notOkTim,@notOkLav", parInizio, parFine, parNotOkApp, parNotOkTim, parNotOkLav)
|
|
.ToList();
|
|
if (rawResult == null)
|
|
{
|
|
dbResult = new List<DipendendiAndAnomalie>();
|
|
}
|
|
else
|
|
{
|
|
dbResult = rawResult;
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<Dipendenti2RuoliModel> Dipendenti2RuoliGetAll()
|
|
{
|
|
List<Dipendenti2RuoliModel> dbResult = new List<Dipendenti2RuoliModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetDip2Ruoli
|
|
.Include(o => o.DipNav)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<DipendentiModel> DipendentiGetAll()
|
|
{
|
|
List<DipendentiModel> dbResult = new List<DipendentiModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetDipendenti
|
|
.Include(o => o.OrarioNav)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public bool DipendentiUpdate(DipendentiModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
if (currItem.IdxDipendente > 0)
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetDipendenti
|
|
.FirstOrDefault(x => x.IdxDipendente == currItem.IdxDipendente);
|
|
if (currRec != null)
|
|
{
|
|
currRec.Cognome = currItem.Cognome;
|
|
currRec.Nome = currItem.Nome;
|
|
currRec.AuthKey = currItem.AuthKey;
|
|
currRec.Cf = currItem.Cf;
|
|
currRec.Email = currItem.Email;
|
|
currRec.DataNascita = currItem.DataNascita;
|
|
currRec.LuogoNascita = currItem.LuogoNascita;
|
|
|
|
localDbCtx
|
|
.DbSetDipendenti
|
|
.Update(currRec);
|
|
}
|
|
// altrimenti aggiungo
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetDipendenti
|
|
.Update(currItem);
|
|
}
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in DipendentiUpdate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Log.Info("Dispose di GPWController");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Imposta stato di una fase
|
|
/// </summary>
|
|
/// <param name="idxFase">ID</param>
|
|
/// <param name="isActive">
|
|
/// Stato attivo true/false (se è amster -_> aggiorna sottofasi x trigger su DB
|
|
/// </param>
|
|
/// <returns></returns>
|
|
public async Task<bool> FasiSetActive(int idxFase, bool isActive)
|
|
{
|
|
// init dati necessari
|
|
bool fatto = false;
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// recupero intero set...
|
|
var dbResult = localDbCtx
|
|
.DbSetAnagFasi
|
|
.Where(x => x.IdxFase == idxFase)
|
|
.FirstOrDefault();
|
|
if (dbResult != null)
|
|
{
|
|
dbResult.Attivo = isActive;
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Errore in FasiSetActive:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
await Task.Delay(1);
|
|
return fatto;
|
|
}
|
|
|
|
public List<CheckVc19Model> GetChecksVC19(int maxNum)
|
|
{
|
|
List<CheckVc19Model> dbResult = new List<CheckVc19Model>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
int numRec = localDbCtx
|
|
.DbSetCheckVc19
|
|
.Count();
|
|
|
|
// se ho meno record che quelli richiesti --> riduco
|
|
maxNum = numRec > maxNum ? maxNum : numRec;
|
|
|
|
dbResult = localDbCtx
|
|
.DbSetCheckVc19
|
|
.OrderByDescending(x => x.DtCheck)
|
|
.Take(maxNum)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<CheckVc19Model> GetChecksVC19Filt(int idxDip, DateTime dtStart, DateTime dtEnd)
|
|
{
|
|
List<CheckVc19Model> dbResult = new List<CheckVc19Model>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
dbResult = localDbCtx
|
|
.DbSetCheckVc19
|
|
.Where(x => (idxDip == 0 || x.IdxDipendente == idxDip) && (x.DtCheck >= dtStart && x.DtCheck <= dtEnd))
|
|
.OrderByDescending(x => x.DtCheck)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public bool InsertCheck(DCCDecode updItem, string clientIp)
|
|
{
|
|
bool done = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
int idxDip = 0;
|
|
DipendentiModel? currUser = new DipendentiModel()
|
|
{
|
|
IdxDipendente = 0
|
|
};
|
|
// per prima cosa cerca il dipendente x cognome/nome...
|
|
var userList = localDbCtx
|
|
.DbSetDipendenti
|
|
.Where(x => x.Cognome.ToUpper() == updItem.nam.fn.ToUpper() && x.Nome.ToUpper() == updItem.nam.gn.ToUpper())
|
|
.ToList();
|
|
// se ne ho solo 1 ok...
|
|
if (userList.Count > 1)
|
|
{
|
|
currUser = userList
|
|
.Where(x => x.DataNascita != null && updItem.dob.Date == ((DateTime)x.DataNascita).Date)
|
|
.FirstOrDefault();
|
|
}
|
|
// altrimenti cerco anche con DOB...
|
|
else if (userList.Count == 1)
|
|
{
|
|
// se lo trova inserisce check...
|
|
currUser = userList[0];
|
|
}
|
|
|
|
if (currUser != null)
|
|
{
|
|
// fisso dipendente
|
|
idxDip = currUser.IdxDipendente;
|
|
}
|
|
|
|
string rawPayload = JsonConvert.SerializeObject(updItem);
|
|
CheckVc19Model newItem = new CheckVc19Model()
|
|
{
|
|
IdxDipendente = idxDip,
|
|
DtCheck = DateTime.Now,
|
|
Cognome = updItem.nam.fn.ToUpper(),
|
|
Nome = updItem.nam.gn.ToUpper(),
|
|
Payload = rawPayload,
|
|
Dob = updItem.dob.Date
|
|
};
|
|
// aggiungo!
|
|
localDbCtx
|
|
.DbSetCheckVc19
|
|
.Add(newItem);
|
|
|
|
// ora salvo!
|
|
localDbCtx.SaveChanges();
|
|
|
|
// se trovato procedo ANCHE x timbratura
|
|
if (idxDip > 0)
|
|
{
|
|
// verifico se ho timbratura ingresso
|
|
var listTimbra = localDbCtx
|
|
.DbSetTimbrature
|
|
.Where(x => x.IdxDipendente == idxDip && x.DataOra.Date == DateTime.Today && x.Entrata == true)
|
|
.ToList();
|
|
// se non ci fosse aggiungo
|
|
if (listTimbra == null || listTimbra.Count == 0)
|
|
{
|
|
var newIngresso = new TimbratureModel()
|
|
{
|
|
IdxDipendente = idxDip,
|
|
DataOra = DateTime.Now,
|
|
CodTipoTimb = "Web",
|
|
Ipv4 = clientIp,
|
|
Entrata = true,
|
|
Approv = true
|
|
};
|
|
|
|
// aggiungo!
|
|
localDbCtx
|
|
.DbSetTimbrature
|
|
.Add(newIngresso);
|
|
}
|
|
// ora salvo!
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
// altrimenti NON FA NULLA
|
|
else
|
|
{
|
|
Log.Info($"Attenzione, dipendente non trovato: {updItem.nam.fn} {updItem.nam.gn}");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in InsertCheck:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
public bool InsertManual(int idxDip, string clientIp)
|
|
{
|
|
bool done = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
// se trovato procedo
|
|
if (idxDip > 0)
|
|
{
|
|
string rawPayload = "MANUAL";
|
|
CheckVc19Model newItem = new CheckVc19Model()
|
|
{
|
|
IdxDipendente = idxDip,
|
|
DtCheck = DateTime.Now,
|
|
Payload = rawPayload
|
|
};
|
|
// aggiungo!
|
|
localDbCtx
|
|
.DbSetCheckVc19
|
|
.Add(newItem);
|
|
|
|
// ora salvo!
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
// altrimenti NON FA NULLA
|
|
else
|
|
{
|
|
Log.Info($"Attenzione, dipendente non trovato: {idxDip}");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in InsertManual:{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco pareto progetti ordinati da filtro
|
|
/// </summary>
|
|
/// <param name="idxDip"></param>
|
|
/// <param name="dataStart"></param>
|
|
/// <param name="dataEnd"></param>
|
|
/// <param name="maxResult"></param>
|
|
/// <returns></returns>
|
|
public List<ParetoRegAttModel> ParetoRegAtt(int idxDip, DateTime dataStart, DateTime dataEnd, int maxResult)
|
|
{
|
|
List<ParetoRegAttModel> dbResult = new List<ParetoRegAttModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
var idxDipendente = new SqlParameter("@idxDipendente", idxDip);
|
|
var inizio = new SqlParameter("@inizio", dataStart);
|
|
var fine = new SqlParameter("@fine", dataEnd);
|
|
var maxRes = new SqlParameter("@maxRes", maxResult);
|
|
|
|
dbResult = localDbCtx
|
|
.DbSetParetoRegAtt
|
|
.FromSqlRaw("EXEC stp_freqProjByDipPeriodo @idxDipendente, @inizio,@fine,@maxRes", idxDipendente, inizio, fine, maxRes)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Righe presenze giornaliere
|
|
/// </summary>
|
|
/// <param name="dtRif">DataOra riferimento per richiesta presenze</param>
|
|
/// <returns></returns>
|
|
public List<StatsDayPresModel> PresenzeDay(DateTime dtRif)
|
|
{
|
|
List<StatsDayPresModel> dbResult = new List<StatsDayPresModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
var idxProgetto = new SqlParameter("@dataRif", dtRif);
|
|
|
|
dbResult = localDbCtx
|
|
.DbSetStatsDayPres
|
|
.FromSqlRaw("EXEC stp_statsDayPres @dataRif", idxProgetto)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public bool RegAttDelete(RegAttivitaModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
localDbCtx.Remove(currItem);
|
|
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RegAttUpdate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera ultima attività dipendente
|
|
/// </summary>
|
|
/// <param name="IdxDipendente"></param>
|
|
/// <param name="onlyActive">cerca ultima solo tra attive (=true) o tutte (=false)</param>
|
|
/// <returns></returns>
|
|
public RegAttivitaModel RegAttLastByDip(int IdxDipendente, bool onlyActive)
|
|
{
|
|
RegAttivitaModel? dbResult = new RegAttivitaModel();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetRegAttivita
|
|
.Where(x => x.FasiNav.Attivo || !onlyActive)
|
|
.OrderByDescending(x => x.Inizio)
|
|
.FirstOrDefault(x => x.IdxDipendente == IdxDipendente);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RegAttLastByDip{Environment.NewLine}{exc}");
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new RegAttivitaModel();
|
|
}
|
|
}
|
|
if (dbResult == null)
|
|
{
|
|
dbResult = new RegAttivitaModel();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Insert/Update attività
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
/// <returns></returns>
|
|
public bool RegAttUpdate(RegAttivitaModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
if (currItem.IdxRa == 0)
|
|
{
|
|
localDbCtx.Entry(currItem).State = EntityState.Added;
|
|
}
|
|
else
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetRegAttivita
|
|
.FirstOrDefault(x => x.IdxRa == currItem.IdxRa);
|
|
if (currRec != null)
|
|
{
|
|
currRec.IdxDipendente = currItem.IdxDipendente;
|
|
currRec.IdxFase = currItem.IdxFase;
|
|
currRec.Inizio = currItem.Inizio;
|
|
currRec.Fine = currItem.Fine;
|
|
currRec.Descrizione = currItem.Descrizione;
|
|
|
|
|
|
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
|
|
|
localDbCtx
|
|
.DbSetRegAttivita
|
|
.Update(currRec);
|
|
}
|
|
// altrimenti aggiungo
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetRegAttivita
|
|
.Update(currItem);
|
|
}
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RegAttUpdate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera eventi dato criteri filtro
|
|
/// </summary>
|
|
/// <param name="inizio"></param>
|
|
/// <param name="fine"></param>
|
|
/// <param name="evento"></param>
|
|
/// <returns></returns>
|
|
public List<RegistroEventiModel> RegEventiGetFilt(DateTime inizio, DateTime fine, string evento)
|
|
{
|
|
List<RegistroEventiModel> dbResult = new List<RegistroEventiModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
dbResult = localDbCtx
|
|
.DbSetRegEventi
|
|
.Where(x => x.DataOra >= inizio && x.DataOra <= fine && (string.IsNullOrEmpty(evento) || x.Evento == evento))
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Insert/Update di un record in Registro Eventi
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
/// <returns></returns>
|
|
public bool RegEventiUpdate(RegistroEventiModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetRegEventi
|
|
.FirstOrDefault(x => x.DataOra == currItem.DataOra && x.Evento == currItem.Evento);
|
|
if (currRec != null)
|
|
{
|
|
currRec.Evento = currItem.Evento;
|
|
currRec.Commento = currItem.Commento;
|
|
|
|
localDbCtx
|
|
.DbSetRegEventi
|
|
.Update(currRec);
|
|
}
|
|
// altrimenti aggiungo
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetRegEventi
|
|
.Add(currItem);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RegEventiUpdate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elimina record registro malattie (SE non confermato)
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
public bool RegMalattieDelete(RegMalattieModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetRegMalattie
|
|
.FirstOrDefault(x => x.IdxRegMal == currItem.IdxRegMal && !x.Conf);
|
|
if (currRec != null)
|
|
{
|
|
localDbCtx
|
|
.DbSetRegMalattie
|
|
.Remove(currRec);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RegMalattieDelete{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// recupera elenco reg malattie del dipendente
|
|
/// </summary>
|
|
/// <param name="maxRecord"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public List<RegMalattieModel> RegMalattieGetAll(int maxRecord)
|
|
{
|
|
List<RegMalattieModel> dbResult = new List<RegMalattieModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
dbResult = localDbCtx
|
|
.DbSetRegMalattie
|
|
.Include(d => d.DipNav)
|
|
.OrderByDescending(x => x.DtInizio)
|
|
.Take(maxRecord)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// recupera elenco reg malattie del dipendente
|
|
/// </summary>
|
|
/// <param name="idxDipendente"></param>
|
|
/// <param name="maxRecord"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public List<RegMalattieModel> RegMalattieGetByDip(int idxDipendente, int maxRecord)
|
|
{
|
|
List<RegMalattieModel> dbResult = new List<RegMalattieModel>();
|
|
if (idxDipendente > 0)
|
|
{
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
dbResult = localDbCtx
|
|
.DbSetRegMalattie
|
|
.Where(x => x.IdxDipendente == idxDipendente)
|
|
.Include(d => d.DipNav)
|
|
.OrderByDescending(x => x.DtInizio)
|
|
.Take(maxRecord)
|
|
.ToList();
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserisce/Aggiorna record registro malattie
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
public bool RegMalattieUpsert(RegMalattieModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetRegMalattie
|
|
.FirstOrDefault(x => x.IdxRegMal == currItem.IdxRegMal);
|
|
if (currRec != null)
|
|
{
|
|
// aggiorno i campi
|
|
currRec.IdxDipendente = currItem.IdxDipendente;
|
|
currRec.DtInizio = currItem.DtInizio;
|
|
currRec.NumGG = currItem.NumGG;
|
|
currRec.CodCert = currItem.CodCert ?? "ND";
|
|
currRec.Conf = currItem.Conf;
|
|
|
|
localDbCtx
|
|
.DbSetRegMalattie
|
|
.Update(currRec);
|
|
}
|
|
// altrimenti aggiungo
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetRegMalattie
|
|
.Add(currItem);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RegMalattieUpsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elimina record registro richieste (SE non confermato)
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
public bool RegRichiesteDelete(RegRichiesteModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetRegRichieste
|
|
.FirstOrDefault(x => x.IdxRegRich == currItem.IdxRegRich && !x.Conf);
|
|
if (currRec != null)
|
|
{
|
|
localDbCtx
|
|
.DbSetRegRichieste
|
|
.Remove(currRec);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RegRichiesteDelete{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// recupera elenco reg richieste del dipendente
|
|
/// </summary>
|
|
/// <param name="idxDipendente"></param>
|
|
/// <param name="dtFrom">Inizio periodo richiesto</param>
|
|
/// <param name="dtTo">Fine periodo richiesto</param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public List<RegRichiesteModel> RegRichiesteGetByDip(int idxDipendente, DateTime dtFrom, DateTime dtTo)
|
|
{
|
|
List<RegRichiesteModel> dbResult = new List<RegRichiesteModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
DateTime oggi = DateTime.Today;
|
|
dbResult = localDbCtx
|
|
.DbSetRegRichieste
|
|
.Where(x => (idxDipendente == 0 || x.IdxDipendente == idxDipendente) && (x.DtStart >= dtFrom && x.DtStart <= dtTo))
|
|
.Include(d => d.DipNav)
|
|
.OrderByDescending(x => x.DtStart)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inserisce/Aggiorna record registro richieste
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
public bool RegRichiesteUpsert(RegRichiesteModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetRegRichieste
|
|
.FirstOrDefault(x => x.IdxRegRich == currItem.IdxRegRich);
|
|
if (currRec != null)
|
|
{
|
|
// aggiorno i campi
|
|
currRec.IdxDipendente = currItem.IdxDipendente;
|
|
currRec.DtStart = currItem.DtStart;
|
|
currRec.DtEnd = currItem.DtEnd;
|
|
currRec.CodGiust = currItem.CodGiust;
|
|
currRec.Note = currItem.Note ?? "";
|
|
currRec.Conf = currItem.Conf;
|
|
|
|
localDbCtx
|
|
.DbSetRegRichieste
|
|
.Update(currRec);
|
|
}
|
|
// altrimenti aggiungo
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetRegRichieste
|
|
.Add(currItem);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RegRichiesteUpsert{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera l'elenco dei dettagli attività e timbrature di un dipendente, dato periodo riferimento
|
|
/// </summary>
|
|
/// <param name="idxDipendente">Dipendente interessato</param>
|
|
/// <param name="periodo">Periodo di riferimento</param>
|
|
/// <returns></returns>
|
|
public ReportDataDTO ReportDetails(int idxDipendente, DtUtils.Periodo periodo)
|
|
{
|
|
// init dati necessari
|
|
DateTime dtInizio = periodo.Inizio;
|
|
DateTime dtFine = periodo.Fine;
|
|
ReportDataDTO dbResult = new ReportDataDTO();
|
|
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
// recupero intero set dati timbrature e attività....
|
|
dbResult.TimbrExpl = localDbCtx
|
|
.DbSetTimbratureExpl
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DataLav && x.DataLav <= dtFine)
|
|
.ToList();
|
|
|
|
dbResult.ListTimbr = localDbCtx
|
|
.DbSetTimbrature
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DataOra && x.DataOra <= dtFine.AddDays(1))
|
|
.ToList();
|
|
|
|
dbResult.ListRA = localDbCtx
|
|
.DbSetRegAttivita
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.Inizio && x.Inizio <= dtFine.AddDays(1))
|
|
.Include(a => a.FasiNav).ThenInclude(p => p.ProgettoNav).ThenInclude(c => c.ClienteNav)
|
|
.ToList();
|
|
|
|
// effettuo calcoli!
|
|
dbResult.DoCalc();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera l'elenco dei Rilievi temperatura nel periodo indicato x dipendente
|
|
/// </summary>
|
|
/// <param name="idxDipendente">Dipendente interessato</param>
|
|
/// <param name="dtInizio">Data di riferimento (ultima/corrente)</param>
|
|
/// <param name="dtFine">NUm settimane precedenti da recuperare</param>
|
|
/// <returns></returns>
|
|
public List<RilievoTempModel> RilTempList(int idxDipendente, DateTime dtInizio, DateTime dtFine)
|
|
{
|
|
// init dati necessari
|
|
List<RilievoTempModel> dbResult = new List<RilievoTempModel>();
|
|
// cerco su DB recuperando set di dati....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetRilievoTemp
|
|
.Where(x => x.IdxDipendente == idxDipendente && dtInizio <= x.DtRilievo && x.DtRilievo <= dtFine)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public bool RilTempUpdate(RilievoTempModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetRilievoTemp
|
|
.FirstOrDefault(x => x.IdxDipendente == currItem.IdxDipendente && x.DtRilievo == currItem.DtRilievo);
|
|
if (currRec != null)
|
|
{
|
|
// aggiorno solo entrata/uscita
|
|
currRec.TempRil = currItem.TempRil;
|
|
|
|
localDbCtx
|
|
.DbSetRilievoTemp
|
|
.Update(currRec);
|
|
}
|
|
// altrimenti aggiungo
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetRilievoTemp
|
|
.Add(currItem);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in RilTempUpdate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Annulla modifiche su una specifica entity (cancel update)
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public bool rollBackEntity(object item)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
if (localDbCtx.Entry(item).State == EntityState.Deleted || localDbCtx.Entry(item).State == EntityState.Modified)
|
|
{
|
|
localDbCtx.Entry(item).Reload();
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera record anomalie dipendenti
|
|
/// </summary>
|
|
/// <param name="idxDipendente">singolo idx oppure 0 = tutti</param>
|
|
/// <param name="dataFrom"></param>
|
|
/// <param name="dataTo"></param>
|
|
/// <param name="inatt"></param>
|
|
/// <param name="showWE"></param>
|
|
/// <param name="maxErrMin"></param>
|
|
/// <param name="maxErrPlus"></param>
|
|
/// <returns></returns>
|
|
public List<TeRaExplModel> TeRaExplGetAll(int idxDipendente, DateTime dataFrom, DateTime dataTo, bool inatt, bool showWE, int maxErrMin, int maxErrPlus)
|
|
{
|
|
List<TeRaExplModel> dbResult = new List<TeRaExplModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
SqlParameter parIdxDip = new SqlParameter("@idxDipendente", idxDipendente);
|
|
SqlParameter parDataFrom = new SqlParameter("@dataFrom", dataFrom);
|
|
SqlParameter parDataTo = new SqlParameter("@dataTo", dataTo);
|
|
SqlParameter parInatt = new SqlParameter("@parInatt", inatt);
|
|
SqlParameter parShowWE = new SqlParameter("@showWE", showWE);
|
|
SqlParameter parMaxErrMin = new SqlParameter("@maxErrMin", maxErrMin);
|
|
SqlParameter parMaxErrPlus = new SqlParameter("@maxErrPlus", maxErrPlus);
|
|
|
|
dbResult = localDbCtx
|
|
.DbSetTeRaExpl
|
|
.FromSqlRaw("EXEC stp_TE_RA_ByUserDate @idxDipendente,@dataFrom,@dataTo,@parInatt,@showWE,@maxErrMin,@maxErrPlus", parIdxDip, parDataFrom, parDataTo, parInatt, parShowWE, parMaxErrMin, parMaxErrPlus)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera record anomalie dipendenti
|
|
/// </summary>
|
|
/// <param name="idxDipendente">singolo idx oppure 0 = tutti</param>
|
|
/// <param name="inizio"></param>
|
|
/// <param name="fine"></param>
|
|
/// <param name="notOkApp"></param>
|
|
/// <param name="notOkTim"></param>
|
|
/// <param name="notOkLav"></param>
|
|
/// <returns></returns>
|
|
public List<TimbratureExplModel> TimbExplGetAnomalie(int idxDipendente, DateTime inizio, DateTime fine, bool notOkApp, bool notOkTim, bool notOkLav)
|
|
{
|
|
List<TimbratureExplModel> dbResult = new List<TimbratureExplModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
SqlParameter parIdxDip = new SqlParameter("@idxDipendente", idxDipendente);
|
|
SqlParameter parInizio = new SqlParameter("@inizio", inizio);
|
|
SqlParameter parFine = new SqlParameter("@fine", fine);
|
|
SqlParameter parNotOkApp = new SqlParameter("@notOkApp", notOkApp);
|
|
SqlParameter parNotOkTim = new SqlParameter("@notOkTim", notOkTim);
|
|
SqlParameter parNotOkLav = new SqlParameter("@notOkLav", notOkLav);
|
|
|
|
dbResult = localDbCtx
|
|
.DbSetTimbratureExpl
|
|
.FromSqlRaw("EXEC stp_timbratureExpl_getByAnomalia @idxDipendente,@inizio,@fine,@notOkApp,@notOkTim,@notOkLav", parIdxDip, parInizio, parFine, parNotOkApp, parNotOkTim, parNotOkLav)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera record anomalie dipendenti x orario continuato
|
|
/// </summary>
|
|
/// <param name="idxDipendente">singolo idx oppure 0 = tutti</param>
|
|
/// <param name="inizio"></param>
|
|
/// <param name="fine"></param>
|
|
/// <returns></returns>
|
|
public List<TimbratureExplModel> TimbExplGetContinuato(int idxDipendente, DateTime inizio, DateTime fine)
|
|
{
|
|
List<TimbratureExplModel> dbResult = new List<TimbratureExplModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
SqlParameter parIdxDip = new SqlParameter("@idxDipendente", idxDipendente);
|
|
SqlParameter parInizio = new SqlParameter("@inizio", inizio);
|
|
SqlParameter parFine = new SqlParameter("@fine", fine);
|
|
|
|
dbResult = localDbCtx
|
|
.DbSetTimbratureExpl
|
|
.FromSqlRaw("EXEC stp_timbratureExpl_getContinuato @idxDipendente,@inizio,@fine", parIdxDip, parInizio, parFine)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco timbrature successive alla data odierna x ogni dipendente (x recupero errori
|
|
/// timbrature future)
|
|
/// - per il check imposta la mezzanotte del giorno successivo
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<TimbratureModel> TimbratureAnomalieFuture()
|
|
{
|
|
// imposta data a domani
|
|
DateTime dateRif = DateTime.Today.AddDays(1);
|
|
List<TimbratureModel> dbResult = new List<TimbratureModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetTimbrature
|
|
.Where(x => x.DataOra.Date >= dateRif.Date)
|
|
.OrderBy(x => x.IdxDipendente)
|
|
.ThenByDescending(x => x.DataOra)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in TimbratureAnomalieFuture{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<TimbratureModel> TimbratureDay(DateTime dateRif, int IdxDip)
|
|
{
|
|
List<TimbratureModel> dbResult = new List<TimbratureModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetTimbrature
|
|
.Where(x => x.DataOra.Date == dateRif.Date && x.IdxDipendente == IdxDip)
|
|
.OrderByDescending(x => x.DataOra)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in TimbratureDay{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public bool TimbratureDelete(TimbratureModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
localDbCtx.Remove(currItem);
|
|
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in TimbratureDelete{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco di tutte le timbrature richieste (= NON approvate)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<TimbratureModel> TimbratureRichieste()
|
|
{
|
|
List<TimbratureModel> dbResult = new List<TimbratureModel>();
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetTimbrature
|
|
.Where(x => x.Approv == false)
|
|
.Include(d => d.DipNav)
|
|
.OrderByDescending(x => x.DataOra)
|
|
.ToList();
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in TimbratureRichieste{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public bool TimbratureUpdate(TimbratureModel currItem)
|
|
{
|
|
bool answ = false;
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetTimbrature
|
|
.FirstOrDefault(x => x.IdxDipendente == currItem.IdxDipendente && x.DataOra == currItem.DataOra);
|
|
if (currRec != null)
|
|
{
|
|
// aggiorno solo entrata/uscita
|
|
currRec.Entrata = currItem.Entrata;
|
|
currRec.Approv = currItem.Approv;
|
|
currRec.Ipv4 = currItem.Ipv4;
|
|
currRec.DataOra = currItem.DataOra;
|
|
|
|
localDbCtx
|
|
.DbSetTimbrature
|
|
.Update(currRec);
|
|
}
|
|
// altrimenti aggiungo
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetTimbrature
|
|
.Add(currItem);
|
|
}
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in TimbratureUpdate{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera overview di un periodo settimanale x dipendente, data riferimento, numero
|
|
/// settimane precedenti
|
|
/// </summary>
|
|
/// <param name="idxDipendente">Dipendente interessato</param>
|
|
/// <param name="dtRif">Data di riferimento (ultima/corrente)</param>
|
|
/// <param name="numWeek">NUm settimane precedenti da recuperare</param>
|
|
/// <returns></returns>
|
|
public List<WeekStatDTO> WeekOverview(int idxDipendente, DateTime dtRif, int numWeek)
|
|
{
|
|
// init dati necessari
|
|
List<WeekStatDTO> dbResult = new List<WeekStatDTO>();
|
|
List<WeekData> weekList = new List<WeekData>();
|
|
|
|
// aggiungo sett corrente + quelle richieste...
|
|
for (int i = numWeek; i >= 0; i--)
|
|
{
|
|
var currWeek = new WeekData(dtRif.AddDays(-i * 7));
|
|
weekList.Add(currWeek);
|
|
}
|
|
|
|
// cerco su DB settimana x settimana....
|
|
using (GPWContext localDbCtx = new GPWContext(_configuration))
|
|
{
|
|
foreach (var item in weekList)
|
|
{
|
|
var totOreTim = localDbCtx
|
|
.DbSetTimbratureExpl
|
|
.Where(x => x.IdxDipendente == idxDipendente && x.DataLav >= item.inizio && x.DataLav <= item.fine)
|
|
.Sum(x => (double)x.HLav);
|
|
var totMinLav = localDbCtx
|
|
.DbSetRegAttivitaExpl
|
|
.Where(x => x.IdxDipendente == idxDipendente && x.DataLav >= item.inizio && x.DataLav <= item.fine)
|
|
.Sum(x => (int)x.MinRegAtt);
|
|
|
|
// aggiungo alla lista...
|
|
var weekData = new WeekStatDTO()
|
|
{
|
|
IdxDipendente = idxDipendente,
|
|
Anno = item.anno,
|
|
WeekNumber = item.weekNumber,
|
|
Inizio = item.inizio,
|
|
Fine = item.fine,
|
|
SumOreLav = totOreTim,
|
|
SumOreComm = (double)totMinLav / 60,
|
|
};
|
|
dbResult.Add(weekData);
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration = null!;
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |