BrightSide Workbench Full Report + Source Code
DocumentSummaryGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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 
19 package org.turro.financials.document;
20 
21 import java.util.Iterator;
22 import org.turro.elephant.util.DecimalFormats;
23 import org.turro.financials.entity.Document;
24 import org.turro.financials.model.document.AmountRetained;
25 import org.turro.financials.model.document.AmountTaxable;
26 import org.turro.financials.model.document.DocumentAmounts;
27 import org.turro.i18n.I_;
28 import org.turro.zkoss.layout.GridLayout;
29 import org.zkoss.zk.ui.ext.AfterCompose;
30 import org.zkoss.zul.Auxhead;
31 import org.zkoss.zul.Auxheader;
32 
37 public class DocumentSummaryGrid extends GridLayout implements AfterCompose {
38 
39  private Document document;
40 
42  }
43 
44  public void setDocument(Document document) {
45  this.document = document;
46  updateSummary();
47  }
48 
49  public void updateSummary() {
50  clearRows();
51  DocumentAmounts da = new DocumentAmounts(document);
52  Iterator<AmountTaxable> iat = da.getTaxables().iterator();
53  Iterator<AmountRetained> iar = da.getRetentions().iterator();
54  boolean keepOn = true, totalDone = false;
55  boolean hasReq = da.hasReq();
56  String pattern = DecimalFormats.getStringFormat(da.getCurrency().getDefaultFractionDigits()),
57  patternPC = "#0.#";
58  while(keepOn) {
59  if(iat.hasNext()) {
60  AmountTaxable at = iat.next();
61  if(hasReq) {
63  DecimalFormats.format(at.getTax(), patternPC) + "% (" +
64  DecimalFormats.format(at.getReq(), patternPC) + "%)"
65  );
66  } else {
67  addBoldValue(DecimalFormats.format(at.getTax(), patternPC) + "%");
68  }
69  addValue(DecimalFormats.format(at.getAmount(), pattern));
70  addValue(DecimalFormats.format(at.getDiscount(), pattern));
72  if(hasReq) {
74  DecimalFormats.format(at.getTaxRealAmount(), pattern) + "(" +
75  DecimalFormats.format(at.getReqAmount(), pattern) + ")"
76  );
77  } else {
79  }
80  } else {
81  addSpace();
82  addSpace();
83  addSpace();
84  addSpace();
85  addSpace();
86  }
87  if(iar.hasNext()) {
88  AmountRetained ar = iar.next();
89  addBoldValue(DecimalFormats.format(ar.getRetention(), patternPC) + "%");
90  addValue(DecimalFormats.format(ar.getTaxable(), pattern));
92  } else {
93  addSpace();
94  addSpace();
95  addSpace();
96  }
97  if(!totalDone) {
99  totalDone = true;
100  }
101  addRow();
102  keepOn = iat.hasNext() || iar.hasNext();
103  }
104  }
105 
106  @Override
107  public void afterCompose() {
108  Auxhead aux = new Auxhead();
109  appendChild(aux);
110  Auxheader auxh = new Auxheader(I_.get("Tax"));
111  auxh.setColspan(5);
112  auxh.setAlign("center");
113  aux.appendChild(auxh);
114  auxh = new Auxheader(I_.get("% Ret."));
115  auxh.setColspan(3);
116  auxh.setAlign("center");
117  aux.appendChild(auxh);
118  auxh = new Auxheader(document.getDocumentDefinition() != null ?
119  document.getDocumentDefinition().getName() : "");
120  auxh.setColspan(1);
121  auxh.setAlign("center");
122  aux.appendChild(auxh);
123  setColumns("right-1,right-3,right-3,right-3,right-3,right-1,right-3,right-3,right-3");
124  setColCaptions(new String[] {
125  I_.get("Type"),
126  I_.get("Subtotal"),
127  I_.get("Discount"),
128  I_.get("Taxable"),
129  I_.get("Tax amount"),
130  I_.get("Type"),
131  I_.get("Taxable"),
132  I_.get("Retained"),
133  I_.get("Total")
134  });
135  }
136 
137 }
static String format(Number value, String pattern)
static String getStringFormat(int fractionDigits)
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
static String get(String msg)
Definition: I_.java:41
void setColCaptions(String captions)
Definition: GridLayout.java:94
GridLayout addValue(String value)
GridLayout addBoldValue(String value)