public async Task <IEnumerable <SelectListItem> > GetShifts()
        {
            var shifts = await _shiftService.GetAllAsync();

            var item = new List <SelectListItem>
            {
                new SelectListItem()
                {
                    Value    = null,
                    Text     = "",
                    Selected = true
                }
            };

            foreach (var shift in shifts)
            {
                item.Add(new SelectListItem()
                {
                    Value = shift.ShiftId.ToString(),
                    Text  = shift.ShiftName
                });
            }

            return(item);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            var shifts = await _shiftService.GetAllAsync();

            if (shifts == null)
            {
                return(View());
            }

            var viewModel = new ShiftViewModel
            {
                Shifts = shifts
            };

            return(View(viewModel));
        }
        public async Task <DashboardViewModel> GetDashboardResult(string date, int?shiftId)
        {
            var viewModel = new DashboardViewModel();
            var filter    = new AttendanceFilter();

            var currentShuftId = 1;

            // get current shift
            var shiftCalendar = await _shiftCalendarService.GetByDateAsync(DateTime.Today);

            if (shiftCalendar != null)
            {
                currentShuftId = shiftCalendar.ShiftId;
            }

            filter.AttendanceDate = date;
            //filter.ShiftId = shiftId ?? currentShuftId;

            var totalEmployee = await _employeeService.CountTotalEmployeeAsync();

            var employeeActive = await _attendanceService.GetActiveAsync(filter);

            var employeeAbsent = await _attendanceService.GetAbsentAsync(filter);

            var employeeState = await _employeeStateService.GetAllAsync();

            var totalWork   = employeeState.Where(x => x.ShiftId == 1 || x.ShiftId == currentShuftId);
            var totalAbsent = employeeAbsent.Where(x => x.ShiftId == 1 || x.ShiftId == currentShuftId);

            viewModel.AttendanceStatusDay     = GetAttendanceStatusAsync(employeeState, employeeActive, 1);
            viewModel.AttendanceStatusCurrent = GetAttendanceStatusAsync(employeeState, employeeActive, currentShuftId);

            var shifts = await _shiftService.GetAllAsync();

            viewModel.CurrentShift = shifts.FirstOrDefault(x => x.ShiftId == currentShuftId).ShiftName;

            var attendanceShifts = await SumAttendanceByShift(employeeActive, shifts);

            // Summary attendance by percent
            var percentAbsent = Math.Round(((double)totalAbsent.Count() / (double)totalWork.Count()) * 100, 2);
            var percentActive = 100 - percentAbsent;

            var percentAttendance      = new string[] { $"{percentActive}", $"{percentAbsent}" };
            var percentAttendanceValue = JsonConvert.SerializeObject(percentAttendance, Formatting.None);

            // Summary attendance by job function
            var attendanceByJob       = SummamryByJobFunction(employeeState, employeeActive, currentShuftId);
            var attendanceByJobLabel  = JsonConvert.SerializeObject(attendanceByJob.Select(x => x.FunctionName).ToList(), Formatting.None);
            var attendanceByJobActive = JsonConvert.SerializeObject(attendanceByJob.Select(x => x.ActivePerson).ToList(), Formatting.None);
            var attendanceByJobAbsent = JsonConvert.SerializeObject(attendanceByJob.Select(x => x.AbsentPerson).ToList(), Formatting.None);

            // Summary attendance by level
            var attendanceByLevel = employeeActive
                                    .OrderBy(x => x.LevelCode)
                                    .GroupBy(g => g.LevelCode)
                                    .Select(x => new
            {
                Level    = x.Key,
                Quantity = x.Select(e => e.EmployeeId).Count()
            });

            var attendanceLevelLabel = JsonConvert.SerializeObject(attendanceByLevel.Select(x => x.Level).ToList(), Formatting.None);
            var attendanceLevelValue = JsonConvert.SerializeObject(attendanceByLevel.Select(x => x.Quantity).ToList(), Formatting.None);

            // Summary attendance by department
            var attendanceByDepartment = employeeActive
                                         .GroupBy(g => g.DepartmentCode)
                                         .Select(x => new
            {
                Department = x.Key,
                Quantity   = x.Select(e => e.EmployeeId).Count()
            }).ToList();

            var departmentChartLabel = JsonConvert.SerializeObject(attendanceByDepartment.Select(x => x.Department).ToList(), Formatting.None);
            var departmentChartValue = JsonConvert.SerializeObject(attendanceByDepartment.Select(x => x.Quantity).ToList(), Formatting.None);

            // Summary attendance by section
            var attendanceSections = employeeActive
                                     .GroupBy(g => g.SectionName)
                                     .Select(x => new
            {
                SectionName = x.Key,
                Quantity    = x.Select(e => e.EmployeeId).Count()
            });

            var sectionChartLabel = JsonConvert.SerializeObject(attendanceSections.Select(x => x.SectionName).ToList(), Formatting.None);
            var sectionChartValue = JsonConvert.SerializeObject(attendanceSections.Select(x => x.Quantity).ToList(), Formatting.None);

            // Summary transportation by route
            var transportRoutes = employeeActive
                                  .GroupBy(g => g.RouteName)
                                  .Select(x => new
            {
                RouteName = x.Key,
                Quantity  = x.Select(e => e.EmployeeId).Count()
            });

            var transportChartLabel = JsonConvert.SerializeObject(transportRoutes.Select(x => x.RouteName).ToList(), Formatting.None);
            var transportChartValue = JsonConvert.SerializeObject(transportRoutes.Select(x => x.Quantity).ToList(), Formatting.None);

            viewModel.CountTotalEmployee     = totalEmployee;
            viewModel.CountActiveWork        = employeeActive.Count;
            viewModel.CountAbsent            = totalAbsent.Count();
            viewModel.PercentAbsent          = $"{percentAbsent}%";
            viewModel.Attendances            = totalAbsent;
            viewModel.AttendanceByShift      = attendanceShifts;
            viewModel.DepartmentChartLabel   = new HtmlString(departmentChartLabel);
            viewModel.DepartmentChartValue   = new HtmlString(departmentChartValue);
            viewModel.SectiobChartLabel      = new HtmlString(sectionChartLabel);
            viewModel.SectiobChartValue      = new HtmlString(sectionChartValue);
            viewModel.AttendancePercentValue = new HtmlString(percentAttendanceValue);
            viewModel.AttendanceByJobLabel   = new HtmlString(attendanceByJobLabel);
            viewModel.AttendanceByJobActive  = new HtmlString(attendanceByJobActive);
            viewModel.AttendanceByJobAbsent  = new HtmlString(attendanceByJobAbsent);
            viewModel.AttendanceLevelLabel   = new HtmlString(attendanceLevelLabel);
            viewModel.AttendanceLevelValue   = new HtmlString(attendanceLevelValue);
            viewModel.TransportChartLabel    = new HtmlString(transportChartLabel);
            viewModel.TransportChartValue    = new HtmlString(transportChartValue);
            viewModel.Shifts = await _employeeDetailService.GetShifts();

            return(viewModel);
        }
