BrightSide Workbench Full Report + Source Code
FixedAssetsGrid.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.assets;
19 
20 import java.util.Collection;
21 import org.turro.command.CommandUtil;
22 import org.turro.elephant.util.DecimalFormats;
23 import org.turro.financials.assets.filter.FixedAssetFilterGrid;
24 import org.turro.financials.entity.FixedAsset;
25 import org.turro.i18n.I_;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.turro.zkoss.label.LabelTypes;
28 import org.zkoss.zk.ui.ext.AfterCompose;
29 import org.zkoss.zul.*;
30 
35 public class FixedAssetsGrid extends PagingGrid implements AfterCompose {
36 
37  private final FixedAssetFilter filter = new FixedAssetFilter();
38  private FixedAssetFilterGrid filterGrid;
39 
40  public void reload() {
41  if(getRows() != null) {
42  getRows().detach();
43  }
44  if(getFoot()!= null) {
45  getFoot().detach();
46  }
47  addRows();
48  }
49 
50  public void setFilterGrid(FixedAssetFilterGrid filterGrid) {
51  this.filterGrid = filterGrid;
52  }
53 
54  @Override
55  public void afterCompose() {
56  addColumns();
57  }
58 
59  private void addRows() {
60  if(!filterGrid.hasValues()) return;
61 
62  Collection<FixedAsset> list = filter.getAssets(filterGrid.getValues());
63 
64  Rows rows = new Rows();
65  appendChild(rows);
66 
67  double t_investment = 0, t_depreciated = 0;
68 
69  for(final FixedAsset fa : list) {
71  Row row = new Row();
72  rows.appendChild(row);
73  if(fa.isUnsubscribed()) {
74  row.setSclass("invalid");
75  }
76  //addDetail(row, fa);
77  row.appendChild(new Label(fa.getId() + ""));
78  row.appendChild(CommandUtil.getAdapter(fa).setLabel(
79  fa.getName() +
80  " (" + fa.getView().getName() + ")" +
81  " - " + fa.getStore().getFullDescription()
82  ));
83  row.appendChild(new Label(fa.getInvestmentPreference().getName()));
84  double investment = faw.getInvestment(),
85  depreciated = faw.getDepreciated();
86  row.appendChild(new Label(DecimalFormats.format(investment,
87  DecimalFormats.getStringFormat(2))));
88  row.appendChild(new Label(DecimalFormats.format(depreciated,
89  DecimalFormats.getStringFormat(2))));
90  row.appendChild(new Label(DecimalFormats.format(investment - depreciated,
91  DecimalFormats.getStringFormat(2))));
92  t_investment += investment;
93  t_depreciated += depreciated;
94  }
95 
96  setRowCount(list.size());
97 
98  Foot foot = createFoot();
99  Footer footer = new Footer("");
100  footer.setSpan(3);
101  foot.appendChild(footer);
102  footer = new Footer();
103  footer.setAlign("right");
104  footer.appendChild(LabelTypes.getCaptionLabel(DecimalFormats.format(t_investment, "#,##0.00")));
105  foot.appendChild(footer);
106  footer = new Footer();
107  footer.setAlign("right");
108  footer.appendChild(LabelTypes.getCaptionLabel(DecimalFormats.format(t_depreciated, "#,##0.00")));
109  foot.appendChild(footer);
110  footer = new Footer();
111  footer.setAlign("right");
112  footer.appendChild(LabelTypes.getCaptionLabel(DecimalFormats.format(t_investment - t_depreciated, "#,##0.00")));
113  foot.appendChild(footer);
114  }
115 
116  private void addColumns() {
117  Columns cols = getColumns(true);
118  appendChild(cols);
119 
120  //addDetailColumn();
121 
122  Column col = new Column("#", null, "40px");
123  cols.appendChild(col);
124 
125  col = new Column(I_.get("Name"));
126  col.setHflex("3");
127  cols.appendChild(col);
128 
129  col = new Column(I_.get("Type"));
130  col.setHflex("1");
131  cols.appendChild(col);
132 
133  col = new Column(I_.get("Investment"), null, "120px");
134  col.setAlign("right");
135  cols.appendChild(col);
136 
137  col = new Column(I_.get("Depreciated"), null, "120px");
138  col.setAlign("right");
139  cols.appendChild(col);
140 
141  col = new Column(I_.get("Pending"), null, "120px");
142  col.setAlign("right");
143  cols.appendChild(col);
144  }
145 
146 // private void addDetail(Row row, FixedAsset fa) {
147 // row.getChildren().clear();
148 // Detail detail = new Detail();
149 // row.appendChild(detail);
150 // Vbox vbox = new Vbox();
151 // vbox.setWidth("100%");
152 // vbox.setStyle("padding:5px");
153 // detail.appendChild(vbox);
154 // detail.setOpen(false);
155 // }
156 
157 }
Collection< FixedAsset > getAssets(List< IFilterValue > values)
void setFilterGrid(FixedAssetFilterGrid filterGrid)
List< IFilterValue > getValues()
Foot getFoot(boolean create)
Columns getColumns(boolean create)
Rows getRows(boolean create)