Esempio n. 1
0
 public static void MapDtoToEntityForUpdating(ShiftProfileDto shiftProfileDto,
                                              ShiftProfile shiftProfile)
 {
     shiftProfile.IsActive            = shiftProfileDto.IsActive;
     shiftProfile.StartDateTime       = shiftProfileDto.StartDateTime;
     shiftProfile.EndDateTime         = shiftProfileDto.EndDateTime;
     shiftProfile.ActualStartDateTime = shiftProfileDto.ActualStartDateTime;
     shiftProfile.ActualEndDateTime   = shiftProfileDto.ActualEndDateTime;
     shiftProfile.ZktStartDateTime    = shiftProfileDto.ZktStartDateTime;
     shiftProfile.ZktEndDateTime      = shiftProfileDto.ZktEndDateTime;
     shiftProfile.HoursWorked         = shiftProfileDto.HoursWorked;
     shiftProfile.EmployeeId          = shiftProfileDto.EmployeeId;
     shiftProfile.ShiftId             = shiftProfileDto.ShiftId;
     shiftProfile.IsApproved          = shiftProfileDto.IsApproved;
     shiftProfile.Status     = shiftProfileDto.Status;
     shiftProfile.Reason     = shiftProfileDto.Reason;
     shiftProfile.Notes      = shiftProfileDto.Notes;
     shiftProfile.IsModified = shiftProfileDto.IsModified;
 }
Esempio n. 2
0
        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);
        }