BrightSide Workbench Full Report + Source Code
SettlementGrid.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.treasury.settlement;
19 
20 import java.util.Date;
21 import org.turro.elephant.util.DecimalFormats;
22 import org.turro.financials.entity.Contract;
23 import org.turro.i18n.I_;
24 import org.turro.zkoss.grid.GroupExtended;
25 import org.turro.zkoss.label.MultilineLabel;
26 import org.turro.zkoss.layout.GridLayout;
27 import org.zkoss.zk.ui.event.Event;
28 import org.zkoss.zk.ui.event.EventListener;
29 import org.zkoss.zk.ui.event.Events;
30 import org.zkoss.zul.Checkbox;
31 import org.zkoss.zul.Groupfoot;
32 import org.zkoss.zul.Label;
33 import org.zkoss.zul.Space;
34 
39 public class SettlementGrid extends GridLayout {
40 
41  private SettlementSet set;
42  private Label debtorLabel, creditorLabel;
43 
44  public SettlementGrid() {
45  super("min,1,right-min,min");
46  setColCaptions(new String[] {
47  I_.get("Account"),
48  I_.get("Name"),
49  I_.get("Amount"),
50  "",
51  });
52  }
53 
54  public void setDate(Date date) {
55  Date prevSettDate = set != null ? set.getSettlementDate() : null;
56  set = new SettlementSet();
57  set.setDate(date);
58  set.setSettlementDate(prevSettDate);
59  compose();
60  }
61 
62  public void setSettlementDate(Date date) {
63  set.setSettlementDate(date);
64  }
65 
66  public void doRegister(Contract store) {
67  set.generateRegister(store);
68  }
69 
70  private void compose() {
71  getRows(true).getChildren().clear();
72  int stage = -1;
73  double subtotal = 0.0, total = 0.0;
74  boolean addToGrid = false;
75  for(final SettlementEntry se : set) {
76  if(stage < 0 && se.isDebtor()) {
77  GroupExtended ge = new GroupExtended(I_.get("Debtor"));
78  getRows().appendChild(ge);
79  stage = 0;
80  subtotal = 0.0;
81  } else if(stage < 1 && (se.isCreditorVAT() || se.isCreditorIRPF())) {
82  if(stage == 0) {
83  Groupfoot gf = new Groupfoot();
84  gf.appendChild(new Space());
85  gf.appendChild(new Label(I_.get("Debtor")));
86  debtorLabel = new Label();
87  gf.appendChild(debtorLabel);
88  gf.appendChild(new Space());
89  getRows().appendChild(gf);
90  }
91  GroupExtended ge = new GroupExtended(I_.get("Creditor"));
92  getRows().appendChild(ge);
93  stage = 1;
94  total = subtotal;
95  subtotal = 0.0;
96  }
97  if(se.isDebtor() || se.isCreditorIRPF() || se.isCreditorVAT()) {
98  addRow();
99  addCaption(se.getAccount());
100  addCaption(se.getName());
101  addComponent(new Label(DecimalFormats.format(se.getAmount())));
102  final Checkbox process = new Checkbox();
103  process.setChecked(se.isChecked());
104  process.addEventListener(Events.ON_CHECK, new EventListener() {
105  @Override
106  public void onEvent(Event event) throws Exception {
107  se.setChecked(process.isChecked());
108  updateAmmounts();
109  }
110  });
111  addComponent(process);
112  subtotal += se.getAmount();
113  }
114  }
115  if(!getRows().getChildren().isEmpty()) {
116  Groupfoot gf = new Groupfoot();
117  gf.setStyle("padding:5px;");
118  gf.appendChild(new Space());
119  gf.appendChild(new MultilineLabel(I_.get("Creditor") + "\n\n" + I_.get("Total")));
120  creditorLabel = new MultilineLabel();
121  gf.appendChild(creditorLabel);
122  gf.appendChild(new Space());
123  getRows().appendChild(gf);
124  }
125  updateAmmounts();
126  }
127 
128  private void updateAmmounts() {
129  double debtor = set.getDebtorTotal(),
130  creditor = set.getCreditorTotal();
131  if(debtorLabel != null) {
132  debtorLabel.setValue(DecimalFormats.format(debtor));
133  }
134  if(creditorLabel != null) {
135  creditorLabel.setValue(DecimalFormats.format(creditor) + "\n\n" + DecimalFormats.format(creditor - debtor));
136  }
137  }
138 }
static String get(String msg)
Definition: I_.java:41
void setColCaptions(String captions)
Definition: GridLayout.java:94
GridLayout addComponent(HtmlBasedComponent comp)
Rows getRows(boolean create)
GridLayout addCaption(String label)