KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.openbravo.erpCommon.utility.DateTimeData;
32 import org.openbravo.erpCommon.ad_combos.PriceListVersionComboData;
33
34 public class SL_Invoice_Amt extends HttpSecureAppServlet {
35   
36   static final BigDecimal JavaDoc ZERO = new BigDecimal JavaDoc(0.0);
37
38   public void init (ServletConfig config) {
39     super.init(config);
40     boolHist = false;
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 strQtyInvoice = vars.getStringParameter("inpqtyinvoiced");
49       String JavaDoc strPriceActual = vars.getStringParameter("inppriceactual");
50       String JavaDoc strPriceLimit = vars.getStringParameter("inppricelimit");
51       String JavaDoc strInvoiceId = vars.getStringParameter("inpcInvoiceId");
52       String JavaDoc strProduct = vars.getStringParameter("inpmProductId");
53       String JavaDoc strTabId = vars.getStringParameter("inpTabId");
54       String JavaDoc strPriceList = vars.getStringParameter("inppricelist");
55       
56       try {
57         printPage(response, vars, strChanged, strQtyInvoice, strPriceActual, strInvoiceId, strProduct, strPriceLimit, strTabId, strPriceList);
58       } catch (ServletException ex) {
59         pageErrorCallOut(response);
60       }
61     } else pageError(response);
62   }
63
64   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strChanged, String JavaDoc strQtyInvoice, String JavaDoc strPriceActual, String JavaDoc strInvoiceId, String JavaDoc strProduct, String JavaDoc strPriceLimit, String JavaDoc strTabId, String JavaDoc strPriceList) throws IOException, ServletException {
65     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
66     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_callouts/CallOut").createXmlDocument();
67     SLInvoiceAmtData[] data = SLInvoiceAmtData.select(this, strInvoiceId);
68     String JavaDoc strPrecision = "0", strPricePrecision="0";
69     boolean enforcedLimit=false;
70     if (data!=null && data.length>0) {
71       strPrecision = data[0].stdprecision;
72       strPricePrecision = data[0].priceprecision;
73       enforcedLimit = (data[0].enforcepricelimit.equals("Y")?true:false);
74     }
75     int StdPrecision = Integer.valueOf(strPrecision).intValue();
76     int PricePrecision = Integer.valueOf(strPricePrecision).intValue();
77
78     BigDecimal JavaDoc qtyInvoice, priceActual, LineNetAmt, priceLimit;
79
80     if (strQtyInvoice.equals("")) qtyInvoice=ZERO;
81     else qtyInvoice = new BigDecimal JavaDoc(strQtyInvoice);
82     if (strChanged.equals("inpqtyinvoiced")||strChanged.equals("inppricelist"))
83     {
84       if (log4j.isDebugEnabled()) log4j.debug("strPriceList: "+strPriceList.replace("\"", "")+" product:"+strProduct+" qty:"+strQtyInvoice);
85       strPriceActual = SLOrderProductData.getOffersPriceInvoice(this, data[0].dateinvoiced, data[0].cBpartnerId, strProduct, strPriceList.replace("\"", ""), strQtyInvoice, data[0].mPricelistId, data[0].id);
86     }
87
88     
89     if (strPriceActual.equals("")) strPriceActual = "0";
90     if (strPriceLimit.equals("")) strPriceLimit = "0";
91  
92     if (log4j.isDebugEnabled()) log4j.debug("strPriceActual: "+strPriceActual);
93     if (log4j.isDebugEnabled()) log4j.debug("strPriceLimit: "+strPriceLimit);
94     priceActual = (new BigDecimal JavaDoc(strPriceActual)).setScale(PricePrecision, BigDecimal.ROUND_HALF_UP);
95     priceLimit = (new BigDecimal JavaDoc(strPriceLimit)).setScale(PricePrecision, BigDecimal.ROUND_HALF_UP);
96
97
98     LineNetAmt = qtyInvoice.multiply(priceActual);
99
100     if (LineNetAmt.scale() > StdPrecision)
101       LineNetAmt = LineNetAmt.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
102
103
104     StringBuffer JavaDoc resultado = new StringBuffer JavaDoc();
105
106     resultado.append("var calloutName='SL_Invoice_Amt';\n\n");
107     resultado.append("var respuesta = new Array(");
108     if (enforcedLimit) {
109       String JavaDoc strPriceVersion = "";
110       PriceListVersionComboData[] data1 = PriceListVersionComboData.selectActual(this, data[0].mPricelistId, DateTimeData.today(this), Utility.getContext(this, vars, "#User_Client", "SLInvoiceAmt"));
111       if (data1!=null && data1.length>0) strPriceVersion = data1[0].mPricelistVersionId;
112       BigDecimal JavaDoc lineLimit = new BigDecimal JavaDoc(SLInvoiceAmtData.selectPriceLimit(this, strPriceVersion, strProduct));
113       if (priceLimit.doubleValue() != 0.0 && priceActual.compareTo(priceLimit) < 0) resultado.append("new Array('MESSAGE', \"" + FormatUtilities.replaceJS(Utility.messageBD(this, "UnderLimitPrice", vars.getLanguage())) + "\"), ");
114     }
115     resultado.append("new Array(\"inplinenetamt\", \"" + LineNetAmt.toString() + "\"),");
116     resultado.append("new Array(\"inppriceactual\", \"" + priceActual.toString() + "\")");
117     resultado.append(");");
118     xmlDocument.setParameter("array", resultado.toString());
119     xmlDocument.setParameter("frameName", "frameAplicacion");
120     response.setContentType("text/html; charset=UTF-8");
121     PrintWriter out = response.getWriter();
122     out.println(xmlDocument.print());
123
124
125     out.close();
126   }
127 }
128
Popular Tags