BrightSide Workbench Full Report + Source Code
contract/DocumentReport.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.financials.document.contract;
19 
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.Map;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import net.sf.jasperreports.engine.JRException;
26 import org.turro.contacts.Contact;
27 import org.turro.elephant.context.Application;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.util.DateFormats;
30 import org.turro.elephant.util.DecimalFormats;
31 import org.turro.financials.entity.Company;
32 import org.turro.financials.entity.Document;
33 import org.turro.financials.entity.DocumentLine;
34 import org.turro.financials.model.business.CompanyWrapper;
35 import org.turro.zkoss.print.ReportButton;
36 import org.turro.zkoss.print.ReportPrint;
37 
42 public class DocumentReport extends ReportButton {
43 
44  private Document document;
45 
46  public void setDocument(Document document) {
47  this.document = document;
48  }
49 
50  @Override
51  protected void print(String type) {
52  Collection<DocumentLine> lines = document.getDocumentLines();
53  if(lines != null && lines.size() > 0) {
54  DocumentLine sample = lines.iterator().next();
55  int fractionDigits = document.getCurrency().getDefaultFractionDigits();
56  Map parameters = new HashMap();
57  Company company = CompanyWrapper.getCompanyFrom(sample);
58  Contact companyContact = (Contact) company.getIContact().getContact();
59  parameters.put("company", company);
60  parameters.put("companyContact", companyContact);
61  parameters.put("dateFormat", DateFormats.getDefaultFormat());
62  parameters.put("currencyFormat", DecimalFormats.getStringFormat(fractionDigits));
63  parameters.put("showDescendants", Boolean.TRUE);
64  Contact contractor = (Contact) document.getContract().getIContractor().getContact();
65  parameters.put("contractor", contractor);
66  parameters.put("exportFormat", type);
67  parameters.put("REPORT_RESOURCE_BUNDLE", Application.getBundle(
68  "labels",
69  ((Contact) document.getContract().getIContractor().getContact()).getLocale(),
71  parameters.put("SUBREPORT_DIR", "../_reports/financials/document/");
72  parameters.put("LOGO_IMAGE", ElephantContext.getRealPath("/WEB-INF/_reports/images/doc_logo.png"));
73  String file = "/WEB-INF/_reports/financials/document/" + document.getDocumentDefinition().getName() +
74  (showValues ? "" : "NoValues") + ".jasper";
75  try {
77  lines, parameters, file, "/WEB-INF/_reports/financials/document/Document" +
78  (showValues ? "" : "NoValues") + ".jasper",
79  type, "Financials");
80  } catch (JRException ex) {
81  Logger.getLogger(DocumentReport.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
82  }
83  }
84  }
85 
86 }
static ResourceBundle getBundle(String bundle, Locale locale, String configured)
static String getStringFormat(int fractionDigits)
Set< DocumentLine > getDocumentLines()
Definition: Document.java:180
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
static void print(String title, Collection collection, Map parameters, String jasperFile, String defaultFile, String type, String certificateStore)