1 19 package org.openbravo.erpCommon.ad_reports; 20 21 import org.openbravo.erpCommon.utility.*; 22 import org.openbravo.erpCommon.businessUtility.WindowTabs; 23 import org.openbravo.base.secureApp.HttpSecureAppServlet; 24 import org.openbravo.base.secureApp.VariablesSecureApp; 25 import org.openbravo.xmlEngine.XmlDocument; 26 import java.io.*; 27 import javax.servlet.*; 28 import javax.servlet.http.*; 29 import java.util.HashMap ; 30 31 import org.openbravo.erpCommon.utility.ComboTableData; 32 33 import org.openbravo.erpCommon.utility.DateTimeData; 34 35 import net.sf.jasperreports.engine.*; 36 import net.sf.jasperreports.engine.design.JasperDesign; 37 import java.sql.Connection ; 38 import net.sf.jasperreports.engine.xml.JRXmlLoader; 39 import net.sf.jasperreports.engine.export.JRHtmlExporter; 40 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; 41 42 public class ReportSalesOrderInvoicedJasper extends HttpSecureAppServlet { 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_ReportSalesOrderInvoicedJR")) { 49 bdError(response, "AccessTableNoView", vars.getLanguage()); 50 return; 51 } 52 53 if (vars.commandIn("DEFAULT")){ 54 String strdateFrom = vars.getStringParameter("inpDateFrom", ""); 55 String strdateTo = vars.getStringParameter("inpDateTo", ""); 56 String strcBpartnerId = vars.getStringParameter("inpcBPartnerId", ""); 57 String strmWarehouseId = vars.getStringParameter("inpmWarehouseId", ""); 58 String strcProjectId = vars.getStringParameter("inpcProjectId", ""); 59 String strmCategoryId = vars.getStringParameter("inpProductCategory", ""); 60 String strProjectkind = vars.getStringParameter("inpProjectkind", ""); 61 String strcRegionId = vars.getStringParameter("inpcRegionId", ""); 62 String strProjectpublic = vars.getStringParameter("inpProjectpublic", ""); 63 String strProduct = vars.getStringParameter("inpProductId", ""); 64 printPageDataSheet(response, vars, strdateFrom, strdateTo, strcBpartnerId, strmWarehouseId, strcProjectId, strmCategoryId, strProjectkind, strcRegionId, strProjectpublic, strProduct); 65 }else if(vars.commandIn("FIND")){ 66 String strdateFrom = vars.getStringParameter("inpDateFrom"); 67 String strdateTo = vars.getStringParameter("inpDateTo"); 68 String strcBpartnerId = vars.getStringParameter("inpcBPartnerId"); 69 String strmWarehouseId = vars.getStringParameter("inpmWarehouseId"); 70 String strcProjectId = vars.getStringParameter("inpcProjectId"); 71 String strmCategoryId = vars.getStringParameter("inpProductCategory"); 72 String strProjectkind = vars.getStringParameter("inpProjectkind"); 73 String strcRegionId = vars.getStringParameter("inpcRegionId"); 74 String strProjectpublic = vars.getStringParameter("inpProjectpublic"); 75 String strProduct = vars.getStringParameter("inpmProductId"); 76 printPageDataSheetJasper(response, vars, strdateFrom, strdateTo, strcBpartnerId, strmWarehouseId, strcProjectId, strmCategoryId, strProjectkind, strcRegionId, strProjectpublic, strProduct); 77 } else pageErrorPopUp(response); 78 } 79 80 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strdateFrom, String strdateTo, String strcBpartnerId, String strmWarehouseId, String strcProjectId, String strmCategoryId, String strProjectkind, String strcRegionId, String strProjectpublic, String strProduct) throws IOException, ServletException { 81 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 82 String discard[]={"sectionPartner"}; 83 String strTitle = ""; 84 XmlDocument xmlDocument=null; 85 if (vars.commandIn("DEFAULT")){ 86 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoicedJasper").createXmlDocument(); 87 88 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportSalesOrderInvoicedJasper", false, "", "", "",false, "ad_reports", strReplaceWith, false, true); 89 toolbar.prepareSimpleToolBarTemplate(); 90 xmlDocument.setParameter("toolbar", toolbar.toString()); 91 92 try { 93 KeyMap key = new KeyMap(this, vars, "ReportSalesOrderInvoicedJasper.html"); 94 xmlDocument.setParameter("keyMap", key.getReportKeyMaps()); 95 } catch (Exception ex) { 96 throw new ServletException(ex); 97 } 98 try { 99 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportSalesOrderInvoicedJasper"); 100 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 101 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 102 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 103 xmlDocument.setParameter("theme", vars.getTheme()); 104 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportSalesOrderInvoicedJasper.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 105 xmlDocument.setParameter("navigationBar", nav.toString()); 106 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportSalesOrderInvoicedJasper.html", strReplaceWith); 107 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 108 } catch (Exception ex) { 109 throw new ServletException(ex); 110 } 111 { 112 OBError myMessage = vars.getMessage("ReportSalesOrderInvoicedJasper"); 113 vars.removeMessage("ReportSalesOrderInvoicedJasper"); 114 if (myMessage!=null) { 115 xmlDocument.setParameter("messageType", myMessage.getType()); 116 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 117 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 118 } 119 } 120 121 xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2)); 122 xmlDocument.setParameter("dateFrom", strdateFrom); 123 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 124 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 125 xmlDocument.setParameter("dateTo", strdateTo); 126 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 127 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 128 xmlDocument.setParameter("paramBPartnerId", strcBpartnerId); 129 xmlDocument.setParameter("mWarehouseId", strmWarehouseId); 130 xmlDocument.setParameter("cProjectId", strcProjectId); 131 xmlDocument.setParameter("mProductCategoryId", strmCategoryId); 132 xmlDocument.setParameter("cProjectKind", strProjectkind); 133 xmlDocument.setParameter("cRegionId", strcRegionId); 134 xmlDocument.setParameter("cProjectPublic", strProjectpublic); 135 xmlDocument.setParameter("projectName", ReportProjectBuildingSiteData.selectProject(this, strcProjectId)); 136 xmlDocument.setParameter("paramBPartnerDescription", ReportSalesOrderInvoicedData.bPartnerDescription(this, strcBpartnerId)); 137 try { 138 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Warehouse_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0); 139 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strmWarehouseId); 140 xmlDocument.setData("reportM_WAREHOUSEID","liststructure", comboTableData.select(false)); 141 comboTableData = null; 142 } catch (Exception ex) { 143 throw new ServletException(ex); 144 } 145 146 try { 147 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Product_Category_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0); 148 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strmCategoryId); 149 xmlDocument.setData("reportM_PRODUCT_CATEGORYID","liststructure", comboTableData.select(false)); 150 comboTableData = null; 151 } catch (Exception ex) { 152 throw new ServletException(ex); 153 } 154 155 try { 156 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "C_Projectkind_ID", "Projectkind", "", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0); 157 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strProjectkind); 158 xmlDocument.setData("reportC_PROJECTKIND","liststructure", comboTableData.select(false)); 159 comboTableData = null; 160 } catch (Exception ex) { 161 throw new ServletException(ex); 162 } 163 164 try { 165 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Region_ID", "", "C_Region of Country", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0); 166 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strcRegionId); 167 xmlDocument.setData("reportC_REGIONID","liststructure", comboTableData.select(false)); 168 comboTableData = null; 169 } catch (Exception ex) { 170 throw new ServletException(ex); 171 } 172 173 try { 174 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "C_Project_Public_ID", "PublicPrivate", "", Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoicedJasper"), Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoicedJasper"), 0); 175 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportSalesOrderInvoicedJasper", strProjectpublic); 176 xmlDocument.setData("reportC_PROJECTPUBLIC","liststructure", comboTableData.select(false)); 177 comboTableData = null; 178 } catch (Exception ex) { 179 throw new ServletException(ex); 180 } 181 182 SubCategoryProductData[] dataSub = SubCategoryProductData.select(this); 183 xmlDocument.setParameter("product", arrayDobleEntrada("array", SubCategoryProductData.selectProduct(this))); 184 xmlDocument.setData("structureCategory", dataSub); 185 xmlDocument.setData("structureProduct", SubCategoryProductData.selectCategoryProduct(this, dataSub[0].id)); 186 } 187 else { 188 ReportSalesOrderInvoicedData[] data = ReportSalesOrderInvoicedData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoiced"), Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoiced"), strdateFrom, DateTimeData.nDaysAfter(this, strdateTo,"1"), strcBpartnerId, strmWarehouseId, strcProjectId, strmCategoryId, strProjectkind, strcRegionId, strProjectpublic, strProduct); 189 if (data == null || data.length == 0){ 190 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoicedPop", discard).createXmlDocument(); 191 xmlDocument.setData("structure1", ReportSalesOrderInvoicedData.set()); 192 } 193 else { 194 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoicedPop").createXmlDocument(); 195 xmlDocument.setData("structure1", data); 196 } 197 if (!strmWarehouseId.equals("")) strTitle += " " + Utility.messageBD(this, "ForWarehouse", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectWarehouse(this, strmWarehouseId); 198 if (!strcRegionId.equals("")) strTitle += ", " + Utility.messageBD(this, "InRegion", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectRegionId(this, strcRegionId); 199 if (!strmCategoryId.equals("")) strTitle += ", " + Utility.messageBD(this, "ForProductCategory", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectCategoryId(this, strmCategoryId); 200 if (!strProjectkind.equals("")) strTitle += ", " + Utility.messageBD(this, "ProjectType", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectProjectkind(this, vars.getLanguage(), strProjectkind); 201 if (!strProjectpublic.equals("")) strTitle += ", " + Utility.messageBD(this, "WithInitiativeType", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectProjectpublic(this, vars.getLanguage(), strProjectpublic); 202 if (!strdateFrom.equals("")) strTitle += ", " + Utility.messageBD(this, "From", vars.getLanguage()) + " " + strdateFrom; 203 if (!strdateTo.equals("")) strTitle += " " + Utility.messageBD(this, "To", vars.getLanguage()) + " " + strdateTo; 204 if (!strProduct.equals("")) strTitle += ", " + Utility.messageBD(this, "ForProduct", vars.getLanguage()) + " " + ReportSalesOrderInvoicedData.selectProduct(this, strProduct); 205 xmlDocument.setParameter("title", strTitle); 206 } 207 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 208 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 209 210 response.setContentType("text/html; charset=UTF-8"); 211 PrintWriter out = response.getWriter(); 212 out.println(xmlDocument.print()); 213 out.close(); 214 } 215 216 217 219 220 221 222 void printPageDataSheetJasper(HttpServletResponse response, VariablesSecureApp vars, String strdateFrom, String strdateTo, String strcBpartnerId, String strmWarehouseId, String strcProjectId, String strmCategoryId, String strProjectkind, String strcRegionId, String strProjectpublic, String strProduct) throws IOException, ServletException { 223 224 JasperPrint jasperPrint; 225 226 227 ReportSalesOrderInvoicedData[] data = ReportSalesOrderInvoicedData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportSalesOrderInvoiced"), Utility.getContext(this, vars, "#User_Org", "ReportSalesOrderInvoiced"), strdateFrom, DateTimeData.nDaysAfter(this, strdateTo,"1"), strcBpartnerId, strmWarehouseId, strcProjectId, strmCategoryId, strProjectkind, strcRegionId, strProjectpublic, strProduct); 228 229 String strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportSalesOrderInvoicedJasper.jrxml"; 230 String strOutput = "html"; 231 if (strOutput.equals("pdf")) response.setHeader("Content-disposition", "inline; filename=ReportSalesOrderInvoiced.pdf"); 232 233 HashMap <String , Object > parameters = new HashMap <String , Object >(); 234 parameters.put("REPORT_TITLE", "Invoiced sale orders report"); 235 parameters.put("REPORT_SUBTITLE", "From "+strdateFrom +" to "+strdateTo); 236 renderJR(vars, response, strReportName, strOutput, parameters, data, null ); 237 238 } 239 240 public String getServletInfo() { 241 return "Servlet ReportSalesOrderInvoicedJasper. This Servlet was made by Jon Alegría"; 242 } } 244 245 | Popular Tags |