18 package org.turro.financials.document.filter;
20 import org.turro.elephant.db.WhereClause;
21 import org.turro.financials.book.BookListbox;
22 import org.turro.financials.contract.ContractCombobox;
23 import org.turro.financials.contract.ContractDefinitionCombobox;
24 import org.turro.financials.document.DocumentDefinitionCombobox;
25 import org.turro.financials.view.ViewListbox;
26 import org.turro.zkoss.filter.FilterField;
27 import org.turro.zkoss.filter.FilterFieldOperator;
28 import org.turro.zkoss.filter.FilterGrid;
29 import org.zkoss.zk.ui.HtmlBasedComponent;
41 public void addConstraint(WhereClause wc) {
42 doAddConstraint(wc,
"doc.documentNumber");
47 public void addConstraint(WhereClause wc) {
48 doAddConstraint(wc,
"doc.id");
51 addField(
new FilterField(
"Date",
new java.util.Date(
new java.util.Date().getTime() - (1L * 30L * 24L * 60L * 60L * 1000L))) {
53 public void addConstraint(WhereClause wc) {
54 doAddConstraint(wc,
"doc.documentDate");
57 addField(
new FilterField(
"Receipt/Issue",
new java.util.Date(
new java.util.Date().getTime() - (1L * 30L * 24L * 60L * 60L * 1000L))) {
59 public void addConstraint(WhereClause wc) {
60 doAddConstraint(wc,
"doc.receiptDate");
63 addField(
new FilterField(
"Contract") {
65 protected HtmlBasedComponent createEditor() {
66 return new ContractCombobox();
69 public void addConstraint(WhereClause wc) {
70 doAddConstraint(wc,
"doc.contract");
73 addField(
new FilterField(
"View") {
75 protected HtmlBasedComponent createEditor() {
76 ViewListbox vl =
new ViewListbox();
78 vl.setAllowNull(
true);
82 public void addConstraint(WhereClause wc) {
83 doAddConstraint(wc,
"ifnull(doc.forcedView, 0)");
86 addField(
new FilterField(
"Contract model") {
88 protected HtmlBasedComponent createEditor() {
89 return new ContractDefinitionCombobox();
92 public void addConstraint(WhereClause wc) {
93 doAddConstraint(wc,
"doc.contract.contractDefinition");
96 addField(
new FilterField(
"Document model") {
98 protected HtmlBasedComponent createEditor() {
99 return new DocumentDefinitionCombobox();
102 public void addConstraint(WhereClause wc) {
103 doAddConstraint(wc,
"doc.documentDefinition");
106 addField(
new FilterField(
"Draft",
true) {
108 public void addConstraint(WhereClause wc) {
109 doAddConstraint(wc,
"doc.draft");
112 addField(
new FilterField(
"Amount", 0.0) {
114 public void addConstraint(WhereClause wc) {
116 if(FilterFieldOperator.FILTER_EQUAL.equals(getOperator())) {
117 wc.addClause(getChain().getOpSQL() +
" (" + getObjectValue() +
" <= ");
119 wc.addClause(
"select sum("+ getAmount() +
") + 0.05 from doc.documentLines as dl");
121 wc.addClause(
"and " + getObjectValue() +
" >= ");
123 wc.addClause(
"select sum(" + getAmount() +
") - 0.05 from doc.documentLines as dl");
125 }
else if(FilterFieldOperator.FILTER_BIG.equals(getOperator())) {
126 wc.addClause(getChain().getOpSQL() +
" (" + getObjectValue() +
" < ");
128 wc.addClause(
"select sum("+ getAmount() +
") from doc.documentLines as dl");
130 }
else if(FilterFieldOperator.FILTER_BIG_OR_EQUAL.equals(getOperator())) {
131 wc.addClause(getChain().getOpSQL() +
" (" + getObjectValue() +
" <= ");
133 wc.addClause(
"select sum("+ getAmount() +
") from doc.documentLines as dl");
135 }
else if(FilterFieldOperator.FILTER_LESS.equals(getOperator())) {
136 wc.addClause(getChain().getOpSQL() +
" (" + getObjectValue() +
" > ");
138 wc.addClause(
"select sum("+ getAmount() +
") from doc.documentLines as dl");
140 }
else if(FilterFieldOperator.FILTER_LESS_OR_EQUAL.equals(getOperator())) {
141 wc.addClause(getChain().getOpSQL() +
" (" + getObjectValue() +
" >= ");
143 wc.addClause(
"select sum("+ getAmount() +
") from doc.documentLines as dl");
145 }
else if(FilterFieldOperator.FILTER_NOT_EQUAL.equals(getOperator())) {
146 wc.addClause(getChain().getOpSQL() +
" (" + getObjectValue() +
" >= ");
148 wc.addClause(
"select sum("+ getAmount() +
") from doc.documentLines as dl");
150 wc.addClause(
"and " + getObjectValue() +
" <= ");
152 wc.addClause(
"select sum(" + getAmount() +
") from doc.documentLines as dl");
157 addField(
new FilterField(
"Quantity", 0.0) {
159 public void addConstraint(WhereClause wc) {
160 doAddSubqueryConstraint(wc,
"doc.documentLines",
"quantity");
163 addField(
new FilterField(
"Store") {
165 protected HtmlBasedComponent createEditor() {
166 return new ContractCombobox();
169 public void addConstraint(WhereClause wc) {
170 doAddSubqueryConstraint(wc,
"doc.documentLines",
"store");
173 addField(
new FilterField(
"Concept",
"") {
175 public void addConstraint(WhereClause wc) {
176 doAddSubqueryConstraint(wc,
"doc.documentLines",
"concept");
179 addField(
new FilterField(
"Book") {
181 protected HtmlBasedComponent createEditor() {
182 BookListbox bl =
new BookListbox();
183 bl.setMold(
"select");
184 bl.setAllowNull(
true);
188 public void addConstraint(WhereClause wc) {
189 doAddSubqueryConstraint(wc,
new String[] {
"doc.registers",
"sqx.bookRegisters"},
"bookDefinition");
192 addField(
new FilterField(
"Book entry", 0L) {
194 public void addConstraint(WhereClause wc) {
195 doAddSubqueryConstraint(wc,
new String[] {
"doc.registers",
"sqx.bookRegisters"},
"bookOrder");
198 if(!loadPreferences(this.getClass().getName()+
"_filter")) {
199 addCurrentField(
"Number");
204 return "case " + field +
" when 0.0 then " + value +
" else ifnull(" + field +
"," + value +
") end";
208 return "(" + getIfNull(
"dl.quantity",
"1.0") +
" * dl.price)";
212 return "((" + getSubtotal() +
" - " + getDiscount() +
") * (" + getIfNull(
"dl.retention",
"0.0") +
" / 100.0))";
216 return "((" + getSubtotal() +
" - dl.discountMoney) * (" + getIfNull(
"dl.discountPerCent",
"0.0") +
" / 100.0) + dl.discountMoney)";
220 return "(" + getSubtotal() +
" - " + getDiscount() +
")";
224 return "(" + getAmount() +
" + " + getRetained() +
") - " + getTaxable();
228 return "(" + getTaxable() +
"* (1.0 + (dl.tax / 100))) - " + getRetained();
String getIfNull(String field, String value)
FilterField addField(FilterField filterField)