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 org.openbravo.erpCommon.utility.DateTimeData; 31 32 import net.sf.jasperreports.engine.*; 33 import net.sf.jasperreports.engine.design.JasperDesign; 34 import java.sql.Connection ; 35 import net.sf.jasperreports.engine.xml.JRXmlLoader; 36 import net.sf.jasperreports.engine.export.JRHtmlExporter; 37 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; 38 import java.util.HashMap ; 39 40 public class ReportProjectProfitabilityJR extends HttpSecureAppServlet { 41 42 public static String strTreeOrg = ""; 43 44 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 45 VariablesSecureApp vars = new VariablesSecureApp(request); 46 47 if (!Utility.hasProcessAccess(this, vars, "", "ReportProjectProfitabilityJR")) { 48 bdError(response, "AccessTableNoView", vars.getLanguage()); 49 return; 50 } 51 52 if (vars.commandIn("DEFAULT")) { 53 String strOrg = vars.getGlobalVariable("inpOrg", "ReportProjectProfitabilityJR|Org", vars.getOrg()); 54 String strProject = vars.getGlobalVariable("inpProject", "ReportProjectProfitabilityJR|Project", ""); 55 String strProjectType = vars.getGlobalVariable("inpProjectType", "ReportProjectProfitabilityJR|ProjectType", ""); 56 String strResponsible = vars.getGlobalVariable("inpResponsible", "ReportProjectProfitabilityJR|Responsible", ""); 57 String strDateFrom = vars.getGlobalVariable("inpDateFrom", "ReportProjectProfitabilityJR|DateFrom", ""); 58 String strDateTo = vars.getGlobalVariable("inpDateTo", "ReportProjectProfitabilityJR|DateTo", ""); 59 String strExpand = vars.getGlobalVariable("inpExpand", "ReportProjectProfitabilityJR|Expand", "Y"); 60 String strPartner = vars.getGlobalVariable("inpcBPartnerId", "ReportProjectProfitabilityJR|Partner", ""); 61 printPageDataSheet(response, vars, strOrg, strProject, strProjectType, strResponsible, strDateFrom, strDateTo, strExpand, strPartner); 62 } else if (vars.commandIn("FIND")) { 63 String strOrg = vars.getRequestGlobalVariable("inpOrg", "ReportProjectProfitabilityJR|Org"); 64 String strProject = vars.getRequestGlobalVariable("inpProject", "ReportProjectProfitabilityJR|Project"); 65 String strProjectType = vars.getRequestGlobalVariable("inpProjectType", "ReportProjectProfitabilityJR|ProjectType"); 66 String strResponsible = vars.getRequestGlobalVariable("inpResponsible", "ReportProjectProfitabilityJR|Responsible"); 67 String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportProjectProfitabilityJR|DateFrom"); 68 String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportProjectProfitabilityJR|DateTo"); 69 String strExpand = vars.getRequestGlobalVariable("inpExpand", "ReportProjectProfitabilityJR|Expand"); 70 String strPartner = vars.getRequestGlobalVariable("inpcBPartnerId", "ReportProjectProfitabilityJR|Partner"); 71 printPageDataHtml(response, vars, strOrg, strProject, strProjectType, strResponsible, strDateFrom, strDateTo, strExpand, strPartner); 72 } else pageError(response); 73 } 74 75 76 void printPageDataHtml(HttpServletResponse response, VariablesSecureApp vars, String strOrg, String strProject, String strProjectType, String strResponsible, String strDateFrom, String strDateTo, String strExpand, String strPartner) 77 throws IOException, ServletException { 78 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 79 80 String discard[]={"discard"}; 81 XmlDocument xmlDocument; 82 strTreeOrg = strOrg; 83 if (strExpand.equals("Y")) treeOrg(vars, strOrg); 84 ReportProjectProfitabilityData[] data= ReportProjectProfitabilityData.select(this, strTreeOrg, strDateFrom , DateTimeData.nDaysAfter(this, strDateTo,"1"), strProjectType, strProject, strResponsible, strPartner); 85 86 if (data == null || data.length == 0) { 87 data = ReportProjectProfitabilityData.set("1","1","1","1","1","1","1","1","1","1","1"); 88 discard[0] = "discardAll"; 89 } 90 91 92 JasperPrint jasperPrint; 93 String strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportProjectProfitabilityJR.jrxml"; 94 String strOutput="html"; 95 if (strOutput.equals("pdf")) response.setHeader("Content-disposition", "inline; filename=ReportProjectProfitabilityJR.pdf"); 96 97 98 HashMap <String , Object > parameters = new HashMap <String , Object >(); 99 parameters.put("Title", "Project profitability"); 100 parameters.put("REPORT_TITLE", "Project profitability"); 101 parameters.put("REPORT_SUBTITLE", "Filters: "+strDateFrom+" to "+strDateTo); 102 103 renderJR(vars, response, strReportName, strOutput, parameters, data, null ); 104 } 105 106 107 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strOrg, String strProject, String strProjectType, String strResponsible, String strDateFrom, String strDateTo, String strExpand, String strPartner) 108 throws IOException, ServletException { 109 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 110 response.setContentType("text/html; charset=UTF-8"); 111 PrintWriter out = response.getWriter(); 112 113 XmlDocument xmlDocument; 114 strTreeOrg = strOrg; 115 if (strExpand.equals("Y")) treeOrg(vars, strOrg); 116 117 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportProjectProfitabilityJR").createXmlDocument(); 118 119 120 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportProjectProfitabilityJR", false, "", "", "",false, "ad_reports", strReplaceWith, false, true); 121 toolbar.prepareSimpleToolBarTemplate(); 122 xmlDocument.setParameter("toolbar", toolbar.toString()); 123 124 try { 125 KeyMap key = new KeyMap(this, vars, "ReportProjectProfitabilityJR.html"); 126 xmlDocument.setParameter("keyMap", key.getReportKeyMaps()); 127 } catch (Exception ex) { 128 throw new ServletException(ex); 129 } 130 try { 131 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportProjectProfitabilityJR"); 132 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 133 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 134 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 135 xmlDocument.setParameter("theme", vars.getTheme()); 136 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportProjectProfitabilityJR.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 137 xmlDocument.setParameter("navigationBar", nav.toString()); 138 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportProjectProfitabilityJR.html", strReplaceWith); 139 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 140 } catch (Exception ex) { 141 throw new ServletException(ex); 142 } 143 { 144 OBError myMessage = vars.getMessage("ReportProjectProfitabilityJR"); 145 vars.removeMessage("ReportProjectProfitabilityJR"); 146 if (myMessage!=null) { 147 xmlDocument.setParameter("messageType", myMessage.getType()); 148 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 149 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 150 } 151 } 152 153 xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2)); 154 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 155 xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 156 157 xmlDocument.setParameter("dateFrom", strDateFrom); 158 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 159 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 160 xmlDocument.setParameter("dateTo", strDateTo); 161 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 162 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 163 164 165 xmlDocument.setParameter("orgid", strOrg); 166 xmlDocument.setParameter("project", strProject); 167 xmlDocument.setParameter("projecttype", strProjectType); 168 xmlDocument.setParameter("responsible", strResponsible); 169 xmlDocument.setParameter("partnerid", strPartner); 170 xmlDocument.setParameter("expand", strExpand); 171 172 173 try { 174 ComboTableData comboTableData = null; 175 176 comboTableData = new ComboTableData(vars, this, "TABLE", "Responsible_ID", "Responsible employee", "", Utility.getContext(this, vars, "#User_Org", "ReportProjectProfitabilityJR"), Utility.getContext(this, vars, "#User_Client", "ReportProjectProfitabilityJR"), 0); 177 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportProjectProfitabilityJR", strResponsible); 178 xmlDocument.setData("reportResponsible","liststructure", comboTableData.select(false)); 179 comboTableData = null; 180 181 comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_Org_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportProjectProfitabilityJR"), Utility.getContext(this, vars, "#User_Client", "ReportProjectProfitabilityJR"), 0); 182 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportProjectProfitabilityJR", strOrg); 183 xmlDocument.setData("reportAD_Org_ID","liststructure", comboTableData.select(false)); 184 comboTableData = null; 185 186 comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Project_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportProjectProfitabilityJR"), Utility.getContext(this, vars, "#User_Client", "ReportProjectProfitabilityJR"), 0); 187 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportProjectProfitabilityJR", strProject); 188 xmlDocument.setData("reportC_Project_ID","liststructure", comboTableData.select(false)); 189 comboTableData = null; 190 191 comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_ProjectType_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportProjectProfitabilityJR"), Utility.getContext(this, vars, "#User_Client", "ReportProjectProfitabilityJR"), 0); 192 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportProjectProfitabilityJR", strProjectType); 193 xmlDocument.setData("reportC_ProjectType_ID","liststructure", comboTableData.select(false)); 194 comboTableData = null; 195 196 } catch (Exception e) {throw new ServletException(e);} 197 198 out.println(xmlDocument.print()); 199 out.close(); 200 } 201 202 public String getServletInfo() { 203 return "Servlet ReportProjectProfitabilityJR. This Servlet was made by Pablo Sarobe"; 204 } 206 void treeOrg(VariablesSecureApp vars, String strOrg) throws ServletException{ 207 ReportProjectProfitabilityData[] dataOrg = ReportProjectProfitabilityData.selectOrg(this, strOrg, vars.getClient()); 208 for (int i = 0; i<dataOrg.length; i++) { 209 strTreeOrg += "," + dataOrg[i].nodeId; 210 if (dataOrg[i].issummary.equals("Y")) treeOrg(vars, dataOrg[i].nodeId); 211 } 212 return; 213 } 214 } 215 | Popular Tags |