| 1 19 package org.openbravo.erpCommon.ad_reports; 20 21 import org.openbravo.erpCommon.utility.*; 22 import org.openbravo.erpCommon.businessUtility.*; 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.ad_combos.OrganizationComboData; 31 32 import org.openbravo.erpCommon.utility.DateTimeData; 33 import org.openbravo.erpCommon.utility.ComboTableData; 34 35 36 import java.util.*; 37 import net.sf.jasperreports.engine.*; 38 import net.sf.jasperreports.engine.design.JasperDesign; 39 import java.sql.Connection ; 40 import net.sf.jasperreports.engine.xml.JRXmlLoader; 41 import net.sf.jasperreports.engine.export.JRHtmlExporter; 42 import net.sf.jasperreports.engine.export.JRHtmlExporterParameter; 43 public class ReportGeneralLedgerJournal extends HttpSecureAppServlet { 44 45 46 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 47 VariablesSecureApp vars = new VariablesSecureApp(request); 48 49 if (log4j.isDebugEnabled()) log4j.debug("Command: "+vars.getStringParameter("Command")); 50 51 if (!Utility.hasProcessAccess(this, vars, "", "RV_GeneralLedgerJournal")) { 52 bdError(response, "AccessTableNoView", vars.getLanguage()); 53 return; 54 } 55 56 57 if (vars.commandIn("DEFAULT")) { 58 String strDateFrom = vars.getGlobalVariable("inpDateFrom", "ReportGeneralLedgerJournal|DateFrom", ""); 59 String strDateTo = vars.getGlobalVariable("inpDateTo", "ReportGeneralLedgerJournal|DateTo", ""); 60 String strDocument = vars.getGlobalVariable("inpDocument", "ReportGeneralLedgerJournal|Document", ""); 61 String strOrg = vars.getGlobalVariable("inpOrg", "ReportGeneralLedgerJournal|Org", "0"); 62 printPageDataSheet(response, vars, strDateFrom, strDateTo, strDocument, strOrg, "", "", ""); 65 } else if (vars.commandIn("DIRECT")) { 66 String strTable = vars.getGlobalVariable("inpTable", "ReportGeneralLedgerJournal|Table"); 67 String strRecord = vars.getGlobalVariable("inpRecord", "ReportGeneralLedgerJournal|Record"); 68 setHistoryCommand(request, "DIRECT"); 69 vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", "0"); 70 printPageDataSheet(response, vars, "", "", "", "", strTable, strRecord, ""); 71 } else if (vars.commandIn("DIRECT2")) { 72 String strFactAcctGroupId = vars.getGlobalVariable("inpFactAcctGroupId", "ReportGeneralLedgerJournal|FactAcctGroupId"); 73 setHistoryCommand(request, "DIRECT2"); 74 vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", "0"); 75 printPageDataSheet(response, vars, "", "", "", "", "", "", strFactAcctGroupId); 76 } else if (vars.commandIn("FIND")) { 77 String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportGeneralLedgerJournal|DateFrom"); 78 String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportGeneralLedgerJournal|DateTo"); 79 String strDocument = vars.getRequestGlobalVariable("inpDocument", "ReportGeneralLedgerJournal|Document"); 80 String strOrg = vars.getGlobalVariable("inpOrg", "ReportGeneralLedgerJournal|Org","0"); 81 vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", "0"); 82 setHistoryCommand(request, "DEFAULT"); 83 printPageDataSheet(response, vars, strDateFrom, strDateTo, strDocument, strOrg, "", "", ""); 84 } else if (vars.commandIn("PDF","XLS")) { 85 if (log4j.isDebugEnabled()) log4j.debug("PDF"); 86 String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "ReportGeneralLedgerJournal|DateFrom"); 87 String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "ReportGeneralLedgerJournal|DateTo"); 88 String strDocument = vars.getRequestGlobalVariable("inpDocument", "ReportGeneralLedgerJournal|Document"); 89 String strOrg = vars.getGlobalVariable("inpOrg", "ReportGeneralLedgerJournal|Org","0"); 90 vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", "0"); 91 setHistoryCommand(request, "DEFAULT"); 92 printPagePDF(response, vars, strDateFrom, strDateTo, strDocument, strOrg, "", "", ""); 93 }else if (vars.commandIn("PREVIOUS_RELATION")) { 94 String strInitRecord = vars.getSessionValue("ReportGeneralLedgerJournal.initRecordNumber"); 95 String strRecordRange = Utility.getContext(this, vars, "#RecordRange", "ReportGeneralLedgerJournal"); 96 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 97 if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", "0"); 98 else { 99 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 100 initRecord -= intRecordRange; 101 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 102 vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", strInitRecord); 103 } 104 response.sendRedirect(strDireccion + request.getServletPath()); 105 } else if (vars.commandIn("NEXT_RELATION")) { 106 String strInitRecord = vars.getSessionValue("ReportGeneralLedgerJournal.initRecordNumber"); 107 String strRecordRange = Utility.getContext(this, vars, "#RecordRange", "ReportGeneralLedgerJournal"); 108 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 109 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 110 if (initRecord==0) initRecord=1; 111 initRecord += intRecordRange; 112 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 113 vars.setSessionValue("ReportGeneralLedgerJournal.initRecordNumber", strInitRecord); 114 response.sendRedirect(strDireccion + request.getServletPath()); 115 } else pageError(response); 116 } 117 118 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strDocument, String strOrg, String strTable, String strRecord, String strFactAcctGroupId) throws IOException, ServletException { 119 String strRecordRange = Utility.getContext(this, vars, "#RecordRange", "ReportGeneralLedgerJournal"); 120 int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange)); 121 String strInitRecord = vars.getSessionValue("ReportGeneralLedgerJournal.initRecordNumber"); 122 int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 123 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 124 response.setContentType("text/html; charset=UTF-8"); 125 PrintWriter out = response.getWriter(); 126 XmlDocument xmlDocument=null; 127 ReportGeneralLedgerJournalData[] data=null; 128 String strPosition = "0"; 129 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "ReportGeneralLedgerJournal", false, "", "", "imprimir();return false;",false, "ad_reports", strReplaceWith, false, true); 130 if (vars.commandIn("DEFAULT","FIND")){ 131 String strTreeOrg = ReportGeneralLedgerJournalData.treeOrg(this, vars.getClient()); 132 String strOrgFamily = getFamily(strTreeOrg, strOrg); 133 data = ReportGeneralLedgerJournalData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strOrgFamily, initRecordNumber, intRecordRange); 134 if (data!=null && data.length > 0) strPosition = ReportGeneralLedgerJournalData.selectCount(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strOrgFamily, data[0].dateacct, data[0].identifier); 135 }else if (vars.commandIn("DIRECT")){ 136 data = ReportGeneralLedgerJournalData.selectDirect(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strTable, strRecord, initRecordNumber, intRecordRange); 137 if (data!=null && data.length > 0) strPosition = ReportGeneralLedgerJournalData.selectCountDirect(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"),strTable, strRecord, data[0].dateacct, data[0].identifier); 138 }else if (vars.commandIn("DIRECT2")){ 139 data = ReportGeneralLedgerJournalData.selectDirect2(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strFactAcctGroupId, initRecordNumber, intRecordRange); 140 if (data!=null && data.length > 0) strPosition = ReportGeneralLedgerJournalData.selectCountDirect2(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"),strFactAcctGroupId, data[0].dateacct, data[0].identifier); 141 } 142 if (data==null || data.length==0) { 143 String discard[]={"sectionJournal"}; 145 toolbar.prepareRelationBarTemplate(false, false,"submitCommandForm('XLS', false, null, 'ReportGeneralLedgerJournal.xls', 'EXCEL');return false;"); 146 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal").createXmlDocument(); 147 data = ReportGeneralLedgerJournalData.set(); 148 } else { 149 154 boolean hasPrevious = !(data==null || data.length==0 || initRecordNumber<=1); 155 boolean hasNext = !(data==null || data.length==0 || data.length<intRecordRange); 156 toolbar.prepareRelationBarTemplate(hasPrevious, hasNext,"submitCommandForm('XLS', false, null, 'ReportGeneralLedgerJournal.xls', 'EXCEL');return false;"); 157 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal").createXmlDocument(); 158 } 159 try { 160 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "C_DocType DocBaseType", "", Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedgerJournal"), Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedgerJournal"), 0); 161 Utility.fillSQLParameters(this, vars, null, comboTableData, "ReportGeneralLedgerJournal", strDocument); 162 xmlDocument.setData("reportDocument","liststructure", comboTableData.select(false)); 163 comboTableData = null; 164 } catch (Exception ex) { 165 throw new ServletException(ex); 166 } 167 xmlDocument.setParameter("toolbar", toolbar.toString()); 168 try { 169 KeyMap key = new KeyMap(this, vars, "ReportGeneralLedgerJournal.html"); 170 xmlDocument.setParameter("keyMap", key.getReportKeyMaps()); 171 } catch (Exception ex) { 172 throw new ServletException(ex); 173 } 174 try { 175 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.ReportGeneralLedgerJournal"); 176 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 177 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 178 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 179 xmlDocument.setParameter("theme", vars.getTheme()); 180 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "ReportGeneralLedgerJournal.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 181 xmlDocument.setParameter("navigationBar", nav.toString()); 182 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "ReportGeneralLedgerJournal.html", strReplaceWith); 183 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 184 } catch (Exception ex) { 185 throw new ServletException(ex); 186 } 187 { 188 OBError myMessage = vars.getMessage("ReportGeneralLedgerJournal"); 189 vars.removeMessage("ReportGeneralLedgerJournal"); 190 if (myMessage!=null) { 191 xmlDocument.setParameter("messageType", myMessage.getType()); 192 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 193 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 194 } 195 } 196 197 xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2)); 198 xmlDocument.setParameter("document", strDocument); 199 xmlDocument.setData("reportAD_ORGID", "liststructure", OrganizationComboData.selectCombo(this, vars.getRole())); 200 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 201 xmlDocument.setParameter("paramLanguage", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 202 xmlDocument.setParameter("dateFrom", strDateFrom); 203 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 204 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 205 xmlDocument.setParameter("dateTo", strDateTo); 206 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 207 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 208 xmlDocument.setParameter("adOrgId", strOrg); 209 xmlDocument.setParameter("groupId", strPosition); 210 xmlDocument.setData("structure1", data); 211 out.println(xmlDocument.print()); 212 out.close(); 213 } 214 215 void printPagePDF(HttpServletResponse response, VariablesSecureApp vars, String strDateFrom, String strDateTo, String strDocument, String strOrg, String strTable, String strRecord, String strFactAcctGroupId) throws IOException, ServletException { 216 217 ReportGeneralLedgerJournalData[] data=null; 218 String strPosition = "0"; 219 220 String strTreeOrg = ReportGeneralLedgerJournalData.treeOrg(this, vars.getClient()); 221 String strOrgFamily = getFamily(strTreeOrg, strOrg); 222 data = ReportGeneralLedgerJournalData.select(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strOrgFamily); 223 if (data!=null && data.length > 0) 224 strPosition = ReportGeneralLedgerJournalData.selectCount(this, Utility.getContext(this, vars, "#User_Client", "ReportGeneralLedger"), Utility.getContext(this, vars, "#User_Org", "ReportGeneralLedger"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strDocument, strOrgFamily, data[0].dateacct, data[0].identifier); 225 226 String strSubtitle = Utility.messageBD(this, "CompanyName",vars.getLanguage())+": "+ ReportGeneralLedgerData.selectCompany(this, vars.getClient()); 227 228 if (strDateFrom.equals("")&&strDateTo.equals("")) 229 strSubtitle += " - "+Utility.messageBD(this, "Period",vars.getLanguage())+": "+strDateFrom + " - " + strDateTo; 230 231 JasperPrint jasperPrint; 232 String strOutput = vars.commandIn("PDF")?"pdf":"xls"; 233 String strReportName = "@basedesign@/org/openbravo/erpCommon/ad_reports/ReportGeneralLedgerJournal.jrxml"; 234 235 HashMap<String , Object > parameters = new HashMap<String , Object >(); 236 parameters.put("Title", classInfo.name); 237 parameters.put("Subtitle",strSubtitle); 238 renderJR(vars, response, strReportName, strOutput, parameters, data, null ); 239 } 240 241 242 public String getFamily(String strTree, String strChild) throws IOException, ServletException { 243 return Tree.getMembers(this, strTree, strChild); 244 253 } 254 255 public String getServletInfo() { 256 return "Servlet ReportGeneralLedgerJournal. This Servlet was made by Pablo Sarobe modified by everybody"; 257 } } 259 260 | Popular Tags |