String strCommand = null;
ImportProductData[] data=null;
XmlDocument xmlDocument=null;
FieldProvider dataField = vars.getEditionData(tabId);
vars.removeEditionData(tabId);
String strParamValue = vars.getSessionValue(tabId + "|paramValue");
boolean hasSearchCondition=false;
if (!(strParamValue.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 = ImportProductData.selectEdit(this, vars.getSessionValue("#AD_SqlDateTimeFormat"), vars.getLanguage(), strI_Product_ID, Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "#AccessibleOrgTree", windowId, accesslevel));
if (!strI_Product_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 ImportProductData[0];
} else {
discard[0] = new String ("newDiscard");
}
} else {
if (dataField.getField("iProductId") == null || dataField.getField("iProductId").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 = ImportProductData.set(Utility.getDefault(this, vars, "AD_Client_ID", "@AD_CLIENT_ID@", "247", "", dataField), Utility.getDefault(this, vars, "ISO_Code", "", "247", "", dataField), Utility.getDefault(this, vars, "DocumentNote", "", "247", "", dataField), Utility.getDefault(this, vars, "VendorProductNo", "", "247", "", dataField), Utility.getDefault(this, vars, "Name", "", "247", "", dataField), "", Utility.getDefault(this, vars, "UpdatedBy", "", "247", "", dataField), ImportProductData.selectDef7821_0(this, Utility.getDefault(this, vars, "UpdatedBy", "", "247", "", dataField)), Utility.getDefault(this, vars, "PriceEffective", "", "247", "", dataField), "Y", Utility.getDefault(this, vars, "Processed", "", "247", "N", dataField), Utility.getDefault(this, vars, "ProductCategory_Value", "", "247", "", dataField), Utility.getDefault(this, vars, "I_ErrorMsg", "", "247", "", dataField), Utility.getDefault(this, vars, "Order_Pack", "", "247", "", dataField), Utility.getDefault(this, vars, "Classification", "", "247", "", dataField), Utility.getDefault(this, vars, "DeliveryTime_Promised", "", "247", "", dataField), Utility.getDefault(this, vars, "CostPerOrder", "", "247", "", dataField), Utility.getDefault(this, vars, "Weight", "", "247", "", dataField), Utility.getDefault(this, vars, "VendorCategory", "", "247", "", dataField), Utility.getDefault(this, vars, "SKU", "", "247", "", dataField), Utility.getDefault(this, vars, "RoyaltyAmt", "", "247", "", dataField), Utility.getDefault(this, vars, "Discontinued", "", "247", "N", dataField), Utility.getDefault(this, vars, "C_Currency_ID", "", "247", "", dataField), Utility.getDefault(this, vars, "CreatedBy", "", "247", "", dataField), ImportProductData.selectDef7838_1(this, Utility.getDefault(this, vars, "CreatedBy", "", "247", "", dataField)), Utility.getDefault(this, vars, "Volume", "", "247", "", dataField), Utility.getDefault(this, vars, "AD_Org_ID", "@AD_Org_ID@", "247", "", dataField), Utility.getDefault(this, vars, "M_Product_ID", "", "247", "", dataField), Utility.getDefault(this, vars, "Description", "", "247", "", dataField), Utility.getDefault(this, vars, "PriceList", "", "247", "", dataField), Utility.getDefault(this, vars, "I_IsImported", "", "247", "N", dataField), Utility.getDefault(this, vars, "ProductType", "I", "247", "", dataField), Utility.getDefault(this, vars, "C_BPartner_ID", "", "247", "", dataField), ImportProductData.selectDef7846_2(this, Utility.getDefault(this, vars, "C_BPartner_ID", "", "247", "", dataField)), Utility.getDefault(this, vars, "BPartner_Value", "", "247", "", dataField), Utility.getDefault(this, vars, "ShelfHeight", "", "247", "", dataField), Utility.getDefault(this, vars, "Manufacturer", "", "247", "", dataField), Utility.getDefault(this, vars, "ShelfDepth", "", "247", "", dataField), Utility.getDefault(this, vars, "DiscontinuedBy", "", "247", "", dataField), Utility.getDefault(this, vars, "UnitsPerPallet", "", "247", "", dataField), Utility.getDefault(this, vars, "ShelfWidth", "", "247", "", dataField), Utility.getDefault(this, vars, "Processing", "", "247", "N", dataField), Utility.getDefault(this, vars, "ImageURL", "", "247", "", dataField), Utility.getDefault(this, vars, "M_Product_Category_ID", "", "247", "", dataField), Utility.getDefault(this, vars, "Order_Min", "", "247", "", dataField), Utility.getDefault(this, vars, "UPC", "", "247", "", dataField), Utility.getDefault(this, vars, "DescriptionURL", "", "247", "", dataField), Utility.getDefault(this, vars, "PricePO", "", "247", "", dataField), Utility.getDefault(this, vars, "Help", "", "247", "", dataField), Utility.getDefault(this, vars, "X12DE355", "", "247", "", dataField), Utility.getDefault(this, vars, "C_UOM_ID", "", "247", "", dataField), Utility.getDefault(this, vars, "Value", "", "247", "", dataField));
}
}
String currentOrg = (boolNew?"":(dataField!=null?dataField.getField("adOrgId"):data[0].getField("adOrgId")));
if (!currentOrg.equals("") && !currentOrg.startsWith("'")) currentOrg = "'"+currentOrg+"'";
String currentClient = (boolNew?"":(dataField!=null?dataField.getField("adClientId"):data[0].getField("adClientId")));
if (!currentClient.equals("") && !currentClient.startsWith("'")) currentClient = "'"+currentClient+"'";
boolean 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/ImportProducts/ImportProduct_Edition",discard).createXmlDocument();
else
xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpWindows/ImportProducts/ImportProduct_NonEditable",discard).createXmlDocument();
xmlDocument.setParameter("tabId", tabId);
ToolBar toolbar = new ToolBar(this, editableTab, vars.getLanguage(), "ImportProduct", (strCommand.equals("NEW") || boolNew || (dataField==null && (data==null || data.length==0))), "document.frmMain.inpiProductId", "", "..", "".equals("Y"), "ImportProducts", strReplaceWith, true, false, false, Utility.hasTabAttachments(this, vars, tabId, strI_Product_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 (!strI_Product_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(), "ImportProduct_Relation.html", "ImportProducts", "W", strReplaceWith, tabs.breadcrumb());
xmlDocument.setParameter("navigationBar", nav.toString());
LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ImportProduct_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;
comboTableData = new ComboTableData(vars, this, "19", "M_Product_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("mProductId"):dataField.getField("mProductId")));
xmlDocument.setData("reportM_Product_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
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", "", "103", 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;
comboTableData = new ComboTableData(vars, this, "19", "C_UOM_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("cUomId"):dataField.getField("cUomId")));
xmlDocument.setData("reportC_UOM_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "19", "M_Product_Category_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("mProductCategoryId"):dataField.getField("mProductCategoryId")));
xmlDocument.setData("reportM_Product_Category_ID","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
comboTableData = new ComboTableData(vars, this, "17", "ProductType", "270", "", 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("producttype"):dataField.getField("producttype")));
xmlDocument.setData("reportProductType","liststructure", comboTableData.select(!strCommand.equals("NEW")));
comboTableData = null;
xmlDocument.setParameter("buttonVolume", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonWeight", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonShelfWidth", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonShelfHeight", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonShelfDepth", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("DiscontinuedBy_Format", vars.getSessionValue("#AD_SqlDateFormat"));
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("buttonPriceList", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonPricePO", Utility.messageBD(this, "Calc", vars.getLanguage()));
xmlDocument.setParameter("buttonRoyaltyAmt", Utility.messageBD(this, "Calc", vars.getLanguage()));