1 17 18 package org.openbravo.erpCommon.ad_process; 19 20 import org.openbravo.erpCommon.utility.*; 21 22 import org.openbravo.erpCommon.businessUtility.*; 23 import org.openbravo.erpCommon.ad_actionButton.*; 24 import org.openbravo.erpCommon.utility.Utility; 25 import org.openbravo.erpCommon.utility.ComboTableData; 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 public class CreateTaxReport extends HttpSecureAppServlet { 35 36 public static String strTreeOrg = ""; 37 38 public void init (ServletConfig config) { 39 super.init(config); 40 boolHist = false; 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, "", "CreateTaxReport")) { 47 bdError(response, "AccessTableNoView", vars.getLanguage()); 48 return; 49 } 50 String process = CreateTaxReportData.processId(this, "CreateTaxReport"); 51 if (vars.commandIn("DEFAULT")) { 52 String strTaxReportId = vars.getGlobalVariable("inpTaxReportId", "CreateTaxReport|taxReport", ""); 53 String strDateFrom = vars.getGlobalVariable("inpDateFrom", "CreateTaxReport|dateFrom", ""); 54 String strDateTo = vars.getGlobalVariable("inpDateTo", "CreateTaxReport|dateTo", ""); 55 String strOrg = vars.getGlobalVariable("inpadOrgId", "CreateTaxReport|orgId", "0"); 56 printPage(response, vars, strTaxReportId, strDateFrom, strDateTo, strOrg, process); 57 } else if (vars.commandIn("FIND")){ 58 String strTaxReportId = vars.getRequestGlobalVariable("inpTaxReportId", "CreateTaxReport|taxReport"); 59 String strDateFrom = vars.getGlobalVariable("inpDateFrom", "CreateTaxReport|dateFrom", ""); 60 String strDateTo = vars.getGlobalVariable("inpDateTo", "CreateTaxReport|dateTo", ""); 61 String strOrg = vars.getGlobalVariable("inpadOrgId", "CreateTaxReport|orgId", "0"); 62 printPagePopUp(response, vars, strTaxReportId, strDateFrom, strDateTo, strOrg); 63 } else pageErrorPopUp(response); 64 } 65 66 67 void printPage(HttpServletResponse response, VariablesSecureApp vars, String strTaxReportId, String strDateFrom, String strDateTo, String strOrg, String strProcessId) throws IOException, ServletException { 68 if (log4j.isDebugEnabled()) log4j.debug("Output: process CreateTaxReport"); 69 70 ActionButtonDefaultData[] data = null; 71 String strHelp="", strDescription=""; 72 if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId); 73 else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId); 74 if (data!=null && data.length!=0) { 75 strDescription = data[0].description; 76 strHelp = data[0].help; 77 } 78 79 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CreateTaxReport").createXmlDocument(); 80 81 83 xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2)); 84 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 85 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 86 xmlDocument.setParameter("description", strDescription); 87 xmlDocument.setParameter("help", strHelp); 88 xmlDocument.setParameter("dateFrom", strDateFrom); 89 xmlDocument.setParameter("dateTo", strDateTo); 90 xmlDocument.setParameter("org", strOrg); 91 xmlDocument.setParameter("taxReport", strTaxReportId); 92 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 93 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 94 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 95 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 96 97 ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "CreateTaxReport", false, "", "", "",false, "ad_process", strReplaceWith, false, true); 98 toolbar.prepareSimpleToolBarTemplate(); 99 xmlDocument.setParameter("toolbar", toolbar.toString()); 100 101 try { 103 KeyMap key = new KeyMap(this, vars, "CreateTaxReport.html"); 104 xmlDocument.setParameter("keyMap", key.getActionButtonKeyMaps()); 105 } catch (Exception ex) { 106 throw new ServletException(ex); 107 } 108 try { 109 WindowTabs tabs = new WindowTabs(this, vars, "org.openbravo.erpCommon.ad_process.CreateTaxReport"); 110 111 xmlDocument.setParameter("parentTabContainer", tabs.parentTabs()); 112 xmlDocument.setParameter("mainTabContainer", tabs.mainTabs()); 113 xmlDocument.setParameter("childTabContainer", tabs.childTabs()); 114 xmlDocument.setParameter("theme", vars.getTheme()); 115 NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "CreateTaxReport.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb()); 116 xmlDocument.setParameter("navigationBar", nav.toString()); 117 LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "CreateTaxReport.html", strReplaceWith); 118 xmlDocument.setParameter("leftTabs", lBar.manualTemplate()); 119 } catch (Exception ex) { 120 throw new ServletException(ex); 121 } 122 { 123 OBError myMessage = vars.getMessage("CreateTaxReport"); 124 vars.removeMessage("CreateTaxReport"); 125 if (myMessage!=null) { 126 xmlDocument.setParameter("messageType", myMessage.getType()); 127 xmlDocument.setParameter("messageTitle", myMessage.getTitle()); 128 xmlDocument.setParameter("messageMessage", myMessage.getMessage()); 129 } 130 } 131 132 134 136 try { 137 ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_Org_ID", "", "", Utility.getContext(this, vars, "#User_Org", "CreateTaxReport"), Utility.getContext(this, vars, "#User_Client", "CreateTaxReport"), 0); 138 Utility.fillSQLParameters(this, vars, null, comboTableData, "CreateTaxReport", ""); 139 xmlDocument.setData("reportAD_ORG", "liststructure", comboTableData.select(false)); 140 comboTableData = null; 141 } catch (Exception ex) { 142 throw new ServletException(ex); 143 } 144 145 xmlDocument.setData("reportC_TAX_REPORT", "liststructure", CreateTaxReportData.selectC_TAX_REPORT(this, Utility.getContext(this, vars, "#User_Org", "CreateTaxReport"), Utility.getContext(this, vars, "#User_Client", "CreateTaxReport"), "")); 146 147 response.setContentType("text/html; charset=UTF-8"); 148 PrintWriter out = response.getWriter(); 149 out.println(xmlDocument.print()); 150 out.close(); 151 } 152 153 void printPagePopUp (HttpServletResponse response, VariablesSecureApp vars, String strTaxReportId, String strDateFrom, String strDateTo, String strOrg) throws IOException, ServletException { 154 if (log4j.isDebugEnabled()) log4j.debug("Output: pop up CreateTaxReport"); 155 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_process/CreateTaxReportPopUp").createXmlDocument(); 156 int level = 0; 157 158 strTreeOrg = strOrg; 159 treeOrg(vars, strOrg); 160 161 Vector<Object > vectorArray = new Vector<Object >(); 162 163 childData(vars, vectorArray, strTaxReportId, strDateFrom, strDateTo, strTreeOrg, level, "0"); 164 165 CreateTaxReportData[] dataTree = convertVector(vectorArray); 166 strTreeOrg = ""; 167 168 xmlDocument.setParameter("title", dataTree[0].name); 169 xmlDocument.setData("structure", dataTree); 170 response.setContentType("text/html; charset=UTF-8"); 171 PrintWriter out = response.getWriter(); 172 out.println(xmlDocument.print()); 173 out.close(); 174 } 175 176 191 192 193 void treeOrg(VariablesSecureApp vars, String strOrg) throws ServletException{ 194 CreateTaxReportData[] dataOrg = CreateTaxReportData.selectOrg(this, strOrg, vars.getClient()); 195 for (int i = 0; i<dataOrg.length; i++) { 196 strTreeOrg += "," + dataOrg[i].id; 197 if (dataOrg[i].issummary.equals("Y")) treeOrg(vars, dataOrg[i].id); 198 } 199 return; 200 } 201 202 void childData(VariablesSecureApp vars, Vector<Object > vectorArray, String strTaxReportId, String strPeriodFrom, String strPeriodTo, String strOrg, int level, String strParent) throws IOException, ServletException{ 203 if (log4j.isDebugEnabled()) log4j.debug("**********************strTaxReportId: "+strTaxReportId); 204 if (log4j.isDebugEnabled()) log4j.debug("**********************strPeriodFrom: "+strPeriodFrom); 205 if (log4j.isDebugEnabled()) log4j.debug("**********************strPeriodTo: "+strPeriodTo); 206 if (log4j.isDebugEnabled()) log4j.debug("**********************strOrg: "+strOrg); 207 if (log4j.isDebugEnabled()) log4j.debug("**********************level: "+String.valueOf(level)); 208 if (log4j.isDebugEnabled()) log4j.debug("**********************User_Client: "+Utility.getContext(this, vars, "#User_Client", "CreateTaxReport")); 209 if (log4j.isDebugEnabled()) log4j.debug("**********************#User_Org: "+Utility.getContext(this, vars, "#User_Org", "CreateTaxReport")); 210 if (log4j.isDebugEnabled()) log4j.debug("Ouput: child tree data"); 211 String strTaxId = CreateTaxReportData.selectTax(this, strTaxReportId); 213 if (log4j.isDebugEnabled()) log4j.debug("**********************strTaxId: "+strTaxId); 214 CreateTaxReportData[] data = CreateTaxReportData.select(this, strParent, String.valueOf(level), Utility.getContext(this, vars, "#User_Client", "CreateTaxReport"), strOrg, strPeriodFrom, strPeriodTo, strTaxReportId); 215 if (data == null || data.length == 0) data = CreateTaxReportData.set(); 216 vectorArray.addElement(data[0]); 217 if (log4j.isDebugEnabled()) log4j.debug("**********************data[0]*********************data[0].id: " + data[0].id + "- data[0].name:"+data[0].name+" data[0].total:"+data[0].total); 218 CreateTaxReportData[] dataAux = CreateTaxReportData.selectChild(this, Utility.getContext(this, vars, "#User_Client", "CreateTaxReport"), Utility.getContext(this, vars, "#User_Org", "CreateTaxReport"), data[0].id); 219 if (log4j.isDebugEnabled()) log4j.debug("**********************dataAux.length: "+ dataAux.length); 220 for (int i = 0; i<dataAux.length; i++){ 221 childData(vars, vectorArray, dataAux[i].id, strPeriodFrom, strPeriodTo, strOrg, level+1, data[0].id); 223 } 225 } 226 227 CreateTaxReportData[] convertVector(Vector<Object > vectorArray) throws ServletException { 228 CreateTaxReportData[] data = new CreateTaxReportData[vectorArray.size()]; 229 double count = 0; 230 for (int i = 0; i<vectorArray.size(); i++){ 231 data[i] = (CreateTaxReportData)vectorArray.elementAt(i); 232 } 233 if (log4j.isDebugEnabled()) log4j.debug("***************************data.length: "+data.length); 234 for (int i = data.length-1; i>=0; i--){ 235 if (log4j.isDebugEnabled()) log4j.debug("*******************dataissummary: "+data[i].name+" "+data[i].issummary+" "+data[i].levelTax); 236 if (data[i].issummary.equals("Y")){ 237 String strLevel = data[i].levelTax; 238 for (int j=i+1; j<data.length; j++){ 239 if (log4j.isDebugEnabled()) log4j.debug("******************************data[j].name: "+data[j].name+" "+data[j].levelTax+" "+data[i].levelTax); 240 if (Integer.valueOf(data[j].levelTax).intValue() > Integer.valueOf(data[i].levelTax).intValue() && data[j].parent.equals(data[i].id)){ 241 if (log4j.isDebugEnabled()) log4j.debug("******************************issummary[j]: "+data[j].issummary); 242 String total = data[j].total; 244 count += Double.valueOf(total).doubleValue(); 245 } 247 254 } 255 data[i].total = String.valueOf(count); 256 count = 0; 257 } 258 } 259 return data; 260 } 261 262 public String getServletInfo() { 263 return "Servlet CreateTaxReport"; 264 } } 266 267
| Popular Tags
|