BrightSide Workbench Full Report + Source Code
BatchOfGrid.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.elephant.util.DateFormats;
22 import org.turro.elephant.util.DecimalFormats;
23 import org.turro.financials.document.action.DocumentActionMenu;
24 import org.turro.financials.entity.BatchOf;
25 import org.turro.financials.entity.Document;
26 import org.turro.financials.menu.FinancialsMenu;
27 import org.turro.i18n.I_;
28 import org.turro.zkoss.grid.PagingGrid;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.event.EventListener;
31 import org.zkoss.zk.ui.event.Events;
32 import org.zkoss.zk.ui.ext.AfterCompose;
33 import org.zkoss.zul.A;
34 import org.zkoss.zul.Column;
35 import org.zkoss.zul.Columns;
36 import org.zkoss.zul.Detail;
37 import org.zkoss.zul.Label;
38 import org.zkoss.zul.Row;
39 import org.zkoss.zul.Rows;
40 import org.zkoss.zul.Vbox;
41 
46 public class BatchOfGrid extends PagingGrid implements AfterCompose {
47 
48  private Document document;
49  private DocumentActionMenu dam;
50  private boolean batchMember = false;
51 
52  public boolean isBatchMember() {
53  return batchMember;
54  }
55 
56  public Document getDocument() {
57  return document;
58  }
59 
60  public void setDocument(Document document) {
61  this.document = document;
62  }
63 
64  public void reload() {
65  addRows();
66  }
67 
68  @Override
69  public void afterCompose() {
70  dam = new DocumentActionMenu();
71  getParent().appendChild(dam);
72  addColumns();
73  addRows();
74  }
75 
76  private void addRows() {
77  Collection<BatchOf> list = BatchOf.getFrom(document);
78 
79  Rows rows = getRows(true);
80  rows.getChildren().clear();
81 
82  for(final BatchOf batch : list) {
83  final Document doc = batch.getBatch();
84  Row row = new Row();
85  rows.appendChild(row);
86  if(doc.isDraft()) {
87  row.setSclass("draft");
88  }
89  addDetail(row, batch);
90  row.appendChild(new Label(doc.getId() + ""));
91  row.appendChild(new Label(DateFormats.format(doc.getReceiptDate(), true)));
92  row.appendChild(new Label(DateFormats.format(doc.getDocumentDate(), true)));
93  row.appendChild(new Label(doc.getDocumentNumber()));
94  A b = new A(
96  (doc.getForcedView() == null ? "" : " (" + doc.getForcedView().getName() + ")") +
97  " - " + doc.getContract().getFullDescription());
98  b.setImage("/_zul/images/batchof.png");
99  b.addEventListener(Events.ON_CLICK, new EventListener() {
100  @Override
101  public void onEvent(Event event) throws Exception {
102  FinancialsMenu.showBatchOf(batch.getId());
103  }
104  });
105  b.setContext(dam);
106  b.setAttribute("document", doc);
107  row.appendChild(b);
108  row.appendChild(new Label(DecimalFormats.format(doc.getTotalAmount(),
109  DecimalFormats.getStringFormat(doc.getCurrency().getDefaultFractionDigits()))));
110  }
111 
112  setRowCount(list.size());
113  batchMember = list.size() > 0;
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("Receipt/Issue"), null, "120px");
126  cols.appendChild(col);
127 
128  col = new Column(I_.get("Date"), null, "90px");
129  cols.appendChild(col);
130 
131  col = new Column(I_.get("Number"), null, "180px");
132  cols.appendChild(col);
133 
134  col = new Column(I_.get("Batch of"));
135  cols.appendChild(col);
136 
137  col = new Column(I_.get("Amount"), null, "120px");
138  col.setAlign("right");
139  cols.appendChild(col);
140  }
141 
142  private void addDetail(Row row, BatchOf batch) {
143  row.getChildren().clear();
144  Detail detail = new Detail();
145  row.appendChild(detail);
146  Vbox vbox = new Vbox();
147  vbox.setWidth("100%");
148  vbox.setStyle("padding:5px");
149  detail.appendChild(vbox);
150  BatchOfDetailGrid eg = new BatchOfDetailGrid(batch, dam);
151  vbox.appendChild(eg);
152  detail.setOpen(true);
153  }
154 
155 }
static Collection< BatchOf > getFrom(Document document)
Definition: BatchOf.java:135
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
Columns getColumns(boolean create)
Rows getRows(boolean create)