예제 #1
0
        public List <AnnualModel> AnnualReport(int year)
        {
            if (year == 0)
            {
                year = Convert.ToInt32(ConfigurationManager.AppSettings["currentYear"]);
            }

            var query = TimeKeeperUnit.Projects.Get()
                        .OrderBy(x => x.Name)
                        .Select(x => new
            {
                project = x.Name,
                details = x.Details.Where(d => d.Day.Date.Year == year)
                          .GroupBy(d => d.Day.Date.Month)
                          .Select(w => new
                {
                    month = w.Key,
                    hours = w.Sum(d => d.Hours)
                })
                          .ToList()
            }).ToList();

            List <AnnualModel> list  = new List <AnnualModel>();
            AnnualModel        total = new AnnualModel {
                ProjectName = "T O T A L"
            };

            foreach (var q in query)
            {
                AnnualModel item = new AnnualModel {
                    ProjectName = q.project
                };
                foreach (var w in q.details)
                {
                    item.TotalHours  += w.hours;
                    total.TotalHours += w.hours;
                    item.MonthlyHours[w.month - 1]   = w.hours;
                    total.MonthlyHours[w.month - 1] += w.hours;
                }
                if (item.TotalHours > 0)
                {
                    list.Add(item);
                }
            }
            list.Add(total);
            return(list);
        }
예제 #2
0
        /*
         * public List<MissingEntriesModel> GetMissingEntries(int year, int month)
         * {
         *  List<MissingEntriesModel> missingEntriesList = new List<MissingEntriesModel>();
         *  var employees = TimeUnit.Days.GetList(x => x.Date.Month == month && x.Date.Year == year)
         *      .Select(x => x.Employee).ToList();
         *
         *  foreach(var employee in employees)
         *  {
         *      List<int> workingDays = DateTimeHelper.ListOfWorkingDays(year, month, employee.BeginDate.Day).ToList();
         *      var employeeDays = employee.Days.Where(y => y.Date.Month == month && y.Date.Year == year && y.Type == DAL.Entities.DayType.WorkingDay)
         *          .Select(x => x.Date.Day).ToList();
         *
         *      var missing = workingDays.Except(employeeDays).ToList();
         *
         *
         *      MissingEntriesModel emp = new MissingEntriesModel()
         *      {
         *          Employee = employee.FirstName + " " + employee.LastName,
         *          MissingDayCount = Math.Abs(TimeUnit.Days.Get().Where(x => x.Employee.Id == employee.Id && x.Date.Year == year && x.Date.Month == month).Count() - workingDays.Count()),
         *          MissingDays = missing
         *      };
         *
         *      missingEntriesList.Add(emp);
         *  }
         *
         *  return missingEntriesList;
         * }
         */
        public List <AnnualModel> AnnualReport(int year)
        {
            var query = TimeUnit.Projects.Get()
                        .OrderBy(x => x.Name)
                        .Select(x => new
            {
                project     = x.Name,
                description = x.Description,
                count       = x.Tasks.Count(t => t.Project.Name == x.Name),
                details     = x.Tasks.Where(d => d.Day.Date.Year == year)
                              .GroupBy(d => d.Day.Date.Month)
                              .Select(w => new
                {
                    month = w.Key,
                    hours = w.Sum(d => d.Hours)
                }).ToList(),
            }).ToList();

            List <AnnualModel> list  = new List <AnnualModel>();
            AnnualModel        total = new AnnualModel()
            {
                ProjectName = "TOTAL"
            };

            foreach (var q in query)
            {
                AnnualModel item = new AnnualModel()
                {
                    ProjectName = q.project, ProjectDescription = q.description, TasksCount = q.count
                };
                foreach (var w in q.details)
                {
                    item.TotalHours  += w.hours;
                    total.TotalHours += w.hours;
                    item.MonthlyHours[w.month - 1]   = w.hours;
                    total.MonthlyHours[w.month - 1] += w.hours;
                }
                if (item.TotalHours > 0)
                {
                    list.Add(item);
                }
            }
            list.Add(total);
            return(list);
        }