BrightSide Workbench Full Report + Source Code
ContractByInterventionListbox.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.document.contract;
19 
20 import java.util.Collection;
21 import org.turro.elephant.db.WhereClause;
22 import org.turro.financials.db.FinancialsPU;
23 import org.turro.financials.entity.Contract;
24 import org.turro.financials.entity.ContractInterventionType;
25 import org.turro.plugin.contacts.IContact;
26 import org.turro.zkoss.input.CollectionListbox;
27 
32 public class ContractByInterventionListbox extends CollectionListbox<Contract> {
33 
34  private IContact contact;
35 
36  public void setContact(IContact contact) {
37  this.contact = contact;
38  if(contact != null) {
39  setCollection(getContracts());
40  }
41  }
42 
43  @Override
44  protected String convertToString(Contract v) {
45  return v.getFullDescription();
46  }
47 
48  private Collection<Contract> getContracts() {
49  WhereClause wc = new WhereClause();
50  wc.addClause("select distinct ctc from Contract ctc");
51  wc.addClause("left join ctc.participants par");
52  wc.addClause("where ctc.contractor = :contractor");
53  wc.addNamedValue("contractor", contact.getId());
54  wc.addClause("and ctc.active = TRUE");
55  wc.addClause("and ctc.contractDefinition.id in (48, 55, 56)");
57  if(cit.isShowDocuments()) {
58  wc.addClause("or (par.interventionType = :cit" + cit.toString());
59  wc.addNamedValue("cit" + cit.toString(), cit);
60  wc.addClause("and par.idContact = :con" + cit.toString() + ")");
61  wc.addNamedValue("con" + cit.toString(), contact.getId());
62  }
63  }
64  return new FinancialsPU().getResultList(wc);
65  }
66 }
void addNamedValue(String name, Object value)
void setCollection(Collection< V > collection)