コード例 #1
0
        // 4.
        private void GenerateStaffIdNumberMatrix()
        {
            // 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);
            }

            VerifyShiftProfileRecordExistence();
        }
コード例 #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
                }
            }
        }