BrightSide Workbench Full Report + Source Code
MovementGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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 
19 package org.turro.financials.product;
20 
21 import java.util.Collection;
22 import java.util.Date;
23 import org.amic.util.date.CheckDate;
24 import org.turro.elephant.util.DecimalFormats;
25 import org.turro.financials.entity.Contract;
26 import org.turro.i18n.I_;
27 import org.turro.zkoss.grid.PagingGrid;
28 import org.turro.zkoss.label.LabelExtended;
29 import org.turro.zkoss.label.LabelTypes;
30 import org.zkoss.zk.ui.ext.AfterCompose;
31 import org.zkoss.zul.*;
32 
37 public class MovementGrid extends PagingGrid implements AfterCompose {
38 
39  private IProduct product;
40  private Date from, to;
41  private Contract store;
42 
43  public Date getFrom() {
44  return from;
45  }
46 
47  public void setFrom(Date from) {
48  this.from = from;
49  }
50 
51  public IProduct getIProduct() {
52  return product;
53  }
54 
55  public void setIProduct(IProduct product) {
56  this.product = product;
57  to = new Date();
58  from = new CheckDate(to).addMonths(-1).getDate();
59  }
60 
61  public Date getTo() {
62  return to;
63  }
64 
65  public void setTo(Date to) {
66  this.to = to;
67  }
68 
69  public Contract getStore() {
70  return store;
71  }
72 
73  public void setStore(Contract store) {
74  this.store = store;
75  }
76 
77  public void refreshRows() {
78  getRows(true).getChildren().clear();
79  initiate();
80  }
81 
82  @Override
83  public void afterCompose() {
84  addColumns();
85  initiate();
86  }
87 
88  private void initiate() {
89  if(product != null) {
90  Collection<Movement> movs = product.getMovements(from, to, store);
91  if(movs != null) {
92  double quantity = 0.0d, amount = 0.0d;
93  for(Movement mov : movs) {
94  Row row = new Row();
95  row.setValue(mov);
96  getRows(true).appendChild(row);
97  if(mov.getContract() == null) {
98  row.appendChild(new Label(I_.get(mov.getConcept())));
99  row.appendChild(new Space());
100  row.appendChild(new Space());
101  row.appendChild(new LabelExtended().setDouble(mov.getQuantity()));
102  row.appendChild(new Space());
103  row.appendChild(new Space());
104  row.appendChild(new LabelExtended().setDouble(mov.getAmount()));
105  quantity += mov.getQuantity();
106  amount += mov.getAmount();
107  } else {
108  row.appendChild(new Label(mov.getContract().getFullDescription()));
109  row.appendChild(new LabelExtended().setDate(mov.getDate()));
110  row.appendChild(new LabelExtended().setDouble(mov.getCoefficient()));
111  row.appendChild(new LabelExtended().setDouble(mov.getQuantity()));
112  row.appendChild(new Label(mov.getConcept()));
113  row.appendChild(new LabelExtended().setDouble(mov.getPrice()));
114  row.appendChild(new LabelExtended().setDouble(mov.getAmount()));
115  quantity += mov.getQuantity();
116  amount += mov.getAmount();
117  }
118  }
119  setRowCount(movs.size());
120  Foot foot = createFoot();
121  foot.getChildren().clear();
122  Footer footer = new Footer("");
123  footer.setSpan(3);
124  foot.appendChild(footer);
125  footer = new Footer();
126  footer.setAlign("right");
127  footer.appendChild(LabelTypes.getCaptionLabel(DecimalFormats.format(quantity, "#,##0.000")));
128  foot.appendChild(footer);
129  footer = new Footer("");
130  foot.appendChild(footer);
131  footer = new Footer("");
132  foot.appendChild(footer);
133  footer = new Footer();
134  footer.setAlign("right");
135  footer.appendChild(LabelTypes.getCaptionLabel(DecimalFormats.format(amount, "#,##0.00")));
136  foot.appendChild(footer);
137  }
138  }
139  }
140 
141  private void addColumns() {
142  Columns cols = getColumns(true);
143 
144  Column col = new Column(I_.get("Description"));
145  col.setHflex("2");
146  cols.appendChild(col);
147 
148  col = new Column(I_.get("Date"));
149  col.setWidth("120px");
150  cols.appendChild(col);
151 
152  col = new Column();
153  col.setWidth("30px");
154  cols.appendChild(col);
155 
156  col = new Column(I_.get("Quantity"));
157  col.setWidth("120px");
158  col.setAlign("right");
159  cols.appendChild(col);
160 
161  col = new Column(I_.get("Concept"));
162  col.setHflex("1");
163  cols.appendChild(col);
164 
165  col = new Column(I_.get("Price"));
166  col.setWidth("120px");
167  col.setAlign("right");
168  cols.appendChild(col);
169 
170  col = new Column(I_.get("Amount"));
171  col.setWidth("120px");
172  col.setAlign("right");
173  cols.appendChild(col);
174  }
175 
176 }
static String get(String msg)
Definition: I_.java:41
Columns getColumns(boolean create)
Rows getRows(boolean create)
Collection< Movement > getMovements()