BrightSide Workbench Full Report + Source Code
BalanceReport.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.register;
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.command.Command;
27 import org.turro.command.Context;
28 import org.turro.contacts.Contact;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.util.DateFormats;
31 import org.turro.elephant.util.DecimalFormats;
32 import org.turro.financials.entity.Company;
33 import org.turro.financials.model.business.CompanyWrapper;
34 import org.turro.i18n.I_;
35 import org.turro.zkoss.dialog.InputDialog;
36 import org.turro.zkoss.print.ReportPrint;
37 import org.turro.zkoss.print.ReportToolbarbutton;
38 
43 public class BalanceReport extends ReportToolbarbutton {
44 
45  private BalanceFilter filter;
46 
47  public void setFilter(BalanceFilter filter) {
48  this.filter = filter;
49  }
50 
51  @Override
52  protected void print(final String type) {
53  final Collection<AccountRI> ari = filter.getAccountRIs();
55  getPage(), I_.get("Account balance"), "Start page", 1, "####", 0,
56  new Command() {
57  @Override
58  public Object execute(Context context) {
59  Integer startPage = (Integer) context.get("value");
60  if(startPage != null) {
61  if(ari != null && ari.size() > 0) {
62  Map parameters = new HashMap();
64  Contact companyContact = (Contact) company.getIContact().getContact();
65  int fractionDigits = companyContact.getCurrency().getDefaultFractionDigits();
66  parameters.put("company", company);
67  parameters.put("companyContact", companyContact);
68  parameters.put("filter", filter);
69  parameters.put("startPage", startPage - 1);
70  parameters.put("dateFormat", DateFormats.getDefaultFormat());
71  parameters.put("currencyFormat", DecimalFormats.getStringFormat(fractionDigits));
72  parameters.put("exportFormat", type);
73  parameters.put("breakdown", filter.getBreakdown());
74  parameters.put("SUBREPORT_DIR", "../_reports/financials/accounting/");
75  String file = filter.hasTwoGroup() ?
76  "/WEB-INF/_reports/financials/accounting/AccountBalanceGroup.jasper" :
77  "/WEB-INF/_reports/financials/accounting/AccountBalance.jasper";
78  try {
79  ReportPrint.print(I_.get("Account balance"),
80  filter.getAccountRIs(), parameters, file, null, type, null);
81  } catch (JRException ex) {
82  Logger.getLogger(BalanceReport.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
83  }
84  }
85  }
86  return null;
87  }
88  });
89  }
90 
91 }
static String getStringFormat(int fractionDigits)
static String get(String msg)
Definition: I_.java:41
static void getInput(Page page, String title, String label, Object value, String format, int scale, final Command onOk)
static void print(String title, Collection collection, Map parameters, String jasperFile, String defaultFile, String type, String certificateStore)