1 19 package org.openbravo.erpCommon.info; 20 21 import org.openbravo.base.secureApp.*; 22 import org.openbravo.xmlEngine.XmlDocument; 23 import org.openbravo.erpCommon.utility.Utility; 24 import java.io.*; 25 import javax.servlet.*; 26 import javax.servlet.http.*; 27 import org.openbravo.utils.Replace; 28 29 import org.openbravo.erpCommon.utility.DateTimeData; 30 31 32 public class Invoice extends HttpSecureAppServlet { 33 34 35 public void init (ServletConfig config) { 36 super.init(config); 37 boolHist = false; 38 } 39 40 public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException { 41 VariablesSecureApp vars = new VariablesSecureApp(request); 42 43 if (vars.commandIn("DEFAULT")) { 44 String strNameValue = vars.getRequestGlobalVariable("inpNameValue", "Invoice.name"); 45 String strWindowId = vars.getRequestGlobalVariable("WindowID", "Invoice.windowId"); 46 String strSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId); 47 if (!strWindowId.equals("")) { 48 vars.setSessionValue("Invoice.isSOTrx", (strSOTrx.equals("")?"N":strSOTrx)); 49 } 50 if (!strNameValue.equals("")) vars.setSessionValue("Invoice.name", strNameValue + "%"); 51 printPageFS(response, vars); 52 } else if (vars.commandIn("KEY")) { 53 String strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "Invoice.name"); 54 String strWindowId = vars.getRequestGlobalVariable("WindowID", "Invoice.windowId"); 55 String strSOTrx = Utility.getContext(this, vars, "isSOTrx", strWindowId); 56 if (!strWindowId.equals("")) { 57 vars.setSessionValue("Invoice.isSOTrx", (strSOTrx.equals("")?"N":strSOTrx)); 58 } 59 vars.setSessionValue("Invoice.name", strKeyValue + "%"); 60 InvoiceData[] data = InvoiceData.selectKey(this, vars.getSqlDateFormat(), Utility.getContext(this, vars, "#User_Client", "Invoice"), Utility.getContext(this, vars, "#User_Org", "Invoice"), strSOTrx, strKeyValue + "%"); 61 if (data!=null && data.length==1) { 62 printPageKey(response, vars, data); 63 } else printPageFS(response, vars); 64 } else if (vars.commandIn("FRAME1")) { 65 String strNameValue = vars.getGlobalVariable("inpName", "Invoice.name", ""); 66 String strWindow = vars.getGlobalVariable("inpwindowId", "Invoice.windowId", ""); 67 printPageFrame1(response, vars, strNameValue, strWindow); 68 } else if (vars.commandIn("FRAME2")) { 69 String strName = vars.getGlobalVariable("inpKey", "Invoice.name", ""); 70 String strPaid = vars.getStringParameter("inpPaid"); 71 String strBpartnerId = vars.getStringParameter("inpBpartnerId"); 72 String strDateFrom = vars.getStringParameter("inpDateFrom"); 73 String strFechaTo = vars.getStringParameter("inpFechaTo"); 74 String strDescription = vars.getStringParameter("inpDescription"); 75 String strCal1 = vars.getStringParameter("inpCal1"); 76 String strCalc2 = vars.getStringParameter("inpCalc2"); 77 String strOrder = vars.getStringParameter("inpOrder"); 78 String strSOTrx = vars.getStringParameter("inpisSOTrx"); 79 printPageFrame2(response, vars, strName, strPaid, strBpartnerId, strDateFrom, strFechaTo, strDescription, strCal1, strCalc2, strOrder, strSOTrx); 80 } else if (vars.commandIn("FIND")) { 81 String strName = vars.getGlobalVariable("inpKey", "Invoice.name", ""); 82 String strPaid = vars.getStringParameter("inpPaid"); 83 if (strPaid.equals(""))strPaid = "N"; 84 if (strPaid.equals("-1"))strPaid = "Y"; 85 if (log4j.isDebugEnabled()) log4j.debug("the value of inpPaid is: "+strPaid); 86 String strBpartnerId = vars.getStringParameter("inpBpartnerId"); 87 String strDateFrom = vars.getStringParameter("inpDateFrom"); 88 String strFechaTo = vars.getStringParameter("inpFechaTo"); 89 String strDescription = vars.getStringParameter("inpDescription"); 90 String strCal1 = vars.getStringParameter("inpCal1"); 91 String strCalc2 = vars.getStringParameter("inpCalc2"); 92 String strOrder = vars.getStringParameter("inpOrder"); 93 String strSOTrx = vars.getStringParameter("inpisSOTrx"); 94 95 vars.setSessionValue("Invoice.initRecordNumber", "0"); 96 97 printPageFrame2(response, vars, strName, strPaid, strBpartnerId, strDateFrom, strFechaTo, strDescription, strCal1, strCalc2, strOrder, strSOTrx); 98 } else if (vars.commandIn("FRAME3")) { 99 printPageFrame3(response, vars); 100 } else if (vars.commandIn("PREVIOUS")) { 101 String strInitRecord = vars.getSessionValue("Invoice.initRecordNumber"); 102 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Invoice"); 103 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 104 if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("Invoice.initRecordNumber", "0"); 105 else { 106 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 107 initRecord -= intRecordRange; 108 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 109 vars.setSessionValue("Invoice.initRecordNumber", strInitRecord); 110 } 111 112 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 113 } else if (vars.commandIn("NEXT")) { 114 String strInitRecord = vars.getSessionValue("Invoice.initRecordNumber"); 115 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Invoice"); 116 int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange); 117 int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 118 if (initRecord==0) initRecord=1; 119 initRecord += intRecordRange; 120 strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord)); 121 vars.setSessionValue("Invoice.initRecordNumber", strInitRecord); 122 123 response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2"); 124 } else pageError(response); 125 } 126 127 void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 128 if (log4j.isDebugEnabled()) log4j.debug("Output: business partners seeker Frame Set"); 129 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Invoice_FS").createXmlDocument(); 130 131 response.setContentType("text/html; charset=UTF-8"); 132 PrintWriter out = response.getWriter(); 133 out.println(xmlDocument.print()); 134 out.close(); 135 } 136 137 void printPageKey(HttpServletResponse response, VariablesSecureApp vars, InvoiceData[] data) throws IOException, ServletException { 138 if (log4j.isDebugEnabled()) log4j.debug("Output: Invoice seeker Frame Set"); 139 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument(); 140 141 xmlDocument.setParameter("script", generateResult(data)); 142 response.setContentType("text/html; charset=UTF-8"); 143 PrintWriter out = response.getWriter(); 144 out.println(xmlDocument.print()); 145 out.close(); 146 } 147 148 String generateResult(InvoiceData[] data) throws IOException, ServletException { 149 StringBuffer html = new StringBuffer (); 150 151 html.append("\nfunction depurarSelector() {\n"); 152 html.append("var clave = \"" + data[0].cInvoiceId + "\";\n"); 153 html.append("var texto = \"" + Replace.replace(data[0].name, "\"", "\\\"") + "\";\n"); 154 html.append("parent.opener.closeSearch(\"SAVE\", clave, texto);\n"); 155 html.append("}\n"); 156 return html.toString(); 157 } 158 159 void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String strNameValue, String strWindow) throws IOException, ServletException { 160 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of invoices seeker"); 161 String strSOTrx = vars.getSessionValue("Invoice.isSOTrx"); 162 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Invoice_F1").createXmlDocument(); 163 if (strNameValue.equals("")) { 164 xmlDocument.setParameter("key", "%"); 165 } else { 166 String substr; 167 String white = " "; 168 int index = strNameValue.indexOf(white, 0); 169 substr = strNameValue.substring(0,index); 170 xmlDocument.setParameter("key", substr); 171 } 172 xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2)); 173 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 174 xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";"); 175 xmlDocument.setParameter("isSOTrxCompra", strSOTrx); 176 xmlDocument.setParameter("isSOTrxVenta", strSOTrx); 177 xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 178 xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 179 xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat")); 180 xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat")); 181 StringBuffer total = new StringBuffer (); 182 total.append("arrTeclas = new Array(\n"); 183 total.append("new Teclas(\"ENTER\", \"openSearch(null, null, 'Invoice_FS.html', 'SELECTOR_INVOICE', false, 'frmMain', 'inpNewcInvoiceId', 'inpNewcInvoiceId_DES', document.frmMain.inpNewcInvoiceId_DES.value, 'Command', 'KEY', 'WindowID', '"); 184 total.append(strWindow).append("');\", \"inpNewcInvoiceId_DES\", \"null\")\n"); 185 total.append(");\n"); 186 total.append("activarControlTeclas();\n"); 187 xmlDocument.setParameter("WindowIDArray", total.toString()); 188 xmlDocument.setParameter("WindowID", strWindow); 189 response.setContentType("text/html; charset=UTF-8"); 190 PrintWriter out = response.getWriter(); 191 out.println(xmlDocument.print()); 192 out.close(); 193 } 194 195 void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String strName, String strPaid, String strBpartnerId, String strDateFrom, String strFechaTo, String strDescription, String strCal1, String strCalc2, String strOrder, String strSOTrx) throws IOException, ServletException { 196 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the invoice seeker"); 197 XmlDocument xmlDocument; 198 199 String strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Invoice"); 200 int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange)); 201 String strInitRecord = vars.getSessionValue("Invoice.initRecordNumber"); 202 int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord)); 203 204 if (strName.equals("") && strPaid.equals("") && strBpartnerId.equals("") && strDateFrom.equals("") && strFechaTo.equals("") && strDescription.equals("") && strCal1.equals("") && strCalc2.equals("") && strOrder.equals("")) { 205 String [] discard = {"sectionDetail", "hasPrevious", "hasNext"}; 206 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Invoice_F2", discard).createXmlDocument(); 207 xmlDocument.setData("structure1", InvoiceData.set()); 208 } else { 209 String [] discard = {"withoutPrevious", "withoutNext"}; 210 InvoiceData[] data = InvoiceData.select(this, vars.getSqlDateFormat(), Utility.getContext(this, vars, "#User_Client", "Invoice"), Utility.getContext(this, vars, "#User_Org", "Invoice"), strName, strDescription, strBpartnerId, strOrder, strDateFrom, DateTimeData.nDaysAfter(this,strFechaTo, "1"), strCal1, strCalc2, strSOTrx, strPaid, initRecordNumber, intRecordRange); 211 if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String ("hasPrevious"); 212 if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String ("hasNext"); 213 xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Invoice_F2", discard).createXmlDocument(); 214 xmlDocument.setData("structure1", data); 215 } 216 xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n"); 217 response.setContentType("text/html; charset=UTF-8"); 218 PrintWriter out = response.getWriter(); 219 out.println(xmlDocument.print()); 220 out.close(); 221 } 222 223 void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException { 224 if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 iof the business partners seeker"); 225 XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/Invoice_F3").createXmlDocument(); 226 227 response.setContentType("text/html; charset=UTF-8"); 228 PrintWriter out = response.getWriter(); 229 out.println(xmlDocument.print()); 230 out.close(); 231 } 232 233 public String getServletInfo() { 234 return "Servlet that presents the business partners seeker"; 235 } } 237 | Popular Tags |