public List<PayStub> GetPayroll(DateTime startOfWeek, int numberOfWeeks)
        {
            var factory = new PayStubFactory();
            var wholePayroll = new List<List<PayStub>>();

            for (var i = 0; i < numberOfWeeks; i++)
            {
                var endOfWeek = startOfWeek.AddDays(7);

                var weekSchedule = db.Shifts.GetRange(startOfWeek, endOfWeek);

                var weekPayroll = new List<PayStub>();

                foreach (var shift in weekSchedule)
                {
                    var timeSpan = shift.TimeStampOut.Subtract(shift.TimeStampIn);

                    if (shift.IsHolidayPay)
                    {
                        AddToPayroll(factory.NewPayStub(shift.Employee, 0, timeSpan.TotalHours), weekPayroll);

                    } else
                    {
                        AddToPayroll(factory.NewPayStub(shift.Employee, timeSpan.TotalHours, 0), weekPayroll);

                    }
                }
                foreach (var payStub in weekPayroll)
                {
                    CalculateEarnings(payStub);
                }

                wholePayroll.Add(weekPayroll);

                startOfWeek = endOfWeek;
            }

            var payroll = CombinePayroll(wholePayroll);

            return payroll.OrderBy(p => p.EmployeeName).ToList();
        }
Example #2
0
        public List <PayStub> GetPayroll(DateTime startOfWeek, int numberOfWeeks)
        {
            var factory      = new PayStubFactory();
            var wholePayroll = new List <List <PayStub> >();

            for (var i = 0; i < numberOfWeeks; i++)
            {
                var endOfWeek = startOfWeek.AddDays(7);

                var weekSchedule = db.Shifts.GetRange(startOfWeek, endOfWeek);

                var weekPayroll = new List <PayStub>();

                foreach (var shift in weekSchedule)
                {
                    var timeSpan = shift.TimeStampOut.Subtract(shift.TimeStampIn);

                    if (shift.IsHolidayPay)
                    {
                        AddToPayroll(factory.NewPayStub(shift.Employee, 0, timeSpan.TotalHours), weekPayroll);
                    }
                    else
                    {
                        AddToPayroll(factory.NewPayStub(shift.Employee, timeSpan.TotalHours, 0), weekPayroll);
                    }
                }
                foreach (var payStub in weekPayroll)
                {
                    CalculateEarnings(payStub);
                }

                wholePayroll.Add(weekPayroll);

                startOfWeek = endOfWeek;
            }

            var payroll = CombinePayroll(wholePayroll);

            return(payroll.OrderBy(p => p.EmployeeName).ToList());
        }