/**
   * Удаляет отчет по id. В случае если текущий авторизованный пользователь является руководителем
   * сотрудника, добавившего отчет.
   *
   * @param id
   * @return OK или Error
   */
  @RequestMapping(value = "/timesheetDel/{id}", method = RequestMethod.POST)
  public String delTimeSheet(@PathVariable("id") Integer id, HttpServletRequest httpRequest) {
    TimeSheetUser securityUser = securityService.getSecurityPrincipal();
    if (securityUser == null) {
      throw new SecurityException("Не найден пользователь в контексте безопасности.");
    }

    TimeSheet timeSheet = timeSheetService.find(id);

    logger.info(
        "Удаляется отчет " + timeSheet + ". Инициатор: " + securityUser.getEmployee().getName());
    timeSheetService.delete(timeSheet);

    sendMailService.performTimeSheetDeletedMailing(timeSheet);

    return "redirect:" + httpRequest.getHeader("Referer");
  }
Beispiel #2
0
  @RequestMapping(value = "/report/{year}/{month}/{day}/{employeeId}", method = RequestMethod.GET)
  public ModelAndView sendViewReports(
      @PathVariable("year") Integer year,
      @PathVariable("month") Integer month,
      @PathVariable("day") Integer day,
      @PathVariable("employeeId") Integer employeeId,
      @ModelAttribute("ReportForm") TimeSheetForm tsForm,
      BindingResult result) {
    logger.info("Date for report: {}.{}", year, month);
    logger.info("Date for report: {}", day);
    ModelAndView mav = new ModelAndView("report");
    mav.addObject("ReportForm", tsForm);
    mav.addObject("year", Integer.toString(year));
    mav.addObject("month", month);
    mav.addObject("day", day);
    mav.addObject("employeeId", employeeId);

    final TimeSheet timeSheet =
        timeSheetService.findForDateAndEmployee(
            year.toString() + "-" + month.toString() + "-" + day.toString(), employeeId);

    if (timeSheet == null) {
      ModelAndView errorMav = new ModelAndView("/errors/commonErrors");
      errorMav.addObject("cause", ERROR_CAUSE);
      logger.error("Trying to view a report that was deleted or placed in draft");
      return errorMav;
    } else {

      mav.addObject(
          "creationDate",
          (timeSheet.getCreationDate() != null)
              ? DateTimeUtil.dateToString(
                  timeSheet.getCreationDate(), DateTimeUtil.VIEW_DATE_TIME_PATTERN)
              : "");
      mav.addObject(
          "report", reportService.modifyURL(sendMailService.initMessageBodyForReport(timeSheet)));

      logger.info("<<<<<<<<< End of RequestMapping <<<<<<<<<<<<<<<<<<<<<<");
      return mav;
    }
  }
  @RequestMapping(value = "/timesheet", method = RequestMethod.POST)
  public ModelAndView sendTimeSheet(
      @ModelAttribute("timeSheetForm") TimeSheetForm tsForm, BindingResult result) {
    logger.info(
        "Processing form validation for employee {} ({}).",
        tsForm.getEmployeeId(),
        tsForm.getCalDate());
    tsFormValidator.validate(tsForm, result);
    if (result.hasErrors()) {
      logger.info(
          "TimeSheetForm for employee {} has errors. Form not validated.", tsForm.getEmployeeId());
      ModelAndView mavWithErrors = new ModelAndView("timesheet");
      mavWithErrors.addObject("timeSheetForm", tsForm);
      mavWithErrors.addObject("errors", result.getAllErrors());
      mavWithErrors.addObject("selectedProjectsJson", getSelectedProjectsJson(tsForm));
      mavWithErrors.addObject("selectedProjectRolesJson", getSelectedProjectRolesJson(tsForm));
      mavWithErrors.addObject("selectedProjectTasksJson", getSelectedProjectTasksJson(tsForm));
      mavWithErrors.addObject("selectedWorkplaceJson", getSelectedWorkplaceJson(tsForm));
      mavWithErrors.addObject("selectedActCategoriesJson", getSelectedActCategoriesJson(tsForm));
      mavWithErrors.addObject(
          "selectedLongVacationIllnessJson", getSelectedLongVacationIllnessJson(tsForm));
      mavWithErrors.addObject("selectedCalDateJson", getSelectedCalDateJson(tsForm));
      mavWithErrors.addObject("getDateByDefault", getDateByDefault(tsForm.getEmployeeId()));
      mavWithErrors.addObject("getFirstWorkDate", getEmployeeFirstWorkDay(tsForm.getEmployeeId()));
      mavWithErrors.addAllObjects(getListsToMAV());

      return mavWithErrors;
    }
    TimeSheet timeSheet = timeSheetService.storeTimeSheet(tsForm);
    overtimeCauseService.store(timeSheet, tsForm);
    sendMailService.performMailing(tsForm);

    ModelAndView mav = new ModelAndView("selected");
    mav.addObject("timeSheetForm", tsForm);
    logger.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

    return mav;
  }
  // Пользователь списывает занятость за продолжительные отпуск или болезнь.
  @RequestMapping(value = "/timesheetLong", method = RequestMethod.POST)
  public ModelAndView sendTimeSheetLong(
      @ModelAttribute("timeSheetForm") TimeSheetForm tsForm, BindingResult result) {
    logger.info(
        "Processing form validation for employee {} ({}) (long).",
        tsForm.getEmployeeId(),
        tsForm.getCalDate());
    tsFormValidator.validate(tsForm, result);
    if (result.hasErrors()) {
      logger.info(
          "TimeSheetForm for employee {} has errors. Form not validated (long).",
          tsForm.getEmployeeId());
      ModelAndView mavWithErrors = new ModelAndView("timesheet");
      mavWithErrors.addObject("timeSheetForm", tsForm);
      mavWithErrors.addObject("errors", result.getAllErrors());
      mavWithErrors.addObject("selectedProjectRolesJson", "[{row:'0', role:''}]");
      mavWithErrors.addObject("selectedProjectTasksJson", "[{row:'0', task:''}]");
      mavWithErrors.addObject("selectedProjectsJson", "[{row:'0', project:''}]");
      mavWithErrors.addObject("selectedActCategoriesJson", "[{row:'0', actCat:''}]");
      mavWithErrors.addObject("selectedWorkplace", "[{row:'0', workplace:''}]");
      mavWithErrors.addObject("selectedCalDateJson", "''");
      mavWithErrors.addObject(
          "selectedLongVacationIllnessJson", getSelectedLongVacationIllnessJson(tsForm));
      mavWithErrors.addAllObjects(getListsToMAV());

      return mavWithErrors;
    }
    timeSheetService.storeTimeSheetLong(tsForm);
    sendMailService.performMailing(tsForm);

    ModelAndView mav = new ModelAndView("selected");
    mav.addObject("timeSheetForm", tsForm);
    logger.info("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

    return mav;
  }