1
2 package com.pnpconsult.zeiterfassung.model;
3
4 import java.util.Date;
5 import java.util.HashSet;
6 import java.util.Set;
7 import java.util.SortedSet;
8 import java.util.TreeSet;
9
10 import org.apache.commons.lang.builder.HashCodeBuilder;
11
12 import com.pnpconsult.zeiterfassung.util.Description;
13
14 /***
15 * @author <a href="mailto:powerpete@users.sf.net">M. Petersen</a>
16 * @version $Id: Project.java,v 1.15 2004/06/24 20:54:19 powerpete Exp $
17 *
18 * @hibernate.class table="project"
19 */
20 public class Project extends ArchivableObject
21 {
22 private long id = -1;
23 private String name;
24 private String number;
25 private float[] taxValue = new float[3];
26 private Date[] taxDate = new Date[3];
27 private String currency;
28 private SortedSet userProjects = new TreeSet();
29 private Set userEntries = new HashSet();
30 private Set bills = new HashSet();
31 private Customer customer;
32
33 /***
34 * @return Returns the id.
35 *
36 * @hibernate.id generator-class="identity" unsaved-value="-1"
37 */
38 public long getId()
39 {
40 return id;
41 }
42
43 /***
44 * @param id
45 * The id to set.
46 */
47 public void setId(long id)
48 {
49 this.id = id;
50 }
51
52 /***
53 * @param projectId
54 */
55 public Project(long id)
56 {
57 this.id = id;
58 }
59
60 public Project()
61 {}
62
63 /***
64 * @return Returns the customer.
65 *
66 * @hibernate.many-to-one column="customerId"
67 */
68 public Customer getCustomer()
69 {
70 return customer;
71 }
72
73 /***
74 * @param customer
75 * The customer to set.
76 */
77 public void setCustomer(Customer customer)
78 {
79 this.customer = customer;
80 }
81
82 /***
83 * @return Returns the currency.
84 *
85 * @hibernate.property
86 */
87 public String getCurrency()
88 {
89 return currency;
90 }
91
92 /***
93 * @param currency
94 * The currency to set.
95 */
96 public void setCurrency(String currency)
97 {
98 this.currency = currency;
99 }
100
101 /***
102 * @return
103 *
104 * @hibernate.set cascade="none" lazy="true"
105 * @hibernate.collection-key column="projectId"
106 * @hibernate.collection-one-to-many class="com.pnpconsult.zeiterfassung.model.UserEntry"
107 */
108 public Set getUserEntries()
109 {
110 return userEntries;
111 }
112
113 public void setUserEntries(Set entries)
114 {
115 this.userEntries = entries;
116 }
117
118 /***
119 * @return Returns the name.
120 *
121 * @hibernate.property
122 */
123 public String getName()
124 {
125 return name;
126 }
127
128 /***
129 * @param name
130 * The name to set.
131 */
132 public void setName(String name)
133 {
134 this.name = name;
135 }
136
137 /***
138 * @return Returns the number.
139 *
140 * @hibernate.property
141 */
142 public String getNumber()
143 {
144 return number;
145 }
146
147 /***
148 * @param number
149 * The number to set.
150 */
151 public void setNumber(String number)
152 {
153 this.number = number;
154 }
155
156 /***
157 * @return Returns the userProjects.
158 *
159 * @hibernate.set cascade="none" sort="natural" lazy="true"
160 * @hibernate.collection-key column="projectId"
161 * @hibernate.collection-one-to-many class="com.pnpconsult.zeiterfassung.model.UserProject"
162 */
163 public SortedSet getUserProjects()
164 {
165 return userProjects;
166 }
167
168 /***
169 * @param userProjects
170 * The userProjects to set.
171 */
172 public void setUserProjects(SortedSet userProjects)
173 {
174 this.userProjects = userProjects;
175 }
176
177 public boolean equals(Object obj)
178 {
179 try
180 {
181 return id == ((Project) obj).id;
182 }
183 catch (ClassCastException e)
184 {
185 return false;
186 }
187 }
188
189 public int hashCode()
190 {
191 return new HashCodeBuilder().append(id).toHashCode();
192 }
193
194 public String getLabel()
195 {
196 return toString();
197 }
198
199 /***
200 * @hibernate.property
201 */
202 public float getTaxValue0()
203 {
204 return taxValue[0];
205 }
206
207 /***
208 * @hibernate.property type="date"
209 */
210 public Date getTaxDate0()
211 {
212 return taxDate[0];
213 }
214
215 public void setTaxValue0(float taxValue)
216 {
217 this.taxValue[0] = taxValue;
218 }
219
220 public void setTaxDate0(Date taxDate)
221 {
222 this.taxDate[0] = taxDate;
223 }
224
225 /***
226 * @hibernate.property
227 */
228 public float getTaxValue1()
229 {
230 return taxValue[1];
231 }
232
233 /***
234 * @hibernate.property type="date"
235 */
236 public Date getTaxDate1()
237 {
238 return taxDate[1];
239 }
240
241 public void setTaxValue1(float taxValue)
242 {
243 this.taxValue[1] = taxValue;
244 }
245
246 public void setTaxDate1(Date taxDate)
247 {
248 this.taxDate[1] = taxDate;
249 }
250
251 /***
252 * @hibernate.property
253 */
254 public float getTaxValue2()
255 {
256 return taxValue[2];
257 }
258
259 /***
260 * @hibernate.property type="date"
261 */
262 public Date getTaxDate2()
263 {
264 return taxDate[2];
265 }
266
267 public void setTaxValue2(float taxValue)
268 {
269 this.taxValue[2] = taxValue;
270 }
271
272 public void setTaxDate2(Date taxDate)
273 {
274 this.taxDate[2] = taxDate;
275 }
276
277 public float getTax(Date date)
278 {
279 Date resultDate = null;
280 float resultValue = 0.0F;
281 for (int i = 0; i < taxDate.length; i++)
282 {
283 if (taxDate[i] != null
284 && !date.before(taxDate[i])
285 && (resultDate == null || resultDate.before(taxDate[i]))
286 && taxValue[i] != 0.0F)
287 {
288 resultDate = taxDate[i];
289 resultValue = taxValue[i];
290 }
291 }
292 return resultValue;
293 }
294
295 protected Description buildDescription()
296 {
297 return new Description().append(null, null, customer, " - ").append(
298 name).append(" ", "(", number, ")");
299 }
300
301 public void addUserEntry(UserEntry userEntry)
302 {
303 if (userEntries == null)
304 {
305 userEntries = new HashSet();
306 }
307 userEntries.add(userEntry);
308 }
309
310 /***
311 * @hibernate.set cascade="none" lazy="true"
312 * @hibernate.collection-key column="projectId"
313 * @hibernate.collection-one-to-many class="com.pnpconsult.zeiterfassung.model.Bill"
314 */
315 public Set getBills()
316 {
317 return bills;
318 }
319
320 public void setBills(Set bills)
321 {
322 this.bills = bills;
323 }
324 }