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.DateTimeData; 32 33 import net.sf.jasperreports.engine.*; 34 import net.sf.jasperreports.engine.design.JasperDesign; 35 import java.sql.Connection ; 36 import net.sf.jasperreports.engine.xml.JRXmlLoader; 37 import net.sf.jasperreports.engine.export.JRHtmlExporter; 38 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; 39 40 public class ReportInvoicesJR extends HttpSecureAppServlet { 41 42 43 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 44 VariablesSecureApp vars = new VariablesSecureApp(request); 45 46 50 51 if (vars.commandIn("DEFAULT")) { 52 String strC_BPartner_ID = vars.getGlobalVariable("inpcBPartnerId", "ReportInvoices|C_BPartner_ID", ""); 53 String strM_Product_ID = vars.getGlobalVariable("inpmProductId", "ReportInvoices|M_Product_ID", ""); 54 String strDateFrom = vars.getGlobalVariable("inpDateInvoiceFrom", "ReportInvoices|DateFrom", ""); 55 String strDateTo = vars.getGlobalVariable("inpDateInvoiceTo", "ReportInvoices|DateTo", ""); 56 String strDocumentNo = vars.getGlobalVariable("inpInvoicedocumentno", "ReportInvoices|DocumentNo", ""); 57 String strOrder = vars.getGlobalVariable("inpOrder", "ReportInvoices|Order", "SalesOrder"); 58 String strC_BpGroup_ID = vars.getGlobalVariable("inpcBpGroupId", "ReportInvoices|C_BpGroup_ID", ""); 59 String strM_Product_Category_ID = vars.getGlobalVariable("inpmProductCategoryId", "ReportInvoices|M_Product_Category_ID", ""); 60 printPageDataSheet(response, vars, strC_BPartner_ID, strM_Product_ID, strDateFrom, strDateTo, strDocumentNo, strOrder, strC_BpGroup_ID, strM_Product_Category_ID); 61 } else if (vars.commandIn("FIND")) { 62 String strC_BPartner_ID = vars.getRequestGlobalVariable("inpcBPartnerId", "ReportInvoices|C_BPartner_ID"); 63 String strM_Product_ID = vars.getRequestGlobalVariable("inpmProductId", "ReportInvoices|M_Product_ID"); 64 String strDateFrom = vars.getRequestGlobalVariable("inpDateInvoiceFrom", "ReportInvoices|DateFrom"); 65 String strDateTo = vars.getRequestGlobalVariable("inpDateInvoiceTo", "ReportInvoices|DateTo"); 66 String strDocumentNo = vars.getRequestGlobalVariable("inpInvoicedocumentno", "ReportInvoices|DocumentNo"); 67 String strOrder = vars.getGlobalVariable("inpOrder", "ReportInvoices|Order"); 68 String strC_BpGroup_ID = vars.getRequestGlobalVariable("inpcBpGroupId", "ReportInvoices|C_BpGroup_ID"); 69 String strM_Product_Category_ID = vars.getRequestGlobalVariable("inpmProductCategoryId", "ReportInvoices|M_Product_Category_ID"); 70 printPageDataHtml(response, vars, strC_BPartner_ID, strM_Product_ID, strDateFrom, strDateTo, strDocumentNo, strOrder, strC_BpGroup_ID, strM_Product_Category_ID); 71 } else pageError(response); 72 } 73 74 void printPageDataHtml(HttpServletResponse response, VariablesSecureApp vars, String strC_BPartner_ID, String strM_Product_ID, String strDateFrom, String strDateTo, String strDocumentNo, String strOrder, String strC_BpGroup_ID, String strM_Product_Category_ID) 75 throws IOException, ServletException { 76 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 77 response.setContentType("text/html; charset=UTF-8"); 78 JasperPrint jasperPrint; 80 81 String strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportInvoicesEditJR.jrxml"; 82 String strOutput = "html"; 83 if (strOutput.equals("html")) response.setHeader("Content-disposition", "inline; filename=ReportInvoicesEdit.html"); 84 85 ReportInvoicesData[] data=null; 86 87 data = ReportInvoicesData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), strC_BpGroup_ID, strM_Product_Category_ID, strC_BPartner_ID, strM_Product_ID, strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocumentNo, (strOrder.equals("PurchaseOrder"))?"":"sales", (strOrder.equals("PurchaseOrder"))?"purchase":""); 88 89 HashMap <String , Object > parameters = new HashMap <String , Object >(); 90 parameters.put("REPORT_TITLE", classInfo.name); 91 92 renderJR(vars, response, strReportName, strOutput, parameters, data, null ); 93 94 String discard[]={"sectionBPartner"}; 95 XmlDocument xmlDocument=null; 96 113 } 114 115 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strC_BPartner_ID, String strM_Product_ID, String strDateFrom, String strDateTo, String strDocumentNo, String strOrder, String strC_BpGroup_ID, String strM_Product_Category_ID) 116 throws IOException, ServletException { 117 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 118 response.setContentType("text/html; charset=UTF-8"); 119 PrintWriter out = response.getWriter(); 120 121 XmlDocument xmlDocument=null; 122 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoicesJR").createXmlDocument(); 123 124 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportInvoicesJR", false, "", "", "",false, "ad_reports", strReplaceWith, false, true); 125 toolbar.prepareSimpleToolBarTemplate(); 126 xmlDocument.setParameter("toolbar", toolbar.toString()); 127 try { 128 KeyMap key = new KeyMap(this, vars, "ReportInvoicesJR.html"); 129 xmlDocument.setParameter("keyMap", key.getReportKeyMaps()); 130 } catch (Exception ex) { 131 throw new ServletException(ex); 132 } 133 try { 134 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportInvoicesJR"); 135 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 136 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 137 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 138 xmlDocument.setParameter("theme", vars.getTheme()); 139 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportInvoicesJR.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 140 xmlDocument.setParameter("navigationBar", nav.toString()); 141 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportInvoicesJR.html", strReplaceWith); 142 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 143 } catch (Exception ex) { 144 throw new ServletException(ex); 145 } 146 { 147 OBError myMessage = vars.getMessage("ReportInvoices"); 148 vars.removeMessage("ReportInvoices"); 149 if (myMessage!=null) { 150 xmlDocument.setParameter("messageType", myMessage.getType()); 151 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 152 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 153 } 154 } 155 156 157 xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2)); 158 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 159 xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 160 xmlDocument.setParameter("paramBPartnerId", strC_BPartner_ID); 161 xmlDocument.setParameter("paramMProductId", strM_Product_ID); 162 xmlDocument.setParameter("dateFrom", strDateFrom); 163 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 164 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 165 xmlDocument.setParameter("dateTo", strDateTo); 166 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 167 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 168 xmlDocument.setParameter("paramDocumentNo", strDocumentNo); 169 xmlDocument.setParameter("paramCBpGroupID", strC_BpGroup_ID); 170 xmlDocument.setParameter("paramMProductCategoryID", strM_Product_Category_ID); 171 xmlDocument.setParameter("sales", strOrder); 172 xmlDocument.setParameter("purchase", strOrder); 173 xmlDocument.setParameter("paramBPartnerDescription", ReportInvoicesData.bPartnerDescription(this, strC_BPartner_ID)); 174 xmlDocument.setParameter("paramMProductIDDES", ReportInvoicesData.mProductDescription(this, strM_Product_ID)); 175 176 177 try { 178 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_BP_Group_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), 0); 179 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoices", strC_BpGroup_ID); 180 xmlDocument.setData("reportC_Bp_Group","liststructure", comboTableData.select(false)); 181 comboTableData = null; 182 } catch (Exception ex) { 183 throw new ServletException(ex); 184 } 185 186 187 188 try { 189 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "M_Product_Category_ID", "", "", Utility.getContext(this, vars, "#User_Org", "ReportInvoices"), Utility.getContext(this, vars, "#User_Client", "ReportInvoices"), 0); 190 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportInvoices", strM_Product_Category_ID); 191 xmlDocument.setData("reportM_Product_Category","liststructure", comboTableData.select(false)); 192 comboTableData = null; 193 } catch (Exception ex) { 194 throw new ServletException(ex); 195 } 196 197 198 199 out.println(xmlDocument.print()); 200 out.close(); 201 } 202 203 293 294 public String getServletInfo() { 295 return "Servlet ReportInvoices. This Servlet was made by Pablo Sarobe"; 296 } } 298 299 | Popular Tags |