18 package org.turro.financials.document.contract;
20 import java.util.Date;
21 import org.amic.util.date.CheckDate;
22 import org.turro.auth.Authentication;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.util.DateFormats;
25 import org.turro.elephant.util.DecimalFormats;
26 import org.turro.financials.entity.Contract;
27 import org.turro.financials.entity.Document;
28 import org.turro.financials.entity.RegisterView;
29 import org.turro.financials.model.document.contract.DocumentByContractList;
30 import org.turro.financials.view.ViewListbox;
31 import org.turro.i18n.I_;
32 import org.turro.plugin.contacts.IContact;
33 import org.turro.zkoss.grid.PagingGrid;
34 import org.turro.zkoss.input.DateboxShort;
35 import org.turro.zkoss.layout.GridLayout;
36 import org.zkoss.zk.ui.event.Event;
37 import org.zkoss.zk.ui.event.EventListener;
38 import org.zkoss.zk.ui.event.Events;
39 import org.zkoss.zk.ui.ext.AfterCompose;
40 import org.zkoss.zul.Button;
41 import org.zkoss.zul.Cell;
42 import org.zkoss.zul.Column;
43 import org.zkoss.zul.Columns;
44 import org.zkoss.zul.Label;
45 import org.zkoss.zul.Row;
46 import org.zkoss.zul.Rows;
47 import org.zkoss.zul.Space;
56 private Button searchButton;
58 private boolean searchBar =
true;
61 private Date from, to;
65 from =
new CheckDate(-1, 1, 1, 0, 0, 0).getDate();
70 this.contact = contact;
74 this.searchBar = searchBar;
77 private void addColumns() {
78 Columns cols =
new Columns();
81 Column col =
new Column(
I_.
get(
"Date"));
83 cols.appendChild(col);
85 col =
new Column(
I_.
get(
"Concept"));
87 cols.appendChild(col);
89 col =
new Column(
I_.
get(
"Invoice"));
90 col.setWidth(
"120px");
91 col.setAlign(
"right");
92 cols.appendChild(col);
94 col =
new Column(
I_.
get(
"Portfolio"));
95 col.setWidth(
"120px");
96 col.setAlign(
"right");
97 cols.appendChild(col);
99 col =
new Column(
I_.
get(
"Settlement"));
100 col.setWidth(
"120px");
101 col.setAlign(
"right");
102 cols.appendChild(col);
104 col =
new Column(
I_.
get(
"Balance"));
105 col.setWidth(
"120px");
106 col.setAlign(
"right");
107 cols.appendChild(col);
110 col.setWidth(
"50px");
111 cols.appendChild(col);
114 private void addRows() {
116 rows.getChildren().clear();
118 if(contract ==
null)
return;
120 DocumentByContractList dbcl =
new DocumentByContractList();
121 dbcl.fillList(view, contract, from, to);
123 double portfolio_balance = 0.0, final_balance = dbcl.getInitialBalance(view, contract, from, to);
126 if(final_balance != 0.0) {
130 rows.appendChild(row);
132 row.appendChild(
new Space());
133 row.appendChild(
new Label(
I_.
get(
"Accumulated")));
134 row.appendChild(
new Space());
135 row.appendChild(
new Space());
137 row.appendChild(
new Space());
140 row.appendChild(
new Space());
143 for(
final Document doc : dbcl) {
145 if(doc.getDocumentDefinition().getId() != 1 &&
146 doc.getDocumentDefinition().getId() != 67 &&
147 doc.getDocumentDefinition().getId() != 2 &&
148 doc.getDocumentDefinition().getId() != 43 &&
149 doc.getDocumentDefinition().getId() != 44 &&
150 doc.getDocumentDefinition().getId() != 6 &&
151 doc.getDocumentDefinition().getId() != 7) {
158 rows.appendChild(row);
160 row.appendChild(
new Label(DateFormats.format(doc.getDocumentDate(),
true)));
162 row.appendChild(
new Label(doc.getDocumentDefinition().getName() +
" " + doc.getDocumentNumber()));
164 double amount = doc.getTotalAmount();
166 if(doc.getDocumentDefinition().getId() == 1 ||
167 doc.getDocumentDefinition().getId() == 67 ||
168 doc.getDocumentDefinition().getId() == 2) {
169 row.appendChild(
new Label(DecimalFormats.format(amount,
170 DecimalFormats.getStringFormat(2))));
171 row.appendChild(
new Cell());
172 portfolio_balance += amount;
175 row.appendChild(
new Cell());
176 final_balance += amount;
177 row.appendChild(
new Label(DecimalFormats.format(final_balance,
178 DecimalFormats.getStringFormat(2))));
179 }
else if(doc.getDocumentDefinition().getId() == 44 ||
180 doc.getDocumentDefinition().getId() == 43) {
181 row.appendChild(
new Cell());
182 row.appendChild(
new Label(DecimalFormats.format(amount,
183 DecimalFormats.getStringFormat(2))));
184 portfolio_balance -= amount;
187 row.appendChild(
new Cell());
188 row.appendChild(
new Label(DecimalFormats.format(final_balance,
189 DecimalFormats.getStringFormat(2))));
190 }
else if(doc.getDocumentDefinition().getId() == 6 ||
191 doc.getDocumentDefinition().getId() == 7) {
192 row.appendChild(
new Cell());
193 row.appendChild(
new Cell());
196 row.appendChild(
new Label(DecimalFormats.format(amount,
197 DecimalFormats.getStringFormat(2))));
198 final_balance -= amount;
199 row.appendChild(
new Label(DecimalFormats.format(final_balance,
200 DecimalFormats.getStringFormat(2))));
203 DocumentReport dr =
new DocumentReport();
205 dr.setShowLabels(
false);
213 private void addSearchBar() {
214 Application app = Application.getApplication();
216 if(toolbar !=
null) getParent().removeChild(toolbar);
218 if(!searchBar)
return;
220 toolbar =
new GridLayout(
"min,1");
221 getParent().insertBefore(toolbar,
this);
222 toolbar.setStyle(
"font-size:11px");
225 if(app.isInRole(
"finan-contract:list")) {
226 final DocumentsByContractCombobox dbc =
new DocumentsByContractCombobox();
228 dbc.addEventListener(Events.ON_CHANGE,
new EventListener() {
230 public void onEvent(Event event)
throws Exception {
231 contract = dbc.getObjectValue();
236 final ContractByInterventionListbox cbi =
new ContractByInterventionListbox();
237 cbi.setContact(Authentication.getIContact());
238 cbi.setMold(
"select");
239 cbi.setAllowNull(
true);
240 cbi.addEventListener(Events.ON_SELECT,
new EventListener() {
242 public void onEvent(Event event)
throws Exception {
243 contract = cbi.getObjectValue();
249 if(app.isInRole(
"finan-view:list")) {
252 final ViewListbox vl =
new ViewListbox();
253 vl.setMold(
"select");
254 vl.setAllowNull(
true);
256 vl.addEventListener(Events.ON_SELECT,
new EventListener() {
258 public void onEvent(Event event)
throws Exception {
259 view = vl.getObjectValue();
266 final DateboxShort fromInput =
new DateboxShort(from);
267 fromInput.addEventListener(Events.ON_CHANGE,
new EventListener() {
269 public void onEvent(Event event)
throws Exception {
270 from = fromInput.getValue();
277 final DateboxShort toInput =
new DateboxShort(to);
278 fromInput.addEventListener(Events.ON_CHANGE,
new EventListener() {
280 public void onEvent(Event event)
throws Exception {
281 to = toInput.getValue();
286 searchButton =
new Button(
288 "/_zul/images/search.png"
290 searchButton.addEventListener(Events.ON_CLICK,
new EventListener() {
292 public void onEvent(Event event)
throws Exception {
DocumentByContractViewerGrid()
void setSearchBar(boolean searchBar)
void setContact(IContact contact)
static String get(String msg)
Rows getRows(boolean create)
void setRowCount(int rows)
GridLayout addComponent(HtmlBasedComponent comp)
GridLayout addCaption(String label)