BrightSide Workbench Full Report + Source Code
DocumentLinesListbox.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 java.util.List;
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.DocumentLine;
26 import org.turro.i18n.I_;
27 import org.turro.zkoss.input.CollectionListbox;
28 import org.zkoss.zul.Listfoot;
29 import org.zkoss.zul.Listfooter;
30 import org.zkoss.zul.Listhead;
31 import org.zkoss.zul.Listheader;
32 import org.zkoss.zul.Listitem;
33 
38 public class DocumentLinesListbox extends CollectionListbox<DocumentLine> {
39 
40  private boolean showContract = false,
41  showTotalAmount = false;
42  private DocumentActionMenu dam;
43 
45  }
46 
47  public DocumentLinesListbox(Collection<DocumentLine> collection) {
48  super(collection);
49  }
50 
51  public boolean isShowContract() {
52  return showContract;
53  }
54 
55  public void setShowContract(boolean showContract) {
56  this.showContract = showContract;
57  }
58 
59  public boolean isShowTotalAmount() {
60  return showTotalAmount;
61  }
62 
63  public void setShowTotalAmount(boolean showTotalAmount) {
64  this.showTotalAmount = showTotalAmount;
65  }
66 
67  @Override
68  protected String convertToString(DocumentLine v) {
69  if(v == null) return null;
70 
71  return (showContract ? v.getDocument().getContract().getFullDescription() + SUBITEM_SEPARATOR : "") +
73  DateFormats.format(v.getDocument().getDocumentDate(), true) + SUBITEM_SEPARATOR +
76  (v.getProduct() != null ? v.getProduct().getDescription() + SUBITEM_SEPARATOR : "") +
77  (v.getProductByContractor() != null ? v.getProductByContractor().getProduct().getDescription() + SUBITEM_SEPARATOR : "") +
78  (v.getConcept() != null ? v.getConcept() + SUBITEM_SEPARATOR : "") +
81  }
82 
83  @Override
84  public void afterCompose() {
85  dam = new DocumentActionMenu();
86  getParent().appendChild(dam);
87  addHeaders();
88  super.afterCompose();
89  if(showTotalAmount) {
90  addFooters();
91  }
92  }
93 
94  @Override
95  protected void populateList() {
96  super.populateList();
97  for(Listitem li : (List<Listitem>) getItems()) {
98  li.setContext(dam);
99  li.setAttribute("document", ((DocumentLine) li.getValue()).getDocument());
100  }
101  }
102 
103  private void addHeaders() {
104  if(getListhead() != null) return;
105  Listhead lh = new Listhead();
106  lh.setSizable(true);
107  lh.appendChild(new Listheader(I_.get("Document"), null, "30%"));
108  lh.appendChild(new Listheader(I_.get("Date"), null, "10%"));
109  lh.appendChild(new Listheader(I_.get("Number"), null, "10%"));
110  lh.appendChild(new Listheader(I_.get("Concept"), null, "40%"));
111  lh.appendChild(new Listheader(I_.get("Amount"), null, "10%"));
112  appendChild(lh);
113  }
114 
115  private void addFooters() {
116  Listfoot lh = getListfoot();
117  if(lh == null) {
118  lh = new Listfoot();
119  appendChild(lh);
120  }
121  lh.getChildren().clear();
122  lh.appendChild(new Listfooter());
123  lh.appendChild(new Listfooter());
124  lh.appendChild(new Listfooter());
125  lh.appendChild(new Listfooter(DecimalFormats.format(getTotal())));
126  }
127 
128  private double getTotal() {
129  double total = 0;
130  for(DocumentLine dl : getCollection()) {
131  total += dl.getTaxable();
132  }
133  return total;
134  }
135 
136 }
static final String format(Date d, boolean dateOnly)
static String format(Number value, String pattern)
DocumentLinesListbox(Collection< DocumentLine > collection)
ProductByContractor getProductByContractor()
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
static String get(String msg)
Definition: I_.java:41