KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > info > Invoice


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

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 JavaDoc strNameValue = vars.getRequestGlobalVariable("inpNameValue", "Invoice.name");
45       String JavaDoc strWindowId = vars.getRequestGlobalVariable("WindowID", "Invoice.windowId");
46       String JavaDoc 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 JavaDoc strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "Invoice.name");
54       String JavaDoc strWindowId = vars.getRequestGlobalVariable("WindowID", "Invoice.windowId");
55       String JavaDoc 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 JavaDoc strNameValue = vars.getGlobalVariable("inpName", "Invoice.name", "");
66       String JavaDoc strWindow = vars.getGlobalVariable("inpwindowId", "Invoice.windowId", "");
67       printPageFrame1(response, vars, strNameValue, strWindow);
68     } else if (vars.commandIn("FRAME2")) {
69       String JavaDoc strName = vars.getGlobalVariable("inpKey", "Invoice.name", "");
70       String JavaDoc strPaid = vars.getStringParameter("inpPaid");
71       String JavaDoc strBpartnerId = vars.getStringParameter("inpBpartnerId");
72       String JavaDoc strDateFrom = vars.getStringParameter("inpDateFrom");
73       String JavaDoc strFechaTo = vars.getStringParameter("inpFechaTo");
74       String JavaDoc strDescription = vars.getStringParameter("inpDescription");
75       String JavaDoc strCal1 = vars.getStringParameter("inpCal1");
76       String JavaDoc strCalc2 = vars.getStringParameter("inpCalc2");
77       String JavaDoc strOrder = vars.getStringParameter("inpOrder");
78       String JavaDoc 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 JavaDoc strName = vars.getGlobalVariable("inpKey", "Invoice.name", "");
82       String JavaDoc 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 JavaDoc strBpartnerId = vars.getStringParameter("inpBpartnerId");
87       String JavaDoc strDateFrom = vars.getStringParameter("inpDateFrom");
88       String JavaDoc strFechaTo = vars.getStringParameter("inpFechaTo");
89       String JavaDoc strDescription = vars.getStringParameter("inpDescription");
90       String JavaDoc strCal1 = vars.getStringParameter("inpCal1");
91       String JavaDoc strCalc2 = vars.getStringParameter("inpCalc2");
92       String JavaDoc strOrder = vars.getStringParameter("inpOrder");
93       String JavaDoc 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 JavaDoc strInitRecord = vars.getSessionValue("Invoice.initRecordNumber");
102       String JavaDoc 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 JavaDoc strInitRecord = vars.getSessionValue("Invoice.initRecordNumber");
115       String JavaDoc 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 JavaDoc generateResult(InvoiceData[] data) throws IOException, ServletException {
149     StringBuffer JavaDoc html = new StringBuffer JavaDoc();
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 JavaDoc strNameValue, String JavaDoc strWindow) throws IOException, ServletException {
160     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of invoices seeker");
161     String JavaDoc 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 JavaDoc substr;
167       String JavaDoc 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 JavaDoc total = new StringBuffer JavaDoc();
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 JavaDoc strName, String JavaDoc strPaid, String JavaDoc strBpartnerId, String JavaDoc strDateFrom, String JavaDoc strFechaTo, String JavaDoc strDescription, String JavaDoc strCal1, String JavaDoc strCalc2, String JavaDoc strOrder, String JavaDoc strSOTrx) throws IOException, ServletException {
196     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the invoice seeker");
197     XmlDocument xmlDocument;
198
199     String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "Invoice");
200     int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange));
201     String JavaDoc 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 JavaDoc[] 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 JavaDoc[] 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 JavaDoc("hasPrevious");
212       if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String JavaDoc("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 JavaDoc getServletInfo() {
234     return "Servlet that presents the business partners seeker";
235   } // end of getServletInfo() method
236
}
237
Popular Tags