KickJava   Java API By Example, From Geeks To Geeks.

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


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 InvoiceLine 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", "InvoiceLine.name");
45       String JavaDoc windowId = vars.getRequestGlobalVariable("WindowID", "InvoiceLine.windowId");
46       String JavaDoc strProduct = vars.getRequestGlobalVariable("inpProduct", "InvoiceLine.product");
47       String JavaDoc strBPartner = vars.getRequestGlobalVariable("inpBPartner", "InvoiceLine.bpartner");
48       if (!strNameValue.equals("")) {
49         int i=0, count=1, inicio=0;
50         String JavaDoc search = " - ", token="";
51         do {
52           i = strNameValue.indexOf(search, inicio);
53           if (i>=0) {
54             token = strNameValue.substring(inicio, i).trim();
55             inicio = i + search.length();
56           } else {
57             token = strNameValue.substring(inicio).trim();
58           }
59
60           switch (count) {
61             case 1:
62               vars.setSessionValue("InvoiceLine.documentno", token);
63               break;
64             case 2:
65               vars.setSessionValue("InvoiceLine.datefrom", token);
66               vars.setSessionValue("InvoiceLine.dateto", token);
67               break;
68             case 3:
69               vars.setSessionValue("InvoiceLine.grandtotalfrom", token);
70               vars.setSessionValue("InvoiceLine.grandtotalto", token);
71               break;
72             case 4:
73               vars.setSessionValue("InvoiceLine.lineno", token);
74               break;
75             case 5:
76               vars.setSessionValue("InvoiceLine.linenet", token);
77               break;
78           }
79           count++;
80         } while (i!=-1);
81       }
82       printPageFS(response, vars);
83     } else if (vars.commandIn("KEY")) {
84       String JavaDoc strKeyValue = vars.getRequestGlobalVariable("inpNameValue", "InvoiceLine.key");
85       String JavaDoc windowId = vars.getRequestGlobalVariable("WindowID", "InvoiceLine.windowId");
86
87       vars.setSessionValue("InvoiceLine.documentno", strKeyValue + "%");
88       InvoiceLineData[] data = null;
89       
90         
91       data = InvoiceLineData.selectKey(this, Utility.getContext(this, vars, "#User_Client", "InvoiceLine"), Utility.getContext(this, vars, "#User_Org", "InvoiceLine"), strKeyValue + "%");
92       
93       if (data!=null && data.length==1) printPageKey(response, vars, data);
94       else printPageFS(response, vars);
95     } else if (vars.commandIn("FRAME1")) {
96       String JavaDoc strBPartner = vars.getGlobalVariable("inpcBpartnerId", "InvoiceLine.bpartner", "");
97       String JavaDoc strProduct = vars.getGlobalVariable("inpmProductId", "InvoiceLine.product", "");
98       String JavaDoc strDocumentNo = vars.getGlobalVariable("inpdocumentno", "InvoiceLine.documentno", "");
99       String JavaDoc strDateFrom = vars.getGlobalVariable("inpDateFrom", "InvoiceLine.datefrom", "");
100       String JavaDoc strDateTo = vars.getGlobalVariable("inpDateTo", "InvoiceLine.dateto", "");
101       String JavaDoc strCal1 = vars.getGlobalVariable("inpCal1", "InvoiceLine.grandtotalfrom", "");
102       String JavaDoc strCal2 = vars.getGlobalVariable("inpCalc2", "InvoiceLine.grandtotalto", "");
103       printPageFrame1(response, vars, strBPartner, strProduct, strDocumentNo, strDateFrom, strDateTo, strCal1, strCal2);
104     } else if (vars.commandIn("FRAME2")) {
105       String JavaDoc strBpartnerId = vars.getGlobalVariable("inpcBpartnerId", "InvoiceLine.bpartner", "");
106       String JavaDoc strProduct = vars.getGlobalVariable("inpmProductId", "InvoiceLine.product", "");
107       String JavaDoc strDocumentNo = vars.getGlobalVariable("inpdocumentno", "InvoiceLine.documentno", "");
108       String JavaDoc strDateFrom = vars.getGlobalVariable("inpDateFrom", "InvoiceLine.datefrom", "");
109       String JavaDoc strDateTo = vars.getGlobalVariable("inpDateTo", "InvoiceLine.dateto", "");
110       String JavaDoc strDescription = vars.getStringParameter("inpDescription");
111       String JavaDoc strCal1 = vars.getGlobalVariable("inpCal1", "InvoiceLine.grandtotalfrom", "");
112       String JavaDoc strCal2 = vars.getGlobalVariable("inpCalc2", "InvoiceLine.grandtotalto", "");
113       String JavaDoc strOrder = vars.getStringParameter("inpInvoice");
114       printPageFrame2(response, vars, strDocumentNo, strBpartnerId, strDateFrom, strDateTo, strDescription, strCal1, strCal2, strOrder, strProduct);
115     } else if (vars.commandIn("FIND")) {
116       String JavaDoc strBpartnerId = vars.getRequestGlobalVariable("inpcBpartnerId", "InvoiceLine.bpartner");
117       String JavaDoc strProduct = vars.getRequestGlobalVariable("inpmProductId", "InvoiceLine.product");
118       String JavaDoc strDocumentNo = vars.getRequestGlobalVariable("inpdocumentno", "InvoiceLine.documentno");
119       String JavaDoc strDateFrom = vars.getRequestGlobalVariable("inpDateFrom", "InvoiceLine.datefrom");
120       String JavaDoc strDateTo = vars.getRequestGlobalVariable("inpDateTo", "InvoiceLine.dateto");
121       String JavaDoc strDescription = vars.getStringParameter("inpDescription");
122       String JavaDoc strCal1 = vars.getRequestGlobalVariable("inpCal1", "InvoiceLine.grandtotalfrom");
123       String JavaDoc strCal2 = vars.getRequestGlobalVariable("inpCalc2", "InvoiceLine.grandtotalto");
124       String JavaDoc strOrder = vars.getStringParameter("inpInvoice");
125
126       vars.setSessionValue("InvoiceLine.initRecordNumber", "0");
127
128       printPageFrame2(response, vars, strDocumentNo, strBpartnerId, strDateFrom, strDateTo, strDescription, strCal1, strCal2, strOrder, strProduct);
129     } else if (vars.commandIn("FRAME3")) {
130       printPageFrame3(response, vars);
131     } else if (vars.commandIn("PREVIOUS")) {
132       String JavaDoc strInitRecord = vars.getSessionValue("InvoiceLine.initRecordNumber");
133       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "InvoiceLine");
134       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
135       if (strInitRecord.equals("") || strInitRecord.equals("0")) vars.setSessionValue("InvoiceLine.initRecordNumber", "0");
136       else {
137         int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
138         initRecord -= intRecordRange;
139         strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
140         vars.setSessionValue("InvoiceLine.initRecordNumber", strInitRecord);
141       }
142
143       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
144     } else if (vars.commandIn("NEXT")) {
145       String JavaDoc strInitRecord = vars.getSessionValue("InvoiceLine.initRecordNumber");
146       String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "InvoiceLine");
147       int intRecordRange = strRecordRange.equals("")?0:Integer.parseInt(strRecordRange);
148       int initRecord = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
149       if (initRecord==0) initRecord=1;
150       initRecord += intRecordRange;
151       strInitRecord = ((initRecord<0)?"0":Integer.toString(initRecord));
152       vars.setSessionValue("InvoiceLine.initRecordNumber", strInitRecord);
153
154       response.sendRedirect(strDireccion + request.getServletPath() + "?Command=FRAME2");
155     } else pageError(response);
156   }
157
158   void printPageFS(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
159     if (log4j.isDebugEnabled()) log4j.debug("Output: sale-order-lines seeker Frame Set");
160     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/InvoiceLine_FS").createXmlDocument();
161
162     response.setContentType("text/html; charset=UTF-8");
163     PrintWriter out = response.getWriter();
164     out.println(xmlDocument.print());
165     out.close();
166   }
167
168   void printPageKey(HttpServletResponse response, VariablesSecureApp vars, InvoiceLineData[] data) throws IOException, ServletException {
169     if (log4j.isDebugEnabled()) log4j.debug("Output: sale-order-lines seeker Frame Set");
170     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/SearchUniqueKeyResponse").createXmlDocument();
171
172     xmlDocument.setParameter("script", generateResult(data));
173     response.setContentType("text/html; charset=UTF-8");
174     PrintWriter out = response.getWriter();
175     out.println(xmlDocument.print());
176     out.close();
177   }
178
179   String JavaDoc generateResult(InvoiceLineData[] data) throws IOException, ServletException {
180     StringBuffer JavaDoc html = new StringBuffer JavaDoc();
181     if (log4j.isDebugEnabled()) log4j.debug("Save- clave:"+data[0].cInvoicelineId+" txt:"+data[0].lineText);
182     html.append("\nfunction depurarSelector() {\n");
183     html.append("var clave = \"" + data[0].cInvoicelineId + "\";\n");
184     html.append("var texto = \"" + Replace.replace(data[0].lineText, "\"", "\\\"") + "\";\n");
185     html.append("parent.opener.closeSearch(\"SAVE\", clave, texto);\n");
186     html.append("}\n");
187     return html.toString();
188   }
189
190   void printPageFrame1(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strBPartner, String JavaDoc strProduct, String JavaDoc strDocumentNo, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strCal1, String JavaDoc strCal2) throws IOException, ServletException {
191     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 1 of sale-order-lines seeker");
192     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/InvoiceLine_F1").createXmlDocument();
193     if (strBPartner.equals("") && strProduct.equals("") && strDocumentNo.equals("") && strDateFrom.equals("") && strDateTo.equals("") && strCal1.equals("") && strCal2.equals("")) {
194       strDocumentNo = "%";
195     }
196     xmlDocument.setParameter("calendar", vars.getLanguage().substring(0,2));
197     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
198     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
199     xmlDocument.setParameter("documentno", strDocumentNo);
200     xmlDocument.setParameter("datefrom", strDateFrom);
201     xmlDocument.setParameter("dateto", strDateTo);
202     xmlDocument.setParameter("grandtotalfrom", strCal1);
203     xmlDocument.setParameter("grandtotalto", strCal2);
204     xmlDocument.setParameter("cBpartnerId", strBPartner);
205     xmlDocument.setParameter("cBpartnerId_DES", InvoiceLineData.selectBPartner(this, strBPartner));
206     xmlDocument.setParameter("mProductId", strProduct);
207     xmlDocument.setParameter("mProductId_DES", InvoiceLineData.selectProduct(this, strProduct));
208     xmlDocument.setParameter("dateFromdisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
209     xmlDocument.setParameter("dateFromsaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
210     xmlDocument.setParameter("dateTodisplayFormat", vars.getSessionValue("#AD_SqlDateFormat"));
211     xmlDocument.setParameter("dateTosaveFormat", vars.getSessionValue("#AD_SqlDateFormat"));
212     response.setContentType("text/html; charset=UTF-8");
213     PrintWriter out = response.getWriter();
214     out.println(xmlDocument.print());
215     out.close();
216   }
217
218   void printPageFrame2(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strDocumentNo, String JavaDoc strBpartnerId, String JavaDoc strDateFrom, String JavaDoc strDateTo, String JavaDoc strDescription, String JavaDoc strCal1, String JavaDoc strCalc2, String JavaDoc strOrder, String JavaDoc strProduct) throws IOException, ServletException {
219     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 2 of the sale-order-lines seeker");
220     XmlDocument xmlDocument;
221
222     InvoiceLineData[] data = null;
223
224     String JavaDoc strRecordRange = Utility.getContext(this, vars, "#RecordRangeInfo", "InvoiceLine");
225     int intRecordRange = (strRecordRange.equals("")?0:Integer.parseInt(strRecordRange));
226     String JavaDoc strInitRecord = vars.getSessionValue("InvoiceLine.initRecordNumber");
227     int initRecordNumber = (strInitRecord.equals("")?0:Integer.parseInt(strInitRecord));
228
229     if (strDocumentNo.equals("") && strBpartnerId.equals("") && strDateFrom.equals("") && strDateTo.equals("") && strDescription.equals("") && strCal1.equals("") && strCalc2.equals("") && strOrder.equals("") && strProduct.equals("")) {
230       String JavaDoc[] discard = {"sectionDetail", "hasPrevious", "hasNext"};
231       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/InvoiceLine_F2", discard).createXmlDocument();
232       data = InvoiceLineData.set();
233     } else {
234       String JavaDoc[] discard = {"withoutPrevious", "withoutNext"};
235
236       data = InvoiceLineData.select(this, Utility.getContext(this, vars, "#User_Client", "InvoiceLine"), Utility.getContext(this, vars, "#User_Org", "InvoiceLine"), strDocumentNo, strDescription, strOrder, strBpartnerId, strDateFrom, DateTimeData.nDaysAfter(this,strDateTo, "1"), strCal1, strCalc2, strProduct, initRecordNumber, intRecordRange);
237       if (data==null || data.length==0 || initRecordNumber<=1) discard[0] = new String JavaDoc("hasPrevious");
238       if (data==null || data.length==0 || data.length<intRecordRange) discard[1] = new String JavaDoc("hasNext");
239       xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/InvoiceLine_F2", discard).createXmlDocument();
240     }
241     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
242     xmlDocument.setData("structure1", data);
243
244     response.setContentType("text/html; charset=UTF-8");
245     PrintWriter out = response.getWriter();
246     out.println(xmlDocument.print());
247     out.close();
248   }
249
250   void printPageFrame3(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
251     if (log4j.isDebugEnabled()) log4j.debug("Output: Frame 3 of the sale-order-lines seeker");
252     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/info/InvoiceLine_F3").createXmlDocument();
253
254     response.setContentType("text/html; charset=UTF-8");
255     PrintWriter out = response.getWriter();
256     out.println(xmlDocument.print());
257     out.close();
258   }
259
260   public String JavaDoc getServletInfo() {
261     return "Servlet that presents que sale-orders lines seeker";
262   } // end of getServletInfo() method
263
}
264
Popular Tags