1 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 strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportInvoiceCustomerDimensionalAnalyses|dateFrom"); 55 String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportSInvoiceCustomerDimensionalAnalyses|dateTo"); 56 String strDateFromRef = vars.getRequestGlobalVariable("inpDateFromRef", "ReportInvoiceCustomerDimensionalAnalyses|dateFromRef"); 57 String strDateToRef = vars.getRequestGlobalVariable("inpDateToRef", "ReportSInvoiceCustomerDimensionalAnalyses|dateToRef"); 58 String strPartnerGroup = vars.getRequestGlobalVariable("inpPartnerGroup", "ReportInvoiceCustomerDimensionalAnalyses|partnerGroup"); 59 String strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportInvoiceCustomerDimensionalAnalyses|partner"); 60 String strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ReportInvoiceCustomerDimensionalAnalyses|productCategory"); 61 String strmProductId = vars.getRequestInGlobalVariable("inpmProductId_IN", "ReportInvoiceCustomerDimensionalAnalyses|product"); 62 String strNotShown = vars.getInStringParameter("inpNotShown"); 63 String strShown = vars.getInStringParameter("inpShown"); 64 String strOrg = vars.getGlobalVariable("inpOrg", "ReportInvoiceCustomerDimensionalAnalyses|org", "0"); 65 String strsalesrepId = vars.getRequestGlobalVariable("inpSalesrepId", "ReportInvoiceCustomerDimensionalAnalyses|salesrep"); 66 String strOrder = vars.getRequestGlobalVariable("inpOrder","ReportInvoiceCustomerDimensionalAnalyses|order"); 67 String strcProjectId = vars.getRequestGlobalVariable("inpcProjectId", "ReportInvoiceCustomerDimensionalAnalyses|project"); 68 String strProducttype = vars.getRequestGlobalVariable("inpProducttype", "ReportInvoiceVendorDimensionalAnalyses|producttype"); 69 String strMayor = vars.getStringParameter("inpMayor", ""); 70 String strMenor = vars.getStringParameter("inpMenor", ""); 71 String strComparative = vars.getStringParameter("inpComparative", "N"); 72 String 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 strComparative, String strDateFrom, String strDateTo, String strPartnerGroup, String 79 strcBpartnerId, String strProductCategory, String strmProductId, String strNotShown, String strShown, String strDateFromRef, String strDateToRef, String strOrg, String 80 strsalesrepId, String strOrder, String strcProjectId, String strProducttype, String strMayor, String strMenor, String strPartnerSalesrepId) throws IOException, ServletException{ 81 if (log4j.isDebugEnabled()) log4j.debug("Output: print pdf"); 82 XmlDocument xmlDocument=null; 83 String strPage = "basicPSMSecond"; 84 String strOrderby = ""; 85 String [] discard = {"", "", "", "", "","", "", "", "", ""}; 86 String [] 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 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 (!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 [] 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 [] strTextShow = {"", "", "", "", "","", "", "", "", ""}; 123 int intDiscard = 0; 124 int intOrder = 0; 125 int intAuxDiscard = -1; 126 String strEliminateQty = " "; 127 String strEliminateQtyRef = " "; 128 String strEliminateQtyAvg = " "; 129 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 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 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 } 259 int count=10; 260 while (count>contador){ 261 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 } 272 int count=10; 273 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 k++; 292 } 293 int count = 10; 294 while (count>intDiscard+1){ 295 discard1[count+30] = "fieldTotal"+String.valueOf(count); 296 discard1[count+40] = "fieldTotalQtyNivel"+String.valueOf(count); 299 discard1[count+50] = "fieldTotalRefQtyNivel"+String.valueOf(count); 300 discard1[count+60] = "fieldTotalQty"+String.valueOf(count); 301 count--; 305 } 306 } else { 307 for (int j = contador; j>0; j--){ 308 discard1[k] = "fieldNoncomparativeTotalQtyNivel"+String.valueOf(j); 309 k++; 312 } 313 int countNon = 10; 314 while (countNon>intDiscard+1){ 315 discard1[countNon+40] = "fieldNoncomparativeTotalQtyNivel"+String.valueOf(countNon); 317 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("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 strResult = xmlDocument.print(); 350 renderFO(strResult, response); 351 } 352 353 public String getServletInfo() { 354 return "Servlet ReportRefundInvoiceCustomerDimensionalAnalyses. This Servlet was made by Jon AlegrÃa"; 355 } } 357 358 | Popular Tags |