Ejemplo n.º 4
0
        public async Task <DashboardViewModel> GetDashboardResult(string date)
        {
            var totalEmployee = await _attendanceService.CountTotalEmployeeAsync();

            var employeeActive = await _attendanceService.GetActiveAsync(date);

            var employeeAbsent = await _attendanceService.GetAbsentAsync(date);

            // todo get current shift by time start and time end
            //var currentTime = DateTime.Now.TimeOfDay;
            //var shifts = await _shiftService.GetByTimeAsync(currentTime);
            var shifts = await _shiftService.GetAllAsync();

            var attendanceShifts = new List <AttendanceShift>();

            foreach (var s in shifts)
            {
                var employeePerShift = await _employeeStateService.CountShiftAsync(s.ShiftId);

                var employeeActivePerShift = employeeActive.Count(x => x.ShiftName == s.ShiftName);

                var attendanceShift = new AttendanceShift
                {
                    ShiftName      = s.ShiftName,
                    TotalEmployee  = employeePerShift,
                    ActiveEmployee = employeeActivePerShift
                };

                attendanceShifts.Add(attendanceShift);
            }

            // Summary attendance by percent
            var percentAbsent = Math.Round(((double)employeeAbsent.Count / (double)totalEmployee) * 100, 2);
            var percentActive = 100 - percentAbsent;

            var percentAttendance      = new string[] { $"{percentActive}", $"{percentAbsent}" };
            var percentAttendanceValue = JsonConvert.SerializeObject(percentAttendance, Formatting.None);

            // Summary attendance by level
            var attendanceByLevel = employeeActive
                                    .OrderBy(x => x.LevelCode)
                                    .GroupBy(g => g.LevelCode)
                                    .Select(x => new
            {
                Level    = x.Key,
                Quantity = x.Select(e => e.EmployeeId).Count()
            });

            var attendanceLevelLabel = JsonConvert.SerializeObject(attendanceByLevel.Select(x => x.Level).ToList(), Formatting.None);
            var attendanceLevelValue = JsonConvert.SerializeObject(attendanceByLevel.Select(x => x.Quantity).ToList(), Formatting.None);

            // Summary attendance by department
            var attendanceByDepartment = employeeActive
                                         .GroupBy(g => g.DepartmentCode)
                                         .Select(x => new
            {
                Department = x.Key,
                Quantity   = x.Select(e => e.EmployeeId).Count()
            }).ToList();

            var departmentChartLabel = JsonConvert.SerializeObject(attendanceByDepartment.Select(x => x.Department).ToList(), Formatting.None);
            var departmentChartValue = JsonConvert.SerializeObject(attendanceByDepartment.Select(x => x.Quantity).ToList(), Formatting.None);

            // Summary attendance by section
            var attendanceSections = employeeActive
                                     .GroupBy(g => g.SectionName)
                                     .Select(x => new
            {
                SectionName = x.Key,
                Quantity    = x.Select(e => e.EmployeeId).Count()
            });

            var sectionChartLabel = JsonConvert.SerializeObject(attendanceSections.Select(x => x.SectionName).ToList(), Formatting.None);
            var sectionChartValue = JsonConvert.SerializeObject(attendanceSections.Select(x => x.Quantity).ToList(), Formatting.None);

            // Summary transportation by route
            var transportRoutes = employeeActive
                                  .GroupBy(g => g.BusStationName)
                                  .Select(x => new
            {
                BusStationName = x.Key,
                Quantity       = x.Select(e => e.EmployeeId).Count()
            });

            var transportChartLabel = JsonConvert.SerializeObject(transportRoutes.Select(x => x.BusStationName).ToList(), Formatting.None);
            var transportChartValue = JsonConvert.SerializeObject(transportRoutes.Select(x => x.Quantity).ToList(), Formatting.None);

            var viewModel = new DashboardViewModel
            {
                CountTotalEmployee     = totalEmployee,
                CountActiveWork        = employeeActive.Count,
                CountAbsent            = employeeAbsent.Count,
                PercentAbsent          = $"{percentAbsent}%",
                Attendances            = employeeAbsent,
                AttendanceByShift      = attendanceShifts,
                DepartmentChartLabel   = new HtmlString(departmentChartLabel),
                DepartmentChartValue   = new HtmlString(departmentChartValue),
                SectiobChartLabel      = new HtmlString(sectionChartLabel),
                SectiobChartValue      = new HtmlString(sectionChartValue),
                AttendancePercentValue = new HtmlString(percentAttendanceValue),
                AttendanceLevelLabel   = new HtmlString(attendanceLevelLabel),
                AttendanceLevelValue   = new HtmlString(attendanceLevelValue),
                TransportChartLabel    = new HtmlString(transportChartLabel),
                TransportChartValue    = new HtmlString(transportChartValue),
            };

            return(viewModel);
        }