KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.*;
27 import java.math.BigDecimal JavaDoc;
28 import javax.servlet.*;
29 import javax.servlet.http.*;
30
31
32
33 public class SL_Internal_Consumption_Conversion extends HttpSecureAppServlet {
34   
35   static final BigDecimal JavaDoc ZERO = new BigDecimal JavaDoc(0.0);
36
37   public void init (ServletConfig config) {
38     super.init(config);
39     boolHist = false;
40   }
41
42
43   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
44     VariablesSecureApp vars = new VariablesSecureApp(request);
45     if (vars.commandIn("DEFAULT")) {
46       String JavaDoc strChanged = vars.getStringParameter("inpLastFieldChanged");
47       if (log4j.isDebugEnabled()) log4j.debug("CHANGED: " + strChanged);
48       String JavaDoc strUOM = vars.getStringParameter("inpcUomId");
49       String JavaDoc strMProductUOMID = vars.getStringParameter("inpmProductUomId");
50       String JavaDoc strQuantityOrder = vars.getStringParameter("inpquantityorder");
51       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
52       try {
53         printPage(response, vars, strChanged, strUOM, strMProductUOMID, strQuantityOrder, strTabId);
54       } catch (ServletException ex) {
55         pageErrorCallOut(response);
56       }
57     } else pageError(response);
58   }
59
60   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strChanged, String JavaDoc strUOM, String JavaDoc strMProductUOMID,String JavaDoc strQuantityOrder, String JavaDoc strTabId) throws IOException, ServletException {
61     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
62     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
63     if (strUOM.startsWith("\"")) strUOM=strUOM.substring(1,strUOM.length()-1);
64     int stdPrecision = Integer.valueOf(SLInvoiceConversionData.stdPrecision(this, strUOM)).intValue();
65     String JavaDoc strInitUOM = SLInvoiceConversionData.initUOMId (this, strMProductUOMID);
66     String JavaDoc strMultiplyRate;
67     boolean check = false;
68
69     strMultiplyRate = SLInvoiceConversionData.multiplyRate (this, strInitUOM, strUOM);
70     if (strInitUOM.equals(strUOM)) strMultiplyRate = "1";
71     if (strMultiplyRate.equals("")) strMultiplyRate = SLInvoiceConversionData.divideRate (this, strUOM, strInitUOM);
72     if (strMultiplyRate.equals("")) {
73       strMultiplyRate = "1";
74       if (!strMProductUOMID.equals("")) check = true;
75     }
76     
77
78     BigDecimal JavaDoc quantityOrder, qtyOrdered, multiplyRate;
79
80     multiplyRate = new BigDecimal JavaDoc(strMultiplyRate);
81
82     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
83     resultado.append("var calloutName='SL_Internal_Consumption_Conversion';\n\n");
84     resultado.append("var respuesta = new Array(");
85
86
87     if (!strQuantityOrder.equals("")) {
88       quantityOrder = new BigDecimal JavaDoc(strQuantityOrder);
89       qtyOrdered = new BigDecimal JavaDoc (quantityOrder.doubleValue()*multiplyRate.doubleValue());
90       if (qtyOrdered.scale() > stdPrecision) qtyOrdered = qtyOrdered.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);
91       resultado.append("new Array(\"inpmovementqty\", " + qtyOrdered.toString() + ")");
92     }
93     if (check) {
94       if (!strQuantityOrder.equals("")) resultado.append(",");
95       resultado.append("new Array('MESSAGE', \"" + FormatUtilities.replaceJS(Utility.messageBD(this, "NoUOMConversion", vars.getLanguage())) + "\")");
96     }
97     if (strMProductUOMID.equals("") && !strChanged.equals("inpquantityorder")){
98       if (!strQuantityOrder.equals("")) resultado.append(",");
99       resultado.append("new Array(\"inpquantityorder\", \"\")");
100     }
101     if (strQuantityOrder.equals("") && strChanged.equals("inpquantityorder") && !strMProductUOMID.equals("")){
102       resultado.append("new Array(\"inpmProductUomId\", \"\")");
103     }
104
105     resultado.append(");");
106     xmlDocument.setParameter("array", resultado.toString());
107     xmlDocument.setParameter("frameName", "frameAplicacion");
108     response.setContentType("text/html; charset=UTF-8");
109     PrintWriter out = response.getWriter();
110     out.println(xmlDocument.print());
111     out.close();
112   }
113 }
114
Popular Tags