BrightSide Workbench Full Report + Source Code
org.turro.financials.account.PrintBook Class Reference
Inheritance diagram for org.turro.financials.account.PrintBook:
Collaboration diagram for org.turro.financials.account.PrintBook:

Public Member Functions

 PrintBook ()
 
- Public Member Functions inherited from org.turro.zkoss.print.ReportMenuitem
 ReportMenuitem ()
 
void afterCompose ()
 

Static Public Member Functions

static void doPrint (Page page, Integer year, final String type)
 
static InputStream getExcel (String sheetName, Collection< Long > bookRegisters, Map parameters)
 
static InputStream getExcelForDocuments (String sheetName, Collection< Long > documentIds, Map parameters)
 

Protected Member Functions

void print (String type)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 84 of file PrintBook.java.

Constructor & Destructor Documentation

◆ PrintBook()

org.turro.financials.account.PrintBook.PrintBook ( )

Definition at line 88 of file PrintBook.java.

88  {
89  }

Member Function Documentation

◆ doPrint()

static void org.turro.financials.account.PrintBook.doPrint ( Page  page,
Integer  year,
final String  type 
)
static

Definition at line 96 of file PrintBook.java.

96  {
97  final RegisterView formalView = ViewWrapper.getFormalView();
98  Integer startPage = 1;
99  year = new CheckDate().getYear();
100 
101  InputDialog.getInput(
102  Framework.getCurrent().getPage(),
103  I_.get("Books"),
104  new InputField[] {
105  new InputField("From", new CheckDate().setMonth(1).setDay(1).getDate(), null, 0),
106  new InputField("To", new CheckDate().setMonth(12).setDay(31).getDate(), null, 0),
107  new InputField("Start page", startPage, null, 0),
108  new InputField("Book", null, null, 0) {
109  @Override
110  protected HtmlBasedComponent createEditor() {
111  BookListbox bl = new BookListbox();
112  bl.setMold("select");
113  return bl;
114  }
115  },
116  new InputField("Export", Boolean.valueOf(false), null, 0)
117  }, new Command() {
118  @Override
119  public Object execute(Context context) {
120  BookDefinition bookDefinition = null;
121  Integer startPage = 1;
122  Date from = null, to = null;
123  Boolean export = false;
124  InputField[] fields = (InputField[]) context.get("fields");
125  if(fields.length > 0) {
126  for(InputField f : fields) {
127  if("From".equals(f.getLabel())) {
128  from = (Date) f.getValue();
129  } else if("To".equals(f.getLabel())) {
130  to = (Date) f.getValue();
131  } else if("Start page".equals(f.getLabel())) {
132  startPage = (Integer) f.getValue() - 1;
133  } else if("Book".equals(f.getLabel())) {
134  bookDefinition = (BookDefinition) f.getValue();
135  } else if("Export".equals(f.getLabel())) {
136  export = (Boolean) f.getValue();
137  }
138  }
139  if(from != null && to != null) {
140  if(bookDefinition.getId() == 4) {
141  Collection<Long> lines = getDocuments(formalView, from, to);
142  if(lines != null && lines.size() > 0) {
143  Map parameters = new HashMap();
144  int fractionDigits = CompanyWrapper.getCompanyCurrency().getDefaultFractionDigits();
145  Company company = CompanyWrapper.getDefaultCompany();
146  Contact companyContact = (Contact) company.getIContact().getContact();
147  parameters.put("labels", Application.getStringMap());
148  parameters.put("i_", I_.api());
149  parameters.put("i", I_.map());
150  parameters.put("k", I_.byKeyMap());
151  parameters.put("bookDef", bookDefinition);
152  parameters.put("majors", getMajorBook(bookDefinition));
153  parameters.put("title", I_.get("Book") + ": " + bookDefinition.getDescription());
154  parameters.put("company", company);
155  parameters.put("companyContact", companyContact);
156  parameters.put("dateFormat", DateFormats.getDefaultFormat());
157  parameters.put("currencyFormat", DecimalFormats.getStringFormat(fractionDigits));
158  parameters.put("exportFormat", type);
159  parameters.put("from", from);
160  parameters.put("to", to);
161  if(export) {
162  String name = ElephantContext.getSiteName() + "_Book" + bookDefinition.getDescription() + ".xls";
163  Filedownload.save(getExcelForDocuments(name, lines, parameters), new MimetypesFileTypeMap().getContentType(name), name);
164  } else {
165 // parameters.put("startPage", startPage);
166 // parameters.put("SUBREPORT_DIR", "../_reports/financials/accounting/");
167 // String file = "/WEB-INF/_reports/financials/accounting/PrintBookDocuments.jasper";
168 // OnDemandBeanCollection collection = new OnDemandBeanCollection(lines) {
169 // @Override
170 // protected Object getRealBean(Object bean) {
171 // return new FinancialsPU().find(BookRegister.class, (Long) bean);
172 // }
173 // };
174 // try {
175 // ReportPrint.print(I_.get("Books"),
176 // collection, parameters, file, null,
177 // type, null);
178 // } catch (JRException ex) {
179 // Logger.getLogger(PrintBook.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
180 // }
181  }
182  }
183 
184 
185  } else {
186  Collection<Long> lines = getBookRegisters(formalView, from, to, bookDefinition);
187  if(lines != null && lines.size() > 0) {
188  Map parameters = new HashMap();
189  int fractionDigits = CompanyWrapper.getCompanyCurrency().getDefaultFractionDigits();
190  Company company = CompanyWrapper.getDefaultCompany();
191  Contact companyContact = (Contact) company.getIContact().getContact();
192  parameters.put("labels", Application.getStringMap());
193  parameters.put("i_", I_.api());
194  parameters.put("i", I_.map());
195  parameters.put("k", I_.byKeyMap());
196  parameters.put("bookDef", bookDefinition);
197  parameters.put("majors", getMajorBook(bookDefinition));
198  parameters.put("title", I_.get("Book") + ": " + bookDefinition.getDescription());
199  parameters.put("company", company);
200  parameters.put("companyContact", companyContact);
201  parameters.put("dateFormat", DateFormats.getDefaultFormat());
202  parameters.put("currencyFormat", DecimalFormats.getStringFormat(fractionDigits));
203  parameters.put("exportFormat", type);
204  parameters.put("from", from);
205  parameters.put("to", to);
206  if(export) {
207  String name = ElephantContext.getSiteName() + "_Book" + bookDefinition.getDescription() + ".xls";
208  Filedownload.save(getExcel(name, lines, parameters), new MimetypesFileTypeMap().getContentType(name), name);
209  } else {
210  parameters.put("startPage", startPage);
211  parameters.put("SUBREPORT_DIR", "../_reports/financials/accounting/");
212  String file = "/WEB-INF/_reports/financials/accounting/PrintBookDocuments.jasper";
213  OnDemandBeanCollection collection = new OnDemandBeanCollection(lines) {
214  @Override
215  protected Object getRealBean(Object bean) {
216  return new FinancialsPU().find(BookRegister.class, (Long) bean);
217  }
218  };
219  try {
220  ReportPrint.print(I_.get("Books"),
221  collection, parameters, file, null,
222  type, null);
223  } catch (JRException ex) {
224  Logger.getLogger(PrintBook.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
225  }
226  }
227  }
228  }
229  }
230  }
231  return null;
232  }
233  });
234  }
static InputStream getExcel(String sheetName, Collection< Long > bookRegisters, Map parameters)
Definition: PrintBook.java:284
static InputStream getExcelForDocuments(String sheetName, Collection< Long > documentIds, Map parameters)
Definition: PrintBook.java:371
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getExcel()

static InputStream org.turro.financials.account.PrintBook.getExcel ( String  sheetName,
Collection< Long >  bookRegisters,
Map  parameters 
)
static

Definition at line 284 of file PrintBook.java.

284  {
285  try {
286  ByteArrayOutputStream baos = new ByteArrayOutputStream();
287  WritableWorkbook ww = Workbook.createWorkbook(baos);
288  WritableSheet ws = ww.createSheet(sheetName, 0);
289  writeSheet(ws, bookRegisters, parameters);
290  ww.write();
291  ww.close();
292  baos.close();
293  return new ByteArrayInputStream(baos.toByteArray());
294  } catch (WriteException | IOException ex) {
295  Logger.getLogger(ExportQuery.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
296  }
297  return null;
298  }
Here is the call graph for this function:

◆ getExcelForDocuments()

static InputStream org.turro.financials.account.PrintBook.getExcelForDocuments ( String  sheetName,
Collection< Long >  documentIds,
Map  parameters 
)
static

Definition at line 371 of file PrintBook.java.

371  {
372  try {
373  ByteArrayOutputStream baos = new ByteArrayOutputStream();
374  WritableWorkbook ww = Workbook.createWorkbook(baos);
375  WritableSheet ws = ww.createSheet(sheetName, 0);
376  writeSheetForDocuments(ws, documentIds, parameters);
377  ww.write();
378  ww.close();
379  baos.close();
380  return new ByteArrayInputStream(baos.toByteArray());
381  } catch (WriteException | IOException ex) {
382  Logger.getLogger(ExportQuery.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
383  }
384  return null;
385  }
Here is the call graph for this function:

◆ print()

void org.turro.financials.account.PrintBook.print ( String  type)
protected

Reimplemented from org.turro.zkoss.print.ReportMenuitem.

Definition at line 92 of file PrintBook.java.

92  {
93  doPrint(getPage(), year, type);
94  }
static void doPrint(Page page, Integer year, final String type)
Definition: PrintBook.java:96
Here is the call graph for this function:

The documentation for this class was generated from the following file: