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 ReportInvoiceDiscountJR 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", "ReportInvoiceDiscountJR|dateFrom", ""); 53 String strDateTo = vars.getGlobalVariable("inpDateTo", "ReportInvoiceDiscountJR|dateTo", ""); 54 String strcBpartnerId = vars.getInGlobalVariable("inpcBPartnerId_IN", "ReportInvoiceDiscountJR|partner", ""); 55 String strDiscount = vars.getGlobalVariable("inpDiscount", "ReportInvoiceDiscountJR|discount", "N"); 56 printPageDataSheet(response, vars, strDateFrom, strDateTo, strcBpartnerId, strDiscount); 57 } else if (vars.commandIn("FIND")) { 58 String strDateFrom = vars.getGlobalVariable("inpDateFrom", "ReportInvoiceDiscountJR|dateFrom", ""); 59 String strDateTo = vars.getGlobalVariable("inpDateTo", "ReportInvoiceDiscountJR|dateTo", ""); 60 String strcBpartnerId = vars.getRequestInGlobalVariable("inpcBPartnerId_IN", "ReportInvoiceDiscountJR|partner"); 61 String strDiscount = vars.getRequestGlobalVariable("inpDiscount", "ReportInvoiceDiscountJR|discount"); 62 printPageDataHtml(response, vars, strDateFrom, strDateTo, strcBpartnerId, strDiscount); 63 } else pageError(response); 64 } 65 66 void printPageDataHtml(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strcBpartnerId, String strDiscount) throws IOException, ServletException { 67 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 68 69 70 XmlDocument xmlDocument=null; 71 if (strDiscount.equals("")) strDiscount = "N"; 72 73 74 JasperPrint jasperPrint; 75 76 String strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscountJR.jrxml"; 77 String strOutput = "html"; 78 if (strOutput.equals("pdf")) response.setHeader("Content-disposition", "inline; filename=ReportInvoiceDiscountEdit.pdf"); 79 ReportInvoiceDiscountData[] data = ReportInvoiceDiscountData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportInvoiceDiscountJR"), Utility.getContext(this, vars, "#User_Org", "ReportInvoiceDiscountJR"), strDateFrom,DateTimeData.nDaysAfter(this, strDateTo,"1"), strcBpartnerId, (strDiscount.equals("N"))?"":"discount"); 80 HashMap <String , Object > parameters = new HashMap <String , Object >(); 81 parameters.put("REPORT_TITLE", ""); 82 83 renderJR(vars, response, strReportName, strOutput, parameters, data, null ); 84 85 96 } 97 98 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strcBpartnerId, String strDiscount) throws IOException, ServletException { 99 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 100 101 XmlDocument xmlDocument=null; 102 if (strDiscount.equals("")) strDiscount = "N"; 103 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportInvoiceDiscountJR").createXmlDocument(); 104 105 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportInvoiceDiscountReportInvoiceDiscountJR", false, "", "", "",false, "ad_reports", strReplaceWith, false, true); 106 toolbar.prepareSimpleToolBarTemplate(); 107 xmlDocument.setParameter("toolbar", toolbar.toString()); 108 try { 109 KeyMap key = new KeyMap(this, vars, "ReportInvoiceDiscountJR.html"); 110 xmlDocument.setParameter("keyMap", key.getReportKeyMaps()); 111 } catch (Exception ex) { 112 throw new ServletException(ex); 113 } 114 try { 115 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportInvoiceDiscountJR"); 116 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 117 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 118 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 119 xmlDocument.setParameter("theme", vars.getTheme()); 120 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportInvoiceDiscountJR.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 121 xmlDocument.setParameter("navigationBar", nav.toString()); 122 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportInvoiceDiscountJR.html", strReplaceWith); 123 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 124 } catch (Exception ex) { 125 throw new ServletException(ex); 126 } 127 { 128 OBError myMessage = vars.getMessage("ReportInvoiceDiscountJR"); 129 vars.removeMessage("ReportInvoiceDiscountJR"); 130 if (myMessage!=null) { 131 xmlDocument.setParameter("messageType", myMessage.getType()); 132 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 133 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 134 } 135 } 136 137 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 138 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 139 xmlDocument.setParameter("dateFrom", strDateFrom); 140 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 141 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 142 xmlDocument.setParameter("dateTo", strDateTo); 143 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 144 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 145 xmlDocument.setParameter("discount", strDiscount); 146 xmlDocument.setData("reportCBPartnerId_IN", "liststructure", ReportInvoiceDiscountData.selectBpartner(this, Utility.getContext(this, vars, "#User_Org", "ReportInvoiceDiscountJR"), Utility.getContext(this, vars, "#User_Client", "ReportInvoiceDiscountJR"), strcBpartnerId)); 147 148 response.setContentType("text/html; charset=UTF-8"); 149 PrintWriter out = response.getWriter(); 150 out.println(xmlDocument.print()); 151 out.close(); 152 } 153 154 155 206 207 208 public String getServletInfo() { 209 return "Servlet ReportInvoiceDiscount. This Servlet was made by Pablo Sarobe"; 210 } } 212 213 | Popular Tags |