Files
2023-06-29 16:35:18 +02:00

181 lines
6.0 KiB
C#

using EgwCoreLib.Utils;
using GPW.CORE.Data.DbModels;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Net.WebSockets;
using System.Text;
using System.Threading.Tasks;
namespace GPW.CORE.Data.DTO
{
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
public class ReportDataDTO
{
public int IdxDipendente { get; set; } = 0;
public DtUtils.Periodo Periodo { get; set; } = new DtUtils.Periodo();
public List<RegAttivitaModel>? ListRA { get; set; } = null;
public List<TimbratureModel>? ListTimbr { get; set; } = null;
public List<TimbratureExplModel>? TimbrExpl { get; set; } = null;
public List<ProjData> ProjTotal { get; set; } = new List<ProjData>();
public void DoCalc()
{
// totalizzazione ore
OreComm = OreCommCalc;
OreLav = OreLavCalc;
// calcolo totali x progetto...
int idxProj = 0;
string gruppo = "";
string cliente = "";
string nomeProj = "";
string descProj = "";
decimal durItem = 0;
foreach (var recRA in ListRA)
{
idxProj = recRA.FasiNav.ProgettoNav.IdxProgetto;
gruppo = recRA.FasiNav.ProgettoNav.Gruppo;
cliente = recRA.FasiNav.ProgettoNav.ClienteNav?.RagSociale ?? $"{recRA.FasiNav.ProgettoNav.IdxCliente}";
nomeProj = recRA.FasiNav.ProgettoNav.NomeProj;
descProj = recRA.FasiNav.ProgettoNav.DescrProj;
durItem = recRA.OreTot ?? 0;
// cerco proj...
var currProj = ProjTotal.FirstOrDefault(x => x.idxProj == idxProj);
if (currProj != null)
{
currProj.TotOre += durItem;
}
else
{
ProjData newProj = new ProjData()
{
NomeProj = nomeProj,
TotOre = durItem,
idxProj = idxProj,
DescProj = descProj,
Gruppo = gruppo,
Cliente = cliente
};
ProjTotal.Add(newProj);
}
}
}
public double OreComm { get; set; } = 0;
public double OreLav { get; set; } = 0;
public double OreCommCalc
{
get
{
double answ = 0;
if (ListRA != null && ListRA.Count > 0)
{
answ = (double)ListRA.Sum(x => x.OreTot ?? 0);
}
// fix arrotondamento ai 5 minuti straight
TimeSpan tSpan = Utils.TSpanRounded(TimeSpan.FromHours(answ), 5);
answ = tSpan.TotalHours;
return answ;
}
}
public double OreLavCalc
{
get
{
double answ = 0;
if (TimbrExpl != null && TimbrExpl.Count > 0)
{
answ = (double)TimbrExpl.Sum(x => x.HLav ?? 0);
if (Periodo.Fine == DateTime.Today)
{
if (ListTimbr != null)
{
// aggiungo ultima timb fino ad adesso...
var lastIn = ListTimbr.Where(x => x.Entrata == true).OrderByDescending(x => x.DataOra).FirstOrDefault();
var lastOut = 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;
}
}
}
}
}
// fix arrotondamento ai 5 minuti x difetto
TimeSpan tSpan = Utils.TSpanRounded(TimeSpan.FromHours(answ), 5, true);
answ = tSpan.TotalHours;
return answ;
}
}
public int MinComm
{
get => (int)Math.Round(OreComm * 60);
}
public int MinLav
{
get => (int)Math.Round(OreLav * 60);
}
public string OreMinLav
{
get
{
TimeSpan durTs = TimeSpan.FromHours(OreLav);
return $"{durTs.Hours}:{durTs.Minutes:00}";
}
}
public string GiorniOreMinLav
{
get
{
TimeSpan durTs = TimeSpan.FromHours(OreLav);
return $"{durTs.Days}gg {durTs.Hours}:{durTs.Minutes:00}";
}
}
public string GiorniOreMinComm
{
get
{
TimeSpan durTs = TimeSpan.FromHours(OreComm);
return $"{durTs.Hours}:{durTs.Minutes:00}";
}
}
public string OreMinComm
{
get
{
TimeSpan durTs = TimeSpan.FromHours(OreComm);
return $"{durTs.Days}gg {durTs.Hours}:{durTs.Minutes:00}";
}
}
public class ProjData
{
public int idxProj { get; set; } = 0;
public string Gruppo { get; set; } = "";
public string Cliente { get; set; } = "";
public string NomeProj { get; set; } = "";
public string DescProj { get; set; } = "";
public decimal TotOre { get; set; } = 0;
}
}
}