BrightSide Workbench Full Report + Source Code
assets/DocumentLinesGrid.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.Command;
22 import org.turro.command.Context;
23 import org.turro.elephant.util.DecimalFormats;
24 import org.turro.financials.assets.filter.AssetFilterGrid;
25 import org.turro.financials.entity.DocumentLine;
26 import org.turro.financials.entity.FixedAsset;
27 import org.turro.financials.menu.FinancialsMenu;
28 import org.turro.i18n.I_;
29 import org.turro.zkoss.grid.PagingGrid;
30 import org.turro.zkoss.label.LabelTypes;
31 import org.zkoss.zk.ui.event.Event;
32 import org.zkoss.zk.ui.event.EventListener;
33 import org.zkoss.zk.ui.event.Events;
34 import org.zkoss.zk.ui.ext.AfterCompose;
35 import org.zkoss.zul.*;
36 
41 public class DocumentLinesGrid extends PagingGrid implements AfterCompose {
42 
43  private FixedAsset fixedAsset;
44 
46  return fixedAsset;
47  }
48 
49  public void setFixedAsset(FixedAsset fixedAsset) {
50  this.fixedAsset = fixedAsset;
51  }
52 
53  public void reload() {
54  getRows().detach();
55  addRows();
56  }
57 
58  public void createRelation(FixedAssetWrapper wrapper, AssetFilterGrid filter) {
59  wrapper.loadLines(filter, new Command() {
60  @Override
61  public Object execute(Context context) {
62  reload();
63  return null;
64  }
65  });
66  }
67 
68  @Override
69  public void afterCompose() {
70  addColumns();
71  addRows();
72  }
73 
74  private void addRows() {
75  Collection<DocumentLine> list = fixedAsset.getDocumentLines();
76 
77  Rows rows = new Rows();
78  appendChild(rows);
79 
80  for(final DocumentLine dl : list) {
81  Row row = new Row();
82  rows.appendChild(row);
83 
84  row.appendChild(new Label(dl.getDocument().getId() + ""));
85  A b = new A();
86  b.addEventListener(Events.ON_CLICK, new EventListener() {
87  @Override
88  public void onEvent(Event event) throws Exception {
89  FinancialsMenu.showDocument(dl.getDocument());
90  }
91  });
92  Vlayout vbox = new Vlayout();
93  vbox.appendChild(LabelTypes.getCaptionLabel(dl.getDocument().getContract().getFullDescription()));
94  vbox.appendChild(LabelTypes.getSoftLabel(dl.getDocument().getDocumentString()));
95  b.appendChild(vbox);
96  row.appendChild(b);
97  vbox = new Vlayout();
98  if(dl.getProduct() != null) {
99  vbox.appendChild(LabelTypes.getSoftLabel(dl.getProduct().getProductCodeStr() +
100  " - " + dl.getProduct().getDescription()));
101  }
102  if(dl.getProductByContractor() != null) {
103  vbox.appendChild(LabelTypes.getSoftLabel(dl.getProductByContractor().getProduct().getProductCodeStr() +
104  " - " + dl.getProductByContractor().getProduct().getDescription()));
105  }
106  if(dl.getConcept() != null) {
107  vbox.appendChild(LabelTypes.getSoftLabel(dl.getConcept()));
108  }
109  vbox.appendChild(LabelTypes.getSoftLabel(dl.getStore().getPartialDescription()));
110  row.appendChild(vbox);
111  row.appendChild(new Label(DecimalFormats.format(dl.getTaxable(),
112  DecimalFormats.getStringFormat(dl.getDocument().getCurrency().getDefaultFractionDigits()))));
113  Checkbox cb = new Checkbox();
114  cb.setChecked(false);
115  row.appendChild(cb);
116  row.setAttribute("cb", cb);
117  row.setValue(dl);
118  }
119 
120  setRowCount(list.size());
121  }
122 
123  private void addColumns() {
124  Columns cols = getColumns(true);
125  appendChild(cols);
126 
127  Column col = new Column("#", null, "60px");
128  cols.appendChild(col);
129 
130  col = new Column(I_.get("Document"), null, "50%");
131  cols.appendChild(col);
132 
133  col = new Column(I_.get("Concept"), null, "50%");
134  cols.appendChild(col);
135 
136  col = new Column(I_.get("Amount"), null, "120px");
137  col.setAlign("right");
138  cols.appendChild(col);
139 
140  col = new Column("", "/_zul/images/edit-delete.png", "30px");
141  cols.appendChild(col);
142  }
143 
144 }
void createRelation(FixedAssetWrapper wrapper, AssetFilterGrid filter)
Set< DocumentLine > getDocumentLines()
Definition: FixedAsset.java:96
Columns getColumns(boolean create)
Rows getRows(boolean create)