KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_actionButton > CopyFromPOOrder


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_actionButton;
20
21 import org.openbravo.erpCommon.utility.SequenceIdData;
22 import org.openbravo.erpCommon.utility.*;
23 import org.openbravo.utils.FormatUtilities;
24 import org.openbravo.erpCommon.ad_callouts.*;
25 import org.openbravo.erpCommon.businessUtility.*;
26 import org.openbravo.base.secureApp.HttpSecureAppServlet;
27 import org.openbravo.base.secureApp.VariablesSecureApp;
28 import org.openbravo.xmlEngine.XmlDocument;
29 import java.io.*;
30 import java.math.BigDecimal JavaDoc;
31 import javax.servlet.*;
32 import javax.servlet.http.*;
33
34 //mports for transactions
35
//import org.openbravo.base.ConnectionProvider;
36
import java.sql.Connection JavaDoc;
37
38 import org.openbravo.erpCommon.utility.DateTimeData;
39
40 public class CopyFromPOOrder extends HttpSecureAppServlet {
41   static final BigDecimal JavaDoc ZERO = new BigDecimal JavaDoc(0.0);
42
43   public void init (ServletConfig config) {
44     super.init(config);
45     boolHist = false;
46   }
47
48   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
49     VariablesSecureApp vars = new VariablesSecureApp(request);
50
51     if (vars.commandIn("DEFAULT")) {
52       String JavaDoc strProcessId = vars.getStringParameter("inpProcessId");
53       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
54       String JavaDoc strTab = vars.getStringParameter("inpTabId");
55       String JavaDoc strKey = vars.getRequiredGlobalVariable("inpcOrderId", strWindow + "|C_Order_ID");
56       printPage(response, vars, strKey, strWindow, strTab, strProcessId);
57     } else if (vars.commandIn("SAVE")) {
58       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
59       String JavaDoc strOrder = vars.getStringParameter("inpcOrderId");
60       String JavaDoc strKey = vars.getRequestGlobalVariable("inpKey", strWindow + "|C_Order_ID");
61       String JavaDoc strTab = vars.getStringParameter("inpTabId");
62       ActionButtonDefaultData[] tab = ActionButtonDefaultData.windowName(this, strTab);
63       String JavaDoc strWindowPath="", strTabName="";
64       if (tab!=null && tab.length!=0) {
65         strTabName = FormatUtilities.replace(tab[0].name);
66         if (tab[0].help.equals("Y")) strWindowPath="../utility/WindowTree_FS.html?inpTabId=" + strTab;
67         else strWindowPath = "../" + FormatUtilities.replace(tab[0].description) + "/" + strTabName + "_Relation.html";
68       } else strWindowPath = strDefaultServlet;
69       String JavaDoc messageResult = processButton(vars, strKey, strOrder, strWindow);
70       vars.setSessionValue(strWindow + "|" + strTabName + ".message", messageResult);
71       printPageClosePopUp(response, vars, strWindowPath);
72     } else pageErrorPopUp(response);
73   }
74
75
76   String JavaDoc processButton(VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strOrder, String JavaDoc windowId) {
77     String JavaDoc priceactual = "";
78     String JavaDoc pricelist = "";
79     String JavaDoc pricelimit = "";
80     String JavaDoc strPrecision = "0";
81     String JavaDoc strPricePrecision="0";
82     String JavaDoc strDiscount = "";
83     Connection JavaDoc conn = null;
84     try {
85       conn = getTransactionConnection();
86       CopyFromPOOrderData[] data = CopyFromPOOrderData.selectLines(this, strOrder);
87       CopyFromPOOrderData[] order = CopyFromPOOrderData.select(this, strKey);
88       for (int i=0;data!=null && i<data.length;i++){
89           SEExpenseProductData[] data3 = SEExpenseProductData.select(this, data[i].mProductId, order[0].mPricelistId.equals("")?CopyFromPOOrderData.defaultPriceList(this):order[0].mPricelistId);
90           for (int j=0;data3!=null && j<data3.length;j++) {
91             if (data3[j].validfrom == null || data3[j].validfrom.equals("") || !DateTimeData.compare(this, DateTimeData.today(this), data3[j].validfrom).equals("-1")){
92             priceactual = data3[j].pricestd;
93             pricelist = data3[j].pricelist;
94             pricelimit = data3[j].pricelimit;
95             SLOrderAmtData[] data4 = SLOrderAmtData.select(this, strKey);
96               if (data4!=null && data4.length>0) {
97               strPrecision = data4[0].stdprecision.equals("")?"0":data4[0].stdprecision;
98               strPricePrecision = data4[0].priceprecision.equals("")?"0":data4[0].priceprecision;
99               }
100             int StdPrecision = Integer.valueOf(strPrecision).intValue();
101             int PricePrecision = Integer.valueOf(strPricePrecision).intValue();
102
103             BigDecimal JavaDoc priceActual, priceList, discount;
104
105             priceActual = (priceactual.equals("")?ZERO:(new BigDecimal JavaDoc(priceactual))).setScale(PricePrecision, BigDecimal.ROUND_HALF_UP);
106             priceList = (pricelist.equals("")?ZERO:new BigDecimal JavaDoc(pricelist));
107             if (priceList.doubleValue() == 0.0) discount = ZERO;
108             else discount = new BigDecimal JavaDoc ((priceList.doubleValue() - priceActual.doubleValue()) / priceList.doubleValue() * 100.0);
109             if (discount.scale() > StdPrecision) discount = discount.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
110             strDiscount = discount.toString();
111             priceactual = priceActual.toString();
112             pricelist = priceList.toString();
113             }
114           }
115           if (priceactual.equals("")) priceactual="0";
116           if (pricelist.equals("")) pricelist="0";
117           if (pricelimit.equals("")) pricelimit="0";
118           int line = 0;
119           String JavaDoc strCTaxID = Tax.get(this, data[i].mProductId, DateTimeData.today(this), order[0].adOrgId, order[0].mWarehouseId.equals("")?vars.getWarehouse():order[0].mWarehouseId, CopyFromPOOrderData.cBPartnerLocationId(this, order[0].cBpartnerId), CopyFromPOOrderData.cBPartnerLocationId(this, order[0].cBpartnerId), order[0].cProjectId, true);
120           line = Integer.valueOf(order[0].line.equals("")?"0":order[0].line).intValue() + ((i+1) * 10);
121           String JavaDoc strCOrderlineID = SequenceIdData.getSequence(this, "C_OrderLine", vars.getClient());
122           CopyFromPOOrderData.insertCOrderline(conn, this, strCOrderlineID, order[0].adClientId, order[0].adOrgId, vars.getUser(),
123           strKey, Integer.toString(line), order[0].cBpartnerId,
124           order[0].cBpartnerLocationId.equals("")?ExpenseSOrderData.cBPartnerLocationId(this,
125           order[0].cBpartnerId):order[0].cBpartnerLocationId, DateTimeData.today(this), DateTimeData.today(this), data[i].description,
126           data[i].mProductId, order[0].mWarehouseId.equals("")?vars.getWarehouse():order[0].mWarehouseId, data[i].cUomId, data[i].qtyordered, data[i].quantityorder,
127           data[i].cCurrencyId, pricelist, priceactual, pricelimit, strCTaxID, strDiscount, data[i].mProductUomId, data[i].orderline);
128       }
129       releaseCommitConnection(conn);
130       return Utility.messageBD(this, "ProcessOK", vars.getLanguage());
131     } catch (Exception JavaDoc e) {
132       log4j.warn(e);
133       try {
134         releaseRollbackConnection(conn);
135       } catch (Exception JavaDoc ignored) {}
136       return Utility.messageBD(this, "ProcessRunError", vars.getLanguage());
137     }
138   }
139
140
141   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc windowId, String JavaDoc strTab, String JavaDoc strProcessId)
142     throws IOException, ServletException {
143       if (log4j.isDebugEnabled()) log4j.debug("Output: Button process Copy lines");
144       ActionButtonDefaultData[] data = null;
145       String JavaDoc strHelp="", strDescription="";
146       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
147       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(),strProcessId);
148       if (data!=null && data.length!=0) {
149         strDescription = data[0].description;
150         strHelp = data[0].help;
151       }
152       String JavaDoc[] discard = {""};
153       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
154       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CopyFromPOOrder", discard).createXmlDocument();
155       xmlDocument.setParameter("key", strKey);
156       xmlDocument.setParameter("window", windowId);
157       xmlDocument.setParameter("tab", strTab);
158       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
159       xmlDocument.setParameter("question", Utility.messageBD(this, "StartProcess?", vars.getLanguage()));
160       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
161       xmlDocument.setParameter("description", strDescription);
162       xmlDocument.setParameter("help", strHelp);
163       response.setContentType("text/html");
164       PrintWriter out = response.getWriter();
165       out.println(xmlDocument.print());
166       out.close();
167     }
168
169   public String JavaDoc getServletInfo() {
170     return "Servlet Copy from order";
171   } // end of the getServletInfo() method
172
}
173
174
Popular Tags