BrightSide Workbench Full Report + Source Code
ProductsItem.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 org.turro.erp.entity.OrderReference;
22 import org.turro.erp.entity.ReceiptItem;
23 import org.turro.erp.entity.Task;
24 import org.turro.erp.entity.WorkOrder;
25 import org.turro.financials.product.IProduct;
26 import org.turro.math.Zero;
27 
32 public class ProductsItem {
33 
34  private WorkOrder workOrder;
35  private OrderReference orderReference;
36  private long workOrderId;
37  private int orderRef;
38  private Task task;
39  private double units, cost;
40  private String description;
41  private IProduct iProduct;
42 
44  task = ri.getOrderItem().getRequiredUsage().getTask();
45  orderReference = task.getOrderReference();
46  workOrder = orderReference.getWorkOrder();
47  workOrderId = workOrder.getWorkOrderId();
48  orderRef = orderReference.getOrderRef();
49  units = ri.getUnits();
50  description = ri.getDescription();
51  iProduct = ri.getIProduct();
52  cost = ri.getCost();
53  }
54 
55  public ProductsItem() {
56  }
57 
58  public String getConcept() {
59  return description;
60  }
61 
62  public void setConcept(String concept) {
63  this.description = concept;
64  }
65 
66  public double getCost() {
67  return cost;
68  }
69 
70  public void setCost(double cost) {
71  this.cost = cost;
72  }
73 
74  public int getOrderRef() {
75  return orderRef;
76  }
77 
78  public void setOrderRef(int orderRef) {
79  if(this.orderRef != orderRef) {
80  orderReference = null;
81  task = null;
82  for(OrderReference or : workOrder.getOrderReferences()) {
83  if(or.getOrderRef() == orderRef) {
84  orderReference = or;
85  break;
86  }
87  }
88  }
89  this.orderRef = orderRef;
90  }
91 
93  return orderReference;
94  }
95 
96  public void setOrderReference(OrderReference orderReference) {
97  this.orderReference = orderReference;
98  }
99 
101  return iProduct;
102  }
103 
104  public void setIProduct(IProduct product) {
105  this.iProduct = product;
106  if(cost == 0 && product != null) {
107  cost = product.getProductCost();
108  }
109  }
110 
111  public Task getTask() {
112  return task;
113  }
114 
115  public void setTask(Task task) {
116  if(task != null) {
117  workOrder = task.getOrderReference().getWorkOrder();
118  workOrderId = workOrder.getWorkOrderId();
119  }
120  this.task = task;
121  }
122 
123  public double getUnits() {
124  return units;
125  }
126 
127  public void setUnits(double units) {
128  this.units = units;
129  }
130 
132  return workOrder;
133  }
134 
135  public void setWorkOrder(WorkOrder workOrder) {
136  this.workOrder = workOrder;
137  }
138 
139  public long getWorkOrderId() {
140  return workOrderId;
141  }
142 
143  public void setWorkOrderId(long workOrderId) {
144  if(this.workOrderId != workOrderId) {
145  workOrder = WorkOrder.getByWorkOrderId(workOrderId);
146  orderRef = 0;
147  orderReference = null;
148  task = null;
149  }
150  this.workOrderId = workOrderId;
151  }
152 
153  boolean isValid() {
154  return task != null && iProduct != null &&
155  !Zero.near(units, 3);
156  }
157 
158 }
RequiredUsage getRequiredUsage()
Definition: OrderItem.java:249
static WorkOrder getByWorkOrderId(long value)
Definition: WorkOrder.java:365
Set< OrderReference > getOrderReferences()
Definition: WorkOrder.java:124
void setIProduct(IProduct product)
void setOrderReference(OrderReference orderReference)
void setWorkOrderId(long workOrderId)
void setWorkOrder(WorkOrder workOrder)
static boolean near(double value, int digits)
Definition: Zero.java:30