public List <Paystub> GetPaystubs(DateTime date)
        {
            var paystubs   = new List <Paystub>();
            var timesheets = _timesheetRepository.GetTimesheetsForLastTwoWeeks(date);

            var timesheetsByEmployee = timesheets.GroupBy(t => t.EmployeeId);

            foreach (var employeesTimesheets in timesheetsByEmployee)
            {
                var employee        = _employeeRepository.Get(employeesTimesheets.First().EmployeeId);
                var employeeState   = employee.State;
                var employeePayRate = employee.HourlyRate;

                var calculator = new OvertimeCalculatorFactory().GetCalculator(employeeState);

                // This was clean until I split these up into weeks. Clean this up?
                var firstWeekTimesheets = employeesTimesheets
                                          .Select(t => t)
                                          .Where(d => d.Date >= date.AddDays(-6) && d.Date <= date);

                var secondWeekTimesheets = employeesTimesheets
                                           .Select(t => t)
                                           .Where(d => d.Date >= date.AddDays(-13) && d.Date <= date.AddDays(-7));

                var firstDto  = calculator.CalculatePay(firstWeekTimesheets.Select(t => t), employeePayRate);
                var secondDto = calculator.CalculatePay(secondWeekTimesheets.Select(t => t), employeePayRate);
                var dto       = new PayDto(firstDto.RegularHoursWorked + secondDto.RegularHoursWorked, firstDto.OvertimeHoursWorked + secondDto.OvertimeHoursWorked, firstDto.RegularPay + secondDto.RegularPay, firstDto.OvertimePay + secondDto.OvertimePay);

                var paystub = new Paystub(employee, date.AddDays(-13), date, dto);
                paystubs.Add(paystub);
            }

            return(paystubs);
        }
Esempio n. 2
0
        public void Add()
        {
            Paystub temp = new Paystub()
            {
                Index = (uint)PaystubDataList.Count + 1
            };

            if (NameInput != null)
            {
                temp.Name = NameInput;
            }

            if (GrossInput != null)
            {
                temp.Gross = (decimal)GrossInput;
            }

            if (NetInput != null)
            {
                temp.Net = (decimal)NetInput;
            }

            PaystubDataList.Add(temp);
            ClearInputFields();
        }
Esempio n. 3
0
 private static XElement CreatePaystubElement(Paystub p)
 {
     return new XElement(Element.Paystub,
         new XAttribute(Element.ID, p.Index),
         new XAttribute(Element.Name, p.Name),
         new XAttribute(Element.Gross, p.Gross),
         new XAttribute(Element.Net, p.Net),
         new XAttribute(Element.Percent, p.Percent)
         );
 }
Esempio n. 4
0
 public void CalculatePercentages()
 {
     PaystubDataList = new BindableCollection <Paystub>(Paystub.GetPercentages(PaystubDataList.ToList()));
 }
Esempio n. 5
0
 public void AddPaystub()
 {
     PaystubDataList.Add(Paystub.Default((uint)PaystubDataList.Count));
 }