1 17 18 package org.openbravo.erpCommon.ad_process; 19 20 21 import org.openbravo.erpCommon.businessUtility.WindowTabs; 22 import org.openbravo.erpCommon.utility.*; 23 24 import org.openbravo.erpCommon.ad_actionButton.*; 25 26 import org.openbravo.base.secureApp.HttpSecureAppServlet; 27 import org.openbravo.base.secureApp.VariablesSecureApp; 28 import org.openbravo.xmlEngine.XmlDocument; 29 import java.io.*; 30 import java.util.*; 31 import javax.servlet.*; 32 import javax.servlet.http.*; 33 34 import org.openbravo.erpCommon.utility.DateTimeData; 35 36 37 public class CreateAccountingReport extends HttpSecureAppServlet { 38 39 public static String strTreeOrg = ""; 40 41 public void init (ServletConfig config) { 42 super.init(config); 43 boolHist = false; 44 } 45 46 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 47 VariablesSecureApp vars = new VariablesSecureApp(request); 48 49 if (!Utility.hasProcessAccess(this, vars, "", "CreateAccountingReport")) { 50 bdError(response, "AccessTableNoView", vars.getLanguage()); 51 return; 52 } 53 String process = CreateAccountingReportData.processId(this, "CreateAccountingReport"); 54 56 if (vars.commandIn("DEFAULT")) { 61 String strAccountingReportId = vars.getGlobalVariable("inpAccountingReportId", "CreateAccountingReport|accountingReport", ""); 63 String strOrg = vars.getGlobalVariable("inpadOrgId", "CreateAccountingReport|orgId", "0"); 64 String strPeriod = vars.getGlobalVariable("inpPeriodId", "CreateAccountingReport|period", ""); 65 printPage(response, vars, strAccountingReportId, strOrg, strPeriod, process); 66 } else if (vars.commandIn("FIND")){ 67 String strAccountingReportId = vars.getRequestGlobalVariable("inpAccountingReportId", "CreateAccountingReport|accountingReport"); 68 String strOrg = vars.getGlobalVariable("inpadOrgId", "CreateAccountingReport|orgId", "0"); 69 String strPeriod = vars.getRequestGlobalVariable("inpPeriodId", "CreateAccountingReport|period"); 70 printPagePopUp(response, vars, strAccountingReportId, strOrg, strPeriod); 71 } else pageErrorPopUp(response); 73 } 74 75 76 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strAccountingReportId, String strOrg, String strPeriod, String strProcessId) throws IOException, ServletException { 77 if (log4j.isDebugEnabled()) log4j.debug("Output: process CreateAccountingReport"); 78 79 ActionButtonDefaultData[] data = null; 80 String strHelp="", strDescription=""; 81 if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId); 82 else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId); 83 if (data!=null && data.length!=0) { 84 strDescription = data[0].description; 85 strHelp = data[0].help; 86 } 87 88 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CreateAccountingReport").createXmlDocument(); 89 90 String strArray = arrayEntry(vars); 91 92 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 93 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 94 xmlDocument.setParameter("description", strDescription); 95 xmlDocument.setParameter("help", strHelp); 96 xmlDocument.setParameter("accounting", strAccountingReportId); 97 xmlDocument.setParameter("org", strOrg); 98 xmlDocument.setParameter("period", strPeriod); 99 xmlDocument.setParameter("array", strArray); 100 101 try { 102 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_Org_ID", "", "", Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), 0); 103 Utility.fillSQLParameters(this, vars, null, comboTableData, "CreateAccountingReport", ""); 104 xmlDocument.setData("reportAD_ORG", "liststructure", comboTableData.select(false)); 105 comboTableData = null; 106 } catch (Exception ex) { 107 throw new ServletException(ex); 108 } 109 110 xmlDocument.setData("reportAD_ACCOUNTINGRPT_ELEMENT", "liststructure", CreateAccountingReportData.selectAD_Accountingrpt_Element_ID(this, Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), "")); 111 112 xmlDocument.setData("reportPeriod", "liststructure", CreateAccountingReportData.selectCombo(this, Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), vars.getLanguage())); 114 115 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "CreateAccountingReport", false, "", "", "",false, "ad_process", strReplaceWith, false, true); 116 toolbar.prepareSimpleToolBarTemplate(); 117 xmlDocument.setParameter("toolbar", toolbar.toString()); 118 119 120 try { 122 KeyMap key = new KeyMap(this, vars, "CreateAccountingReport.html"); 123 xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps()); 124 } catch (Exception ex) { 125 throw new ServletException(ex); 126 } 127 try { 128 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_process.CreateAccountingReport"); 129 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 130 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 131 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 132 xmlDocument.setParameter("theme", vars.getTheme()); 133 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "CreateAccountingReport.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 134 xmlDocument.setParameter("navigationBar", nav.toString()); 135 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "CreateAccountingReport.html", strReplaceWith); 136 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 137 } catch (Exception ex) { 138 throw new ServletException(ex); 139 } 140 { 141 OBError myMessage = vars.getMessage("CreateAccountingReport"); 142 vars.removeMessage("CreateAccountingReport"); 143 if (myMessage!=null) { 144 xmlDocument.setParameter("messageType", myMessage.getType()); 145 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 146 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 147 } 148 } 149 150 152 response.setContentType("text/html; charset=UTF-8"); 153 PrintWriter out = response.getWriter(); 154 out.println(xmlDocument.print()); 155 out.close(); 156 } 157 158 void printPagePopUp (HttpServletResponse response, VariablesSecureApp vars, String strAccountingReportId, String strOrg, String strPeriod) throws IOException, ServletException { 159 if (log4j.isDebugEnabled()) log4j.debug("Output: pop up CreateAccountingReport"); 160 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CreateAccountingReportPopUp").createXmlDocument(); 161 String strPeriodFrom = ""; 162 int level = 0; 163 String strPeriodTo = ""; 164 String strYear = DateTimeData.sysdateYear(this); 165 String strAccountingType = CreateAccountingReportData.selectType(this, strAccountingReportId); 167 if (strAccountingType.equals("Q")) { 169 String strAux = CreateAccountingReportData.selectMax(this, strPeriod); 170 strPeriodFrom = "01/" + CreateAccountingReportData.selectMin(this, strPeriod) + "/" + strYear; 172 strPeriodTo = CreateAccountingReportData.lastDay(this, "01/"+ strAux + "/" + strYear, vars.getSqlDateFormat()); 174 strPeriodTo = DateTimeData.nDaysAfter(this, strPeriodTo, "1"); 175 }else if (strAccountingType.equals("M")) { 177 strPeriodFrom = "01/" + strPeriod + "/" + strYear; 178 strPeriodTo = CreateAccountingReportData.lastDay(this, strPeriodFrom, vars.getSqlDateFormat()); 180 strPeriodTo = DateTimeData.nDaysAfter(this, strPeriodTo, "1"); 181 }else { 183 strPeriodFrom = "01/01/" + strPeriod; 184 strPeriodTo = DateTimeData.nDaysAfter(this, "31/12/" + strPeriod, "1"); 186 } 187 strPeriodFrom = CreateAccountingReportData.selectFormat(this, strPeriodFrom, vars.getSqlDateFormat()); 188 strPeriodTo = CreateAccountingReportData.selectFormat(this, strPeriodTo, vars.getSqlDateFormat()); 189 strTreeOrg = strOrg; 190 treeOrg(vars, strOrg); 191 192 Vector<Object > vectorArray = new Vector<Object >(); 193 194 childData(vars, vectorArray, strAccountingReportId, strPeriodFrom, strPeriodTo, strTreeOrg, level); 195 196 CreateAccountingReportData[] dataTree = convertVector(vectorArray); 197 strTreeOrg = ""; 198 199 xmlDocument.setParameter("title", dataTree[0].name); 200 xmlDocument.setData("structure", dataTree); 201 response.setContentType("text/html; charset=UTF-8"); 202 PrintWriter out = response.getWriter(); 203 out.println(xmlDocument.print()); 204 out.close(); 205 } 206 207 String arrayEntry(VariablesSecureApp vars) throws ServletException{ 208 String result = ""; 209 CreateAccountingReportData[] data = CreateAccountingReportData.selectAD_Accountingrpt_Element_ID(this, Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), ""); 210 if (data == null || data.length == 0) { 211 result = "var array = null;"; 212 } else { 213 result = "var array = new Array(\n"; 214 for (int i = 0;i<data.length;i++) { 215 result += "new Array(\"" + data[i].id + "\",\"" + data[i].filteredbyorganization + "\",\"" + data[i].temporaryfiltertype + "\")"; 216 if (i<data.length-1) result += ",\n"; 217 } 218 result += ");"; 219 CreateAccountingReportData[] dataPeriod = CreateAccountingReportData.selectCombo(this, Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), vars.getLanguage()); 220 if (dataPeriod == null || dataPeriod.length == 0){ 221 result += "\nvar combo = null;"; 222 } else { 223 result += "\nvar combo = new Array(\n"; 224 for (int j = 0; j<dataPeriod.length; j++){ 225 result += "new Array(\"" + dataPeriod[j].value + "\", \"" + dataPeriod[j].id +"\", \"" + dataPeriod[j].name + "\")"; 226 if (j<dataPeriod.length-1) result += ",\n"; 227 } 228 result += ");"; 229 } 230 231 } 232 return result; 233 } 234 235 236 void treeOrg(VariablesSecureApp vars, String strOrg) throws ServletException{ 237 CreateAccountingReportData[] dataOrg = CreateAccountingReportData.selectOrg(this, strOrg, vars.getClient()); 238 for (int i = 0; i<dataOrg.length; i++) { 239 strTreeOrg += "," + dataOrg[i].id; 240 if (dataOrg[i].issummary.equals("Y")) treeOrg(vars, dataOrg[i].id); 241 } 242 return; 243 } 244 245 void childData(VariablesSecureApp vars, Vector<Object > vectorArray, String strAccountingReportId, String strPeriodFrom, String strPeriodTo, String strOrg, int level) throws IOException, ServletException{ 246 253 if (log4j.isDebugEnabled()) log4j.debug("Ouput: child tree data"); 254 String strAccountId = CreateAccountingReportData.selectAccounting(this, strAccountingReportId); 256 CreateAccountingReportData[] data = CreateAccountingReportData.select(this, String.valueOf(level), Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), strOrg, strPeriodFrom, strPeriodTo, strAccountId, strAccountingReportId); 258 if (data == null || data.length == 0) data = CreateAccountingReportData.set(); 259 vectorArray.addElement(data[0]); 260 CreateAccountingReportData[] dataAux = CreateAccountingReportData.selectChild(this, Utility.getContext(this, vars, "#User_Client", "CreateAccountingReport"), Utility.getContext(this, vars, "#User_Org", "CreateAccountingReport"), data[0].id); 262 for (int i = 0; i<dataAux.length; i++){ 263 childData(vars, vectorArray, dataAux[i].id, strPeriodFrom, strPeriodTo, strOrg, level+1); 265 } 267 } 268 269 CreateAccountingReportData[] convertVector(Vector<Object > vectorArray) throws ServletException { 270 CreateAccountingReportData[] data = new CreateAccountingReportData[vectorArray.size()]; 271 double count = 0; 272 for (int i = 0; i<vectorArray.size(); i++){ 273 data[i] = (CreateAccountingReportData)vectorArray.elementAt(i); 274 } 275 for (int i = 0; i<data.length; i++){ 277 if (data[i].issummary.equals("Y")){ 279 String strLevel = data[i].levelAccount; 280 for (int j=i+1; j<data.length; j++){ 281 if (Integer.valueOf(data[j].levelAccount).intValue() > Integer.valueOf(data[i].levelAccount).intValue()){ 283 if (!data[j].issummary.equals("Y")){ 285 String total = data[j].total; 286 count += Double.valueOf(total).doubleValue(); 287 } 288 } 289 296 } 297 data[i].total = String.valueOf(count); 298 count = 0; 299 } 300 } 301 return data; 302 } 303 304 public String getServletInfo() { 305 return "Servlet CreateAccountingReport"; 306 } } 308 309 | Popular Tags |