Exemple #1
0
        public HoursOfMonth(string UserId, int Year, int Month)
        {
            this.Year = Year;
            this.Month = Month;

            // Verifico se il mese e congelato
            this.Frozen = db.MonthsFrozen.Any(x => x.Year == Year && x.Month == Month);

            //Carico le ore annuali
            this.HoursOfYear = new HoursOfYear(UserId, Year);

            var wtExcludes = new WorkType[] { WorkType.Default, WorkType.Lavoro, WorkType.Straordinario, WorkType.Viaggio, WorkType.PermessoRetribuito };
            var report = Hours.Where(x => ! wtExcludes.Contains(x.WorkTypeRegular))
                    .GroupBy(x => x.WorkTypeRegular)
                    .Select(x => new HoursReport
                    {
                        Id = (int)x.Key,
                        Description = x.Key.Description(),
                        Value = GetReport(x)
                    }).ToList();
            // Aggiungo ordinario previsto
            report.Add(new HoursReport
            {
                Id = 0,
                Description = "Ordinario Previsto",
                Value = TimeSpan.FromSeconds(Hours.Sum(x => x.Ordinary.TotalSeconds))
            });
            // Aggiungo ordinario effettuato
            report.Add(new HoursReport
            {
                Id = 1,
                Description = "Ordinario Svolto",
                Value = TimeSpan.FromSeconds(Hours.Sum(x => x.WorkTimeOrdinary.TotalSeconds))
            });
            // Aggiungo Straordinario
            if (Hours.Any(x => x.ExtraRegular > TimeSpan.Zero))
            {
                report.Add(new HoursReport
                {
                    Id = 2,
                    Description = WorkType.Straordinario.Description(),
                    Value = TimeSpan.FromSeconds(Hours.Sum(x => x.ExtraRegular.TotalSeconds))
                });
            }

            // Aggiungo le Presenze
            report.Add(new HoursReport
            {
                Id = 997,
                Description = "Presenze",
                Value = Hours.Count(x => x.Presence)
            });
            // Aggiungo la Trasferta
            var trasf = Hours.Where(x => x.OffSite);
            if (trasf.Any())
            {
                report.Add(new HoursReport
                {
                    Id = 997,
                    Description = "Trasferta",
                    Value = trasf.Count()
                });
            }
            // Aggiungo Viaggio
            if (Hours.Any(x => x.OrdersTimeTravel > TimeSpan.Zero))
            {
                report.Add(new HoursReport
                {
                    Id = 999,
                    Description = WorkType.Viaggio.Description(),
                    Value = TimeSpan.FromSeconds(Hours.Sum(x => x.OrdersTimeTravel.TotalSeconds))
                });
            }
            // Permesso retribuito
            var permes = Hours.Where(x => x.Holiday != null && x.Holiday == Holiday.Holiday_Type.Permesso);
            if (permes.Any())
            {
                report.Add(new HoursReport
                {
                    Id = 5,
                    Description = WorkType.PermessoRetribuito.Description(),
                    Value = TimeSpan.FromSeconds(permes.Sum(x => x.HolidayTime.TotalSeconds))
                });
            }
            Report = report.OrderBy(x => x.Id).ToArray();
        }