BrightSide Workbench Full Report + Source Code
ReceiptItem.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.erp.entity;
20 
21 import java.util.Collection;
22 import java.util.Date;
23 import java.util.Iterator;
24 import javax.persistence.*;
25 import org.turro.string.Strings;
26 import org.turro.contacts.Contact;
27 import org.turro.contacts.db.ContactsPU;
28 import org.turro.financials.db.FinancialsPU;
29 import org.turro.financials.entity.Contract;
30 import org.turro.financials.entity.DocumentLine;
31 import org.turro.financials.entity.Product;
32 import org.turro.financials.entity.ProductByContractor;
33 import org.turro.financials.product.CachedIProduct;
34 import org.turro.financials.product.IProduct;
35 import org.turro.financials.product.IProductKey;
36 import org.turro.jpa.Dao;
37 import org.turro.jpa.entity.CachedEntity;
38 
43 @Entity
44 public class ReceiptItem implements java.io.Serializable {
45 
46  @Id
47  @GeneratedValue(strategy=GenerationType.IDENTITY)
48  @Column(name="IDENTIFIER")
49  private long id;
50 
51  @Lob
52  @Column(length=4096)
53  private String description;
54 
55  private long providerId, providerProductId, productId, documentLineId;
56 
57  @ManyToOne
58  private HumanResource humanResource;
59 
60  @ManyToOne
61  private Resource resource;
62 
63  @Temporal(value = TemporalType.DATE)
64  private Date documentDate;
65 
66  private String documentNumber;
67 
68  private double units, dedication, cost, tax;
69 
70  private String productDescription;
71 
72  @Column(name="START_WORKING")
73  @Temporal(value = TemporalType.TIMESTAMP)
74  private Date startWorking;
75 
76  private String receptorId;
77 
78  @ManyToOne
79  private OrderItem orderItem;
80 
81  public double getCost() {
82  return cost;
83  }
84 
85  public void setCost(double cost) {
86  this.cost = cost;
87  }
88 
89  public double getDedication() {
90  return dedication;
91  }
92 
93  public void setDedication(double dedication) {
94  this.dedication = dedication;
95  }
96 
97  public String getDescription() {
98  return description;
99  }
100 
101  public void setDescription(String description) {
102  this.description = description;
103  }
104 
105  public Date getDocumentDate() {
106  return documentDate;
107  }
108 
109  public void setDocumentDate(Date documentDate) {
110  this.documentDate = documentDate;
111  }
112 
113  public long getDocumentLineId() {
114  return documentLineId;
115  }
116 
117  public void setDocumentLineId(long documentLineId) {
118  this.documentLineId = documentLineId;
119  }
120 
121  public String getDocumentNumber() {
122  return documentNumber;
123  }
124 
125  public void setDocumentNumber(String documentNumber) {
126  this.documentNumber = documentNumber;
127  }
128 
129  public double getUnits() {
130  return units;
131  }
132 
133  public void setUnits(double units) {
134  this.units = units;
135  }
136 
138  return humanResource;
139  }
140 
141  public void setHumanResource(HumanResource humanResource) {
142  this.humanResource = humanResource;
143  }
144 
145  public long getId() {
146  return id;
147  }
148 
149  public void setId(long id) {
150  this.id = id;
151  }
152 
154  return orderItem;
155  }
156 
157  public void setOrderItem(OrderItem orderItem) {
158  this.orderItem = orderItem;
159  }
160 
161  public String getProductDescription() {
162  return productDescription;
163  }
164 
165  public void setProductDescription(String productDescription) {
166  this.productDescription = productDescription;
167  }
168 
169  public long getProductId() {
170  return productId;
171  }
172 
173  public void setProductId(long productId) {
174  this.productId = productId;
175  }
176 
177  public long getProviderId() {
178  return providerId;
179  }
180 
181  public void setProviderId(long providerId) {
182  this.providerId = providerId;
183  }
184 
185  public long getProviderProductId() {
186  return providerProductId;
187  }
188 
189  public void setProviderProductId(long providerProductId) {
190  this.providerProductId = providerProductId;
191  }
192 
193  public String getReceptorId() {
194  return receptorId;
195  }
196 
197  public void setReceptorId(String receptorId) {
198  this.receptorId = receptorId;
199  }
200 
202  return resource;
203  }
204 
205  public void setResource(Resource resource) {
206  this.resource = resource;
207  }
208 
209  public Date getStartWorking() {
210  return startWorking;
211  }
212 
213  public void setStartWorking(Date startWorking) {
214  this.startWorking = startWorking;
215  }
216 
217  public double getTax() {
218  return tax;
219  }
220 
221  public void setTax(double tax) {
222  this.tax = tax;
223  }
224 
225  /* Financials Helpers */
226 
227  private transient CachedEntity<DocumentLine, Long> documentLine =
228  new CachedEntity<DocumentLine, Long>() {
229  @Override
230  protected Dao createDao() {
231  return new FinancialsPU();
232  }
233  };
234 
236  return documentLine.getEntity(documentLineId);
237  }
238 
239  public void setDocumentLine(DocumentLine documentLine) {
240  documentLineId = this.documentLine.setEntity(documentLine);
241  }
242 
243  private transient CachedEntity<Product, Long> product =
244  new CachedEntity<Product, Long>() {
245  @Override
246  protected Dao createDao() {
247  return new FinancialsPU();
248  }
249  };
250 
251  public Product getProduct() {
252  return product.getEntity(productId);
253  }
254 
255  public void setProduct(Product product) {
256  productId = this.product.setEntity(product);
257  }
258 
259  private transient CachedIProduct iproduct = new CachedIProduct();
260 
262  return iproduct.getIProduct(new IProductKey(productId, providerId, providerProductId, productDescription));
263  }
264 
265  public void setIProduct(IProduct product) {
266  IProductKey productKey = iproduct.setIProduct(product);
267  productId = productKey.getProductId();
268  providerId = productKey.getProviderId();
269  providerProductId = productKey.getProviderProductId();
270  productDescription = productKey.getProductDescription();
271  }
272 
273  private transient CachedEntity<Contract, Long> provider =
274  new CachedEntity<Contract, Long>() {
275  @Override
276  protected Dao createDao() {
277  return new FinancialsPU();
278  }
279  };
280 
282  return provider.getEntity(providerId);
283  }
284 
285  public void setProvider(Contract provider) {
286  providerId = this.provider.setEntity(provider);
287  }
288 
289  private transient CachedEntity<ProductByContractor, Long> providerProduct =
290  new CachedEntity<ProductByContractor, Long>() {
291  @Override
292  protected Dao createDao() {
293  return new FinancialsPU();
294  }
295  };
296 
298  return providerProduct.getEntity(providerProductId);
299  }
300 
301  public void setProviderProduct(ProductByContractor providerProduct) {
302  providerProductId = this.providerProduct.setEntity(providerProduct);
303  }
304 
305  /* Helpers */
306 
307  private transient CachedEntity<Contact, String> receptor =
308  new CachedEntity<Contact, String>() {
309  @Override
310  protected Dao createDao() {
311  return new ContactsPU();
312  }
313  };
314 
316  return receptor.getEntity(receptorId);
317  }
318 
319  public void setPetitioner(Contact petitioner) {
320  receptorId = this.receptor.setEntity(petitioner);
321  }
322 
323  public boolean isEmpty() {
324  return units == 0;
325  }
326 
327  public boolean isProductType() {
328  return ((providerProductId > 0 || productId > 0) ||
329  !Strings.isEmpty(productDescription));
330  }
331 
332  public boolean isHumanResourceType() {
333  return humanResource != null;
334  }
335 
336  public boolean isResourceType() {
337  return resource != null;
338  }
339 
340  public String getName() {
341  if(humanResource != null) {
342  return humanResource.getName();
343  } else if(resource != null) {
344  return resource.getName();
345  } else {
346  IProduct product = getIProduct();
347  return product != null ? product.getProductName() : null;
348  }
349  }
350 
351  public String getType() {
352  if(humanResource != null) {
353  return "operator";
354  } else if(resource != null) {
355  return "resource";
356  } else {
357  return "product";
358  }
359  }
360 
361  public double getAmount() {
362  return cost * units * dedication;
363  }
364 
365  public Date getWorkDate() {
366  return startWorking == null ? documentDate : startWorking;
367  }
368 
370  if(orderItem == null) {
372  }
373  if(orderItem.getUnits() <= units) {
375  } else {
377  }
378  }
379 
381  OrderItem oi = orderItem != null ? orderItem.getRelated() : null;
382  if(oi != null) {
383  Collection<ReceiptItem> ris = oi.getReceiptItems();
384  Iterator<ReceiptItem> itri = ris.iterator();
385  if(itri.hasNext()) {
386  return ris.iterator().next();
387  }
388  }
389  return null;
390  }
391 
392  public double getRealUnits() {
393  return units * dedication;
394  }
395 
396 }
Set< ReceiptItem > getReceiptItems()
Definition: OrderItem.java:221
void setProductId(long productId)
void setDedication(double dedication)
void setProductDescription(String productDescription)
void setResource(Resource resource)
void setHumanResource(HumanResource humanResource)
void setDescription(String description)
void setProvider(Contract provider)
void setOrderItem(OrderItem orderItem)
void setProviderId(long providerId)
void setReceptorId(String receptorId)
void setDocumentNumber(String documentNumber)
void setIProduct(IProduct product)
void setDocumentLineId(long documentLineId)
void setProduct(Product product)
void setDocumentLine(DocumentLine documentLine)
ProductByContractor getProviderProduct()
void setProviderProductId(long providerProductId)
void setStartWorking(Date startWorking)
void setPetitioner(Contact petitioner)
void setProviderProduct(ProductByContractor providerProduct)
void setDocumentDate(Date documentDate)
IProductKey setIProduct(IProduct product)
IProduct getIProduct(IProductKey productKey)