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 import org.openbravo.utils.Replace; 27 28 import org.openbravo.erpCommon.utility.DateTimeData; 29 import org.openbravo.erpCommon.utility.Utility; 30 import org.openbravo.erpCommon.utility.ToolBar; 31 32 import org.openbravo.erpCommon.ad_combos.WarehouseComboData; 33 import org.openbravo.erpCommon.ad_combos.PriceListVersionComboData; 34 35 36 public class Product extends HttpSecureAppServlet { 37 38 39 public void init (ServletConfig config) { 40 super.init(config); 41 boolHist = false; 42 } 43 44 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 45 VariablesSecureApp vars = new VariablesSecureApp(request); 46 47 if (vars.commandIn("DEFAULT")) { 48 String strNameValue = vars.getRequestGlobalVariable("inpNameValue", "Product.name"); 49 String strIDValue = vars.getStringParameter("inpIDValue"); 50 if (!strIDValue.equals("")) { 51 String strNameAux = ProductData.existsActual(this, vars.getLanguage(), strNameValue, strIDValue); 52 if (!strNameAux.equals("")) strNameValue = strNameAux; 53 } 54 String strPriceList = vars.getRequestGlobalVariable("inpPriceList", "Product.priceList"); 55 String strDate = vars.getRequestGlobalVariable("inpDate", "Product.date"); 56 String windowId = vars.getRequestGlobalVariable("WindowID", "Product.windowId"); 57 String strWarehouse = vars.getGlobalVariable("inpWarehouse", "Product.warehouse", Utility.getContext(this, vars, "M_Warehouse_ID", windowId)); 58 vars.removeSessionValue("Product.key"); 59 if (!strNameValue.equals("")) vars.setSessionValue("Product.name", strNameValue + "%"); 60 if (strPriceList.equals("")) { 61 strPriceList = Utility.getContext(this, vars, "M_Pricelist_ID", windowId); 62 if (strPriceList.equals("")) strPriceList = ProductData.priceListDefault(this, Utility.getContext(this, vars, "#User_Client", "Product"), Utility.getContext(this, vars, "#User_Org", "Product")); 63 vars.setSessionValue("Product.priceList", strPriceList); 64 } 65 if (strDate.equals("")) { 66 strDate = Utility.getContext(this, vars, "DateOrdered", windowId); 67 if (log4j.isDebugEnabled()) log4j.debug("DateOrdered:"+strDate); 68 } 69 if (strDate.equals("")) { 70 strDate = Utility.getContext(this, vars, "DateInvoiced", windowId); 71 if (log4j.isDebugEnabled()) log4j.debug("DateInvoiced:"+strDate); 72 } 73 if (strDate.equals("")) strDate = DateTimeData.today(this); 74 vars.setSessionValue("Product.date", strDate); 75 76 vars.setSessionValue("Product.priceListVersion", getPriceListVersion(vars, strPriceList, strDate)); 77 78 printPageFS(response, vars); 79 } else if (vars.commandIn("KEY")) { 80 String strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "Product.key"); 81 String strIDValue = vars.getStringParameter("inpIDValue"); 82 if (!strIDValue.equals("")) { 83 String strNameAux = ProductData.existsActualValue(this, vars.getLanguage(), strKeyValue, strIDValue); 84 if (!strNameAux.equals("")) strKeyValue = strNameAux; 85 } 86 String strWarehouse = vars.getRequestGlobalVariable("inpWarehouse", "Product.warehouse"); 87 String strPriceList = vars.getRequestGlobalVariable("inpPriceList", "Product.priceList"); 88 String strDate = vars.getRequestGlobalVariable("inpDate", "Product.date"); 89 String windowId = vars.getRequestGlobalVariable("WindowID", "Product.windowId"); 90 vars.removeSessionValue("Product.name"); 91 if (!strKeyValue.equals("")) vars.setSessionValue("Product.key", strKeyValue + "%"); 92 if (strWarehouse.equals("")) strWarehouse = Utility.getContext(this, vars, "M_Warehouse_ID", windowId); 93 vars.setSessionValue("Product.warehouse", strWarehouse); 94 if (strPriceList.equals("")) { 95 strPriceList = Utility.getContext(this, vars, "M_Pricelist_ID", windowId); 96 if (strPriceList.equals("")) strPriceList = ProductData.priceListDefault(this, Utility.getContext(this, vars, "#User_Client", "Product"), Utility.getContext(this, vars, "#User_Org", "Product")); 97 vars.setSessionValue("Product.priceList", strPriceList); 98 } 99 100 if (strDate.equals("")) { 101 strDate = Utility.getContext(this, vars, "DateOrdered", windowId); 102 if (log4j.isDebugEnabled()) log4j.debug("DateOrdered:"+strDate); 103 } 104 if (strDate.equals("")) { 105 strDate = Utility.getContext(this, vars, "DateInvoiced", windowId); 106 if (log4j.isDebugEnabled()) log4j.debug("DateInvoiced:"+strDate); 107 } 108 vars.setSessionValue("Product.date", strDate); 109 110 String strPriceListVersion = getPriceListVersion(vars, strPriceList, strDate); 111 vars.setSessionValue("Product.priceListVersion", strPriceListVersion); 112 ProductData[] data = ProductData.select(this, vars.getLanguage(), strWarehouse, strKeyValue + "%", "", strPriceListVersion, Utility.getContext(this, vars, "#User_Client", "Product"), Utility.getContext(this, vars, "#User_Org", "Product")); 113 if (data!=null && data.length==1) printPageKey(response, vars, data, strWarehouse, strPriceListVersion); 114 else printPageFS(response, vars); 115 } else if (vars.commandIn("FRAME1")) { 116 String strKeyValue = vars.getGlobalVariable("inpKey", "Product.key", ""); 117 String strNameValue = vars.getGlobalVariable("inpName", "Product.name", ""); 118 String strWarehouse = vars.getGlobalVariable("inpWarehouse", "Product.warehouse", ""); 119 String strPriceList = vars.getGlobalVariable("inpPriceList", "Product.priceList", ""); 120 String strPriceListVersion = vars.getGlobalVariable("inpPriceListVersion", "Product.priceListVersion", ""); 121 String windowId = vars.getGlobalVariable("WindowID", "Product.windowId", ""); 122 printPageFrame1(response, vars, strKeyValue, strNameValue, strWarehouse, strPriceList, strPriceListVersion, windowId); 123 } else if (vars.commandIn("FRAME2")) { 124 String strKey = vars.getGlobalVariable("inpKey", "Product.key", ""); 125 String strName = vars.getGlobalVariable("inpName", "Product.name", ""); 126 String strWarehouse = vars.getGlobalVariable("inpWarehouse", "Product.warehouse", ""); 127 String strPriceListVersion = vars.getGlobalVariable("inpPriceListVersion", "Product.priceListVersion", ""); 128 printPageFrame2(response, vars, strKey, strName, strWarehouse, strPriceListVersion); 129 } else if (vars.commandIn("FIND")) { 130 String strKey = vars.getRequestGlobalVariable("inpKey", "Product.key"); 131 String strName = vars.getRequestGlobalVariable("inpName", "Product.name"); 132 String strWarehouse = vars.getRequiredGlobalVariable("inpWarehouse", "Product.warehouse"); 133 String strPriceListVersion = vars.getRequiredGlobalVariable("inpPriceListVersion", "Product.priceListVersion"); 134 135 vars.setSessionValue("Product.initRecordNumber", "0"); 136 137 printPageFrame2(response, vars, strKey, strName, strWarehouse, strPriceListVersion); 138 } else if (vars.commandIn("FRAME3")) { 139 printPageFrame3(response, vars); 140 } else if (vars.commandIn("PREVIOUS_RELATION")) { 141 String strInitRecord = vars.getSessionValue("Product.initRecordNumber"); 142 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Product"); 143 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 144 if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("Product.initRecordNumber", "0"); 145 else { 146 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 147 initRecord -= intRecordRange; 148 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 149 vars.setSessionValue("Product.initRecordNumber", strInitRecord); 150 } 151 152 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 153 } else if (vars.commandIn("NEXT_RELATION")) { 154 String strInitRecord = vars.getSessionValue("Product.initRecordNumber"); 155 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Product"); 156 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 157 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 158 if (initRecord==0) initRecord=1; 159 initRecord += intRecordRange; 160 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 161 vars.setSessionValue("Product.initRecordNumber", strInitRecord); 162 163 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 164 } else pageError(response); 165 } 166 167 168 String getPriceListVersion(VariablesSecureApp vars, String strPriceList, String strDate) throws IOException,ServletException { 169 PriceListVersionComboData[] data = PriceListVersionComboData.selectActual(this, strPriceList, strDate, Utility.getContext(this, vars, "#User_Client", "Product")); 170 if (log4j.isDebugEnabled()) log4j.debug("Selecting pricelistversion date:"+strDate+" - pricelist:"+strPriceList); 171 if (data==null || data.length==0) return ""; 172 return data[0].mPricelistVersionId; 173 } 174 175 void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 176 if (log4j.isDebugEnabled()) log4j.debug("Output: product seeker Frame Set"); 177 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Product_FS").createXmlDocument(); 178 179 response.setContentType("text/html; charset=UTF-8"); 180 PrintWriter out = response.getWriter(); 181 out.println(xmlDocument.print()); 182 out.close(); 183 } 184 185 void printPageKey(HttpServletResponse response, VariablesSecureApp vars, ProductData[] data, String strWarehouse, String strPriceListVersion) throws IOException, ServletException { 186 if (log4j.isDebugEnabled()) log4j.debug("Output: product seeker Frame Set"); 187 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument(); 188 189 xmlDocument.setParameter("script", generateResult(data, strWarehouse, strPriceListVersion)); 190 response.setContentType("text/html; charset=UTF-8"); 191 PrintWriter out = response.getWriter(); 192 out.println(xmlDocument.print()); 193 out.close(); 194 } 195 196 String generateResult(ProductData[] data, String strWarehouse, String strPriceListVersion) throws IOException, ServletException { 197 StringBuffer html = new StringBuffer (); 198 199 html.append("\nfunction depurarSelector() {\n"); 200 html.append("var clave = \"" + data[0].mProductId + "\";\n"); 201 html.append("var texto = \"" + Replace.replace(data[0].name, "\"", "\\\"") + "\";\n"); 202 html.append("var parameter = new Array(\n"); 203 html.append("new SearchElements(\"_UOM\", true, \"" + data[0].cUomId + "\"),\n"); 204 html.append("new SearchElements(\"_PSTD\", true, \"" + data[0].pricestd + "\"),\n"); 205 html.append("new SearchElements(\"_PLIM\", true, \"" + data[0].pricelimit + "\"),\n"); 206 html.append("new SearchElements(\"_CURR\", true, \"" + data[0].cCurrencyId + "\"),\n"); 207 html.append("new SearchElements(\"_PLIST\", true, \"" + data[0].pricelist + "\")\n"); 208 html.append(");\n"); 209 html.append("parent.opener.closeSearch(\"SAVE\", clave, texto, parameter);\n"); 210 html.append("}\n"); 211 return html.toString(); 212 } 213 214 void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String strKeyValue, String strNameValue, String strWarehouse, String strPriceList, String strPriceListVersion, String windowId) throws IOException, ServletException { 215 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of the products seeker"); 216 String [] discard=new String [1]; 217 if (windowId.equals("800004")) { 218 discard[0] = new String ("NotReducedSearch"); 219 } else { 220 discard[0] = new String ("ReducedSearch"); 221 } 222 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Product_F1", discard).createXmlDocument(); 223 224 if (strKeyValue.equals("") && strNameValue.equals("")) { 225 xmlDocument.setParameter("key", "%"); 226 } else { 227 xmlDocument.setParameter("key", strKeyValue); 228 } 229 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 230 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 231 xmlDocument.setParameter("name", strNameValue); 232 xmlDocument.setParameter("warehouse", strWarehouse); 233 xmlDocument.setParameter("priceListVersion", strPriceListVersion); 234 xmlDocument.setData("structure1", WarehouseComboData.selectFilter(this, Utility.getContext(this, vars, "#User_Client", "Product"))); 235 xmlDocument.setData("structure2", PriceListVersionComboData.select(this, strPriceList, Utility.getContext(this, vars, "#User_Client", "Product"))); 236 response.setContentType("text/html; charset=UTF-8"); 237 PrintWriter out = response.getWriter(); 238 out.println(xmlDocument.print()); 239 out.close(); 240 } 241 242 void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String strKey, String strName, String strWarehouse, String strPriceListVersion) throws IOException, ServletException { 243 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the products seeker"); 244 XmlDocument xmlDocument; 245 246 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Product"); 247 int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange)); 248 String strInitRecord = vars.getSessionValue("Product.initRecordNumber"); 249 int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 250 boolean hasPrevious = false, hasNext = false; 251 252 if (strKey.equals("") && strName.equals("")) { 253 String [] discard = {"sectionDetail"}; 254 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Product_F2", discard).createXmlDocument(); 255 xmlDocument.setData("structure1", ProductData.set()); 256 } else { 257 hasPrevious = hasNext = true; 258 ProductData[] data = ProductData.select(this, vars.getLanguage(), strWarehouse, strKey, strName, strPriceListVersion, Utility.getContext(this, vars, "#User_Client", "Product"), Utility.getContext(this, vars, "#User_Org", "Product"), initRecordNumber, intRecordRange); 259 if (data==null || data.length==0 || initRecordNumber<=1) hasPrevious = false; 260 if (data==null || data.length==0 || data.length<intRecordRange) hasNext = false; 261 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Product_F2").createXmlDocument(); 262 xmlDocument.setData("structure1", data); 263 } 264 265 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "Product_F2", false, "document.frmMain.inpClave", "", "", false, "info", strReplaceWith, false, true); 266 toolbar.prepareInfoTemplate(hasPrevious, hasNext, vars.getSessionValue("#ShowTest", "N").equals("Y")); 267 xmlDocument.setParameter("toolbar", toolbar.toString()); 268 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 269 response.setContentType("text/html; charset=UTF-8"); 270 PrintWriter out = response.getWriter(); 271 out.println(xmlDocument.print()); 272 out.close(); 273 } 274 275 void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 276 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the products seeker"); 277 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Product_F3").createXmlDocument(); 278 279 response.setContentType("text/html; charset=UTF-8"); 280 PrintWriter out = response.getWriter(); 281 out.println(xmlDocument.print()); 282 out.close(); 283 } 284 285 public String getServletInfo() { 286 return "Servlet that presents the products seeker"; 287 } } 289 | Popular Tags |