KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_callouts > SL_CreateFromMultiple_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_CreateFromMultiple_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 strLocator = vars.getStringParameter("inpmProductId_LOC");
45       String JavaDoc strQty = vars.getStringParameter("inpmProductId_QTY");
46       String JavaDoc strUOM = vars.getStringParameter("inpmProductId_UOM");
47       String JavaDoc strAttribute = vars.getStringParameter("inpmProductId_ATR");
48       String JavaDoc strQtyOrder = vars.getStringParameter("inpmProductId_PQTY");
49       String JavaDoc strPUOM = vars.getStringParameter("inpmProductId_PUOM");
50       String JavaDoc strMProductID = vars.getStringParameter("inpmProductId");
51       String JavaDoc strWindowId = vars.getStringParameter("inpWindowId");
52       String JavaDoc strIsSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId);
53       String JavaDoc strWharehouse = Utility.getContext(this, vars, "#M_Warehouse_ID", strWindowId);
54       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
55       
56       try {
57         printPage(response, vars, strLocator, strQty, strUOM, strAttribute, strQtyOrder, strPUOM, strMProductID, strIsSOTrx, strWharehouse, strTabId);
58       } catch (ServletException ex) {
59         pageErrorCallOut(response);
60       }
61     } else pageError(response);
62   }
63
64   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strLocator, String JavaDoc strQty, String JavaDoc strUOM, String JavaDoc strAttribute, String JavaDoc strQtyOrder, String JavaDoc strPUOM, String JavaDoc strMProductID, String JavaDoc strIsSOTrx, String JavaDoc strWharehouse, String JavaDoc strTabId) throws IOException, ServletException {
65     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
66     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
67
68     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
69     resultado.append("var frameDefault='frameButton';\n\n");
70     resultado.append("var calloutName='SL_CreateFromMultiple_Product';\n\n");
71     resultado.append("var respuesta = new Array(");
72     /*if (strIsSOTrx.equals("Y")) {
73       if (strLocator.startsWith("\"")) strLocator=strLocator.substring(1,strLocator.length()-1);
74       resultado.append("new Array(\"inpmLocatorId\", \"" + strLocator + "\"),");
75       resultado.append("new Array(\"inpmLocatorId_R\", \"" + SLInOutLineProductData.locator(this, strLocator, vars.getLanguage()) + "\"),");
76       if (strAttribute.startsWith("\"")) strAttribute=strAttribute.substring(1,strAttribute.length()-1);
77       resultado.append("new Array(\"inpmAttributesetinstanceId\", \"" + strAttribute + "\"),");
78       resultado.append("new Array(\"inpmAttributesetinstanceId_R\", \"" + SLInOutLineProductData.attribute(this, strAttribute) + "\"),");
79       resultado.append("new Array(\"inpquantityorder\", " + (strQtyOrder.equals("")?"\"\"":strQtyOrder) + "),");
80       resultado.append("new Array(\"inpmovementqty\", " + (strQty.equals("")?"\"\"":strQty) + "),");
81     }*/

82     String JavaDoc strHasSecondaryUOM = SLOrderProductData.hasSecondaryUOM(this, strMProductID);
83     resultado.append("new Array(\"inphasseconduom\", " + strHasSecondaryUOM + "),\n");
84     resultado.append("new Array(\"inpmProductUomId\", ");
85     if (strPUOM.startsWith("\"")) strPUOM=strPUOM.substring(1,strPUOM.length()-1);
86     if (vars.getLanguage().equals("en_US")) {
87     FieldProvider [] tld = null;
88     try {
89         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLCreateFromMultipleProduct"), Utility.getContext(this, vars, "#User_Client", "SLCreateFromMultipleProduct"), 0);
90         Utility.fillSQLParameters(this, vars, null, comboTableData, "SLCreateFromMultipleProduct", "");
91         tld = comboTableData.select(false);
92         comboTableData = null;
93     } catch (Exception JavaDoc ex) {
94         throw new ServletException(ex);
95     }
96
97       if (tld!=null && tld.length>0) {
98         resultado.append("new Array(");
99         for (int i=0;i<tld.length;i++) {
100           resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strPUOM)?"true":"false") + "\")");
101           if (i<tld.length-1) resultado.append(",\n");
102         }
103         resultado.append("\n)");
104       } else resultado.append("null");
105       resultado.append("\n),");
106     } else {
107     FieldProvider [] tld = null;
108     try {
109         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLE", "", "M_Product_UOM", "", Utility.getContext(this, vars, "#User_Org", "SLCreateFromMultipleProduct"), Utility.getContext(this, vars, "#User_Client", "SLCreateFromMultipleProduct"), 0);
110         Utility.fillSQLParameters(this, vars, null, comboTableData, "SLCreateFromMultipleProduct", "");
111         tld = comboTableData.select(false);
112         comboTableData = null;
113     } catch (Exception JavaDoc ex) {
114         throw new ServletException(ex);
115     }
116
117       if (tld!=null && tld.length>0) {
118         resultado.append("new Array(");
119         for (int i=0;i<tld.length;i++) {
120           resultado.append("new Array(\"" + tld[i].getField("id") + "\", \"" + FormatUtilities.replaceJS(tld[i].getField("name")) + "\", \"" + (tld[i].getField("id").equalsIgnoreCase(strPUOM)?"true":"false") + "\")");
121           if (i<tld.length-1) resultado.append(",\n");
122         }
123         resultado.append("\n)");
124       } else resultado.append("null");
125       resultado.append("\n),");
126     }
127     resultado.append("new Array(\"inpcUomId\", " + (strUOM.equals("")?"\"\"":strUOM) + "),\n");
128     resultado.append("new Array(\"EXECUTE\", \"displayLogic();\")\n");
129
130
131     resultado.append(");");
132
133     if (log4j.isDebugEnabled()) log4j.debug("Array: " + resultado.toString());
134     xmlDocument.setParameter("array", resultado.toString());
135     xmlDocument.setParameter("frameName", "frameButton");
136     response.setContentType("text/html; charset=UTF-8");
137     PrintWriter out = response.getWriter();
138     out.println(xmlDocument.print());
139     out.close();
140   }
141 }
142
Popular Tags