BrightSide Workbench Full Report + Source Code
CustomerOrder.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.erp.entity;
19 
20 import java.util.Date;
21 import javax.persistence.*;
22 import org.turro.string.Strings;
23 import org.turro.erp.db.ErpPU;
24 import org.turro.financials.db.FinancialsPU;
25 import org.turro.financials.entity.Contract;
26 import org.turro.financials.product.ProductFactory;
27 import org.turro.jpa.Dao;
28 import org.turro.jpa.entity.DaoEntity;
29 
34 @Entity
35 public class CustomerOrder implements java.io.Serializable {
36 
37  @Id
38  @GeneratedValue(strategy=GenerationType.IDENTITY)
39  @Column(name="IDENTIFIER")
40  private long id;
41 
42  private String customerCode;
43 
44  @Lob
45  @Column(length=4096)
46  private String description;
47 
48  @Column(name="CONTROL_DATE")
49  @Temporal(value = TemporalType.TIMESTAMP)
50  private Date controlDate;
51 
52  @Column(name="DELIVERY_DATE")
53  @Temporal(value = TemporalType.TIMESTAMP)
54  private Date delivery;
55 
56  private boolean wantBudget;
57 
58  private String orderId;
59 
60  @Column(name="ORDER_DATE")
61  @Temporal(value = TemporalType.TIMESTAMP)
62  private Date orderDate;
63 
64  private long customerId;
65 
66  private long serviceId;
67 
68  private double quantity, price;
69 
70  private boolean noFraction;
71 
72  public Date getControlDate() {
73  return controlDate;
74  }
75 
76  public void setControlDate(Date controlDate) {
77  this.controlDate = controlDate;
78  }
79 
80  public String getCustomerCode() {
81  return customerCode;
82  }
83 
84  public void setCustomerCode(String customerCode) {
85  this.customerCode = customerCode;
86  }
87 
88  public long getCustomerId() {
89  return customerId;
90  }
91 
92  public void setCustomerId(long customerId) {
93  this.customerId = customerId;
94  }
95 
96  public String getOrderId() {
97  return orderId;
98  }
99 
100  public void setOrderId(String orderId) {
101  this.orderId = orderId;
102  }
103 
104  public Date getDelivery() {
105  return delivery;
106  }
107 
108  public void setDelivery(Date delivery) {
109  this.delivery = delivery;
110  }
111 
112  public String getDescription() {
113  return description;
114  }
115 
116  public void setDescription(String description) {
117  this.description = description;
118  }
119 
120  public long getId() {
121  return id;
122  }
123 
124  public void setId(long id) {
125  this.id = id;
126  }
127 
128  public boolean isNoFraction() {
129  return noFraction;
130  }
131 
132  public void setNoFraction(boolean noFraction) {
133  this.noFraction = noFraction;
134  }
135 
136  public Date getOrderDate() {
137  return orderDate;
138  }
139 
140  public void setOrderDate(Date orderDate) {
141  this.orderDate = orderDate;
142  }
143 
144  public double getPrice() {
145  return price;
146  }
147 
148  public void setPrice(double price) {
149  this.price = price;
150  }
151 
152  public double getQuantity() {
153  return quantity;
154  }
155 
156  public void setQuantity(double quantity) {
157  this.quantity = quantity;
158  }
159 
160  public long getServiceId() {
161  return serviceId;
162  }
163 
164  public void setServiceId(long service) {
165  this.serviceId = service;
166  }
167 
168  public boolean isWantBudget() {
169  return wantBudget;
170  }
171 
172  public void setWantBudget(boolean wantBudget) {
173  this.wantBudget = wantBudget;
174  }
175 
176  /* Helpers */
177 
178  public double getAmount() {
179  return (quantity == 0 ? 1 : quantity) * price;
180  }
181 
182  public boolean isEmpty() {
183  return Strings.isBlank(description) ||
184  customerId <= 0;
185  }
186 
187  public void initFrom(OrderReference orderReference) {
188  setDescription(orderReference.getDescription());
189  if(orderReference.getProduct() != null) {
190  ProductFactory.setContractorProduct(orderReference.getProduct(), orderReference.getWorkOrder().getContractId());
191  if(orderReference.getProduct().getProductByContractor() != null) {
193  }
194  }
195  }
196 
198  if(id == 0) {
199  return null;
200  }
202  "select o from OrderReference as o " +
203  "where o.customerOrder = ?",
204  new Object[] { this });
205  }
206 
207  /* Financials Helpers */
208 
209  public Contract getService() {
210  return new DaoEntity<Contract, Long>() {
211  @Override
212  protected Dao createDao() {
213  return new FinancialsPU();
214  }
215  @Override
216  protected boolean shouldLog() {
217  return false;
218  }
219  }.find(serviceId);
220  }
221 
222  public void setService(Contract service) {
223  if(service != null) {
224  serviceId = service.getId();
225  } else {
226  serviceId = 0;
227  }
228  }
229 
231  return new DaoEntity<Contract, Long>() {
232  @Override
233  protected Dao createDao() {
234  return new FinancialsPU();
235  }
236  @Override
237  protected boolean shouldLog() {
238  return false;
239  }
240  }.find(customerId);
241  }
242 
243  public void setCustomer(Contract customer) {
244  if(customer != null) {
245  customerId = customer.getId();
246  } else {
247  customerId = 0;
248  }
249  }
250 
251 }
void setControlDate(Date controlDate)
void setWantBudget(boolean wantBudget)
void initFrom(OrderReference orderReference)
void setDescription(String description)
void setCustomer(Contract customer)
void setService(Contract service)
void setCustomerId(long customerId)
void setNoFraction(boolean noFraction)
void setCustomerCode(String customerCode)
ProductByContractor getProductByContractor()
Definition: Product.java:208
static void setContractorProduct(IProduct product, long contractorId)
Object getSingleResultOrNull(SqlClause sc)
Definition: Dao.java:419