KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_callouts > SL_Inventory_Product


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

19 package org.openbravo.erpCommon.ad_callouts;
20
21 import org.openbravo.base.secureApp.HttpSecureAppServlet;
22 import org.openbravo.base.secureApp.VariablesSecureApp;
23 import org.openbravo.xmlEngine.XmlDocument;
24 import org.openbravo.utils.FormatUtilities;
25 import org.openbravo.erpCommon.utility.*;
26 import org.openbravo.data.FieldProvider;
27 import java.io.*;
28 import javax.servlet.*;
29 import javax.servlet.http.*;
30
31 public class SL_Inventory_Product extends HttpSecureAppServlet {
32   
33
34   public void init (ServletConfig config) {
35     super.init(config);
36     boolHist = false;
37   }
38
39   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
40     VariablesSecureApp vars = new VariablesSecureApp(request);
41     if (vars.commandIn("DEFAULT")) {
42       String JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
43       if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
44       String JavaDoc strProduct = vars.getStringParameter("inpmProductId");
45       String JavaDoc strLocator = vars.getStringParameter("inpmProductId_LOC");
46       String JavaDoc strAttribute = vars.getStringParameter("inpmProductId_ATR");
47       String JavaDoc strQty = vars.getStringParameter("inpmProductId_QTY");
48       String JavaDoc strUOM = vars.getStringParameter("inpmProductId_UOM");
49       String JavaDoc strQtyOrder = vars.getStringParameter("inpmProductId_PQTY");
50       String JavaDoc strPUOM = vars.getStringParameter("inpmProductId_PUOM");
51       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
52       printPage(response, vars, strChanged, strProduct, strLocator, strAttribute, strQty, strUOM, strQtyOrder, strPUOM, strTabId);
53     } else pageError(response);
54   }
55
56   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strChanged, String JavaDoc strProduct, String JavaDoc strLocator, String JavaDoc strAttribute, String JavaDoc strQty, String JavaDoc strUOM, String JavaDoc strQtyOrder, String JavaDoc strPUOM, String JavaDoc strTabId) throws IOException, ServletException {
57     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
58     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
59
60     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
61     resultado.append("var calloutName='SL_Inventory_Product';\n\n");
62     resultado.append("var respuesta = new Array(");
63     if (strLocator.startsWith("\"")) strLocator=strLocator.substring(1,strLocator.length()-1);
64     if (!strLocator.equals("")) {
65       resultado.append("new Array(\"inpmLocatorId\", \"" + strLocator + "\"),");
66       resultado.append("new Array(\"inpmLocatorId_R\", \"" + FormatUtilities.replaceJS(SLInOutLineProductData.locator(this, strLocator, vars.getLanguage())) + "\"),");
67     }
68     /*resultado.append("new Array(\"inpcUomId\", " + SLInventoryProductData.select(this, strProduct) + "),");*/
69     resultado.append("new Array(\"inpcUomId\", " + (strUOM.equals("")?"\"\"":strUOM) + "),");
70     if (strAttribute.startsWith("\"")) strAttribute=strAttribute.substring(1,strAttribute.length()-1);
71     resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + strAttribute + "\"),");
72     resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"" + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, strAttribute)) + "\"),");
73     String JavaDoc strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strProduct);
74     resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n");
75     resultado.append("new Array(\"inpquantityorder\", " + ((strQtyOrder==null || strQtyOrder=="")?"\"\"":strQtyOrder) + "), \n");
76     resultado.append("new Array(\"inpquantityorderbook\", " + ((strQtyOrder==null || strQtyOrder=="")?"\"\"":strQtyOrder) + "), \n");
77     resultado.append("new Array(\"inpqtycount\", " + ((strQty==null || strQty=="")?"\"\"":strQty) + "), \n");
78     resultado.append("new Array(\"inpqtybook\", " + ((strQty==null || strQty=="")?"\"\"":strQty) + "), \n");
79     resultado.append("new Array(\"inpmProductUomId\", ");
80     if (strPUOM.startsWith("\"")) strPUOM=strPUOM.substring(1,strPUOM.length()-1);
81     if (vars.getLanguage().equals("en_US")) {
82     FieldProvider [] tld = null;
83     try {
84         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLInventoryProduct"), Utility.getContext(this, vars, "#User_Client", "SLInventoryProduct"), 0);
85         Utility.fillSQLParameters(this, vars, null, comboTableData, "SLInventoryProduct", "");
86         tld = comboTableData.select(false);
87         comboTableData = null;
88     } catch (Exception JavaDoc ex) {
89         throw new ServletException(ex);
90     }
91
92       if (tld!=null && tld.length>0) {
93         resultado.append("new Array(");
94         for (int i=0;i<tld.length;i++) {
95           resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strPUOM)?"true":"false") + "\")");
96           if (i<tld.length-1) resultado.append(",\n");
97         }
98         resultado.append("\n)");
99       } else resultado.append("null");
100       resultado.append("\n),");
101     } else {
102     FieldProvider [] tld = null;
103     try {
104         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLInventoryProduct"), Utility.getContext(this, vars, "#User_Client", "SLInventoryProduct"), 0);
105         Utility.fillSQLParameters(this, vars, null, comboTableData, "SLInventoryProduct", "");
106         tld = comboTableData.select(false);
107         comboTableData = null;
108     } catch (Exception JavaDoc ex) {
109         throw new ServletException(ex);
110     }
111
112       if (tld!=null && tld.length>0) {
113         resultado.append("new Array(");
114         for (int i=0;i<tld.length;i++) {
115           resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strPUOM)?"true":"false") + "\")");
116           if (i<tld.length-1) resultado.append(",\n");
117         }
118         resultado.append("\n)");
119       } else resultado.append("null");
120       resultado.append("\n),");
121     }
122     resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
123     resultado.append(");");
124     xmlDocument.setParameter("array", resultado.toString());
125     xmlDocument.setParameter("frameName", "frameAplicacion");
126     response.setContentType("text/html; charset=UTF-8");
127     PrintWriter out = response.getWriter();
128     out.println(xmlDocument.print());
129     out.close();
130   }
131 }
132
Popular Tags