KickJava   Java API By Example, From Geeks To Geeks.

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


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 ReportInvoiceCustomerDimensionalPDF 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_ReportInvoiceCustomerDimensionalAnaly")) {
49       bdError(response, "AccessTableNoView", vars.getLanguage());
50       return;
51     }
52
53     if (vars.commandIn("DEFAULT")){
54       String JavaDoc strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportInvoiceCustomerDimensionalAnalyses|dateFrom");
55       String JavaDoc strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportSInvoiceCustomerDimensionalAnalyses|dateTo");
56       String JavaDoc strDateFromRef = vars.getRequestGlobalVariable("inpDateFromRef", "ReportInvoiceCustomerDimensionalAnalyses|dateFromRef");
57       String JavaDoc strDateToRef = vars.getRequestGlobalVariable("inpDateToRef", "ReportSInvoiceCustomerDimensionalAnalyses|dateToRef");
58       String JavaDoc strPartnerGroup = vars.getRequestGlobalVariable("inpPartnerGroup", "ReportInvoiceCustomerDimensionalAnalyses|partnerGroup");
59       String JavaDoc strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportInvoiceCustomerDimensionalAnalyses|partner");
60       String JavaDoc strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ReportInvoiceCustomerDimensionalAnalyses|productCategory");
61       String JavaDoc strmProductId = vars.getRequestInGlobalVariable("inpmProductId_IN", "ReportInvoiceCustomerDimensionalAnalyses|product");
62       String JavaDoc strNotShown = vars.getInStringParameter("inpNotShown");
63       String JavaDoc strShown = vars.getInStringParameter("inpShown");
64       String JavaDoc strOrg = vars.getGlobalVariable("inpOrg", "ReportInvoiceCustomerDimensionalAnalyses|org", "0");
65       String JavaDoc strsalesrepId = vars.getRequestGlobalVariable("inpSalesrepId", "ReportInvoiceCustomerDimensionalAnalyses|salesrep");
66       String JavaDoc strOrder = vars.getRequestGlobalVariable("inpOrder","ReportInvoiceCustomerDimensionalAnalyses|order");
67       String JavaDoc strcProjectId = vars.getRequestGlobalVariable("inpcProjectId", "ReportInvoiceCustomerDimensionalAnalyses|project");
68       String JavaDoc strProducttype = vars.getRequestGlobalVariable("inpProducttype", "ReportInvoiceVendorDimensionalAnalyses|producttype");
69       String JavaDoc strMayor = vars.getStringParameter("inpMayor", "");
70       String JavaDoc strMenor = vars.getStringParameter("inpMenor", "");
71       String JavaDoc strComparative = vars.getStringParameter("inpComparative", "N");
72       String JavaDoc strPartnerSalesrepId = vars.getRequestGlobalVariable("inpPartnerSalesrepId", "ReportInvoiceCustomerDimensionalAnalyses|partnersalesrep");
73       printPagePdf(response, vars, strComparative, strDateFrom, strDateTo, strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strNotShown, strShown,
74           strDateFromRef, strDateToRef, strOrg, strsalesrepId, strOrder, strcProjectId, strProducttype, strMayor, strMenor, strPartnerSalesrepId);
75     } else pageErrorPopUp(response);
76   }
77
78   void printPagePdf(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strComparative, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strPartnerGroup, String JavaDoc
79       strcBpartnerId, String JavaDoc strProductCategory, String JavaDoc strmProductId, String JavaDoc strNotShown, String JavaDoc strShown, String JavaDoc strDateFromRef, String JavaDoc strDateToRef, String JavaDoc strOrg, String JavaDoc
80       strsalesrepId, String JavaDoc strOrder, String JavaDoc strcProjectId, String JavaDoc strProducttype, String JavaDoc strMayor, String JavaDoc strMenor, String JavaDoc strPartnerSalesrepId) throws IOException, ServletException{
81     if (log4j.isDebugEnabled()) log4j.debug("Output: print pdf");
82     XmlDocument xmlDocument=null;
83     String JavaDoc strPage = "basicPSMSecond";
84     String JavaDoc strOrderby = "";
85     String JavaDoc[] discard = {"", "", "", "", "","", "", "", "", ""};
86     String JavaDoc[] discard1={"selEliminarBody1", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard",
87       "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard",
88       "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard",
89       "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard",
90       "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard",
91       "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard",
92       "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard",
93       "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard", "discard",
94       "discard", "discard", "discard"};
95     if (strComparative.equals("Y")) {
96       discard1[0] = "selEliminarBody2";
97       strPage = "basicPSM";
98     }
99     String JavaDoc strTitle = "";
100     strTitle = Utility.messageBD(this, "From", vars.getLanguage()) + " "+strDateFrom+" " + Utility.messageBD(this, "To", vars.getLanguage()) + " "+strDateTo;
101     if (!strPartnerGroup.equals("")) strTitle = strTitle + ", " + Utility.messageBD(this, "ForBPartnerGroup", vars.getLanguage()) + " "+ReportRefundInvoiceCustomerDimensionalAnalysesData.selectBpgroup(this, strPartnerGroup);
102     //if (!strcBpartnerId.equals("")) strTitle = strTitle+", para el tercero "+ReportRefundInvoiceCustomerDimensionalAnalysesData.selectBpartner(this, strcBpartnerId);
103
if (!strProductCategory.equals("")) strTitle = strTitle+", " + Utility.messageBD(this, "ProductCategory", vars.getLanguage()) + " "+ReportInvoiceCustomerDimensionalAnalysesData.selectProductCategory(this, strProductCategory);
104     if (!strcProjectId.equals("")) strTitle = strTitle+", " + Utility.messageBD(this, "Project", vars.getLanguage()) + " "+ReportInvoiceCustomerDimensionalAnalysesData.selectProject(this, strcProjectId);
105     if (!strProducttype.equals("")) strTitle = strTitle+", " + Utility.messageBD(this, "PRODUCTTYPE", vars.getLanguage()) + " "+ReportInvoiceCustomerDimensionalAnalysesData.selectProducttype(this, "270", vars.getLanguage(), strProducttype);
106     if (!strsalesrepId.equals("")) strTitle = strTitle+", " + Utility.messageBD(this, "TheSalesRep", vars.getLanguage()) + " "+ReportRefundInvoiceCustomerDimensionalAnalysesData.selectSalesrep(this, strsalesrepId);
107     if (!strPartnerSalesrepId.equals("")) strTitle = strTitle+", " + Utility.messageBD(this, "TheClientSalesRep", vars.getLanguage()) + " "+ReportRefundInvoiceCustomerDimensionalAnalysesData.selectSalesrep(this, strPartnerSalesrepId);
108     ReportInvoiceCustomerDimensionalAnalysesData[] data = null;
109     String JavaDoc[] strShownArray = {"", "", "", "", "", "", "", "", "", ""};
110     if (strShown.startsWith("(")) strShown = strShown.substring(1, strShown.length()-1);
111     if (!strShown.equals("")) {
112       strShown = Replace.replace(strShown, "'", "");
113       strShown = Replace.replace(strShown, " ", "");
114       StringTokenizer st = new StringTokenizer(strShown, ",", false);
115       int intContador = 0;
116       while (st.hasMoreTokens()){
117         strShownArray[intContador] = st.nextToken();
118         intContador++;
119       }
120
121     }
122     String JavaDoc[] strTextShow = {"", "", "", "", "","", "", "", "", ""};
123     int intDiscard = 0;
124     int intOrder = 0;
125     int intAuxDiscard = -1;
126     String JavaDoc strEliminateQty = " ";
127     String JavaDoc strEliminateQtyRef = " ";
128     String JavaDoc strEliminateQtyAvg = " ";
129     //String strEliminateWeight = " ";
130
//String strEliminateWeightRef = " ";
131
for (int i = 0; i<10; i++){
132       if (strShownArray[i].equals("1")) {
133         strTextShow[i] = "C_BP_GROUP.NAME";
134         discard[i] = "10";
135         intDiscard++;
136         intOrder++;
137       }
138       else if (strShownArray[i].equals("2")) {
139         strTextShow[i] = "AD_COLUMN_IDENTIFIER('C_Bpartner', TO_CHAR(C_BPARTNER.C_BPARTNER_ID), 'es_ES')";
140         discard[i] = "10";
141         intDiscard++;
142         intOrder++;
143       }
144       else if (strShownArray[i].equals("3")) {
145         strTextShow[i] = "M_PRODUCT_CATEGORY.NAME";
146         discard[i] = "10";
147         intDiscard++;
148         intOrder++;
149       }
150       else if (strShownArray[i].equals("4")) {
151         strTextShow[i] = "AD_COLUMN_IDENTIFIER('M_Product', TO_CHAR(M_PRODUCT.M_PRODUCT_ID), 'es_ES')||' ('||UOMSYMBOL||')'";
152         discard[i] = "10";
153         strEliminateQty = "Cant";
154         strEliminateQtyRef = "Cant ref";
155         strEliminateQtyAvg = "%cant";
156         //strEliminateWeight = "Peso";
157
//strEliminateWeightRef = "Peso ref";
158
intAuxDiscard = i;
159         intOrder++;
160       }
161       else if (strShownArray[i].equals("5")) {
162         strTextShow[i] = "C_INVOICE.DOCUMENTNO";
163         discard[i] = "10";
164         intDiscard++;
165         intOrder++;
166       }
167       else if (strShownArray[i].equals("6")) {
168         strTextShow[i] = "AD_USER.FIRSTNAME||' '||' '||AD_USER.LASTNAME";
169         discard[i] = "10";
170         intDiscard++;
171         intOrder++;
172       }
173       else if (strShownArray[i].equals("8")) {
174         strTextShow[i] = "AD_ORG.NAME";
175         discard[i] = "10";
176         intDiscard++;
177         intOrder++;
178       }
179       else if (strShownArray[i].equals("9")) {
180         strTextShow[i] = "AD_COLUMN_IDENTIFIER('C_Bpartner', TO_CHAR(CB.C_BPARTNER_ID), 'es_ES')";
181         discard[i] = "10";
182         intDiscard++;
183         intOrder++;
184       }
185       else if (strShownArray[i].equals("10")) {
186         strTextShow[i] = "C_PROJECT.NAME";
187         discard[i] = "10";
188         intDiscard++;
189         intOrder++;
190       }
191       else if (strShownArray[i].equals("11")) {
192         strTextShow[i] = "AD_COLUMN_IDENTIFIER('C_Bpartner_Location', TO_CHAR(M_INOUT.C_BPARTNER_LOCATION_ID), 'es_ES')";
193         intDiscard++;
194         intOrder++;
195       }
196       else {
197         strTextShow[i] = "''";
198         discard[i] = "0.1";
199       }
200     }
201     if (intOrder != 0 || intAuxDiscard != -1){
202       int k=1;
203       strOrderby = " ORDER BY NIVEL"+k+",";
204       while (k<intOrder){
205         strOrderby = strOrderby+"NIVEL"+k+",";
206         k++;
207       }
208       if (k==1){
209         if (strOrder.equals("Normal")){
210           strOrderby = " ORDER BY NIVEL"+k;
211         } else if (strOrder.equals("Amountasc")){
212           strOrderby = " ORDER BY LINENETAMT ASC";
213         } else if (strOrder.equals("Amountdesc")){
214           strOrderby = " ORDER BY LINENETAMT DESC";
215         } else{
216           strOrderby = "1";
217         }
218       } else{
219         if (strOrder.equals("Normal")){
220           strOrderby += "NIVEL"+k;
221         } else if (strOrder.equals("Amountasc")){
222           strOrderby += "LINENETAMT ASC";
223         } else if (strOrder.equals("Amountdesc")){
224           strOrderby += "LINENETAMT DESC";
225         } else{
226           strOrderby = "1";
227         }
228       }
229
230     } else{
231       strOrderby = " ORDER BY 1";
232     }
233     String JavaDoc strHaving = "";
234     if (!strMayor.equals("") && !strMenor.equals("")) {strHaving = " HAVING SUM(LINENETAMT) > "+strMayor+" AND SUM(LINENETAMT) < "+strMenor;}
235     else if (!strMayor.equals("") && strMenor.equals("")) {strHaving = " HAVING SUM(LINENETAMT) > "+strMayor;}
236     else if (strMayor.equals("") && !strMenor.equals("")) {strHaving = " HAVING SUM(LINENETAMT) < "+strMenor;}
237     else{ strHaving = " HAVING SUM(LINENETAMT) <> 0 OR SUM(LINENETREF) <> 0";}
238     strOrderby = strHaving + strOrderby;
239     if (strComparative.equals("Y")){
240       data = ReportInvoiceCustomerDimensionalAnalysesData.select(this, strTextShow[0], strTextShow[1], strTextShow[2], strTextShow[3], strTextShow[4], strTextShow[5], strTextShow[6], strTextShow[7], strTextShow[8], strTextShow[9], Tree.getMembers(this, TreeData.getTreeOrg(this, vars.getClient()), strOrg), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceCustomerDimensionalPDF"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strsalesrepId, strPartnerSalesrepId, strcProjectId, strProducttype, strDateFromRef, DateTimeData.nDaysAfter(this, strDateToRef,"1"), strOrderby);
241     } else {
242       data = ReportInvoiceCustomerDimensionalAnalysesData.selectNoComparative(this, strTextShow[0], strTextShow[1], strTextShow[2], strTextShow[3], strTextShow[4], strTextShow[5], strTextShow[6], strTextShow[7], strTextShow[8], strTextShow[9], Tree.getMembers(this, TreeData.getTreeOrg(this, vars.getClient()), strOrg), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceCustomerDimensionalPDF"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strsalesrepId, strPartnerSalesrepId, strcProjectId, strProducttype, strOrderby);
243     }
244
245     if (data.length == 0 || data == null){
246       data = ReportInvoiceCustomerDimensionalAnalysesData.set();
247     } else {
248       int contador = intDiscard;
249       if (intAuxDiscard == -1) {
250         if (strComparative.equals("Y")){
251           for ( int j=1; j<11; j++){
252             discard1[j] = "fieldTotalQtyNivel"+String.valueOf(j);
253             discard1[j+10] = "fieldTotalRefQtyNivel"+String.valueOf(j);
254             discard1[j+20] = "fieldTotalQty"+String.valueOf(j);
255             //discard1[j+27] = "fieldTotalWeightNivel"+String.valueOf(j);
256
//discard1[j+36] = "fieldTotalRefWeightNivel"+String.valueOf(j);
257
//discard1[j+18] = "fieldUomsymbol"+String.valueOf(j);
258
}
259           int count=10;
260           while (count>contador){
261             //discard1[count+24] = "fieldTotalNivel"+String.valueOf(count);
262
//discard1[count+30] = "fieldTotalRefNivel"+String.valueOf(count);
263
discard1[count+40] = "fieldTotal"+String.valueOf(count);
264             count--;
265           }
266         } else {
267           for ( int j=1; j<11; j++){
268             discard1[j] = "fieldNoncomparativeTotalQtyNivel"+String.valueOf(j);
269             //discard1[j+27] = "fieldNoncomparativeTotalWeightNivel"+String.valueOf(j);
270
//discard1[j+18] = "fieldNoncomparativeUomsymbol"+String.valueOf(j);
271
}
272           int count=10;
273           /*while(count>contador){
274             discard1[count+24] = "fieldNoncomparativeTotalNivel"+String.valueOf(count);
275             count--;
276             }*/

277         }
278
279       }
280       else {
281         contador = intAuxDiscard;
282         int k = 1;
283         if (strComparative.equals("Y")){
284           for (int j = contador; j>0; j--){
285             discard1[k] = "fieldTotalQtyNivel"+String.valueOf(j);
286             discard1[k+10] = "fieldTotalRefQtyNivel"+String.valueOf(j);
287             discard1[k+20] = "fieldTotalQty"+String.valueOf(j);
288             //discard1[k+27] = "fieldTotalWeightNivel"+String.valueOf(j);
289
//discard1[k+36] = "fieldTotalRefWeightNivel"+String.valueOf(j);
290
//discard1[k+18] = "fieldUomsymbol"+String.valueOf(j);
291
k++;
292           }
293           int count = 10;
294           while (count>intDiscard+1){
295             discard1[count+30] = "fieldTotal"+String.valueOf(count);
296             //discard1[count+30] = "fieldTotalNivel"+String.valueOf(count);
297
//discard1[count+36] = "fieldTotalRefNivel"+String.valueOf(count);
298
discard1[count+40] = "fieldTotalQtyNivel"+String.valueOf(count);
299             discard1[count+50] = "fieldTotalRefQtyNivel"+String.valueOf(count);
300             discard1[count+60] = "fieldTotalQty"+String.valueOf(count);
301             //discard1[count+63] = "fieldTotalWeightNivel"+String.valueOf(count);
302
//discard1[count+72] = "fieldTotalRefWeightNivel"+String.valueOf(count);
303
//discard1[count+60] = "fieldUomsymbol"+String.valueOf(count);
304
count--;
305           }
306         } else {
307           for (int j = contador; j>0; j--){
308             discard1[k] = "fieldNoncomparativeTotalQtyNivel"+String.valueOf(j);
309             //discard1[k+27] = "fieldNoncomparativeTotalWeightNivel"+String.valueOf(j);
310
//discard1[k+18] = "fieldNoncomparativeUomsymbol"+String.valueOf(j);
311
k++;
312           }
313           int countNon = 10;
314           while (countNon>intDiscard+1){
315             //discard1[countNon+24] = "fieldNoncomparativeTotalNivel"+String.valueOf(countNon);
316
discard1[countNon+40] = "fieldNoncomparativeTotalQtyNivel"+String.valueOf(countNon);
317             //discard1[k+27] = "fieldNoncomparativeTotalWeightNivel"+String.valueOf(countNon);
318
//discard1[countNon+36] = "fieldNoncomparativeUomsymbol"+String.valueOf(countNon);
319
countNon--;
320           }
321         }
322       }
323     }
324     xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoiceCustomerDimensionalPDF", discard1).createXmlDocument();
325     xmlDocument.setParameter("eliminar2", discard[1]);
326     xmlDocument.setParameter("eliminar3", discard[2]);
327     xmlDocument.setParameter("eliminar4", discard[3]);
328     xmlDocument.setParameter("eliminar5", discard[4]);
329     xmlDocument.setParameter("eliminar6", discard[5]);
330     xmlDocument.setParameter("eliminar7", discard[6]);
331     xmlDocument.setParameter("eliminar8", discard[7]);
332     xmlDocument.setParameter("eliminar9", discard[8]);
333     xmlDocument.setParameter("eliminar10", discard[9]);
334     xmlDocument.setParameter("eliminateQty", strEliminateQty);
335     xmlDocument.setParameter("eliminateQtyRef", strEliminateQtyRef);
336     xmlDocument.setParameter("eliminateQtyAvg", strEliminateQtyAvg);
337     //xmlDocument.setParameter("eliminateWeight", strEliminateWeight);
338
//xmlDocument.setParameter("eliminateWeightRef", strEliminateWeightRef);
339
xmlDocument.setParameter("total", ReportInvoiceCustomerDimensionalAnalysesData.selectTotal(this,Tree.getMembers(this, TreeData.getTreeOrg(this, vars.getClient()), strOrg), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceCustomerDimensionalAnalyses"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strsalesrepId, strPartnerSalesrepId, strcProjectId, strProducttype));
340     xmlDocument.setParameter("title", strTitle);
341     xmlDocument.setParameter("page", strPage);
342     xmlDocument.setParameter("entity", ReportInvoiceCustomerDimensionalAnalysesData.selectEntity(this, vars.getClient()));
343     xmlDocument.setParameter("constante", "100");
344     if (strComparative.equals("Y")){
345       xmlDocument.setData("structure1", data);
346     } else {
347       xmlDocument.setData("structure2", data);
348     }
349     String JavaDoc strResult = xmlDocument.print();
350     renderFO(strResult, response);
351       }
352
353   public String JavaDoc getServletInfo() {
354     return "Servlet ReportRefundInvoiceCustomerDimensionalAnalyses. This Servlet was made by Jon Alegría";
355   } // end of getServletInfo() method
356
}
357
358
Popular Tags