KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpReports > RptC_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.erpReports;
20
21 import org.openbravo.base.secureApp.*;
22 import org.openbravo.xmlEngine.XmlDocument;
23 import java.io.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26
27 import org.openbravo.erpCommon.utility.DateTimeData;
28
29
30 public class RptC_Invoice extends HttpSecureAppServlet {
31   
32   
33   public void init (ServletConfig config) {
34     super.init(config);
35     boolHist = false;
36   }
37
38   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
39     VariablesSecureApp vars = new VariablesSecureApp(request);
40
41     if (vars.commandIn("DEFAULT")) {
42       String JavaDoc strcInvoiceId = vars.getSessionValue("RptC_Invoice.inpcInvoiceId_R");
43       if (strcInvoiceId.equals("")) strcInvoiceId = vars.getSessionValue("RptC_Invoice.inpcInvoiceId");
44       printPagePDF(response, vars, strcInvoiceId);
45     } else if (vars.commandIn("FIND")) {
46       String JavaDoc strbPartnerId = vars.getStringParameter("inpcBpartnerId");
47       String JavaDoc strDateTo = vars.getStringParameter("inpDateInvoiceFrom");
48       String JavaDoc strDateFrom = vars.getStringParameter("inpDateInvoiceTo");
49       String JavaDoc strDocNoFrom = vars.getStringParameter("inpInvoicedocumentnoFrom");
50       String JavaDoc strDocNoTo = vars.getStringParameter("inpInvoicedocumentnoTo");
51       String JavaDoc strcInvoiceId="";
52       RptCInvoiceData[] data2= RptCInvoiceData.select(this, strDocNoFrom, strDocNoTo, strbPartnerId, strDateFrom, DateTimeData.nDaysAfter(this, strDateTo,"1"));
53       int j;
54       for (j=0;j<data2.length;j++) {
55         if (j!=0) strcInvoiceId += ",";
56         strcInvoiceId += data2[j].cInvoiceId;
57       }
58       strcInvoiceId = "("+strcInvoiceId+")";
59       printPagePDF(response, vars, strcInvoiceId);
60     } else pageError(response);
61   }
62
63   void printPagePDF(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strcInvoiceId) throws IOException,ServletException{
64     if (log4j.isDebugEnabled()) log4j.debug("Output: pdf");
65     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpReports/RptC_Invoice").createXmlDocument();
66
67     int i=0;
68     RptCInvoiceHeaderData[] pdfInvoicesData = RptCInvoiceHeaderData.select(this, strcInvoiceId);
69
70     RptCInvoiceLinesData[][] pdfInvoiceLinesDataArray = new RptCInvoiceLinesData[pdfInvoicesData.length][];
71
72     RptCInvoiceTaxData[][] pdfInvoiceTaxLinesDataArray = new RptCInvoiceTaxData[pdfInvoicesData.length][];
73
74     for (i=0;i<pdfInvoicesData.length;i++) {
75       RptCInvoiceLinesData[] data = RptCInvoiceLinesData.select(this,pdfInvoicesData[i].cInvoiceId);
76       // If the invoice has zero lines it will insert an empty line for not failing the fop
77
if (data == null || data.length == 0) {
78         data = RptCInvoiceLinesData.set();
79       }
80       pdfInvoiceLinesDataArray[i] = data;
81     }
82
83     for (i=0;i<pdfInvoicesData.length;i++) {
84       RptCInvoiceTaxData[] data1 = RptCInvoiceTaxData.select(this,pdfInvoicesData[i].cInvoiceId);
85       // If the invoice has zero lines it will insert an empty line for not failing the fop
86
if (data1 == null || data1.length == 0) {
87         data1 = RptCInvoiceTaxData.set();
88       }
89       pdfInvoiceTaxLinesDataArray[i] = data1;
90     }
91
92
93     xmlDocument.setData("structure1",pdfInvoicesData);
94     xmlDocument.setDataArray("reportInvoiceLines","structureInvoiceLines",pdfInvoiceLinesDataArray);
95     xmlDocument.setDataArray("reportInvoiceLines","structureInvoiceTaxes",pdfInvoiceTaxLinesDataArray);
96
97     String JavaDoc strResult = xmlDocument.print();
98     if (log4j.isDebugEnabled()) log4j.debug(strResult);
99     renderFO(strResult, response);
100   }
101
102   public String JavaDoc getServletInfo() {
103     return "Servlet that presents the RptCOrders seeker";
104   } // End of getServletInfo() method
105
}
106
Popular Tags