Package org.openbravo.base.secureApp

Examples of org.openbravo.base.secureApp.VariablesSecureApp


    boolHist = false;
  }

  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
      ServletException {
    VariablesSecureApp vars = new VariablesSecureApp(request);
    if (vars.commandIn("DEFAULT")) {
      String strChanged = vars.getStringParameter("inpLastFieldChanged");
      if (log4j.isDebugEnabled())
        log4j.debug("CHANGED: " + strChanged);
      String strMProductID = vars.getStringParameter("inpmProductId");
      String strCBPartnerLocationID = vars.getStringParameter("inpcBpartnerLocationId");
      String strDateOrdered = vars.getStringParameter("inpdateordered");
      String strADOrgID = vars.getStringParameter("inpadOrgId");
      String strMWarehouseID = vars.getStringParameter("inpmWarehouseId");
      String strCOrderId = vars.getStringParameter("inpcOrderId");
      String strWindowId = vars.getStringParameter("inpwindowId");
      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
      String strTabId = vars.getStringParameter("inpTabId");

      try {
        printPage(response, vars, strChanged, strMProductID, strCBPartnerLocationID,
            strDateOrdered, strADOrgID, strMWarehouseID, strCOrderId, strIsSOTrx, strTabId);
      } catch (ServletException ex) {
View Full Code Here


  private static final int accesslevel = 3;
  private static final double SUBTABS_COL_SIZE = 15;

  public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
    TableSQLData tableSQL = null;
    VariablesSecureApp vars = new VariablesSecureApp(request);
    Boolean saveRequest = (Boolean) request.getAttribute("autosave");
   
    if(saveRequest != null && saveRequest){
      String currentOrg = vars.getStringParameter("inpadOrgId");
      String currentClient = vars.getStringParameter("inpadClientId");
      boolean editableTab = (!org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)
                            && (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)));
   
        OBError myError = new OBError();
        String commandType = request.getParameter("inpCommandType");
        String strmaToolsetId = request.getParameter("inpmaToolsetId");
         String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !strmaToolsetId.equals(""))
              total = saveRecord(vars, myError, 'U', strPMA_Toolset_Type_ID);
          else
              total = saveRecord(vars, myError, 'I', strPMA_Toolset_Type_ID);
         
          if (!myError.isEmpty() && total == 0)    
            throw new OBException(myError.getMessage());
        }
        vars.setSessionValue(request.getParameter("mappingName") +"|hash", vars.getPostDataHash());
        vars.setSessionValue(tabId + "|Header.view", "EDIT");
       
        return;
    }
   
    try {
      tableSQL = new TableSQLData(vars, this, tabId, Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel), Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    String strOrderBy = vars.getSessionValue(tabId + "|orderby");
    if (!strOrderBy.equals("")) {
      vars.setSessionValue(tabId + "|newOrder", "1");
    }

    if (vars.commandIn("DEFAULT")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID", "");

      String strMA_Toolset_ID = vars.getGlobalVariable("inpmaToolsetId", windowId + "|MA_Toolset_ID", "");
            if (strPMA_Toolset_Type_ID.equals("")) {
        strPMA_Toolset_Type_ID = getParentID(vars, strMA_Toolset_ID);
        if (strPMA_Toolset_Type_ID.equals("")) throw new ServletException("Required parameter :" + windowId + "|MA_Toolset_Type_ID");
        vars.setSessionValue(windowId + "|MA_Toolset_Type_ID", strPMA_Toolset_Type_ID);

        refreshParentSession(vars, strPMA_Toolset_Type_ID);
      }


      String strView = vars.getSessionValue(tabId + "|Toolset.view");
      if (strView.equals("")) {
        strView = defaultTabView;

        if (strView.equals("EDIT")) {
          if (strMA_Toolset_ID.equals("")) strMA_Toolset_ID = firstElement(vars, tableSQL);
          if (strMA_Toolset_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strMA_Toolset_ID, strPMA_Toolset_Type_ID, tableSQL);

      else printPageDataSheet(response, vars, strPMA_Toolset_Type_ID, strMA_Toolset_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strMA_Toolset_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strMA_Toolset_ID.equals("")) strMA_Toolset_ID = vars.getRequiredGlobalVariable("inpmaToolsetId", windowId + "|MA_Toolset_ID");
      else vars.setSessionValue(windowId + "|MA_Toolset_ID", strMA_Toolset_ID);
     
     
      String strPMA_Toolset_Type_ID = getParentID(vars, strMA_Toolset_ID);
     
      vars.setSessionValue(windowId + "|MA_Toolset_Type_ID", strPMA_Toolset_Type_ID);
      vars.setSessionValue("800096|Toolset Type.view", "EDIT");

      refreshParentSession(vars, strPMA_Toolset_Type_ID);

      vars.setSessionValue(tabId + "|Toolset.view", "EDIT");

      printPageEdit(response, request, vars, false, strMA_Toolset_ID, strPMA_Toolset_Type_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID", false, false, true, "");
      vars.removeSessionValue(windowId + "|MA_Toolset_ID");
      refreshParentSession(vars, strPMA_Toolset_Type_ID);


      String strView = vars.getSessionValue(tabId + "|Toolset.view");
      String strMA_Toolset_ID = "";
      if (strView.equals("")) {
        strView = defaultTabView;
        if (strView.equals("EDIT")) {
          strMA_Toolset_ID = firstElement(vars, tableSQL);
          if (strMA_Toolset_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT")) {

        if (strMA_Toolset_ID.equals("")) strMA_Toolset_ID = firstElement(vars, tableSQL);
        printPageEdit(response, request, vars, false, strMA_Toolset_ID, strPMA_Toolset_Type_ID, tableSQL);

      } else printPageDataSheet(response, vars, strPMA_Toolset_Type_ID, "", tableSQL);
    } else if (vars.commandIn("SEARCH")) {
vars.getRequestGlobalVariable("inpParamValue", tabId + "|paramValue");

            String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");

     
      vars.removeSessionValue(windowId + "|MA_Toolset_ID");
      String strMA_Toolset_ID="";

      String strView = vars.getSessionValue(tabId + "|Toolset.view");
      if (strView.equals("")) strView=defaultTabView;

      if (strView.equals("EDIT")) {
        strMA_Toolset_ID = firstElement(vars, tableSQL);
        if (strMA_Toolset_ID.equals("")) {
          // filter returns empty set
          strView = "RELATION";
          // switch to grid permanently until the user changes the view again
          vars.setSessionValue(tabId + "|Toolset.view", strView);
        }
      }

      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strMA_Toolset_ID, strPMA_Toolset_Type_ID, tableSQL);

      else printPageDataSheet(response, vars, strPMA_Toolset_Type_ID, strMA_Toolset_ID, tableSQL);
    } else if (vars.commandIn("RELATION")) {
            String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");
     

      String strMA_Toolset_ID = vars.getGlobalVariable("inpmaToolsetId", windowId + "|MA_Toolset_ID", "");
      vars.setSessionValue(tabId + "|Toolset.view", "RELATION");
      printPageDataSheet(response, vars, strPMA_Toolset_Type_ID, strMA_Toolset_ID, tableSQL);
    } else if (vars.commandIn("NEW")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");


      printPageEdit(response, request, vars, true, "", strPMA_Toolset_Type_ID, tableSQL);

    } else if (vars.commandIn("EDIT")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");

      @SuppressWarnings("unused") // In Expense Invoice tab this variable is not used, to be fixed
      String strMA_Toolset_ID = vars.getGlobalVariable("inpmaToolsetId", windowId + "|MA_Toolset_ID", "");
      vars.setSessionValue(tabId + "|Toolset.view", "EDIT");

      setHistoryCommand(request, "EDIT");
      printPageEdit(response, request, vars, false, strMA_Toolset_ID, strPMA_Toolset_Type_ID, tableSQL);

    } else if (vars.commandIn("NEXT")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");
      String strMA_Toolset_ID = vars.getRequiredStringParameter("inpmaToolsetId");
     
      String strNext = nextElement(vars, strMA_Toolset_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, strPMA_Toolset_Type_ID, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");
      String strMA_Toolset_ID = vars.getRequiredStringParameter("inpmaToolsetId");
     
      String strPrevious = previousElement(vars, strMA_Toolset_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, strPMA_Toolset_Type_ID, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {
vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");

      vars.setSessionValue(tabId + "|Toolset.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Toolset.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      if (strInitRecord.equals("") || strInitRecord.equals("0")) {
        vars.setSessionValue(tabId + "|Toolset.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|Toolset.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|MA_Toolset_ID");
      vars.setSessionValue(windowId + "|MA_Toolset_Type_ID", strPMA_Toolset_Type_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Toolset.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
      if (initRecord==0) initRecord=1;
      initRecord += intRecordRange;
      strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
      vars.setSessionValue(tabId + "|Toolset.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|MA_Toolset_ID");
      vars.setSessionValue(windowId + "|MA_Toolset_Type_ID", strPMA_Toolset_Type_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");
     
      String strFirst = firstElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strFirst, strPMA_Toolset_Type_ID, tableSQL);
    } else if (vars.commandIn("LAST_RELATION")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");

      String strLast = lastElement(vars, tableSQL);
      printPageDataSheet(response, vars, strPMA_Toolset_Type_ID, strLast, tableSQL);
    } else if (vars.commandIn("LAST")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");
     
      String strLast = lastElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strLast, strPMA_Toolset_Type_ID, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");
      OBError myError = new OBError();     
      int total = saveRecord(vars, myError, 'I', strPMA_Toolset_Type_ID);     
      if (!myError.isEmpty()) {       
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
      }
      else {
    if (myError.isEmpty()) {
      myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsInserted");
      myError.setMessage(total + " " + myError.getMessage());
      vars.setMessage(tabId, myError);
    }       
        if (vars.commandIn("SAVE_NEW_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_NEW_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
    } else if (vars.commandIn("SAVE_EDIT_RELATION", "SAVE_EDIT_NEW", "SAVE_EDIT_EDIT", "SAVE_EDIT_NEXT")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");
      String strMA_Toolset_ID = vars.getRequiredGlobalVariable("inpmaToolsetId", windowId + "|MA_Toolset_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U', strPMA_Toolset_Type_ID);     
      if (!myError.isEmpty()) {
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
      }
      else {
        if (myError.isEmpty()) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsUpdated");
          myError.setMessage(total + " " + myError.getMessage());
          vars.setMessage(tabId, myError);
        }
        if (vars.commandIn("SAVE_EDIT_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_EDIT_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else if (vars.commandIn("SAVE_EDIT_NEXT")) {
          String strNext = nextElement(vars, strMA_Toolset_ID, tableSQL);
          vars.setSessionValue(windowId + "|MA_Toolset_ID", strNext);
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        } else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
/*    } else if (vars.commandIn("DELETE_RELATION")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");

      String strMA_Toolset_ID = vars.getRequiredInStringParameter("inpmaToolsetId");
      String message = deleteRelation(vars, strMA_Toolset_ID, strPMA_Toolset_Type_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|maToolsetId");
        vars.setSessionValue(tabId + "|Toolset.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {
      String strPMA_Toolset_Type_ID = vars.getGlobalVariable("inpmaToolsetTypeId", windowId + "|MA_Toolset_Type_ID");

      String strMA_Toolset_ID = vars.getRequiredStringParameter("inpmaToolsetId");
      //ToolsetData data = getEditVariables(vars, strPMA_Toolset_Type_ID);
      int total = 0;
      OBError myError = null;
      if (org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
        vars.setMessage(tabId, myError);
      } else {
        try {
          total = ToolsetData.delete(this, strMA_Toolset_ID, strPMA_Toolset_Type_ID, Utility.getContext(this, vars, "#User_Client", windowId, accesslevel), Utility.getContext(this, vars, "#User_Org", windowId, accesslevel));
        } catch(ServletException ex) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
          if (!myError.isConnectionAvailable()) {
            bdErrorConnection(response);
            return;
          } else vars.setMessage(tabId, myError);
        }
        if (myError==null && total==0) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
        }
        vars.removeSessionValue(windowId + "|maToolsetId");
        vars.setSessionValue(tabId + "|Toolset.view", "RELATION");
      }
      if (myError==null) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsDeleted");
        myError.setMessage(total + " " + myError.getMessage());
        vars.setMessage(tabId, myError);
      }
      response.sendRedirect(strDireccion + request.getServletPath());








    } else if (vars.getCommand().toUpperCase().startsWith("BUTTON") || vars.getCommand().toUpperCase().startsWith("SAVE_BUTTON")) {
      pageErrorPopUp(response);
    } else pageError(response);
  }
View Full Code Here

    super.init(config);
    boolHist = false;
  }

  public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
    VariablesSecureApp vars = new VariablesSecureApp(request);
    if (vars.commandIn("DEFAULT")) {
      String strChanged = vars.getStringParameter("inpLastFieldChanged");
      if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
      String strDate = vars.getStringParameter("inppickupdate");   
      String strProductID = vars.getStringParameter("inpmproductid");  
    String strDriverID = vars.getStringParameter("inpdriver");
    String strDuration = vars.getStringParameter("inpmPricelistVersionId");
      String strnoofduration = vars.getStringParameter("inpdquantity");     
    String strTabId = vars.getStringParameter("inpTabId");
      try {
        printPage(response, vars, strChanged, strDate, strProductID, strDriverID, strDuration, strnoofduration, strTabId);
      } catch (ServletException ex) {
        pageErrorCallOut(response);
      }
View Full Code Here

  private static final int accesslevel = 3;
  private static final double SUBTABS_COL_SIZE = 15;

  public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
    TableSQLData tableSQL = null;
    VariablesSecureApp vars = new VariablesSecureApp(request);
    Boolean saveRequest = (Boolean) request.getAttribute("autosave");
   
    if(saveRequest != null && saveRequest){
      String currentOrg = vars.getStringParameter("inpadOrgId");
      String currentClient = vars.getStringParameter("inpadClientId");
      boolean editableTab = (!org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)
                            && (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)));
   
        OBError myError = new OBError();
        String commandType = request.getParameter("inpCommandType");
        String strmaCostcenterMachineId = request.getParameter("inpmaCostcenterMachineId");
         String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !strmaCostcenterMachineId.equals(""))
              total = saveRecord(vars, myError, 'U', strPMA_Costcenter_Version_ID);
          else
              total = saveRecord(vars, myError, 'I', strPMA_Costcenter_Version_ID);
         
          if (!myError.isEmpty() && total == 0)    
            throw new OBException(myError.getMessage());
        }
        vars.setSessionValue(request.getParameter("mappingName") +"|hash", vars.getPostDataHash());
        vars.setSessionValue(tabId + "|Header.view", "EDIT");
       
        return;
    }
   
    try {
      tableSQL = new TableSQLData(vars, this, tabId, Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel), Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    String strOrderBy = vars.getSessionValue(tabId + "|orderby");
    if (!strOrderBy.equals("")) {
      vars.setSessionValue(tabId + "|newOrder", "1");
    }

    if (vars.commandIn("DEFAULT")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID", "");

      String strMA_Costcenter_Machine_ID = vars.getGlobalVariable("inpmaCostcenterMachineId", windowId + "|MA_Costcenter_Machine_ID", "");
            if (strPMA_Costcenter_Version_ID.equals("")) {
        strPMA_Costcenter_Version_ID = getParentID(vars, strMA_Costcenter_Machine_ID);
        if (strPMA_Costcenter_Version_ID.equals("")) throw new ServletException("Required parameter :" + windowId + "|MA_Costcenter_Version_ID");
        vars.setSessionValue(windowId + "|MA_Costcenter_Version_ID", strPMA_Costcenter_Version_ID);
      vars.removeSessionValue(windowId + "|MA_Costcenter_ID");
        refreshParentSession(vars, strPMA_Costcenter_Version_ID);
      }


      String strView = vars.getSessionValue(tabId + "|Machine.view");
      if (strView.equals("")) {
        strView = defaultTabView;

        if (strView.equals("EDIT")) {
          if (strMA_Costcenter_Machine_ID.equals("")) strMA_Costcenter_Machine_ID = firstElement(vars, tableSQL);
          if (strMA_Costcenter_Machine_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strMA_Costcenter_Machine_ID, strPMA_Costcenter_Version_ID, tableSQL);

      else printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, strMA_Costcenter_Machine_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strMA_Costcenter_Machine_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strMA_Costcenter_Machine_ID.equals("")) strMA_Costcenter_Machine_ID = vars.getRequiredGlobalVariable("inpmaCostcenterMachineId", windowId + "|MA_Costcenter_Machine_ID");
      else vars.setSessionValue(windowId + "|MA_Costcenter_Machine_ID", strMA_Costcenter_Machine_ID);
     
     
      String strPMA_Costcenter_Version_ID = getParentID(vars, strMA_Costcenter_Machine_ID);
     
      vars.setSessionValue(windowId + "|MA_Costcenter_Version_ID", strPMA_Costcenter_Version_ID);
      vars.setSessionValue("800234|Version.view", "EDIT");
      vars.removeSessionValue(windowId + "|MA_Costcenter_ID");
      refreshParentSession(vars, strPMA_Costcenter_Version_ID);

      vars.setSessionValue(tabId + "|Machine.view", "EDIT");

      printPageEdit(response, request, vars, false, strMA_Costcenter_Machine_ID, strPMA_Costcenter_Version_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID", false, false, true, "");
      vars.removeSessionValue(windowId + "|MA_Costcenter_Machine_ID");
      refreshParentSession(vars, strPMA_Costcenter_Version_ID);


      String strView = vars.getSessionValue(tabId + "|Machine.view");
      String strMA_Costcenter_Machine_ID = "";
      if (strView.equals("")) {
        strView = defaultTabView;
        if (strView.equals("EDIT")) {
          strMA_Costcenter_Machine_ID = firstElement(vars, tableSQL);
          if (strMA_Costcenter_Machine_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT")) {

        if (strMA_Costcenter_Machine_ID.equals("")) strMA_Costcenter_Machine_ID = firstElement(vars, tableSQL);
        printPageEdit(response, request, vars, false, strMA_Costcenter_Machine_ID, strPMA_Costcenter_Version_ID, tableSQL);

      } else printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, "", tableSQL);
    } else if (vars.commandIn("SEARCH")) {
vars.getRequestGlobalVariable("inpParamMA_Costcenter_Version_ID", tabId + "|paramMA_Costcenter_Version_ID");
vars.getRequestGlobalVariable("inpParamMA_Machine_ID", tabId + "|paramMA_Machine_ID");

            String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");

     
      vars.removeSessionValue(windowId + "|MA_Costcenter_Machine_ID");
      String strMA_Costcenter_Machine_ID="";

      String strView = vars.getSessionValue(tabId + "|Machine.view");
      if (strView.equals("")) strView=defaultTabView;

      if (strView.equals("EDIT")) {
        strMA_Costcenter_Machine_ID = firstElement(vars, tableSQL);
        if (strMA_Costcenter_Machine_ID.equals("")) {
          // filter returns empty set
          strView = "RELATION";
          // switch to grid permanently until the user changes the view again
          vars.setSessionValue(tabId + "|Machine.view", strView);
        }
      }

      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strMA_Costcenter_Machine_ID, strPMA_Costcenter_Version_ID, tableSQL);

      else printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, strMA_Costcenter_Machine_ID, tableSQL);
    } else if (vars.commandIn("RELATION")) {
            String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
     

      String strMA_Costcenter_Machine_ID = vars.getGlobalVariable("inpmaCostcenterMachineId", windowId + "|MA_Costcenter_Machine_ID", "");
      vars.setSessionValue(tabId + "|Machine.view", "RELATION");
      printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, strMA_Costcenter_Machine_ID, tableSQL);
    } else if (vars.commandIn("NEW")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");


      printPageEdit(response, request, vars, true, "", strPMA_Costcenter_Version_ID, tableSQL);

    } else if (vars.commandIn("EDIT")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");

      @SuppressWarnings("unused") // In Expense Invoice tab this variable is not used, to be fixed
      String strMA_Costcenter_Machine_ID = vars.getGlobalVariable("inpmaCostcenterMachineId", windowId + "|MA_Costcenter_Machine_ID", "");
      vars.setSessionValue(tabId + "|Machine.view", "EDIT");

      setHistoryCommand(request, "EDIT");
      printPageEdit(response, request, vars, false, strMA_Costcenter_Machine_ID, strPMA_Costcenter_Version_ID, tableSQL);

    } else if (vars.commandIn("NEXT")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
      String strMA_Costcenter_Machine_ID = vars.getRequiredStringParameter("inpmaCostcenterMachineId");
     
      String strNext = nextElement(vars, strMA_Costcenter_Machine_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, strPMA_Costcenter_Version_ID, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
      String strMA_Costcenter_Machine_ID = vars.getRequiredStringParameter("inpmaCostcenterMachineId");
     
      String strPrevious = previousElement(vars, strMA_Costcenter_Machine_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, strPMA_Costcenter_Version_ID, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {
vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");

      vars.setSessionValue(tabId + "|Machine.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Machine.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      if (strInitRecord.equals("") || strInitRecord.equals("0")) {
        vars.setSessionValue(tabId + "|Machine.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|Machine.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|MA_Costcenter_Machine_ID");
      vars.setSessionValue(windowId + "|MA_Costcenter_Version_ID", strPMA_Costcenter_Version_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Machine.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
      if (initRecord==0) initRecord=1;
      initRecord += intRecordRange;
      strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
      vars.setSessionValue(tabId + "|Machine.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|MA_Costcenter_Machine_ID");
      vars.setSessionValue(windowId + "|MA_Costcenter_Version_ID", strPMA_Costcenter_Version_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
     
      String strFirst = firstElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strFirst, strPMA_Costcenter_Version_ID, tableSQL);
    } else if (vars.commandIn("LAST_RELATION")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");

      String strLast = lastElement(vars, tableSQL);
      printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, strLast, tableSQL);
    } else if (vars.commandIn("LAST")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
     
      String strLast = lastElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strLast, strPMA_Costcenter_Version_ID, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
      OBError myError = new OBError();     
      int total = saveRecord(vars, myError, 'I', strPMA_Costcenter_Version_ID);     
      if (!myError.isEmpty()) {       
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
      }
      else {
    if (myError.isEmpty()) {
      myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsInserted");
      myError.setMessage(total + " " + myError.getMessage());
      vars.setMessage(tabId, myError);
    }       
        if (vars.commandIn("SAVE_NEW_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_NEW_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
    } else if (vars.commandIn("SAVE_EDIT_RELATION", "SAVE_EDIT_NEW", "SAVE_EDIT_EDIT", "SAVE_EDIT_NEXT")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
      String strMA_Costcenter_Machine_ID = vars.getRequiredGlobalVariable("inpmaCostcenterMachineId", windowId + "|MA_Costcenter_Machine_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U', strPMA_Costcenter_Version_ID);     
      if (!myError.isEmpty()) {
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
      }
      else {
        if (myError.isEmpty()) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsUpdated");
          myError.setMessage(total + " " + myError.getMessage());
          vars.setMessage(tabId, myError);
        }
        if (vars.commandIn("SAVE_EDIT_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_EDIT_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else if (vars.commandIn("SAVE_EDIT_NEXT")) {
          String strNext = nextElement(vars, strMA_Costcenter_Machine_ID, tableSQL);
          vars.setSessionValue(windowId + "|MA_Costcenter_Machine_ID", strNext);
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        } else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
/*    } else if (vars.commandIn("DELETE_RELATION")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");

      String strMA_Costcenter_Machine_ID = vars.getRequiredInStringParameter("inpmaCostcenterMachineId");
      String message = deleteRelation(vars, strMA_Costcenter_Machine_ID, strPMA_Costcenter_Version_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|maCostcenterMachineId");
        vars.setSessionValue(tabId + "|Machine.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {
      String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");

      String strMA_Costcenter_Machine_ID = vars.getRequiredStringParameter("inpmaCostcenterMachineId");
      //MachineData data = getEditVariables(vars, strPMA_Costcenter_Version_ID);
      int total = 0;
      OBError myError = null;
      if (org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
        vars.setMessage(tabId, myError);
      } else {
        try {
          total = MachineData.delete(this, strMA_Costcenter_Machine_ID, strPMA_Costcenter_Version_ID, Utility.getContext(this, vars, "#User_Client", windowId, accesslevel), Utility.getContext(this, vars, "#User_Org", windowId, accesslevel));
        } catch(ServletException ex) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
          if (!myError.isConnectionAvailable()) {
            bdErrorConnection(response);
            return;
          } else vars.setMessage(tabId, myError);
        }
        if (myError==null && total==0) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
        }
        vars.removeSessionValue(windowId + "|maCostcenterMachineId");
        vars.setSessionValue(tabId + "|Machine.view", "RELATION");
      }
      if (myError==null) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsDeleted");
        myError.setMessage(total + " " + myError.getMessage());
        vars.setMessage(tabId, myError);
      }
      response.sendRedirect(strDireccion + request.getServletPath());








    } else if (vars.getCommand().toUpperCase().startsWith("BUTTON") || vars.getCommand().toUpperCase().startsWith("SAVE_BUTTON")) {
      pageErrorPopUp(response);
    } else pageError(response);
  }
View Full Code Here

    boolHist = false;
  }

  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
      ServletException {
    VariablesSecureApp vars = new VariablesSecureApp(request);
    if (vars.commandIn("DEFAULT")) {
      String strChanged = vars.getStringParameter("inpLastFieldChanged");
      if (log4j.isDebugEnabled())
        log4j.debug("WE GO INTO THE DEFAULT");
      if (log4j.isDebugEnabled())
        log4j.debug("CHANGED: " + strChanged);
      String strcInvoiceId = vars.getStringParameter("inpcInvoiceId");
      String strcDoctypeId = vars.getStringParameter("inpcDoctypeId");
      String strTabId = vars.getStringParameter("inpTabId");

      try {
        printPage(response, vars, strChanged, strcInvoiceId, strcDoctypeId, strTabId);
      } catch (ServletException ex) {
        pageErrorCallOut(response);
View Full Code Here

  private static final int accesslevel = 6;
  private static final double SUBTABS_COL_SIZE = 15;

  public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
    TableSQLData tableSQL = null;
    VariablesSecureApp vars = new VariablesSecureApp(request);
    Boolean saveRequest = (Boolean) request.getAttribute("autosave");
   
    if(saveRequest != null && saveRequest){
      String currentOrg = vars.getStringParameter("inpadOrgId");
      String currentClient = vars.getStringParameter("inpadClientId");
      boolean editableTab = (!org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)
                            && (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)));
   
        OBError myError = new OBError();
        String commandType = request.getParameter("inpCommandType");
        String stradTableAccessId = request.getParameter("inpadTableAccessId");
         String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !stradTableAccessId.equals(""))
              total = saveRecord(vars, myError, 'U', strPAD_Table_ID);
          else
              total = saveRecord(vars, myError, 'I', strPAD_Table_ID);
         
          if (!myError.isEmpty() && total == 0)    
            throw new OBException(myError.getMessage());
        }
        vars.setSessionValue(request.getParameter("mappingName") +"|hash", vars.getPostDataHash());
        vars.setSessionValue(tabId + "|Header.view", "EDIT");
       
        return;
    }
   
    try {
      tableSQL = new TableSQLData(vars, this, tabId, Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel), Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    String strOrderBy = vars.getSessionValue(tabId + "|orderby");
    if (!strOrderBy.equals("")) {
      vars.setSessionValue(tabId + "|newOrder", "1");
    }

    if (vars.commandIn("DEFAULT")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID", "");

      String strAD_Table_Access_ID = vars.getGlobalVariable("inpadTableAccessId", windowId + "|AD_Table_Access_ID", "");
            if (strPAD_Table_ID.equals("")) {
        strPAD_Table_ID = getParentID(vars, strAD_Table_Access_ID);
        if (strPAD_Table_ID.equals("")) throw new ServletException("Required parameter :" + windowId + "|AD_Table_ID");
        vars.setSessionValue(windowId + "|AD_Table_ID", strPAD_Table_ID);

        refreshParentSession(vars, strPAD_Table_ID);
      }


      String strView = vars.getSessionValue(tabId + "|RoleAccess.view");
      if (strView.equals("")) {
        strView = defaultTabView;

        if (strView.equals("EDIT")) {
          if (strAD_Table_Access_ID.equals("")) strAD_Table_Access_ID = firstElement(vars, tableSQL);
          if (strAD_Table_Access_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strAD_Table_Access_ID, strPAD_Table_ID, tableSQL);

      else printPageDataSheet(response, vars, strPAD_Table_ID, strAD_Table_Access_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strAD_Table_Access_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strAD_Table_Access_ID.equals("")) strAD_Table_Access_ID = vars.getRequiredGlobalVariable("inpadTableAccessId", windowId + "|AD_Table_Access_ID");
      else vars.setSessionValue(windowId + "|AD_Table_Access_ID", strAD_Table_Access_ID);
     
     
      String strPAD_Table_ID = getParentID(vars, strAD_Table_Access_ID);
     
      vars.setSessionValue(windowId + "|AD_Table_ID", strPAD_Table_ID);
      vars.setSessionValue("100|Table.view", "EDIT");

      refreshParentSession(vars, strPAD_Table_ID);

      vars.setSessionValue(tabId + "|RoleAccess.view", "EDIT");

      printPageEdit(response, request, vars, false, strAD_Table_Access_ID, strPAD_Table_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID", false, false, true, "");
      vars.removeSessionValue(windowId + "|AD_Table_Access_ID");
      refreshParentSession(vars, strPAD_Table_ID);


      String strView = vars.getSessionValue(tabId + "|RoleAccess.view");
      String strAD_Table_Access_ID = "";
      if (strView.equals("")) {
        strView = defaultTabView;
        if (strView.equals("EDIT")) {
          strAD_Table_Access_ID = firstElement(vars, tableSQL);
          if (strAD_Table_Access_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT")) {

        if (strAD_Table_Access_ID.equals("")) strAD_Table_Access_ID = firstElement(vars, tableSQL);
        printPageEdit(response, request, vars, false, strAD_Table_Access_ID, strPAD_Table_ID, tableSQL);

      } else printPageDataSheet(response, vars, strPAD_Table_ID, "", tableSQL);
    } else if (vars.commandIn("SEARCH")) {
vars.getRequestGlobalVariable("inpParamAD_Table_ID", tabId + "|paramAD_Table_ID");

            String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");

     
      vars.removeSessionValue(windowId + "|AD_Table_Access_ID");
      String strAD_Table_Access_ID="";

      String strView = vars.getSessionValue(tabId + "|RoleAccess.view");
      if (strView.equals("")) strView=defaultTabView;

      if (strView.equals("EDIT")) {
        strAD_Table_Access_ID = firstElement(vars, tableSQL);
        if (strAD_Table_Access_ID.equals("")) {
          // filter returns empty set
          strView = "RELATION";
          // switch to grid permanently until the user changes the view again
          vars.setSessionValue(tabId + "|RoleAccess.view", strView);
        }
      }

      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strAD_Table_Access_ID, strPAD_Table_ID, tableSQL);

      else printPageDataSheet(response, vars, strPAD_Table_ID, strAD_Table_Access_ID, tableSQL);
    } else if (vars.commandIn("RELATION")) {
            String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");
     

      String strAD_Table_Access_ID = vars.getGlobalVariable("inpadTableAccessId", windowId + "|AD_Table_Access_ID", "");
      vars.setSessionValue(tabId + "|RoleAccess.view", "RELATION");
      printPageDataSheet(response, vars, strPAD_Table_ID, strAD_Table_Access_ID, tableSQL);
    } else if (vars.commandIn("NEW")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");


      printPageEdit(response, request, vars, true, "", strPAD_Table_ID, tableSQL);

    } else if (vars.commandIn("EDIT")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");

      @SuppressWarnings("unused") // In Expense Invoice tab this variable is not used, to be fixed
      String strAD_Table_Access_ID = vars.getGlobalVariable("inpadTableAccessId", windowId + "|AD_Table_Access_ID", "");
      vars.setSessionValue(tabId + "|RoleAccess.view", "EDIT");

      setHistoryCommand(request, "EDIT");
      printPageEdit(response, request, vars, false, strAD_Table_Access_ID, strPAD_Table_ID, tableSQL);

    } else if (vars.commandIn("NEXT")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");
      String strAD_Table_Access_ID = vars.getRequiredStringParameter("inpadTableAccessId");
     
      String strNext = nextElement(vars, strAD_Table_Access_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, strPAD_Table_ID, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");
      String strAD_Table_Access_ID = vars.getRequiredStringParameter("inpadTableAccessId");
     
      String strPrevious = previousElement(vars, strAD_Table_Access_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, strPAD_Table_ID, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {
vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");

      vars.setSessionValue(tabId + "|RoleAccess.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|RoleAccess.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      if (strInitRecord.equals("") || strInitRecord.equals("0")) {
        vars.setSessionValue(tabId + "|RoleAccess.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|RoleAccess.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|AD_Table_Access_ID");
      vars.setSessionValue(windowId + "|AD_Table_ID", strPAD_Table_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|RoleAccess.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
      if (initRecord==0) initRecord=1;
      initRecord += intRecordRange;
      strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
      vars.setSessionValue(tabId + "|RoleAccess.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|AD_Table_Access_ID");
      vars.setSessionValue(windowId + "|AD_Table_ID", strPAD_Table_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");
     
      String strFirst = firstElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strFirst, strPAD_Table_ID, tableSQL);
    } else if (vars.commandIn("LAST_RELATION")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");

      String strLast = lastElement(vars, tableSQL);
      printPageDataSheet(response, vars, strPAD_Table_ID, strLast, tableSQL);
    } else if (vars.commandIn("LAST")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");
     
      String strLast = lastElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strLast, strPAD_Table_ID, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");
      OBError myError = new OBError();     
      int total = saveRecord(vars, myError, 'I', strPAD_Table_ID);     
      if (!myError.isEmpty()) {       
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
      }
      else {
    if (myError.isEmpty()) {
      myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsInserted");
      myError.setMessage(total + " " + myError.getMessage());
      vars.setMessage(tabId, myError);
    }       
        if (vars.commandIn("SAVE_NEW_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_NEW_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
    } else if (vars.commandIn("SAVE_EDIT_RELATION", "SAVE_EDIT_NEW", "SAVE_EDIT_EDIT", "SAVE_EDIT_NEXT")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");
      String strAD_Table_Access_ID = vars.getRequiredGlobalVariable("inpadTableAccessId", windowId + "|AD_Table_Access_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U', strPAD_Table_ID);     
      if (!myError.isEmpty()) {
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
      }
      else {
        if (myError.isEmpty()) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsUpdated");
          myError.setMessage(total + " " + myError.getMessage());
          vars.setMessage(tabId, myError);
        }
        if (vars.commandIn("SAVE_EDIT_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_EDIT_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else if (vars.commandIn("SAVE_EDIT_NEXT")) {
          String strNext = nextElement(vars, strAD_Table_Access_ID, tableSQL);
          vars.setSessionValue(windowId + "|AD_Table_Access_ID", strNext);
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        } else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
/*    } else if (vars.commandIn("DELETE_RELATION")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");

      String strAD_Table_Access_ID = vars.getRequiredInStringParameter("inpadTableAccessId");
      String message = deleteRelation(vars, strAD_Table_Access_ID, strPAD_Table_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|adTableAccessId");
        vars.setSessionValue(tabId + "|RoleAccess.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {
      String strPAD_Table_ID = vars.getGlobalVariable("inpadTableId", windowId + "|AD_Table_ID");

      String strAD_Table_Access_ID = vars.getRequiredStringParameter("inpadTableAccessId");
      //RoleAccessData data = getEditVariables(vars, strPAD_Table_ID);
      int total = 0;
      OBError myError = null;
      if (org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
        vars.setMessage(tabId, myError);
      } else {
        try {
          total = RoleAccessData.delete(this, strAD_Table_Access_ID, strPAD_Table_ID);
        } catch(ServletException ex) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
          if (!myError.isConnectionAvailable()) {
            bdErrorConnection(response);
            return;
          } else vars.setMessage(tabId, myError);
        }
        if (myError==null && total==0) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
        }
        vars.removeSessionValue(windowId + "|adTableAccessId");
        vars.setSessionValue(tabId + "|RoleAccess.view", "RELATION");
      }
      if (myError==null) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsDeleted");
        myError.setMessage(total + " " + myError.getMessage());
        vars.setMessage(tabId, myError);
      }
      response.sendRedirect(strDireccion + request.getServletPath());








    } else if (vars.getCommand().toUpperCase().startsWith("BUTTON") || vars.getCommand().toUpperCase().startsWith("SAVE_BUTTON")) {
      pageErrorPopUp(response);
    } else pageError(response);
  }
View Full Code Here

    boolHist = false;
  }

  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
      ServletException {
    VariablesSecureApp vars = new VariablesSecureApp(request);
    if (vars.commandIn("DEFAULT")) {
      String strChanged = vars.getStringParameter("inpLastFieldChanged");
      if (log4j.isDebugEnabled())
        log4j.debug("CHANGED: " + strChanged);
      String strTaxAmt = vars.getNumericParameter("inptaxamt");
      String strTaxBaseAmt = vars.getNumericParameter("inptaxbaseamt");
      String strTaxId = vars.getStringParameter("inpcTaxId");
      String strInvoiceId = vars.getStringParameter("inpcInvoiceId");

      try {
        printPage(response, vars, strChanged, strTaxAmt, strTaxBaseAmt, strTaxId, strInvoiceId);
      } catch (ServletException ex) {
        pageErrorCallOut(response);
View Full Code Here

    boolHist = false;
  }

  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,
      ServletException {
    VariablesSecureApp vars = new VariablesSecureApp(request);
    if (vars.commandIn("DEFAULT")) {
      String strChanged = vars.getStringParameter("inpLastFieldChanged");
      if (log4j.isDebugEnabled())
        log4j.debug("CHANGED: " + strChanged);
      String strUOM = vars.getStringParameter("inpmProductId_UOM");
      String strPriceList = vars.getStringParameter("inpmProductId_PLIST");
      String strPriceStd = vars.getStringParameter("inpmProductId_PSTD");
      String strPriceLimit = vars.getStringParameter("inpmProductId_PLIM");
      String strCurrency = vars.getStringParameter("inpmProductId_CURR");
      String strQty = vars.getNumericParameter("inpqtyinvoiced");

      String strMProductID = vars.getStringParameter("inpmProductId");
      String strADOrgID = vars.getStringParameter("inpadOrgId");
      String strCInvoiceID = vars.getStringParameter("inpcInvoiceId");
      String strWindowId = vars.getStringParameter("inpwindowId");
      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
      String strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId);
      String strTabId = vars.getStringParameter("inpTabId");

      try {
        printPage(response, vars, strUOM, strPriceList, strPriceStd, strPriceLimit, strCurrency,
            strMProductID, strADOrgID, strCInvoiceID, strIsSOTrx, strWharehouse, strTabId, strQty);
      } catch (ServletException ex) {
View Full Code Here

  private static final int accesslevel = 3;
  private static final double SUBTABS_COL_SIZE = 15;

  public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
    TableSQLData tableSQL = null;
    VariablesSecureApp vars = new VariablesSecureApp(request);
    Boolean saveRequest = (Boolean) request.getAttribute("autosave");
   
    if(saveRequest != null && saveRequest){
      String currentOrg = vars.getStringParameter("inpadOrgId");
      String currentClient = vars.getStringParameter("inpadClientId");
      boolean editableTab = (!org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)
                            && (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)));
   
        OBError myError = new OBError();
        String commandType = request.getParameter("inpCommandType");
        String straAssetAcctId = request.getParameter("inpaAssetAcctId");
         String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !straAssetAcctId.equals(""))
              total = saveRecord(vars, myError, 'U', strPA_Asset_ID);
          else
              total = saveRecord(vars, myError, 'I', strPA_Asset_ID);
         
          if (!myError.isEmpty() && total == 0)    
            throw new OBException(myError.getMessage());
        }
        vars.setSessionValue(request.getParameter("mappingName") +"|hash", vars.getPostDataHash());
        vars.setSessionValue(tabId + "|Header.view", "EDIT");
       
        return;
    }
   
    try {
      tableSQL = new TableSQLData(vars, this, tabId, Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel), Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    String strOrderBy = vars.getSessionValue(tabId + "|orderby");
    if (!strOrderBy.equals("")) {
      vars.setSessionValue(tabId + "|newOrder", "1");
    }

    if (vars.commandIn("DEFAULT")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID", "");

      String strA_Asset_Acct_ID = vars.getGlobalVariable("inpaAssetAcctId", windowId + "|A_Asset_Acct_ID", "");
            if (strPA_Asset_ID.equals("")) {
        strPA_Asset_ID = getParentID(vars, strA_Asset_Acct_ID);
        if (strPA_Asset_ID.equals("")) throw new ServletException("Required parameter :" + windowId + "|A_Asset_ID");
        vars.setSessionValue(windowId + "|A_Asset_ID", strPA_Asset_ID);

        refreshParentSession(vars, strPA_Asset_ID);
      }


      String strView = vars.getSessionValue(tabId + "|Accounting.view");
      if (strView.equals("")) {
        strView = defaultTabView;

        if (strView.equals("EDIT")) {
          if (strA_Asset_Acct_ID.equals("")) strA_Asset_Acct_ID = firstElement(vars, tableSQL);
          if (strA_Asset_Acct_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strA_Asset_Acct_ID, strPA_Asset_ID, tableSQL);

      else printPageDataSheet(response, vars, strPA_Asset_ID, strA_Asset_Acct_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strA_Asset_Acct_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strA_Asset_Acct_ID.equals("")) strA_Asset_Acct_ID = vars.getRequiredGlobalVariable("inpaAssetAcctId", windowId + "|A_Asset_Acct_ID");
      else vars.setSessionValue(windowId + "|A_Asset_Acct_ID", strA_Asset_Acct_ID);
     
     
      String strPA_Asset_ID = getParentID(vars, strA_Asset_Acct_ID);
     
      vars.setSessionValue(windowId + "|A_Asset_ID", strPA_Asset_ID);
      vars.setSessionValue("800078|Assets.view", "EDIT");

      refreshParentSession(vars, strPA_Asset_ID);

      vars.setSessionValue(tabId + "|Accounting.view", "EDIT");

      printPageEdit(response, request, vars, false, strA_Asset_Acct_ID, strPA_Asset_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID", false, false, true, "");
      vars.removeSessionValue(windowId + "|A_Asset_Acct_ID");
      refreshParentSession(vars, strPA_Asset_ID);


      String strView = vars.getSessionValue(tabId + "|Accounting.view");
      String strA_Asset_Acct_ID = "";
      if (strView.equals("")) {
        strView = defaultTabView;
        if (strView.equals("EDIT")) {
          strA_Asset_Acct_ID = firstElement(vars, tableSQL);
          if (strA_Asset_Acct_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT")) {

        if (strA_Asset_Acct_ID.equals("")) strA_Asset_Acct_ID = firstElement(vars, tableSQL);
        printPageEdit(response, request, vars, false, strA_Asset_Acct_ID, strPA_Asset_ID, tableSQL);

      } else printPageDataSheet(response, vars, strPA_Asset_ID, "", tableSQL);
    } else if (vars.commandIn("SEARCH")) {
vars.getRequestGlobalVariable("inpParamA_Asset_ID", tabId + "|paramA_Asset_ID");
vars.getRequestGlobalVariable("inpParamC_AcctSchema_ID", tabId + "|paramC_AcctSchema_ID");

            String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");

     
      vars.removeSessionValue(windowId + "|A_Asset_Acct_ID");
      String strA_Asset_Acct_ID="";

      String strView = vars.getSessionValue(tabId + "|Accounting.view");
      if (strView.equals("")) strView=defaultTabView;

      if (strView.equals("EDIT")) {
        strA_Asset_Acct_ID = firstElement(vars, tableSQL);
        if (strA_Asset_Acct_ID.equals("")) {
          // filter returns empty set
          strView = "RELATION";
          // switch to grid permanently until the user changes the view again
          vars.setSessionValue(tabId + "|Accounting.view", strView);
        }
      }

      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strA_Asset_Acct_ID, strPA_Asset_ID, tableSQL);

      else printPageDataSheet(response, vars, strPA_Asset_ID, strA_Asset_Acct_ID, tableSQL);
    } else if (vars.commandIn("RELATION")) {
            String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");
     

      String strA_Asset_Acct_ID = vars.getGlobalVariable("inpaAssetAcctId", windowId + "|A_Asset_Acct_ID", "");
      vars.setSessionValue(tabId + "|Accounting.view", "RELATION");
      printPageDataSheet(response, vars, strPA_Asset_ID, strA_Asset_Acct_ID, tableSQL);
    } else if (vars.commandIn("NEW")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");


      printPageEdit(response, request, vars, true, "", strPA_Asset_ID, tableSQL);

    } else if (vars.commandIn("EDIT")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");

      @SuppressWarnings("unused") // In Expense Invoice tab this variable is not used, to be fixed
      String strA_Asset_Acct_ID = vars.getGlobalVariable("inpaAssetAcctId", windowId + "|A_Asset_Acct_ID", "");
      vars.setSessionValue(tabId + "|Accounting.view", "EDIT");

      setHistoryCommand(request, "EDIT");
      printPageEdit(response, request, vars, false, strA_Asset_Acct_ID, strPA_Asset_ID, tableSQL);

    } else if (vars.commandIn("NEXT")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");
      String strA_Asset_Acct_ID = vars.getRequiredStringParameter("inpaAssetAcctId");
     
      String strNext = nextElement(vars, strA_Asset_Acct_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, strPA_Asset_ID, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");
      String strA_Asset_Acct_ID = vars.getRequiredStringParameter("inpaAssetAcctId");
     
      String strPrevious = previousElement(vars, strA_Asset_Acct_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, strPA_Asset_ID, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {
vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");

      vars.setSessionValue(tabId + "|Accounting.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Accounting.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      if (strInitRecord.equals("") || strInitRecord.equals("0")) {
        vars.setSessionValue(tabId + "|Accounting.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|Accounting.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|A_Asset_Acct_ID");
      vars.setSessionValue(windowId + "|A_Asset_ID", strPA_Asset_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Accounting.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
      if (initRecord==0) initRecord=1;
      initRecord += intRecordRange;
      strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
      vars.setSessionValue(tabId + "|Accounting.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|A_Asset_Acct_ID");
      vars.setSessionValue(windowId + "|A_Asset_ID", strPA_Asset_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");
     
      String strFirst = firstElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strFirst, strPA_Asset_ID, tableSQL);
    } else if (vars.commandIn("LAST_RELATION")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");

      String strLast = lastElement(vars, tableSQL);
      printPageDataSheet(response, vars, strPA_Asset_ID, strLast, tableSQL);
    } else if (vars.commandIn("LAST")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");
     
      String strLast = lastElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strLast, strPA_Asset_ID, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");
      OBError myError = new OBError();     
      int total = saveRecord(vars, myError, 'I', strPA_Asset_ID);     
      if (!myError.isEmpty()) {       
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
      }
      else {
    if (myError.isEmpty()) {
      myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsInserted");
      myError.setMessage(total + " " + myError.getMessage());
      vars.setMessage(tabId, myError);
    }       
        if (vars.commandIn("SAVE_NEW_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_NEW_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
    } else if (vars.commandIn("SAVE_EDIT_RELATION", "SAVE_EDIT_NEW", "SAVE_EDIT_EDIT", "SAVE_EDIT_NEXT")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");
      String strA_Asset_Acct_ID = vars.getRequiredGlobalVariable("inpaAssetAcctId", windowId + "|A_Asset_Acct_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U', strPA_Asset_ID);     
      if (!myError.isEmpty()) {
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
      }
      else {
        if (myError.isEmpty()) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsUpdated");
          myError.setMessage(total + " " + myError.getMessage());
          vars.setMessage(tabId, myError);
        }
        if (vars.commandIn("SAVE_EDIT_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_EDIT_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else if (vars.commandIn("SAVE_EDIT_NEXT")) {
          String strNext = nextElement(vars, strA_Asset_Acct_ID, tableSQL);
          vars.setSessionValue(windowId + "|A_Asset_Acct_ID", strNext);
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        } else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
/*    } else if (vars.commandIn("DELETE_RELATION")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");

      String strA_Asset_Acct_ID = vars.getRequiredInStringParameter("inpaAssetAcctId");
      String message = deleteRelation(vars, strA_Asset_Acct_ID, strPA_Asset_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|aAssetAcctId");
        vars.setSessionValue(tabId + "|Accounting.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {
      String strPA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");

      String strA_Asset_Acct_ID = vars.getRequiredStringParameter("inpaAssetAcctId");
      //AccountingData data = getEditVariables(vars, strPA_Asset_ID);
      int total = 0;
      OBError myError = null;
      if (org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
        vars.setMessage(tabId, myError);
      } else {
        try {
          total = AccountingData.delete(this, strA_Asset_Acct_ID, strPA_Asset_ID, Utility.getContext(this, vars, "#User_Client", windowId, accesslevel), Utility.getContext(this, vars, "#User_Org", windowId, accesslevel));
        } catch(ServletException ex) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
          if (!myError.isConnectionAvailable()) {
            bdErrorConnection(response);
            return;
          } else vars.setMessage(tabId, myError);
        }
        if (myError==null && total==0) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
        }
        vars.removeSessionValue(windowId + "|aAssetAcctId");
        vars.setSessionValue(tabId + "|Accounting.view", "RELATION");
      }
      if (myError==null) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsDeleted");
        myError.setMessage(total + " " + myError.getMessage());
        vars.setMessage(tabId, myError);
      }
      response.sendRedirect(strDireccion + request.getServletPath());








    } else if (vars.getCommand().toUpperCase().startsWith("BUTTON") || vars.getCommand().toUpperCase().startsWith("SAVE_BUTTON")) {
      pageErrorPopUp(response);
    } else pageError(response);
  }
View Full Code Here

  private static final int accesslevel = 3;
  private static final double SUBTABS_COL_SIZE = 15;

  public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
    TableSQLData tableSQL = null;
    VariablesSecureApp vars = new VariablesSecureApp(request);
    Boolean saveRequest = (Boolean) request.getAttribute("autosave");
   
    if(saveRequest != null && saveRequest){
      String currentOrg = vars.getStringParameter("inpadOrgId");
      String currentClient = vars.getStringParameter("inpadClientId");
      boolean editableTab = (!org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)
                            && (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)));
   
        OBError myError = new OBError();
        String commandType = request.getParameter("inpCommandType");
        String strmaProcessId = request.getParameter("inpmaProcessId");
       
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !strmaProcessId.equals(""))
              total = saveRecord(vars, myError, 'U');
          else
              total = saveRecord(vars, myError, 'I');
         
          if (!myError.isEmpty() && total == 0)    
            throw new OBException(myError.getMessage());
        }
        vars.setSessionValue(request.getParameter("mappingName") +"|hash", vars.getPostDataHash());
        vars.setSessionValue(tabId + "|Header.view", "EDIT");
       
        return;
    }
   
    try {
      tableSQL = new TableSQLData(vars, this, tabId, Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel), Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    String strOrderBy = vars.getSessionValue(tabId + "|orderby");
    if (!strOrderBy.equals("")) {
      vars.setSessionValue(tabId + "|newOrder", "1");
    }

    if (vars.commandIn("DEFAULT")) {

      String strMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID", "");
     

      String strView = vars.getSessionValue(tabId + "|Activity.view");
      if (strView.equals("")) {
        strView = defaultTabView;

        if (strView.equals("EDIT")) {
          if (strMA_Process_ID.equals("")) strMA_Process_ID = firstElement(vars, tableSQL);
          if (strMA_Process_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strMA_Process_ID, tableSQL);

      else printPageDataSheet(response, vars, strMA_Process_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strMA_Process_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strMA_Process_ID.equals("")) strMA_Process_ID = vars.getRequiredGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");
      else vars.setSessionValue(windowId + "|MA_Process_ID", strMA_Process_ID);
     
      vars.setSessionValue(tabId + "|Activity.view", "EDIT");

      printPageEdit(response, request, vars, false, strMA_Process_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {


      String strView = vars.getSessionValue(tabId + "|Activity.view");
      String strMA_Process_ID = "";
      if (strView.equals("")) {
        strView = defaultTabView;
        if (strView.equals("EDIT")) {
          strMA_Process_ID = firstElement(vars, tableSQL);
          if (strMA_Process_ID.equals("")) strView = "RELATION";
        }
      }
      if (strView.equals("EDIT")) {

        if (strMA_Process_ID.equals("")) strMA_Process_ID = firstElement(vars, tableSQL);
        printPageEdit(response, request, vars, false, strMA_Process_ID, tableSQL);

      } else printPageDataSheet(response, vars, "", tableSQL);
    } else if (vars.commandIn("SEARCH")) {
vars.getRequestGlobalVariable("inpParamName", tabId + "|paramName");

     
     
      vars.removeSessionValue(windowId + "|MA_Process_ID");
      String strMA_Process_ID="";

      String strView = vars.getSessionValue(tabId + "|Activity.view");
      if (strView.equals("")) strView=defaultTabView;

      if (strView.equals("EDIT")) {
        strMA_Process_ID = firstElement(vars, tableSQL);
        if (strMA_Process_ID.equals("")) {
          // filter returns empty set
          strView = "RELATION";
          // switch to grid permanently until the user changes the view again
          vars.setSessionValue(tabId + "|Activity.view", strView);
        }
      }

      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strMA_Process_ID, tableSQL);

      else printPageDataSheet(response, vars, strMA_Process_ID, tableSQL);
    } else if (vars.commandIn("RELATION")) {
     

      String strMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID", "");
      vars.setSessionValue(tabId + "|Activity.view", "RELATION");
      printPageDataSheet(response, vars, strMA_Process_ID, tableSQL);
    } else if (vars.commandIn("NEW")) {


      printPageEdit(response, request, vars, true, "", tableSQL);

    } else if (vars.commandIn("EDIT")) {

      @SuppressWarnings("unused") // In Expense Invoice tab this variable is not used, to be fixed
      String strMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID", "");
      vars.setSessionValue(tabId + "|Activity.view", "EDIT");

      setHistoryCommand(request, "EDIT");
      printPageEdit(response, request, vars, false, strMA_Process_ID, tableSQL);

    } else if (vars.commandIn("NEXT")) {

      String strMA_Process_ID = vars.getRequiredStringParameter("inpmaProcessId");
     
      String strNext = nextElement(vars, strMA_Process_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {

      String strMA_Process_ID = vars.getRequiredStringParameter("inpmaProcessId");
     
      String strPrevious = previousElement(vars, strMA_Process_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {

      vars.setSessionValue(tabId + "|Activity.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {

      String strInitRecord = vars.getSessionValue(tabId + "|Activity.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      if (strInitRecord.equals("") || strInitRecord.equals("0")) {
        vars.setSessionValue(tabId + "|Activity.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|Activity.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|MA_Process_ID");

      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {

      String strInitRecord = vars.getSessionValue(tabId + "|Activity.initRecordNumber");
      String strRecordRange = Utility.getContext(this, vars, "#RecordRange", windowId);
      int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
      int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
      if (initRecord==0) initRecord=1;
      initRecord += intRecordRange;
      strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
      vars.setSessionValue(tabId + "|Activity.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|MA_Process_ID");

      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {

     
      String strFirst = firstElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strFirst, tableSQL);
    } else if (vars.commandIn("LAST_RELATION")) {

      String strLast = lastElement(vars, tableSQL);
      printPageDataSheet(response, vars, strLast, tableSQL);
    } else if (vars.commandIn("LAST")) {

     
      String strLast = lastElement(vars, tableSQL);

      printPageEdit(response, request, vars, false, strLast, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {

      OBError myError = new OBError();     
      int total = saveRecord(vars, myError, 'I');     
      if (!myError.isEmpty()) {       
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
      }
      else {
    if (myError.isEmpty()) {
      myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsInserted");
      myError.setMessage(total + " " + myError.getMessage());
      vars.setMessage(tabId, myError);
    }       
        if (vars.commandIn("SAVE_NEW_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_NEW_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
    } else if (vars.commandIn("SAVE_EDIT_RELATION", "SAVE_EDIT_NEW", "SAVE_EDIT_EDIT", "SAVE_EDIT_NEXT")) {

      String strMA_Process_ID = vars.getRequiredGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U');     
      if (!myError.isEmpty()) {
        response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
      }
      else {
        if (myError.isEmpty()) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsUpdated");
          myError.setMessage(total + " " + myError.getMessage());
          vars.setMessage(tabId, myError);
        }
        if (vars.commandIn("SAVE_EDIT_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
        else if (vars.commandIn("SAVE_EDIT_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        else if (vars.commandIn("SAVE_EDIT_NEXT")) {
          String strNext = nextElement(vars, strMA_Process_ID, tableSQL);
          vars.setSessionValue(windowId + "|MA_Process_ID", strNext);
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        } else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
/*    } else if (vars.commandIn("DELETE_RELATION")) {

      String strMA_Process_ID = vars.getRequiredInStringParameter("inpmaProcessId");
      String message = deleteRelation(vars, strMA_Process_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|maProcessId");
        vars.setSessionValue(tabId + "|Activity.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {

      String strMA_Process_ID = vars.getRequiredStringParameter("inpmaProcessId");
      //ActivityData data = getEditVariables(vars);
      int total = 0;
      OBError myError = null;
      if (org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
        vars.setMessage(tabId, myError);
      } else {
        try {
          total = ActivityData.delete(this, strMA_Process_ID, Utility.getContext(this, vars, "#User_Client", windowId, accesslevel), Utility.getContext(this, vars, "#User_Org", windowId, accesslevel));
        } catch(ServletException ex) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
          if (!myError.isConnectionAvailable()) {
            bdErrorConnection(response);
            return;
          } else vars.setMessage(tabId, myError);
        }
        if (myError==null && total==0) {
          myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
        }
        vars.removeSessionValue(windowId + "|maProcessId");
        vars.setSessionValue(tabId + "|Activity.view", "RELATION");
      }
      if (myError==null) {
        myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsDeleted");
        myError.setMessage(total + " " + myError.getMessage());
        vars.setMessage(tabId, myError);
      }
      response.sendRedirect(strDireccion + request.getServletPath());








    } else if (vars.getCommand().toUpperCase().startsWith("BUTTON") || vars.getCommand().toUpperCase().startsWith("SAVE_BUTTON")) {
      pageErrorPopUp(response);
    } else pageError(response);
  }
View Full Code Here

TOP

Related Classes of org.openbravo.base.secureApp.VariablesSecureApp

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.