Beispiel #1
0
  private void addEmployeePlans(
      List<EmployeePlan> employeePlans,
      Integer year,
      Integer month,
      Employee employee,
      JsonNode jsonNode) {
    final Map<JsonStringNode, JsonNode> fields = jsonNode.getFields();

    JsonStringNode field;

    for (Map.Entry<JsonStringNode, TSEnum> entry : PLAN_TYPE_MAP.entrySet()) {
      field = entry.getKey();

      final EmployeePlan employeePlan =
          createEmployeePlanIfNeed(
              year, month, employee, dictionaryItemService.find(entry.getValue().getId()));

      if (fields.containsKey(field)) {
        employeePlan.setValue(JsonUtil.getFloatNumberValue(jsonNode, field.getText()));

        employeePlans.add(employeePlan);
      }
    }

    // KSS APLANATS-850 Удалять будем только существующие записи с value=0.
    // Удаление будет вызвано в методе
    // com.aplana.timesheet.service.EmployeePlanService.mergeProjectPlans

  }
Beispiel #2
0
  public List<Vacation> getVacationList(VacationsForm vacationsForm) {
    Integer divisionId = vacationsForm.getDivisionId();
    Integer employeeId = vacationsForm.getEmployeeId();
    Date dateFrom = DateTimeUtil.parseStringToDateForDB(vacationsForm.getCalFromDate());
    Date dateTo = DateTimeUtil.parseStringToDateForDB(vacationsForm.getCalToDate());
    Integer projectId = vacationsForm.getProjectId();
    Integer managerId = vacationsForm.getManagerId();
    List<Integer> regions = vacationsForm.getRegions();
    DictionaryItem vacationType =
        vacationsForm.getVacationType() != 0
            ? dictionaryItemService.find(vacationsForm.getVacationType())
            : null;

    List<Vacation> vacations = new ArrayList<Vacation>();
    if (employeeId != null && employeeId != ALL_VALUE) {
      vacations.addAll(findVacations(employeeId, dateFrom, dateTo, vacationType));
    } else {
      List<Employee> employees =
          employeeService.getEmployees(
              employeeService.createDivisionList(divisionId),
              employeeService.createManagerList(managerId),
              employeeService.createRegionsList(regions),
              employeeService.createProjectList(projectId),
              dateFrom,
              dateTo,
              true);
      vacations.addAll(findVacations(employees, dateFrom, dateTo, vacationType));
    }
    sortVacations(vacations);
    return vacations;
  }
Beispiel #3
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()));
  }
Beispiel #4
0
 public Boolean isVacationNotApproved(Vacation vacation) {
   return !vacation
       .getStatus()
       .getId()
       .equals(dictionaryItemService.find(VacationStatusEnum.APPROVED.getId()).getId());
 }
Beispiel #5
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);
  }