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 java.math.BigDecimal ; 28 import javax.servlet.*; 29 import javax.servlet.http.*; 30 31 import org.openbravo.erpCommon.utility.DateTimeData; 32 33 public class GeneralAccountingReports extends HttpSecureAppServlet { 34 35 36 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 37 VariablesSecureApp vars = new VariablesSecureApp(request); 38 39 if (!Utility.hasProcessAccess(this, vars, "", "GeneralAccountingReports")) { 40 bdError(response, "AccessTableNoView", vars.getLanguage()); 41 return; 42 } 43 44 if (vars.commandIn("DEFAULT")) { 45 String strAgno = vars.getGlobalVariable("inpAgno", "GeneralAccountingReports|agno", ""); 46 String strAgnoRef = vars.getGlobalVariable("inpAgnoRef", "GeneralAccountingReports|agnoRef", ""); 47 String strDateFrom = vars.getGlobalVariable("inpDateFrom", "GeneralAccountingReports|dateFrom", ""); 48 String strDateTo = vars.getGlobalVariable("inpDateTo", "GeneralAccountingReports|dateTo", ""); 49 String strDateFromRef = vars.getGlobalVariable("inpDateFromRef", "GeneralAccountingReports|dateFromRef", ""); 50 String strDateToRef = vars.getGlobalVariable("inpDateToRef", "GeneralAccountingReports|dateToRef", ""); 51 String strElementValue = vars.getGlobalVariable("inpcElementvalueId", "GeneralAccountingReports|C_ElementValue_ID", ""); 52 String strConImporte = vars.getGlobalVariable("inpConImporte", "GeneralAccountingReports|conImporte", "N"); 53 String strConCodigo = vars.getGlobalVariable("inpConCodigo", "GeneralAccountingReports|conCodigo", "N"); 54 String strOrg = vars.getGlobalVariable("inpOrganizacion", "GeneralAccountingReports|organizacion", vars.getOrg()); 55 String strLevel = vars.getGlobalVariable("inpLevel", "GeneralAccountingReports|level", ""); 56 printPageDataSheet(response, vars, strAgno, strAgnoRef, strDateFrom, strDateTo, strDateFromRef, strDateToRef, strElementValue, strConImporte, strOrg, strLevel, strConCodigo); 57 } else if (vars.commandIn("FIND")) { 58 String strAgno = vars.getRequiredGlobalVariable("inpAgno", "GeneralAccountingReports|agno"); 59 String strAgnoRef = vars.getRequiredGlobalVariable("inpAgnoRef", "GeneralAccountingReports|agnoRef"); 60 String strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "GeneralAccountingReports|dateFrom"); 61 String strDateTo = vars.getRequestGlobalVariable("inpDateTo", "GeneralAccountingReports|dateTo"); 62 String strDateFromRef = vars.getRequestGlobalVariable("inpDateFromRef", "GeneralAccountingReports|dateFromRef"); 63 String strDateToRef = vars.getRequestGlobalVariable("inpDateToRef", "GeneralAccountingReports|dateToRef"); 64 String strElementValue = vars.getRequiredGlobalVariable("inpcElementvalueId", "GeneralAccountingReports|C_ElementValue_ID"); 65 String strConImporte = vars.getRequestGlobalVariable("inpConImporte", "GeneralAccountingReports|conImporte"); 66 String strConCodigo = vars.getRequestGlobalVariable("inpConCodigo", "GeneralAccountingReports|conCodigo"); 67 String strOrg = vars.getRequestGlobalVariable("inpOrganizacion", "GeneralAccountingReports|organizacion"); 68 String strLevel = vars.getRequestGlobalVariable("inpLevel", "GeneralAccountingReports|level"); 69 printPagePDF(response, vars, strAgno, strAgnoRef, strDateFrom, strDateTo, strDateFromRef, strDateToRef, strElementValue, strConImporte, strOrg, strLevel, strConCodigo); 70 } else pageError(response); 71 } 72 73 void printPagePDF(HttpServletResponse response, VariablesSecureApp vars, String strAgno, String strAgnoRef, String strDateFrom, String strDateTo, String strDateFromRef, String strDateToRef, String strElementValue, String strConImporte, String strOrg, String strLevel, String strConCodigo) throws IOException,ServletException{ 74 if (log4j.isDebugEnabled()) log4j.debug("Output: pdf"); 75 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/GeneralAccountingReportsPDF").createXmlDocument(); 76 77 GeneralAccountingReportsData[] strGroups = GeneralAccountingReportsData.selectGroups(this, strElementValue); 78 strGroups[strGroups.length-1].pagebreak = ""; 79 80 String [][] strElementValueDes = new String [strGroups.length][]; 81 if (log4j.isDebugEnabled()) log4j.debug("strElementValue:"+strElementValue+" - strGroups.length:"+strGroups.length); 82 for (int i=0; i<strGroups.length; i++) { 83 GeneralAccountingReportsData[] strElements = GeneralAccountingReportsData.selectElements(this, strGroups[i].id); 84 strElementValueDes[i] = new String [strElements.length]; 85 if (log4j.isDebugEnabled()) log4j.debug("strElements.length:"+strElements.length); 86 for (int j=0; j<strElements.length; j++){ 87 strElementValueDes[i][j] = strElements[j].id; 88 } 89 } 90 91 92 String strTreeOrg = GeneralAccountingReportsData.treeOrg(this, vars.getClient()); 93 AccountTree[] acct = new AccountTree[strGroups.length]; 94 95 AccountTreeData[][] elements = new AccountTreeData[strGroups.length][]; 96 97 WindowTreeData[] dataTree = WindowTreeData.selectTreeID(this, vars.getClient(), "EV"); 98 String TreeID = ""; 99 if (dataTree!=null && dataTree.length!=0) TreeID = dataTree[0].id; 100 101 for (int i=0; i<strGroups.length; i++) { 102 if (vars.getLanguage().equals("en_US")){ 103 elements[i] = AccountTreeData.select(this, strConCodigo, TreeID); 104 } else { 105 elements[i] = AccountTreeData.selectTrl(this, strConCodigo,vars.getLanguage(), TreeID ); 106 } 107 AccountTreeData[] accounts = AccountTreeData.selectAcct(this, Utility.getContext(this, vars, "#User_Org", "GeneralAccountingReports"), Utility.getContext(this, vars, "#User_Client", "GeneralAccountingReports"), strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), Tree.getMembers(this, strTreeOrg, strOrg), strAgno, strDateFromRef, DateTimeData.nDaysAfter(this, strDateToRef,"1"), strAgnoRef); 108 109 { 110 String strIncomeSummary = GeneralAccountingReportsData.incomesummary(this, Utility.getContext(this, vars, "$C_ACCTSCHEMA_ID", "GeneralAccountingReports")); 111 if (log4j.isDebugEnabled()) log4j.debug("*********** strIncomeSummary: " + strIncomeSummary); 112 String strISyear = processIncomeSummary(strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"), strAgno, strTreeOrg, strOrg); 113 if (log4j.isDebugEnabled()) log4j.debug("*********** strISyear: " + strISyear); 114 String strISyearRef = processIncomeSummary(strDateFromRef, DateTimeData.nDaysAfter(this, strDateToRef,"1"), strAgnoRef, strTreeOrg, strOrg); 115 if (log4j.isDebugEnabled()) log4j.debug("*********** strISyearRef: " + strISyearRef); 116 accounts = appendRecords(accounts, strIncomeSummary, strISyear, strISyearRef); 117 118 } 119 acct[i] = new AccountTree(vars, this, elements[i], accounts, strElementValueDes[i]); 120 if (acct[i]!=null) { 121 acct[i].filter(strConImporte.equals("Y"), strLevel, false); 122 } else if (log4j.isDebugEnabled()) log4j.debug("acct null!!!"); 123 } 124 125 126 xmlDocument.setData("group", strGroups); 127 128 xmlDocument.setParameter("agno", "Ejercicio "+strAgno); 129 xmlDocument.setParameter("agno2", "Ejercicio "+strAgno); 130 xmlDocument.setParameter("column", "Ejercicio "+strAgno); 131 xmlDocument.setParameter("columnRef", "Ejercicio "+strAgnoRef); 132 xmlDocument.setParameter("column1", "Ejercicio "+strAgno); 133 xmlDocument.setParameter("columnRef1", "Ejercicio "+strAgnoRef); 134 xmlDocument.setParameter("companyName", GeneralAccountingReportsData.companyName(this, vars.getClient())); 135 xmlDocument.setParameter("date", DateTimeData.today(this)); 136 if (strDateFrom.equals("")) strDateFrom = "01/01/"+strAgno; 137 if (strDateTo.equals("")) strDateTo = GeneralAccountingReportsData.date(this, strAgno, vars.getSqlDateFormat()); 138 if (strDateFromRef.equals("")) strDateFromRef = "01/01/"+strAgnoRef; 139 if (strDateToRef.equals("")) strDateToRef = GeneralAccountingReportsData.date(this, strAgnoRef, vars.getSqlDateFormat()); 140 xmlDocument.setParameter("period", strDateFrom + " - " + strDateTo); 141 xmlDocument.setParameter("periodRef", strDateFromRef + " - " + strDateToRef); 142 xmlDocument.setParameter("agnoInitial", strAgno); 143 xmlDocument.setParameter("agnoRef", strAgnoRef); 144 145 146 147 xmlDocument.setParameter("principalTitle", GeneralAccountingReportsData.rptTitle(this, strElementValue)); 148 149 150 AccountTreeData[][] trees= new AccountTreeData[strGroups.length][]; 151 152 for (int i=0; i<strGroups.length; i++) 153 trees[i] = acct[i].getAccounts(); 154 155 xmlDocument.setDataArray("reportDetail","structure1",trees); 156 157 String strResult = xmlDocument.print(); 158 renderFO(strResult, response); 159 } 160 161 AccountTreeData[] appendRecords(AccountTreeData[] data, String strIncomeSummary, String strISyear, String strISyearRef) throws ServletException { 162 if (data==null || strIncomeSummary==null || strIncomeSummary.equals("") || strISyear==null || strISyear.equals("") || strISyearRef==null || strISyearRef.equals("")) return data; 163 AccountTreeData[] data2 = new AccountTreeData[data.length + 1]; 164 boolean found = false; 165 for (int i=0;i<data.length;i++) { 166 if (data[i].id.equals(strIncomeSummary)) { 167 found=true; 168 double isYear = Double.valueOf(strISyear).doubleValue(); 169 double isYearRef = Double.valueOf(strISyearRef).doubleValue(); 170 data[i].qty = Double.toString(Double.valueOf(data[i].qty).doubleValue() + isYear); 171 data[i].qtycredit = Double.toString(Double.valueOf(data[i].qtycredit).doubleValue() + isYear); 172 data[i].qtyRef = Double.toString(Double.valueOf(data[i].qtyRef).doubleValue() + isYearRef); 173 data[i].qtycreditRef = Double.toString(Double.valueOf(data[i].qtycreditRef).doubleValue() + isYearRef); 174 } 175 data2[i] = data[i]; 176 } 177 if (!found) { 178 data2[data2.length-1] = new AccountTreeData(); 179 data2[data2.length-1].id = strIncomeSummary; 180 data2[data2.length-1].qty = strISyear; 181 data2[data2.length-1].qtycredit = strISyear; 182 data2[data2.length-1].qtyRef = strISyearRef; 183 data2[data2.length-1].qtycreditRef = strISyearRef; 184 } else return data; 185 return data2; 186 } 187 188 String processIncomeSummary(String strDateFrom, String strDateTo, String strAgno, String strTreeOrg, String strOrg) throws ServletException, IOException { 189 String strISRevenue = GeneralAccountingReportsData.selectPyG(this, "R", strDateFrom, strDateTo, strAgno, Tree.getMembers(this, strTreeOrg, strOrg)); 190 String strISExpense = GeneralAccountingReportsData.selectPyG(this, "E", strDateFrom, strDateTo, strAgno, Tree.getMembers(this, strTreeOrg, strOrg)); 191 BigDecimal totalRevenue = new BigDecimal (strISRevenue); 192 BigDecimal totalExpense = new BigDecimal (strISExpense); 193 BigDecimal total = totalRevenue.add(totalExpense); 194 if (log4j.isDebugEnabled()) log4j.debug(total.toString()); 195 return total.toString(); 196 } 197 198 void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String strAgno, String strAgnoRef, String strDateFrom, String strDateTo, String strDateFromRef, String strDateToRef, String strElementValue, String strConImporte, String strOrg, String strLevel, String strConCodigo) throws IOException, ServletException { 199 if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); 200 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_reports/GeneralAccountingReports").createXmlDocument(); 201 202 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "GeneralAccountingReports", false, "", "", "",false, "ad_reports", strReplaceWith, false, true); 203 toolbar.prepareSimpleToolBarTemplate(); 204 xmlDocument.setParameter("toolbar", toolbar.toString()); 205 206 try { 207 KeyMap key = new KeyMap(this, vars, "GeneralAccountingReports.html"); 208 xmlDocument.setParameter("keyMap", key.getReportKeyMaps()); 209 } catch (Exception ex) { 210 throw new ServletException(ex); 211 } 212 try { 213 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_reports.GeneralAccountingReports"); 214 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 215 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 216 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 217 xmlDocument.setParameter("theme", vars.getTheme()); 218 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "GeneralAccountingReports.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 219 xmlDocument.setParameter("navigationBar", nav.toString()); 220 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "GeneralAccountingReports.html", strReplaceWith); 221 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 222 } catch (Exception ex) { 223 throw new ServletException(ex); 224 } 225 { 226 OBError myMessage = vars.getMessage("GeneralAccountingReports"); 227 vars.removeMessage("GeneralAccountingReports"); 228 if (myMessage!=null) { 229 xmlDocument.setParameter("messageType", myMessage.getType()); 230 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 231 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 232 } 233 } 234 235 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 236 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 237 xmlDocument.setParameter("agno", strAgno); 238 xmlDocument.setParameter("agnoRef", strAgnoRef); 239 xmlDocument.setParameter("dateFrom", strDateFrom); 240 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 241 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 242 xmlDocument.setParameter("dateTo", strDateTo); 243 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 244 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 245 xmlDocument.setParameter("dateFromRef", strDateFromRef); 246 xmlDocument.setParameter("dateFromRefdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 247 xmlDocument.setParameter("dateFromRefsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 248 xmlDocument.setParameter("dateToRef", strDateToRef); 249 xmlDocument.setParameter("dateToRefdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 250 xmlDocument.setParameter("dateToRefsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 251 xmlDocument.setParameter("conImporte", strConImporte); 252 xmlDocument.setParameter("conCodigo", strConCodigo); 253 xmlDocument.setParameter("organizacion", strOrg); 254 xmlDocument.setParameter("C_ElementValue_ID", strElementValue); 255 xmlDocument.setParameter("level", strLevel); 256 try { 257 ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "C_ElementValue level", "", Utility.getContext(this, vars, "#User_Org", "GeneralAccountingReports"), Utility.getContext(this, vars, "#User_Client", "GeneralAccountingReports"), 0); 258 Utility.fillSQLParameters(this, vars, null, comboTableData, "GeneralAccountingReports", ""); 259 xmlDocument.setData("reportLevel","liststructure", comboTableData.select(false)); 260 comboTableData = null; 261 } catch (Exception ex) { 262 throw new ServletException(ex); 263 } 264 265 xmlDocument.setData("reportAD_ORGID", "liststructure", GeneralAccountingReportsData.selectCombo(this, vars.getRole())); 266 WindowTreeData[] data = WindowTreeData.selectTreeID(this, vars.getClient(), "EV"); 267 String TreeID = ""; 268 if (data!=null && data.length!=0) TreeID = data[0].id; 269 270 271 try { 272 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_Acct_Rpt_ID", "", "", Utility.getContext(this, vars, "#User_Org", "GeneralAccountingReports"), Utility.getContext(this, vars, "#User_Client", "GeneralAccountingReports"), 0); 273 Utility.fillSQLParameters(this, vars, null, comboTableData, "GeneralAccountingReports", ""); 274 xmlDocument.setData("reportC_ElementValue_ID","liststructure", comboTableData.select(false)); 275 comboTableData = null; 276 } catch (Exception ex) { 277 throw new ServletException(ex); 278 } 279 280 281 response.setContentType("text/html; charset=UTF-8"); 282 PrintWriter out = response.getWriter(); 283 out.println(xmlDocument.print()); 284 out.close(); 285 } 286 287 public String getServletInfo() { 288 return "Servlet GeneralAccountingReportsData"; 289 } } 291 292 | Popular Tags |