BrightSide Workbench Full Report + Source Code
DocumentAmountsGrid.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.logging.Level;
21 import java.util.logging.Logger;
22 import org.turro.elephant.context.ElephantContext;
23 import org.turro.financials.entity.Document;
24 import org.turro.financials.model.Amount;
25 import org.turro.i18n.I_;
26 import org.turro.zkoss.grid.CollectionGrid;
27 import org.zkoss.zul.Row;
28 
33 public class DocumentAmountsGrid extends CollectionGrid<Amount> {
34 
35  private Document document;
36 
38  super();
39  }
40 
41  public DocumentAmountsGrid(Document document) {
42  super();
43  setDocument(document);
44  }
45 
46  public Document getDocument() {
47  return document;
48  }
49 
50  public void setDocument(Document document) {
51  this.document = document;
52  //setCollection(document.getAmountSet());
53  }
54 
55  public void updateDocument(Document document) {
56  clearTable();
57  setDocument(document);
58  afterCompose();
59  }
60 
61  @Override
62  protected void initiateRow(Row row, Amount value) {
63  row.setValue(value);
64  }
65 
66  @Override
67  protected boolean deleteRow(Row row) {
68  throw new UnsupportedOperationException("Not supported yet.");
69  }
70 
71  @Override
72  protected boolean isValid(Amount v) {
73  return true;
74  }
75 
76  @Override
77  public void afterCompose() {
78  setReadOnly(true);
79  if(document.getDocumentDefinition() != null) {
80  try {
81  addColumns();
82  } catch (ClassNotFoundException ex) {
83  Logger.getLogger(DocumentAmountsGrid.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
84  }
85  }
86  super.afterCompose();
87  }
88 
89  private void addColumns() throws ClassNotFoundException {
90  int fractionDigits = document.getCurrency().getDefaultFractionDigits();
91  addColumn(I_.get("Subtotal"), "double",
92  "subtotal", null, fractionDigits, false, false);
93  addColumn(I_.get("Discount"), "double",
94  "discount", null, fractionDigits, false, false);
95  addColumn(I_.get("Taxable"), "double",
96  "taxable", null, fractionDigits, false, false);
97  addColumn(I_.get("Tax"), "double",
98  "tax", null, 2, false, false);
99  addColumn(I_.get("Tax amount"), "double",
100  "taxValue", null, fractionDigits, false, false);
101  if(document.getContract().isEquivalenceSurcharge()) {
102  addColumn(I_.get("EqSur."), "double",
103  "req", null, 2, false, false);
104  addColumn(I_.get("Tax amount"), "double",
105  "reqValue", null, fractionDigits, false, false);
106  }
107  addColumn(I_.get("Retained"), "double",
108  "retained", null, fractionDigits, false, false);
109  addColumn(I_.get("Amount"), "double",
110  "amount", null, fractionDigits, false, false);
111  }
112 
113 }
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
static String get(String msg)
Definition: I_.java:41
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
void setReadOnly(boolean readOnly)