public static DayPunchesDto GetRowedDayPunches(this DayPunchesDto dayPunchesDto, Punch[] punchArray)
        {
            if (dayPunchesDto == null)
            {
                throw new System.ArgumentNullException(nameof(dayPunchesDto));
            }

            var dayTotal = 0.0;

            dayPunchesDto.Punches = new List <PunchRowDto>();
            var dayPunchesArray = punchArray.OrderBy(dp => dp.TimeDec).ToArray();
            var i = 0;

            do
            {
                var row = new PunchRowDto();
                if (punchArray.Any())
                {
                    var punch = dayPunchesArray[i];
                    if (punch.Direction)
                    {
                        row.Enter = new PunchDto();
                        row.Enter.SetPunch(punch);
                        if (i < dayPunchesArray.Length - 1 && !dayPunchesArray[i + 1].Direction)
                        {
                            i++;
                            punch     = dayPunchesArray[i];
                            row.Leave = new PunchDto();
                            row.Leave.SetPunch(punch);
                        }
                    }
                    else
                    {
                        row.Leave = new PunchDto();
                        row.Leave.SetPunch(punch);
                    }
                }
                // calc dayTotal
                dayTotal += row.GetRowTotal();
                dayPunchesDto.Punches.Add(row);
                i++;
            } while (i < punchArray.Count());
            dayPunchesDto.Daytotal = dayTotal;
            return(dayPunchesDto);
        }
Exemple #2
0
 public static double GetRowTotal(this PunchRowDto punchRowDto)
 {
     if (punchRowDto.Enter != null && punchRowDto.Leave != null)
     {
         if (punchRowDto.Leave.Timedec != null)
         {
             if (punchRowDto.Enter.Timedec != null)
             {
                 punchRowDto.RowTotal = punchRowDto.Leave.Timedec.Value - punchRowDto.Enter.Timedec.Value;
             }
         }
         if (punchRowDto.RowTotal != null)
         {
             return(punchRowDto.RowTotal.Value);
         }
     }
     return(0.0);
 }