Esempio n. 1
0
        public string CalculationOfAvailableVacationDays(int?employeeID)
        {
            if (employeeID.HasValue)
            {
                var employee = _employeeService.GetById(employeeID.Value);

                if (employee.EnrollmentDate.HasValue)
                {
                    EmployeeVacationDto employeeVacationDto = GetAvailableVacationDays(employee);

                    return(JsonConvert.SerializeObject(employeeVacationDto));
                }
            }

            return(JsonConvert.SerializeObject(""));
        }
Esempio n. 2
0
        //TODO перенести метод в VacationRecordService
        protected EmployeeVacationDto GetAvailableVacationDays(Employee employee)
        {
            EmployeeVacationDto employeeVacationDto = null;

            if (employee.EnrollmentDate.HasValue)
            {
                var employeeVacationRecordList = _vacationRecordService.Get(records => records.Where(x => x.EmployeeID == employee.ID).ToList());

                employeeVacationDto = new EmployeeVacationDto()
                {
                    ID        = employee.ID,
                    LastName  = employee.LastName,
                    FirstName = employee.FirstName,
                    MidName   = employee.MidName,
                    FullName  = employee.FullName,

                    EnrollmentDate = employee.EnrollmentDate
                };

                int durationOfVacation = 28;


                employeeVacationDto.VacationPaidDaysUsed = (employeeVacationRecordList.Where(r => r.VacationType == VacationRecordType.VacationPaid).Count() != 0) ?
                                                           employeeVacationRecordList.Where(r => r.VacationType == VacationRecordType.VacationPaid).Sum(x => x.VacationDays) : 0;

                employeeVacationDto.VacationNoPaidDaysUsed = (employeeVacationRecordList.Where(r => r.VacationType == VacationRecordType.VacationNoPaid).Count() != 0) ?
                                                             employeeVacationRecordList.Where(r => r.VacationType == VacationRecordType.VacationNoPaid).Sum(x => x.VacationDays) : 0;

                DateTime currentDay     = DateTime.Today;
                DateTime enrollmentDate = employeeVacationDto.EnrollmentDate.Value;

                int subtractDays = 0;


                // 1. отпусков без сохранения заработной платы, превышающее 14 календарных дней в текущем рабочем году сотрудника;
                var employeeVacationNoPaidRecordList = employeeVacationRecordList.Where(r => r.VacationType == VacationRecordType.VacationNoPaid).ToList();

                foreach (var employeeVacationNoPaidRecord in employeeVacationNoPaidRecordList)
                {
                    if (employeeVacationNoPaidRecord.VacationBeginDate <= currentDay)
                    {
                        DateTime dateBegin = (employeeVacationNoPaidRecord.VacationBeginDate.Year == currentDay.Year) ? employeeVacationNoPaidRecord.VacationBeginDate : new DateTime(currentDay.Year, 1, 1);
                        DateTime dateEnd   = (employeeVacationNoPaidRecord.VacationEndDate <= currentDay) ? employeeVacationNoPaidRecord.VacationEndDate : currentDay;

                        subtractDays += Convert.ToInt32(Math.Floor((dateEnd - dateBegin).TotalDays));
                    }
                }

                if (subtractDays < 14)
                {
                    subtractDays = 0;
                }

                //TODO
                // 2. нахождения в отпуске по уходу за ребенком;
                // 3. отсутствия без уважительных причин.

                enrollmentDate.AddDays(subtractDays);

                employeeVacationDto.SubtractDays = subtractDays;

                int monthCount = (currentDay.Year * 12 + currentDay.Month)
                                 - (enrollmentDate.Year * 12 + enrollmentDate.Month)
                                 + ((currentDay.Day >= enrollmentDate.Day) ? 0 : -1);

                if ((currentDay - enrollmentDate.AddMonths(monthCount)).TotalDays >= 15)
                {
                    employeeVacationDto.MonthCount = monthCount + 1;
                }
                else
                {
                    employeeVacationDto.MonthCount = monthCount;
                }

                employeeVacationDto.AvailableVacationDays = Convert.ToInt32(Math.Round((((double)durationOfVacation / 12) * employeeVacationDto.MonthCount) - employeeVacationDto.VacationPaidDaysUsed, 0, MidpointRounding.AwayFromZero));
            }

            return(employeeVacationDto);
        }