Exemplo n.º 1
0
        public Paycheck AddOrUpdatePaycheck(DateTime issueDate, DateTime from)
        {
            var maybePaychek = this.Paychecks.SingleOrDefault(p => p.GetPeriod().From == from);

            if (maybePaychek != null)
            {
                maybePaychek.Update(this);
                return(maybePaychek);
            }
            else
            {
                var paycheck = Paycheck.Create(this, DateTime.Now, from);
                this.Paychecks.Add(paycheck);
                return(paycheck);
            }
        }
Exemplo n.º 2
0
        public static Paycheck Create(Employee employee, DateTime issuingDate, DateTime from)
        {
            var period   = ValueObjects.Period.CreateForCurrentMonth(from);
            var paycheck = new Paycheck()
            {
                EmployeeId = employee.Id,
                Date       = issuingDate,
                Period     = period,
            };

            CalculateHours(paycheck, employee.Schedules.Where(s =>
                                                              s.Date >= period.From && s.Date <= period.To));

            paycheck.SubTotals = CalculateSubTotals(paycheck.GetWorkingHours(), paycheck.GetDaysOff(), employee.PayRate);
            paycheck.Total     = CalculateTotal(paycheck.GetSubTotals());

            return(paycheck);
        }
Exemplo n.º 3
0
        private static void CalculateHours(Paycheck paycheck, IEnumerable <Schedule> schedules)
        {
            var paidDaysOff   = schedules.Where(x => x.ScheduleOption == ScheduleOption.PaidDayOff).Count();
            var unpaidDaysOff = schedules.Where(x => x.ScheduleOption == ScheduleOption.UnpaidDayOff).Count();
            var sickDaysOff   = schedules.Where(x => x.ScheduleOption == ScheduleOption.UnpaidDayOff).Count();

            paycheck.DaysOff = ValueObjects.DaysOff.Create(paidDaysOff, unpaidDaysOff, sickDaysOff);

            var hourOnBusinessTrip = schedules.Where(x => x.ScheduleOption == ScheduleOption.BusinessTrip).Sum(x => x.WorkHours);
            var hourOnHolidays     = schedules.Where(x => x.ScheduleOption == ScheduleOption.Holiday).Sum(x => x.WorkHours);
            var hours      = schedules.Where(x => x.ScheduleOption == ScheduleOption.AtWork).Sum(x => x.WorkHours);
            var extraHours = schedules.Where(x =>
                                             x.ScheduleOption == ScheduleOption.Holiday ||
                                             x.ScheduleOption == ScheduleOption.AtWork ||
                                             x.ScheduleOption == ScheduleOption.BusinessTrip)
                             .Sum(x => x.ExtraWorkHours);

            paycheck.WorkingHours = ValueObjects.WorkingHours.Create(hours, hourOnBusinessTrip, hourOnHolidays, extraHours);
        }