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 30 import java.util.*; 31 import net.sf.jasperreports.engine.*; 32 import net.sf.jasperreports.engine.design.JasperDesign; 33 import java.sql.Connection ; 34 import net.sf.jasperreports.engine.xml.JRXmlLoader; 35 import net.sf.jasperreports.engine.export.JRHtmlExporter; 36 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; 37 38 import org.openbravo.erpCommon.utility.ComboTableData; 39 40 import org.openbravo.erpCommon.utility.ToolBar; 41 42 public class ReportSalesOrderJR 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, "", "ReportSalesOrderJR")) { 49 bdError(response, "AccessTableNoView", vars.getLanguage()); 50 return; 51 } 52 53 if (vars.commandIn("DEFAULT")){ 54 String strdateFrom = vars.getGlobalVariable("inpDateFrom", "ReportSalesOrderJR|dateFrom", ""); 55 String strdateTo = vars.getGlobalVariable("inpDateTo", "ReportSalesOrderJR|dateTo", ""); 56 String strcProjectId = vars.getGlobalVariable("inpcProjectId", "ReportSalesOrderJR|projectId", ""); 57 String strmWarehouseId = vars.getGlobalVariable("inpmWarehouseId", "ReportSalesOrderJR|warehouseId", ""); 58 String strProjectpublic = vars.getGlobalVariable("inpProjectpublic", "ReportSalesOrderJR|projectpublic", ""); 59 printPageDataSheet(response, vars, strdateFrom, strdateTo, strmWarehouseId, strcProjectId, strProjectpublic); 60 }else if (vars.commandIn("EDIT_HTML","EDIT_PDF")) { 61 String strdateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportSalesOrderJR|dateFrom"); 62 String strdateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportSalesOrderJR|dateTo"); 63 String strmWarehouseId = vars.getRequestGlobalVariable("inpmWarehouseId", "ReportSalesOrderJR|warehouseId"); 64 String strcProjectId = vars.getRequestGlobalVariable("inpcProjectId", "ReportSalesOrderJR|projectId"); 65 String strProjectpublic = vars.getRequestGlobalVariable("inpProjectpublic", "ReportSalesOrderJR|projectpublic"); 66 String strcRegionId = vars.getRequestInGlobalVariable("inpcRegionId", "ReportSalesOrderJR|regionId"); 67 String strmProductCategoryId = vars.getRequestInGlobalVariable("inpmProductCategoryId", "ReportSalesOrderJR|productCategoryId"); 68 String strProjectkind = vars.getRequestInGlobalVariable("inpProjectkind", "ReportSalesOrderJR|projectKind"); 69 String strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportSalesOrderJR|bpartnerId"); 70 String strmProductId = vars.getRequestInGlobalVariable("inpmProductId_IN", "ReportSalesOrderJR|productId"); 71 printPageHtml(response, vars, strdateFrom, strdateTo, strmWarehouseId, strcProjectId, strProjectpublic, strcRegionId, strmProductCategoryId, strProjectkind, strcBpartnerId, strmProductId); 72 } else pageErrorPopUp(response); 73 } 74 75 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strdateFrom, String strdateTo, String strmWarehouseId, String strcProjectId, String strProjectpublic) throws IOException, ServletException { 76 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 77 String discard[]={"discard"}; 78 XmlDocument xmlDocument=null; 79 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportSalesOrderFilterJR").createXmlDocument(); 80 81 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportSalesOrderJR", false, "", "", "openServletNewWindow('EDIT_PDF', true, 'ReportSalesOrderJR.pdf', 'ReportSalesOrderFilterJR', null, false, '700', '1000', true);return false;",false, "ad_reports", strReplaceWith, false, true); 82 toolbar.prepareSimpleToolBarTemplate(); 83 xmlDocument.setParameter("toolbar", toolbar.toString()); 84 85 try { 86 KeyMap key = new KeyMap(this, vars, "ReportSalesOrderFilterJR.html"); 87 xmlDocument.setParameter("keyMap", key.getReportKeyMaps()); 88 } catch (Exception ex) { 89 throw new ServletException(ex); 90 } 91 try { 92 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportSalesOrderJR"); 93 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 94 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 95 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 96 xmlDocument.setParameter("theme", vars.getTheme()); 97 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportSalesOrderFilterJR.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 98 xmlDocument.setParameter("navigationBar", nav.toString()); 99 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportSalesOrderFilterJR.html", strReplaceWith); 100 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 101 } catch (Exception ex) { 102 throw new ServletException(ex); 103 } 104 { 105 OBError myMessage = vars.getMessage("ReportSalesOrderJR"); 106 vars.removeMessage("ReportSalesOrderJR"); 107 if (myMessage!=null) { 108 xmlDocument.setParameter("messageType", myMessage.getType()); 109 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 110 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 111 } 112 } 113 114 115 xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2)); 116 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 117 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 118 xmlDocument.setParameter("dateFrom", strdateFrom); 119 xmlDocument.setParameter("dateTo", strdateTo); 120 xmlDocument.setParameter("paramBPartnerId", ""); 121 xmlDocument.setParameter("mWarehouseId", strmWarehouseId); 122 xmlDocument.setParameter("cProjectId", strcProjectId); 123 xmlDocument.setParameter("projectName", OrderEditionData.selectProject(this, strcProjectId)); 124 xmlDocument.setParameter("cProjectKind", ""); 125 xmlDocument.setParameter("cRegionId", ""); 126 xmlDocument.setParameter("cProjectPublic", strProjectpublic); 127 xmlDocument.setParameter("mProductCatId", ""); 128 try { 129 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Warehouse_ID", "", "", Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilter"), 0); 130 Utility.fillSQLParameters(this, vars, null, comboTableData, "SalesOrderFilterJR", ""); 131 xmlDocument.setData("reportM_WAREHOUSEID","liststructure", comboTableData.select(false)); 132 comboTableData = null; 133 } catch (Exception ex) { 134 throw new ServletException(ex); 135 } 136 137 try { 138 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "C_Projectkind_ID", "Projectkind", "", Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilterJR"), 0); 139 Utility.fillSQLParameters(this, vars, null, comboTableData, "SalesOrderFilterJR", ""); 140 xmlDocument.setData("reportC_PROJECTKIND","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", "C_Region_ID", "", "C_Region of Country", Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilterJR"), 0); 148 Utility.fillSQLParameters(this, vars, null, comboTableData, "SalesOrderFilterJR", ""); 149 xmlDocument.setData("reportC_REGIONID","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", "PublicPrivate", "", Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilterJR"), 0); 157 Utility.fillSQLParameters(this, vars, null, comboTableData, "SalesOrderFilter", ""); 158 xmlDocument.setData("reportC_PROJECTKIND","liststructure", comboTableData.select(false)); 159 comboTableData = null; 160 } catch (Exception ex) { 161 throw new ServletException(ex); 162 } 163 164 xmlDocument.setData("reportCBPartnerId_IN", "liststructure", ReportProjectBuildingSiteData.selectBpartner(this, Utility.getContext(this, vars, "#User_Org", ""), Utility.getContext(this, vars, "#User_Client", ""), "")); 165 xmlDocument.setData("reportMProductId_IN", "liststructure", ReportProjectBuildingSiteData.selectMproduct(this, Utility.getContext(this, vars, "#User_Org", ""), Utility.getContext(this, vars, "#User_Client", ""), "")); 166 xmlDocument.setData("reportC_PRODUCTCATREGORY","liststructure",SubCategoryProductData.select(this)); 167 response.setContentType("text/html; charset=UTF-8"); 168 169 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 170 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 171 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 172 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 173 174 175 PrintWriter out = response.getWriter(); 176 out.println(xmlDocument.print()); 177 out.close(); 178 } 179 180 void printPageHtml(HttpServletResponse response, VariablesSecureApp vars, String strdateFrom, String strdateTo, String strmWarehouseId, String strcProjectId, String strProjectpublic, String strcRegionId, String strmProductCategoryId, String strProjectkind, String strcBpartnerId, String strmProductId) throws IOException, ServletException{ 181 if (log4j.isDebugEnabled()) log4j.debug("Output: print html"); 182 OrderEditionData[] data = null; 183 data = OrderEditionData.select(this, Utility.getContext(this, vars, "#User_Org", "SalesOrderFilterJR"), Utility.getContext(this, vars, "#User_Client", "SalesOrderFilterJR"), strdateFrom, strdateTo, strmWarehouseId, strcProjectId, strProjectpublic, strcRegionId, strmProductCategoryId, strProjectkind, strcBpartnerId, strmProductId); 184 if (data == null || data.length == 0) data = OrderEditionData.set(); 185 186 JasperPrint jasperPrint; 187 String strOutput = vars.commandIn("EDIT_HTML")?"html":"pdf"; 188 String strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportSalesOrderJR.jrxml"; 189 190 HashMap<String , Object > parameters = new HashMap<String , Object >(); 191 parameters.put("Title", classInfo.name); 192 renderJR(vars, response, strReportName, strOutput, parameters, data, null ); 194 } 195 196 197 198 199 public String getServletInfo() { 200 return "Servlet PurchaseOrderFilter. This Servlet was made by Jon AlegrÃa"; 201 } } 203 204 | Popular Tags |