BrightSide Workbench Full Report + Source Code
DocumentByContractVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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 
19 package org.turro.financials.model.document.contract;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.Date;
25 import java.util.List;
26 import org.amic.util.date.CheckDate;
27 import org.turro.auth.Authentication;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.financials.db.FinancialsPU;
30 import org.turro.financials.entity.Contract;
31 import org.turro.financials.entity.ContractInterventionType;
32 import org.turro.i18n.I_;
33 import org.turro.plugin.contacts.IContact;
34 import org.zkoss.bind.annotation.Command;
35 import org.zkoss.bind.annotation.NotifyChange;
36 
41 public class DocumentByContractVM {
42 
43  private DocumentByContractList documents;
44  private Contract contract;
45  private Date from, to;
46 
48  from = new CheckDate().addMonths(-6).getDate();
49  to = new Date();
50  }
51 
52  public Contract getContract() {
53  return contract;
54  }
55 
56  public void setContract(Contract contract) {
57  this.contract = contract;
58  }
59 
60  public Date getFrom() {
61  return from;
62  }
63 
64  public void setFrom(Date from) {
65  this.from = from;
66  }
67 
68  public Date getTo() {
69  return to;
70  }
71 
72  public void setTo(Date to) {
73  this.to = to;
74  }
75 
76  @NotifyChange("model")
77  @Command("update")
78  public void update() {}
79 
80  public List<DocumentPortfolio> getModel() {
81  if(contract != null && from != null && to != null) {
82  documents = new DocumentByContractList();
83  ContractPortfolioList cpl = new ContractPortfolioList(documents, null, contract, from, to);
84  return new ArrayList(cpl);
85  } else {
86  return Collections.EMPTY_LIST;
87  }
88  }
89 
90  public Collection<Contract> getContractModel() {
92  if(contact != null && contact.isWebUser()) {
93  WhereClause wc = new WhereClause();
94  wc.addClause("select distinct ctc from Contract ctc");
95  wc.addClause("left join ctc.participants par");
96  wc.addClause("where ctc.active = TRUE");
97  wc.addClause("and ctc.contractDefinition.id in (48, 55, 56)");
98  if(!contact.isAdmin()) {
99  wc.addClause("and (ctc.contractor = :contractor");
100  wc.addNamedValue("contractor", contact.getId());
102  if(cit.isShowDocuments()) {
103  wc.addClause("or (par.interventionType = :cit" + cit.toString());
104  wc.addNamedValue("cit" + cit.toString(), cit);
105  wc.addClause("and par.idContact = :con" + cit.toString() + ")");
106  wc.addNamedValue("con" + cit.toString(), contact.getId());
107  }
108  }
109  wc.addClause(")");
110  }
111  wc.addClause("order by ctc.name");
112  return new FinancialsPU().getResultList(wc);
113  } else {
114  return Collections.EMPTY_LIST;
115  }
116  }
117 
118  public String getLabel(String label) {
119  return I_.get(label);
120  }
121 
122 }
void addNamedValue(String name, Object value)
static String get(String msg)
Definition: I_.java:41