BrightSide Workbench Full Report + Source Code
ContractItem.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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.operating;
20 
21 import org.turro.financials.db.FinancialsPU;
22 import org.turro.financials.entity.Contract;
23 import org.turro.jpa.Dao;
24 import org.turro.util.CompareUtil;
25 
30 public class ContractItem implements Comparable<ContractItem> {
31 
32  private long id;
33  private String name;
34  private MonthItemSet months = new MonthItemSet();
35 
36  public ContractItem(long id) {
37  this.id = id;
38  }
39 
40  public long getId() {
41  return id;
42  }
43 
44  public String getName() {
45  return name;
46  }
47 
48  public void setName(String name) {
49  if(name == null) {
50  Dao dao = new FinancialsPU();
51  Contract c = dao.find(Contract.class, id);
52  if(c != null) {
53  name = c.getPartialDescription();
54  }
55  }
56  this.name = name;
57  }
58 
60  return months;
61  }
62 
63  public ValuesSet getValues() {
64  ValuesSet values = new ValuesSet();
65  for(MonthItem mi : getMonths()) {
66  for(ValueItem vi : mi.getMovements().getValues()) {
67  ValueItem acum = values.getItem(vi.getMajor());
68  acum.setName(vi.getName());
69  acum.setValue(acum.getValue() + vi.getValue());
70  }
71  }
72  return values;
73  }
74 
76  ParticipantSet values = new ParticipantSet();
77  for(MonthItem mi : getMonths()) {
78  for(ValueItem vi : mi.getMovements().getParticipants()) {
79  ValueItem acum = values.getItem(vi.getMajor());
80  acum.setName(vi.getName());
81  acum.setValue(acum.getValue() + vi.getValue());
82  }
83  }
84  return values;
85  }
86 
87  @Override
88  public int compareTo(ContractItem o) {
89  return CompareUtil.compare(id, o.id);
90  }
91 
92 }