BrightSide Workbench Full Report + Source Code
HoursItem.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.purchase;
20 
21 import java.util.Date;
22 import org.turro.erp.entity.OrderReference;
23 import org.turro.erp.entity.ReceiptItem;
24 import org.turro.erp.entity.Task;
25 import org.turro.erp.entity.WorkOrder;
26 import org.turro.erp.resource.ResourceAptitude;
27 import org.turro.math.Zero;
28 
33 public class HoursItem {
34 
35  private WorkOrder workOrder;
36  private OrderReference orderReference;
37  private long workOrderId;
38  private int orderRef;
39  private Task task;
40  private Date startWorking;
41  private double units, dedication, costHour;
42  private boolean automatic;
43  private String description;
44  private ResourceAptitude resourceAptitude;
45 
48  orderReference = hr.getOrderItem().getRequiredUsage().getTask().getOrderReference();
49  workOrderId = workOrder.getWorkOrderId();
50  orderRef = orderReference.getOrderRef();
51  task = hr.getOrderItem().getRequiredUsage().getTask();
52  startWorking = hr.getStartWorking();
53  units = hr.getUnits();
54  dedication = hr.getDedication();
55  automatic = false;
56  description = hr.getDescription();
57  resourceAptitude = hr.getOrderItem().getRequiredUsage().getResourceAptitude();
59  }
60 
61  HoursItem() {
62  }
63 
64  public boolean isAutomatic() {
65  return automatic;
66  }
67 
68  public void setAutomatic(boolean automatic) {
69  if(this.automatic && !automatic) {
70  dedication = 1.0;
71  } else if(!this.automatic && automatic && resourceAptitude != null) {
72  dedication = 0.0d;
73  }
74  this.automatic = automatic;
75  }
76 
77  public String getConcept() {
78  return description;
79  }
80 
81  public void setConcept(String concept) {
82  this.description = concept;
83  }
84 
85  public double getCostHour() {
86  return costHour;
87  }
88 
89  public void setCostHour(double costHour) {
90  this.costHour = costHour;
91  }
92 
93  public double getDedication() {
94  return dedication;
95  }
96 
97  public void setDedication(double dedication) {
98  this.dedication = dedication;
99  }
100 
101  public int getOrderRef() {
102  return orderRef;
103  }
104 
105  public void setOrderRef(int orderRef) {
106  if(this.orderRef != orderRef) {
107  orderReference = null;
108  task = null;
109  for(OrderReference or : workOrder.getOrderReferences()) {
110  if(or.getOrderRef() == orderRef) {
111  orderReference = or;
112  break;
113  }
114  }
115  }
116  this.orderRef = orderRef;
117  }
118 
120  return orderReference;
121  }
122 
123  public void setOrderReference(OrderReference orderReference) {
124  this.orderReference = orderReference;
125  }
126 
128  return resourceAptitude;
129  }
130 
131  public void setResourceAptitude(ResourceAptitude resourceAptitude) {
132  this.resourceAptitude = resourceAptitude;
133  }
134 
135  public Date getStartWorking() {
136  return startWorking;
137  }
138 
139  public void setStartWorking(Date startWorking) {
140  this.startWorking = startWorking;
141  }
142 
143  public Task getTask() {
144  return task;
145  }
146 
147  public void setTask(Task task) {
148  if(task != null) {
149  workOrder = task.getOrderReference().getWorkOrder();
150  workOrderId = workOrder.getWorkOrderId();
151  }
152  this.task = task;
153  }
154 
155  public double getUnits() {
156  return units;
157  }
158 
159  public void setUnits(double units) {
160  this.units = units;
161  }
162 
164  return workOrder;
165  }
166 
167  public void setWorkOrder(WorkOrder workOrder) {
168  this.workOrder = workOrder;
169  }
170 
171  public long getWorkOrderId() {
172  return workOrderId;
173  }
174 
175  public void setWorkOrderId(long workOrderId) {
176  if(this.workOrderId != workOrderId) {
177  workOrder = WorkOrder.getByWorkOrderId(workOrderId);
178  orderRef = 0;
179  orderReference = null;
180  task = null;
181  }
182  this.workOrderId = workOrderId;
183  }
184 
185  boolean isValid() {
186  return task != null && startWorking != null &&
187  !Zero.near(units, 3) && !Zero.near(dedication, 2);
188  }
189 
190 }
RequiredUsage getRequiredUsage()
Definition: OrderItem.java:249
static WorkOrder getByWorkOrderId(long value)
Definition: WorkOrder.java:365
Set< OrderReference > getOrderReferences()
Definition: WorkOrder.java:124
void setStartWorking(Date startWorking)
Definition: HoursItem.java:139
void setWorkOrderId(long workOrderId)
Definition: HoursItem.java:175
void setAutomatic(boolean automatic)
Definition: HoursItem.java:68
void setCostHour(double costHour)
Definition: HoursItem.java:89
ResourceAptitude getResourceAptitude()
Definition: HoursItem.java:127
void setResourceAptitude(ResourceAptitude resourceAptitude)
Definition: HoursItem.java:131
void setConcept(String concept)
Definition: HoursItem.java:81
void setWorkOrder(WorkOrder workOrder)
Definition: HoursItem.java:167
OrderReference getOrderReference()
Definition: HoursItem.java:119
void setOrderReference(OrderReference orderReference)
Definition: HoursItem.java:123
void setDedication(double dedication)
Definition: HoursItem.java:97
void setOrderRef(int orderRef)
Definition: HoursItem.java:105
static boolean near(double value, int digits)
Definition: Zero.java:30