1 19 package org.openbravo.erpCommon.info; 20 21 import org.openbravo.base.secureApp.*; 22 import org.openbravo.xmlEngine.XmlDocument; 23 import org.openbravo.erpCommon.utility.Utility; 24 import org.openbravo.erpCommon.utility.ComboTableData; 25 26 import java.io.*; 27 import javax.servlet.*; 28 import javax.servlet.http.*; 29 import org.openbravo.utils.Replace; 30 31 32 33 public class Account extends HttpSecureAppServlet { 34 35 36 public void init (ServletConfig config) { 37 super.init(config); 38 boolHist = false; 39 } 40 41 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 42 VariablesSecureApp vars = new VariablesSecureApp(request); 43 44 if (vars.commandIn("DEFAULT")) { 45 String strNameValue = vars.getRequestGlobalVariable("inpNameValue", "Account.combination"); 46 String strAcctSchema = vars.getRequestGlobalVariable("inpAcctSchema", "Account.cAcctschemaId"); 47 if (strAcctSchema.equals("")) { 48 strAcctSchema = Utility.getContext(this, vars, "$C_AcctSchema_ID", "Account"); 49 vars.setSessionValue("Account.cAcctschemaId", strAcctSchema); 50 } 51 vars.removeSessionValue("Account.alias"); 52 if (!strNameValue.equals("")) vars.setSessionValue("Account.combination", strNameValue + "%"); 53 printPageFS(response, vars); 54 } else if (vars.commandIn("LOAD_FIELD")) { 55 String strClave = vars.getStringParameter("inpClave"); 56 printPageFrame1(response, vars, "", "", strClave, false); 57 } else if (vars.commandIn("KEY")) { 58 String strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "Account.alias"); 59 String strAcctSchema = vars.getRequestGlobalVariable("inpAcctSchema", "Account.cAcctschemaId"); 60 if (strAcctSchema.equals("")) { 61 strAcctSchema = Utility.getContext(this, vars, "$C_AcctSchema_ID", "Account"); 62 vars.setSessionValue("Account.cAcctschemaId", strAcctSchema); 63 } 64 vars.removeSessionValue("Account.combination"); 65 vars.setSessionValue("Account.alias", strKeyValue + "%"); 66 AccountData[] data = AccountData.selectKey(this, strAcctSchema, Utility.getContext(this, vars, "#User_Client", "Account"), Utility.getContext(this, vars, "#User_Org", "Account"), strKeyValue + "%"); 67 if (data!=null && data.length==1) { 68 printPageKey(response, vars, data); 69 } else printPageFS(response, vars); 70 } else if (vars.commandIn("FRAME1")) { 71 String strAlias = vars.getGlobalVariable("inpAlias", "Account.alias", ""); 72 String strCombination = vars.getGlobalVariable("inpCombination", "Account.combination", ""); 73 printPageFrame1(response, vars, strAlias, strCombination, "", true); 74 } else if (vars.commandIn("FRAME2")) { 75 String strAlias = vars.getGlobalVariable("inpAlias", "Account.alias", ""); 76 String strCombination = vars.getGlobalVariable("inpCombination", "Account.combination", ""); 77 String strOrganization = vars.getStringParameter("inpOrganization"); 78 String strAccount = vars.getStringParameter("inpAccount"); 79 String strProduct = vars.getStringParameter("inpProduct"); 80 String strBPartner = vars.getStringParameter("inpBPartner"); 81 String strProject = vars.getStringParameter("inpProject"); 82 String strCampaign = vars.getStringParameter("inpCampaign"); 83 printPageFrame2(response, vars, strAlias, strCombination, strOrganization, strAccount, strProduct, strBPartner, strProject, strCampaign); 84 } else if (vars.commandIn("FIND")) { 85 String strAlias = vars.getRequestGlobalVariable("inpAlias", "Account.alias"); 86 String strCombination = vars.getRequestGlobalVariable("inpCombination", "Account.combination"); 87 String strOrganization = vars.getStringParameter("inpOrganization"); 88 String strAccount = vars.getStringParameter("inpAccount"); 89 String strProduct = vars.getStringParameter("inpProduct"); 90 String strBPartner = vars.getStringParameter("inpBPartner"); 91 String strProject = vars.getStringParameter("inpProject"); 92 String strCampaign = vars.getStringParameter("inpCampaign"); 93 94 vars.setSessionValue("Account.initRecordNumber", "0"); 95 printPageFrame2(response, vars, strAlias, strCombination, strOrganization, strAccount, strProduct, strBPartner, strProject, strCampaign); 96 } else if (vars.commandIn("FRAME3")) { 97 printPageFrame3(response, vars); 98 } else if (vars.commandIn("SAVE")) { 99 String strAcctSchema = vars.getSessionValue("Account.cAcctschemaId"); 100 String strClave = vars.getStringParameter("inpValidCombination"); 101 String strAlias = vars.getRequestGlobalVariable("inpAlias", "Account.alias"); 102 String strOrganization = vars.getRequiredStringParameter("inpOrganization"); 103 String strAccount = vars.getRequiredStringParameter("inpAccount"); 104 String strProduct = vars.getStringParameter("inpProduct"); 105 String strBPartner = vars.getStringParameter("inpBPartner"); 106 String strProject = vars.getStringParameter("inpProject"); 107 String strCampaign = vars.getStringParameter("inpCampaign"); 108 AccountData data = AccountData.insert(this, vars.getClient(), strOrganization, strAcctSchema, strAccount, strClave, strAlias, vars.getUser(), strProduct, strBPartner, strProject, strCampaign); 109 if (data!=null) strClave = data.cValidcombinationId; 110 vars.removeSessionValue("Account.alias"); 111 vars.setSessionValue("Account.combination", AccountData.combination(this, strClave)); 112 printPageFS(response, vars); 113 } else if (vars.commandIn("PREVIOUS")) { 114 String strInitRecord = vars.getSessionValue("Account.initRecordNumber"); 115 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Account"); 116 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 117 if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("Account.initRecordNumber", "0"); 118 else { 119 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 120 initRecord -= intRecordRange; 121 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 122 vars.setSessionValue("Account.initRecordNumber", strInitRecord); 123 } 124 125 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 126 } else if (vars.commandIn("NEXT")) { 127 String strInitRecord = vars.getSessionValue("Account.initRecordNumber"); 128 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Account"); 129 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 130 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 131 if (initRecord==0) initRecord=1; 132 initRecord += intRecordRange; 133 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 134 vars.setSessionValue("Account.initRecordNumber", strInitRecord); 135 136 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 137 } else pageError(response); 138 } 139 140 void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 141 if (log4j.isDebugEnabled()) log4j.debug("Output: Account seeker Frame Set"); 142 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_FS").createXmlDocument(); 143 144 response.setContentType("text/html; charset=UTF-8"); 145 PrintWriter out = response.getWriter(); 146 out.println(xmlDocument.print()); 147 out.close(); 148 } 149 150 void printPageKey(HttpServletResponse response, VariablesSecureApp vars, AccountData[] data) throws IOException, ServletException { 151 if (log4j.isDebugEnabled()) log4j.debug("Output: Account seeker Frame Set"); 152 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument(); 153 154 xmlDocument.setParameter("script", generateResult(data)); 155 response.setContentType("text/html; charset=UTF-8"); 156 PrintWriter out = response.getWriter(); 157 out.println(xmlDocument.print()); 158 out.close(); 159 } 160 161 String generateResult(AccountData[] data) throws IOException, ServletException { 162 StringBuffer html = new StringBuffer (); 163 164 html.append("\nfunction depurarSelector() {\n"); 165 html.append("var clave = \"" + data[0].cValidcombinationId + "\";\n"); 166 html.append("var texto = \"" + Replace.replace(data[0].combination, "\"", "\\\"") + "\";\n"); 167 html.append("parent.opener.closeSearch(\"SAVE\", clave, texto, null);\n"); 168 html.append("}\n"); 169 return html.toString(); 170 } 171 172 void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String strAlias, String strCombination, String strValidCombination, boolean isDefault) throws IOException, ServletException { 173 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the accounts seeker"); 174 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_F1").createXmlDocument(); 175 AccountData[] data = null; 176 if (isDefault) { 177 if (strAlias.equals("") && strCombination.equals("")) strAlias = "%"; 178 data = AccountData.set(strAlias, strCombination); 179 } else { 180 data = AccountData.select(this, "", "", "", "", "", "", "", "", "", strValidCombination, Utility.getContext(this, vars, "#User_Client", "Account"), Utility.getContext(this, vars, "#User_Org", "Account")); 181 } 182 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 183 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 184 xmlDocument.setData("structure1", data); 185 try { 186 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "C_Campaign_ID", "C_Campaign", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0); 187 Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", ""); 188 xmlDocument.setData("reportC_Campaign_ID","liststructure", comboTableData.select(false)); 189 comboTableData = null; 190 } catch (Exception ex) { 191 throw new ServletException(ex); 192 } 193 194 try { 195 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "C_Project_ID", "C_Project", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0); 196 Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", ""); 197 xmlDocument.setData("reportC_Project_ID","liststructure", comboTableData.select(false)); 198 comboTableData = null; 199 } catch (Exception ex) { 200 throw new ServletException(ex); 201 } 202 203 204 try { 205 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "AD_Org_ID", "AD_Org (Trx)", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0); 206 Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", ""); 207 xmlDocument.setData("reportAD_Org_ID","liststructure", comboTableData.select(false)); 208 comboTableData = null; 209 } catch (Exception ex) { 210 throw new ServletException(ex); 211 } 212 213 214 try { 215 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "Account_ID", "C_ElementValue (Accounts)", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0); 216 Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", ""); 217 xmlDocument.setData("reportAccount_ID","liststructure", comboTableData.select(false)); 218 comboTableData = null; 219 } catch (Exception ex) { 220 throw new ServletException(ex); 221 } 222 223 224 try { 225 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "M_Product_ID", "M_Product (no summary)", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0); 226 Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", ""); 227 xmlDocument.setData("reportM_Product_ID","liststructure", comboTableData.select(false)); 228 comboTableData = null; 229 } catch (Exception ex) { 230 throw new ServletException(ex); 231 } 232 233 234 try { 235 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "C_BPartner_ID", "C_BPartner", "", Utility.getContext(this, vars, "#User_Org", "Account"), Utility.getContext(this, vars, "#User_Client", "Account"), 0); 236 Utility.fillSQLParameters(this, vars, null, comboTableData, "Account", ""); 237 xmlDocument.setData("reportC_BPartner_ID","liststructure", comboTableData.select(false)); 238 comboTableData = null; 239 } catch (Exception ex) { 240 throw new ServletException(ex); 241 } 242 243 response.setContentType("text/html; charset=UTF-8"); 244 PrintWriter out = response.getWriter(); 245 out.println(xmlDocument.print()); 246 out.close(); 247 } 248 249 void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String strAlias, String strCombination, String strOrganization, String strAccount, String strProduct, String strBPartner, String strProject, String strCampaign) throws IOException, ServletException { 250 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the accounts seeker"); 251 XmlDocument xmlDocument; 252 String strAcctSchema = vars.getSessionValue("Account.cAcctschemaId"); 253 254 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Account"); 255 int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange)); 256 String strInitRecord = vars.getSessionValue("Account.initRecordNumber"); 257 int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 258 259 if (strAlias.equals("") && strCombination.equals("") && strOrganization.equals("") && strAccount.equals("") && strProduct.equals("") && strBPartner.equals("") && strProject.equals("") && strCampaign.equals("")) { 260 String [] discard = {"sectionDetail", "hasPrevious", "hasNext"}; 261 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_F2", discard).createXmlDocument(); 262 xmlDocument.setData("structure1", AccountData.set(strAlias, strCombination)); 263 } else { 264 String [] discard = {"withoutPrevious", "withoutNext"}; 265 AccountData[] data = AccountData.select(this, strAcctSchema, strAlias, strCombination, strOrganization, strAccount, strProduct, strBPartner, strProject, strCampaign, "", Utility.getContext(this, vars, "#User_Client", "Account"), Utility.getContext(this, vars, "#User_Org", "Account"), initRecordNumber, intRecordRange); 266 if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String ("hasPrevious"); 267 if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String ("hasNext"); 268 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_F2", discard).createXmlDocument(); 269 xmlDocument.setData("structure1", data); 270 } 271 272 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 273 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 274 response.setContentType("text/html; charset=UTF-8"); 275 PrintWriter out = response.getWriter(); 276 out.println(xmlDocument.print()); 277 out.close(); 278 } 279 280 void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 281 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the business partners seeker"); 282 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Account_F3").createXmlDocument(); 283 284 response.setContentType("text/html; charset=UTF-8"); 285 PrintWriter out = response.getWriter(); 286 out.println(xmlDocument.print()); 287 out.close(); 288 } 289 290 public String getServletInfo() { 291 return "Servlet that presents que accounts seeker"; 292 } } 294 | Popular Tags |