public IHttpActionResult UpdateShiftProfile(ShiftProfileModel shiftProfileModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { //var shiftProfileDto = Mapper.Map<ShiftProfileDto>(shiftProfileModel); var shiftProfileDto = _shiftProfileAppService.GetById(shiftProfileModel.Id); shiftProfileDto.Reason = shiftProfileModel.Reason; shiftProfileDto.Notes = shiftProfileModel.Notes; shiftProfileDto.ActualStartDateTime = shiftProfileModel.ActualStartDateTime; shiftProfileDto.ActualEndDateTime = shiftProfileModel.ActualEndDateTime; shiftProfileDto.IsApproved = shiftProfileModel.IsApproved; shiftProfileDto.IsModified = shiftProfileModel.IsModified; shiftProfileDto.HoursWorked = CommonHelperAppService.ReturnCalculatedTimespanBetweenTwoDateTimeObjects( shiftProfileDto.ActualStartDateTime, shiftProfileDto.ActualEndDateTime, 0); _shiftProfileAppService.Update(shiftProfileDto, AuthHelper.GetCurrentUserId()); return(Ok("Shift Profile Updated")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
// CRUD public void Create(ShiftProfileDto shiftProfileDto, long userId) { shiftProfileDto.HoursWorked = CommonHelperAppService.ReturnCalculatedTimespanBetweenTwoDateTimeObjects( shiftProfileDto.ActualStartDateTime, shiftProfileDto.ActualEndDateTime, shiftProfileDto.Status); var shiftProfile = Mapper.Map <ShiftProfile>(shiftProfileDto); _unitOfWork.ShiftProfileRepository.Create(shiftProfile); _unitOfWork.Save(); // Audit _auditLogAppService.Audit( AppConstants.ActionTypeCreate, AppConstants.ShiftProfileTableName, userId, shiftProfile.Id); UpdateAndDeleteNoShow(shiftProfileDto.ShiftId, userId); }
public IHttpActionResult UpdateFormAndShiftProfile(TimeAdjustmentFormAndShiftProfileUpdateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { // TAF var tafDto = _timeAdjustmentFormAppService.GetById(model.TimeAdjustmentFormId); tafDto.IsManagerApproved = model.IsManagerApproved; tafDto.IsAdminApproved = model.IsAdminApproved; _timeAdjustmentFormAppService.Update(tafDto, AuthHelper.GetCurrentUserId()); // Shift Profile var shiftProfileDto = _shiftProfileAppService.GetById(model.ShiftProfileId); shiftProfileDto.Reason = model.Reason; shiftProfileDto.Notes = model.Notes; if (model.IsAdminApproved) { shiftProfileDto.IsApproved = true; shiftProfileDto.ActualStartDateTime = model.ActualStartDateTime; shiftProfileDto.ActualEndDateTime = model.ActualEndDateTime; shiftProfileDto.HoursWorked = CommonHelperAppService.ReturnCalculatedTimespanBetweenTwoDateTimeObjects( shiftProfileDto.ActualStartDateTime, shiftProfileDto.ActualEndDateTime, 0); } _shiftProfileAppService.Update(shiftProfileDto, AuthHelper.GetCurrentUserId()); return(Ok("Success.")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private void MatchAnyLatentClockOuts(IEnumerable <ShiftProfileDto> shiftProfiles, IEnumerable <ZkTimeClockingRecord> zktimeClockingRecords) { // flush every time in case new staff have been entered into system since last time _staffIdMatrix = new List <StaffIdMatrixDto>(); var employees = _unitOfWork.EmployeeRepository.Get(e => e.IsActive, null, "User"); foreach (var employee in employees) { var matrixEntry = new StaffIdMatrixDto { EmployeeId = employee.Id, UserId = employee.User.Id, ZkTimeUserId = employee.User.ExternalTimeSystemId }; _staffIdMatrix.Add(matrixEntry); } foreach (var shiftProfileDto in shiftProfiles) { if (shiftProfileDto.EmployeeId != null) { var matchedId = _staffIdMatrix.Where(sm => sm.EmployeeId == shiftProfileDto.EmployeeId) .Select(sm => sm.ZkTimeUserId) .FirstOrDefault(); // shift end time + 5hrs var newEndDateTime = shiftProfileDto.EndDateTime.AddHours(5); var result = zktimeClockingRecords.FirstOrDefault(z => z.ZkTimeBadgeNumber == matchedId && z.ClockingTime >= shiftProfileDto.EndDateTime && z.ClockingTime <= newEndDateTime); if (result != null) { if (result.ClockingTime < shiftProfileDto.EndDateTime) { return; } // update existing record shiftProfileDto.Status = (int)ShiftProfileStatus.Valid; shiftProfileDto.ActualEndDateTime = shiftProfileDto.EndDateTime; shiftProfileDto.ZktEndDateTime = shiftProfileDto.EndDateTime; shiftProfileDto.HoursWorked = CommonHelperAppService.ReturnCalculatedTimespanBetweenTwoDateTimeObjects(shiftProfileDto.StartDateTime, shiftProfileDto.EndDateTime, shiftProfileDto.Status); shiftProfileDto.IsApproved = true; var shiftProfile = _unitOfWork.ShiftProfileRepository.GetById(shiftProfileDto.Id); CommonHelperAppService.MapDtoToEntityForUpdating(shiftProfileDto, shiftProfile); _unitOfWork.ShiftProfileRepository.Update(shiftProfile); _unitOfWork.Save(); // create the overtime shift profile record var overstayShiftProfile = new ShiftProfile { ActualStartDateTime = shiftProfileDto.EndDateTime, ActualEndDateTime = result.ClockingTime, ZktStartDateTime = shiftProfileDto.EndDateTime, ZktEndDateTime = result.ClockingTime, EmployeeId = shiftProfileDto.EmployeeId, EndDateTime = result.ClockingTime, HoursWorked = CommonHelperAppService.ReturnCalculatedTimespanBetweenTwoDateTimeObjects(shiftProfileDto.EndDateTime, result.ClockingTime, (int)ShiftProfileStatus.OverStayed), IsActive = true, IsApproved = false, ShiftId = shiftProfileDto.ShiftId, StartDateTime = shiftProfileDto.EndDateTime, Status = (int)ShiftProfileStatus.OverStayed, IsModified = false }; _unitOfWork.ShiftProfileRepository.Create(overstayShiftProfile); _unitOfWork.Save(); result.ShiftId = shiftProfile.ShiftId; result.IsMatched = true; _unitOfWork.ZkTimeClockingRecordRepository.Update(result); _unitOfWork.Save(); } // else it's still missing a clock out so leave alone } } }
// 9. private void CreateShiftProfileRecords( Shift shift, DateTime clockInDateTime, DateTime clockOutDateTime, DateTime actualStartDateTime, DateTime actualEndDateTime, bool lateIn, bool earlyOut, bool earlyIn, bool missingClockIn, bool missingClockOut, bool validClockIn, bool validClockOut) { var status = -1; var autoApprove = false; if (validClockIn && validClockOut) { status = (int)ShiftProfileStatus.Valid; } // EARLY IN if (earlyIn && validClockOut) { status = (int)ShiftProfileStatus.Valid; } //if (earlyIn && validClockOut) { status = (int)ShiftProfileStatus.EarlyIn; } if (earlyIn && missingClockOut) { status = (int)ShiftProfileStatus.MissingClockOut; } if (earlyIn && earlyOut) { status = (int)ShiftProfileStatus.EarlyOut; } // LATE IN if (lateIn && validClockOut) { status = (int)ShiftProfileStatus.LateIn; } if (lateIn && missingClockOut) { status = (int)ShiftProfileStatus.MissingClockOut; } if (lateIn && earlyOut) { status = (int)ShiftProfileStatus.LateIn; } // MISSING CLOCK IN if (missingClockIn && validClockOut) { status = (int)ShiftProfileStatus.MissingClockIn; } if (missingClockIn && missingClockOut) { status = (int)ShiftProfileStatus.NoShow; } if (missingClockIn && earlyOut) { status = (int)ShiftProfileStatus.MissingClockIn; } // VALID CLOCK IN if (validClockIn && missingClockOut) { status = (int)ShiftProfileStatus.MissingClockOut; } if (validClockIn && earlyOut) { status = (int)ShiftProfileStatus.EarlyOut; } if (status == (int)ShiftProfileStatus.Valid) { autoApprove = true; } //if (status == (int)ShiftProfileStatus.EarlyIn) { autoApprove = true; } var shiftProfile = new ShiftProfile { ActualStartDateTime = actualStartDateTime, ActualEndDateTime = actualEndDateTime, ZktStartDateTime = clockInDateTime, ZktEndDateTime = clockOutDateTime, EmployeeId = _employeeId, EndDateTime = shift.EndDate, HoursWorked = CommonHelperAppService.ReturnCalculatedTimespanBetweenTwoDateTimeObjects(actualStartDateTime, actualEndDateTime, status), IsActive = true, IsApproved = autoApprove, ShiftId = shift.Id, StartDateTime = shift.StartDate, Status = status, IsModified = false }; _shiftProfileList.Add(shiftProfile); }