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.ToolBar; 39 40 public class ReportInvoiceCustomerJR extends HttpSecureAppServlet { 41 42 43 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 44 VariablesSecureApp vars = new VariablesSecureApp(request); 45 46 if (!Utility.hasProcessAccess(this, vars, "", "RV_ReportInvoiceCustomer")) { 47 bdError(response, "AccessTableNoView", vars.getLanguage()); 48 return; 49 } 50 51 if (vars.commandIn("DEFAULT")){ 52 String strdateFrom = vars.getGlobalVariable("inpDateFrom", "ReportInvoiceCustomerEdition|DateFrom", ""); 53 String strdateTo = vars.getGlobalVariable("inpDateTo", "ReportInvoiceCustomerEdition|DateTo", ""); 54 String strcProjectId = vars.getGlobalVariable("inpcProjectId", "ReportInvoiceCustomerEdition|cProjectId", ""); 55 String strcBpartnerId = vars.getInGlobalVariable("inpcBPartnerId_IN", "ReportInvoiceCustomerEdition|cBPartnerId_IN", ""); 56 String strmCategoryId = vars.getInGlobalVariable("inpmProductCategoryId", "ReportInvoiceCustomerEdition|mCategoryId", ""); 57 String strProjectkind = vars.getInGlobalVariable("inpProjectkind", "ReportInvoiceCustomerEdition|Projectkind", ""); 58 String strProjectstatus = vars.getInGlobalVariable("inpProjectstatus", "ReportInvoiceCustomerEdition|Projectstatus", ""); 59 String strProjectphase = vars.getInGlobalVariable("inpProjectphase", "ReportInvoiceCustomerEdition|Projectphase", ""); 60 String strProduct = vars.getInGlobalVariable("inpmProductId_IN", "ReportInvoiceCustomerEdition|mProductId_IN", ""); 61 String strProjectpublic = vars.getGlobalVariable("inpProjectpublic", "ReportInvoiceCustomerEdition|Projectpublic", ""); 62 String strSalesRep = vars.getGlobalVariable("inpSalesRepId", "ReportInvoiceCustomerEdition|SalesRepId", ""); 63 String strcRegionId = vars.getInGlobalVariable("inpcRegionId", "ReportInvoiceCustomerEdition|cRegionId", ""); 64 printPageDataSheet(response, vars, strdateFrom, strdateTo, strcProjectId, strcBpartnerId, strmCategoryId, strProjectkind, strProjectstatus, strProjectphase, strProduct, strProjectpublic, strSalesRep, strcRegionId); 65 }else if (vars.commandIn("EDIT_HTML","EDIT_PDF")) { 66 String strdateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportInvoiceCustomerEdition|DateFrom"); 67 String strdateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportInvoiceCustomerEdition|DateTo"); 68 String strcProjectId = vars.getRequestGlobalVariable("inpcProjectId", "ReportInvoiceCustomerEdition|cProjectId"); 69 String strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportInvoiceCustomerEdition|cBPartnerId_IN"); 70 String strmCategoryId = vars.getRequestInGlobalVariable("inpmProductCategoryId", "ReportInvoiceCustomerEdition|mCategoryId"); 71 String strProjectkind = vars.getRequestInGlobalVariable("inpProjectkind", "ReportInvoiceCustomerEdition|Projectkind"); 72 String strProjectstatus = vars.getRequestInGlobalVariable("inpProjectstatus", "ReportInvoiceCustomerEdition|Projectstatus"); 73 String strProjectphase = vars.getRequestInGlobalVariable("inpProjectphase", "ReportInvoiceCustomerEdition|Projectphase"); 74 String strProduct = vars.getRequestInGlobalVariable("inpmProductId_IN", "ReportInvoiceCustomerEdition|mProductId_IN"); 75 String strProjectpublic = vars.getRequestGlobalVariable("inpProjectpublic", "ReportInvoiceCustomerEdition|Projectpublic"); 76 String strSalesRep = vars.getRequestGlobalVariable("inpSalesRepId", "ReportInvoiceCustomerEdition|SalesRepId"); 77 String strcRegionId = vars.getRequestInGlobalVariable("inpcRegionId", "ReportInvoiceCustomerEdition|cRegionId"); 78 printPageHtml(response, vars, strdateFrom, strdateTo, strcProjectId, strcBpartnerId, strmCategoryId, strProjectkind, strProjectstatus, strProjectphase, strProduct, strProjectpublic, strSalesRep, strcRegionId); 79 } else pageErrorPopUp(response); 80 } 81 82 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strdateFrom, String strdateTo, String strcProjectId, String strcBpartnerId, String strmCategoryId, String strProjectkind, String strProjectstatus, String strProjectphase, String strProduct, String strProjectpublic, String strSalesRep, String strcRegionId) throws IOException, ServletException { 83 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 84 85 86 String discard[]={"discard"}; 87 XmlDocument xmlDocument=null; 88 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoiceCustomerFilterJR").createXmlDocument(); 89 90 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportInvoiceCustomerFilter", false, "", "", "",false, "ad_reports", strReplaceWith, false, true); 91 toolbar.prepareSimpleToolBarTemplate(); 92 xmlDocument.setParameter("toolbar", toolbar.toString()); 93 try { 94 KeyMap key = new KeyMap(this, vars, "ReportInvoiceCustomerEdition.html"); 95 xmlDocument.setParameter("keyMap", key.getReportKeyMaps()); 96 } catch (Exception ex) { 97 throw new ServletException(ex); 98 } 99 try { 100 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportInvoiceCustomerEdition"); 101 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 102 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 103 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 104 xmlDocument.setParameter("theme", vars.getTheme()); 105 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportInvoiceCustomerEdition.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 106 xmlDocument.setParameter("navigationBar", nav.toString()); 107 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportInvoiceCustomerEdition.html", strReplaceWith); 108 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 109 } catch (Exception ex) { 110 throw new ServletException(ex); 111 } 112 { 113 OBError myMessage = vars.getMessage("ReportInvoiceCustomerEdition"); 114 vars.removeMessage("ReportInvoiceCustomerEdition"); 115 if (myMessage!=null) { 116 xmlDocument.setParameter("messageType", myMessage.getType()); 117 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 118 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 119 } 120 } 121 122 xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2)); 123 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 124 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 125 xmlDocument.setParameter("dateFrom", strdateFrom); 126 xmlDocument.setParameter("dateTo", strdateTo); 127 xmlDocument.setParameter("paramBPartnerId", strcBpartnerId); 128 xmlDocument.setParameter("cProjectId", strcProjectId); 129 xmlDocument.setParameter("projectName", InvoiceCustomerEditionData.selectProject(this, strcProjectId)); 130 xmlDocument.setParameter("mProductCatId", strmCategoryId); 131 xmlDocument.setParameter("cProjectKind", strProjectkind); 132 xmlDocument.setParameter("cRegionId", strcRegionId); 133 xmlDocument.setParameter("cProjectPhase", strProjectphase); 134 xmlDocument.setParameter("cProjectStatus", strProjectstatus); 135 xmlDocument.setParameter("cProjectPublic", strProjectpublic); 136 xmlDocument.setParameter("salesRep", strSalesRep); 137 138 try { 139 ComboTableData comboTableData = new ComboTableData(this, "LIST", "", "Projectkind", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoiceCustomerEdition"), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceCustomerEdition"), 0); 140 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoiceCustomerEdition", strProjectkind); 141 xmlDocument.setData("reportC_PROJECTKIND","liststructure", comboTableData.select(false)); 142 comboTableData = null; 143 } catch (Exception ex) { 144 throw new ServletException(ex); 145 } 146 147 try { 148 ComboTableData comboTableData = new ComboTableData(this, "LIST", "", "Projectphase", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoiceCustomerEdition"), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceCustomerEdition"), 0); 149 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoiceCustomerEdition", strProjectphase); 150 xmlDocument.setData("reportC_PROJECTPHASE","liststructure", comboTableData.select(false)); 151 comboTableData = null; 152 } catch (Exception ex) { 153 throw new ServletException(ex); 154 } 155 156 try { 157 ComboTableData comboTableData = new ComboTableData(this, "LIST", "", "ProjectStatus", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoiceCustomerEdition"), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceCustomerEdition"), 0); 158 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoiceCustomerEdition", strProjectstatus); 159 xmlDocument.setData("reportC_PROJECTSTATUS","liststructure", comboTableData.select(false)); 160 comboTableData = null; 161 } catch (Exception ex) { 162 throw new ServletException(ex); 163 } 164 165 try { 166 ComboTableData comboTableData = new ComboTableData(this, "LIST", "", "PublicPrivate", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoiceCustomerEdition"), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceCustomerEdition"), 0); 167 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoiceCustomerEdition", strProjectpublic); 168 xmlDocument.setData("reportC_PROJECTPUBLIC","liststructure", comboTableData.select(false)); 169 comboTableData = null; 170 } catch (Exception ex) { 171 throw new ServletException(ex); 172 } 173 174 xmlDocument.setData("reportC_PRODUCTCATREGORY","liststructure",SubCategoryProductData.select(this)); 175 176 177 try { 178 ComboTableData comboTableData = new ComboTableData(this, "TABLEDIR", "C_REGION_ID", "", "C_Region of Country", Utility.getContext(this, vars, "#User_Org", "ReportInvoiceCustomerEdition"), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceCustomerEdition"), 0); 179 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoiceCustomerEdition", strcRegionId); 180 xmlDocument.setData("reportC_REGIONID","liststructure", comboTableData.select(false)); 181 comboTableData = null; 182 } catch (Exception ex) { 183 throw new ServletException(ex); 184 } 185 186 try { 187 ComboTableData comboTableData = new ComboTableData(this, "TABLE", "", "190", "AD_User SalesRep", Utility.getContext(this, vars, "#User_Org", "ReportInvoiceCustomerEdition"), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceCustomerEdition"), 0); 188 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoiceCustomerEdition", strSalesRep); 189 xmlDocument.setData("reportSALESREP","liststructure", comboTableData.select(false)); 190 comboTableData = null; 191 } catch (Exception ex) { 192 throw new ServletException(ex); 193 } 194 195 xmlDocument.setData("reportCBPartnerId_IN", "liststructure", ReportProjectBuildingSiteData.selectBpartner(this, Utility.getContext(this, vars, "#User_Org", ""), Utility.getContext(this, vars, "#User_Client", ""), strcBpartnerId)); 196 xmlDocument.setData("reportMProductId_IN", "liststructure", ReportProjectBuildingSiteData.selectMproduct(this, Utility.getContext(this, vars, "#User_Org", ""), Utility.getContext(this, vars, "#User_Client", ""), strProduct)); 197 198 199 200 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 201 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 202 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 203 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 204 205 response.setContentType("text/html; charset=UTF-8"); 206 PrintWriter out = response.getWriter(); 207 out.println(xmlDocument.print()); 208 out.close(); 209 } 210 211 void printPageHtml(HttpServletResponse response, VariablesSecureApp vars, String strdateFrom, String strdateTo, String strcProjectId, String strcBpartnerId, String strmCategoryId, String strProjectkind, String strProjectstatus, String strProjectphase, String strProduct, String strProjectpublic, String strSalesRep, String strcRegionId) throws IOException, ServletException{ 212 if (log4j.isDebugEnabled()) log4j.debug("Output: print html"); 213 214 InvoiceCustomerEditionData[] data = null; 215 data = InvoiceCustomerEditionData.select(this, Utility.getContext(this, vars, "#User_Org", "InvoiceCustomerFilter"), Utility.getContext(this, vars, "#User_Client", "InvoiceCustomerFilter"), strdateFrom, strdateTo, strcBpartnerId, strcProjectId, strmCategoryId, strProjectkind, strProjectphase, strProjectstatus, strProjectpublic, strcRegionId, strSalesRep, strProduct); 216 217 218 219 JasperPrint jasperPrint; 220 String strOutput = vars.commandIn("EDIT_HTML")?"html":"pdf"; 221 String strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportSalesOrderCustomerJR.jrxml"; 222 223 HashMap<String , Object > parameters = new HashMap<String , Object >(); 224 parameters.put("Title", classInfo.name); 225 renderJR(vars, response, strReportName, strOutput, parameters, data, null ); 227 } 228 229 230 } 231 | Popular Tags |