public void DeleteShift(string index) { try { //Step 1 Code to delete the object from the database AttendanceShift s = new AttendanceShift(); s.recordId = index; s.dayId = CurrentDay.Text; s.employeeId = CurrentEmployee.Text; s.checkIn = "00:00"; s.checkOut = "00:00"; PostRequest <AttendanceShift> req = new PostRequest <AttendanceShift>(); req.entity = s; PostResponse <AttendanceShift> resp = _timeAttendanceService.ChildDelete <AttendanceShift>(req); if (!resp.Success) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(resp); return; } SynchronizeAttendanceDay GD = new SynchronizeAttendanceDay(); PostRequest <SynchronizeAttendanceDay> request = new PostRequest <SynchronizeAttendanceDay>(); GD.employeeId = Convert.ToInt32(CurrentEmployee.Text); GD.fromDayId = CurrentDay.Text; GD.toDayId = CurrentDay.Text; request.entity = GD; PostResponse <SynchronizeAttendanceDay> resp1 = _helpFunctionService.ChildAddOrUpdate <SynchronizeAttendanceDay>(request); //Step 2 : remove the object from the store if (!resp1.Success) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, GetGlobalResourceObject("Errors", resp1.ErrorCode) != null ? GetGlobalResourceObject("Errors", resp1.ErrorCode).ToString() + "<br>" + GetGlobalResourceObject("Errors", "ErrorLogId") + resp1.LogId : resp1.Summary).Show(); return; } attendanceShiftStore.Remove(index); //Step 3 : Showing a notification for the user Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordDeletedSucc }); Store1.Reload(); } catch (Exception ex) { //In case of error, showing a message box to the user X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorDeletingRecord).Show(); } }
private async Task <List <AttendanceShift> > SumAttendanceByShift(List <AttendanceModel> employeeActive, List <ShiftModel> shifts) { 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); } return(attendanceShifts); }
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); }
protected void SaveShift(object sender, DirectEventArgs e) { //Getting the id to check if it is an Add or an edit as they are managed within the same form. string id = e.ExtraParams["recordId"]; string day = e.ExtraParams["dayId"]; string emp = e.ExtraParams["EmployeeId"]; string obj = e.ExtraParams["values"]; AttendanceShift b = JsonConvert.DeserializeObject <AttendanceShift>(obj); b.recordId = id; b.dayId = day; b.employeeId = emp; // Define the object to add or edit as null if (string.IsNullOrEmpty(id)) { try { //New Mode //Step 1 : Fill The object and insert in the store PostRequest <AttendanceShift> request = new PostRequest <AttendanceShift>(); request.entity = b; PostResponse <AttendanceShift> r = _selfServiceService.ChildAddOrUpdate <AttendanceShift>(request); b.recordId = r.recordId; //check if the insert failed if (!r.Success)//it maybe be another condition { //Show an error saving... X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r); return; } else { //Add this record to the store this.attendanceShiftStore.Insert(0, b); //Display successful notification Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordSavingSucc }); this.EditShiftWindow.Close(); RowSelectionModel sm = this.GridPanel1.GetSelectionModel() as RowSelectionModel; sm.DeselectAll(); sm.Select(b.recordId.ToString()); Store1.Reload(); } } catch (Exception ex) { //Error exception displaying a messsage box X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorSavingRecord).Show(); } } else { //Update Mode try { int index = Convert.ToInt32(id);//getting the id of the record PostRequest <AttendanceShift> request = new PostRequest <AttendanceShift>(); request.entity = b; PostResponse <AttendanceShift> r = _selfServiceService.ChildAddOrUpdate <AttendanceShift>(request); //Step 1 Selecting the object or building up the object for update purpose //Step 2 : saving to store //Step 3 : Check if request fails if (!r.Success)//it maybe another check { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; Common.errorMessage(r);; return; } else { ModelProxy record = this.attendanceShiftStore.GetById(index); EditShiftForm.UpdateRecord(record); record.Commit(); Notification.Show(new NotificationConfig { Title = Resources.Common.Notification, Icon = Icon.Information, Html = Resources.Common.RecordUpdatedSucc }); this.EditShiftWindow.Close(); } } catch (Exception ex) { X.MessageBox.ButtonText.Ok = Resources.Common.Ok; X.Msg.Alert(Resources.Common.Error, Resources.Common.ErrorUpdatingRecord).Show(); } Store1.Reload(); } }