Пример #1
0
        public MonthExtract(DateTime date, IEnumerable <HourPoints> hourPoints, HourPointConfigurations currentConfiguration)
        {
            Date        = date;
            _hourPoints = hourPoints.Where(h => h.Date.Month == date.Month && h.Date.Year == date.Year).ToList().AsReadOnly();

            CalculateExtraAndMissingTime();
            CalculateWorkedTime(currentConfiguration);
            CalculatePredictedSalary(currentConfiguration);
        }
Пример #2
0
        private void CalculateWorkedTime(HourPointConfigurations currentConfiguration)
        {
            WorkedTime = TimeSpan.Zero;

            if (_hourPoints.Any())
            {
                long totalWorkedTimeInTicks = _hourPoints.Count * currentConfiguration.OfficeHour.Ticks;
                WorkedTime = TimeSpan.FromTicks((totalWorkedTimeInTicks + ExtraTime.Ticks) - MissingTime.Ticks);
            }
        }
Пример #3
0
        public void CalculateMissingTime(HourPointConfigurations hourPointConfigurations)
        {
            TimeSpan totalWorkedTimeInDay = GetWorkedTime();

            if (totalWorkedTimeInDay < hourPointConfigurations.OfficeHour)
            {
                MissingTime = hourPointConfigurations.OfficeHour - totalWorkedTimeInDay;
            }
            else
            {
                MissingTime = new TimeSpan(0, 0, 0);
            }
        }
Пример #4
0
        public void CalculateExtraTime(HourPointConfigurations hourPointConfigurations)
        {
            TimeSpan totalWorkedTimeInDay = GetWorkedTime();

            if (totalWorkedTimeInDay > hourPointConfigurations.OfficeHour)
            {
                ExtraTime = totalWorkedTimeInDay - hourPointConfigurations.OfficeHour;
            }
            else
            {
                ExtraTime = new TimeSpan(0, 0, 0);
            }
        }
Пример #5
0
 public void AddTimeEntry(TimeEntry timeEntry, HourPointConfigurations hourPointConfigurations)
 {
     try
     {
         timeEntry.Validate();
         timeEntry.AssociateHourPoints(Id);
         _timeEntries.Add(timeEntry);
         RecalculateTimes(hourPointConfigurations);
     }
     catch (ValidationException except)
     {
         throw new Exception(except.Message);
     }
 }
Пример #6
0
        public static HourPoints CreateWithAutoGeneratedTimeEntries(Guid userId, HourPointConfigurations hourPointConfigurations)
        {
            HourPoints hourPoints = new HourPoints(DateTime.Now, userId);

            Random byteRandomic            = new Random();
            sbyte  randomTolerance         = (sbyte)byteRandomic.Next(-hourPointConfigurations.ToleranceTime.Minutes, hourPointConfigurations.ToleranceTime.Minutes);
            byte   randomStartLunchHour    = (byte)byteRandomic.Next(11, 12);
            byte   randomStartLunchMinutes = (byte)byteRandomic.Next(30, 59);

            DateTime currentDate = DateTime.Now;

            int startWorkTimeWithTolerance = hourPointConfigurations.StartWorkTime.Minutes + randomTolerance;
            int startWorkTimeHours         = hourPointConfigurations.StartWorkTime.Hours;

            if (startWorkTimeWithTolerance <= 0)
            {
                startWorkTimeHours--;
                startWorkTimeWithTolerance = 60 + randomTolerance;
            }

            DateTime dateHourPointed = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, startWorkTimeHours, startWorkTimeWithTolerance, 0);

            hourPoints.AddTimeEntry(new TimeEntry(dateHourPointed), hourPointConfigurations);

            DateTime startLunchTimePoint = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, randomStartLunchHour, randomStartLunchMinutes, 0);

            hourPoints.AddTimeEntry(new TimeEntry(startLunchTimePoint), hourPointConfigurations);

            DateTime endLunchTimePoint = startLunchTimePoint.AddTicks(hourPointConfigurations.LunchTime.Ticks);

            hourPoints.AddTimeEntry(new TimeEntry(endLunchTimePoint), hourPointConfigurations);

            DateTime endOfWorkDayPoint = endLunchTimePoint.AddHours(hourPoints.MissingTime.Hours).AddMinutes(hourPoints.MissingTime.Minutes + randomTolerance);

            hourPoints.AddTimeEntry(new TimeEntry(endOfWorkDayPoint), hourPointConfigurations);

            return(hourPoints);
        }
Пример #7
0
        private void CalculatePredictedSalary(HourPointConfigurations configurations)
        {
            decimal valueByMinute = configurations.HourValue / 60;

            PredictedSalary = (decimal)WorkedTime.TotalMinutes * valueByMinute;
        }
Пример #8
0
        public void ChangeTimeEntryDateHourPointed(DateTime newDateHourPointed, Guid timeEntryId, HourPointConfigurations hourPointConfigurations)
        {
            TimeEntry timeEntry = _timeEntries.SingleOrDefault(time => time.Id.Equals(timeEntryId));

            if (timeEntry is null)
            {
                throw new ArgumentException("The time entry wasn't found in database.");
            }

            timeEntry.ChangeDateHourPointed(newDateHourPointed);

            RecalculateTimes(hourPointConfigurations);
        }
Пример #9
0
 private void RecalculateTimes(HourPointConfigurations hourPointConfigurations)
 {
     CalculateExtraTime(hourPointConfigurations);
     CalculateMissingTime(hourPointConfigurations);
 }
Пример #10
0
 public void RemoveTimeEntry(TimeEntry timeEntry, HourPointConfigurations hourPointConfigurations)
 {
     _timeEntries.RemoveAll(time => time.Id.Equals(timeEntry.Id));
     RecalculateTimes(hourPointConfigurations);
 }