1 19 package org.openbravo.erpCommon.info; 20 21 import org.openbravo.base.secureApp.*; 22 import org.openbravo.xmlEngine.XmlDocument; 23 import java.io.*; 24 import javax.servlet.*; 25 import javax.servlet.http.*; 26 27 import org.openbravo.utils.FormatUtilities; 28 import org.openbravo.erpCommon.utility.*; 29 30 import org.openbravo.erpCommon.ad_combos.WarehouseComboData; 31 32 33 public class ProductComplete 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", "ProductComplete.name"); 46 String strIDValue = vars.getStringParameter("inpIDValue"); 47 if (!strIDValue.equals("")) { 49 String strNameAux = ProductData.existsActual(this, vars.getLanguage(), strNameValue, strIDValue); 50 if (!strNameAux.equals("")) strNameValue = strNameAux; 51 } 52 String windowId = vars.getRequestGlobalVariable("WindowID", "ProductComplete.windowId"); 53 String strWarehouse = vars.getRequestGlobalVariable("inpWarehouse", "ProductComplete.warehouse"); 54 if (strWarehouse.equals("")) strWarehouse = Utility.getContext(this, vars, "M_Warehouse_ID", windowId); 55 vars.setSessionValue("ProductComplete.warehouse", strWarehouse); 56 String strBpartner = vars.getRequestGlobalVariable("inpBPartner", "ProductComplete.bpartner"); 57 vars.removeSessionValue("ProductComplete.key"); 58 if (!strNameValue.equals("")) vars.setSessionValue("ProductComplete.name", strNameValue + "%"); 59 String strIsSOTrxTab = vars.getStringParameter("inpisSOTrxTab"); 60 String isSOTrx = strIsSOTrxTab; 61 if (strIsSOTrxTab.equals("")) isSOTrx = Utility.getContext(this, vars, "isSOTrx", windowId); 62 vars.setSessionValue("ProductComplete.isSOTrx", isSOTrx); 63 64 printPageFS(response, vars); 65 } else if (vars.commandIn("KEY")) { 66 String windowId = vars.getRequestGlobalVariable("WindowID", "ProductComplete.windowId"); 67 String strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "ProductComplete.key"); 68 String strWarehouse = vars.getRequestGlobalVariable("inpWarehouse", "ProductComplete.warehouse"); 69 if (strWarehouse.equals("")) strWarehouse = Utility.getContext(this, vars, "M_Warehouse_ID", windowId); 70 vars.setSessionValue("ProductComplete.warehouse", strWarehouse); 71 String strBpartner = vars.getRequestGlobalVariable("inpBPartner", "ProductComplete.bpartner"); 72 String strIsSOTrxTab = vars.getStringParameter("inpisSOTrxTab"); 73 String isSOTrx = strIsSOTrxTab; 74 if (strIsSOTrxTab.equals("")) isSOTrx = Utility.getContext(this, vars, "isSOTrx", windowId); 75 vars.setSessionValue("ProductComplete.isSOTrx", isSOTrx); 76 String strStore = vars.getStringParameter("inpWithStoreLines", isSOTrx); 77 vars.removeSessionValue("ProductComplete.name"); 78 if (!strKeyValue.equals("")) vars.setSessionValue("ProductComplete.key", strKeyValue + "%"); 79 80 ProductCompleteData[] data = null; 81 String strClients = Utility.getContext(this, vars, "#User_Client", "ProductComplete"); 82 String strOrgs = Utility.getContext(this, vars, "#User_Org", "ProductComplete"); 83 if (strStore.equals("Y")) { 84 if (vars.getLanguage().equals("en_US")) data = ProductCompleteData.select(this, strKeyValue + "%", "", strWarehouse, vars.getRole(), strBpartner, strClients); 85 else data = ProductCompleteData.selecttrl(this, vars.getLanguage(), strKeyValue + "%", "", strWarehouse, vars.getRole(), strBpartner, strClients); 86 }else { 87 if (vars.getLanguage().equals("en_US")) data = ProductCompleteData.selectNotStored(this, strKeyValue + "%", "", strBpartner, strClients, strOrgs); 88 else data = ProductCompleteData.selectNotStoredtrl(this, vars.getLanguage(), strKeyValue + "%", "", strBpartner, strClients, strOrgs); 89 } 90 if (data!=null && data.length==1) printPageKey(response, vars, data, strWarehouse); 91 else printPageFS(response, vars); 92 } else if (vars.commandIn("FRAME1")) { 93 String strKeyValue = vars.getGlobalVariable("inpKey", "ProductComplete.key", ""); 94 String strNameValue = vars.getGlobalVariable("inpName", "ProductComplete.name", ""); 95 String strWarehouse = vars.getGlobalVariable("inpWarehouse", "ProductComplete.warehouse", ""); 96 String strBpartner = vars.getGlobalVariable("inpBPartner", "ProductComplete.bpartner", ""); 97 String windowId = vars.getGlobalVariable("WindowID", "ProductComplete.windowId", ""); 98 String strStore = vars.getStringParameter("inpWithStoreLines", vars.getSessionValue("ProductComplete.isSOTrx")); 99 printPageFrame1(response, vars, strKeyValue, strNameValue, strWarehouse, windowId, strStore, strBpartner); 100 } else if (vars.commandIn("FRAME2")) { 101 String strKey = vars.getGlobalVariable("inpKey", "ProductComplete.key", ""); 102 String strName = vars.getGlobalVariable("inpName", "ProductComplete.name", ""); 103 String strWarehouse = vars.getGlobalVariable("inpWarehouse", "ProductComplete.warehouse", ""); 104 String strBpartner = vars.getGlobalVariable("inpBPartner", "ProductComplete.bpartner", ""); 105 String windowId = vars.getGlobalVariable("WindowID", "ProductComplete.windowId", ""); 106 String strStore = vars.getStringParameter("inpWithStoreLines", vars.getSessionValue("ProductComplete.isSOTrx")); 107 printPageFrame2(response, vars, strKey, strName, strWarehouse, strStore, strBpartner); 108 } else if (vars.commandIn("FIND")) { 109 String strKey = vars.getRequestGlobalVariable("inpKey", "ProductComplete.key"); 110 String strName = vars.getRequestGlobalVariable("inpName", "ProductComplete.name"); 111 String strWarehouse = vars.getRequestGlobalVariable("inpWarehouse", "ProductComplete.warehouse"); 112 String strBpartner = vars.getRequestGlobalVariable("inpBPartner", "ProductComplete.bpartner"); 113 String strStore = vars.getStringParameter("inpWithStoreLines", "N"); 114 115 vars.setSessionValue("ProductComplete.initRecordNumber", "0"); 116 117 printPageFrame2(response, vars, strKey, strName, strWarehouse, strStore, strBpartner); 118 } else if (vars.commandIn("FRAME3")) { 119 printPageFrame3(response, vars); 120 } else if (vars.commandIn("PREVIOUS")) { 121 String strInitRecord = vars.getSessionValue("ProductComplete.initRecordNumber"); 122 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ProductComplete"); 123 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 124 if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("ProductComplete.initRecordNumber", "0"); 125 else { 126 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 127 initRecord -= intRecordRange; 128 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 129 vars.setSessionValue("ProductComplete.initRecordNumber", strInitRecord); 130 } 131 132 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 133 } else if (vars.commandIn("NEXT")) { 134 String strInitRecord = vars.getSessionValue("ProductComplete.initRecordNumber"); 135 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ProductComplete"); 136 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 137 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 138 if (initRecord==0) initRecord=1; 139 initRecord += intRecordRange; 140 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 141 vars.setSessionValue("ProductComplete.initRecordNumber", strInitRecord); 142 143 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 144 } else pageError(response); 145 } 146 147 148 void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 149 if (log4j.isDebugEnabled()) log4j.debug("Output: Product seeker Frame Set"); 150 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductComplete_FS").createXmlDocument(); 151 152 response.setContentType("text/html; charset=UTF-8"); 153 PrintWriter out = response.getWriter(); 154 out.println(xmlDocument.print()); 155 out.close(); 156 } 157 158 void printPageKey(HttpServletResponse response, VariablesSecureApp vars, ProductCompleteData[] data, String strWarehouse) throws IOException, ServletException { 159 if (log4j.isDebugEnabled()) log4j.debug("Output: Product seeker Frame Set"); 160 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument(); 161 162 xmlDocument.setParameter("script", generateResult(data, strWarehouse)); 163 response.setContentType("text/html; charset=UTF-8"); 164 PrintWriter out = response.getWriter(); 165 out.println(xmlDocument.print()); 166 out.close(); 167 } 168 169 String generateResult(ProductCompleteData[] data, String strWarehouse) throws IOException, ServletException { 170 StringBuffer html = new StringBuffer (); 171 172 html.append("\nfunction depurarSelector() {\n"); 173 html.append("var clave = \"" + data[0].mProductId + "\";\n"); 174 html.append("var texto = \"" + FormatUtilities.replaceJS(data[0].name) + "\";\n"); 175 html.append("var parameter = new Array(\n"); 176 html.append("new SearchElements(\"_LOC\", true, \"" + data[0].mLocatorId + "\"),\n"); 177 html.append("new SearchElements(\"_ATR\", true, \"" + data[0].mAttributesetinstanceId + "\"),\n"); 178 html.append("new SearchElements(\"_PQTY\", true, \"" + (data[0].qtyorder.equals("0")?"":data[0].qtyorder) + "\"),\n"); 179 html.append("new SearchElements(\"_PUOM\", true, \"" + data[0].cUom2Id + "\"),\n"); 180 html.append("new SearchElements(\"_QTY\", true, \"" + data[0].qty + "\"),\n"); 181 html.append("new SearchElements(\"_UOM\", true, \"" + data[0].cUom1Id + "\")\n"); 182 html.append(");\n"); 183 html.append("parent.opener.closeSearch(\"SAVE\", clave, texto, parameter);\n"); 184 html.append("}\n"); 185 return html.toString(); 186 } 187 188 void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String strKeyValue, String strNameValue, String strWarehouse, String windowId, String strStore, String strBpartner) throws IOException, ServletException { 189 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the product seeker"); 190 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductComplete_F1").createXmlDocument(); 191 192 if (strKeyValue.equals("") && strNameValue.equals("")) { 193 xmlDocument.setParameter("key", "%"); 194 } else { 195 xmlDocument.setParameter("key", strKeyValue); 196 } 197 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 198 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 199 xmlDocument.setParameter("name", strNameValue); 200 xmlDocument.setParameter("warehouse", strWarehouse); 201 xmlDocument.setParameter("store", strStore); 202 xmlDocument.setParameter("bpartner", strBpartner); 203 xmlDocument.setData("structure1", WarehouseComboData.select(this, vars.getRole(), vars.getClient())); 204 response.setContentType("text/html; charset=UTF-8"); 205 PrintWriter out = response.getWriter(); 206 out.println(xmlDocument.print()); 207 out.close(); 208 } 209 210 void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strName, String strWarehouse, String strStore, String strBpartner) throws IOException, ServletException { 211 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the products seeker"); 212 XmlDocument xmlDocument; 213 String strClients = Utility.getContext(this, vars, "#User_Client", "ProductComplete"); 214 String strOrgs = Utility.getContext(this, vars, "#User_Org", "ProductComplete"); 215 216 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "ProductComplete"); 217 int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange)); 218 String strInitRecord = vars.getSessionValue("ProductComplete.initRecordNumber"); 219 int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 220 221 if (strKey.equals("") && strName.equals("")) { 222 String [] discard = {"sectionDetail", "hasPrevious", "hasNext"}; 223 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductComplete_F2", discard).createXmlDocument(); 224 xmlDocument.setData("structure1", ProductCompleteData.set()); 225 } else { 226 String [] discard = {"withoutPrevious", "withoutNext"}; 227 ProductCompleteData[] data = null; 228 231 232 233 234 if (strStore.equals("Y")) { 235 if (vars.getLanguage().equals("en_US")) data = ProductCompleteData.select(this, strKey, strName, strWarehouse, vars.getRole(), strBpartner, strClients, initRecordNumber, intRecordRange); 236 else data = ProductCompleteData.selecttrl(this, vars.getLanguage(), strKey, strName, strWarehouse, vars.getRole(), strBpartner, strClients, initRecordNumber, intRecordRange); 237 }else { 238 if (vars.getLanguage().equals("en_US")) data = ProductCompleteData.selectNotStored(this, strKey, strName, strBpartner, strClients, strOrgs, initRecordNumber, intRecordRange); 239 else data = ProductCompleteData.selectNotStoredtrl(this, vars.getLanguage(), strKey, strName, strBpartner, strClients, strOrgs, initRecordNumber, intRecordRange); 240 } 241 242 243 244 if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String ("hasPrevious"); 245 if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String ("hasNext"); 246 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductComplete_F2", discard).createXmlDocument(); 247 xmlDocument.setData("structure1", data); 248 } 249 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 250 response.setContentType("text/html; charset=UTF-8"); 251 PrintWriter out = response.getWriter(); 252 out.println(xmlDocument.print()); 253 out.close(); 254 } 255 256 void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 257 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the products seeker"); 258 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/ProductComplete_F3").createXmlDocument(); 259 260 response.setContentType("text/html; charset=UTF-8"); 261 PrintWriter out = response.getWriter(); 262 out.println(xmlDocument.print()); 263 out.close(); 264 } 265 266 public String getServletInfo() { 267 return "Servlet that presents que products seeker"; 268 } } 270 | Popular Tags |