1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.ole.module.purap.businessobject;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.ole.module.purap.PurapConstants;
21 import org.kuali.ole.module.purap.PurapPropertyConstants;
22 import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
23 import org.kuali.ole.module.purap.document.service.PurchaseOrderService;
24 import org.kuali.ole.select.businessobject.OleNotes;
25 import org.kuali.ole.select.businessobject.OlePurchaseOrderNotes;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.rice.core.api.util.type.KualiDecimal;
28 import org.kuali.rice.krad.service.SequenceAccessorService;
29 import org.kuali.rice.krad.util.ObjectUtils;
30
31 import java.math.BigDecimal;
32 import java.util.ArrayList;
33 import java.util.LinkedHashMap;
34 import java.util.List;
35
36 import static org.kuali.rice.core.api.util.type.KualiDecimal.ZERO;
37
38
39
40
41 public class PurchaseOrderItem extends PurchasingItemBase {
42 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(PurchaseOrderItem.class);
43
44 private String documentNumber;
45 private KualiDecimal itemInvoicedTotalQuantity;
46 private KualiDecimal itemInvoicedTotalAmount;
47 private KualiDecimal itemReceivedTotalQuantity;
48 private KualiDecimal itemOutstandingEncumberedQuantity;
49 private KualiDecimal itemOutstandingEncumberedAmount;
50 private boolean itemActiveIndicator = true;
51 private KualiDecimal itemDamagedTotalQuantity;
52 private List<OleNotes> notes;
53 private Integer noteTypeId;
54 private String note;
55
56 private PurchaseOrderDocument purchaseOrder;
57
58
59 private boolean itemSelectedForRetransmitIndicator;
60 private boolean movingToSplit;
61
62
63
64
65
66 public PurchaseOrderItem() {
67 notes = new ArrayList<OleNotes>();
68 }
69
70
71
72
73
74
75
76 public PurchaseOrderItem(RequisitionItem ri, PurchaseOrderDocument po, RequisitionCapitalAssetItem reqCamsItem) {
77 super();
78 this.setPurchaseOrder(po);
79 SequenceAccessorService sas = SpringContext.getBean(SequenceAccessorService.class);
80 Integer itemIdentifier = sas.getNextAvailableSequenceNumber("PO_ITM_ID", PurchaseOrderDocument.class).intValue();
81 this.setItemIdentifier(itemIdentifier);
82 this.setItemLineNumber(ri.getItemLineNumber());
83 this.setItemUnitOfMeasureCode(ri.getItemUnitOfMeasureCode());
84 this.setItemQuantity(ri.getItemQuantity());
85 this.setItemCatalogNumber(ri.getItemCatalogNumber());
86 this.setItemDescription(ri.getItemDescription());
87 this.setItemUnitPrice(ri.getItemUnitPrice());
88 this.setItemAuxiliaryPartIdentifier(ri.getItemAuxiliaryPartIdentifier());
89 this.setItemAssignedToTradeInIndicator(ri.getItemAssignedToTradeInIndicator());
90 this.setItemTaxAmount(ri.getItemTaxAmount());
91
92 for (PurApItemUseTax useTaxItem : ri.getUseTaxItems()) {
93 PurchaseOrderItemUseTax newItemUseTax = new PurchaseOrderItemUseTax(useTaxItem);
94 newItemUseTax.setItemIdentifier(itemIdentifier);
95 this.getUseTaxItems().add(newItemUseTax);
96
97 }
98
99 this.setExternalOrganizationB2bProductReferenceNumber(ri.getExternalOrganizationB2bProductReferenceNumber());
100 this.setExternalOrganizationB2bProductTypeName(ri.getExternalOrganizationB2bProductTypeName());
101
102 this.setItemReceivedTotalQuantity(ZERO);
103 this.setItemDamagedTotalQuantity(ZERO);
104
105 this.setItemTypeCode(ri.getItemTypeCode());
106
107 if (ri.getSourceAccountingLines() != null && ri.getSourceAccountingLines().size() > 0 &&
108 !StringUtils.equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ORDER_DISCOUNT_CODE, ri.getItemType().getItemTypeCode())) {
109 List accounts = new ArrayList();
110 for (PurApAccountingLine account : ri.getSourceAccountingLines()) {
111 PurchaseOrderAccount poAccount = new PurchaseOrderAccount(account);
112 poAccount.setPurchaseOrderItem(this);
113 accounts.add(poAccount);
114 }
115 this.setSourceAccountingLines(accounts);
116 }
117
118
119
120 this.setItemActiveIndicator(true);
121
122 this.setPurchasingCommodityCode(ri.getPurchasingCommodityCode());
123 this.setCommodityCode(getCommodityCode());
124
125
126 if (ObjectUtils.isNotNull(reqCamsItem)) {
127 PurchaseOrderCapitalAssetItem newPOCapitalAssetItem = new PurchaseOrderCapitalAssetItem(reqCamsItem, itemIdentifier);
128 po.getPurchasingCapitalAssetItems().add(newPOCapitalAssetItem);
129 }
130 }
131
132 public boolean isItemActiveIndicator() {
133 return itemActiveIndicator;
134 }
135
136
137
138
139
140
141 public List<OleNotes> getNotes() {
142 return notes;
143 }
144
145 public void setNotes(List<OleNotes> notes) {
146 this.notes = notes;
147 }
148
149 public String getNote() {
150 return note;
151 }
152
153 public void setNote(String note) {
154 this.note = note;
155 }
156
157 public Integer getNoteTypeId() {
158 return noteTypeId;
159 }
160
161 public void setNoteTypeId(Integer noteTypeId) {
162 this.noteTypeId = noteTypeId;
163 }
164
165 public void setItemActiveIndicator(boolean itemActiveIndicator) {
166 this.itemActiveIndicator = itemActiveIndicator;
167 }
168
169 public KualiDecimal getItemInvoicedTotalAmount() {
170 return itemInvoicedTotalAmount;
171 }
172
173 public void setItemInvoicedTotalAmount(KualiDecimal itemInvoicedTotalAmount) {
174 this.itemInvoicedTotalAmount = itemInvoicedTotalAmount;
175 }
176
177 public KualiDecimal getItemInvoicedTotalQuantity() {
178 return itemInvoicedTotalQuantity;
179 }
180
181 public void setItemInvoicedTotalQuantity(KualiDecimal itemInvoicedTotalQuantity) {
182 this.itemInvoicedTotalQuantity = itemInvoicedTotalQuantity;
183 }
184
185 public KualiDecimal getItemOutstandingEncumberedQuantity() {
186 return itemOutstandingEncumberedQuantity;
187 }
188
189 public void setItemOutstandingEncumberedQuantity(KualiDecimal itemOutstandingEncumberedQuantity) {
190 this.itemOutstandingEncumberedQuantity = itemOutstandingEncumberedQuantity;
191 }
192
193 public KualiDecimal getItemOutstandingEncumberedAmount() {
194 return itemOutstandingEncumberedAmount;
195 }
196
197 public void setItemOutstandingEncumberedAmount(KualiDecimal itemOutstandingEncumbranceAmount) {
198 this.itemOutstandingEncumberedAmount = itemOutstandingEncumbranceAmount;
199 }
200
201 public KualiDecimal getItemReceivedTotalQuantity() {
202 return itemReceivedTotalQuantity;
203 }
204
205 public void setItemReceivedTotalQuantity(KualiDecimal itemReceivedTotalQuantity) {
206 this.itemReceivedTotalQuantity = itemReceivedTotalQuantity;
207 }
208
209
210
211
212
213
214 public KualiDecimal getItemDamagedTotalQuantity() {
215 return itemDamagedTotalQuantity;
216 }
217
218
219
220
221
222
223 public void setItemDamagedTotalQuantity(KualiDecimal itemDamagedTotalQuantity) {
224 this.itemDamagedTotalQuantity = itemDamagedTotalQuantity;
225 }
226
227 public PurchaseOrderDocument getPurchaseOrder() {
228 if (ObjectUtils.isNull(purchaseOrder)) {
229 refreshReferenceObject(PurapPropertyConstants.PURAP_DOC);
230 }
231 return super.getPurapDocument();
232 }
233
234 public void setPurchaseOrder(PurchaseOrderDocument purchaseOrder) {
235 setPurapDocument(purchaseOrder);
236 }
237
238 public String getDocumentNumber() {
239 return documentNumber;
240 }
241
242 public void setDocumentNumber(String documentNumber) {
243 this.documentNumber = documentNumber;
244 }
245
246 public boolean isItemSelectedForRetransmitIndicator() {
247 return itemSelectedForRetransmitIndicator;
248 }
249
250 public void setItemSelectedForRetransmitIndicator(boolean itemSelectedForRetransmitIndicator) {
251 this.itemSelectedForRetransmitIndicator = itemSelectedForRetransmitIndicator;
252 }
253
254 public boolean isMovingToSplit() {
255 return movingToSplit;
256 }
257
258 public void setMovingToSplit(boolean movingToSplit) {
259 this.movingToSplit = movingToSplit;
260 }
261
262
263
264
265
266 protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
267 LinkedHashMap m = new LinkedHashMap();
268 m.put("documentNumber", this.documentNumber);
269 if (this.getItemIdentifier() != null) {
270 m.put("itemIdentifier", this.getItemIdentifier().toString());
271 }
272 return m;
273 }
274
275
276
277
278 public Class getAccountingLineClass() {
279 return PurchaseOrderAccount.class;
280 }
281
282
283
284
285
286
287 public KualiDecimal getItemPaidAmount() {
288 if (!(this.isItemActiveIndicator())) {
289 return KualiDecimal.ZERO;
290 }
291 return this.getItemInvoicedTotalAmount();
292 }
293
294 public KualiDecimal getItemEncumbranceRelievedAmount() {
295
296 if (this == null || !this.isItemActiveIndicator()) {
297 return KualiDecimal.ZERO;
298 }
299
300 KualiDecimal outstandingAmount = KualiDecimal.ZERO;
301 KualiDecimal totalEncumberance = this.getTotalAmount();
302
303 ItemType iT = this.getItemType();
304
305 if (iT.isAmountBasedGeneralLedgerIndicator()) {
306 outstandingAmount = outstandingAmount.add(this.getItemOutstandingEncumberedAmount());
307 } else {
308
309 BigDecimal qty = new BigDecimal(this.getOutstandingQuantity().toString());
310 outstandingAmount = outstandingAmount.add(new KualiDecimal(this.getItemUnitPrice().multiply(qty).setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
311
312 KualiDecimal itemTaxAmount = this.getItemTaxAmount() == null ? ZERO : this.getItemTaxAmount();
313 KualiDecimal outstandingTaxAmount = new KualiDecimal(qty).divide(this.getItemQuantity()).multiply(itemTaxAmount);
314 outstandingAmount = outstandingAmount.add(outstandingTaxAmount);
315 }
316
317
318 return totalEncumberance.subtract(outstandingAmount);
319 }
320
321
322
323
324
325
326
327 public void setOutstandingQuantity() {
328
329 }
330
331 public KualiDecimal getOutstandingQuantity() {
332 KualiDecimal outstandingQuantity = (this.getItemQuantity() != null) ? this.getItemQuantity() : KualiDecimal.ZERO;
333 KualiDecimal invoicedQuantity = (this.getItemInvoicedTotalQuantity() != null) ? this.getItemInvoicedTotalQuantity() : KualiDecimal.ZERO;
334 return outstandingQuantity.subtract(invoicedQuantity);
335 }
336
337 public boolean isCanInactivateItem() {
338 if (versionNumber == null) {
339
340 return false;
341 } else if (versionNumber != null && itemActiveIndicator && !getPurchaseOrder().getContainsUnpaidPaymentRequestsOrCreditMemos()) {
342 return true;
343 }
344 return false;
345 }
346
347
348
349
350
351
352
353
354
355 @Override
356 public PurApSummaryItem getSummaryItem() {
357 if (!this.itemActiveIndicator) {
358 return null;
359 } else {
360 return super.getSummaryItem();
361 }
362 }
363
364 public boolean isNewUnorderedItem() {
365 return SpringContext.getBean(PurchaseOrderService.class).isNewUnorderedItem(this);
366 }
367
368 @Override
369 public boolean isNewItemForAmendment() {
370 return SpringContext.getBean(PurchaseOrderService.class).isNewItemForAmendment(this);
371 }
372
373 @Override
374 public Class getUseTaxClass() {
375 return PurchaseOrderItemUseTax.class;
376 }
377
378
379 }