String strCommand = null;
AssetsData[] data=null;
XmlDocument xmlDocument=null;
FieldProvider dataField = vars.getEditionData(tabId);
vars.removeEditionData(tabId);
String strParamValue = vars.getSessionValue(tabId + "|paramValue");
String strParamA_Asset_Group_ID = vars.getSessionValue(tabId + "|paramA_Asset_Group_ID");
boolean hasSearchCondition=false;
if (!(strParamValue.equals("") && strParamA_Asset_Group_ID.equals(""))) hasSearchCondition=true;
String strParamSessionDate = vars.getGlobalVariable("inpParamSessionDate", Utility.getTransactionalDate(this, vars, windowId), "");
String buscador = "";
String[] discard = {"", "isNotTest"};
if (vars.getSessionValue("#ShowTest", "N").equals("Y")) discard[1] = new String("isTest");
if (dataField==null) {
if (!boolNew) {
discard[0] = new String("newDiscard");
data = AssetsData.selectEdit(this, vars.getSessionValue("#AD_SqlDateTimeFormat"), vars.getLanguage(), strA_Asset_ID, Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel));
if (!strA_Asset_ID.equals("") && (data == null || data.length==0)) {
response.sendRedirect(strDireccion + request.getServletPath() + "?Command=RELATION");
return;
}
refreshSessionEdit(vars, data);
strCommand = "EDIT";
}
if (boolNew || data==null || data.length==0) {
discard[0] = new String ("editDiscard");
strCommand = "NEW";
data = new AssetsData[0];
} else {
discard[0] = new String ("newDiscard");
}
} else {
if (dataField.getField("aAssetId") == null || dataField.getField("aAssetId").equals("")) {
discard[0] = new String ("editDiscard");
strCommand = "NEW";
boolNew = true;
} else {
discard[0] = new String ("newDiscard");
strCommand = "EDIT";
}
}
if (dataField==null) {
if (boolNew || data==null || data.length==0) {
refreshSessionNew(vars);
data = AssetsData.set(Utility.getDefault(this, vars, "Datepurchased", "", "800027", "", dataField), Utility.getDefault(this, vars, "Datecancelled", "", "800027", "", dataField), Utility.getDefault(this, vars, "Amortizationstartdate", "", "800027", "", dataField), Utility.getDefault(this, vars, "Amortizationenddate", "", "800027", "", dataField), Utility.getDefault(this, vars, "Annualamortizationpercentage", "", "800027", "", dataField), Utility.getDefault(this, vars, "C_Currency_ID", "@C_Currency_ID@", "800027", "", dataField), Utility.getDefault(this, vars, "AssetValueAmt", "", "800027", "", dataField), Utility.getDefault(this, vars, "Residualassetvalueamt", "", "800027", "", dataField), Utility.getDefault(this, vars, "M_AttributeSetInstance_ID", "", "800027", "", dataField), AssetsData.selectDef801068_0(this, Utility.getDefault(this, vars, "M_AttributeSetInstance_ID", "", "800027", "", dataField)), Utility.getDefault(this, vars, "Acctvalueamt", "", "800027", "", dataField), Utility.getDefault(this, vars, "Amortizationtype", "", "800027", "", dataField), Utility.getDefault(this, vars, "Amortizationvalueamt", "", "800027", "", dataField), Utility.getDefault(this, vars, "Assetschedule", "", "800027", "", dataField), Utility.getDefault(this, vars, "DocumentNo", "", "800027", "", dataField), Utility.getDefault(this, vars, "Processed", "N", "800027", "N", dataField), (vars.getLanguage().equals("en_US")?ListData.selectName(this, "800042", Utility.getDefault(this, vars, "Processed", "N", "800027", "N", dataField)):ListData.selectNameTrl(this, vars.getLanguage(), "800042", Utility.getDefault(this, vars, "Processed", "N", "800027", "N", dataField))), Utility.getDefault(this, vars, "Profit", "", "800027", "", dataField), Utility.getDefault(this, vars, "Qty", "", "800027", "", dataField), Utility.getDefault(this, vars, "Depreciatedvalue", "0", "800027", "", dataField), Utility.getDefault(this, vars, "Depreciatedplan", "0", "800027", "", dataField), Utility.getDefault(this, vars, "Amortizationcalctype", "", "800027", "", dataField), Utility.getDefault(this, vars, "Depreciatedpreviousamt", "0", "800027", "", dataField), Utility.getDefault(this, vars, "Lot", "", "800027", "", dataField), Utility.getDefault(this, vars, "AD_User_ID", "", "800027", "", dataField), Utility.getDefault(this, vars, "IsDisposed", "", "800027", "N", dataField), Utility.getDefault(this, vars, "M_Locator_ID", "", "800027", "", dataField), Utility.getDefault(this, vars, "IsInPosession", "", "800027", "N", dataField), "Y", Utility.getDefault(this, vars, "AssetDepreciationDate", "", "800027", "", dataField), Utility.getDefault(this, vars, "CreatedBy", "", "800027", "", dataField), AssetsData.selectDef8045_1(this, Utility.getDefault(this, vars, "CreatedBy", "", "800027", "", dataField)), Utility.getDefault(this, vars, "UseLifeYears", "", "800027", "", dataField), Utility.getDefault(this, vars, "M_Product_ID", "", "800027", "", dataField), AssetsData.selectDef8047_2(this, Utility.getDefault(this, vars, "M_Product_ID", "", "800027", "", dataField)), Utility.getDefault(this, vars, "AssetDisposalDate", "", "800027", "", dataField), Utility.getDefault(this, vars, "C_Location_ID", "", "800027", "", dataField), Utility.getDefault(this, vars, "A_Asset_Group_ID", "", "800027", "", dataField), Utility.getDefault(this, vars, "AD_Org_ID", "@AD_Org_ID@", "800027", "", dataField), Utility.getDefault(this, vars, "VersionNo", "", "800027", "", dataField), Utility.getDefault(this, vars, "Value", "", "800027", "", dataField), Utility.getDefault(this, vars, "IsOwned", "", "800027", "N", dataField), Utility.getDefault(this, vars, "Name", "", "800027", "", dataField), Utility.getDefault(this, vars, "Description", "", "800027", "", dataField), Utility.getDefault(this, vars, "LocationComment", "", "800027", "", dataField), Utility.getDefault(this, vars, "IsDepreciated", "", "800027", "N", dataField), Utility.getDefault(this, vars, "LifeUseUnits", "", "800027", "", dataField), Utility.getDefault(this, vars, "Help", "", "800027", "", dataField), Utility.getDefault(this, vars, "UpdatedBy", "", "800027", "", dataField), AssetsData.selectDef8063_3(this, Utility.getDefault(this, vars, "UpdatedBy", "", "800027", "", dataField)), Utility.getDefault(this, vars, "AD_Client_ID", "@AD_CLIENT_ID@", "800027", "", dataField), Utility.getDefault(this, vars, "C_BPartner_ID", "", "800027", "", dataField), Utility.getDefault(this, vars, "GuaranteeDate", "", "800027", "", dataField), Utility.getDefault(this, vars, "UseLifeMonths", "", "800027", "", dataField), Utility.getDefault(this, vars, "AssetServiceDate", "", "800027", "", dataField), Utility.getDefault(this, vars, "UseUnits", "", "800027", "", dataField), "", Utility.getDefault(this, vars, "SerNo", "", "800027", "", dataField), Utility.getDefault(this, vars, "C_BPartner_Location_ID", "", "800027", "", dataField), Utility.getDefault(this, vars, "IsFullyDepreciated", "N", "800027", "N", dataField));
data[0].documentno = "<" + Utility.getDocumentNo( this, vars, windowId, "A_Asset", "", "", false, false) + ">";
}
}
String currentOrg = (boolNew?"":(dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId")));
if (!currentOrg.equals("") && !currentOrg.startsWith("'")) currentOrg = "'"+currentOrg+"'";
String currentClient = (boolNew?"":(dataField!=null?dataField.getField("adClientId"):data[0].getField("adClientId")));
if (!currentClient.equals("") && !currentClient.startsWith("'")) currentClient = "'"+currentClient+"'";
boolean 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)));
if (editableTab)
xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpWindows/Assets/Assets_Edition",discard).createXmlDocument();
else
xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpWindows/Assets/Assets_NonEditable",discard).createXmlDocument();
xmlDocument.setParameter("tabId", tabId);
ToolBar toolbar = new ToolBar(this, editableTab, vars.getLanguage(), "Assets", (strCommand.equals("NEW") || boolNew || (dataField==null && (data==null || data.length==0))), "document.frmMain.inpaAssetId", "", "..", "".equals("Y"), "Assets", strReplaceWith, true, false, false, Utility.hasTabAttachments(this, vars, tabId, strA_Asset_ID));
toolbar.prepareEditionTemplate("N".equals("Y"), hasSearchCondition, vars.getSessionValue("#ShowTest", "N").equals("Y"), "STD", Utility.getContext(this, vars, "ShowAudit", windowId).equals("Y"));
xmlDocument.setParameter("toolbar", toolbar.toString());
try {
WindowTabs tabs = new WindowTabs(this, vars, tabId, windowId, true, (strCommand.equalsIgnoreCase("NEW")));
xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
// if (!strA_Asset_ID.equals("")) xmlDocument.setParameter("childTabContainer", tabs.childTabs(false));
// else xmlDocument.setParameter("childTabContainer", tabs.childTabs(true));
xmlDocument.setParameter("childTabContainer", tabs.childTabs(false));
NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "Assets_Relation.html", "Assets", "W", strReplaceWith, tabs.breadcrumb());
xmlDocument.setParameter("navigationBar", nav.toString());
LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "Assets_Relation.html", strReplaceWith);
xmlDocument.setParameter("leftTabs", lBar.editionTemplate(strCommand.equals("NEW")));
} catch (Exception ex) {
throw new ServletException(ex);
}
xmlDocument.setParameter("commandType", strCommand);
xmlDocument.setParameter("buscador",buscador);
xmlDocument.setParameter("windowId", windowId);
xmlDocument.setParameter("changed", "");
xmlDocument.setParameter("language", "defaultLang=\"" + vars.getLanguage() + "\";");
xmlDocument.setParameter("theme", vars.getTheme());
final String strMappingName = UtilityData.selectObjectMapping(this, tabId);
xmlDocument.setParameter("mappingName", strMappingName);
xmlDocument.setParameter("confirmOnChanges", Utility.getJSConfirmOnChanges(vars, windowId));
//xmlDocument.setParameter("buttonReference", Utility.messageBD(this, "Reference", vars.getLanguage()));
xmlDocument.setParameter("paramSessionDate", strParamSessionDate);
xmlDocument.setParameter("directory", "var baseDirectory = \"" + strReplaceWith + "/\";\n");
OBError myMessage = vars.getMessage(tabId);
vars.removeMessage(tabId);
if (myMessage!=null) {
xmlDocument.setParameter("messageType", myMessage.getType());
xmlDocument.setParameter("messageTitle", myMessage.getTitle());
xmlDocument.setParameter("messageMessage", myMessage.getMessage());
}
xmlDocument.setParameter("displayLogic", getDisplayLogicContext(vars, boolNew));
if (dataField==null) {
xmlDocument.setData("structure1",data);
} else {
FieldProvider[] dataAux = new FieldProvider[1];
dataAux[0] = dataField;
xmlDocument.setData("structure1",dataAux);
}
try {
ComboTableData comboTableData = null;
String userClientList = "";
if (editableTab)
userClientList=Utility.getContext(this, vars, "#User_Client", windowId, accesslevel); //editable record
else
userClientList=currentClient;
comboTableData = new ComboTableData(vars, this, "19", "AD_Client_ID", "", "", null, userClientList, 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("adClientId"):dataField.getField("adClientId")));
xmlDocument.setData("reportAD_Client_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
String userOrgList = "";
if (editableTab)
userOrgList=Utility.getContext(this, vars, "#User_Org", windowId, accesslevel); //editable record
else
userOrgList=currentOrg;
comboTableData = new ComboTableData(vars, this, "19", "AD_Org_ID", "", "", userOrgList, Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("adOrgId"):dataField.getField("adOrgId")));
xmlDocument.setData("reportAD_Org_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
xmlDocument.setParameter("buttonQty", Utility.messageBD(this, "Calc", vars.getLanguage()));
comboTableData = new ComboTableData(vars, this, "19", "A_Asset_Group_ID", "", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("aAssetGroupId"):dataField.getField("aAssetGroupId")));
xmlDocument.setData("reportA_Asset_Group_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "17", "Amortizationtype", "800040", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("amortizationtype"):dataField.getField("amortizationtype")));
xmlDocument.setData("reportAmortizationtype","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "17", "Amortizationcalctype", "800068", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("amortizationcalctype"):dataField.getField("amortizationcalctype")));
xmlDocument.setData("reportAmortizationcalctype","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "17", "Assetschedule", "800041", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("assetschedule"):dataField.getField("assetschedule")));
xmlDocument.setData("reportAssetschedule","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
xmlDocument.setParameter("buttonAnnualamortizationpercentage", Utility.messageBD(this, "Calc", vars.getLanguage()));
comboTableData = new ComboTableData(vars, this, "19", "C_Currency_ID", "", "", Utility.getReferenceableOrg(vars, (dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId").equals("")?vars.getOrg():data[0].getField("adOrgId"))), Utility.getContext(this, vars, "#User_Client", windowId), 0);
Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField("cCurrencyId"):dataField.getField("cCurrencyId")));
xmlDocument.setData("reportC_Currency_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
xmlDocument.setParameter("Datepurchased_Format", vars.getSessionValue("#AD_SqlDateFormat"));
xmlDocument.setParameter("Datecancelled_Format", vars.getSessionValue("#AD_SqlDateFormat"));
xmlDocument.setParameter("Amortizationstartdate_Format", vars.getSessionValue("#AD_SqlDateFormat"));
xmlDocument.setParameter("Amortizationenddate_Format", vars.getSessionValue("#AD_SqlDateFormat"));
xmlDocument.setParameter("buttonAssetValueAmt", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonResidualassetvalueamt", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonAmortizationvalueamt", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonDepreciatedpreviousamt", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonDepreciatedvalue", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonDepreciatedplan", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("Processed_BTNname", Utility.getButtonName(this, vars, "800042", (dataField==null?data[0].getField("processed"):dataField.getField("processed")), "Processed_linkBTN", usedButtonShortCuts, reservedButtonShortCuts));
xmlDocument.setParameter("Created_Format", vars.getSessionValue("#AD_SqlDateTimeFormat"));xmlDocument.setParameter("Created_Maxlength", Integer.toString(vars.getSessionValue("#AD_SqlDateTimeFormat").length()));
xmlDocument.setParameter("Updated_Format", vars.getSessionValue("#AD_SqlDateTimeFormat"));xmlDocument.setParameter("Updated_Maxlength", Integer.toString(vars.getSessionValue("#AD_SqlDateTimeFormat").length()));
xmlDocument.setParameter("buttonAcctvalueamt", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("GuaranteeDate_Format", vars.getSessionValue("#AD_SqlDateFormat"));
xmlDocument.setParameter("AssetDisposalDate_Format", vars.getSessionValue("#AD_SqlDateFormat"));