BrightSide Workbench Full Report + Source Code
m111/ModelGrid.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.treasury.m111;
19 
20 import java.text.NumberFormat;
21 import java.util.Date;
22 import org.turro.elephant.util.DecimalFormats;
23 import org.turro.financials.model.business.CompanyWrapper;
24 import org.turro.i18n.I_;
25 import org.turro.zkoss.grid.GroupExtended;
26 import org.turro.zkoss.layout.GridLayout;
27 import org.zkoss.zul.Groupfoot;
28 import org.zkoss.zul.Label;
29 import org.zkoss.zul.Space;
30 
35 public class ModelGrid extends GridLayout {
36 
37  private ModelSet modelSet;
38  private Date fromDate, toDate;
39 
40  public void setFromDate(Date fromDate) {
41  this.fromDate = fromDate;
42  }
43 
44  public void setToDate(Date toDate) {
45  this.toDate = toDate;
46  }
47 
48  public void refresh() {
49  modelSet = new ModelSet(fromDate, toDate);
50  getChildren().clear();
51  setColumns("1,right-300px,right-100px,right-300px");
52  setColCaptions(new String[] {
53  I_.get("Name"),
54  I_.get("Amount"),
55  I_.get("Percent"),
56  I_.get("% Ret.")
57  });
58  compose();
59  }
60 
61  private void compose() {
62  getRows(true);
63  NumberFormat currencyFormatter = CompanyWrapper.getCurrencyFormatter();
64  ModelType currentType = null;
65  ModelEntry previous = null;
66  double taxable = 0.0, retention = 0.0;
67  long contractCount = 0;
68  for(ModelEntry me : modelSet) {
69  if(currentType == null || me.getType().getOrder() != currentType.getOrder()) {
70  if(currentType != null) {
71  Groupfoot gf = new Groupfoot();
72  gf.appendChild(new Label(contractCount + " " + I_.get("Contracts")));
73  gf.appendChild(new Label(currencyFormatter.format(taxable)));
74  gf.appendChild(new Space());
75  gf.appendChild(new Label(currencyFormatter.format(retention)));
76  getRows().appendChild(gf);
77  taxable = 0.0;
78  retention = 0.0;
79  contractCount = 0;
80  }
81  GroupExtended ge = new GroupExtended(I_.byKey(me.getType().toString()));
82  ge.setOpen(false);
83  getRows().appendChild(ge);
84  currentType = me.getType();
85  }
86  for(EntryContract ec : me.getContracts().values()) {
87  addRow();
88  addCaption(ec.getContractName() + " (" + ec.getDocuments().size() + " " + I_.get("Documents") + ")");
89  addComponent(new Label(currencyFormatter.format(ec.getTaxable())));
90  addComponent(new Label(DecimalFormats.format(me.getPerCent())));
91  addComponent(new Label(currencyFormatter.format(ec.getRetention())));
92  }
93  taxable += me.getTaxable();
94  retention += me.getRetention();
95  contractCount += me.getContracts().size();
96  previous = me;
97  }
98  if(previous != null) {
99  Groupfoot gf = new Groupfoot();
100  gf.appendChild(new Label(contractCount + " " + I_.get("Contracts")));
101  gf.appendChild(new Label(currencyFormatter.format(taxable)));
102  gf.appendChild(new Space());
103  gf.appendChild(new Label(currencyFormatter.format(retention)));
104  getRows().appendChild(gf);
105  }
106  }
107 
108 }
static String get(String msg)
Definition: I_.java:41
void setColCaptions(String captions)
Definition: GridLayout.java:94
GridLayout addComponent(HtmlBasedComponent comp)
Rows getRows(boolean create)
GridLayout addCaption(String label)