BrightSide Workbench Full Report + Source Code
BatchOfDetailGrid.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.batchof;
19 
20 import java.util.Collection;
21 import org.turro.command.CommandUtil;
22 import org.turro.elephant.util.DateFormats;
23 import org.turro.elephant.util.DecimalFormats;
24 import org.turro.financials.document.action.DocumentActionMenu;
25 import org.turro.financials.entity.BatchOf;
26 import org.turro.financials.entity.Document;
27 import org.turro.financials.menu.FinancialsMenu;
28 import org.turro.i18n.I_;
29 import org.turro.zkoss.grid.PagingGrid;
30 import org.zkoss.zk.ui.event.Event;
31 import org.zkoss.zk.ui.event.EventListener;
32 import org.zkoss.zk.ui.event.Events;
33 import org.zkoss.zul.*;
34 
39 public class BatchOfDetailGrid extends PagingGrid {
40 
41  private BatchOf batchOf;
42  private DocumentActionMenu dam;
43 
45  this.batchOf = batchOf;
46  this.dam = dam;
47  addColumns();
48  addRows();
49  }
50 
51  private void addRows() {
52  Collection<Document> list = batchOf.getDocuments();
53 
54  Rows rows = new Rows();
55  appendChild(rows);
56 
57  for(final Document doc : list) {
58  Row row = new Row();
59  rows.appendChild(row);
60  if(doc.isDraft()) {
61  row.setSclass("draft");
62  }
63  row.appendChild(new Label(doc.getId() + ""));
64  row.appendChild(new Label(DateFormats.format(doc.getReceiptDate(), true)));
65  row.appendChild(new Label(DateFormats.format(doc.getDocumentDate(), true)));
66  row.appendChild(new Label(doc.getDocumentNumber()));
67  Vlayout vbox = new Vlayout();
68  A b = new A(
69  doc.getDocumentDefinition().getName() +
70  (doc.getForcedView() == null ? "" : " (" + doc.getForcedView().getName() + ")"));
71  b.setImage("/_zul/images/document.png");
72  b.addEventListener(Events.ON_CLICK, new EventListener() {
73  @Override
74  public void onEvent(Event event) throws Exception {
75  FinancialsMenu.showDocument(doc.getId());
76  }
77  });
78  b.setContext(dam);
79  b.setAttribute("document", doc);
80  vbox.appendChild(b);
81  vbox.appendChild(CommandUtil.getLinkOrSpace(doc.getContract()));
82  row.appendChild(vbox);
83  row.appendChild(new Label(DecimalFormats.format(doc.getTotalAmount(),
84  DecimalFormats.getStringFormat(doc.getCurrency().getDefaultFractionDigits()))));
85  }
86 
87  setRowCount(list.size());
88  }
89 
90  private void addColumns() {
91  Columns cols = getColumns(true);
92  appendChild(cols);
93 
94  Column col = new Column("#", null, "40px");
95  cols.appendChild(col);
96 
97  col = new Column(I_.get("Receipt/Issue"), null, "120px");
98  cols.appendChild(col);
99 
100  col = new Column(I_.get("Date"), null, "90px");
101  cols.appendChild(col);
102 
103  col = new Column(I_.get("Number"), null, "180px");
104  cols.appendChild(col);
105 
106  col = new Column(I_.get("Document"));
107  cols.appendChild(col);
108 
109  col = new Column(I_.get("Amount"), null, "120px");
110  col.setAlign("right");
111  cols.appendChild(col);
112  }
113 
114 }
BatchOfDetailGrid(BatchOf batchOf, DocumentActionMenu dam)
Set< Document > getDocuments()
Definition: BatchOf.java:67
Columns getColumns(boolean create)