public static TeamReport GetTeamReport(this UnitOfWork unit, string teamId, int year, int month, ModelFactory factory)
        {
            var employees = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).ToList();
            List <TeamMemberModel> reports = new List <TeamMemberModel>();
            decimal?hours = 0;

            var totalTeamHours = unit.Engagements.Get().Where(x => x.Team.Id == teamId)
                                 .Select(x => x.Employee)
                                 .SelectMany(x => x.Days)
                                 .Where(t => t.Date.Month == month && t.Date.Year == year)
                                 .Sum(p => p.Hours);

            DayStatisticModel statistika = new DayStatisticModel()
            {
                BusinessAbscenceDays    = 0,
                MissingEntries          = 0,
                OtherAbscenceDays       = 0,
                OvertimeHours           = 0,
                PercentageOfWorkingDays = 0,
                PublicHolidays          = 0,
                ReligiousDays           = 0,
                SickLeaveDays           = 0,
                VacationDays            = 0,
                WorkingDays             = 0
            };

            foreach (var employee in employees)
            {
                var days = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days)
                           .Where(x => x.Employee.Id == employee.Id &&
                                  x.Date.Year == year &&
                                  x.Date.Month == month);
                List <int> listDates = null;
                var        date      = new DateTime(year, month, 1);

                if (employee.BeginDate.Year == date.Year && employee.BeginDate.Month == date.Month &&
                    employee.BeginDate.Day < DateTime.DaysInMonth(year, month))
                {
                    listDates = DateTimeHelper.ListOfWorkingDays(year, month, employee.BeginDate.Day).ToList();
                }
                else
                {
                    listDates = DateTimeHelper.ListOfWorkingDays(year, month).ToList();
                }
                int workingDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days)
                                  .Where(x => x.Employee.Id == employee.Id &&
                                         x.Date.Year == year &&
                                         x.Date.Month == month &&
                                         x.Type.ToString() == "WorkingDay").Count();
                statistika.WorkingDays += workingDays;


                decimal?overtime = 0;
                foreach (var day in days)
                {
                    if (day.Hours > 8)
                    {
                        overtime += day.Hours - 8;
                    }
                    ;
                }
                ;
                statistika.OvertimeHours += overtime;

                int vacationDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                x.Date.Year == year &&
                                                                                                                                                x.Date.Month == month &&
                                                                                                                                                x.Type.ToString() == "Vacation").Count();
                statistika.VacationDays += vacationDays;

                int businessAbscenceDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                        x.Date.Year == year &&
                                                                                                                                                        x.Date.Month == month &&
                                                                                                                                                        x.Type.ToString() == "BusinessAbsence").Count();

                statistika.BusinessAbscenceDays += businessAbscenceDays;
                int publicHolidays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                  x.Date.Year == year &&
                                                                                                                                                  x.Date.Month == month &&
                                                                                                                                                  x.Type.ToString() == "PublicHoliday").Count();
                statistika.PublicHolidays += publicHolidays;

                int sickLeaveDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                 x.Date.Year == year &&
                                                                                                                                                 x.Date.Month == month &&
                                                                                                                                                 x.Type.ToString() == "SickLeave").Count();
                statistika.SickLeaveDays += sickLeaveDays;

                int religiousDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                 x.Date.Year == year &&
                                                                                                                                                 x.Date.Month == month &&
                                                                                                                                                 x.Type.ToString() == "ReligiousDay").Count();

                statistika.ReligiousDays += religiousDays;
                int otherAbsenceDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                    x.Date.Year == year &&
                                                                                                                                                    x.Date.Month == month &&
                                                                                                                                                    x.Type.ToString() == "OtherAbsence").Count();
                statistika.OtherAbscenceDays += otherAbsenceDays;

                decimal?totalhoursss = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                    x.Date.Year == year &&
                                                                                                                                                    x.Date.Month == month &&
                                                                                                                                                    x.Type.ToString() == "WorkingDay")
                                       .Select(x => x.Hours).DefaultIfEmpty(0).Sum();

                var missingEntries = (employee.BeginDate.Date > date.Date) ? 0 : listDates.Except(days.Select(x => x.Date.Day)).Count();
                statistika.MissingEntries += missingEntries;
                TeamMemberModel employeeModel = new TeamMemberModel()
                {
                    Employee = new BaseModel()
                    {
                        Id   = employee.Id,
                        Name = employee.FirstName + ' ' + employee.LastName
                    },
                    Days = new DayStatisticModel()
                    {
                        WorkingDays             = workingDays,
                        VacationDays            = vacationDays,
                        BusinessAbscenceDays    = businessAbscenceDays,
                        PublicHolidays          = publicHolidays,
                        SickLeaveDays           = sickLeaveDays,
                        ReligiousDays           = religiousDays,
                        OtherAbscenceDays       = otherAbsenceDays,
                        OvertimeHours           = overtime,
                        PercentageOfWorkingDays = Math.Round(100 * (double)workingDays / listDates.Count(), 2),
                        MissingEntries          = missingEntries,
                    },
                    TotalHours = totalhoursss
                };

                reports.Add(employeeModel);
                hours += employeeModel.TotalHours;
            }
            //foreach(var employee in reports)
            //{
            //    hours += employee.TotalHours;
            //}
            int numberOfEmployees = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Count();
            var fullworkingdays   = numberOfEmployees * DateTimeHelper.ListOfWorkingDays(year, month).Count();

            statistika.PercentageOfWorkingDays = Math.Round(100 * (double)statistika.WorkingDays / fullworkingdays);


            var report = new TeamReport()
            {
                Id   = teamId,
                Name = unit.Teams.Get(teamId).Name,
                NumberOfEmployees = numberOfEmployees,
                NumberOfProjects  = unit.Teams.Get(teamId).Projects.Count(),
                Dayss             = statistika,
                Reports           = reports,
                TotalHours        = totalTeamHours,
                Year  = year,
                Month = month
                        //Members = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(y=> GetPersonalReport(unit,y.Employee.Id, year,month,factory)).ToList()
                        //Ok(TimeUnit.GetPersonalReport(employeeId, year, month, TimeFactory));
            };

            return(report);
        }
