BrightSide Workbench Full Report + Source Code
OrderReferenceClone.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.clone;
20 
21 import java.util.Collection;
22 import java.util.HashSet;
23 import org.turro.clone.ClonedEntity;
24 import org.turro.clone.ClonedEntitySet;
25 import org.turro.erp.entity.OrderReference;
26 import org.turro.erp.entity.Task;
27 import org.turro.hierarchy.Hierarchical;
28 
33 public class OrderReferenceClone extends ClonedEntity<OrderReference, Long> implements Hierarchical {
34 
35  private WorkOrderClone workOrder;
36  private String description;
37  private long productId;
38  private int orderRef;
39  private boolean noFraction;
40  private double quantity, price, tax, retention, old_units;
41  private long serviceId;
42  private HashSet<TaskClone> tasks = new HashSet<TaskClone>();
43 
44  public OrderReferenceClone(OrderReference orderReference, ClonedEntitySet entities) {
45  super(orderReference.getId(), orderReference, entities);
46  description = orderReference.getDescription();
47  productId = orderReference.getProductId();
48  orderRef = orderReference.getOrderRef();
49  noFraction = orderReference.isNoFraction();
50  quantity = orderReference.getQuantity();
51  price = orderReference.getPrice();
52  tax = orderReference.getTax();
53  retention = orderReference.getRetention();
54  serviceId = orderReference.getServiceId();
55  for(Task task : orderReference.getTasks()) {
56  if(task.getId() > 0) {
57  TaskClone t = new TaskClone(task, entities);
58  t.setOrderReference(this);
59  tasks.add((TaskClone) entities.addClonedEntity(t));
60  }
61  }
62  old_units = quantity;
63  }
64 
65  public void setWorkOrder(WorkOrderClone workOrder) {
66  this.workOrder = workOrder;
67  }
68 
69  public void setUnits(double units) {
70  double ratio =
71  (units == 0.0 || old_units == 0.0d) ?
72  1 : units / old_units;
73  for(Object t : children()) {
74  for(RequiredUsageClone ru : ((TaskClone) t).getRequiredUsages()) {
75  ru.setUnitRatio(ratio);
76  }
77  }
78  }
79 
80  @Override
82  OrderReference orderReference = new OrderReference();
83  applyData(orderReference);
84  for(TaskClone taskClone : tasks) {
85  taskClone.generateClone();
86  Task task = taskClone.getClone();
87  task.setOrderReference(orderReference);
88  orderReference.getTasks().add(task);
89  }
90  return orderReference;
91  }
92 
93  @Override
94  protected void applyData(OrderReference entity) {
95  entity.setDescription(description);
96  entity.setProductId(productId);
97  entity.setOrderRef(orderRef);
98  entity.setNoFraction(noFraction);
99  entity.setQuantity(quantity);
100  entity.setPrice(price);
101  entity.setTax(tax);
102  entity.setRetention(retention);
103  entity.setServiceId(serviceId);
104  }
105 
106  @Override
107  protected void applyChildren(OrderReference entity) {
108  for(TaskClone taskClone : tasks) {
109  taskClone.applyChanges();
110  }
111  }
112 
113  @Override
114  protected void assignEntities() {
115  for(TaskClone taskClone : tasks) {
116  taskClone.assignEntities();
117  }
118  }
119 
120  /* Hierarchical */
121 
122  @Override
123  public Collection children() {
124  return tasks;
125  }
126 
127  @Override
128  public Object parent() {
129  return workOrder;
130  }
131 
132 }
void setWorkOrder(WorkOrderClone workOrder)
OrderReferenceClone(OrderReference orderReference, ClonedEntitySet entities)
void setOrderReference(OrderReferenceClone orderReference)
Definition: TaskClone.java:81
void setNoFraction(boolean noFraction)
void setDescription(String description)