KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_callouts > SL_Internal_Consumption_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_Internal_Consumption_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 strLocator = vars.getStringParameter("inpmLocatorId");
46
String JavaDoc strPLocator = vars.getStringParameter("inpmProductId_LOC");
47       String JavaDoc strPAttr = vars.getStringParameter("inpmProductId_ATR");
48       String JavaDoc strPQty = vars.getStringParameter("inpmProductId_PQTY");
49       String JavaDoc strPUOM = vars.getStringParameter("inpmProductId_PUOM");
50       String JavaDoc strQty = vars.getStringParameter("inpmProductId_QTY");
51       String JavaDoc strUOM = vars.getStringParameter("inpmProductId_UOM");
52       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
53       
54       try {
55         printPage(response, vars, strChanged, strProduct, strPLocator, strPAttr, strPQty, strPUOM, strQty, strUOM, strTabId);
56       } catch (ServletException ex) {
57         pageErrorCallOut(response);
58       }
59     } else pageError(response);
60   }
61
62   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strChanged, String JavaDoc strProduct, String JavaDoc strPLocator, String JavaDoc strPAttr, String JavaDoc strPQty, String JavaDoc strPUOM, String JavaDoc strQty, String JavaDoc strUOM, String JavaDoc strTabId) throws IOException, ServletException {
63     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
64     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
65
66     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
67     resultado.append("var calloutName='SL_Internal_Consumption_Product';\n\n");
68     resultado.append("var respuesta = new Array(");
69     resultado.append("new Array(\"inpcUomId\", " + strUOM + "),\n");
70     if (strPLocator.startsWith("\"")) strPLocator=strPLocator.substring(1,strPLocator.length()-1);
71     resultado.append("new Array(\"inpmLocatorId\", \"" + strPLocator + "\"),\n");
72     resultado.append("new Array(\"inpmLocatorId_R\", \"" + FormatUtilities.replaceJS(SLInternalConsumptionProductData.selectLocator(this, strPLocator)) + "\"),\n");
73     String JavaDoc strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strProduct);
74     resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n");
75     if (strPAttr.startsWith("\"")) strPAttr=strPAttr.substring(1,strPAttr.length()-1);
76     resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + strPAttr + "\"),\n");
77     resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"" + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, strPAttr)) + "\"),\n");
78     resultado.append("new Array(\"inpmovementqty\", " + (strQty.equals("")?"\"\"":strQty) + "),\n");
79     resultado.append("new Array(\"inpquantityorder\", " + (strPQty.equals("")?"\"\"":strPQty) + "),\n");
80     if (strPUOM.startsWith("\"")) strPUOM=strPUOM.substring(1,strPUOM.length()-1);
81     resultado.append("new Array(\"inpmProductUomId\", ");
82     if (vars.getLanguage().equals("en_US")) {
83     FieldProvider [] tld = null;
84     try {
85         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLInternalConsumptionProduct"), Utility.getContext(this, vars, "#User_Client", "SLInternalConsumptionProduct"), 0);
86         Utility.fillSQLParameters(this, vars, null, comboTableData, "SLInternalConsumptionProduct", "");
87         tld = comboTableData.select(false);
88         comboTableData = null;
89     } catch (Exception JavaDoc ex) {
90         throw new ServletException(ex);
91     }
92
93       if (tld!=null && tld.length>0) {
94         resultado.append("new Array(");
95         for (int i=0;i<tld.length;i++) {
96           resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + ((tld[i].getField("id").equals(strPUOM))?"true":"false") + "\")");
97           if (i<tld.length-1) resultado.append(",\n");
98         }
99         resultado.append("\n)");
100       } else resultado.append("null");
101       resultado.append("\n),");
102     } else {
103     FieldProvider [] tld = null;
104     try {
105         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLInternalConsumptionProduct"), Utility.getContext(this, vars, "#User_Client", "SLInternalConsumptionProduct"), 0);
106         Utility.fillSQLParameters(this, vars, null, comboTableData, "SLInternalConsumptionProduct", "");
107         tld = comboTableData.select(false);
108         comboTableData = null;
109     } catch (Exception JavaDoc ex) {
110         throw new ServletException(ex);
111     }
112
113       if (tld!=null && tld.length>0) {
114         resultado.append("new Array(");
115         for (int i=0;i<tld.length;i++) {
116           resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + ((tld[i].getField("id").equals(strPUOM))?"true":"false") + "\")");
117           if (i<tld.length-1) resultado.append(",\n");
118         }
119         resultado.append("\n)");
120       } else resultado.append("null");
121       resultado.append("\n),");
122     }
123     resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
124     resultado.append(");");
125     xmlDocument.setParameter("array", resultado.toString());
126     xmlDocument.setParameter("frameName", "frameAplicacion");
127     response.setContentType("text/html; charset=UTF-8");
128     PrintWriter out = response.getWriter();
129     out.println(xmlDocument.print());
130     out.close();
131   }
132 }
133
Popular Tags