Example #2
0
        public static TeamReport GetTeamReport(this UnitOfWork unit, string teamId, int year, int month, ModelFactory factory)
        {
            var employees = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).ToList();
            List <TeamMemberModel> reports = new List <TeamMemberModel>();
            decimal?hours           = 0;
            int     maxPossibleDays = noDaysInMonth(year, month);

            DayStatisticModel statictic = new DayStatisticModel()
            {
                BusinessAbscenceDays    = 0,
                MissingEntries          = 0,
                OtherAbscenceDays       = 0,
                OvertimeHours           = 0,
                PercentageOfWorkingDays = 0,
                PublicHolidays          = 0,
                ReligiousDays           = 0,
                SickLeaveDays           = 0,
                VacationDays            = 0,
                WorkingDays             = 0,
                MaxPossibleWorkingDays  = maxPossibleDays
            };

            var projects = unit.Projects.Get().ToList();

            foreach (var employee in employees)
            {
                decimal hoursTeam1 = 0;
                var     days       = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days)
                                     .Where(x => x.Employee.Id == employee.Id &&
                                            x.Date.Year == year &&
                                            x.Date.Month == month);
                List <int> listDates = null;
                var        date      = new DateTime(year, month, 1);

                if (employee.BeginDate.Year == date.Year && employee.BeginDate.Month == date.Month &&
                    employee.BeginDate.Day < DateTime.DaysInMonth(year, month))
                {
                    listDates = DateTimeHelper.ListOfWorkingDays(year, month, employee.BeginDate.Day).ToList();
                }
                else
                {
                    listDates = DateTimeHelper.ListOfWorkingDays(year, month).ToList();
                }

                int workingDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days)
                                  .Where(x => x.Employee.Id == employee.Id &&
                                         x.Date.Year == year &&
                                         x.Date.Month == month &&
                                         x.Type == DayType.WorkingDay).Count();

                statictic.WorkingDays += workingDays;

                //novoovovo

                //decimal totHours = 0;
                //foreach (var project in projects)
                //{
                //    var hoursPro = unit.Days.Get().Where(x => x.Date.Month == month && x.Date.Year == year).SelectMany(t => t.Tasks)
                //                         .Where(x => x.Project.Id == project.Id)
                //                         .Select(h => h.Hours)
                //                         .DefaultIfEmpty(0)
                //                         .Sum();
                //    totHours += hoursPro;
                //}

                //hoursTeam1 += totHours;


                decimal?overtime = 0;

                foreach (var day in days)
                {
                    if (day.Hours > 8)
                    {
                        overtime += day.Hours - 8;
                    }
                    ;
                }
                ;

                statictic.OvertimeHours += overtime;

                int vacationDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                x.Date.Year == year &&
                                                                                                                                                x.Date.Month == month &&
                                                                                                                                                x.Type == DayType.Vacation).Count();
                statictic.VacationDays += vacationDays;

                int businessAbscenceDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                        x.Date.Year == year &&
                                                                                                                                                        x.Date.Month == month &&
                                                                                                                                                        x.Type == DayType.BusinessAbsence).Count();

                statictic.BusinessAbscenceDays += businessAbscenceDays;

                int publicHolidays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                  x.Date.Year == year &&
                                                                                                                                                  x.Date.Month == month &&
                                                                                                                                                  x.Type == DayType.PublicHoliday).Count();

                statictic.PublicHolidays += publicHolidays;

                int sickLeaveDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                 x.Date.Year == year &&
                                                                                                                                                 x.Date.Month == month &&
                                                                                                                                                 x.Type == DayType.SickLeave).Count();

                statictic.SickLeaveDays += sickLeaveDays;

                int religiousDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                 x.Date.Year == year &&
                                                                                                                                                 x.Date.Month == month &&
                                                                                                                                                 x.Type == DayType.ReligiousDay).Count();

                statictic.ReligiousDays += religiousDays;

                int otherAbsenceDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                    x.Date.Year == year &&
                                                                                                                                                    x.Date.Month == month &&
                                                                                                                                                    x.Type == DayType.OtherAbsence).Count();

                statictic.OtherAbscenceDays += otherAbsenceDays;

                decimal?totalhoursss = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                    x.Date.Year == year &&
                                                                                                                                                    x.Date.Month == month && x.Type == DayType.WorkingDay)
                                       .Select(x => x.Hours).DefaultIfEmpty(0).Sum();

                var missingEntries = (employee.BeginDate.Date > date.Date) ? 0 : listDates.Except(days.Select(x => x.Date.Day)).Count();

                statictic.MissingEntries += missingEntries;

                TeamMemberModel employeeModel = new TeamMemberModel()
                {
                    Employee = new BaseModel()
                    {
                        Id   = employee.Id,
                        Name = employee.FirstName + ' ' + employee.LastName
                    },
                    Days = new DayStatisticModel()
                    {
                        WorkingDays             = workingDays,
                        VacationDays            = vacationDays,
                        BusinessAbscenceDays    = businessAbscenceDays,
                        PublicHolidays          = publicHolidays,
                        SickLeaveDays           = sickLeaveDays,
                        ReligiousDays           = religiousDays,
                        OtherAbscenceDays       = otherAbsenceDays,
                        OvertimeHours           = overtime,
                        PercentageOfWorkingDays = Math.Round(100 * (double)workingDays / listDates.Count(), 2),
                        MissingEntries          = missingEntries,
                        MaxPossibleWorkingDays  = maxPossibleDays
                    },
                    TotalHours = totalhoursss
                                 //TotalHours = hoursTeam1
                };

                reports.Add(employeeModel);
                hours += employeeModel.TotalHours;
            }

            var utilization = Math.Round(((decimal)statictic.WorkingDays / (decimal)noDaysInMonth(year, month)) * 100, 2);

            int numberOfEmployees = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Count();
            var fullworkingdays   = numberOfEmployees * DateTimeHelper.ListOfWorkingDays(year, month).Count();

            statictic.PercentageOfWorkingDays = Math.Round(100 * (double)statictic.WorkingDays / fullworkingdays);

            var report = new TeamReport()
            {
                Id   = teamId,
                Name = unit.Teams.Get(teamId).Name,
                NumberOfEmployees = numberOfEmployees,
                NumberOfProjects  = unit.Teams.Get(teamId).Projects.Count(),
                Days        = statictic,
                Reports     = reports,
                TotalHours  = hours,
                Year        = year,
                Month       = month,
                Utilization = utilization
            };

            return(report);
        }
