/** * AddReportDetail to Grid */
  @Override
  public void addReportDetail(ActionEvent actionEvent) {

    logger.trace("addReportDetail... {}", inputReport014Detail);

    if (!validateReportDetail()) {
      return;
    }

    if (report014Details == null || report014Details.isEmpty()) {

      report014Details = new ArrayList<>();
      inputReport014Detail.setKey(1);

    } else {

      inputReport014Detail.setKey(report014Details.get(report014Details.size() - 1).getKey() + 1);
    }

    inputReport014Detail.setReportId(report014);

    report014Details.add(inputReport014Detail);

    JsfUtil.hidePopup("REPORT_014dlgAddReportDetail");
  }
  public void loginProcess() {

    MDC.put("reqId", ECTUtils.generateToken());

    logger.info("loginProcess!!");

    logger.info("userName : {} , passWord : {}", userName, "********");

    if (!validateLongin()) {
      addError("loggin fial!!");
      return;
    }

    /** * Authen Login */
    try {

      String nPassWord = ECTUtils.encrypt(passWord);

      loginUser = getAuthenDao().loginUser(userName, nPassWord);

    } catch (Exception ex) {

      logger.error("Cannot Authen : ", ex);
      return;
    }

    if (loginUser == null) {

      addError(MessageUtils.getResourceBundleString("login.authen.fail"));

      logger.warn("Login {} fail!!", loginUser);

      return;
    }

    if (!loginUser.getIsActive()) {

      addError(MessageUtils.getResourceBundleString("login.authen.disabled"));

      logger.warn("Login {} block user was disbled!!", loginUser);

      return;
    }

    loggedIn = true;

    super.getRequest().getSession().setAttribute("userAuthen", loginUser);

    addInfo(MessageUtils.getResourceBundleString("login.loginprocess"));

    String path = JsfUtil.getContextPath();

    logger.trace("path : {}", path);

    executeJavaScript(
        "setTimeout(function(){window.location='"
            + path
            + "/pages/form/index.xhtml?firstLogin=true';blockUI.show();},100);");
  }
  @Override
  public void save() {

    logger.trace(
        MessageUtils.PRINT_LINE_STAR() + "Save Report : {}",
        REPORT_014 + MessageUtils.PRINT_LINE_STAR());

    calSum();

    report014.setReport014DetailList(report014Details);
    report014.setCreatedDate(new Date());
    report014.setCreatedUser(super.getUserAuthen().getUserId());
    report014.setFlowStatusId(EctFlowStatus.FlowStatus.DRAFF.getStatus());
    report014.setReportDesc(ectConfManager.getReportName(REPORT_014));
    report014.setReportCode(REPORT_014);
    report014.setCreatedUserGroup(getUserAuthen().getUserGroupId());

    if (!validateBeforeSave()) {
      return;
    }

    try {

      reportGennericService.create(report014);

      logger.trace("Save Success !! ");

      JsfUtil.alertJavaScript(MessageUtils.SAVE_SUCCESS());

      goToClose();

    } catch (Exception ex) {

      JsfUtil.alertJavaScript(MessageUtils.SAVE_NOT_SUCCESS() + " ข้อผิดพลาด :" + MDC.get("reqId"));

      logger.error("Cannot Save Data : ", ex);

    } finally {

      logger.trace("Save... {} ", report014);
      resetForm();
    }
  }
  private boolean validateBeforeSave() {

    String msg = "";

    if (report014.getReport014DetailList() == null
        || report014.getReport014DetailList().isEmpty()) {
      msg += (MessageUtils.REQUIRE_ADD_REPORT_DETAIL());
    }

    if (!StringUtils.isBlank(msg.toString())) {
      JsfUtil.alertJavaScript(msg.toString().trim());
      return false;
    }

    return true;
  }
  /**
   * * Row Edit
   *
   * @param event
   */
  @Override
  public void onEdit(RowEditEvent event) {

    Report014Detail editRow = ((Report014Detail) event.getObject());

    logger.trace("Edit Row : {}", editRow);

    for (int i = 0; i < report014Details.size(); i++) {

      if (report014Details.get(i).getKey() == editRow.getKey()) {

        report014Details.remove(i);
        report014Details.add(i, editRow);

        logger.trace("After Edit Row : {}", editRow);
      }

      break;
    }

    JsfUtil.addSuccessMessage("แก้ใขข้อมูลสำเร็จ!!");
  }
  /**
   * * Row Cancel
   *
   * @param event
   */
  @Override
  public void onCancel(RowEditEvent event) {

    JsfUtil.addSuccessMessage("ยกเลิก!!");
  }
  public void logout() {

    logger.trace("logout!!");

    redirectPage(JsfUtil.getContextPath() + "/LogoutController");
  }