Exemple #1
0
  public Integer getVacationDaysCount(
      Employee employee, Integer year, Integer month, Boolean fact) {
    VacationDays vacationDays = vacationDaysService.findByEmployee(employee);
    if (vacationDays != null) {
      Calendar calendarAct = Calendar.getInstance();
      calendarAct.setTime(employee.getStartDate());

      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.MONTH, --month);
      calendar.set(Calendar.YEAR, year);
      calendar.set(Calendar.DAY_OF_MONTH, calendarAct.get(Calendar.DAY_OF_MONTH));

      Date start = vacationDays.getActualizationDate();
      Date end = calendar.getTime();

      if (start.after(end)) {
        return 0;
      }

      int months = DateTimeUtil.getDiffInMonths(start, end);
      int vacDays = (int) (++months * VACATION_KOEF);
      vacDays += vacationDays.getCountDays();
      Integer vacationsCountByPeriod;
      if (!fact) {
        vacationsCountByPeriod =
            getPlannedVacationsCountByPeriod(employee, vacationDays.getActualizationDate());
      } else {
        vacationsCountByPeriod =
            getFactVacationsCountByPeriod(employee, vacationDays.getActualizationDate());
      }
      if (vacDays > 0) {
        vacDays -= vacationsCountByPeriod;
        return vacDays;
      } else {
        return vacDays;
      }
    }
    return null;
  }