1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.businessobject;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.document.AccountsPayableDocumentBase;
20 import org.kuali.ole.module.purap.document.LineItemReceivingDocument;
21 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
22 import org.kuali.ole.module.purap.exception.PurError;
23 import org.kuali.rice.core.api.util.type.KualiDecimal;
24 import org.kuali.rice.krad.util.ObjectUtils;
25
26 import java.util.List;
27
28
29
30
31 public class LineItemReceivingItem extends ReceivingItemBase {
32
33 private KualiDecimal itemOrderedQuantity;
34
35
36 private KualiDecimal itemReceivedPriorQuantity;
37 private KualiDecimal itemReceivedToBeQuantity;
38
39 private LineItemReceivingDocument lineItemReceivingDocument;
40
41 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountsPayableDocumentBase.class);
42
43
44
45
46 public LineItemReceivingItem() {
47 }
48
49 public LineItemReceivingItem(LineItemReceivingDocument rld) {
50 this.setDocumentNumber(rld.getDocumentNumber());
51 this.setItemReceivedTotalQuantity(KualiDecimal.ZERO);
52 this.setItemReturnedTotalQuantity(KualiDecimal.ZERO);
53 this.setItemDamagedTotalQuantity(KualiDecimal.ZERO);
54 this.setItemOriginalReceivedTotalQuantity(KualiDecimal.ZERO);
55 this.setItemOriginalReturnedTotalQuantity(KualiDecimal.ZERO);
56 this.setItemOriginalDamagedTotalQuantity(KualiDecimal.ZERO);
57 }
58
59 public LineItemReceivingItem(PurchaseOrderItem poi, LineItemReceivingDocument rld) {
60
61 this.setDocumentNumber(rld.getDocumentNumber());
62 this.setItemTypeCode(poi.getItemTypeCode());
63 this.setPurchaseOrderIdentifier(rld.getPurchaseOrderIdentifier());
64
65 this.setItemLineNumber(poi.getItemLineNumber());
66 this.setItemCatalogNumber(poi.getItemCatalogNumber());
67 this.setItemDescription(poi.getItemDescription());
68
69 this.setItemOrderedQuantity(poi.getItemQuantity());
70 this.setItemUnitOfMeasureCode(poi.getItemUnitOfMeasureCode());
71
72
73 if (ObjectUtils.isNull(poi.getItemReceivedTotalQuantity())) {
74 this.setItemReceivedPriorQuantity(KualiDecimal.ZERO);
75 } else {
76 this.setItemReceivedPriorQuantity(poi.getItemReceivedTotalQuantity());
77 }
78
79 this.setItemReceivedToBeQuantity(this.getItemOrderedQuantity().subtract(this.getItemReceivedPriorQuantity()));
80
81
82 this.setItemReceivedTotalQuantity(KualiDecimal.ZERO);
83
84 this.setItemReturnedTotalQuantity(KualiDecimal.ZERO);
85 this.setItemDamagedTotalQuantity(KualiDecimal.ZERO);
86
87 this.setItemOriginalReceivedTotalQuantity(KualiDecimal.ZERO);
88 this.setItemOriginalReturnedTotalQuantity(KualiDecimal.ZERO);
89 this.setItemOriginalDamagedTotalQuantity(KualiDecimal.ZERO);
90
91
92 this.setItemReasonAddedCode(null);
93 }
94
95
96
97
98
99
100
101 public PurchaseOrderItem getPurchaseOrderItem() {
102 if (ObjectUtils.isNotNull(this.getLineItemReceivingDocument())) {
103 if (ObjectUtils.isNull(this.getLineItemReceivingDocument())) {
104 this.refreshReferenceObject("lineItemReceivingDocument");
105 }
106 }
107
108
109 if (getLineItemReceivingDocument() != null) {
110 PurchaseOrderDocument po = getLineItemReceivingDocument().getPurchaseOrderDocument();
111 PurchaseOrderItem poi = null;
112 if (this.getItemType().isLineItemIndicator()) {
113 List<PurchaseOrderItem> items = po.getItems();
114 poi = items.get(this.getItemLineNumber().intValue() - 1);
115
116
117 }
118 if (poi != null) {
119 return poi;
120 } else {
121
122
123 return null;
124 }
125 } else {
126 LOG.error("getPurchaseOrderItem() Returning null because paymentRequest object is null");
127 throw new PurError("Receiving Line Object in Purchase Order item line number " + getItemLineNumber() + "or itemType " + getItemTypeCode() + " is null");
128 }
129 }
130
131
132
133
134
135
136 public KualiDecimal getItemOrderedQuantity() {
137 return itemOrderedQuantity;
138 }
139
140
141
142
143
144
145 public void setItemOrderedQuantity(KualiDecimal itemOrderedQuantity) {
146 this.itemOrderedQuantity = itemOrderedQuantity;
147 }
148
149
150
151
152
153
154 public LineItemReceivingDocument getLineItemReceivingDocument() {
155 return lineItemReceivingDocument;
156 }
157
158
159
160
161
162
163
164 public void setLineItemReceivingDocument(LineItemReceivingDocument lineItemReceivingDocument) {
165 this.lineItemReceivingDocument = lineItemReceivingDocument;
166 }
167
168 public KualiDecimal getItemReceivedPriorQuantity() {
169 if (ObjectUtils.isNull(itemReceivedPriorQuantity)) {
170 setItemReceivedPriorQuantity(getPurchaseOrderItem().getItemReceivedTotalQuantity());
171 }
172 return itemReceivedPriorQuantity;
173 }
174
175 public void setItemReceivedPriorQuantity(KualiDecimal itemReceivedPriorQuantity) {
176
177 this.itemReceivedPriorQuantity = itemReceivedPriorQuantity;
178 }
179
180 public KualiDecimal getItemReceivedToBeQuantity() {
181
182 KualiDecimal toBeQuantity = this.getItemOrderedQuantity().subtract(getItemReceivedPriorQuantity());
183 if (toBeQuantity.isNegative()) {
184 toBeQuantity = KualiDecimal.ZERO;
185 }
186 setItemReceivedToBeQuantity(toBeQuantity);
187
188 return itemReceivedToBeQuantity;
189 }
190
191 public void setItemReceivedToBeQuantity(KualiDecimal itemReceivedToBeQuantity) {
192 this.itemReceivedToBeQuantity = itemReceivedToBeQuantity;
193 }
194
195 public boolean isOrderedItem() {
196 return StringUtils.isEmpty(getItemReasonAddedCode());
197 }
198
199 }