private void updateDocDetail(HttpServletRequest req) {

    String projectId = req.getParameter("project");
    String projectStageId = req.getParameter("projectStage");
    String costItemId = req.getParameter("costItem");
    String currencyString = req.getParameter("currency");
    String sumString = req.getParameter("sum");

    if (!req.getParameter("EditCurrentDetail").isEmpty()) {

      long rowNumber = Long.parseLong(req.getParameter("EditCurrentDetail"));
      PaymentDocument paymentDocument =
          (PaymentDocument) req.getSession(false).getAttribute("currentPaymentDocumentForEdit");

      if (paymentDocument == null) {

        LOG.error("Payment Document not found in session scope.");
        req.getSession(false)
            .setAttribute("errorMessage", "Payment Document not found. Please reload the page.");

      } else {

        PaymentDocumentDetail detail = paymentDocument.getPaymentDetailByRowNumber(rowNumber);

        try {

          if (!((costItemId == null) || costItemId.isEmpty())) {
            CostItem costItemRef = costItemService.retrieveById(Long.parseLong(costItemId));
            detail.setCostItem(costItemRef);
          }
          if (!((projectId == null) || projectId.isEmpty())) {
            Project projectRef = projectService.retrieveById(Long.parseLong(projectId));
            detail.setProject(projectRef);
          }
          if (!((projectStageId == null) || projectStageId.isEmpty())) {
            ProjectStage projectStageRef =
                projectStageService.retrieveById(Long.parseLong(projectStageId));
            detail.setProjectStage(projectStageRef);
          }
          Currency currency = Currency.getInstance(currencyString);
          Money sum = new Money(Double.parseDouble(sumString), currency);
          detail.setSum(sum);

        } catch (IllegalArgumentException | POMServicesException | POMDataModelException e) {

          LOG.error("Could not change Document Details properties: " + e.getMessage(), e);
          req.getSession(false)
              .setAttribute(
                  "errorMessage",
                  "Could not change Document Details properties: " + e.getMessage());
          return;
        }
        req.getSession(false).setAttribute("currentDocDetailForEdit", null);
      }
    }
  }
  private void markForDeleteDocDetail(HttpServletRequest req) {

    if (!req.getParameter("DellCurrentDetail").isEmpty()) {

      long rowNumber = Long.parseLong(req.getParameter("DellCurrentDetail"));
      PaymentDocument paymentDocument =
          (PaymentDocument) req.getSession(false).getAttribute("currentPaymentDocumentForEdit");

      if (paymentDocument == null) {

        LOG.error("Payment Document not found in session scope.");
        req.getSession(false)
            .setAttribute("errorMessage", "Payment Document not found. Please reload the page.");

      } else {

        PaymentDocumentDetail detail = paymentDocument.getPaymentDetailByRowNumber(rowNumber);
        if (detail != null) {
          detail.setMarkedForDelete(true);
        }
      }
    }
  }