KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > ad_actionButton > CreateFile


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.ad_actionButton;
20
21 import org.openbravo.erpCommon.ad_combos.*;
22 import org.openbravo.erpCommon.utility.Utility;
23 import org.openbravo.utils.Replace;
24 import org.openbravo.base.secureApp.HttpSecureAppServlet;
25 import org.openbravo.base.secureApp.VariablesSecureApp;
26 import org.openbravo.xmlEngine.XmlDocument;
27 import java.io.*;
28 import javax.servlet.*;
29 import javax.servlet.http.*;
30
31
32 public class CreateFile extends HttpSecureAppServlet {
33
34   public void init (ServletConfig config) {
35     super.init(config);
36     boolHist = false;
37   }
38
39   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
40     VariablesSecureApp vars = new VariablesSecureApp(request);
41
42     if (vars.commandIn("DEFAULT")) {
43       String JavaDoc strProcessId = vars.getStringParameter("inpProcessId");
44       String JavaDoc strWindow = vars.getStringParameter("inpwindowId");
45       String JavaDoc strKey = vars.getStringParameter("inpcRemittanceId");
46       String JavaDoc strMessage = "";
47       printPage(response, vars, strKey, strWindow, strProcessId, strMessage);
48     } else if(vars.commandIn("GENERATE")){
49       String JavaDoc strKey = vars.getStringParameter("inpcRemittanceId");
50       getPrintPage(response, vars, strKey);
51     }
52   }
53
54
55   void printPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc windowId, String JavaDoc strProcessId, String JavaDoc strMessage)
56     throws IOException, ServletException {
57       if (log4j.isDebugEnabled()) log4j.debug("Output: Button create file msg:"+strMessage);
58
59       ActionButtonDefaultData[] data = null;
60       String JavaDoc strHelp="", strDescription="";
61       if (vars.getLanguage().equals("en_US")) data = ActionButtonDefaultData.select(this, strProcessId);
62       else data = ActionButtonDefaultData.selectLanguage(this, vars.getLanguage(), strProcessId);
63
64       if (data!=null && data.length!=0) {
65         strDescription = data[0].description;
66         strHelp = data[0].help;
67       }
68       String JavaDoc[] discard = {""};
69       if (strHelp.equals("")) discard[0] = new String JavaDoc("helpDiscard");
70       XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/ad_actionButton/CreateFile", discard).createXmlDocument();
71       xmlDocument.setParameter("key", strKey);
72       xmlDocument.setParameter("window", windowId);
73       xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
74       xmlDocument.setData("reportTyperemittance","liststructure", TyperemittanceComboData.select(this, Utility.getContext(this, vars, "#User_Client", "CreateFile"), Utility.getContext(this, vars, "#User_Org", "CreateFile")));
75       xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\r\n");
76       xmlDocument.setParameter("description", strDescription);
77       xmlDocument.setParameter("help", strHelp);
78       xmlDocument.setParameter("message",strMessage.equals("")?"":"alert('" + strMessage + "');");
79
80       response.setContentType("text/html; charset=UTF-8");
81       PrintWriter out = response.getWriter();
82       out.println(xmlDocument.print());
83       out.close();
84     }
85
86   void getPrintPage(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey) throws IOException, ServletException {
87     if (log4j.isDebugEnabled()) log4j.debug("generate "+strKey);
88     String JavaDoc strCuaderno = CreateFileData.selectParam(this,strKey,"CUADERNO");
89     String JavaDoc strContract = CreateFileData.selectParam(this,strKey,"CONTRACT");
90
91     if (strCuaderno.equals("58")) printPageFind58(response, vars, strKey, strContract);
92     else if (strCuaderno.equals("19")) printPageFind19(response, vars, strKey, strContract);
93     else if (strCuaderno.equals("34")) printPageFind34(response, vars, strKey);
94   }
95
96   void printPageFind58(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strContract) throws IOException, ServletException {
97     if (log4j.isDebugEnabled()) log4j.debug("Output: pageFind");
98     StringBuffer JavaDoc strBuf = new StringBuffer JavaDoc();
99     String JavaDoc strMessage = "";
100     CreateFileData[] Principio = CreateFileData.select(this, strKey);
101     CreateFileData[] Lineas = CreateFileData.selectLineas(this,strKey);
102     CreateFileData[] Total = CreateFileData.selectTotal(this,strKey);
103     int comprobacion1 = new Integer JavaDoc(CreateFileData.selectComprobacion1(this, strKey)).intValue();
104     int comprobacion2 = new Integer JavaDoc(CreateFileData.selectComprobacion2(this, strKey)).intValue();
105     int comprobacion3 = new Integer JavaDoc(CreateFileData.selectComprobacion3(this, strKey)).intValue();
106     int comprobacion4 = new Integer JavaDoc(CreateFileData.selectComprobacion4(this, strKey)).intValue();
107     if (log4j.isDebugEnabled()) log4j.debug(" c1:"+comprobacion1+" c2:"+comprobacion2+" c3:"+comprobacion3+" c4:"+comprobacion4);
108
109     if(comprobacion1 != 0 || comprobacion2 != 1 || comprobacion3 !=1 || comprobacion4 == 0){
110     strMessage = Utility.messageBD(this, "CreateFileError", vars.getLanguage());
111     printPage(response, vars, strKey, "", "", strMessage);
112     }
113     int contador = 2;
114     String JavaDoc strLinea = "";
115     // dubugging headers
116
if (Principio == null || Principio.length == 0){
117         strMessage = Utility.messageBD(this, "DefaultAccountError", vars.getLanguage());
118         printPage(response, vars, strKey, "", "", strMessage);
119         return;
120     }
121     if (Lineas == null || Total == null)return;
122     if (Principio[0].nif == null || Principio[0].nif.equals("")){
123         strMessage = Utility.messageBD(this, "NIFError", vars.getLanguage());
124     }
125     if (Principio[0].codebank == null || Principio[0].codebank.equals("")){
126         strMessage = Utility.messageBD(this, "CodeBankError", vars.getLanguage());
127     }
128     if (Principio[0].codebranch == null || Principio[0].codebranch.equals("")){
129         strMessage = Utility.messageBD(this, "CodeBranchError", vars.getLanguage());
130     }
131     if (Principio[0].digitcontrol1 == null || Principio[0].digitcontrol1.equals("")){
132         strMessage = Utility.messageBD(this, "DC1Error", vars.getLanguage());
133     }
134     if (Principio[0].digitcontrol2 == null || Principio[0].digitcontrol2.equals("")){
135         strMessage = Utility.messageBD(this, "DC2Error", vars.getLanguage());
136     }
137     if (Principio[0].ine == null || Principio[0].ine.equals("")){
138         strMessage = Utility.messageBD(this, "INEError", vars.getLanguage());
139     }
140     // presentation header
141
strBuf = strBuf.append("5170").append(Principio[0].nif).append(strContract).append(Principio[0].dateplanned);
142     strBuf = strBuf.append(Principio[0].entidad);
143     strBuf = strBuf.append(Principio[0].entofi).append("\r\n");
144     // ordering header
145
strBuf = strBuf.append("5370").append(Principio[0].nif).append(strContract).append(Principio[0].dateplanned);
146     strBuf = strBuf.append(Principio[0].entidad).append(Principio[0].nCuenta).append(" 06");
147     strBuf = strBuf.append(Principio[0].ine).append(" \r\n");
148     // lines
149
for (int i=0;i<Lineas.length;i++){
150         // debugging lines
151
if (Lineas[i].creditcardnumber == null || Lineas[i].creditcardnumber.equals("")){
152             strMessage = Utility.messageBD(this, "CodeBankBPError", vars.getLanguage()) + Lineas[i].tercero;
153         }
154         if (Lineas[i].fechaVencimiento == null || Lineas[i].fechaVencimiento.equals("")){
155             strMessage = Utility.messageBD(this, "DatePlannedError", vars.getLanguage()) + Lineas[i].tercero;
156         }
157         if (Lineas[i].direccion == null || Lineas[i].direccion.equals("")){
158             strMessage = Utility.messageBD(this, "AddressError", vars.getLanguage()) + Lineas[i].tercero;
159         }
160         if (Lineas[i].plaza == null || Lineas[i].plaza.equals("")){
161             strMessage = Utility.messageBD(this, "SquareError", vars.getLanguage()) + Lineas[i].tercero;
162         }
163         if (Lineas[i].postal == null || Lineas[i].postal.equals("")){
164             strMessage = Utility.messageBD(this, "PostCodeError", vars.getLanguage()) + Lineas[i].tercero;
165         }
166         if (Lineas[i].localidad == null || Lineas[i].localidad.equals("")){
167             strMessage = Utility.messageBD(this, "TownError", vars.getLanguage()) + Lineas[i].tercero;
168         }
169         if (Lineas[i].fechaFactura == null || Lineas[i].fechaFactura.equals("")){
170             strMessage = Utility.messageBD(this, "InvoiceDateError", vars.getLanguage()) + Lineas[i].tercero;;
171         }
172         strBuf = strBuf.append("5670").append(Principio[0].nif).append(strContract).append(Lineas[i].nFactura).append(Lineas[i].tercero);
173         strBuf = strBuf.append(Lineas[i].creditcardnumber).append(Lineas[i].payamt).append(" ");
174         strBuf = strBuf.append(Replace.replace(Lineas[i].concepto,"\n", "")).append(Lineas[i].fechaVencimiento).append(" \r\n");
175         contador++;
176         strBuf = strBuf.append("5676").append(Principio[0].nif).append(strContract).append(Lineas[i].nFactura).append(Lineas[i].direccion);
177         strBuf = strBuf.append(Lineas[i].plaza).append(Lineas[i].postal).append(Lineas[i].localidad);
178         strBuf = strBuf.append(Lineas[i].codigoProvincia).append(Lineas[i].fechaFactura).append("\r\n");
179         contador++;
180     }
181     CreateFileData[] NLineas = CreateFileData.selectNLineas(this, String.valueOf(contador));
182     //total orderer
183
strBuf = strBuf.append("5870").append(Principio[0].nif).append(strContract).append(NLineas[0].hueco);
184     strBuf = strBuf.append(Total[0].payamt).append(Total[0].nFactura).append(NLineas[0].lineas).append("\r\n");
185     NLineas = CreateFileData.selectNLineas(this, String.valueOf(contador + 2));
186     //total
187
strBuf = strBuf.append("5970").append(Principio[0].nif).append(strContract);
188     strBuf = strBuf.append(NLineas[0].ordenantes).append(Total[0].payamt).append(Total[0].nFactura).append(NLineas[0].lineas);
189     if (!strMessage.equals("")){
190       printPage(response, vars, strKey, "", "", strMessage);
191     }else{
192       response.setContentType("application/rtf");
193       response.setHeader("Content-Disposition","attachment; filename=BANK.DAT");
194       PrintWriter out = response.getWriter();
195       out.println(strBuf.toString());
196       out.close();
197     }
198   }
199
200   void printPageFind19(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey, String JavaDoc strContract) throws IOException, ServletException {
201     if (log4j.isDebugEnabled()) log4j.debug("Output: pageFind");
202     StringBuffer JavaDoc strBuf = new StringBuffer JavaDoc();
203     String JavaDoc strMessage = "";
204     CreateFileData[] Principio = CreateFileData.select(this, strKey);
205     CreateFileData[] Lineas = CreateFileData.selectLineas(this,strKey);
206     CreateFileData[] Total = CreateFileData.selectTotal(this,strKey);
207
208     int comprobacion1 = new Integer JavaDoc(CreateFileData.selectComprobacion1(this, strKey)).intValue();
209     int comprobacion2 = new Integer JavaDoc(CreateFileData.selectComprobacion2(this, strKey)).intValue();
210     int comprobacion3 = new Integer JavaDoc(CreateFileData.selectComprobacion3(this, strKey)).intValue();
211     int comprobacion4 = new Integer JavaDoc(CreateFileData.selectComprobacion4(this, strKey)).intValue();
212
213     if(comprobacion1 != 0 || comprobacion2 != 1 || comprobacion3 !=1 || comprobacion4 == 0){
214       if (log4j.isDebugEnabled()) log4j.debug("Error: c1:"+comprobacion1+" c2:"+comprobacion2+" c3:"+comprobacion3+" c4:"+comprobacion4);
215       strMessage = Utility.messageBD(this, "CreateFileError", vars.getLanguage());
216       printPage(response, vars, strKey, "", "", strMessage);
217     }
218     if (log4j.isDebugEnabled()) log4j.debug("check1 ok");
219     int contador = 2;
220     String JavaDoc strLinea = "";
221     //debugging headers
222
if (Principio == null || Principio.length == 0){
223         strMessage = Utility.messageBD(this, "DefaultAccountError", vars.getLanguage());
224         printPage(response, vars, strKey, "", "", strMessage);
225         return;
226     }
227     if (Lineas == null || Total == null)return;
228     if (Principio[0].nif == null || Principio[0].nif.equals("")){
229         strMessage = Utility.messageBD(this, "NIFError", vars.getLanguage());
230         if (log4j.isDebugEnabled()) log4j.debug("NIF");
231     }
232     if (Principio[0].codebank == null || Principio[0].codebank.equals("")){
233         strMessage = Utility.messageBD(this, "CodeBankError", vars.getLanguage());
234         if (log4j.isDebugEnabled()) log4j.debug("codebank");
235     }
236     if (Principio[0].codebranch == null || Principio[0].codebranch.equals("")){
237         strMessage = Utility.messageBD(this, "CodeBranchError", vars.getLanguage());
238         if (log4j.isDebugEnabled()) log4j.debug("CodeBranchError");
239     }
240     if (Principio[0].digitcontrol1 == null || Principio[0].digitcontrol1.equals("")){
241         strMessage = Utility.messageBD(this, "DC1Error", vars.getLanguage());
242         if (log4j.isDebugEnabled()) log4j.debug("DC1Error");
243     }
244     if (Principio[0].digitcontrol2 == null || Principio[0].digitcontrol2.equals("")){
245         strMessage = Utility.messageBD(this, "DC2Error", vars.getLanguage());
246         if (log4j.isDebugEnabled()) log4j.debug("DC2Error");
247     }
248     if (log4j.isDebugEnabled()) log4j.debug("check2 ok");
249     //presentation header
250
strBuf = strBuf.append("5180").append(Principio[0].nif).append(strContract).append(Principio[0].hoy).append(Principio[0].dateplanned);
251     strBuf = strBuf.append(Principio[0].entidad19);
252     strBuf = strBuf.append(Principio[0].entofi).append("\r\n");
253     //ordering header
254
strBuf = strBuf.append("5380").append(Principio[0].nif).append(strContract).append(Principio[0].hoy).append(Principio[0].dateplanned);
255     strBuf = strBuf.append(Principio[0].entidad19).append(Principio[0].nCuenta).append(" 01 ");
256     strBuf = strBuf.append(" \r\n");
257     // Lines
258
for (int i=0;i<Lineas.length;i++){
259         //lines debugging
260
if (Lineas[i].creditcardnumber == null || Lineas[i].creditcardnumber.equals("")){
261             if (log4j.isDebugEnabled()) log4j.debug("CodeBankBPError");
262             strMessage = Utility.messageBD(this, "CodeBankBPError", vars.getLanguage()) + Lineas[i].tercero;
263         }
264         if (Lineas[i].fechaVencimiento == null || Lineas[i].fechaVencimiento.equals("")){
265           if (log4j.isDebugEnabled()) log4j.debug("DatePlannedError");
266             strMessage = Utility.messageBD(this, "DatePlannedError", vars.getLanguage()) + Lineas[i].tercero;
267         }
268         if (Lineas[i].direccion == null || Lineas[i].direccion.equals("")){
269           if (log4j.isDebugEnabled()) log4j.debug("AddressError");
270             strMessage = Utility.messageBD(this, "AddressError", vars.getLanguage()) + Lineas[i].tercero;
271         }
272         if (Lineas[i].plaza == null || Lineas[i].plaza.equals("")){
273           if (log4j.isDebugEnabled()) log4j.debug("SquareError");
274             strMessage = Utility.messageBD(this, "SquareError", vars.getLanguage()) + Lineas[i].tercero;
275         }
276         if (Lineas[i].postal == null || Lineas[i].postal.equals("")){
277           if (log4j.isDebugEnabled()) log4j.debug("PostCodeError");
278             strMessage = Utility.messageBD(this, "PostCodeError", vars.getLanguage()) + Lineas[i].tercero;
279         }
280         if (Lineas[i].localidad == null || Lineas[i].localidad.equals("")){
281           if (log4j.isDebugEnabled()) log4j.debug("TownError");
282             strMessage = Utility.messageBD(this, "TownError", vars.getLanguage()) + Lineas[i].tercero;
283         }
284         if (Lineas[i].fechaFactura == null || Lineas[i].fechaFactura.equals("")){
285           if (log4j.isDebugEnabled()) log4j.debug("InvoiceDateError");
286             strMessage = Utility.messageBD(this, "InvoiceDateError", vars.getLanguage()) + Lineas[i].tercero;;
287         }
288         strBuf = strBuf.append("5680").append(Principio[0].nif).append(strContract).append(Lineas[i].nFactura19).append(Lineas[i].tercero);
289         strBuf = strBuf.append(Lineas[i].creditcardnumber).append(Lineas[i].payamt).append("0000000000000000");
290         strBuf = strBuf.append(Replace.replace(Lineas[i].concepto,"\n", "")).append(Lineas[i].fechaVencimiento).append(" \r\n");
291         contador++;
292 /* strBuf = strBuf.append("5676").append(Principio[0].nif).append("000").append(Lineas[i].nFactura).append(Lineas[i].direccion);
293         strBuf = strBuf.append(Lineas[i].plaza).append(Lineas[i].postal).append(Lineas[i].localidad);
294         strBuf = strBuf.append(Lineas[i].codigoProvincia).append(Lineas[i].fechaFactura).append("\r\n");
295         contador++;*/

296     }
297     if (log4j.isDebugEnabled()) log4j.debug("check3 ok");
298     CreateFileData[] NLineas = CreateFileData.selectNLineas(this, String.valueOf(contador));
299     //total orderer
300
strBuf = strBuf.append("5880").append(Principio[0].nif).append(strContract).append(NLineas[0].hueco);
301     strBuf = strBuf.append(Total[0].payamt).append(Total[0].nFactura).append(NLineas[0].lineas).append("\r\n");
302     NLineas = CreateFileData.selectNLineas(this, String.valueOf(contador + 2));
303     //total
304
strBuf = strBuf.append("5980").append(Principio[0].nif).append(strContract);
305     strBuf = strBuf.append(NLineas[0].ordenantes).append(Total[0].payamt).append(Total[0].nFactura).append(NLineas[0].lineas);
306     if (!strMessage.equals("")){
307       printPage(response, vars, strKey, "", "", strMessage);
308     }else{
309       response.setContentType("application/rtf");
310       response.setHeader("Content-Disposition","attachment; filename=BANK.DAT");
311       PrintWriter out = response.getWriter();
312       out.println(strBuf.toString());
313       out.close();
314     }
315   }
316
317
318
319   void printPageFind34(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strKey) throws IOException, ServletException {
320     if (log4j.isDebugEnabled()) log4j.debug("Output: pageFind34");
321     StringBuffer JavaDoc strBuf = new StringBuffer JavaDoc();
322     String JavaDoc strMessage = "";
323
324
325     String JavaDoc strConcepto = CreateFileData.selectParam(this,strKey,"CONCEPTO");
326     if (log4j.isDebugEnabled()) log4j.debug("Item"+strConcepto);
327     if (strConcepto == null||strConcepto.equals("")) strConcepto="N";
328     if (log4j.isDebugEnabled()) log4j.debug("Item"+strConcepto);
329     char cConcepto=strConcepto.charAt(0);
330
331     String JavaDoc strCodigo;
332
333     switch (cConcepto)
334     {
335       case 'C': //check
336
strCodigo = "57";
337         break;
338       case 'R': //promissory note
339
strCodigo = "58";
340         break;
341       case 'P': //certified payments
342
strCodigo = "59";
343         break;
344       default: //Salaries y bank transfers
345
strCodigo = "56";
346     }
347     if (log4j.isDebugEnabled()) log4j.debug("code"+strCodigo);
348     /*
349       1->Orderer (by default)
350       2->Beneficiary
351     */

352     String JavaDoc strGastos = CreateFileData.selectParam(this,strKey,"GASTOS");
353     if (strGastos==null||!strGastos.equals("2")) strGastos="1";
354     if (log4j.isDebugEnabled()) log4j.debug("strGastos"+strGastos);
355
356     /*
357       0->Only one journal entry
358       1->One entry per beneficiary
359     */

360     String JavaDoc strDetalle = CreateFileData.selectParam(this,strKey,"DETALLE");
361     if (strDetalle==null||!strDetalle.equals("1")) strDetalle="0";
362     if (log4j.isDebugEnabled()) log4j.debug("code"+strDetalle);
363
364
365     CreateFile34Data[] Principio = CreateFile34Data.select(this, strKey);
366     CreateFile34Data[] Lineas = CreateFile34Data.selectLineas(this,strKey);
367     CreateFile34Data[] Total = CreateFile34Data.selectTotal(this,strKey);
368     int comprobacion1 = new Integer JavaDoc(CreateFileData.selectComprobacion1(this, strKey)).intValue();
369     int comprobacion2 = new Integer JavaDoc(CreateFileData.selectComprobacion2(this, strKey)).intValue();
370     int comprobacion3 = new Integer JavaDoc(CreateFileData.selectComprobacion3(this, strKey)).intValue();
371     int comprobacion4 = new Integer JavaDoc(CreateFileData.selectComprobacion4(this, strKey)).intValue();
372
373     int comprobacion341 = new Integer JavaDoc(CreateFile34Data.selectComprobacion341(this, Principio[0].hoy, Principio[0].duedate)).intValue();
374
375     if(comprobacion1 != 0 || comprobacion2 != 1 || comprobacion3 !=1 || comprobacion4 == 0){
376       if (log4j.isDebugEnabled()) log4j.debug("Error: c1:"+comprobacion1+" c2:"+comprobacion2+" c3:"+comprobacion3+" c4:"+comprobacion4);
377       strMessage = Utility.messageBD(this, "CreateFileError", vars.getLanguage());
378       printPage(response, vars, strKey, "", "", strMessage);
379     }
380
381     if (log4j.isDebugEnabled()) log4j.debug("Principio[0].taxid = " + Principio[0].taxid);
382     if (log4j.isDebugEnabled()) log4j.debug("Principio[0].acct = " + Principio[0].acct);
383     if (log4j.isDebugEnabled()) log4j.debug("check1 ok");
384
385
386     //debugging headers
387
if (Principio == null || Principio.length == 0){
388         strMessage = Utility.messageBD(this, "DefaultAccountError", vars.getLanguage());
389         printPage(response, vars, strKey, "", "", strMessage);
390             return;
391     }
392     if (Lineas == null || Total == null) return;
393     if (Principio[0].taxid == null || Principio[0].taxid.length()!=9){
394         strMessage = Utility.messageBD(this, "NIFError", vars.getLanguage());
395         if (log4j.isDebugEnabled()) log4j.debug("VAT number");
396         printPage(response, vars, strKey, "", "", strMessage);
397         return;
398     }
399     if (Principio[0].acct == null || Principio[0].acct.length()!=18){
400         strMessage = Utility.messageBD(this, "BankAccountError", vars.getLanguage());
401         if (log4j.isDebugEnabled()) log4j.debug("bankaccount");
402         printPage(response, vars, strKey, "", "", strMessage);
403         return;
404     }
405
406     /*if (comprobacion341!=0)
407     {
408        strMessage = Utility.messageBD(this, "TodayHigherDueData", vars.getLanguage());
409        if (log4j.isDebugEnabled()) log4j.debug("TodayHigherDueData");
410        printPage(response, vars, strKey, "", "", strMessage);
411        return;
412     }*/

413
414     if (log4j.isDebugEnabled()) log4j.debug("check2 ok");
415     //header: orderer
416
//001
417
strBuf = strBuf.append("03").append(strCodigo).append(Principio[0].nif).append(" "); //A-D (common)
418
strBuf = strBuf.append("001").append(Principio[0].hoy).append(Principio[0].duedate); // E-F2
419
strBuf = strBuf.append(Principio[0].nCuenta).append(strDetalle).append(" ").append(Principio[0].dc).append(Principio[0].hueco).append("\r\n"); //F3-G
420

421     //002
422
strBuf = strBuf.append("03").append(strCodigo).append(Principio[0].nif).append(" "); //A-D (common)
423
strBuf = strBuf.append("002").append(Principio[0].nombre).append(Principio[0].hueco).append("\r\n"); //E-G
424

425     //003
426
strBuf = strBuf.append("03").append(strCodigo).append(Principio[0].nif).append(" "); //A-D (common)
427
strBuf = strBuf.append("003").append(Principio[0].domicilio).append(Principio[0].hueco).append("\r\n"); //E-G
428

429     //004
430
strBuf = strBuf.append("03").append(strCodigo).append(Principio[0].nif).append(" "); //A-D (common)
431
strBuf = strBuf.append("004").append(Principio[0].plaza).append(Principio[0].hueco).append("\r\n"); //E-G
432

433     int contador = 4;
434     //Lines
435
for (int i=0;i<Lineas.length;i++){
436         //debugging lines
437
if (log4j.isDebugEnabled()) log4j.debug("Lineas[i].taxid=" + Lineas[i].taxid);
438           if (log4j.isDebugEnabled()) log4j.debug("Lineas[i].acct=" + Lineas[i].acct);
439           if (log4j.isDebugEnabled()) log4j.debug("Lineas[i].nom=" + Lineas[i].nom);
440           if (log4j.isDebugEnabled()) log4j.debug("Lineas[i].dom=" + Lineas[i].dom);
441           if (log4j.isDebugEnabled()) log4j.debug("Lineas[i].pla=" + Lineas[i].pla);
442           if (log4j.isDebugEnabled()) log4j.debug("Lineas[i].prov=" + Lineas[i].prov);
443
444
445         if (Lineas[i].nom == null || Lineas[i].nom.length()<1){
446           if (log4j.isDebugEnabled()) log4j.debug("NameError");
447             strMessage = Utility.messageBD(this, "NameError", vars.getLanguage()) + Lineas[i].nif;
448             printPage(response, vars, strKey, "", "", strMessage);
449             return;
450         }
451         if (Lineas[i].taxid == null || Lineas[i].taxid.length()!=9){
452             if (log4j.isDebugEnabled()) log4j.debug("NIFError");
453             strMessage = Utility.messageBD(this, "NIFBPartnerError", vars.getLanguage()) + Lineas[i].nombre;
454             printPage(response, vars, strKey, "", "", strMessage);
455             return;
456         }
457         if (Lineas[i].acct == null || Lineas[i].acct.length()!=20){
458             if (log4j.isDebugEnabled()) log4j.debug("CodeBankBPError");
459             strMessage = Utility.messageBD(this, "CodeBankBPError", vars.getLanguage()) + Lineas[i].nombre;
460             printPage(response, vars, strKey, "", "", strMessage);
461             return;
462         }
463         if (Lineas[i].dom == null || Lineas[i].dom.length()<1){
464           if (log4j.isDebugEnabled()) log4j.debug("AddressError");
465             strMessage = Utility.messageBD(this, "AddressError", vars.getLanguage()) + Lineas[i].nombre;
466             printPage(response, vars, strKey, "", "", strMessage);
467             return;
468         }
469         if (Lineas[i].pla == null || Lineas[i].pla.length()<1){
470           if (log4j.isDebugEnabled()) log4j.debug("SquareError");
471             strMessage = Utility.messageBD(this, "SquareError", vars.getLanguage()) + Lineas[i].nombre;
472             printPage(response, vars, strKey, "", "", strMessage);
473             return;
474         }
475         if (Lineas[i].prov == null || Lineas[i].prov.length()<1){
476           if (log4j.isDebugEnabled()) log4j.debug("AddressError");
477             strMessage = Utility.messageBD(this, "AddressError", vars.getLanguage()) + Lineas[i].nombre;
478             printPage(response, vars, strKey, "", "", strMessage);
479             return;
480         }
481         //010
482
strBuf = strBuf.append("06").append(strCodigo).append(Principio[0].nif).append(Lineas[i].nif); //A-D (common)
483
strBuf = strBuf.append("010").append(Lineas[i].payamt).append(Lineas[i].nCuenta); //F1-F4
484
strBuf = strBuf.append(strGastos);
485         strBuf = strBuf.append(cConcepto=='N'?"1":cConcepto=='P'?"8":"9").append(" ");
486         strBuf = strBuf.append(Lineas[i].dc).append(Principio[0].hueco).append("\r\n");
487
488         //011
489
strBuf = strBuf.append("06").append(strCodigo).append(Principio[0].nif).append(Lineas[i].nif); //A-D (common)
490
strBuf = strBuf.append("011").append(Lineas[i].nombre).append(Principio[0].hueco).append("\r\n");
491         //012
492
strBuf = strBuf.append("06").append(strCodigo).append(Principio[0].nif).append(Lineas[i].nif); //A-D (common)
493
strBuf = strBuf.append("012").append(Lineas[i].domicilio).append(Principio[0].hueco).append("\r\n");
494
495         //014
496
strBuf = strBuf.append("06").append(strCodigo).append(Principio[0].nif).append(Lineas[i].nif); //A-D (common)
497
strBuf = strBuf.append("014").append(Lineas[i].plaza).append(Principio[0].hueco).append("\r\n");
498
499         //015
500
strBuf = strBuf.append("06").append(strCodigo).append(Principio[0].nif).append(Lineas[i].nif); //A-D (common)
501
strBuf = strBuf.append("015").append(Lineas[i].provincia).append(Principio[0].hueco).append("\r\n");
502
503         //016
504
strBuf = strBuf.append("06").append(strCodigo).append(Principio[0].nif).append(Lineas[i].nif); //A-D (common)
505
strBuf = strBuf.append("016").append(Lineas[i].concepto).append(Principio[0].hueco).append("\r\n");
506
507         contador+=6;
508    }
509    //total
510
CreateFile34Data[] NLineas = CreateFile34Data.selectNLineas(this, String.valueOf(contador+1));
511    strBuf = strBuf.append("08").append(strCodigo).append(Principio[0].nif).append(Total[0].payamt); //A-E
512
strBuf = strBuf.append(NLineas[0].ordenantes).append(NLineas[0].lineas).append(NLineas[0].hueco).append("\r\n");
513
514     if (!strMessage.equals("")){
515       printPage(response, vars, strKey, "", "", strMessage);
516     }else{
517       response.setContentType("application/rtf");
518       response.setHeader("Content-Disposition","attachment; filename=BANK.DAT");
519       PrintWriter out = response.getWriter();
520       out.println(strBuf.toString());
521       out.close();
522     }
523   }
524
525   public String JavaDoc getServletInfo() {
526     return "Servlet for the generation of files for banks";
527   } // end of getServletInfo() method
528
}
529
Popular Tags