private void printPageDataSheet(
      HttpServletResponse response,
      VariablesSecureApp vars,
      String strComparative,
      String strDateFrom,
      String strDateTo,
      String strPartnerGroup,
      String strcBpartnerId,
      String strProductCategory,
      String strmProductId,
      String strNotShown,
      String strShown,
      String strDateFromRef,
      String strDateToRef,
      String strOrg,
      String strsalesrepId,
      String strmWarehouseId,
      String strOrder,
      String strMayor,
      String strMenor,
      String strRatioMayor,
      String strRatioMenor,
      String strCurrencyId)
      throws IOException, ServletException {
    if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
    String discard[] = {"selEliminarHeader1"};
    String strCommand = "EDIT_PDF";
    if (strComparative.equals("Y")) {
      discard[0] = "selEliminarHeader2";
      strCommand = "EDIT_PDF_COMPARATIVE";
    }
    XmlDocument xmlDocument = null;
    xmlDocument =
        xmlEngine
            .readXmlTemplate(
                "org/openbravo/erpCommon/ad_reports/ReportRefundSalesDimensionalAnalysesFilter",
                discard)
            .createXmlDocument();

    ToolBar toolbar =
        new ToolBar(
            this,
            vars.getLanguage(),
            "ReportRefundSalesDimensionalAnalysesFilter",
            false,
            "",
            "",
            "",
            false,
            "ad_reports",
            strReplaceWith,
            false,
            true);
    toolbar.prepareSimpleToolBarTemplate();
    xmlDocument.setParameter("toolbar", toolbar.toString());

    try {
      WindowTabs tabs =
          new WindowTabs(
              this,
              vars,
              "org.openbravo.erpCommon.ad_reports.ReportRefundSalesDimensionalAnalyses");
      xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
      xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
      xmlDocument.setParameter("childTabContainer", tabs.childTabs());
      xmlDocument.setParameter("theme", vars.getTheme());
      NavigationBar nav =
          new NavigationBar(
              this,
              vars.getLanguage(),
              "ReportRefundSalesDimensionalAnalyses.html",
              classInfo.id,
              classInfo.type,
              strReplaceWith,
              tabs.breadcrumb());
      xmlDocument.setParameter("navigationBar", nav.toString());
      LeftTabsBar lBar =
          new LeftTabsBar(
              this,
              vars.getLanguage(),
              "ReportRefundSalesDimensionalAnalyses.html",
              strReplaceWith);
      xmlDocument.setParameter("leftTabs", lBar.manualTemplate());
    } catch (Exception ex) {
      throw new ServletException(ex);
    }
    {
      OBError myMessage = vars.getMessage("ReportRefundSalesDimensionalAnalyses");
      vars.removeMessage("ReportRefundSalesDimensionalAnalyses");
      if (myMessage != null) {
        xmlDocument.setParameter("messageType", myMessage.getType());
        xmlDocument.setParameter("messageTitle", myMessage.getTitle());
        xmlDocument.setParameter("messageMessage", myMessage.getMessage());
      }
    }

    xmlDocument.setParameter("calendar", vars.getLanguage().substring(0, 2));
    xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";");
    xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
    xmlDocument.setParameter("dateFrom", strDateFrom);
    xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
    xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
    xmlDocument.setParameter("dateTo", strDateTo);
    xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
    xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
    xmlDocument.setParameter("dateFromRef", strDateFromRef);
    xmlDocument.setParameter("dateFromRefdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
    xmlDocument.setParameter("dateFromRefsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
    xmlDocument.setParameter("dateToRef", strDateToRef);
    xmlDocument.setParameter("dateToRefdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
    xmlDocument.setParameter("dateToRefsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
    xmlDocument.setParameter("cBpGroupId", strPartnerGroup);
    xmlDocument.setParameter("mProductCategoryId", strProductCategory);
    xmlDocument.setParameter("adOrgId", strOrg);
    xmlDocument.setParameter("salesRepId", strsalesrepId);
    xmlDocument.setParameter("mWarehouseId", strmWarehouseId);
    xmlDocument.setParameter("normal", strOrder);
    xmlDocument.setParameter("amountasc", strOrder);
    xmlDocument.setParameter("amountdesc", strOrder);
    xmlDocument.setParameter("ratioasc", strOrder);
    xmlDocument.setParameter("ratiodesc", strOrder);
    xmlDocument.setParameter("mayor", strMayor);
    xmlDocument.setParameter("menor", strMenor);
    xmlDocument.setParameter("ratioMayor", strRatioMayor);
    xmlDocument.setParameter("ratioMenor", strRatioMenor);
    xmlDocument.setParameter("comparative", strComparative);
    xmlDocument.setParameter("command", strCommand);
    try {
      ComboTableData comboTableData =
          new ComboTableData(
              vars,
              this,
              "TABLEDIR",
              "C_BP_Group_ID",
              "",
              "",
              Utility.getContext(
                  this, vars, "#AccessibleOrgTree", "ReportRefundSalesDimensionalAnalyses"),
              Utility.getContext(
                  this, vars, "#User_Client", "ReportRefundSalesDimensionalAnalyses"),
              0);
      Utility.fillSQLParameters(
          this,
          vars,
          null,
          comboTableData,
          "ReportRefundSalesDimensionalAnalyses",
          strPartnerGroup);
      xmlDocument.setData("reportC_BP_GROUPID", "liststructure", comboTableData.select(false));
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    try {
      ComboTableData comboTableData =
          new ComboTableData(
              vars,
              this,
              "TABLEDIR",
              "M_Product_Category_ID",
              "",
              "",
              Utility.getContext(
                  this, vars, "#AccessibleOrgTree", "ReportRefundSalesDimensionalAnalyses"),
              Utility.getContext(
                  this, vars, "#User_Client", "ReportRefundSalesDimensionalAnalyses"),
              0);
      Utility.fillSQLParameters(
          this,
          vars,
          null,
          comboTableData,
          "ReportRefundSalesDimensionalAnalyses",
          strProductCategory);
      xmlDocument.setData(
          "reportM_PRODUCT_CATEGORYID", "liststructure", comboTableData.select(false));
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }
    try {
      ComboTableData comboTableData =
          new ComboTableData(
              vars,
              this,
              "TABLEDIR",
              "AD_Org_ID",
              "",
              "",
              Utility.getContext(
                  this, vars, "#AccessibleOrgTree", "ReportRefundSalesDimensionalAnalyses"),
              Utility.getContext(
                  this, vars, "#User_Client", "ReportRefundSalesDimensionalAnalyses"),
              0);
      Utility.fillSQLParameters(
          this, vars, null, comboTableData, "ReportRefundSalesDimensionalAnalyses", strOrg);
      xmlDocument.setData("reportAD_ORGID", "liststructure", comboTableData.select(false));
      comboTableData = null;

    } catch (Exception ex) {
      throw new ServletException(ex);
    }
    try {
      ComboTableData comboTableData =
          new ComboTableData(
              vars,
              this,
              "TABLE",
              "SalesRep_ID",
              "AD_User SalesRep",
              "",
              Utility.getContext(
                  this, vars, "#AccessibleOrgTree", "ReportRefundSalesDimensionalAnalyses"),
              Utility.getContext(
                  this, vars, "#User_Client", "ReportRefundSalesDimensionalAnalyses"),
              0);
      Utility.fillSQLParameters(
          this, vars, null, comboTableData, "ReportRefundSalesDimensionalAnalyses", strsalesrepId);
      xmlDocument.setData("reportSalesRep_ID", "liststructure", comboTableData.select(false));
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    xmlDocument.setData(
        "reportCBPartnerId_IN",
        "liststructure",
        SelectorUtilityData.selectBpartner(
            this,
            Utility.getContext(this, vars, "#AccessibleOrgTree", ""),
            Utility.getContext(this, vars, "#User_Client", ""),
            strcBpartnerId));
    xmlDocument.setData(
        "reportMProductId_IN",
        "liststructure",
        SelectorUtilityData.selectMproduct(
            this,
            Utility.getContext(this, vars, "#AccessibleOrgTree", ""),
            Utility.getContext(this, vars, "#User_Client", ""),
            strmProductId));
    try {
      ComboTableData comboTableData =
          new ComboTableData(
              vars,
              this,
              "TABLEDIR",
              "M_Warehouse_ID",
              "",
              "",
              Utility.getContext(this, vars, "#AccessibleOrgTree", "ReportSalesDimensionalAnalyze"),
              Utility.getContext(
                  this, vars, "#User_Client", "ReportRefundSalesDimensionalAnalyses"),
              0);
      Utility.fillSQLParameters(
          this,
          vars,
          null,
          comboTableData,
          "ReportRefundSalesDimensionalAnalyses",
          strmWarehouseId);
      xmlDocument.setData("reportM_WAREHOUSEID", "liststructure", comboTableData.select(false));
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    xmlDocument.setParameter("ccurrencyid", strCurrencyId);
    try {
      ComboTableData comboTableData =
          new ComboTableData(
              vars,
              this,
              "TABLEDIR",
              "C_Currency_ID",
              "",
              "",
              Utility.getContext(
                  this, vars, "#AccessibleOrgTree", "ReportRefundSalesDimensionalAnalyses"),
              Utility.getContext(
                  this, vars, "#User_Client", "ReportRefundSalesDimensionalAnalyses"),
              0);
      Utility.fillSQLParameters(
          this, vars, null, comboTableData, "ReportRefundSalesDimensionalAnalyses", strCurrencyId);
      xmlDocument.setData("reportC_Currency_ID", "liststructure", comboTableData.select(false));
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    if (vars.getLanguage().equals("en_US")) {
      xmlDocument.setData(
          "structure1", ReportRefundSalesDimensionalAnalysesData.selectNotShown(this, strShown));
      xmlDocument.setData(
          "structure2",
          strShown.equals("")
              ? new ReportRefundSalesDimensionalAnalysesData[0]
              : ReportRefundSalesDimensionalAnalysesData.selectShown(this, strShown));
    } else {
      xmlDocument.setData(
          "structure1",
          ReportRefundSalesDimensionalAnalysesData.selectNotShownTrl(
              this, vars.getLanguage(), strShown));
      xmlDocument.setData(
          "structure2",
          strShown.equals("")
              ? new ReportRefundSalesDimensionalAnalysesData[0]
              : ReportRefundSalesDimensionalAnalysesData.selectShownTrl(
                  this, vars.getLanguage(), strShown));
    }

    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println(xmlDocument.print());
    out.close();
  }
  @Override
  protected void execute(CalloutInfo info) throws ServletException {

    // General data

    String strBPartner = info.vars.getStringParameter("inpcBpartnerId");
    String strIsSOTrx = Utility.getContext(this, info.vars, "isSOTrx", info.getWindowId());
    String strOrgId = info.vars.getStringParameter("inpadOrgId");
    String strPriceList = "";
    String strUserRep = "";
    String strInvoiceRule = "";
    String strFinPaymentMethodId = "";
    String strPaymentrule = "";
    String strDeliveryViaRule = "";
    String strPaymentterm = "";
    String strDeliveryRule = "";
    String strDocTypeTarget = info.vars.getStringParameter("inpcDoctypetargetId");
    String docSubTypeSO = "";

    BpartnerMiscData[] data = BpartnerMiscData.select(this, strBPartner);
    if (data != null && data.length > 0) {
      strDeliveryRule =
          data[0].deliveryrule.equals("")
              ? info.vars.getStringParameter("inpdeliveryrule")
              : data[0].deliveryrule;
      strUserRep = SEOrderBPartnerData.userIdSalesRep(this, data[0].salesrepId);
      strUserRep =
          strUserRep.equals("") ? info.vars.getStringParameter("inpsalesrepId") : strUserRep;
      SLOrderDocTypeData[] docTypeData = SLOrderDocTypeData.select(this, strDocTypeTarget);
      if (docTypeData != null && docTypeData.length > 0) {
        docSubTypeSO = docTypeData[0].docsubtypeso;
      }
      strInvoiceRule =
          (docSubTypeSO.equals("PR") || docSubTypeSO.equals("WI") || data[0].invoicerule.equals("")
              ? info.vars.getStringParameter("inpinvoicerule")
              : data[0].invoicerule);
      strPaymentrule = (strIsSOTrx.equals("Y") ? data[0].paymentrule : data[0].paymentrulepo);
      strPaymentrule =
          strPaymentrule.equals("")
              ? info.vars.getStringParameter("inppaymentrule")
              : strPaymentrule;

      strPaymentterm = (strIsSOTrx.equals("Y") ? data[0].cPaymenttermId : data[0].poPaymenttermId);
      if (strPaymentterm.equalsIgnoreCase("")) {
        BpartnerMiscData[] paymentTerm =
            BpartnerMiscData.selectPaymentTerm(this, strOrgId, info.vars.getClient());
        if (paymentTerm.length != 0) {
          strPaymentterm =
              strPaymentterm.equals("") ? paymentTerm[0].cPaymenttermId : strPaymentterm;
        }
      }
      strPaymentterm =
          strPaymentterm.equals("")
              ? info.vars.getStringParameter("inpcPaymenttermId")
              : strPaymentterm;

      strFinPaymentMethodId =
          (strIsSOTrx.equals("Y") ? data[0].finPaymentmethodId : data[0].poPaymentmethodId);

      strPriceList = (strIsSOTrx.equals("Y") ? data[0].mPricelistId : data[0].poPricelistId);
      if (strPriceList.equalsIgnoreCase("")) {
        strPriceList =
            SEOrderBPartnerData.defaultPriceList(this, strIsSOTrx, info.vars.getClient());
      }
      strPriceList =
          strPriceList.equals("") ? info.vars.getStringParameter("inpmPricelistId") : strPriceList;
      strDeliveryViaRule =
          data[0].deliveryviarule.equals("")
              ? info.vars.getStringParameter("inpdeliveryviarule")
              : data[0].deliveryviarule;
    }

    // Price list

    info.addResult(
        "inpmPricelistId",
        strPriceList.equals("")
            ? Utility.getContext(this, info.vars, "#M_PriceList_ID", info.getWindowId())
            : strPriceList);

    // BPartner Location

    FieldProvider[] tdv = null;

    String strLocation = info.vars.getStringParameter("inpcBpartnerId_LOC");
    if (strLocation != null && !strLocation.isEmpty()) {
      info.addResult("inpcBpartnerLocationId", strLocation);
    }

    // Warehouses

    FieldProvider[] td = null;
    try {
      ComboTableData comboTableData =
          new ComboTableData(
              info.vars,
              this,
              "18",
              "M_Warehouse_ID",
              "197",
              "",
              Utility.getReferenceableOrg(info.vars, info.vars.getStringParameter("inpadOrgId")),
              Utility.getContext(this, info.vars, "#User_Client", info.getWindowId()),
              0);
      Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
      td = comboTableData.select(false);
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    if (td != null && td.length > 0) {
      info.addSelect("inpmWarehouseId");
      String strMwarehouse = SEOrderBPartnerData.mWarehouse(this, strBPartner);

      if (strMwarehouse.equals("")) {
        strMwarehouse = info.vars.getWarehouse();
      }

      for (int i = 0; i < td.length; i++) {
        info.addSelectResult(
            td[i].getField("id"),
            td[i].getField("name"),
            td[i].getField("id").equalsIgnoreCase(strMwarehouse));
      }
      info.endSelect();
    } else {
      info.addResult("inpmWarehouseId", null);
    }
    // Sales Representative

    FieldProvider[] tld = null;
    try {
      ComboTableData comboTableData =
          new ComboTableData(
              info.vars,
              this,
              "TABLE",
              "",
              "AD_User SalesRep",
              "",
              Utility.getContext(this, info.vars, "#AccessibleOrgTree", "SEOrderBPartner"),
              Utility.getContext(this, info.vars, "#User_Client", "SEOrderBPartner"),
              0);
      Utility.fillSQLParameters(this, info.vars, null, comboTableData, "SEOrderBPartner", "");
      tld = comboTableData.select(false);
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    if (tld != null && tld.length > 0) {
      info.addSelect("inpsalesrepId");
      for (int i = 0; i < tld.length; i++) {
        info.addSelectResult(
            tld[i].getField("id"),
            tld[i].getField("name"),
            tld[i].getField("id").equalsIgnoreCase(strUserRep));
      }

      info.endSelect();

    } else {
      info.addResult("inpsalesrepId", null);
    }

    // Invoice Rule

    FieldProvider[] l = null;
    try {
      ComboTableData comboTableData = null;
      if ("WR".equals(docSubTypeSO)) {
        comboTableData =
            new ComboTableData(
                info.vars,
                this,
                "LIST",
                "",
                "C_Order InvoiceRule",
                "Values for Invoice Rules for POS Sales orders",
                Utility.getContext(this, info.vars, "#AccessibleOrgTree", "SEOrderBPartner"),
                Utility.getContext(this, info.vars, "#User_Client", "SEOrderBPartner"),
                0);
      } else {
        comboTableData =
            new ComboTableData(
                info.vars,
                this,
                "LIST",
                "",
                "C_Order InvoiceRule",
                "",
                Utility.getContext(this, info.vars, "#AccessibleOrgTree", "SEOrderBPartner"),
                Utility.getContext(this, info.vars, "#User_Client", "SEOrderBPartner"),
                0);
      }
      Utility.fillSQLParameters(this, info.vars, null, comboTableData, "SEOrderBPartner", "");
      l = comboTableData.select(false);
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    if (l != null && l.length > 0) {
      info.addSelect("inpinvoicerule");
      for (int i = 0; i < l.length; i++) {
        info.addSelectResult(
            l[i].getField("id"),
            l[i].getField("name"),
            l[i].getField("id").equalsIgnoreCase(strInvoiceRule));
      }

      info.endSelect();

    } else {
      info.addResult("inpinvoicerule", null);
    }
    // Project

    info.addResult("inpcProjectId", "");

    // Project R

    info.addResult("inpcProjectId_R", "");

    // Financial Payment

    if (!"".equals(strFinPaymentMethodId)) {
      info.addResult("inpfinPaymentmethodId", strFinPaymentMethodId);
    }

    // Bill to

    if (strLocation != null && !strLocation.isEmpty()) {
      info.addResult("inpbilltoId", strLocation);
    }

    // Payment rule

    info.addResult("inppaymentrule", strPaymentrule);

    // Delivery via rule

    info.addResult("inpdeliveryviarule", strDeliveryViaRule);

    // Discount printed

    info.addResult(
        "inpisdiscountprinted", SEOrderBPartnerData.getIsDicountPrinted(this, strBPartner));

    // Payment term

    info.addResult("inpcPaymenttermId", strPaymentterm);

    // Delivery rule

    try {
      ComboTableData comboTableData =
          new ComboTableData(
              info.vars,
              this,
              "LIST",
              "",
              "C_Order DeliveryRule",
              "",
              Utility.getContext(this, info.vars, "#AccessibleOrgTree", "SEOrderBPartner"),
              Utility.getContext(this, info.vars, "#User_Client", "SEOrderBPartner"),
              0);
      Utility.fillSQLParameters(this, info.vars, null, comboTableData, "SEOrderBPartner", "");
      l = comboTableData.select(false);
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    if (strIsSOTrx.equals("N")) {
      info.addResult(
          "inpdeliveryrule",
          strDeliveryRule.equals("")
              ? ((l != null && l.length > 0) ? l[0].getField("id") : "null")
              : strDeliveryRule);
    } else {

      if (l != null && l.length > 0) {
        info.addSelect("inpdeliveryrule");

        for (int i = 0; i < l.length; i++) {
          info.addSelectResult(
              l[i].getField("id"),
              l[i].getField("name"),
              l[i].getField("id").equalsIgnoreCase(strDeliveryRule));
        }

        info.endSelect();
      } else {
        info.addResult("inpdeliveryrule", null);
      }
    }

    // Ad User

    try {
      ComboTableData comboTableData =
          new ComboTableData(
              info.vars,
              this,
              "TABLEDIR",
              "AD_User_ID",
              "",
              "AD_User C_BPartner User/Contacts",
              Utility.getContext(this, info.vars, "#AccessibleOrgTree", info.getWindowId()),
              Utility.getContext(this, info.vars, "#User_Client", info.getWindowId()),
              0);
      Utility.fillSQLParameters(this, info.vars, null, comboTableData, info.getWindowId(), "");
      tdv = comboTableData.select(false);
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    if (tdv != null && tdv.length > 0) {
      info.addSelect("inpadUserId");

      String contactID = info.vars.getStringParameter("inpcBpartnerId_CON");
      if (contactID.isEmpty()) {
        // If a contactID has not been specified, the first one is selected
        info.addSelectResult(tdv[0].getField("id"), tdv[0].getField("name"), true);
        for (int i = 1; i < tdv.length; i++) {
          info.addSelectResult(tdv[i].getField("id"), tdv[i].getField("name"), false);
        }
      } else {
        for (int i = 0; i < tdv.length; i++) {
          info.addSelectResult(
              tdv[i].getField("id"),
              tdv[i].getField("name"),
              tdv[i]
                  .getField("id")
                  .equalsIgnoreCase(info.vars.getStringParameter("inpcBpartnerId_CON")));
        }
      }
      info.endSelect();

    } else {
      info.addResult("inpadUserId", null);
    }

    // Message

    StringBuilder message = new StringBuilder();
    final String rtvendor = "C50A8AEE6F044825B5EF54FAAE76826F";
    final String rfcustomer = "FF808081330213E60133021822E40007";
    String strwindow = info.getStringParameter("inpwindowId", null);

    if (!(strwindow.equals(rtvendor) || strwindow.equals(rfcustomer))) {
      if ((!strBPartner.equals(""))
          && (FIN_Utility.isBlockedBusinessPartner(strBPartner, "Y".equals(strIsSOTrx), 1))) {
        // If the Business Partner is blocked for this document, show an information message.
        if (message.length() > 0) {
          message.append("<br>");
        }
        BusinessPartner bPartner = OBDal.getInstance().get(BusinessPartner.class, strBPartner);
        message.append(
            OBMessageUtils.messageBD("ThebusinessPartner")
                + " "
                + bPartner.getIdentifier()
                + " "
                + OBMessageUtils.messageBD("BusinessPartnerBlocked"));
      }
    }

    if (data != null
        && data.length > 0
        && new BigDecimal(data[0].creditavailable).compareTo(BigDecimal.ZERO) < 0
        && strIsSOTrx.equals("Y")) {
      if (message.length() > 0) {
        message.append("<br>");
      }
      String creditLimitExceed = "" + Double.parseDouble(data[0].creditavailable) * -1;
      message.append(
          Utility.messageBD(this, "CreditLimitOver", info.vars.getLanguage()) + creditLimitExceed);
    }

    info.addResult("MESSAGE", message.toString());
  }
  private void printPage(
      HttpServletResponse response,
      VariablesSecureApp vars,
      String strKey,
      String strProjectType,
      String windowId,
      String strTab,
      String strProcessId)
      throws IOException, ServletException {
    if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Project set Type");

    ActionButtonDefaultData[] data = null;
    String strHelp = "", strDescription = "";
    if (vars.getLanguage().equals("en_US"))
      data = ActionButtonDefaultData.select(this, strProcessId);
    else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);

    if (data != null && data.length != 0) {
      strDescription = data[0].description;
      strHelp = data[0].help;
    }
    String[] discard = {""};
    if (strHelp.equals("")) discard[0] = new String("helpDiscard");
    XmlDocument xmlDocument =
        xmlEngine
            .readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/ProjectSetType", discard)
            .createXmlDocument();
    xmlDocument.setParameter("key", strKey);
    xmlDocument.setParameter("window", windowId);
    xmlDocument.setParameter("tab", strTab);
    xmlDocument.setParameter("calendar", vars.getLanguage().substring(0, 2));
    xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";");
    xmlDocument.setParameter(
        "question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
    xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
    xmlDocument.setParameter("theme", vars.getTheme());
    xmlDocument.setParameter("description", strDescription);
    xmlDocument.setParameter("help", strHelp);

    try {
      ComboTableData comboTableData =
          new ComboTableData(
              vars,
              this,
              "TABLEDIR",
              "C_ProjectType_ID",
              "",
              "Project type service",
              Utility.getContext(this, vars, "#AccessibleOrgTree", ""),
              Utility.getContext(this, vars, "#User_Client", ""),
              0);
      Utility.fillSQLParameters(this, vars, null, comboTableData, "", strProjectType);
      xmlDocument.setData("reportcProjecttypeId", "liststructure", comboTableData.select(false));
      comboTableData = null;
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    ProjectSetTypeData[] dataDates = ProjectSetTypeData.selectDates(this, strKey);
    String strDateFrom =
        dataDates[0].startdate.equals("") ? DateTimeData.today(this) : dataDates[0].startdate;
    xmlDocument.setParameter("dateFrom", strDateFrom);
    xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
    xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));

    xmlDocument.setParameter("cProjecttypeId", strProjectType);

    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println(xmlDocument.print());
    out.close();
  }
  private void printPageEdit(
      HttpServletResponse response,
      HttpServletRequest request,
      VariablesSecureApp vars,
      boolean boolNew,
      String strC_BP_Group_ID,
      TableSQLData tableSQL)
      throws IOException, ServletException {
    if (log4j.isDebugEnabled()) log4j.debug("Output: edit");

    HashMap<String, String> usedButtonShortCuts;

    usedButtonShortCuts = new HashMap<String, String>();

    String strOrderByFilter = vars.getSessionValue(tabId + "|orderby");
    String orderClause = " C_BP_Group.Value";
    if (strOrderByFilter == null || strOrderByFilter.equals("")) strOrderByFilter = orderClause;
    /*{
      if (!strOrderByFilter.equals("") && !orderClause.equals("")) strOrderByFilter += ", ";
      strOrderByFilter += orderClause;
    }*/

    String strCommand = null;
    BusinessPartnerCategoryData[] data = null;
    XmlDocument xmlDocument = null;
    FieldProvider dataField = vars.getEditionData(tabId);
    vars.removeEditionData(tabId);
    String strParamName = vars.getSessionValue(tabId + "|paramName");

    boolean hasSearchCondition = false;
    hasSearchCondition =
        (tableSQL.hasInternalFilter() && ("").equals(strParamName))
            || !(("").equals(strParamName) || ("%").equals(strParamName));

    String strParamSessionDate =
        vars.getGlobalVariable(
            "inpParamSessionDate", Utility.getTransactionalDate(this, vars, windowId), "");
    String buscador = "";
    String[] discard = {"", "isNotTest"};

    if (vars.getSessionValue("#ShowTest", "N").equals("Y")) discard[1] = new String("isTest");
    if (dataField == null) {
      if (!boolNew) {
        discard[0] = new String("newDiscard");
        data =
            BusinessPartnerCategoryData.selectEdit(
                this,
                vars.getSessionValue("#AD_SqlDateTimeFormat"),
                vars.getLanguage(),
                strC_BP_Group_ID,
                Utility.getContext(this, vars, "#User_Client", windowId),
                Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel));

        if (!strC_BP_Group_ID.equals("") && (data == null || data.length == 0)) {
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
          return;
        }
        refreshSessionEdit(vars, data);
        strCommand = "EDIT";
      }

      if (boolNew || data == null || data.length == 0) {
        discard[0] = new String("editDiscard");
        strCommand = "NEW";
        data = new BusinessPartnerCategoryData[0];
      } else {
        discard[0] = new String("newDiscard");
      }
    } else {
      if (dataField.getField("cBpGroupId") == null || dataField.getField("cBpGroupId").equals("")) {
        discard[0] = new String("editDiscard");
        strCommand = "NEW";
        boolNew = true;
      } else {
        discard[0] = new String("newDiscard");
        strCommand = "EDIT";
      }
    }

    if (dataField == null) {
      if (boolNew || data == null || data.length == 0) {
        refreshSessionNew(vars);
        data =
            BusinessPartnerCategoryData.set(
                "",
                Utility.getDefault(
                    this, vars, "AD_Client_ID", "@AD_CLIENT_ID@", "192", "", dataField),
                Utility.getDefault(this, vars, "AD_Org_ID", "@AD_Org_ID@", "192", "", dataField),
                "Y",
                Utility.getDefault(this, vars, "CreatedBy", "", "192", "", dataField),
                BusinessPartnerCategoryData.selectDef4966_0(
                    this, Utility.getDefault(this, vars, "CreatedBy", "", "192", "", dataField)),
                Utility.getDefault(this, vars, "UpdatedBy", "", "192", "", dataField),
                BusinessPartnerCategoryData.selectDef4968_1(
                    this, Utility.getDefault(this, vars, "UpdatedBy", "", "192", "", dataField)),
                Utility.getDefault(this, vars, "Value", "", "192", "", dataField),
                Utility.getDefault(this, vars, "Name", "", "192", "", dataField),
                Utility.getDefault(this, vars, "Description", "", "192", "", dataField),
                Utility.getDefault(this, vars, "IsDefault", "", "192", "N", dataField));
      }
    }

    String currentOrg =
        (boolNew
            ? ""
            : (dataField != null ? dataField.getField("adOrgId") : data[0].getField("adOrgId")));
    if (!currentOrg.equals("") && !currentOrg.startsWith("'")) currentOrg = "'" + currentOrg + "'";
    String currentClient =
        (boolNew
            ? ""
            : (dataField != null
                ? dataField.getField("adClientId")
                : data[0].getField("adClientId")));
    if (!currentClient.equals("") && !currentClient.startsWith("'"))
      currentClient = "'" + currentClient + "'";

    boolean hasReadOnlyAccess =
        org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(
            this, vars.getRole(), tabId);
    boolean editableTab =
        (!hasReadOnlyAccess
            && (currentOrg.equals("")
                || Utility.isElementInList(
                    Utility.getContext(this, vars, "#User_Org", windowId, accesslevel), currentOrg))
            && (currentClient.equals("")
                || Utility.isElementInList(
                    Utility.getContext(this, vars, "#User_Client", windowId, accesslevel),
                    currentClient)));
    if (editableTab)
      xmlDocument =
          xmlEngine
              .readXmlTemplate(
                  "org/openbravo/erpWindows/BusinessPartnerCategory/BusinessPartnerCategory_Edition",
                  discard)
              .createXmlDocument();
    else
      xmlDocument =
          xmlEngine
              .readXmlTemplate(
                  "org/openbravo/erpWindows/BusinessPartnerCategory/BusinessPartnerCategory_NonEditable",
                  discard)
              .createXmlDocument();

    xmlDocument.setParameter("tabId", tabId);
    ToolBar toolbar =
        new ToolBar(
            this,
            editableTab,
            vars.getLanguage(),
            "BusinessPartnerCategory",
            (strCommand.equals("NEW")
                || boolNew
                || (dataField == null && (data == null || data.length == 0))),
            "document.frmMain.inpcBpGroupId",
            "",
            "..",
            "".equals("Y"),
            "BusinessPartnerCategory",
            strReplaceWith,
            true,
            false,
            false,
            Utility.hasTabAttachments(this, vars, tabId, strC_BP_Group_ID),
            !hasReadOnlyAccess);
    toolbar.setTabId(tabId);
    toolbar.setDeleteable(true);
    toolbar.prepareEditionTemplate(
        "N".equals("Y"),
        hasSearchCondition,
        vars.getSessionValue("#ShowTest", "N").equals("Y"),
        "STD",
        Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
    xmlDocument.setParameter("toolbar", toolbar.toString());

    // set updated timestamp to manage locking mechanism
    if (!boolNew) {
      xmlDocument.setParameter(
          "updatedTimestamp",
          (dataField != null
              ? dataField.getField("updatedTimeStamp")
              : data[0].getField("updatedTimeStamp")));
    }

    boolean concurrentSave = vars.getSessionValue(tabId + "|concurrentSave").equals("true");
    if (concurrentSave) {
      // after concurrent save error, force autosave
      xmlDocument.setParameter("autosave", "Y");
    } else {
      xmlDocument.setParameter("autosave", "N");
    }
    vars.removeSessionValue(tabId + "|concurrentSave");

    try {
      WindowTabs tabs =
          new WindowTabs(this, vars, tabId, windowId, true, (strCommand.equalsIgnoreCase("NEW")));
      xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
      xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
      // if (!strC_BP_Group_ID.equals("")) xmlDocument.setParameter("childTabContainer",
      // tabs.childTabs(false));
      // else xmlDocument.setParameter("childTabContainer", tabs.childTabs(true));
      xmlDocument.setParameter("childTabContainer", tabs.childTabs(false));
      String hideBackButton = vars.getGlobalVariable("hideMenu", "#Hide_BackButton", "");
      NavigationBar nav =
          new NavigationBar(
              this,
              vars.getLanguage(),
              "BusinessPartnerCategory_Relation.html",
              "BusinessPartnerCategory",
              "W",
              strReplaceWith,
              tabs.breadcrumb(),
              hideBackButton.equals("true"),
              !concurrentSave);
      xmlDocument.setParameter("navigationBar", nav.toString());
      LeftTabsBar lBar =
          new LeftTabsBar(
              this, vars.getLanguage(), "BusinessPartnerCategory_Relation.html", strReplaceWith);
      xmlDocument.setParameter("leftTabs", lBar.editionTemplate(strCommand.equals("NEW")));
    } catch (Exception ex) {
      throw new ServletException(ex);
    }

    xmlDocument.setParameter("commandType", strCommand);
    xmlDocument.setParameter("buscador", buscador);
    xmlDocument.setParameter("windowId", windowId);
    xmlDocument.setParameter("changed", "");
    xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";");
    xmlDocument.setParameter("theme", vars.getTheme());
    final String strMappingName = Utility.getTabURL(tabId, "E", false);
    xmlDocument.setParameter("mappingName", strMappingName);
    xmlDocument.setParameter("confirmOnChanges", Utility.getJSConfirmOnChanges(vars, windowId));
    // xmlDocument.setParameter("buttonReference", Utility.messageBD(this, "Reference",
    // vars.getLanguage()));

    xmlDocument.setParameter("paramSessionDate", strParamSessionDate);

    xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
    OBError myMessage = vars.getMessage(tabId);
    vars.removeMessage(tabId);
    if (myMessage != null) {
      xmlDocument.setParameter("messageType", myMessage.getType());
      xmlDocument.setParameter("messageTitle", myMessage.getTitle());
      xmlDocument.setParameter("messageMessage", myMessage.getMessage());
    }
    xmlDocument.setParameter("displayLogic", getDisplayLogicContext(vars, boolNew));

    if (dataField == null) {
      xmlDocument.setData("structure1", data);

    } else {

      FieldProvider[] dataAux = new FieldProvider[1];
      dataAux[0] = dataField;

      xmlDocument.setData("structure1", dataAux);
    }

    try {
      ComboTableData comboTableData = null;
      String userOrgList = "";
      if (editableTab)
        userOrgList =
            Utility.getContext(this, vars, "#User_Org", windowId, accesslevel); // editable record
      else userOrgList = currentOrg;
      comboTableData =
          new ComboTableData(
              vars,
              this,
              "19",
              "AD_Org_ID",
              "",
              "",
              userOrgList,
              Utility.getContext(this, vars, "#User_Client", windowId),
              0);
      Utility.fillSQLParameters(
          this,
          vars,
          (dataField == null ? data[0] : dataField),
          comboTableData,
          windowId,
          (dataField == null ? data[0].getField("adOrgId") : dataField.getField("adOrgId")));
      xmlDocument.setData(
          "reportAD_Org_ID", "liststructure", comboTableData.select(!strCommand.equals("NEW")));
      comboTableData = null;
      xmlDocument.setParameter("Created_Format", vars.getSessionValue("#AD_SqlDateTimeFormat"));
      xmlDocument.setParameter(
          "Created_Maxlength",
          Integer.toString(vars.getSessionValue("#AD_SqlDateTimeFormat").length()));
      xmlDocument.setParameter("Updated_Format", vars.getSessionValue("#AD_SqlDateTimeFormat"));
      xmlDocument.setParameter(
          "Updated_Maxlength",
          Integer.toString(vars.getSessionValue("#AD_SqlDateTimeFormat").length()));
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new ServletException(ex);
    }

    xmlDocument.setParameter("scriptOnLoad", getShortcutScript(usedButtonShortCuts));

    final String refererURL = vars.getSessionValue(tabId + "|requestURL");
    vars.removeSessionValue(tabId + "|requestURL");
    if (!refererURL.equals("")) {
      final Boolean failedAutosave = (Boolean) vars.getSessionObject(tabId + "|failedAutosave");
      vars.removeSessionValue(tabId + "|failedAutosave");
      if (failedAutosave != null && failedAutosave) {
        final String jsFunction = "continueUserAction('" + refererURL + "');";
        xmlDocument.setParameter("failedAutosave", jsFunction);
      }
    }

    if (strCommand.equalsIgnoreCase("NEW")) {
      vars.removeSessionValue(tabId + "|failedAutosave");
      vars.removeSessionValue(strMappingName + "|hash");
    }

    response.setContentType("text/html; charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println(xmlDocument.print());
    out.close();
  }