BrightSide Workbench Full Report + Source Code
bsfinancials-core/src/main/java/org/turro/financials/model/document/DocumentDefinitionWrapper.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.model.document;
19 
20 import java.util.Collection;
21 import java.util.HashSet;
22 import org.turro.financials.db.FinancialsPU;
23 import org.turro.financials.entity.Contract;
24 import org.turro.financials.entity.DocumentDefinition;
25 import org.turro.financials.entity.RelatedContractStore;
26 import org.turro.financials.entity.RelatedStoreDefinition;
27 
33 
35 
37  this.documentDefinition = documentDefinition;
38  }
39 
40  public Collection<Contract> getRelatedStores(Contract contract) {
41  HashSet<Contract> c = new HashSet<Contract>();
42  if(documentDefinition != null) {
43  if(contract != null) {
44  for(RelatedContractStore rcs : contract.getRelatedContractStores()) {
45  if(rcs.getStore() != null && rcs.getDocumentDefinition().getId() == documentDefinition.getId()) {
46  c.add(rcs.getStore());
47  }
48  }
49  }
50  }
51  return c;
52  }
53 
54  public Collection<Contract> getRelatedStores() {
55  if(documentDefinition != null) {
56  StringBuilder sb = new StringBuilder();
58  if(sb.length() > 0) sb.append(",");
59  sb.append(rsd.getRelatedStore().getId());
60  }
61  return new FinancialsPU().getResultList(
62  "select ctc from Contract as ctc " +
63  "where ctc.contractDefinition.id in (" + sb.toString() + ") " +
64  "and ctc.active = TRUE " +
65  "and ctc.stock = TRUE " +
66  "order by ctc.contractDefinition.name, ctc.contractDefinition.id, ctc.id"
67  );
68  }
69  return new HashSet<Contract>();
70  }
71 
72  public static Collection<DocumentDefinition> getDocumentDefinitions() {
73  return new FinancialsPU().getResultList(
74  "select docdef from DocumentDefinition as docdef " +
75  "order by docdef.name"
76  );
77  }
78 
79 }
Set< RelatedContractStore > getRelatedContractStores()
Definition: Contract.java:268