예제 #1
0
  @Transactional
  public String approveVacation(Integer vacationId) {
    Vacation vacation = findVacation(vacationId);
    Set<VacationApproval> vacationApprovals = vacation.getVacationApprovals();

    Date responseDate = new Date();

    vacation.setStatus(dictionaryItemService.find(VacationStatusEnum.APPROVED.getId()));
    store(vacation);

    vacationApprovalProcessService.sendBackDateVacationApproved(vacation);

    if (!vacationApprovals.isEmpty()) {
      for (VacationApproval vacationApproval : vacationApprovals) {
        vacationApproval.setResult(true);
        vacationApproval.setResponseDate(responseDate);
        StringBuilder comment = new StringBuilder("Согласовано ");
        if (isVacationApprovePermission(vacation)) {
          comment.append("РЦК");
        } else if (request.isUserInRole(ROLE_ADMIN)) {
          comment.append("Администратором");
        }
        vacationApproval.setComment(comment.toString());
        vacationApprovalService.store(vacationApproval);
      }
    }

    return JsonUtil.format(
        anObjectBuilder().withField("isApproved", JsonNodeBuilders.aTrueBuilder()));
  }
예제 #2
0
 // возвращает количество дней в списке отпусков (в зависимости от того какой список был передан)
 private int getSummaryDaysCount(Map<Vacation, Integer> days) {
   int summaryDays = 0;
   for (Map.Entry<Vacation, Integer> entry : days.entrySet()) {
     Vacation vacation = entry.getKey();
     Integer daysInVacation = entry.getValue();
     if (VacationStatusEnum.APPROVED.getId() == vacation.getStatus().getId()
         || VacationTypesEnum.PLANNED.getId() == vacation.getType().getId()) {
       summaryDays += daysInVacation;
     }
   }
   return summaryDays;
 }
예제 #3
0
 /* функция возвращает можно ли удалить планируемый отпуск в таблице заявлений на отпуск */
 public Boolean isVacationDeletePermission(Vacation vacation, Employee employee) {
   if (employee != null && vacation != null) {
     /* проверим Админ ли текущий пользователь */
     if (employeeService.isEmployeeAdmin(employee.getId())) {
       return Boolean.TRUE;
     } else {
       /* для запланированных отпусков проверяем что это либо создатель отпуска либо сам отпускник
        * либо является лин. рук. отпускника */
       if (vacation.getType().getId() == VacationTypesEnum.PLANNED.getId()
           && (vacation.getEmployee().equals(employee)
               || vacation.getAuthor().equals(employee)
               || employeeService.getLinearEmployees(vacation.getEmployee()).contains(employee))) {
         return Boolean.TRUE;
       }
       /* пользователь создатель или отпускник и статус не отклонено и не утверждено */
       if ((vacation.getEmployee().equals(employee) || vacation.getAuthor().equals(employee))
           && vacation.getStatus().getId() != VacationStatusEnum.REJECTED.getId()
           && vacation.getStatus().getId() != VacationStatusEnum.APPROVED.getId()) {
         return Boolean.TRUE;
       }
     }
   }
   return Boolean.FALSE;
 }
예제 #4
0
 public Boolean isVacationNotApproved(Vacation vacation) {
   return !vacation
       .getStatus()
       .getId()
       .equals(dictionaryItemService.find(VacationStatusEnum.APPROVED.getId()).getId());
 }
예제 #5
0
 private boolean needsToBeApproved(Vacation vacation) {
   return !vacation.getStatus().getId().equals(VacationStatusEnum.APPROVED.getId());
 }
예제 #6
0
  public void createAndMailVacation(
      CreateVacationForm createVacationForm,
      Employee employee,
      Employee curEmployee,
      boolean isApprovedVacation)
      throws VacationApprovalServiceException {

    final Vacation vacation = new Vacation();

    vacation.setCreationDate(new Date());
    vacation.setBeginDate(DateTimeUtil.stringToTimestamp(createVacationForm.getCalFromDate()));
    vacation.setEndDate(DateTimeUtil.stringToTimestamp(createVacationForm.getCalToDate()));
    vacation.setComment(createVacationForm.getComment().trim());
    vacation.setType(dictionaryItemService.find(createVacationForm.getVacationType()));
    vacation.setAuthor(curEmployee);
    vacation.setEmployee(employee);
    vacation.setRemind(false);

    vacation.setStatus(
        dictionaryItemService.find(
            isApprovedVacation
                ? VacationStatusEnum.APPROVED.getId()
                : VacationStatusEnum.APPROVEMENT_WITH_PM.getId()));

    TransactionStatus transactionStatus = null;

    try {
      transactionStatus = getNewTransaction();

      store(vacation);

      boolean isPlannedVacation =
          vacation.getType().getId().equals(VacationTypesEnum.PLANNED.getId());

      if (isPlannedVacation) {
        vacationApprovalProcessService.sendNoticeForPlannedVacaton(vacation);
      } else {
        List<Vacation> plannedVacations =
            vacationDAO.getPlannedVacationsByBeginAndEndDates(
                employee, vacation.getBeginDate(), vacation.getEndDate());
        for (Vacation plannedVacation : plannedVacations) {
          delete(plannedVacation);
        }
        if (needsToBeApproved(vacation)) {
          vacationApprovalProcessService.sendVacationApproveRequestMessages(
              vacation); // рассылаем письма о согласовании отпуска
        } else {
          vacationApprovalProcessService.sendBackDateVacationApproved(vacation);
        }
      }
      commit(transactionStatus);
    } catch (VacationApprovalServiceException e) {
      if (transactionStatus != null) {
        rollback(transactionStatus);
        logger.error("Transaction rollbacked. Error saving vacation: {} ", e);
      } else {
        logger.error("TransactionStatus is null.");
      }
    }
    sendMailService.performVacationCreateMailing(vacation);
  }