KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_reports > ReportRefundSalesDimensionalAnalysesPDF


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
20 package org.openbravo.erpCommon.ad_reports;
21
22 import org.openbravo.erpCommon.utility.Utility;
23 import org.openbravo.erpCommon.businessUtility.Tree;
24 import org.openbravo.erpCommon.businessUtility.TreeData;
25 import org.openbravo.base.secureApp.HttpSecureAppServlet;
26 import org.openbravo.base.secureApp.VariablesSecureApp;
27 import org.openbravo.xmlEngine.XmlDocument;
28 import java.io.*;
29 import java.util.*;
30 import javax.servlet.*;
31 import javax.servlet.http.*;
32
33 import org.openbravo.utils.Replace;
34
35 import org.openbravo.erpCommon.utility.DateTimeData;
36
37 public class ReportRefundSalesDimensionalAnalysesPDF extends HttpSecureAppServlet {
38
39
40   public void init (ServletConfig config) {
41     super.init(config);
42     boolHist = false;
43   }
44
45   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
46     VariablesSecureApp vars = new VariablesSecureApp(request);
47
48     if (!Utility.hasProcessAccess(this, vars, "", "RV_ReportRefundSalesDimensionalAnalyses")) {
49       bdError(response, "AccessTableNoView", vars.getLanguage());
50       return;
51     }
52
53     if (vars.commandIn("DEFAULT")){
54       String JavaDoc strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportRefundSalesDimensionalAnalyses|dateFrom");
55       String JavaDoc strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportRefundSalesDimensionalAnalyses|dateTo");
56       String JavaDoc strDateFromRef = vars.getRequestGlobalVariable("inpDateFromRef", "ReportRefundSalesDimensionalAnalyses|dateFromRef");
57       String JavaDoc strDateToRef = vars.getRequestGlobalVariable("inpDateToRef", "ReportRefundSalesDimensionalAnalyses|dateToRef");
58       String JavaDoc strPartnerGroup = vars.getRequestGlobalVariable("inpPartnerGroup", "ReportRefundSalesDimensionalAnalyses|partnerGroup");
59       String JavaDoc strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportRefundSalesDimensionalAnalyses|partner");
60       String JavaDoc strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ReportRefundSalesDimensionalAnalyses|productCategory");
61       String JavaDoc strmProductId = vars.getRequestInGlobalVariable("inpmProductId_IN", "ReportRefundSalesDimensionalAnalyses|product");
62       String JavaDoc strNotShown = vars.getInStringParameter("inpNotShown");
63       String JavaDoc strShown = vars.getInStringParameter("inpShown");
64       String JavaDoc strOrg = vars.getGlobalVariable("inpOrg", "ReportRefundSalesDimensionalAnalyses|org", "0");
65       String JavaDoc strsalesrepId = vars.getRequestGlobalVariable("inpSalesrepId", "ReportRefundSalesDimensionalAnalyses|salesrep");
66       String JavaDoc strmWarehouseId = vars.getRequestGlobalVariable("inpmWarehouseId", "ReportRefundSalesDimensionalAnalyses|warehouseId");
67       String JavaDoc strOrder = vars.getRequestGlobalVariable("inpOrder","ReportRefundSalesDimensionalAnalyses|order");
68       String JavaDoc strMayor = vars.getStringParameter("inpMayor", "");
69       String JavaDoc strMenor = vars.getStringParameter("inpMenor", "");
70       String JavaDoc strRatioMayor = vars.getStringParameter("inpRatioMayor", "");
71       String JavaDoc strRatioMenor = vars.getStringParameter("inpRatioMenor", "");
72       String JavaDoc strComparative = vars.getStringParameter("inpComparative", "N");
73       printPagePdf(response, vars, strComparative, strDateFrom, strDateTo, strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strNotShown, strShown, strDateFromRef, strDateToRef, strOrg, strsalesrepId, strmWarehouseId, strOrder, strMayor, strMenor, strRatioMayor, strRatioMenor);
74     } else pageErrorPopUp(response);
75   }
76
77   void printPagePdf(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strComparative, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strPartnerGroup, String JavaDoc strcBpartnerId, String JavaDoc strProductCategory, String JavaDoc strmProductId, String JavaDoc strNotShown, String JavaDoc strShown, String JavaDoc strDateFromRef, String JavaDoc strDateToRef, String JavaDoc strOrg, String JavaDoc strsalesrepId, String JavaDoc strmWarehouseId, String JavaDoc strOrder, String JavaDoc strMayor, String JavaDoc strMenor, String JavaDoc strRatioMayor, String JavaDoc strRatioMenor) throws IOException, ServletException{
78     if (log4j.isDebugEnabled()) log4j.debug("Output: print pdf");
79     XmlDocument xmlDocument=null;
80     String JavaDoc strOrderby = "";
81     if (log4j.isDebugEnabled()) log4j.debug("********************************"+strComparative);
82     String JavaDoc[] discard = {"", "", "", "", "","", ""};
83     String JavaDoc[] discard1={"selEliminarBody1", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard"};
84     if (strComparative.equals("Y")) discard1[0] = "selEliminarBody2";
85     String JavaDoc strTitle = "";
86     strTitle = Utility.messageBD(this, "From", vars.getLanguage()) + " "+strDateFrom+" " + Utility.messageBD(this, "To", vars.getLanguage()) + " "+strDateTo;
87     if (!strPartnerGroup.equals("")) strTitle = strTitle + ", " + Utility.messageBD(this, "ForBPartnerGroup", vars.getLanguage()) + " "+ReportRefundSalesDimensionalAnalysesData.selectBpgroup(this, strPartnerGroup);
88     if (!strProductCategory.equals("")) strTitle = strTitle+", " + Utility.messageBD(this, "ProductCategory", vars.getLanguage()) + " "+ReportRefundSalesDimensionalAnalysesData.selectProductCategory(this, strProductCategory);
89     if (!strsalesrepId.equals("")) strTitle = strTitle+" " + Utility.messageBD(this, "And", vars.getLanguage()) + " " + Utility.messageBD(this, "TheSalesRep", vars.getLanguage()) + " "+ReportRefundSalesDimensionalAnalysesData.selectSalesrep(this, strsalesrepId);
90     if (!strmWarehouseId.equals("")) strTitle = strTitle+" " + Utility.messageBD(this, "And", vars.getLanguage()) + " " + Utility.messageBD(this, "TheWarehouse", vars.getLanguage()) + " "+ReportRefundSalesDimensionalAnalysesData.selectMwarehouse(this, strmWarehouseId);
91
92     ReportRefundSalesDimensionalAnalysesData[] data = null;
93     String JavaDoc[] strShownArray = {"", "", "", "", "", "", ""};
94     if (strShown.startsWith("(")) strShown = strShown.substring(1, strShown.length()-1);
95     if (!strShown.equals("")) {
96       strShown = Replace.replace(strShown, "'", "");
97       strShown = Replace.replace(strShown, " ", "");
98       StringTokenizer st = new StringTokenizer(strShown, ",", false);
99       int intContador = 0;
100       while (st.hasMoreTokens()){
101         strShownArray[intContador] = st.nextToken();
102         intContador++;
103       }
104
105     }
106     String JavaDoc[] strTextShow = {"", "", "", "", "","", ""};
107     int intDiscard = 0;
108     int intAuxDiscard = -1;
109     for (int i = 0; i<7; i++){
110       if (strShownArray[i].equals("1")) {
111         strTextShow[i] = "C_BP_GROUP.NAME";
112         discard[i] = "10";
113         intDiscard++;
114       }
115       else if (strShownArray[i].equals("2")) {
116         strTextShow[i] = "AD_COLUMN_IDENTIFIER('C_Bpartner', TO_CHAR(C_BPARTNER.C_BPARTNER_ID), 'es_ES')";
117         discard[i] = "10";
118         intDiscard++;
119       }
120       else if (strShownArray[i].equals("3")) {
121         strTextShow[i] = "M_PRODUCT_CATEGORY.NAME";
122         discard[i] = "10";
123         intDiscard++;
124       }
125       else if (strShownArray[i].equals("4")) {
126         strTextShow[i] = "AD_COLUMN_IDENTIFIER('M_Product', TO_CHAR(M_PRODUCT.M_PRODUCT_ID), 'es_ES')";
127         discard[i] = "10";
128         intAuxDiscard = i;
129       }
130       else if (strShownArray[i].equals("5")) {
131         strTextShow[i] = "C_ORDER.DOCUMENTNO";
132         discard[i] = "10";
133         intDiscard++;
134       }
135       else if (strShownArray[i].equals("6")) {
136         strTextShow[i] = "AD_USER.FIRSTNAME||' '||' '||AD_USER.LASTNAME";
137         discard[i] = "10";
138         intDiscard++;
139       }
140       else if (strShownArray[i].equals("7")) {
141         strTextShow[i] = "M_WAREHOUSE.NAME";
142         discard[i] = "10";
143         intDiscard++;
144       }
145       else {
146         strTextShow[i] = "''";
147         discard[i] = "0.1";
148       }
149     }
150     if (intDiscard != 0){
151       int k=1;
152       strOrderby = " ORDER BY NIVEL"+k+",";
153       while (k<intDiscard){
154         strOrderby = strOrderby+"NIVEL"+k+",";
155         k++;
156       }
157       if (k==1){
158         if (strOrder.equals("Normal")){
159           strOrderby = " ORDER BY NIVEL"+k;
160         } else if (strOrder.equals("Amountasc")){
161           strOrderby = " ORDER BY LINENETAMT ASC";
162         } else if (strOrder.equals("Amountdesc")){
163           strOrderby = " ORDER BY LINENETAMT DESC";
164         } else if (strOrder.equals("Ratioasc")){
165           strOrderby = " ORDER BY RATIO ASC";
166         } else if (strOrder.equals("Ratiodesc")){
167           strOrderby = " ORDER BY RATIO DESC";
168         } else{
169           strOrderby = "1";
170         }
171       } else{
172         if (strOrder.equals("Normal")){
173           strOrderby += "NIVEL"+k;
174         } else if (strOrder.equals("Amountasc")){
175           strOrderby += "LINENETAMT ASC";
176         } else if (strOrder.equals("Amountdesc")){
177           strOrderby += "LINENETAMT DESC";
178         } else if (strOrder.equals("Ratioasc")){
179           strOrderby += "RATIO ASC";
180         } else if (strOrder.equals("Ratiodesc")){
181           strOrderby += "RATIO DESC";
182         } else{
183           strOrderby = "1";
184         }
185       }
186
187     } else{
188       strOrderby = " ORDER BY 1";
189     }
190     String JavaDoc strHaving = "";
191     if (!strMayor.equals("") && !strMenor.equals("")) {strHaving = " HAVING SUM(LINENETAMT) > "+strMayor+" AND SUM(LINENETAMT) < "+strMenor;}
192     else if (!strMayor.equals("") && strMenor.equals("")) {strHaving = " HAVING SUM(LINENETAMT) > "+strMayor;}
193     else if (strMayor.equals("") && !strMenor.equals("")) {strHaving = " HAVING SUM(LINENETAMT) < "+strMenor;}
194     else{}
195     if (strHaving.equals("")){
196       if (!strRatioMayor.equals("") && !strRatioMenor.equals("")) {strHaving = " HAVING DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 > "+strRatioMayor+" AND DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 < "+strRatioMenor;}
197       else if (!strRatioMayor.equals("") && strRatioMenor.equals("")) {strHaving = " HAVING DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 > "+strRatioMayor;}
198       else if (strRatioMayor.equals("") && !strRatioMenor.equals("")) {strHaving = " HAVING DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 < "+strRatioMenor;}
199       else{}
200     } else {
201       if (!strRatioMayor.equals("") && !strRatioMenor.equals("")) {strHaving = " AND DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 > "+strRatioMayor+" AND DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 < "+strRatioMenor;}
202       else if (!strRatioMayor.equals("") && strRatioMenor.equals("")) {strHaving = " AND DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 > "+strRatioMayor;}
203       else if (strRatioMayor.equals("") && !strRatioMenor.equals("")) {strHaving = " AND DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 < "+strRatioMenor;}
204       else{}
205     }
206     strOrderby = strHaving + strOrderby;
207     if (log4j.isDebugEnabled()) log4j.debug("*******************PDF"+strOrderby);
208     if (strComparative.equals("Y")){
209       data = ReportRefundSalesDimensionalAnalysesData.select(this, strTextShow[0], strTextShow[1], strTextShow[2], strTextShow[3], strTextShow[4], strTextShow[5], strTextShow[6], Tree.getMembers(this, TreeData.getTreeOrg(this, vars.getClient()), strOrg), Utility.getContext(this, vars, "#User_Client", "ReportRefundSalesDimensionalAnalyses"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strsalesrepId, strmWarehouseId, strDateFromRef, DateTimeData.nDaysAfter(this, strDateToRef,"1"), strOrderby);
210     } else {
211       data = ReportRefundSalesDimensionalAnalysesData.selectNoComparative(this, strTextShow[0], strTextShow[1], strTextShow[2], strTextShow[3], strTextShow[4], strTextShow[5], strTextShow[6], Tree.getMembers(this, TreeData.getTreeOrg(this, vars.getClient()), strOrg), Utility.getContext(this, vars, "#User_Client", "ReportRefundSalesDimensionalAnalyses"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strsalesrepId, strmWarehouseId, strOrderby);
212     }
213     if (data.length == 0 || data == null){
214      
215       data = ReportRefundSalesDimensionalAnalysesData.set();
216     } else {
217       int contador = intDiscard;
218       if (intAuxDiscard != -1) contador = intAuxDiscard;
219       int k = 1;
220       if (strComparative.equals("Y")){
221         for (int j = contador; j>0; j--){
222           discard1[k] = "fieldTotalQtyNivel"+String.valueOf(j);
223           discard1[k+12] = "fieldTotalRefundQtyNivel"+String.valueOf(j);
224           discard1[k+24] = "fieldUomsymbol"+String.valueOf(j);
225           discard1[k+6] = "fieldTotalRefQtyNivel"+String.valueOf(j);
226           discard1[k+18] = "fieldTotalRefRefundQtyNivel"+String.valueOf(j);
227           k++;
228         }
229       } else {
230         for (int j = contador; j>0; j--){
231           discard1[k] = "fieldNoncomparativeTotalQtyNivel"+String.valueOf(j);
232           discard1[k+10] = "fieldNoncomparativeTotalRefundQtyNivel"+String.valueOf(j);
233           discard1[k+20] = "fieldNoncomparativeUomsymbol"+String.valueOf(j);
234           k++;
235         }
236       }
237
238     }
239     xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportRefundSalesDimensionalAnalysesEditionPDF", discard1).createXmlDocument();
240
241     xmlDocument.setParameter("eliminar2", discard[1]);
242     xmlDocument.setParameter("eliminar3", discard[2]);
243     xmlDocument.setParameter("eliminar4", discard[3]);
244     xmlDocument.setParameter("eliminar5", discard[4]);
245     xmlDocument.setParameter("eliminar6", discard[5]);
246     xmlDocument.setParameter("eliminar7", discard[6]);
247     xmlDocument.setParameter("title", strTitle);
248     xmlDocument.setParameter("constante", "100");
249     if (strComparative.equals("Y")){
250       xmlDocument.setData("structure1", data);
251     } else {
252       xmlDocument.setData("structure2", data);
253     }
254     String JavaDoc strResult = xmlDocument.print();
255     renderFO(strResult, response);
256   }
257
258   public String JavaDoc getServletInfo() {
259     return "Servlet ReportRefundSalesDimensionalAnalyses. This Servlet was made by Jon Alegría";
260   } // end of getServletInfo() method
261
}
262
263
Popular Tags