Example #3
0
        public static TeamReport GetTeamReport(this UnitOfWork unit, string teamId, int year, int month, ModelFactory factory)
        {
            var date      = new DateTime(year, month, 1);
            var employees = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).Where(x => x.BeginDate < date).ToList();
            List <TeamMemberModel>            reports        = new List <TeamMemberModel>();
            List <PersonalReportProjectModel> ProjectDetails = new List <PersonalReportProjectModel>();

            var projects = unit.Teams.Get().Where(x => x.Id == teamId).SelectMany(t => t.Projects).ToList();

            decimal?hours = 0;
            var     numberOfEmployeesInTeam = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).Where(x => x.BeginDate < date).Count();

            DayStatisticModel statistika = new DayStatisticModel()
            {
                BusinessAbscenceDays    = 0,
                MissingEntries          = 0,
                OtherAbscenceDays       = 0,
                OvertimeHours           = 0,
                PercentageOfWorkingDays = 0,
                PublicHolidays          = 0,
                ReligiousDays           = 0,
                SickLeaveDays           = 0,
                VacationDays            = 0,
                WorkingDays             = 0
            };
            decimal?overtime = 0;

            foreach (var employee in employees)
            {
                int PTO  = 0;
                var days = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days)
                           .Where(x => x.Employee.Id == employee.Id &&
                                  x.Date.Value.Year == year &&
                                  x.Date.Value.Month == month).ToList();
                List <int> listDates = null;

                if (employee.BeginDate.Value.Year == date.Year && employee.BeginDate.Value.Month == date.Month &&
                    employee.BeginDate.Value.Day < DateTime.DaysInMonth(year, month))
                {
                    listDates = DateTimeHelper.ListOfWorkingDays(year, month, employee.BeginDate.Value.Day).ToList();
                }
                else
                {
                    listDates = DateTimeHelper.ListOfWorkingDays(year, month).ToList();
                }
                int workingDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days)
                                  .Where(x => x.Employee.Id == employee.Id &&
                                         x.Date.Value.Year == year &&
                                         x.Date.Value.Month == month &&
                                         x.Category.Description == "Working day").Count();
                statistika.WorkingDays += workingDays;


                overtime = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                        x.Date.Value.Year == year &&
                                                                                                                                        x.Date.Value.Month == month && x.Hours > 8)
                           .Select(x => x.Hours).DefaultIfEmpty(0).Sum();

                int overtimeCount = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days)
                                    .Where(x => x.Employee.Id == employee.Id &&
                                           x.Date.Value.Year == year &&
                                           x.Date.Value.Month == month && x.Hours > 8).Select(x => x.Hours).Count();
                overtime -= overtimeCount * 8;

                statistika.OvertimeHours += overtime;

                int vacationDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                x.Date.Value.Year == year &&
                                                                                                                                                x.Date.Value.Month == month &&
                                                                                                                                                x.Category.Description == "Vacation").Count();
                statistika.VacationDays += vacationDays;
                PTO += vacationDays;

                int businessAbscenceDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                        x.Date.Value.Year == year &&
                                                                                                                                                        x.Date.Value.Month == month &&
                                                                                                                                                        x.Category.Description == "Business absence").Count();

                statistika.BusinessAbscenceDays += businessAbscenceDays;
                int publicHolidays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                  x.Date.Value.Year == year &&
                                                                                                                                                  x.Date.Value.Month == month &&
                                                                                                                                                  x.Category.Description == "Public holiday").Count();
                statistika.PublicHolidays += publicHolidays;
                PTO += publicHolidays;

                int sickLeaveDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                 x.Date.Value.Year == year &&
                                                                                                                                                 x.Date.Value.Month == month &&
                                                                                                                                                 x.Category.Description == "Sick leave").Count();
                statistika.SickLeaveDays += sickLeaveDays;
                PTO += sickLeaveDays;

                int religiousDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                 x.Date.Value.Year == year &&
                                                                                                                                                 x.Date.Value.Month == month &&
                                                                                                                                                 x.Category.Description == "Religious day").Count();

                statistika.ReligiousDays += religiousDays;
                PTO += religiousDays;
                int otherAbsenceDays = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id &&
                                                                                                                                                    x.Date.Value.Year == year &&
                                                                                                                                                    x.Date.Value.Month == month &&
                                                                                                                                                    x.Category.Description == "Other absence").Count();
                statistika.OtherAbscenceDays += otherAbsenceDays;
                PTO += otherAbsenceDays;

                //decimal? totalhoursss = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(x => x.Employee).SelectMany(y => y.Days).Where(x => x.Employee.Id == employee.Id
                //                                        && x.Date.Value.Year == year
                //                                        && x.Date.Value.Month == month && x.Category.Description == "Working day")
                //                                        .Select(x => x.Hours).DefaultIfEmpty(0).Sum();

                decimal?totalhoursss = 0;

                foreach (var project in projects)
                {
                    var hoursAtProject = unit.Days.Get()
                                         .Where(d => d.Employee.Id == employee.Id && d.Date.Value.Year == year && d.Date.Value.Month == month)
                                         .SelectMany(a => a.Assignments).Where(a => a.Project.Id == project.Id).Select(h => h.Hours).DefaultIfEmpty(0).Sum();

                    totalhoursss += hoursAtProject;
                }
                var maxPossibleHoursEmployee = listDates.Count() * 8;
                var missingEntries           = (employee.BeginDate.Value.Date > date.Date) ? 0 : listDates.Except(days.Select(x => x.Date.Value.Day)).Count();
                statistika.MissingEntries += missingEntries;

                TeamMemberModel employeeModel = new TeamMemberModel()
                {
                    Employee = new BaseModel()
                    {
                        Id   = employee.Id,
                        Name = employee.FirstName + ' ' + employee.LastName,
                    },
                    PTO  = PTO,
                    Days = new DayStatisticModel()
                    {
                        WorkingDays             = workingDays,
                        VacationDays            = vacationDays,
                        BusinessAbscenceDays    = businessAbscenceDays,
                        PublicHolidays          = publicHolidays,
                        SickLeaveDays           = sickLeaveDays,
                        ReligiousDays           = religiousDays,
                        OtherAbscenceDays       = otherAbsenceDays,
                        OvertimeHours           = overtime,
                        PercentageOfWorkingDays = Math.Round(100 * (double)totalhoursss / maxPossibleHoursEmployee, 2),
                        MissingEntries          = missingEntries,
                    },
                    TotalHours       = totalhoursss,
                    MaxPossibleHours = maxPossibleHoursEmployee
                };

                reports.Add(employeeModel);
                hours += employeeModel.TotalHours;
            }
            //foreach(var employee in reports)
            //{
            //    hours += employee.TotalHours;
            //}
            //int numberOfEmployees = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Count();
            var fullworkingdays  = numberOfEmployeesInTeam * DateTimeHelper.ListOfWorkingDays(year, month).Count();
            int maxPossibleHours = NoDaysInMonth(year, month) * 8 * numberOfEmployeesInTeam;

            statistika.PercentageOfWorkingDays = Math.Round(100 * (double)hours / maxPossibleHours);
            foreach (var project in projects)
            {
                var hoursAtProject = unit.Days.Get()
                                     .Where(d => d.Date.Value.Year == year && d.Date.Value.Month == month)
                                     .SelectMany(a => a.Assignments).Where(a => a.Project.Id == project.Id).Select(h => h.Hours).DefaultIfEmpty(0).Sum();
                ProjectDetails.Add(new PersonalReportProjectModel()
                {
                    Id    = project.Id,
                    Name  = project.Name,
                    Hours = hoursAtProject
                });
            }

            var report = new TeamReport()
            {
                Id   = teamId,
                Name = unit.Teams.Get(teamId).Name,
                NumberOfEmployees = numberOfEmployeesInTeam,
                NumberOfProjects  = unit.Teams.Get(teamId).Projects.Count(),
                Dayss             = statistika,
                Reports           = reports,
                TotalHours        = hours,
                MaxPossibleHours  = maxPossibleHours,
                Year     = year,
                Month    = month,
                Projects = ProjectDetails
                           //Members = unit.Engagements.Get().Where(x => x.Team.Id == teamId).Select(y=> GetPersonalReport(unit,y.Employee.Id, year,month,factory)).ToList()
                           // Ok(TimeUnit.GetPersonalReport(employeeId, year, month, TimeFactory));
            };

            return(report);
        }