public async Task <IActionResult> ActiveWork(AttendanceFilter filterModel) { var viewModel = new AttendanceViewModel(); if (string.IsNullOrEmpty(filterModel.AttendanceDate)) { filterModel.AttendanceDate = DateTime.Today.ToString("yyyy/MM/dd"); } viewModel.Attendances = await _attendanceService.GetActiveAsync(filterModel); viewModel.Departments = await _employeeDetailService.GetDepartments(); viewModel.Shifts = await _employeeDetailService.GetShifts(); viewModel.Positions = await _employeeDetailService.GetPositions(); if (filterModel.DepartmentId.HasValue) { viewModel.Sections = await _employeeDetailService.GetSectionsByDepartmentId(filterModel.DepartmentId.Value); } if (filterModel.SectionId.HasValue) { viewModel.JobFunctions = await _employeeDetailService.GetJobFunctionsBySectionId(filterModel.SectionId.Value); } _httpContextAccessor.HttpContext.Session.SetObjectAsJson("attendances", viewModel.Attendances); return(View(viewModel)); }
public async Task <IActionResult> Create() { var viewModel = new ShiftCalendarEditViewModel { Shifts = await _employeeDetailService.GetShifts() }; return(View(viewModel)); }
public async Task <EmployeeViewModel> GetEmployeeList(EmployeeFilter filter) { var viewModel = new EmployeeViewModel(); var employees = await _employeeService.GetAsync(filter); if (employees != null) { viewModel.Employees = employees; viewModel.Departments = await _employeeDetailService.GetDepartments(); viewModel.Shifts = await _employeeDetailService.GetShifts(); viewModel.Positions = await _employeeDetailService.GetPositions(); } return(viewModel); }
public async Task <AttendanceFilterModel> GetAttendanceFilterAsync() { var shifts = await _employeeDetailService.GetShifts(); var positions = await _employeeDetailService.GetPositions(); var jobFunctions = await _employeeDetailService.GetJobFunctions(); var departments = await _employeeDetailService.GetDepartments(); var sections = await _employeeDetailService.GetSections(); var filterModel = new AttendanceFilterModel { Shifts = shifts, Positions = positions, JobFunctions = jobFunctions, Departments = departments, Sections = sections }; return(filterModel); }
public async Task <IActionResult> EmployeeList(EmployeeFilter filterModel) { var viewModel = new EmployeeViewModel(); viewModel.Departments = await _employeeDetailService.GetDepartments(); viewModel.Shifts = await _employeeDetailService.GetShifts(); viewModel.Positions = await _employeeDetailService.GetPositions(); viewModel.JobLevels = await _employeeDetailService.GetLevels(); if (filterModel.AvailableFlag == null) { filterModel.AvailableFlag = true; } if (filterModel.DepartmentId.HasValue) { viewModel.Sections = await _employeeDetailService.GetSectionsByDepartmentId(filterModel.DepartmentId.Value); } if (filterModel.SectionId.HasValue) { viewModel.JobFunctions = await _employeeDetailService.GetJobFunctionsBySectionId(filterModel.SectionId.Value); } var employees = await _employeeService.GetAsync(filterModel); if (employees != null) { viewModel.Employees = employees; } 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); }
public async Task <ProfileEditViewModel> EditProfile(string employeeId) { var viewModel = new ProfileEditViewModel(); viewModel.Departments = await _employeeDetailService.GetDepartments(); //viewModel.Sections = await _employeeDetailService.GetSections(); viewModel.Shifts = await _employeeDetailService.GetShifts(); viewModel.JobTitles = await _employeeDetailService.GetPositions(); //viewModel.JobFunctions = await _employeeDetailService.GetJobFunctions(); viewModel.JobLevels = await _employeeDetailService.GetLevels(); viewModel.BusStations = await _employeeDetailService.GetBusStations(); var employee = await _employeeService.GetByEmployeeIdAsync(employeeId); if (employee != null) { viewModel.EmployeeId = employee.EmployeeId; viewModel.GlobalId = employee.GlobalId; viewModel.CardId = employee.CardId; viewModel.Title = employee.Title; viewModel.TitleThai = employee.TitleThai; viewModel.EmployeeType = employee.EmployeeType; viewModel.FirstName = employee.FirstName; viewModel.LastName = employee.LastName; viewModel.FirstNameThai = employee.FirstNameThai; viewModel.LastNameThai = employee.LastNameThai; viewModel.Gender = employee.Gender; viewModel.BirthDate = employee.BirthDate; viewModel.HireDate = employee.HireDate; } var employeeState = await _employeeStateService.GetByEmployeeId(employeeId); if (employeeState != null) { viewModel.DepartmentId = employeeState.DepartmentId; viewModel.SectionId = employeeState.SectionId; viewModel.ShiftId = employeeState.ShiftId; viewModel.JobPositionId = employeeState.PositionId; viewModel.JobFunctionId = employeeState.JobFunctionId; viewModel.LevelId = employeeState.LevelId; viewModel.BusStationId = employeeState.BusStationId; viewModel.JoinDate = employeeState.JoinDate; } var address = await _employeeAddressService.GetByEmployeeId(employeeId); if (address != null) { viewModel.EmployeeAddressId = address.EmployeeAddressId; viewModel.HomeAddress = address.HomeAddress; viewModel.City = address.City; viewModel.Country = address.Country; viewModel.PostalCode = address.PostalCode; viewModel.PhoneNumber = address.PhoneNumber; viewModel.EmailAddress = address.EmailAddress; } return(viewModel); }
public async Task <ProfileEditViewModel> EditProfile(string employeeId) { var viewModel = new ProfileEditViewModel(); viewModel.Departments = await _employeeDetailService.GetDepartments(); viewModel.Shifts = await _employeeDetailService.GetShifts(); viewModel.JobPosition = await _employeeDetailService.GetPositions(); viewModel.JobLevels = await _employeeDetailService.GetLevels(); viewModel.Routes = await _employeeDetailService.GetRoutes(); viewModel.BusStations = await _employeeDetailService.GetBusStations(); var employee = await _employeeService.GetByEmployeeIdWithDetailAsync(employeeId); if (employee != null) { viewModel.EmployeeId = employee.EmployeeId; viewModel.GlobalId = employee.GlobalId; viewModel.CardId = employee.CardId; viewModel.Title = employee.Title; viewModel.TitleThai = employee.TitleThai; viewModel.EmployeeType = employee.EmployeeType; viewModel.FirstName = employee.FirstName; viewModel.LastName = employee.LastName; viewModel.FirstNameThai = employee.FirstNameThai; viewModel.LastNameThai = employee.LastNameThai; viewModel.Height = employee.Height; viewModel.Hand = employee.Hand; viewModel.Gender = employee.Gender; viewModel.BirthDate = employee.BirthDate; viewModel.HireType = employee.HireType; viewModel.HireDate = employee.HireDate; if (employee.EmployeeState != null) { viewModel.DepartmentId = employee.EmployeeState.JobFunction.Section.Department.DepartmentId; viewModel.SectionId = employee.EmployeeState.JobFunction.Section.SectionId; viewModel.ShiftId = employee.EmployeeState.ShiftId; viewModel.JobPositionId = employee.EmployeeState.PositionId; viewModel.JobFunctionId = employee.EmployeeState.JobFunctionId; viewModel.LevelId = employee.EmployeeState.LevelId; viewModel.RouteId = employee.EmployeeState.BusStation.Route.RouteId; viewModel.BusStationId = employee.EmployeeState.BusStationId; viewModel.JoinDate = employee.EmployeeState.JoinDate; } } var address = await _employeeAddressService.GetByEmployeeId(employeeId); if (address != null) { viewModel.EmployeeAddressId = address.EmployeeAddressId; viewModel.HomeAddress = address.HomeAddress; viewModel.City = address.City; viewModel.Country = address.Country; viewModel.PostalCode = address.PostalCode; viewModel.PhoneNumber = address.PhoneNumber; viewModel.EmailAddress = address.EmailAddress; } var image = await _employeeImageService.GetByEmployeeId(employeeId); if (image != null) { var imageBase64Data = Convert.ToBase64String(image.Images); viewModel.ProfileImage = string.Format("data:image/png;base64,{0}", imageBase64Data); } return(viewModel); }