BrightSide Workbench Full Report + Source Code
DocumentGrid.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.document;
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.db.FinancialsPU;
25 import org.turro.financials.document.filter.DocumentFilterGrid;
26 import org.turro.financials.entity.Document;
27 import org.turro.i18n.I_;
28 import org.turro.jpa.Dao;
29 import org.turro.jpa.grid.RendererOnDemand;
30 import org.turro.zkoss.grid.PagingGrid;
31 import org.zkoss.zk.ui.ext.AfterCompose;
32 import org.zkoss.zul.*;
33 
38 public class DocumentGrid extends PagingGrid implements AfterCompose {
39 
40  private final DocumentFilter filter = new DocumentFilter();
41  private DocumentFilterGrid filterGrid;
42 
44  return filter;
45  }
46 
47  public void setFilterGrid(DocumentFilterGrid filterGrid) {
48  this.filterGrid = filterGrid;
49  }
50 
51  public void reload() {
52  if(getRows() != null) {
53  getRows().detach();
54  }
55  addRows();
56  }
57 
59  Dao dao = new FinancialsPU();
60  ListModelList<Long> model = (ListModelList) getModel();
61  model.forEach(id -> {
62  Document doc = dao.find(Document.class, id);
63  DocumentReport dr = new DocumentReport();
64  dr.setDocument(doc);
65  dr.setSendToParticipants(true);
66  dr.setAskBeforeSend(false);
67  dr.doPrint();
68  });
69  }
70 
71  public void sendDocumentsToCurrent() {
72  Dao dao = new FinancialsPU();
73  ListModelList<Long> model = (ListModelList) getModel();
74  model.forEach(id -> {
75  Document doc = dao.find(Document.class, id);
76  DocumentReport dr = new DocumentReport();
77  dr.setDocument(doc);
78  dr.setSendToCurrent(true);
79  dr.setAskBeforeSend(false);
80  dr.doPrint();
81  });
82  }
83 
84  @Override
85  public void afterCompose() {
86  addColumns();
87  }
88 
89  private void addRows() {
90  if(!filterGrid.hasValues()) return;
91 
92  Collection list = filter.getDocuments(filterGrid.getValues(), true);
93 
94  setRowRenderer(new RendererOnDemand<Document, Long>(() -> new FinancialsPU()) {
95  @Override
96  protected void renderRow(Row row, final Document doc) {
97  if(doc.isDraft()) {
98  row.setSclass("draft");
99  }
100  row.appendChild(new Label(doc.getId() + ""));
101  row.appendChild(new Label(DateFormats.format(doc.getReceiptDate(), true)));
102  row.appendChild(new Label(DateFormats.format(doc.getDocumentDate(), true)));
103  row.appendChild(new Label(doc.getDocumentNumber()));
104  row.appendChild(CommandUtil.getAdapterOrSpace(doc).setLabel(doc.getDocumentDefinition().getName()));
105  row.appendChild(CommandUtil.getLabelAdapter(doc.getContract()).setSclass("softLabel"));
106  row.appendChild(new Label(DecimalFormats.format(doc.getTotalAmount(),
107  DecimalFormats.getStringFormat(doc.getCurrency().getDefaultFractionDigits()))));
108  }
109  });
110 
111  setModel(new ListModelList(list));
112 
113  setRowCount(list.size());
114  }
115 
116  private void addColumns() {
117  Columns cols = getColumns(true);
118  appendChild(cols);
119 
120  Column col = new Column("#", null, "80px");
121  cols.appendChild(col);
122 
123  col = new Column(I_.get("Receipt/Issue"), null, "120px");
124  cols.appendChild(col);
125 
126  col = new Column(I_.get("Date"), null, "120px");
127  cols.appendChild(col);
128 
129  col = new Column(I_.get("Number"), null, "180px");
130  cols.appendChild(col);
131 
132  col = new Column(I_.get("Document"));
133  col.setHflex("2");
134  cols.appendChild(col);
135 
136  col = new Column(I_.get("Contract"));
137  col.setHflex("3");
138  cols.appendChild(col);
139 
140  col = new Column(I_.get("Amount"), null, "120px");
141  col.setAlign("right");
142  cols.appendChild(col);
143  }
144 
145 }
Collection getDocuments(List< IFilterValue > values, boolean onlyIds)
void setFilterGrid(DocumentFilterGrid filterGrid)
void setSendToCurrent(boolean sendToCurrent)
void setSendToParticipants(boolean sendToParticipants)
void setAskBeforeSend(boolean askBeforeSend)
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
List< IFilterValue > getValues()
Columns getColumns(boolean create)
Rows getRows(boolean create)