BrightSide Workbench Full Report + Source Code
PortfolioFilterGrid.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.portfolio.filter;
19 
20 import org.turro.contacts.Contact;
21 import org.turro.contacts.util.ContactCombobox;
22 import org.turro.elephant.db.WhereClause;
23 import org.turro.financials.book.BookListbox;
24 import org.turro.financials.contract.ContractCombobox;
25 import org.turro.financials.contract.ContractDefinitionCombobox;
26 import org.turro.financials.document.DocumentDefinitionCombobox;
27 import org.turro.financials.portfolio.RelationMode;
28 import org.turro.financials.view.ViewListbox;
29 import org.turro.zkoss.filter.FilterField;
30 import org.turro.zkoss.filter.FilterFieldOperator;
31 import org.turro.zkoss.filter.FilterGrid;
32 import org.zkoss.zk.ui.HtmlBasedComponent;
33 
38 public class PortfolioFilterGrid extends FilterGrid {
39 
41  super();
42  addField(new FilterField("Document model") {
43  @Override
44  protected HtmlBasedComponent createEditor() {
45  return new DocumentDefinitionCombobox();
46  }
47  @Override
48  public void addConstraint(WhereClause wc) {
49  RelationMode mode = (RelationMode) wc.getAttributes().get("mode");
50  if(mode.equals(RelationMode.RELATE_FORWARD)) {
51  doAddConstraint(wc, "dw.descendant");
52  } else if(mode.equals(RelationMode.RELATE_BACKWARD)) {
53  doAddConstraint(wc, "dw.ancestor");
54  }
55  }
56  });
58  @Override
59  public void addConstraint(WhereClause wc) {
60  doAddConstraint(wc, "doc.documentNumber");
61  }
62  });
63  addField(new FilterField("Date", new java.util.Date(new java.util.Date().getTime() - (1L * 30L * 24L * 60L * 60L * 1000L))) {
64  @Override
65  public void addConstraint(WhereClause wc) {
66  doAddConstraint(wc, "doc.documentDate");
67  }
68  });
69  addField(new FilterField("Receipt/Issue", new java.util.Date(new java.util.Date().getTime() - (1L * 30L * 24L * 60L * 60L * 1000L))) {
70  @Override
71  public void addConstraint(WhereClause wc) {
72  doAddConstraint(wc, "doc.receiptDate");
73  }
74  });
75  addField(new FilterField("Contract") {
76  @Override
77  protected HtmlBasedComponent createEditor() {
78  return new ContractCombobox();
79  }
80  @Override
81  public void addConstraint(WhereClause wc) {
82  doAddConstraint(wc, "doc.contract");
83  }
84  });
85  addField(new FilterField("Contact") {
86  @Override
87  protected HtmlBasedComponent createEditor() {
88  return new ContactCombobox();
89  }
90  @Override
91  protected Object getEditorValue() {
92  Contact c = ((ContactCombobox) editor).getContact();
93  return c == null ? null : c.getId();
94  }
95  @Override
96  public void addConstraint(WhereClause wc) {
97  doAddConstraint(wc, "doc.contract.contractor");
98  }
99  });
100  addField(new FilterField("View") {
101  @Override
102  protected HtmlBasedComponent createEditor() {
103  ViewListbox vl = new ViewListbox();
104  vl.setMold("select");
105  vl.setAllowNull(true);
106  return vl;
107  }
108  @Override
109  public void addConstraint(WhereClause wc) {
110  doAddConstraint(wc, "ifnull(doc.forcedView, 0)");
111  }
112  });
113  addField(new FilterField("Contract model") {
114  @Override
115  protected HtmlBasedComponent createEditor() {
116  return new ContractDefinitionCombobox();
117  }
118  @Override
119  public void addConstraint(WhereClause wc) {
120  doAddConstraint(wc, "doc.contract.contractDefinition");
121  }
122  });
123  addField(new FilterField("Draft", true) {
124  @Override
125  public void addConstraint(WhereClause wc) {
126  doAddConstraint(wc, "doc.draft");
127  }
128  });
129  addField(new FilterField("Amount", 0.0) {
130  @Override
131  public void addConstraint(WhereClause wc) {
132  doAddSubqueryConstraint(wc, "doc.documentLines", "price");
133  }
134  });
135  addField(new FilterField("Quantity", 0.0) {
136  @Override
137  public void addConstraint(WhereClause wc) {
138  doAddSubqueryConstraint(wc, "doc.documentLines", "quantity");
139  }
140  });
141  addField(new FilterField("Store") {
142  @Override
143  protected HtmlBasedComponent createEditor() {
144  return new ContractCombobox();
145  }
146  @Override
147  public void addConstraint(WhereClause wc) {
148  doAddSubqueryConstraint(wc, "doc.documentLines", "store");
149  }
150  });
151  addField(new FilterField("Concept", "") {
152  @Override
153  public void addConstraint(WhereClause wc) {
154  doAddSubqueryConstraint(wc, "doc.documentLines", "concept");
155  }
156  });
157  addField(new FilterField("Book") {
158  @Override
159  protected HtmlBasedComponent createEditor() {
160  BookListbox bl = new BookListbox();
161  bl.setMold("select");
162  bl.setAllowNull(true);
163  return bl;
164  }
165  @Override
166  public void addConstraint(WhereClause wc) {
167  doAddSubqueryConstraint(wc, new String[] {"doc.registers", "sqx.bookRegisters"}, "bookDefinition");
168  }
169  });
170  addField(new FilterField("Book entry", 0L) {
171  @Override
172  public void addConstraint(WhereClause wc) {
173  doAddSubqueryConstraint(wc, new String[] {"doc.registers", "sqx.bookRegisters"}, "bookOrder");
174  }
175  });
176  if(!loadPreferences(this.getClass().getName()+"_filter")) {
177  addCurrentField("Document model");
178  }
179  }
180 
181 }
Map< String, Object > getAttributes()
FilterField addField(FilterField filterField)
Definition: FilterGrid.java:62