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 ReportDimensionalAnalysesPDF 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_ReportRefundInvoiceCustomerDimensiona")) { 49 bdError(response, "AccessTableNoView", vars.getLanguage()); 50 return; 51 } 52 53 if (vars.commandIn("DEFAULT")){ 54 String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportRefundInvoiceCustomerDimensionalAnalyses|dateFrom"); 55 String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportRefundInvoiceCustomerDimensionalAnalyses|dateTo"); 56 String strDateFromRef = vars.getRequestGlobalVariable("inpDateFromRef", "ReportRefundInvoiceCustomerDimensionalAnalyses|dateFromRef"); 57 String strDateToRef = vars.getRequestGlobalVariable("inpDateToRef", "ReportRefundInvoiceCustomerDimensionalAnalyses|dateToRef"); 58 String strPartnerGroup = vars.getRequestGlobalVariable("inpPartnerGroup", "ReportRefundInvoiceCustomerDimensionalAnalyses|partnerGroup"); 59 String strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportRefundInvoiceCustomerDimensionalAnalyses|partner"); 60 String strProductCategory = vars.getRequestGlobalVariable("inpProductCategory", "ReportRefundInvoiceCustomerDimensionalAnalyses|productCategory"); 61 String strmProductId = vars.getRequestInGlobalVariable("inpmProductId_IN", "ReportRefundInvoiceCustomerDimensionalAnalyses|product"); 62 String strNotShown = vars.getInStringParameter("inpNotShown"); 63 String strShown = vars.getInStringParameter("inpShown"); 64 String strOrg = vars.getGlobalVariable("inpOrg", "ReportRefundInvoiceCustomerDimensionalAnalyses|org", "0"); 65 String strsalesrepId = vars.getRequestGlobalVariable("inpSalesrepId", "ReportRefundInvoiceCustomerDimensionalAnalyses|salesrep"); 66 String strOrder = vars.getRequestGlobalVariable("inpOrder","ReportRefundInvoiceCustomerDimensionalAnalyses|order"); 67 String strMayor = vars.getStringParameter("inpMayor", ""); 68 String strMenor = vars.getStringParameter("inpMenor", ""); 69 String strRatioMayor = vars.getStringParameter("inpRatioMayor", ""); 70 String strRatioMenor = vars.getStringParameter("inpRatioMenor", ""); 71 String strComparative = vars.getStringParameter("inpComparative", "N"); 72 printPagePdf(response, vars, strComparative, strDateFrom, strDateTo, strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strNotShown, strShown, strDateFromRef, strDateToRef, strOrg, strsalesrepId, strOrder, strMayor, strMenor, strRatioMayor, strRatioMenor); 73 } else pageErrorPopUp(response); 74 } 75 76 void printPagePdf(HttpServletResponse response, VariablesSecureApp vars, String strComparative, String strDateFrom, String strDateTo, String strPartnerGroup, String strcBpartnerId, String strProductCategory, String strmProductId, String strNotShown, String strShown, String strDateFromRef, String strDateToRef, String strOrg, String strsalesrepId, String strOrder, String strMayor, String strMenor, String strRatioMayor, String strRatioMenor) throws IOException, ServletException{ 77 if (log4j.isDebugEnabled()) log4j.debug("Output: print pdf"); 78 XmlDocument xmlDocument=null; 79 String strOrderby = ""; 80 if (log4j.isDebugEnabled()) log4j.debug("********************************"+strComparative); 81 String [] discard = {"", "", "", "", "",""}; 82 String [] 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"}; 83 if (strComparative.equals("Y")) discard1[0] = "selEliminarBody2"; 84 String strTitle = ""; 85 strTitle = "del "+strDateFrom+" al "+strDateTo; 86 if (!strPartnerGroup.equals("")) strTitle = strTitle+", para el grupo de terceros "+ReportRefundInvoiceCustomerDimensionalAnalysesData.selectBpgroup(this, strPartnerGroup); 87 if (!strProductCategory.equals("")) strTitle = strTitle+", categoria de producto "+ReportInvoiceCustomerDimensionalAnalysesData.selectProductCategory(this, strProductCategory); 89 if (!strsalesrepId.equals("")) strTitle = strTitle+"y el comercial "+ReportRefundInvoiceCustomerDimensionalAnalysesData.selectSalesrep(this, strsalesrepId); 90 ReportRefundInvoiceCustomerDimensionalAnalysesData[] data = null; 92 String [] strShownArray = {"", "", "", "", "", ""}; 93 if (strShown.startsWith("(")) strShown = strShown.substring(1, strShown.length()-1); 94 if (!strShown.equals("")) { 95 strShown = Replace.replace(strShown, "'", ""); 96 strShown = Replace.replace(strShown, " ", ""); 97 StringTokenizer st = new StringTokenizer(strShown, ",", false); 98 int intContador = 0; 99 while (st.hasMoreTokens()){ 100 strShownArray[intContador] = st.nextToken(); 101 intContador++; 102 } 103 104 } 105 String [] strTextShow = {"", "", "", "", "",""}; 106 int intDiscard = 0; 107 int intAuxDiscard = -1; 108 for (int i = 0; i<6; i++){ 109 if (strShownArray[i].equals("1")) { 110 strTextShow[i] = "C_BP_GROUP.NAME"; 111 discard[i] = "10"; 112 intDiscard++; 113 } 114 else if (strShownArray[i].equals("2")) { 115 strTextShow[i] = "C_BPARTNER.NAME"; 116 discard[i] = "10"; 117 intDiscard++; 118 } 119 else if (strShownArray[i].equals("3")) { 120 strTextShow[i] = "M_PRODUCT_CATEGORY.NAME"; 121 discard[i] = "10"; 122 intDiscard++; 123 } 124 else if (strShownArray[i].equals("4")) { 125 strTextShow[i] = "M_PRODUCT.NAME"; 126 discard[i] = "10"; 127 intAuxDiscard = i; 128 } 129 else if (strShownArray[i].equals("5")) { 130 strTextShow[i] = "C_INVOICE.DOCUMENTNO"; 131 discard[i] = "10"; 132 intDiscard++; 133 } 134 else if (strShownArray[i].equals("6")) { 135 strTextShow[i] = "AD_USER.FIRSTNAME||' '||' '||AD_USER.LASTNAME"; 136 discard[i] = "10"; 137 intDiscard++; 138 } 139 else { 140 strTextShow[i] = "''"; 141 discard[i] = "0.1"; 142 } 143 } 144 if (intDiscard != 0){ 145 int k=1; 146 strOrderby = " ORDER BY NIVEL"+k+","; 147 while (k<intDiscard){ 148 strOrderby = strOrderby+"NIVEL"+k+","; 149 k++; 150 } 151 if (k==1){ 152 if (strOrder.equals("Normal")){ 153 strOrderby = " ORDER BY NIVEL"+k; 154 } else if (strOrder.equals("Amountasc")){ 155 strOrderby = " ORDER BY LINENETAMT ASC"; 156 } else if (strOrder.equals("Amountdesc")){ 157 strOrderby = " ORDER BY LINENETAMT DESC"; 158 } else if (strOrder.equals("Ratioasc")){ 159 strOrderby = " ORDER BY LINENETAMT ASC"; 160 } else if (strOrder.equals("Ratiodesc")){ 161 strOrderby = " ORDER BY LINENETAMT DESC"; 162 } else{ 163 strOrderby = "1"; 164 } 165 } else{ 166 if (strOrder.equals("Normal")){ 167 strOrderby += "NIVEL"+k; 168 } else if (strOrder.equals("Amountasc")){ 169 strOrderby += "LINENETAMT ASC"; 170 } else if (strOrder.equals("Amountdesc")){ 171 strOrderby += "LINENETAMT DESC"; 172 } else if (strOrder.equals("Ratioasc")){ 173 strOrderby += "LINENETAMT ASC"; 174 } else if (strOrder.equals("Ratiodesc")){ 175 strOrderby += "LINENETAMT DESC"; 176 } else{ 177 strOrderby = "1"; 178 } 179 } 180 181 } else{ 182 strOrderby = " ORDER BY 1"; 183 } 184 String strHaving = ""; 185 if (!strMayor.equals("") && !strMenor.equals("")) {strHaving = " HAVING SUM(LINENETAMT) > "+strMayor+" AND SUM(LINENETAMT) < "+strMenor;} 186 else if (!strMayor.equals("") && strMenor.equals("")) {strHaving = " HAVING SUM(LINENETAMT) > "+strMayor;} 187 else if (strMayor.equals("") && !strMenor.equals("")) {strHaving = " HAVING SUM(LINENETAMT) < "+strMenor;} 188 else{} 189 if (strHaving.equals("")){ 190 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;} 191 else if (!strRatioMayor.equals("") && strRatioMenor.equals("")) {strHaving = " HAVING DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 > "+strRatioMayor;} 192 else if (strRatioMayor.equals("") && !strRatioMenor.equals("")) {strHaving = " HAVING DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 < "+strRatioMenor;} 193 else{} 194 } else { 195 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;} 196 else if (!strRatioMayor.equals("") && strRatioMenor.equals("")) {strHaving = " AND DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 > "+strRatioMayor;} 197 else if (strRatioMayor.equals("") && !strRatioMenor.equals("")) {strHaving = " AND DIVIDE(SUM(REFUNDAMT), (SUM(LINENETAMT)+SUM(REFUNDAMT)))*100 < "+strRatioMenor;} 198 else{} 199 } 200 strOrderby = strHaving + strOrderby; 201 if (log4j.isDebugEnabled()) log4j.debug("*******************PDF"+strOrderby); 202 if (strComparative.equals("Y")){ 203 data = ReportRefundInvoiceCustomerDimensionalAnalysesData.select(this, strTextShow[0], strTextShow[1], strTextShow[2], strTextShow[3], strTextShow[4], strTextShow[5], Tree.getMembers(this, TreeData.getTreeOrg(this, vars.getClient()), strOrg), Utility.getContext(this, vars, "#User_Client", "ReportRefundInvoiceCustomerDimensionalAnalyses"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strsalesrepId, strDateFromRef, DateTimeData.nDaysAfter(this, strDateToRef,"1"), strOrderby); 204 } else { 205 data = ReportRefundInvoiceCustomerDimensionalAnalysesData.selectNoComparative(this, strTextShow[0], strTextShow[1], strTextShow[2], strTextShow[3], strTextShow[4], strTextShow[5], Tree.getMembers(this, TreeData.getTreeOrg(this, vars.getClient()), strOrg), Utility.getContext(this, vars, "#User_Client", "ReportRefundInvoiceCustomerDimensionalAnalyses"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strPartnerGroup, strcBpartnerId, strProductCategory, strmProductId, strsalesrepId, strOrderby); 206 } 207 if (data.length == 0 || data == null){ 209 if (log4j.isDebugEnabled()) log4j.debug("********************No dataPDF"); 211 data = ReportRefundInvoiceCustomerDimensionalAnalysesData.set(); 212 } else { 213 if (log4j.isDebugEnabled()) log4j.debug("*************************level1PDF"+data[0].nivel1); 214 int contador = intDiscard; 215 if (intAuxDiscard != -1) contador = intAuxDiscard; 216 int k = 1; 217 if (strComparative.equals("Y")){ 218 for (int j = contador; j>0; j--){ 219 discard1[k] = "fieldTotalQtyNivel"+String.valueOf(j); 220 discard1[k+10] = "fieldTotalRefundQtyNivel"+String.valueOf(j); 221 discard1[k+20] = "fieldUomsymbol"+String.valueOf(j); 222 discard1[k+5] = "fieldTotalRefQtyNivel"+String.valueOf(j); 223 discard1[k+15] = "fieldTotalRefRefundQtyNivel"+String.valueOf(j); 224 k++; 225 } 226 } else { 227 for (int j = contador; j>0; j--){ 228 discard1[k] = "fieldNoncomparativeTotalQtyNivel"+String.valueOf(j); 229 discard1[k+10] = "fieldNoncomparativeTotalRefundQtyNivel"+String.valueOf(j); 230 discard1[k+20] = "fieldNoncomparativeUomsymbol"+String.valueOf(j); 231 k++; 232 } 233 } 234 235 } 236 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportRefundInvoiceCustomerDimensionalAnalysesEditionPDF", discard1).createXmlDocument(); 237 238 xmlDocument.setParameter("eliminar2", discard[1]); 239 xmlDocument.setParameter("eliminar3", discard[2]); 240 xmlDocument.setParameter("eliminar4", discard[3]); 241 xmlDocument.setParameter("eliminar5", discard[4]); 242 xmlDocument.setParameter("eliminar6", discard[5]); 243 xmlDocument.setParameter("title", strTitle); 244 xmlDocument.setParameter("constante", "100"); 245 if (strComparative.equals("Y")){ 246 xmlDocument.setData("structure1", data); 247 } else { 248 xmlDocument.setData("structure2", data); 249 } 250 String strResult = xmlDocument.print(); 251 renderFO(strResult, response); 252 } 253 254 public String getServletInfo() { 255 return "Servlet ReportRefundInvoiceCustomerDimensionalAnalyses. This Servlet was made by Jon AlegrÃa"; 256 } } 258 259 | Popular Tags |