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 strmaCostcenterEmployeeId = request.getParameter("inpmaCostcenterEmployeeId");
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
if (editableTab) {
int total = 0;
if(commandType.equalsIgnoreCase("EDIT") && !strmaCostcenterEmployeeId.equals(""))
total = saveRecord(vars, myError, 'U', strPMA_Costcenter_Version_ID);
else
total = saveRecord(vars, myError, 'I', strPMA_Costcenter_Version_ID);
if (!myError.isEmpty() && total == 0)
throw new OBException(myError.getMessage());
}
vars.setSessionValue(request.getParameter("mappingName") +"|hash", vars.getPostDataHash());
vars.setSessionValue(tabId + "|Header.view", "EDIT");
return;
}
try {
tableSQL = new TableSQLData(vars, this, tabId, Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel), Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
} catch (Exception ex) {
ex.printStackTrace();
}
String strOrderBy = vars.getSessionValue(tabId + "|orderby");
if (!strOrderBy.equals("")) {
vars.setSessionValue(tabId + "|newOrder", "1");
}
if (vars.commandIn("DEFAULT")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID", "");
String strMA_Costcenter_Employee_ID = vars.getGlobalVariable("inpmaCostcenterEmployeeId", windowId + "|MA_Costcenter_Employee_ID", "");
if (strPMA_Costcenter_Version_ID.equals("")) {
strPMA_Costcenter_Version_ID = getParentID(vars, strMA_Costcenter_Employee_ID);
if (strPMA_Costcenter_Version_ID.equals("")) throw new ServletException("Required parameter :" + windowId + "|MA_Costcenter_Version_ID");
vars.setSessionValue(windowId + "|MA_Costcenter_Version_ID", strPMA_Costcenter_Version_ID);
vars.removeSessionValue(windowId + "|MA_Costcenter_ID");
refreshParentSession(vars, strPMA_Costcenter_Version_ID);
}
String strView = vars.getSessionValue(tabId + "|Employee.view");
if (strView.equals("")) {
strView = defaultTabView;
if (strView.equals("EDIT")) {
if (strMA_Costcenter_Employee_ID.equals("")) strMA_Costcenter_Employee_ID = firstElement(vars, tableSQL);
if (strMA_Costcenter_Employee_ID.equals("")) strView = "RELATION";
}
}
if (strView.equals("EDIT"))
printPageEdit(response, request, vars, false, strMA_Costcenter_Employee_ID, strPMA_Costcenter_Version_ID, tableSQL);
else printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, strMA_Costcenter_Employee_ID, tableSQL);
} else if (vars.commandIn("DIRECT")) {
String strMA_Costcenter_Employee_ID = vars.getStringParameter("inpDirectKey");
if (strMA_Costcenter_Employee_ID.equals("")) strMA_Costcenter_Employee_ID = vars.getRequiredGlobalVariable("inpmaCostcenterEmployeeId", windowId + "|MA_Costcenter_Employee_ID");
else vars.setSessionValue(windowId + "|MA_Costcenter_Employee_ID", strMA_Costcenter_Employee_ID);
String strPMA_Costcenter_Version_ID = getParentID(vars, strMA_Costcenter_Employee_ID);
vars.setSessionValue(windowId + "|MA_Costcenter_Version_ID", strPMA_Costcenter_Version_ID);
vars.setSessionValue("800234|Version.view", "EDIT");
vars.removeSessionValue(windowId + "|MA_Costcenter_ID");
refreshParentSession(vars, strPMA_Costcenter_Version_ID);
vars.setSessionValue(tabId + "|Employee.view", "EDIT");
printPageEdit(response, request, vars, false, strMA_Costcenter_Employee_ID, strPMA_Costcenter_Version_ID, tableSQL);
} else if (vars.commandIn("TAB")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID", false, false, true, "");
vars.removeSessionValue(windowId + "|MA_Costcenter_Employee_ID");
refreshParentSession(vars, strPMA_Costcenter_Version_ID);
String strView = vars.getSessionValue(tabId + "|Employee.view");
String strMA_Costcenter_Employee_ID = "";
if (strView.equals("")) {
strView = defaultTabView;
if (strView.equals("EDIT")) {
strMA_Costcenter_Employee_ID = firstElement(vars, tableSQL);
if (strMA_Costcenter_Employee_ID.equals("")) strView = "RELATION";
}
}
if (strView.equals("EDIT")) {
if (strMA_Costcenter_Employee_ID.equals("")) strMA_Costcenter_Employee_ID = firstElement(vars, tableSQL);
printPageEdit(response, request, vars, false, strMA_Costcenter_Employee_ID, strPMA_Costcenter_Version_ID, tableSQL);
} else printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, "", tableSQL);
} else if (vars.commandIn("SEARCH")) {
vars.getRequestGlobalVariable("inpParamMA_Costcenter_Version_ID", tabId + "|paramMA_Costcenter_Version_ID");
vars.getRequestGlobalVariable("inpParamC_Salary_Category_ID", tabId + "|paramC_Salary_Category_ID");
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
vars.removeSessionValue(windowId + "|MA_Costcenter_Employee_ID");
String strMA_Costcenter_Employee_ID="";
String strView = vars.getSessionValue(tabId + "|Employee.view");
if (strView.equals("")) strView=defaultTabView;
if (strView.equals("EDIT")) {
strMA_Costcenter_Employee_ID = firstElement(vars, tableSQL);
if (strMA_Costcenter_Employee_ID.equals("")) {
// filter returns empty set
strView = "RELATION";
// switch to grid permanently until the user changes the view again
vars.setSessionValue(tabId + "|Employee.view", strView);
}
}
if (strView.equals("EDIT"))
printPageEdit(response, request, vars, false, strMA_Costcenter_Employee_ID, strPMA_Costcenter_Version_ID, tableSQL);
else printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, strMA_Costcenter_Employee_ID, tableSQL);
} else if (vars.commandIn("RELATION")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strMA_Costcenter_Employee_ID = vars.getGlobalVariable("inpmaCostcenterEmployeeId", windowId + "|MA_Costcenter_Employee_ID", "");
vars.setSessionValue(tabId + "|Employee.view", "RELATION");
printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, strMA_Costcenter_Employee_ID, tableSQL);
} else if (vars.commandIn("NEW")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
printPageEdit(response, request, vars, true, "", strPMA_Costcenter_Version_ID, tableSQL);
} else if (vars.commandIn("EDIT")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
@SuppressWarnings("unused") // In Expense Invoice tab this variable is not used, to be fixed
String strMA_Costcenter_Employee_ID = vars.getGlobalVariable("inpmaCostcenterEmployeeId", windowId + "|MA_Costcenter_Employee_ID", "");
vars.setSessionValue(tabId + "|Employee.view", "EDIT");
setHistoryCommand(request, "EDIT");
printPageEdit(response, request, vars, false, strMA_Costcenter_Employee_ID, strPMA_Costcenter_Version_ID, tableSQL);
} else if (vars.commandIn("NEXT")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strMA_Costcenter_Employee_ID = vars.getRequiredStringParameter("inpmaCostcenterEmployeeId");
String strNext = nextElement(vars, strMA_Costcenter_Employee_ID, tableSQL);
printPageEdit(response, request, vars, false, strNext, strPMA_Costcenter_Version_ID, tableSQL);
} else if (vars.commandIn("PREVIOUS")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strMA_Costcenter_Employee_ID = vars.getRequiredStringParameter("inpmaCostcenterEmployeeId");
String strPrevious = previousElement(vars, strMA_Costcenter_Employee_ID, tableSQL);
printPageEdit(response, request, vars, false, strPrevious, strPMA_Costcenter_Version_ID, tableSQL);
} else if (vars.commandIn("FIRST_RELATION")) {
vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
vars.setSessionValue(tabId + "|Employee.initRecordNumber", "0");
response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
} else if (vars.commandIn("PREVIOUS_RELATION")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strInitRecord = vars.getSessionValue(tabId + "|Employee.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 + "|Employee.initRecordNumber", "0");
} else {
int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
initRecord -= intRecordRange;
strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
vars.setSessionValue(tabId + "|Employee.initRecordNumber", strInitRecord);
}
vars.removeSessionValue(windowId + "|MA_Costcenter_Employee_ID");
vars.setSessionValue(windowId + "|MA_Costcenter_Version_ID", strPMA_Costcenter_Version_ID);
response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
} else if (vars.commandIn("NEXT_RELATION")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strInitRecord = vars.getSessionValue(tabId + "|Employee.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 + "|Employee.initRecordNumber", strInitRecord);
vars.removeSessionValue(windowId + "|MA_Costcenter_Employee_ID");
vars.setSessionValue(windowId + "|MA_Costcenter_Version_ID", strPMA_Costcenter_Version_ID);
response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
} else if (vars.commandIn("FIRST")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strFirst = firstElement(vars, tableSQL);
printPageEdit(response, request, vars, false, strFirst, strPMA_Costcenter_Version_ID, tableSQL);
} else if (vars.commandIn("LAST_RELATION")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strLast = lastElement(vars, tableSQL);
printPageDataSheet(response, vars, strPMA_Costcenter_Version_ID, strLast, tableSQL);
} else if (vars.commandIn("LAST")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strLast = lastElement(vars, tableSQL);
printPageEdit(response, request, vars, false, strLast, strPMA_Costcenter_Version_ID, tableSQL);
} else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
OBError myError = new OBError();
int total = saveRecord(vars, myError, 'I', strPMA_Costcenter_Version_ID);
if (!myError.isEmpty()) {
response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
}
else {
if (myError.isEmpty()) {
myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsInserted");
myError.setMessage(total + " " + myError.getMessage());
vars.setMessage(tabId, myError);
}
if (vars.commandIn("SAVE_NEW_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
else if (vars.commandIn("SAVE_NEW_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
}
} else if (vars.commandIn("SAVE_EDIT_RELATION", "SAVE_EDIT_NEW", "SAVE_EDIT_EDIT", "SAVE_EDIT_NEXT")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strMA_Costcenter_Employee_ID = vars.getRequiredGlobalVariable("inpmaCostcenterEmployeeId", windowId + "|MA_Costcenter_Employee_ID");
OBError myError = new OBError();
int total = saveRecord(vars, myError, 'U', strPMA_Costcenter_Version_ID);
if (!myError.isEmpty()) {
response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
}
else {
if (myError.isEmpty()) {
myError = Utility.translateError(this, vars, vars.getLanguage(), "@CODE=RowsUpdated");
myError.setMessage(total + " " + myError.getMessage());
vars.setMessage(tabId, myError);
}
if (vars.commandIn("SAVE_EDIT_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
else if (vars.commandIn("SAVE_EDIT_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
else if (vars.commandIn("SAVE_EDIT_NEXT")) {
String strNext = nextElement(vars, strMA_Costcenter_Employee_ID, tableSQL);
vars.setSessionValue(windowId + "|MA_Costcenter_Employee_ID", strNext);
response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
} else response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
}
/* } else if (vars.commandIn("DELETE_RELATION")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strMA_Costcenter_Employee_ID = vars.getRequiredInStringParameter("inpmaCostcenterEmployeeId");
String message = deleteRelation(vars, strMA_Costcenter_Employee_ID, strPMA_Costcenter_Version_ID);
if (!message.equals("")) {
bdError(request, response, message, vars.getLanguage());
} else {
vars.removeSessionValue(windowId + "|maCostcenterEmployeeId");
vars.setSessionValue(tabId + "|Employee.view", "RELATION");
response.sendRedirect(strDireccion + request.getServletPath());
}*/
} else if (vars.commandIn("DELETE")) {
String strPMA_Costcenter_Version_ID = vars.getGlobalVariable("inpmaCostcenterVersionId", windowId + "|MA_Costcenter_Version_ID");
String strMA_Costcenter_Employee_ID = vars.getRequiredStringParameter("inpmaCostcenterEmployeeId");
//EmployeeData data = getEditVariables(vars, strPMA_Costcenter_Version_ID);
int total = 0;
OBError myError = null;
if (org.openbravo.erpCommon.utility.WindowAccessData.hasReadOnlyAccess(this, vars.getRole(), tabId)) {
myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
vars.setMessage(tabId, myError);
} else {
try {
total = EmployeeData.delete(this, strMA_Costcenter_Employee_ID, strPMA_Costcenter_Version_ID, Utility.getContext(this, vars, "#User_Client", windowId, accesslevel), Utility.getContext(this, vars, "#User_Org", windowId, accesslevel));
} catch(ServletException ex) {
myError = Utility.translateError(this, vars, vars.getLanguage(), ex.getMessage());
if (!myError.isConnectionAvailable()) {
bdErrorConnection(response);
return;
} else vars.setMessage(tabId, myError);
}
if (myError==null && total==0) {
myError = Utility.translateError(this, vars, vars.getLanguage(), Utility.messageBD(this, "NoWriteAccess", vars.getLanguage()));
vars.setMessage(tabId, myError);
}
vars.removeSessionValue(windowId + "|maCostcenterEmployeeId");
vars.setSessionValue(tabId + "|Employee.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);
}