18 package org.turro.erp.entity;
20 import java.util.Date;
21 import java.util.HashSet;
22 import java.util.Iterator;
24 import javax.persistence.*;
25 import org.amic.util.string.MultipleString;
26 import org.turro.string.Strings;
27 import org.turro.contacts.Contact;
28 import org.turro.contacts.db.ContactsPU;
29 import org.turro.elephant.db.IdUtils;
30 import org.turro.elephant.impl.util.StringParser;
31 import org.turro.erp.db.ErpPU;
32 import org.turro.financials.db.FinancialsPU;
33 import org.turro.financials.entity.Contract;
34 import org.turro.financials.entity.Product;
35 import org.turro.financials.entity.RegisterView;
36 import org.turro.jpa.Dao;
37 import org.turro.jpa.entity.CachedEntity;
44 public class WorkOrder implements java.io.Serializable {
47 @GeneratedValue(strategy=GenerationType.IDENTITY)
48 @Column(name=
"IDENTIFIER")
51 private long productId;
53 @Column(name=
"WORKORDER_DATE")
54 @Temporal(value = TemporalType.DATE)
55 private Date workOrderDate;
59 private String description;
61 private long workOrderId;
63 private long contractId;
65 private String petitionerId;
69 private boolean draft;
77 @OneToMany(mappedBy =
"parent", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=
true)
78 private Set<WorkOrder> extensions =
new HashSet<WorkOrder>();
80 @OneToMany(mappedBy =
"workOrder", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=
true)
81 @OrderBy(value=
"orderRef")
82 private Set<OrderReference> orderReferences =
new HashSet<OrderReference>();
89 this.contractId = contractId;
97 this.description = description;
113 this.extensions = extensions;
125 return orderReferences;
129 this.orderReferences = orderReferences;
137 this.parent = parent;
145 this.petitionerId = petitionerId;
153 this.productId = productId;
161 this.supervised = supervised;
169 this.viewId = viewId;
173 return workOrderDate;
177 this.workOrderDate = workOrderDate;
185 this.workOrderId = workOrderId;
190 private transient CachedEntity<Product, Long> product =
191 new CachedEntity<Product, Long>() {
193 protected Dao createDao() {
199 return product.getEntity(productId);
203 productId = this.product.setEntity(product);
206 private transient CachedEntity<Contract, Long> contract =
207 new CachedEntity<Contract, Long>() {
209 protected Dao createDao() {
215 return contract.getEntity(contractId);
219 contractId = this.contract.setEntity(contract);
222 private transient CachedEntity<Contact, String> petitioner =
223 new CachedEntity<Contact, String>() {
225 protected Dao createDao() {
231 return petitioner.getEntity(petitionerId);
235 petitionerId = this.petitioner.setEntity(petitioner);
238 private transient CachedEntity<RegisterView, Long> view =
239 new CachedEntity<RegisterView, Long>() {
241 protected Dao createDao() {
247 return view.getEntity(viewId);
251 viewId = this.view.setEntity(view);
261 if(!Strings.isBlank(description)) {
264 MultipleString ms =
new MultipleString();
266 ms.add(or.getSomeDescription());
268 return ms.getString(100);
280 return productId > 0;
284 boolean empty = workOrderDate ==
null;
298 Iterator<OrderReference> it = orderReferences.iterator();
299 while(it.hasNext()) {
311 wo.prepareForSaving();
314 or.prepareForSaving();
316 if(workOrderId == 0 && !draft) {
318 new ErpPU(),
"WorkOrder",
"workOrderId");
323 return (
isDraft() ?
"" : workOrderId +
" - ") +
328 HashSet<OrderReference>
set =
new HashSet<OrderReference>();
341 for(
Budget b : or.getBudgets()) {
342 num = Math.max(num, b.getBudgetNumber() + 1);
352 price += or.getPrice();
360 cost += or.getCost();
369 "select wo from WorkOrder as wo " +
370 "where wo.workOrderId = ?",
371 new Object[] { value });
static long getMaxLongIdFromLong(Dao dao, String table, String field)
static String toHTML(String value)
void setWorkOrder(WorkOrder workOrder)
void setPetitionerId(String petitionerId)
void setView(RegisterView view)
void setOrderReferences(Set< OrderReference > orderReferences)
void setExtensions(Set< WorkOrder > extensions)
void setSupervised(OwnedAptitude supervised)
Set< WorkOrder > getExtensions()
void setDescription(String description)
void setContract(Contract contract)
void setProduct(Product product)
OwnedAptitude getSupervised()
void setWorkOrderDate(Date workOrderDate)
String getFullDescription()
void setParent(WorkOrder parent)
String getSomeDescription()
void setContractId(long contractId)
Set< OrderReference > getSavedOrderReferences()
void setWorkOrderId(long workOrderId)
long getNextBudgetNumber()
void setPetitioner(Contact petitioner)
static WorkOrder getByWorkOrderId(long value)
void setProductId(long productId)
Set< OrderReference > getOrderReferences()
String getHtmlDescription()
void setViewId(long viewId)
void setDraft(boolean draft)
String getProductString()
Object getSingleResultOrNull(SqlClause sc)