1 19 package org.openbravo.erpCommon.ad_process; 20 21 import org.openbravo.erpCommon.utility.*; 22 23 import org.openbravo.erpCommon.reference.*; 24 import org.openbravo.erpCommon.ad_actionButton.*; 25 26 import org.openbravo.erpCommon.businessUtility.*; 27 import org.openbravo.base.secureApp.HttpSecureAppServlet; 28 import org.openbravo.base.secureApp.VariablesSecureApp; 29 import org.openbravo.xmlEngine.XmlDocument; 30 import java.io.*; 31 import javax.servlet.*; 32 import javax.servlet.http.*; 33 34 35 import java.sql.Connection ; 37 38 39 public class PriceListCreateAll extends HttpSecureAppServlet { 40 41 42 public void init (ServletConfig config) { 43 super.init(config); 44 boolHist = false; 45 } 46 47 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 48 VariablesSecureApp vars = new VariablesSecureApp(request); 49 50 if (vars.commandIn("DEFAULT")) { 51 printPage(response, vars); 52 } else if (vars.commandIn("SAVE")) { 53 String strWindow = "PriceListCreateAll"; 54 String strKey = vars.getRequiredStringParameter("inpmPricelistVersionId"); 55 String messageResult = processButton(vars, strKey, strWindow); 56 vars.setSessionValue("PriceListCreateAll.message", messageResult); 57 response.sendRedirect(strDireccion + request.getServletPath()); 58 } else pageErrorPopUp(response); 59 } 60 61 String processButton(VariablesSecureApp vars, String strPriceListVersion, String windowId) throws ServletException { 62 Connection conn = null; 63 String strMessage = ""; 64 try { 65 conn = getTransactionConnection(); 66 PriceListCreateAllData[] data = PriceListCreateAllData.selectParent(conn, this, strPriceListVersion, Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId)); 67 if (data==null || data.length==0) { 68 releaseRollbackConnection(conn); 69 return Utility.messageBD(this, "SearchNothing", vars.getLanguage()); 70 } 71 strMessage = processPL(conn, vars, data[0]); 72 if (!strMessage.equals("")) { 73 releaseRollbackConnection(conn); 74 return strMessage; 75 } 76 strMessage = processHijos(conn, vars, windowId, data[0].mPricelistVersionId); 77 if (!strMessage.equals("")) { 78 releaseRollbackConnection(conn); 79 return strMessage; 80 } else strMessage = Utility.messageBD(this, "ProcessOK", vars.getLanguage()); 81 82 releaseCommitConnection(conn); 83 } catch (Exception e) { 84 try { 85 releaseRollbackConnection(conn); 86 } catch (Exception ignored) {} 87 log4j.warn(e); 88 return Utility.messageBD(this, "ProcessRunError", vars.getLanguage()); 89 } 90 return strMessage; 91 } 92 93 String processHijos(Connection conn, VariablesSecureApp vars, String windowId, String strPriceListVersion) throws ServletException { 94 String strMessage=""; 95 PriceListCreateAllData[] data = PriceListCreateAllData.select(conn, this, strPriceListVersion, Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId)); 96 if (data==null || data.length==0) return ""; 97 for (int i=0;i<data.length;i++) { 98 strMessage = processPL(conn, vars, data[i]); 99 if (!strMessage.equals("")) break; 100 strMessage = processHijos(conn, vars, windowId, data[i].mPricelistVersionId); 101 if (!strMessage.equals("")) break; 102 } 103 return strMessage; 104 } 105 106 String processPL(Connection conn, VariablesSecureApp vars, PriceListCreateAllData data) throws ServletException { 107 if (data.mPricelistVersionBaseId.equals("")) return ""; 108 String pinstance = SequenceIdData.getSequence(this, "AD_PInstance", vars.getClient()); 109 PInstanceProcessData.insertPInstance(this, pinstance, "800040", data.mPricelistVersionId, "N", vars.getUser(), vars.getClient(), vars.getOrg()); 110 111 PriceListCreateAllData.process(conn, this, pinstance); 112 113 PInstanceProcessData[] pinstanceData = PInstanceProcessData.select(this, pinstance); 114 String messageResult=""; 115 if (pinstanceData!=null && pinstanceData.length>0) { 116 if (!pinstanceData[0].result.equals("1")) { 117 if (!pinstanceData[0].errormsg.equals("")) { 118 String message = pinstanceData[0].errormsg; 119 if (message.startsWith("@") && message.endsWith("@")) { 120 message = message.substring(1, message.length()-1); 121 if (message.indexOf("@")==-1) messageResult = Utility.messageBD(this, message, vars.getLanguage()); 122 else messageResult = Utility.parseTranslation(this, vars, vars.getLanguage(), "@" + message + "@"); 123 } else { 124 messageResult = Utility.parseTranslation(this, vars, vars.getLanguage(), message); 125 } 126 } else if (!pinstanceData[0].pMsg.equals("")) { 127 String message = pinstanceData[0].pMsg; 128 messageResult = Utility.parseTranslation(this, vars, vars.getLanguage(), message); 129 } else { 130 messageResult = Utility.messageBD(this, "Error", vars.getLanguage()); 131 } 132 } 133 } 134 if (!messageResult.equals("")) if (log4j.isDebugEnabled()) log4j.debug(messageResult); 135 return messageResult; 136 } 137 138 void printPage(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 139 if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Create Pricelist"); 140 141 ActionButtonDefaultData[] data = null; 142 String strMessage = vars.getSessionValue("PriceListCreateAll.message"); 143 vars.removeSessionValue("PriceListCreateAll.message"); 144 String strHelp="", strDescription=""; 145 if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, classInfo.id); 146 else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), classInfo.id); 147 148 if (data!=null && data.length!=0) { 149 strDescription = data[0].description; 150 strHelp = data[0].help; 151 } 152 String [] discard = {""}; 153 if (strHelp.equals("")) discard[0] = new String ("helpDiscard"); 154 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/PriceListCreateAll", discard).createXmlDocument(); 155 156 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "PriceListCreateAll", false, "", "", "",false, "ad_process", strReplaceWith, false, true); 157 toolbar.prepareSimpleToolBarTemplate(); 158 xmlDocument.setParameter("toolbar", toolbar.toString()); 159 160 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 161 xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage())); 162 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 163 xmlDocument.setParameter("description", strDescription); 164 xmlDocument.setParameter("help", strHelp); 165 166 try { 168 KeyMap key = new KeyMap(this, vars, "PriceListCreate.html"); 169 xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps()); 170 } catch (Exception ex) { 171 throw new ServletException(ex); 172 } 173 try { 174 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_process.PriceListCreateAll"); 175 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 176 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 177 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 178 xmlDocument.setParameter("theme", vars.getTheme()); 179 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "PriceListCreateAll.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 180 xmlDocument.setParameter("navigationBar", nav.toString()); 181 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "PriceListCreateAll.html", strReplaceWith); 182 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 183 } catch (Exception ex) { 184 throw new ServletException(ex); 185 } 186 { 187 OBError myMessage = vars.getMessage("PriceListCreateAll"); 188 vars.removeMessage("PriceListCreateAll"); 189 if (myMessage!=null) { 190 xmlDocument.setParameter("messageType", myMessage.getType()); 191 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 192 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 193 } 194 } 195 196 198 if (!strMessage.equals("")) strMessage = "alert('" + strMessage + "');"; 199 xmlDocument.setParameter("message", strMessage); 200 201 202 try { 203 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_PriceList_Version_ID", "", "", Utility.getContext(this, vars, "#User_Org", "PriceListCreateAll"), Utility.getContext(this, vars, "#User_Client", "PriceListCreateAll"), 0); 204 Utility.fillSQLParameters(this, vars, null, comboTableData, "PriceListCreateAll", ""); 205 xmlDocument.setData("reportM_PriceList_Version_ID", "liststructure", comboTableData.select(false)); 206 comboTableData = null; 207 } catch (Exception ex) { 208 throw new ServletException(ex); 209 } 210 211 212 response.setContentType("text/html; charset=UTF-8"); 213 PrintWriter out = response.getWriter(); 214 out.println(xmlDocument.print()); 215 out.close(); 216 } 217 218 public String getServletInfo() { 219 return "Servlet Drop reg fact acct"; 220 } } 222 223
| Popular Tags
|