BrightSide Workbench Full Report + Source Code
FinancialsSheets.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.menu;
19 
20 import java.io.File;
21 import java.io.IOException;
22 import java.util.Date;
23 import java.util.logging.Level;
24 import java.util.logging.Logger;
25 import javax.activation.MimetypesFileTypeMap;
26 import jxl.read.biff.BiffException;
27 import jxl.write.WriteException;
28 import org.turro.command.Command;
29 import org.turro.command.Context;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.financials.entity.RegisterView;
32 import org.turro.financials.model.register.ViewWrapper;
33 import org.turro.financials.sheets.ReportSheet;
34 import org.turro.financials.view.ViewListbox;
35 import org.turro.i18n.I_;
36 import org.turro.zkoss.dialog.InputDialog;
37 import org.turro.zkoss.dialog.InputField;
38 import org.zkoss.zk.ui.Page;
39 import org.zkoss.zul.Filedownload;
40 
45 public class FinancialsSheets {
46 
47  public void exportSheet(Page page) {
48  File dir = new File(ElephantContext.getRealPath("/WEB-INF/_reports/financials/sheets"));
49  InputField iDate = new InputField("Date", new Date(), null, 0);
50  InputField iFile = new InputField("Sheet", dir, "*.xls", 0);
51  ViewListbox vl = new ViewListbox();
52  vl.setMold("select");
53  vl.setAllowNull(true);
54  InputField iView = new InputField("View", vl, ViewWrapper.getFormalView());
56  page, I_.get("Report sheets"),
57  new InputField[] {iDate, iFile, iView},
58  new Command() {
59  @Override
60  public Object execute(Context context) {
61  File file = null;
62  Date date = null;
63  RegisterView view = null;
64  InputField[] fields = (InputField[]) context.get("fields");
65  if(fields.length > 0) {
66  for(InputField f : fields) {
67  if("Date".equals(f.getLabel())) {
68  date = (Date) f.getValue();
69  } else if("Sheet".equals(f.getLabel())) {
70  file = (File) f.getValue();
71  } else if("View".equals(f.getLabel())) {
72  view = (RegisterView) f.getValue();
73  }
74  }
75  try {
76  //File file = new File(Application.getApplication().getRealPath("/WEB-INF/_reports/financials/sheets/ComptesAnuals.xls"));
77  ReportSheet rs = new ReportSheet(file, date, view);
78  Filedownload.save(rs.getExcel(), new MimetypesFileTypeMap().getContentType(file.getName()), file.getName());
79  } catch (IOException | BiffException | WriteException ex) {
80  Logger.getLogger(FinancialsSheets.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
81  }
82  }
83  return null;
84  }
85  });
86  }
87 
88 }
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)