Package org.openbravo.base.secureApp

Examples of org.openbravo.base.secureApp.VariablesSecureApp


  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 strmaToolsetprocessId = request.getParameter("inpmaToolsetprocessId");
         String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !strmaToolsetprocessId.equals(""))
              total = saveRecord(vars, myError, 'U', strPMA_Process_ID);
          else
              total = saveRecord(vars, myError, 'I', strPMA_Process_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_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID", "");

      String strMA_Toolsetprocess_ID = vars.getGlobalVariable("inpmaToolsetprocessId", windowId + "|MA_Toolsetprocess_ID", "");
            if (strPMA_Process_ID.equals("")) {
        strPMA_Process_ID = getParentID(vars, strMA_Toolsetprocess_ID);
        if (strPMA_Process_ID.equals("")) throw new ServletException("Required parameter :" + windowId + "|MA_Process_ID");
        vars.setSessionValue(windowId + "|MA_Process_ID", strPMA_Process_ID);

        refreshParentSession(vars, strPMA_Process_ID);
      }


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

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

        printPageEdit(response, request, vars, false, strMA_Toolsetprocess_ID, strPMA_Process_ID, tableSQL);

      else printPageDataSheet(response, vars, strPMA_Process_ID, strMA_Toolsetprocess_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strMA_Toolsetprocess_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strMA_Toolsetprocess_ID.equals("")) strMA_Toolsetprocess_ID = vars.getRequiredGlobalVariable("inpmaToolsetprocessId", windowId + "|MA_Toolsetprocess_ID");
      else vars.setSessionValue(windowId + "|MA_Toolsetprocess_ID", strMA_Toolsetprocess_ID);
     
     
      String strPMA_Process_ID = getParentID(vars, strMA_Toolsetprocess_ID);
     
      vars.setSessionValue(windowId + "|MA_Process_ID", strPMA_Process_ID);
      vars.setSessionValue("800143|Activity.view", "EDIT");

      refreshParentSession(vars, strPMA_Process_ID);

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

      printPageEdit(response, request, vars, false, strMA_Toolsetprocess_ID, strPMA_Process_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {
      String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID", false, false, true, "");
      vars.removeSessionValue(windowId + "|MA_Toolsetprocess_ID");
      refreshParentSession(vars, strPMA_Process_ID);


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

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

      } else printPageDataSheet(response, vars, strPMA_Process_ID, "", tableSQL);
    } else if (vars.commandIn("SEARCH")) {
vars.getRequestGlobalVariable("inpParamMA_Toolset_Type_ID", tabId + "|paramMA_Toolset_Type_ID");
vars.getRequestGlobalVariable("inpParamMA_Process_ID", tabId + "|paramMA_Process_ID");

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

     
      vars.removeSessionValue(windowId + "|MA_Toolsetprocess_ID");
      String strMA_Toolsetprocess_ID="";

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

      if (strView.equals("EDIT")) {
        strMA_Toolsetprocess_ID = firstElement(vars, tableSQL);
        if (strMA_Toolsetprocess_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_Toolsetprocess_ID, strPMA_Process_ID, tableSQL);

      else printPageDataSheet(response, vars, strPMA_Process_ID, strMA_Toolsetprocess_ID, tableSQL);
    } else if (vars.commandIn("RELATION")) {
            String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");
     

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


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

    } else if (vars.commandIn("EDIT")) {
      String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");

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

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

    } else if (vars.commandIn("NEXT")) {
      String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");
      String strMA_Toolsetprocess_ID = vars.getRequiredStringParameter("inpmaToolsetprocessId");
     
      String strNext = nextElement(vars, strMA_Toolsetprocess_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, strPMA_Process_ID, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {
      String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");
      String strMA_Toolsetprocess_ID = vars.getRequiredStringParameter("inpmaToolsetprocessId");
     
      String strPrevious = previousElement(vars, strMA_Toolsetprocess_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, strPMA_Process_ID, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {
vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");

      vars.setSessionValue(tabId + "|Toolset.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {
      String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_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_Toolsetprocess_ID");
      vars.setSessionValue(windowId + "|MA_Process_ID", strPMA_Process_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {
      String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_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_Toolsetprocess_ID");
      vars.setSessionValue(windowId + "|MA_Process_ID", strPMA_Process_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {
      String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");
     
      String strFirst = firstElement(vars, tableSQL);

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

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

      printPageEdit(response, request, vars, false, strLast, strPMA_Process_ID, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
      String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");
      OBError myError = new OBError();     
      int total = saveRecord(vars, myError, 'I', strPMA_Process_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_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");
      String strMA_Toolsetprocess_ID = vars.getRequiredGlobalVariable("inpmaToolsetprocessId", windowId + "|MA_Toolsetprocess_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U', strPMA_Process_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_Toolsetprocess_ID, tableSQL);
          vars.setSessionValue(windowId + "|MA_Toolsetprocess_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_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");

      String strMA_Toolsetprocess_ID = vars.getRequiredInStringParameter("inpmaToolsetprocessId");
      String message = deleteRelation(vars, strMA_Toolsetprocess_ID, strPMA_Process_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|maToolsetprocessId");
        vars.setSessionValue(tabId + "|Toolset.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {
      String strPMA_Process_ID = vars.getGlobalVariable("inpmaProcessId", windowId + "|MA_Process_ID");

      String strMA_Toolsetprocess_ID = vars.getRequiredStringParameter("inpmaToolsetprocessId");
      //ToolsetData data = getEditVariables(vars, strPMA_Process_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_Toolsetprocess_ID, strPMA_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 + "|maToolsetprocessId");
        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


    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 strMPriceListID = vars.getStringParameter("inpmPricelistId");
      String strTabId = vars.getStringParameter("inpTabId");

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

  private static final int accesslevel = 1;
  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 strmaMeasureShiftId = request.getParameter("inpmaMeasureShiftId");
       
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !strmaMeasureShiftId.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_Measure_Shift_ID = vars.getGlobalVariable("inpmaMeasureShiftId", windowId + "|MA_Measure_Shift_ID", "");
     

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

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

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

      else printPageDataSheet(response, vars, strMA_Measure_Shift_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strMA_Measure_Shift_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strMA_Measure_Shift_ID.equals("")) strMA_Measure_Shift_ID = vars.getRequiredGlobalVariable("inpmaMeasureShiftId", windowId + "|MA_Measure_Shift_ID");
      else vars.setSessionValue(windowId + "|MA_Measure_Shift_ID", strMA_Measure_Shift_ID);
     
      vars.setSessionValue(tabId + "|DateandShift.view", "EDIT");

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

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


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

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

      } else printPageDataSheet(response, vars, "", tableSQL);
    } else if (vars.commandIn("SEARCH")) {
vars.getRequestGlobalVariable("inpParamMeasuredate", tabId + "|paramMeasuredate");
vars.getRequestGlobalVariable("inpParamMeasuredate_f", tabId + "|paramMeasuredate_f");

     
     
      vars.removeSessionValue(windowId + "|MA_Measure_Shift_ID");
      String strMA_Measure_Shift_ID="";

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

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

      if (strView.equals("EDIT"))

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

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

      String strMA_Measure_Shift_ID = vars.getGlobalVariable("inpmaMeasureShiftId", windowId + "|MA_Measure_Shift_ID", "");
      vars.setSessionValue(tabId + "|DateandShift.view", "RELATION");
      printPageDataSheet(response, vars, strMA_Measure_Shift_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_Measure_Shift_ID = vars.getGlobalVariable("inpmaMeasureShiftId", windowId + "|MA_Measure_Shift_ID", "");
      vars.setSessionValue(tabId + "|DateandShift.view", "EDIT");

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

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

      String strMA_Measure_Shift_ID = vars.getRequiredStringParameter("inpmaMeasureShiftId");
     
      String strNext = nextElement(vars, strMA_Measure_Shift_ID, tableSQL);

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

      String strMA_Measure_Shift_ID = vars.getRequiredStringParameter("inpmaMeasureShiftId");
     
      String strPrevious = previousElement(vars, strMA_Measure_Shift_ID, tableSQL);

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

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

      String strInitRecord = vars.getSessionValue(tabId + "|DateandShift.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 + "|DateandShift.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|DateandShift.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|MA_Measure_Shift_ID");

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

      String strInitRecord = vars.getSessionValue(tabId + "|DateandShift.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 + "|DateandShift.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|MA_Measure_Shift_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_Measure_Shift_ID = vars.getRequiredGlobalVariable("inpmaMeasureShiftId", windowId + "|MA_Measure_Shift_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_Measure_Shift_ID, tableSQL);
          vars.setSessionValue(windowId + "|MA_Measure_Shift_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_Measure_Shift_ID = vars.getRequiredInStringParameter("inpmaMeasureShiftId");
      String message = deleteRelation(vars, strMA_Measure_Shift_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|maMeasureShiftId");
        vars.setSessionValue(tabId + "|DateandShift.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {

      String strMA_Measure_Shift_ID = vars.getRequiredStringParameter("inpmaMeasureShiftId");
      //DateandShiftData 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 = DateandShiftData.delete(this, strMA_Measure_Shift_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 + "|maMeasureShiftId");
        vars.setSessionValue(tabId + "|DateandShift.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.commandIn("BUTTONProcessed800127")) {
        vars.setSessionValue("button800127.strprocessed", vars.getStringParameter("inpprocessed"));
        vars.setSessionValue("button800127.strProcessing", vars.getStringParameter("inpprocessing", "Y"));
        vars.setSessionValue("button800127.strOrg", vars.getStringParameter("inpadOrgId"));
        vars.setSessionValue("button800127.strClient", vars.getStringParameter("inpadClientId"));
       
       
        HashMap<String, String> p = new HashMap<String, String>();
       
       
        //Save in session needed params for combos if needed
        vars.setSessionObject("button800127.originalParams", FieldProviderFactory.getFieldProvider(p));
        printPageButtonFS(response, vars, "800127", request.getServletPath());   
     } else if (vars.commandIn("BUTTON800127")) {
        String strMA_Measure_Shift_ID = vars.getGlobalVariable("inpmaMeasureShiftId", windowId + "|MA_Measure_Shift_ID", "");
        String strprocessed = vars.getSessionValue("button800127.strprocessed");
        String strProcessing = vars.getSessionValue("button800127.strProcessing");
        String strOrg = vars.getSessionValue("button800127.strOrg");
        String strClient = vars.getSessionValue("button800127.strClient");
       
       
        if ((org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) || !(Utility.isElementInList(Utility.getContext(this, vars, "#User_Client", windowId, accesslevel),strClient&& Utility.isElementInList(Utility.getContext(this, vars, "#User_Org", windowId, accesslevel),strOrg))){
          OBError myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
          printPageClosePopUp(response, vars);
        }else{      
          printPageButtonProcessed800127(response, vars, strMA_Measure_Shift_ID, strprocessed, strProcessing);
        }


    } else if (vars.commandIn("SAVE_BUTTONProcessed800127")) {
        String strMA_Measure_Shift_ID = vars.getGlobalVariable("inpKey", windowId + "|MA_Measure_Shift_ID", "");
        @SuppressWarnings("unused")
        String strprocessed = vars.getStringParameter("inpprocessed");
        String strProcessing = vars.getStringParameter("inpprocessing");
        OBError myMessage = null;
        try {
          String pinstance = SequenceIdData.getUUID();
          PInstanceProcessData.insertPInstance(this, pinstance, "800127", (("MA_Measure_Shift_ID".equalsIgnoreCase("AD_Language"))?"0":strMA_Measure_Shift_ID), strProcessing, vars.getUser(), vars.getClient(), vars.getOrg());
         
         
          ProcessBundle bundle = ProcessBundle.pinstance(pinstance, vars, this);
          new ProcessRunner(bundle).execute(this);
         
          PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(this, pinstance);
          myMessage = Utility.getProcessInstanceMessage(this, vars, pinstanceData);
        } catch (ServletException ex) {
          myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
          if (!myMessage.isConnectionAvailable()) {
            bdErrorConnection(response);
            return;
          } else vars.setMessage(tabId, myMessage);
        }
        //close popup
        if (myMessage!=null) {
          if (log4j.isDebugEnabled()) log4j.debug(myMessage.getMessage());
          vars.setMessage(tabId, myMessage);
        }
        printPageClosePopUp(response, vars);






    } 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 = 1;
  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 strmTransactionId = request.getParameter("inpmTransactionId");
         String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !strmTransactionId.equals(""))
              total = saveRecord(vars, myError, 'U', strPM_Locator_ID);
          else
              total = saveRecord(vars, myError, 'I', strPM_Locator_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 strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID", "");

      String strM_Transaction_ID = vars.getGlobalVariable("inpmTransactionId", windowId + "|M_Transaction_ID", "");
            if (strPM_Locator_ID.equals("")) {
        strPM_Locator_ID = getParentID(vars, strM_Transaction_ID);
        if (strPM_Locator_ID.equals("")) throw new ServletException("Required parameter :" + windowId + "|M_Locator_ID");
        vars.setSessionValue(windowId + "|M_Locator_ID", strPM_Locator_ID);
      vars.removeSessionValue(windowId + "|M_Warehouse_ID");
        refreshParentSession(vars, strPM_Locator_ID);
      }


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

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

        printPageEdit(response, request, vars, false, strM_Transaction_ID, strPM_Locator_ID, tableSQL);

      else printPageDataSheet(response, vars, strPM_Locator_ID, strM_Transaction_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strM_Transaction_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strM_Transaction_ID.equals("")) strM_Transaction_ID = vars.getRequiredGlobalVariable("inpmTransactionId", windowId + "|M_Transaction_ID");
      else vars.setSessionValue(windowId + "|M_Transaction_ID", strM_Transaction_ID);
     
     
      String strPM_Locator_ID = getParentID(vars, strM_Transaction_ID);
     
      vars.setSessionValue(windowId + "|M_Locator_ID", strPM_Locator_ID);
      vars.setSessionValue("null|null.view", "EDIT");
      vars.removeSessionValue(windowId + "|M_Warehouse_ID");
      refreshParentSession(vars, strPM_Locator_ID);

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

      printPageEdit(response, request, vars, false, strM_Transaction_ID, strPM_Locator_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID", false, false, true, "");
      vars.removeSessionValue(windowId + "|M_Transaction_ID");
      refreshParentSession(vars, strPM_Locator_ID);


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

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

      } else printPageDataSheet(response, vars, strPM_Locator_ID, "", tableSQL);
    } else if (vars.commandIn("SEARCH")) {
vars.getRequestGlobalVariable("inpParamMovementDate", tabId + "|paramMovementDate");
vars.getRequestGlobalVariable("inpParamMovementType", tabId + "|paramMovementType");
vars.getRequestGlobalVariable("inpParamM_Product_ID", tabId + "|paramM_Product_ID");
vars.getRequestGlobalVariable("inpParamMovementDate_f", tabId + "|paramMovementDate_f");

            String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");

     
      vars.removeSessionValue(windowId + "|M_Transaction_ID");
      String strM_Transaction_ID="";

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

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

      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strM_Transaction_ID, strPM_Locator_ID, tableSQL);

      else printPageDataSheet(response, vars, strPM_Locator_ID, strM_Transaction_ID, tableSQL);
    } else if (vars.commandIn("RELATION")) {
            String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");
     

      String strM_Transaction_ID = vars.getGlobalVariable("inpmTransactionId", windowId + "|M_Transaction_ID", "");
      vars.setSessionValue(tabId + "|ProductTransactions.view", "RELATION");
      printPageDataSheet(response, vars, strPM_Locator_ID, strM_Transaction_ID, tableSQL);
    } else if (vars.commandIn("NEW")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");


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

    } else if (vars.commandIn("EDIT")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");

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

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

    } else if (vars.commandIn("NEXT")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");
      String strM_Transaction_ID = vars.getRequiredStringParameter("inpmTransactionId");
     
      String strNext = nextElement(vars, strM_Transaction_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, strPM_Locator_ID, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");
      String strM_Transaction_ID = vars.getRequiredStringParameter("inpmTransactionId");
     
      String strPrevious = previousElement(vars, strM_Transaction_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, strPM_Locator_ID, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {
vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");

      vars.setSessionValue(tabId + "|ProductTransactions.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|ProductTransactions.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 + "|ProductTransactions.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|ProductTransactions.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|M_Transaction_ID");
      vars.setSessionValue(windowId + "|M_Locator_ID", strPM_Locator_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|ProductTransactions.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 + "|ProductTransactions.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|M_Transaction_ID");
      vars.setSessionValue(windowId + "|M_Locator_ID", strPM_Locator_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");
     
      String strFirst = firstElement(vars, tableSQL);

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

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

      printPageEdit(response, request, vars, false, strLast, strPM_Locator_ID, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");
      OBError myError = new OBError();     
      int total = saveRecord(vars, myError, 'I', strPM_Locator_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 strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");
      String strM_Transaction_ID = vars.getRequiredGlobalVariable("inpmTransactionId", windowId + "|M_Transaction_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U', strPM_Locator_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, strM_Transaction_ID, tableSQL);
          vars.setSessionValue(windowId + "|M_Transaction_ID", strNext);
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        } else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
/*    } else if (vars.commandIn("DELETE_RELATION")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");

      String strM_Transaction_ID = vars.getRequiredInStringParameter("inpmTransactionId");
      String message = deleteRelation(vars, strM_Transaction_ID, strPM_Locator_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|mTransactionId");
        vars.setSessionValue(tabId + "|ProductTransactions.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {
      String strPM_Locator_ID = vars.getGlobalVariable("inpmLocatorId", windowId + "|M_Locator_ID");

      String strM_Transaction_ID = vars.getRequiredStringParameter("inpmTransactionId");
      //ProductTransactionsData data = getEditVariables(vars, strPM_Locator_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 = ProductTransactionsData.delete(this, strM_Transaction_ID, strPM_Locator_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 + "|mTransactionId");
        vars.setSessionValue(tabId + "|ProductTransactions.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 strIsActive = vars.getStringParameter("inpisactive");
      String strParentTaxId = vars.getStringParameter("inpcTaxId");
      try {
        printPage(response, vars, strIsActive, strParentTaxId);
      } 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 strBPartner = vars.getStringParameter("inpcBpartnerId");
      String strLocation = vars.getStringParameter("inpcBpartnerId_LOC");
      String strContact = vars.getStringParameter("inpcBpartnerId_CON");
      String strWindowId = vars.getStringParameter("inpwindowId");
      String strProjectId = vars.getStringParameter("inpcProjectId");
      String strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
      String strTabId = vars.getStringParameter("inpTabId");

      try {
        printPage(response, vars, strBPartner, strLocation, strContact, strWindowId, strProjectId,
            strIsSOTrx, strTabId);
      } catch (ServletException ex) {
View Full Code Here

  private static final int accesslevel = 4;
  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 stradMonthTrlId = request.getParameter("inpadMonthTrlId");
         String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !stradMonthTrlId.equals(""))
              total = saveRecord(vars, myError, 'U', strPAD_Month_ID);
          else
              total = saveRecord(vars, myError, 'I', strPAD_Month_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_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID", "");

      String strAD_Month_Trl_ID = vars.getGlobalVariable("inpadMonthTrlId", windowId + "|AD_Month_Trl_ID", "");
            if (strPAD_Month_ID.equals("")) {
        strPAD_Month_ID = getParentID(vars, strAD_Month_Trl_ID);
        if (strPAD_Month_ID.equals("")) throw new ServletException("Required parameter :" + windowId + "|AD_Month_ID");
        vars.setSessionValue(windowId + "|AD_Month_ID", strPAD_Month_ID);

        refreshParentSession(vars, strPAD_Month_ID);
      }


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

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

        printPageEdit(response, request, vars, false, strAD_Month_Trl_ID, strPAD_Month_ID, tableSQL);

      else printPageDataSheet(response, vars, strPAD_Month_ID, strAD_Month_Trl_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strAD_Month_Trl_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strAD_Month_Trl_ID.equals("")) strAD_Month_Trl_ID = vars.getRequiredGlobalVariable("inpadMonthTrlId", windowId + "|AD_Month_Trl_ID");
      else vars.setSessionValue(windowId + "|AD_Month_Trl_ID", strAD_Month_Trl_ID);
     
     
      String strPAD_Month_ID = getParentID(vars, strAD_Month_Trl_ID);
     
      vars.setSessionValue(windowId + "|AD_Month_ID", strPAD_Month_ID);
      vars.setSessionValue("800063|Month.view", "EDIT");

      refreshParentSession(vars, strPAD_Month_ID);

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

      printPageEdit(response, request, vars, false, strAD_Month_Trl_ID, strPAD_Month_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID", false, false, true, "");
      vars.removeSessionValue(windowId + "|AD_Month_Trl_ID");
      refreshParentSession(vars, strPAD_Month_ID);


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

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

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

            String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");

     
      vars.removeSessionValue(windowId + "|AD_Month_Trl_ID");
      String strAD_Month_Trl_ID="";

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

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

      if (strView.equals("EDIT"))

        printPageEdit(response, request, vars, false, strAD_Month_Trl_ID, strPAD_Month_ID, tableSQL);

      else printPageDataSheet(response, vars, strPAD_Month_ID, strAD_Month_Trl_ID, tableSQL);
    } else if (vars.commandIn("RELATION")) {
            String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");
     

      String strAD_Month_Trl_ID = vars.getGlobalVariable("inpadMonthTrlId", windowId + "|AD_Month_Trl_ID", "");
      vars.setSessionValue(tabId + "|Translation.view", "RELATION");
      printPageDataSheet(response, vars, strPAD_Month_ID, strAD_Month_Trl_ID, tableSQL);
    } else if (vars.commandIn("NEW")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");


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

    } else if (vars.commandIn("EDIT")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");

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

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

    } else if (vars.commandIn("NEXT")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");
      String strAD_Month_Trl_ID = vars.getRequiredStringParameter("inpadMonthTrlId");
     
      String strNext = nextElement(vars, strAD_Month_Trl_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, strPAD_Month_ID, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");
      String strAD_Month_Trl_ID = vars.getRequiredStringParameter("inpadMonthTrlId");
     
      String strPrevious = previousElement(vars, strAD_Month_Trl_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, strPAD_Month_ID, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {
vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");

      vars.setSessionValue(tabId + "|Translation.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Translation.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 + "|Translation.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|Translation.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|AD_Month_Trl_ID");
      vars.setSessionValue(windowId + "|AD_Month_ID", strPAD_Month_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Translation.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 + "|Translation.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|AD_Month_Trl_ID");
      vars.setSessionValue(windowId + "|AD_Month_ID", strPAD_Month_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");
     
      String strFirst = firstElement(vars, tableSQL);

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

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

      printPageEdit(response, request, vars, false, strLast, strPAD_Month_ID, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");
      OBError myError = new OBError();     
      int total = saveRecord(vars, myError, 'I', strPAD_Month_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_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");
      String strAD_Month_Trl_ID = vars.getRequiredGlobalVariable("inpadMonthTrlId", windowId + "|AD_Month_Trl_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U', strPAD_Month_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_Month_Trl_ID, tableSQL);
          vars.setSessionValue(windowId + "|AD_Month_Trl_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_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");

      String strAD_Month_Trl_ID = vars.getRequiredInStringParameter("inpadMonthTrlId");
      String message = deleteRelation(vars, strAD_Month_Trl_ID, strPAD_Month_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|adMonthTrlId");
        vars.setSessionValue(tabId + "|Translation.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {
      String strPAD_Month_ID = vars.getGlobalVariable("inpadMonthId", windowId + "|AD_Month_ID");

      String strAD_Month_Trl_ID = vars.getRequiredStringParameter("inpadMonthTrlId");
      //TranslationData data = getEditVariables(vars, strPAD_Month_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 = TranslationData.delete(this, strAD_Month_Trl_ID, strPAD_Month_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 + "|adMonthTrlId");
        vars.setSessionValue(tabId + "|Translation.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 = 1;
  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 straAssetId = request.getParameter("inpaAssetId");
       
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !straAssetId.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 strA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID", "");
     

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

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

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

      else printPageDataSheet(response, vars, strA_Asset_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strA_Asset_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strA_Asset_ID.equals("")) strA_Asset_ID = vars.getRequiredGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID");
      else vars.setSessionValue(windowId + "|A_Asset_ID", strA_Asset_ID);
     
      vars.setSessionValue(tabId + "|Assets.view", "EDIT");

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

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


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

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

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

     
     
      vars.removeSessionValue(windowId + "|A_Asset_ID");
      String strA_Asset_ID="";

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

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

      if (strView.equals("EDIT"))

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

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

      String strA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID", "");
      vars.setSessionValue(tabId + "|Assets.view", "RELATION");
      printPageDataSheet(response, vars, strA_Asset_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 strA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID", "");
      vars.setSessionValue(tabId + "|Assets.view", "EDIT");

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

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

      String strA_Asset_ID = vars.getRequiredStringParameter("inpaAssetId");
     
      String strNext = nextElement(vars, strA_Asset_ID, tableSQL);

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

      String strA_Asset_ID = vars.getRequiredStringParameter("inpaAssetId");
     
      String strPrevious = previousElement(vars, strA_Asset_ID, tableSQL);

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

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

      String strInitRecord = vars.getSessionValue(tabId + "|Assets.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 + "|Assets.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|Assets.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|A_Asset_ID");

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

      String strInitRecord = vars.getSessionValue(tabId + "|Assets.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 + "|Assets.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|A_Asset_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 strA_Asset_ID = vars.getRequiredGlobalVariable("inpaAssetId", windowId + "|A_Asset_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, strA_Asset_ID, tableSQL);
          vars.setSessionValue(windowId + "|A_Asset_ID", strNext);
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        } else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
/*    } else if (vars.commandIn("DELETE_RELATION")) {

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

      String strA_Asset_ID = vars.getRequiredStringParameter("inpaAssetId");
      //AssetsData 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 = AssetsData.delete(this, strA_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 + "|aAssetId");
        vars.setSessionValue(tabId + "|Assets.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.commandIn("BUTTONProcessed800125")) {
        vars.setSessionValue("button800125.strprocessed", vars.getStringParameter("inpprocessed"));
        vars.setSessionValue("button800125.strProcessing", vars.getStringParameter("inpprocessing", "Y"));
        vars.setSessionValue("button800125.strOrg", vars.getStringParameter("inpadOrgId"));
        vars.setSessionValue("button800125.strClient", vars.getStringParameter("inpadClientId"));
       
       
        HashMap<String, String> p = new HashMap<String, String>();
       
       
        //Save in session needed params for combos if needed
        vars.setSessionObject("button800125.originalParams", FieldProviderFactory.getFieldProvider(p));
        printPageButtonFS(response, vars, "800125", request.getServletPath());   
     } else if (vars.commandIn("BUTTON800125")) {
        String strA_Asset_ID = vars.getGlobalVariable("inpaAssetId", windowId + "|A_Asset_ID", "");
        String strprocessed = vars.getSessionValue("button800125.strprocessed");
        String strProcessing = vars.getSessionValue("button800125.strProcessing");
        String strOrg = vars.getSessionValue("button800125.strOrg");
        String strClient = vars.getSessionValue("button800125.strClient");
       
       
        if ((org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) || !(Utility.isElementInList(Utility.getContext(this, vars, "#User_Client", windowId, accesslevel),strClient&& Utility.isElementInList(Utility.getContext(this, vars, "#User_Org", windowId, accesslevel),strOrg))){
          OBError myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
          printPageClosePopUp(response, vars);
        }else{      
          printPageButtonProcessed800125(response, vars, strA_Asset_ID, strprocessed, strProcessing);
        }


    } else if (vars.commandIn("SAVE_BUTTONProcessed800125")) {
        String strA_Asset_ID = vars.getGlobalVariable("inpKey", windowId + "|A_Asset_ID", "");
        @SuppressWarnings("unused")
        String strprocessed = vars.getStringParameter("inpprocessed");
        String strProcessing = vars.getStringParameter("inpprocessing");
        OBError myMessage = null;
        try {
          String pinstance = SequenceIdData.getUUID();
          PInstanceProcessData.insertPInstance(this, pinstance, "800125", (("A_Asset_ID".equalsIgnoreCase("AD_Language"))?"0":strA_Asset_ID), strProcessing, vars.getUser(), vars.getClient(), vars.getOrg());
         
         
          ProcessBundle bundle = ProcessBundle.pinstance(pinstance, vars, this);
          new ProcessRunner(bundle).execute(this);
         
          PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(this, pinstance);
          myMessage = Utility.getProcessInstanceMessage(this, vars, pinstanceData);
        } catch (ServletException ex) {
          myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
          if (!myMessage.isConnectionAvailable()) {
            bdErrorConnection(response);
            return;
          } else vars.setMessage(tabId, myMessage);
        }
        //close popup
        if (myMessage!=null) {
          if (log4j.isDebugEnabled()) log4j.debug(myMessage.getMessage());
          vars.setMessage(tabId, myMessage);
        }
        printPageClosePopUp(response, vars);






    } 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 = 7;
  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 strvmLoanPaymentId = request.getParameter("inpvmLoanPaymentId");
         String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");
        if (editableTab) {
          int total = 0;
         
          if(commandType.equalsIgnoreCase("EDIT") && !strvmLoanPaymentId.equals(""))
              total = saveRecord(vars, myError, 'U', strPVM_Vehicle_Loan_ID);
          else
              total = saveRecord(vars, myError, 'I', strPVM_Vehicle_Loan_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 strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID", "");

      String strVM_Loan_Payment_ID = vars.getGlobalVariable("inpvmLoanPaymentId", windowId + "|VM_Loan_Payment_ID", "");
            if (strPVM_Vehicle_Loan_ID.equals("")) {
        strPVM_Vehicle_Loan_ID = getParentID(vars, strVM_Loan_Payment_ID);
        if (strPVM_Vehicle_Loan_ID.equals("")) throw new ServletException("Required parameter :" + windowId + "|VM_Vehicle_Loan_ID");
        vars.setSessionValue(windowId + "|VM_Vehicle_Loan_ID", strPVM_Vehicle_Loan_ID);
      vars.removeSessionValue(windowId + "|VM_Vehicle_Info_ID");
        refreshParentSession(vars, strPVM_Vehicle_Loan_ID);
      }


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

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

        printPageEdit(response, request, vars, false, strVM_Loan_Payment_ID, strPVM_Vehicle_Loan_ID, tableSQL);

      else printPageDataSheet(response, vars, strPVM_Vehicle_Loan_ID, strVM_Loan_Payment_ID, tableSQL);
    } else if (vars.commandIn("DIRECT")) {
      String strVM_Loan_Payment_ID = vars.getStringParameter("inpDirectKey");
     
       
      if (strVM_Loan_Payment_ID.equals("")) strVM_Loan_Payment_ID = vars.getRequiredGlobalVariable("inpvmLoanPaymentId", windowId + "|VM_Loan_Payment_ID");
      else vars.setSessionValue(windowId + "|VM_Loan_Payment_ID", strVM_Loan_Payment_ID);
     
     
      String strPVM_Vehicle_Loan_ID = getParentID(vars, strVM_Loan_Payment_ID);
     
      vars.setSessionValue(windowId + "|VM_Vehicle_Loan_ID", strPVM_Vehicle_Loan_ID);
      vars.setSessionValue("0DA2897DFEB24D65A74047EA0E0CDF29|Loan.view", "EDIT");
      vars.removeSessionValue(windowId + "|VM_Vehicle_Info_ID");
      refreshParentSession(vars, strPVM_Vehicle_Loan_ID);

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

      printPageEdit(response, request, vars, false, strVM_Loan_Payment_ID, strPVM_Vehicle_Loan_ID, tableSQL);

    } else if (vars.commandIn("TAB")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID", false, false, true, "");
      vars.removeSessionValue(windowId + "|VM_Loan_Payment_ID");
      refreshParentSession(vars, strPVM_Vehicle_Loan_ID);


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

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

      } else printPageDataSheet(response, vars, strPVM_Vehicle_Loan_ID, "", tableSQL);

    } else if (vars.commandIn("RELATION")) {
            String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");
     

      String strVM_Loan_Payment_ID = vars.getGlobalVariable("inpvmLoanPaymentId", windowId + "|VM_Loan_Payment_ID", "");
      vars.setSessionValue(tabId + "|Payment.view", "RELATION");
      printPageDataSheet(response, vars, strPVM_Vehicle_Loan_ID, strVM_Loan_Payment_ID, tableSQL);
    } else if (vars.commandIn("NEW")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");


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

    } else if (vars.commandIn("EDIT")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");

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

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

    } else if (vars.commandIn("NEXT")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");
      String strVM_Loan_Payment_ID = vars.getRequiredStringParameter("inpvmLoanPaymentId");
     
      String strNext = nextElement(vars, strVM_Loan_Payment_ID, tableSQL);

      printPageEdit(response, request, vars, false, strNext, strPVM_Vehicle_Loan_ID, tableSQL);
    } else if (vars.commandIn("PREVIOUS")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");
      String strVM_Loan_Payment_ID = vars.getRequiredStringParameter("inpvmLoanPaymentId");
     
      String strPrevious = previousElement(vars, strVM_Loan_Payment_ID, tableSQL);

      printPageEdit(response, request, vars, false, strPrevious, strPVM_Vehicle_Loan_ID, tableSQL);
    } else if (vars.commandIn("FIRST_RELATION")) {
vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");

      vars.setSessionValue(tabId + "|Payment.initRecordNumber", "0");
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("PREVIOUS_RELATION")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Payment.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 + "|Payment.initRecordNumber", "0");
      } else {
        int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
        initRecord -= intRecordRange;
        strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
        vars.setSessionValue(tabId + "|Payment.initRecordNumber", strInitRecord);
      }
      vars.removeSessionValue(windowId + "|VM_Loan_Payment_ID");
      vars.setSessionValue(windowId + "|VM_Vehicle_Loan_ID", strPVM_Vehicle_Loan_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("NEXT_RELATION")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");

      String strInitRecord = vars.getSessionValue(tabId + "|Payment.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 + "|Payment.initRecordNumber", strInitRecord);
      vars.removeSessionValue(windowId + "|VM_Loan_Payment_ID");
      vars.setSessionValue(windowId + "|VM_Vehicle_Loan_ID", strPVM_Vehicle_Loan_ID);
      response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
    } else if (vars.commandIn("FIRST")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");
     
      String strFirst = firstElement(vars, tableSQL);

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

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

      printPageEdit(response, request, vars, false, strLast, strPVM_Vehicle_Loan_ID, tableSQL);
    } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");
      OBError myError = new OBError();     
      int total = saveRecord(vars, myError, 'I', strPVM_Vehicle_Loan_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 strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");
      String strVM_Loan_Payment_ID = vars.getRequiredGlobalVariable("inpvmLoanPaymentId", windowId + "|VM_Loan_Payment_ID");
      OBError myError = new OBError();
      int total = saveRecord(vars, myError, 'U', strPVM_Vehicle_Loan_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, strVM_Loan_Payment_ID, tableSQL);
          vars.setSessionValue(windowId + "|VM_Loan_Payment_ID", strNext);
          response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
        } else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
      }
/*    } else if (vars.commandIn("DELETE_RELATION")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");

      String strVM_Loan_Payment_ID = vars.getRequiredInStringParameter("inpvmLoanPaymentId");
      String message = deleteRelation(vars, strVM_Loan_Payment_ID, strPVM_Vehicle_Loan_ID);
      if (!message.equals("")) {
        bdError(request, response, message, vars.getLanguage());
      } else {
        vars.removeSessionValue(windowId + "|vmLoanPaymentId");
        vars.setSessionValue(tabId + "|Payment.view", "RELATION");
        response.sendRedirect(strDireccion + request.getServletPath());
      }*/
    } else if (vars.commandIn("DELETE")) {
      String strPVM_Vehicle_Loan_ID = vars.getGlobalVariable("inpvmVehicleLoanId", windowId + "|VM_Vehicle_Loan_ID");

      String strVM_Loan_Payment_ID = vars.getRequiredStringParameter("inpvmLoanPaymentId");
      //PaymentData data = getEditVariables(vars, strPVM_Vehicle_Loan_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 = PaymentData.delete(this, strVM_Loan_Payment_ID, strPVM_Vehicle_Loan_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 + "|vmLoanPaymentId");
        vars.setSessionValue(tabId + "|Payment.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.commandIn("BUTTONProcessedB8E65C2B0C2142BF8F8E238CBF20B0D6")) {
        vars.setSessionValue("buttonB8E65C2B0C2142BF8F8E238CBF20B0D6.strprocessed", vars.getStringParameter("inpprocessed"));
        vars.setSessionValue("buttonB8E65C2B0C2142BF8F8E238CBF20B0D6.strProcessing", vars.getStringParameter("inpprocessing", "Y"));
        vars.setSessionValue("buttonB8E65C2B0C2142BF8F8E238CBF20B0D6.strOrg", vars.getStringParameter("inpadOrgId"));
        vars.setSessionValue("buttonB8E65C2B0C2142BF8F8E238CBF20B0D6.strClient", vars.getStringParameter("inpadClientId"));
       
       
        HashMap<String, String> p = new HashMap<String, String>();
       
       
        //Save in session needed params for combos if needed
        vars.setSessionObject("buttonB8E65C2B0C2142BF8F8E238CBF20B0D6.originalParams", FieldProviderFactory.getFieldProvider(p));
        printPageButtonFS(response, vars, "B8E65C2B0C2142BF8F8E238CBF20B0D6", request.getServletPath());   
     } else if (vars.commandIn("BUTTONB8E65C2B0C2142BF8F8E238CBF20B0D6")) {
        String strVM_Loan_Payment_ID = vars.getGlobalVariable("inpvmLoanPaymentId", windowId + "|VM_Loan_Payment_ID", "");
        String strprocessed = vars.getSessionValue("buttonB8E65C2B0C2142BF8F8E238CBF20B0D6.strprocessed");
        String strProcessing = vars.getSessionValue("buttonB8E65C2B0C2142BF8F8E238CBF20B0D6.strProcessing");
        String strOrg = vars.getSessionValue("buttonB8E65C2B0C2142BF8F8E238CBF20B0D6.strOrg");
        String strClient = vars.getSessionValue("buttonB8E65C2B0C2142BF8F8E238CBF20B0D6.strClient");
       
       
        if ((org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) || !(Utility.isElementInList(Utility.getContext(this, vars, "#User_Client", windowId, accesslevel),strClient&& Utility.isElementInList(Utility.getContext(this, vars, "#User_Org", windowId, accesslevel),strOrg))){
          OBError myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
          printPageClosePopUp(response, vars);
        }else{      
          printPageButtonProcessedB8E65C2B0C2142BF8F8E238CBF20B0D6(response, vars, strVM_Loan_Payment_ID, strprocessed, strProcessing);
        }


    } else if (vars.commandIn("SAVE_BUTTONProcessedB8E65C2B0C2142BF8F8E238CBF20B0D6")) {
        String strVM_Loan_Payment_ID = vars.getGlobalVariable("inpKey", windowId + "|VM_Loan_Payment_ID", "");
        @SuppressWarnings("unused")
        String strprocessed = vars.getStringParameter("inpprocessed");
        String strProcessing = vars.getStringParameter("inpprocessing");
        OBError myMessage = null;
        try {
          String pinstance = SequenceIdData.getUUID();
          PInstanceProcessData.insertPInstance(this, pinstance, "B8E65C2B0C2142BF8F8E238CBF20B0D6", (("VM_Loan_Payment_ID".equalsIgnoreCase("AD_Language"))?"0":strVM_Loan_Payment_ID), strProcessing, vars.getUser(), vars.getClient(), vars.getOrg());
         
         
          ProcessBundle bundle = ProcessBundle.pinstance(pinstance, vars, this);
          new ProcessRunner(bundle).execute(this);
         
          PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(this, pinstance);
          myMessage = Utility.getProcessInstanceMessage(this, vars, pinstanceData);
        } catch (ServletException ex) {
          myMessage = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
          if (!myMessage.isConnectionAvailable()) {
            bdErrorConnection(response);
            return;
          } else vars.setMessage(tabId, myMessage);
        }
        //close popup
        if (myMessage!=null) {
          if (log4j.isDebugEnabled()) log4j.debug(myMessage.getMessage());
          vars.setMessage(tabId, myMessage);
        }
        printPageClosePopUp(response, vars);



    } else if (vars.commandIn("BUTTONPosted")) {
        String strVM_Loan_Payment_ID = vars.getGlobalVariable("inpvmLoanPaymentId", windowId + "|VM_Loan_Payment_ID", "");
        String strTableId = "6FEA143F187247E8A914EB99264BFF44";
        String strPosted = vars.getStringParameter("inpposted");
        String strProcessId = "";
        log4j.debug("Loading Posted button in table: " + strTableId);
        String strOrg = vars.getStringParameter("inpadOrgId");
        String strClient = vars.getStringParameter("inpadClientId");
        if ((org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) || !(Utility.isElementInList(Utility.getContext(this, vars, "#User_Client", windowId, accesslevel),strClient&& Utility.isElementInList(Utility.getContext(this, vars, "#User_Org", windowId, accesslevel),strOrg))){
          OBError myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
          vars.setMessage(tabId, myError);
          printPageClosePopUp(response, vars);
        }else{
          vars.setSessionValue("Posted|key", strVM_Loan_Payment_ID);
          vars.setSessionValue("Posted|tableId", strTableId);
          vars.setSessionValue("Posted|tabId", tabId);
          vars.setSessionValue("Posted|posted", strPosted);
          vars.setSessionValue("Posted|processId", strProcessId);
          vars.setSessionValue("Posted|path", strDireccion + request.getServletPath());
          vars.setSessionValue("Posted|windowId", windowId);
          vars.setSessionValue("Posted|tabName", "Payment");
          response.sendRedirect(strDireccion + "/ad_actionButton/Posted.html");
        }



    } 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 strBPartnerId = vars.getStringParameter("inpcBpartnerId");
      String strProjectId = vars.getStringParameter("inpcProjectId");
      String strChanged = vars.getStringParameter("inpLastFieldChanged");
      String strWindowId = vars.getStringParameter("inpwindowId");
      String strTabId = vars.getStringParameter("inpTabId");

      try {
        printPage(response, vars, strBPartnerId, strProjectId, strChanged, strTabId, strWindowId);
      } catch (ServletException ex) {
        pageErrorCallOut(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.