KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_forms > InvoiceVendorMultiline


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
20 package org.openbravo.erpCommon.ad_forms;
21
22 import org.openbravo.erpCommon.utility.*;
23 import org.openbravo.utils.FormatUtilities;
24 import org.openbravo.base.secureApp.HttpSecureAppServlet;
25 import org.openbravo.base.secureApp.VariablesSecureApp;
26 import org.openbravo.xmlEngine.XmlDocument;
27 import org.openbravo.utils.Replace;
28 import java.io.*;
29 import javax.servlet.*;
30 import javax.servlet.http.*;
31
32 import org.openbravo.erpCommon.businessUtility.*;
33
34
35 public class InvoiceVendorMultiline extends HttpSecureAppServlet {
36
37   protected String JavaDoc windowId = "";
38   protected String JavaDoc tabId = "";
39   protected String JavaDoc tableId = "";
40   protected String JavaDoc tabName = "";
41   protected String JavaDoc windowName = "";
42   protected String JavaDoc windowNameEnUS = "";
43   protected String JavaDoc tabNameEnUS = "";
44   private static final String JavaDoc formClassName = "org.openbravo.erpCommon.ad_forms.InvoiceVendorMultiline";
45
46   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
47     VariablesSecureApp vars = new VariablesSecureApp(request);
48
49     if (!Utility.hasFormAccess(this, vars, "", formClassName)) {
50       bdError(response, "AccessTableNoView", vars.getLanguage());
51       return;
52     }
53     {
54       InvoiceVendorMultilineData[] data = InvoiceVendorMultilineData.selectWindowData(this, vars.getLanguage(), formClassName);
55       if (data==null || data.length==0) {
56         throw new ServletException(formClassName + ": Error on window data");
57       }
58       windowId = data[0].adWindowId;
59       tabId = data[0].adTabId;
60       tableId = data[0].adTableId;
61       tabName = data[0].tabname;
62       windowName = data[0].windowname;
63       tabNameEnUS = data[0].tabnameEnUs;
64       windowNameEnUS = data[0].windownameEnUs;
65     }
66
67     if (vars.commandIn("DEFAULT", "EDIT")) {
68       String JavaDoc strC_Invoice_ID = vars.getGlobalVariable("inpcInvoiceId", windowId + "|C_Invoice_ID", "");
69       if (strC_Invoice_ID.equals("")) response.sendRedirect(strDireccion + "/" + FormatUtilities.replace(windowNameEnUS) + "/" + FormatUtilities.replace(tabNameEnUS) + "_Relation.html?Command=RELATION");
70       else printPageDataSheet(response, vars, strC_Invoice_ID);
71     } else if (vars.commandIn("NEW")) {
72       vars.removeSessionValue(windowId + "|C_Invoice_ID");
73       printPageDataSheet(response, vars, "");
74     } else if (vars.commandIn("SAVE_NEW_RELATION", "SAVE_NEW_NEW", "SAVE_NEW_EDIT")) {
75       InvoiceVendorMultilineData data = getEditVariables(vars);
76       String JavaDoc strSequence = SequenceIdData.getSequence(this, "C_Invoice", vars.getClient());
77       log4j.info("Sequence: " + strSequence);
78       data.cInvoiceId = strSequence;
79       if (data.insert(this)==0) {
80         bdError(response, "DBExecuteError", vars.getLanguage());
81       } else {
82         vars.setSessionValue(windowId + "|C_Invoice_ID", data.cInvoiceId);
83         if (vars.commandIn("SAVE_NEW_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
84         else if (vars.commandIn("SAVE_NEW_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
85         else response.sendRedirect(strDireccion + "/" + FormatUtilities.replace(windowNameEnUS) + "/" + FormatUtilities.replace(tabNameEnUS) + "_Relation.html?Command=RELATION");
86       }
87     } else if (vars.commandIn("SAVE_EDIT_RELATION", "SAVE_EDIT_NEW", "SAVE_EDIT_EDIT")) {
88       String JavaDoc strC_Invoice_ID = vars.getRequiredGlobalVariable("inpcInvoiceId", windowId + "|C_Invoice_ID");
89       InvoiceVendorMultilineData data = getEditVariables(vars);
90       if (data.update(this)==0) {
91         bdError(response, "DBExecuteError", vars.getLanguage());
92       } else {
93         if (vars.commandIn("SAVE_EDIT_NEW")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=NEW");
94         else if (vars.commandIn("SAVE_EDIT_EDIT")) response.sendRedirect(strDireccion + request.getServletPath() + "?Command=EDIT");
95         else response.sendRedirect(strDireccion + "/" + FormatUtilities.replace(windowNameEnUS) + "/" + FormatUtilities.replace(tabNameEnUS) + "_Relation.html?Command=RELATION");
96       }
97     } else if (vars.commandIn("DELETE")) {
98       String JavaDoc strC_Invoice_ID = vars.getRequiredStringParameter("inpcInvoiceId");
99       InvoiceVendorMultilineData.delete(this, strC_Invoice_ID);
100       vars.removeSessionValue(windowId + "|C_Invoice_ID");
101       response.sendRedirect(strDireccion + "/" + FormatUtilities.replace(windowNameEnUS) + "/" + FormatUtilities.replace(tabNameEnUS) + "_Relation.html?Command=RELATION");
102     } else if (vars.commandIn("RELATION")) {
103       vars.getGlobalVariable("inpcInvoiceId", windowId + "|C_Invoice_ID", "");
104       response.sendRedirect(strDireccion + "/" + FormatUtilities.replace(windowNameEnUS) + "/" + FormatUtilities.replace(tabNameEnUS) + "_Relation.html?Command=RELATION");
105     } else pageError(response);
106   }
107
108   InvoiceVendorMultilineData getEditVariables(VariablesSecureApp vars) throws IOException,ServletException {
109     InvoiceVendorMultilineData data = new InvoiceVendorMultilineData();
110
111     data.processing = vars.getStringParameter("inpprocessing", "N");
112     data.issotrx = vars.getRequiredInputGlobalVariable("inpissotrx", windowId + "|IsSOTrx", "N");
113     data.sendemail = vars.getStringParameter("inpsendemail", "N");
114     data.ispaid = vars.getStringParameter("inpispaid", "N");
115     data.cInvoiceId = vars.getRequestGlobalVariable("inpcInvoiceId", windowId + "|C_Invoice_ID");
116     data.isapproved = vars.getRequiredInputGlobalVariable("inpisapproved", windowId + "|IsApproved", "N");
117     data.dateprinted = vars.getStringParameter("inpdateprinted");
118     data.isprinted = vars.getStringParameter("inpisprinted", "N");
119     data.isselfservice = vars.getStringParameter("inpisselfservice", "N");
120     data.istransferred = vars.getStringParameter("inpistransferred", "N");
121     data.processed = vars.getStringParameter("inpprocessed", "N");
122     data.istaxincluded = vars.getStringParameter("inpistaxincluded", "N");
123     data.adClientId = vars.getGlobalVariable("inpadClientId", windowId + "|AD_Client_ID", vars.getClient());
124     data.adOrgId = vars.getRequiredGlobalVariable("inpadOrgId", windowId + "|AD_Org_ID");
125     data.cOrderId = vars.getStringParameter("inpcOrderId");
126     data.dateordered = vars.getStringParameter("inpdateordered");
127     data.documentno = vars.getStringParameter("inpdocumentno", "<>");
128     data.poreference = vars.getStringParameter("inpporeference");
129     data.description = vars.getStringParameter("inpdescription");
130     data.isactive = vars.getStringParameter("inpisactive", "Y");
131     data.dateinvoiced = vars.getStringParameter("inpdate");
132     data.dateacct = vars.getRequiredStringParameter("inpdate");
133     data.cBpartnerId = vars.getRequiredGlobalVariable("inpcBpartnerId", windowId + "|C_BPartner_ID");
134     data.cBpartnerLocationId = vars.getRequiredStringParameter("inpcBpartnerLocationId");
135     data.adUserId = vars.getStringParameter("inpadUserId");
136     data.salesrepId = vars.getStringParameter("inpsalesrepId");
137     data.isdiscountprinted = vars.getStringParameter("inpisdiscountprinted", "N");
138     data.cChargeId = vars.getStringParameter("inpcChargeId");
139     data.chargeamt = vars.getStringParameter("inpchargeamt");
140     data.paymentrule = vars.getRequiredStringParameter("inppaymentrule");
141     data.cPaymenttermId = vars.getRequiredStringParameter("inpcPaymenttermId");
142     data.createfrom = vars.getStringParameter("inpcreatefrom", "N");
143     data.generateto = vars.getStringParameter("inpgenerateto", "N");
144     data.cProjectId = vars.getStringParameter("inpcProjectId");
145     data.cActivityId = vars.getStringParameter("inpcActivityId");
146     data.cCampaignId = vars.getStringParameter("inpcCampaignId");
147     data.adOrgtrxId = vars.getStringParameter("inpadOrgtrxId");
148     data.user1Id = vars.getStringParameter("inpuser1Id");
149     data.user2Id = vars.getStringParameter("inpuser2Id");
150     data.copyfrom = vars.getStringParameter("inpcopyfrom", "N");
151     data.posted = vars.getStringParameter("inpposted", "N");
152     data.docstatus = vars.getStringParameter("inpdocstatus", "DR");
153     data.docaction = vars.getStringParameter("inpdocaction", "CO");
154
155     data.cDoctypetargetId = vars.getStringParameter("inpcDoctypetargetId");
156     data.mPricelistId = vars.getGlobalVariable("inpmPricelistId", windowId + "|M_PriceList_ID", "");
157     data.cCurrencyId = vars.getGlobalVariable("inpcCurrencyId", windowId + "|C_Currency_ID", "");
158     data.cDoctypeId = vars.getGlobalVariable("inpcDoctypeId", windowId + "|C_DocType_ID", "");
159
160     data.createdby = vars.getUser();
161     data.updatedby = vars.getUser();
162
163     if (data.cDoctypetargetId.equals("")) data.cDoctypetargetId = InvoiceVendorMultilineData.selectDocTypeTarget(this, Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), Utility.getContext(this, vars, "#AD_Client_ID", windowId), data.issotrx);
164
165     if (data.cDoctypeId.equals("")) data.cDoctypeId = InvoiceVendorMultilineData.selectDocType(this, Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId));
166
167     if (data.mPricelistId.equals("")) data.mPricelistId = InvoiceVendorMultilineData.selectPriceList(this, Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId));
168
169     if (data.cCurrencyId.equals("")) data.cCurrencyId = InvoiceVendorMultilineData.selectCurrency(this, Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId));
170
171     if (data.documentno.startsWith("<")) data.documentno = Utility.getDocumentNo(this, vars, windowId, "C_Invoice", data.cDoctypetargetId, data.cDoctypeId, false, true);
172
173     return data;
174   }
175
176   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strC_Invoice_ID) throws IOException, ServletException {
177     if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet");
178     String JavaDoc[] discard = {"newDiscard",""};
179     String JavaDoc strCommand = "EDIT";
180     String JavaDoc strDateFormat = vars.getSessionValue("#AD_SqlDateFormat");
181     InvoiceVendorMultilineData[] data = InvoiceVendorMultilineData.select(this, strDateFormat, vars.getLanguage(), strC_Invoice_ID);
182     if (data==null || data.length==0) {
183       discard[0] = new String JavaDoc("editDiscard");
184       strCommand = "NEW";
185       data = InvoiceVendorMultilineData.set(vars.getOrg(), vars.getClient(), DateTimeData.today(this), "DR", "CO", InvoiceVendorMultilineData.selectDocAction(this, vars.getLanguage(), "CO"), "0", "0");
186     }
187
188     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_forms/InvoiceVendorMultiline", discard).createXmlDocument();
189     
190     xmlDocument.setParameter("theme", vars.getTheme());
191     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
192     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
193     xmlDocument.setParameter("command", strCommand);
194     xmlDocument.setParameter("commandType", strCommand);
195     xmlDocument.setParameter("windowName", windowName);
196     xmlDocument.setParameter("tabName", tabName);
197     xmlDocument.setParameter("windowId", windowId);
198     xmlDocument.setParameter("tabId", tabId);
199     xmlDocument.setParameter("tableId", tableId);
200     xmlDocument.setParameter("windowPath", FormatUtilities.replace(windowNameEnUS) + "/" + FormatUtilities.replace(tabNameEnUS) + "_Edition.html");
201     
202     ToolBar toolbar = new ToolBar(this, vars.getLanguage(), "Expenseinvoice", (strCommand.equals("NEW") || (data==null || data.length==0)), "document.frmMain.inpcInvoiceId", "", "", "".equals("Y"), "ExpenseInvoice", strReplaceWith, true);
203     toolbar.prepareEditionTemplate("N".equals("Y"), false, vars.getSessionValue("#ShowTest", "N").equals("Y"), "N".equals("Y"));
204     xmlDocument.setParameter("toolbar", toolbar.toString());
205
206     try {
207       WindowTabs tabs = new WindowTabs(this, vars, tabId, windowId);
208       xmlDocument.setParameter("parentTabContainer", tabs.parentTabs());
209       xmlDocument.setParameter("mainTabContainer", tabs.mainTabs());
210       xmlDocument.setParameter("childTabContainer", tabs.childTabs());
211       NavigationBar nav = new NavigationBar(this, vars.getLanguage(), "../ExpenseInvoice/Expenseinvoice_Relation.html", classInfo.id, classInfo.type, strReplaceWith, tabs.breadcrumb());
212       xmlDocument.setParameter("navigationBar", nav.toString());
213       LeftTabsBar lBar = new LeftTabsBar(this, vars.getLanguage(), "../ExpenseInvoice/Expenseinvoice_Relation.html", strReplaceWith);
214       xmlDocument.setParameter("leftTabs", lBar.editionTemplate());
215     } catch (Exception JavaDoc ex) {
216       throw new ServletException(ex);
217     }
218     try {
219       KeyMap key = new KeyMap(this, vars, tabId, windowId);
220       xmlDocument.setParameter("keyMap", key.getEditionKeyMaps((strCommand.equals("NEW") || (data==null || data.length==0))));
221     } catch (Exception JavaDoc ex) {
222       throw new ServletException(ex);
223     }
224     
225     {
226       OBError myMessage = vars.getMessage(tabId);
227       vars.removeMessage(tabId);
228       if (myMessage!=null) {
229         xmlDocument.setParameter("messageType", myMessage.getType());
230         xmlDocument.setParameter("messageTitle", myMessage.getTitle());
231         xmlDocument.setParameter("messageMessage", myMessage.getMessage());
232       }
233     }
234
235     try {
236       ComboTableData comboTableData = new ComboTableData(vars, this, "LIST", "", "All_Payment Rule", "", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0);
237       Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, data[0].paymentrule);
238       xmlDocument.setData("reportPaymentRule","liststructure", comboTableData.select(false));
239       comboTableData = null;
240     } catch (Exception JavaDoc ex) {
241       throw new ServletException(ex);
242     }
243
244     try {
245       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_Org_ID", "", "AD_Org Trx Security validation", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0);
246       Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, data[0].adOrgId);
247       xmlDocument.setData("reportAD_Org_ID","liststructure", comboTableData.select(false));
248       comboTableData = null;
249     } catch (Exception JavaDoc ex) {
250       throw new ServletException(ex);
251     }
252
253     try {
254       ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "AD_Org_ID", "", "AD_Org Trx Security validation", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0);
255       Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, data[0].adOrgId);
256       xmlDocument.setData("reportAD_Org_ID","liststructure", comboTableData.select(false));
257       comboTableData = null;
258     } catch (Exception JavaDoc ex) {
259       throw new ServletException(ex);
260     }
261
262       try {
263         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_PaymentTerm_ID", "", "", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0);
264         Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, data[0].cPaymenttermId);
265         xmlDocument.setData("reportC_PaymentTerm_ID","liststructure", comboTableData.select(false));
266         comboTableData = null;
267       } catch (Exception JavaDoc ex) {
268         throw new ServletException(ex);
269       }
270
271       try {
272         ComboTableData comboTableData = new ComboTableData(vars, this, "TABLEDIR", "C_BPartner_Location_ID", "", "C_BPartner Location - Bill To", Utility.getContext(this, vars, "#User_Org", windowId), Utility.getContext(this, vars, "#User_Client", windowId), 0);
273         Utility.fillSQLParameters(this, vars, null, comboTableData, windowId, data[0].cBpartnerId);
274         xmlDocument.setData("reportC_BPartner_Location_ID","liststructure", comboTableData.select(false));
275         comboTableData = null;
276       } catch (Exception JavaDoc ex) {
277         throw new ServletException(ex);
278       }
279
280     xmlDocument.setData("structure1", data);
281     
282     response.setContentType("text/html; charset=UTF-8");
283     PrintWriter out = response.getWriter();
284     out.println(xmlDocument.print());
285     out.close();
286   }
287
288   public String JavaDoc getServletInfo() {
289     return "InvoiceVendorMultiline Servlet";
290   } // end of getServletInfo() method
291
}
292
293
Popular Tags