1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.businessobject;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.businessobject.InvoiceItem;
22 import org.kuali.ole.module.purap.businessobject.PurApItemUseTax;
23 import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
24 import org.kuali.ole.module.purap.document.InvoiceDocument;
25 import org.kuali.ole.module.purap.util.ExpiredOrClosedAccountEntry;
26 import org.kuali.ole.module.purap.util.PurApRelatedViews;
27 import org.kuali.ole.pojo.OleOrderRecord;
28 import org.kuali.ole.select.OleSelectConstant;
29 import org.kuali.ole.select.lookup.DocData;
30 import org.kuali.ole.sys.businessobject.UnitOfMeasure;
31 import org.kuali.rice.core.api.util.type.KualiDecimal;
32 import org.kuali.rice.core.api.util.type.KualiInteger;
33 import org.kuali.rice.krad.util.ObjectUtils;
34
35 import java.math.BigDecimal;
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39
40 public class OleInvoiceItem extends InvoiceItem {
41
42 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleInvoiceItem.class);
43
44 protected String itemCurrencyType;
45 protected KualiDecimal itemForeignListPrice;
46 protected KualiDecimal itemForeignDiscount;
47 protected String itemForeignDiscountType;
48 protected KualiDecimal itemForeignDiscountAmt;
49 protected KualiDecimal itemForeignUnitCost;
50 protected KualiDecimal itemExchangeRate;
51 protected KualiDecimal itemUnitCostUSD;
52 protected KualiDecimal foreignCurrencyExtendedPrice;
53
54 protected Integer formatTypeId;
55 protected KualiInteger itemNoOfParts;
56 protected KualiDecimal itemListPrice;
57 protected KualiDecimal itemDiscount;
58 private String discountItem;
59 protected String itemDiscountType;
60 protected BigDecimal itemSurcharge;
61 protected String note;
62 protected List<OleInvoiceNote> notes;
63 protected Integer poItemIdentifier;
64
65 private String relatedViewExist;
66 private PurApRelatedViews relatedViews = null;
67 private UnitOfMeasure itemUnitOfMeasure;
68
69
70 private BibInfoBean bibInfoBean;
71 protected String itemTitleId;
72 protected String bibUUID;
73 private DocData docData;
74 private InvoiceDocument invoiceDocument;
75 private OleOrderRecord oleOrderRecord;
76 protected Integer receiptStatusId;
77 private OleReceiptStatus oleReceiptStatus;
78 private boolean useTaxIndicator;
79
80
81
82 private KualiInteger oleItemQuantity;
83 private String oleCopiesOrdered;
84 private KualiInteger olePoOutstandingQuantity;
85 private String oleOpenQuantity;
86 private OleFormatType formatType = new OleFormatType();
87
88
89
90 public String getOleOpenQuantity() {
91 if (getPoOutstandingQuantity() != null) {
92 return String.valueOf(super.getPoOutstandingQuantity().intValue());
93 }
94 return "0";
95 }
96
97 public void setOleOpenQuantity(String oleOpenQuantity) {
98 if (oleOpenQuantity != null) {
99 super.setPoOutstandingQuantity(new KualiDecimal(oleOpenQuantity));
100 }
101 }
102
103
104
105
106
107
108
109 public Integer getReceiptStatusId() {
110 return receiptStatusId;
111 }
112
113
114
115
116
117
118 public void setReceiptStatusId(Integer receiptStatusId) {
119 this.receiptStatusId = receiptStatusId;
120 }
121
122
123
124
125
126
127 public OleReceiptStatus getOleReceiptStatus() {
128 return oleReceiptStatus;
129 }
130
131
132
133
134
135
136 public void setOleReceiptStatus(OleReceiptStatus oleReceiptStatus) {
137 this.oleReceiptStatus = oleReceiptStatus;
138 }
139
140 public OleOrderRecord getOleOrderRecord() {
141 return oleOrderRecord;
142 }
143
144 public void setOleOrderRecord(OleOrderRecord oleOrderRecord) {
145 this.oleOrderRecord = oleOrderRecord;
146 }
147
148
149 protected boolean additionalChargeUsd;
150
151
152
153
154 public OleInvoiceItem() {
155 this.setItemNoOfParts(new KualiInteger(1));
156 this.setItemUnitOfMeasureCode(PurapConstants.InvoiceDocumentStrings.CUSTOMER_INVOICE_DETAIL_UOM_DEFAULT);
157 this.setOleItemQuantity(new KualiInteger(1));
158 this.setItemListPrice(new KualiDecimal(0.00));
159 notes = new ArrayList<OleInvoiceNote>();
160
161 this.setItemCurrencyType(OleSelectConstant.USD);
162 }
163
164
165
166
167
168
169
170
171 public OleInvoiceItem(PurchaseOrderItem poi, InvoiceDocument prqs, HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList) {
172 super(poi, prqs, expiredOrClosedAccountList);
173 this.setInvoiceDocument(prqs);
174 LOG.debug("Inside OleInvoiceItem Constructor");
175 LOG.debug("Setting the Format,Discount and Price Details");
176 notes = new ArrayList<OleInvoiceNote>();
177
178 OlePurchaseOrderItem olePoi = (OlePurchaseOrderItem) poi;
179 olePoi.getItemTypeCode();
180 notes.addAll(olePoi.getInvoiceNotes());
181 this.setItemForeignListPrice(olePoi.getItemForeignListPrice());
182 this.setItemForeignDiscount(olePoi.getItemForeignDiscount());
183 this.setItemForeignDiscountType(olePoi.getItemForeignDiscountType());
184 this.setItemForeignDiscountAmt(olePoi.getItemForeignDiscountAmt());
185 this.setItemForeignUnitCost(olePoi.getItemForeignUnitCost());
186 this.setItemExchangeRate(olePoi.getItemExchangeRate());
187 this.setItemUnitCostUSD(olePoi.getItemUnitCostUSD());
188 this.setFormatTypeId(olePoi.getFormatTypeId());
189 this.setItemNoOfParts(olePoi.getNoOfPartsInvoiced());
190 this.setItemListPrice(olePoi.getItemListPrice());
191 this.setItemDiscount(olePoi.getItemDiscount());
192 this.setItemDiscountType(olePoi.getItemDiscountType());
193 this.setItemCatalogNumber(olePoi.getItemCatalogNumber());
194 this.setPoItemIdentifier(olePoi.getItemIdentifier());
195 this.setExtendedPrice(olePoi.getExtendedPrice());
196 this.setBibInfoBean(olePoi.getBibInfoBean());
197 this.setItemTitleId(olePoi.getItemTitleId());
198 this.setItemQuantity(olePoi.getNoOfCopiesInvoiced().kualiDecimalValue());
199 this.setItemListPrice(new KualiDecimal(olePoi.getInvoiceItemListPrice()));
200
201 this.setItemCurrencyType(OleSelectConstant.USD);
202 this.setReceiptStatusId(olePoi.getReceiptStatusId());
203 this.setItemSurcharge(olePoi.getItemSurcharge());
204 this.setPurapDocumentIdentifier(prqs.getPurapDocumentIdentifier());
205 }
206
207
208
209
210
211
212
213 public OleInvoiceItem(PurchaseOrderItem poi, InvoiceDocument prqs) {
214 super(poi, prqs);
215 this.setInvoiceDocument(prqs);
216 LOG.debug("Inside OleInvoiceItem Constructor");
217 LOG.debug("Setting the Format,Discount and Price Details");
218 notes = new ArrayList<OleInvoiceNote>();
219 OlePurchaseOrderItem olePoi = (OlePurchaseOrderItem) poi;
220 notes.addAll(olePoi.getInvoiceNotes());
221 this.setItemForeignListPrice(olePoi.getItemForeignListPrice());
222 this.setItemForeignDiscount(olePoi.getItemForeignDiscount());
223 this.setItemForeignDiscountType(olePoi.getItemForeignDiscountType());
224 this.setItemForeignDiscountAmt(olePoi.getItemForeignDiscountAmt());
225 this.setItemForeignUnitCost(olePoi.getItemForeignUnitCost());
226 this.setItemExchangeRate(olePoi.getItemExchangeRate());
227 this.setItemUnitCostUSD(olePoi.getItemUnitCostUSD());
228 this.setFormatTypeId(olePoi.getFormatTypeId());
229 this.setItemNoOfParts(olePoi.getItemNoOfParts());
230 this.setItemListPrice(olePoi.getItemListPrice());
231 this.setItemDiscount(olePoi.getItemDiscount());
232 this.setItemDiscountType(olePoi.getItemDiscountType());
233 this.setItemCatalogNumber(olePoi.getItemCatalogNumber());
234 this.setPoItemIdentifier(olePoi.getItemIdentifier());
235
236 this.setItemCurrencyType(OleSelectConstant.USD);
237 this.setPurapDocumentIdentifier(prqs.getPurapDocumentIdentifier());
238 }
239
240 @Override
241 public boolean isConsideredEnteredWithZero() {
242 return isConsideredEntered(true);
243 }
244
245 @Override
246 public boolean isConsideredEnteredWithoutZero() {
247 return isConsideredEntered(false);
248 }
249
250 private boolean isConsideredEntered(boolean allowsZero) {
251 if (getItemType().isLineItemIndicator()) {
252 if ((getItemType().isQuantityBasedGeneralLedgerIndicator())) {
253 if ((ObjectUtils.isNull(getItemQuantity()) || getItemQuantity().isZero()) && (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero()))) {
254 return false;
255 }
256 } else {
257 if (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero())) {
258 return false;
259 }
260 }
261 } else {
262 if ((ObjectUtils.isNull(getItemUnitPrice()) || (allowsZero && this.getItemUnitPrice().compareTo(new BigDecimal(0)) == 0)) && (StringUtils.isBlank(getItemDescription()))) {
263 return false;
264 }
265 }
266
267 return true;
268 }
269
270 public String getItemCurrencyType() {
271 return itemCurrencyType;
272 }
273
274 public void setItemCurrencyType(String itemCurrencyType) {
275 this.itemCurrencyType = itemCurrencyType;
276 }
277
278 public KualiDecimal getItemForeignListPrice() {
279 return itemForeignListPrice;
280 }
281
282 public void setItemForeignListPrice(KualiDecimal itemForeignListPrice) {
283 this.itemForeignListPrice = itemForeignListPrice;
284 }
285
286 public KualiDecimal getItemForeignDiscount() {
287 return itemForeignDiscount;
288 }
289
290 public void setItemForeignDiscount(KualiDecimal itemForeignDiscount) {
291 this.itemForeignDiscount = itemForeignDiscount;
292 }
293
294 public String getItemForeignDiscountType() {
295 return itemForeignDiscountType;
296 }
297
298 public void setItemForeignDiscountType(String itemForeignDiscountType) {
299 this.itemForeignDiscountType = itemForeignDiscountType;
300 }
301
302 public KualiDecimal getItemForeignDiscountAmt() {
303 return itemForeignDiscountAmt;
304 }
305
306 public void setItemForeignDiscountAmt(KualiDecimal itemForeignDiscountAmt) {
307 this.itemForeignDiscountAmt = itemForeignDiscountAmt;
308 }
309
310 public KualiDecimal getItemForeignUnitCost() {
311 return itemForeignUnitCost;
312 }
313
314 public void setItemForeignUnitCost(KualiDecimal itemForeignUnitCost) {
315 this.itemForeignUnitCost = itemForeignUnitCost;
316 }
317
318 public KualiDecimal getItemExchangeRate() {
319 return itemExchangeRate;
320 }
321
322 public void setItemExchangeRate(KualiDecimal itemExchangeRate) {
323 this.itemExchangeRate = itemExchangeRate;
324 }
325
326 public KualiDecimal getItemUnitCostUSD() {
327 return itemUnitCostUSD;
328 }
329
330 public void setItemUnitCostUSD(KualiDecimal itemUnitCostUSD) {
331 this.itemUnitCostUSD = itemUnitCostUSD;
332 }
333
334 public Integer getFormatTypeId() {
335 return formatTypeId;
336 }
337
338 public void setFormatTypeId(Integer formatTypeId) {
339 this.formatTypeId = formatTypeId;
340 }
341
342 public KualiInteger getItemNoOfParts() {
343 if (this.itemNoOfParts != null) {
344 return itemNoOfParts;
345 } else {
346 return itemNoOfParts;
347 }
348 }
349
350 public void setItemNoOfParts(KualiInteger itemNoOfParts) {
351 this.itemNoOfParts = itemNoOfParts;
352 }
353
354 public KualiDecimal getItemListPrice() {
355 return itemListPrice;
356 }
357
358 public void setItemListPrice(KualiDecimal itemListPrice) {
359 this.itemListPrice = itemListPrice;
360 }
361
362 public String getDiscountItem() {
363 return String.valueOf(itemDiscount);
364 }
365
366 public void setDiscountItem(String discountItem) {
367 this.itemDiscount = new KualiDecimal(discountItem);
368 }
369
370 public KualiDecimal getItemDiscount() {
371 return itemDiscount;
372 }
373
374 public void setItemDiscount(KualiDecimal itemDiscount) {
375 this.itemDiscount = itemDiscount;
376 }
377
378 public String getItemDiscountType() {
379 return itemDiscountType;
380 }
381
382 public void setItemDiscountType(String itemDiscountType) {
383 this.itemDiscountType = itemDiscountType;
384 }
385
386 public BigDecimal getItemSurcharge() {
387 return itemSurcharge;
388 }
389
390 public void setItemSurcharge(BigDecimal itemSurcharge) {
391 this.itemSurcharge = itemSurcharge;
392 }
393
394 public Integer getPoItemIdentifier() {
395 return poItemIdentifier;
396 }
397
398 public void setPoItemIdentifier(Integer poItemIdentifier) {
399 this.poItemIdentifier = poItemIdentifier;
400 }
401
402 public String getNote() {
403 return note;
404 }
405
406 public void setNote(String note) {
407 this.note = note;
408 }
409
410 public List<OleInvoiceNote> getNotes() {
411 return notes;
412 }
413
414 public void setNotes(List<OleInvoiceNote> notes) {
415 this.notes = notes;
416 }
417
418 public UnitOfMeasure getItemUnitOfMeasure() {
419 if (ObjectUtils.isNull(itemUnitOfMeasure) || !StringUtils.equalsIgnoreCase(itemUnitOfMeasure.getItemUnitOfMeasureCode(), getItemUnitOfMeasureCode())) {
420 refreshReferenceObject(PurapPropertyConstants.ITEM_UNIT_OF_MEASURE);
421 }
422 return itemUnitOfMeasure;
423 }
424
425 public void setItemUnitOfMeasure(UnitOfMeasure itemUnitOfMeasure) {
426 this.itemUnitOfMeasure = itemUnitOfMeasure;
427 }
428
429 public boolean getIsUnorderedItem() {
430 if (this.getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
431 return false;
432 }
433 return true;
434 }
435
436 public KualiDecimal getForeignCurrencyExtendedPrice() {
437 return foreignCurrencyExtendedPrice;
438 }
439
440 public void setForeignCurrencyExtendedPrice(KualiDecimal foreignCurrencyExtendedPrice) {
441 this.foreignCurrencyExtendedPrice = foreignCurrencyExtendedPrice;
442 }
443
444 public String getItemTitleId() {
445 return itemTitleId;
446 }
447
448 public void setItemTitleId(String itemTitleId) {
449 this.itemTitleId = itemTitleId;
450 }
451
452 public BibInfoBean getBibInfoBean() {
453 return bibInfoBean;
454 }
455
456 public void setBibInfoBean(BibInfoBean bibInfoBean) {
457 this.bibInfoBean = bibInfoBean;
458 }
459
460 public String getBibUUID() {
461 return bibUUID;
462 }
463
464 public void setBibUUID(String bibUUID) {
465 this.bibUUID = bibUUID;
466 }
467
468 public DocData getDocData() {
469 return docData;
470 }
471
472 public void setDocData(DocData docData) {
473 this.docData = docData;
474 }
475
476 public InvoiceDocument getInvoiceDocument() {
477 return invoiceDocument;
478 }
479
480 public void setInvoiceDocument(InvoiceDocument invoiceDocument) {
481 setPurapDocument(invoiceDocument);
482 this.invoiceDocument = invoiceDocument;
483 }
484
485 public boolean isAdditionalChargeUsd() {
486 return additionalChargeUsd;
487 }
488
489 public void setAdditionalChargeUsd(boolean additionalChargeUsd) {
490 this.additionalChargeUsd = additionalChargeUsd;
491 }
492
493 public String getOleCopiesOrdered() {
494 return String.valueOf(super.getItemQuantity().intValue());
495 }
496
497 public void setOleCopiesOrdered(String oleCopiesOrdered) {
498 super.setItemQuantity(new KualiDecimal(oleCopiesOrdered));
499 }
500
501
502
503
504
505
506 public KualiInteger getOleItemQuantity() {
507 return new KualiInteger(super.getItemQuantity().intValue());
508 }
509
510
511
512
513
514
515 public void setOleItemQuantity(KualiInteger oleItemQuantity) {
516 super.setItemQuantity(new KualiDecimal(oleItemQuantity.intValue()));
517 }
518
519
520
521
522
523
524 public KualiInteger getOlePoOutstandingQuantity() {
525 if (getPoOutstandingQuantity() != null) {
526 return new KualiInteger(super.getPoOutstandingQuantity().intValue());
527 }
528 return new KualiInteger(0);
529 }
530
531
532
533
534
535
536 public void setOlePoOutstandingQuantity(KualiInteger olePoOutstandingQuantity) {
537 if (olePoOutstandingQuantity != null) {
538 super.setPoOutstandingQuantity(new KualiDecimal(olePoOutstandingQuantity.intValue()));
539 }
540 }
541
542 public boolean isUseTaxIndicator() {
543 return useTaxIndicator;
544 }
545
546 public void setUseTaxIndicator(boolean useTaxIndicator) {
547 this.useTaxIndicator = useTaxIndicator;
548 }
549
550 @Override
551 public KualiDecimal getItemTaxAmount() {
552 KualiDecimal taxAmount = KualiDecimal.ZERO;
553
554
555
556
557
558 if (this.isUseTaxIndicator() == false) {
559 taxAmount = this.getItemSalesTaxAmount();
560 } else {
561
562 for (PurApItemUseTax useTaxItem : this.getUseTaxItems()) {
563 taxAmount = taxAmount.add(useTaxItem.getTaxAmount());
564 }
565 }
566
567 return taxAmount;
568 }
569
570 public OleFormatType getFormatType() {
571 return formatType;
572 }
573
574 public void setFormatType(OleFormatType formatType) {
575 this.formatType = formatType;
576 }
577
578 public PurApRelatedViews getRelatedViews() {
579 if (relatedViews == null) {
580 relatedViews = new PurApRelatedViews(this.getInvoiceDocument().getDocumentNumber(),
581 this.getAccountsPayablePurchasingDocumentLinkIdentifier());
582 }
583 return relatedViews;
584 }
585
586 public void setRelatedViews(PurApRelatedViews relatedViews) {
587 this.relatedViews = relatedViews;
588 }
589
590 public String getRelatedViewExist() {
591 if (this.relatedViews != null) {
592 this.relatedViewExist = "true";
593 } else {
594 this.relatedViewExist = "false";
595 }
596 return relatedViewExist;
597 }
598
599 public void setRelatedViewExist(String relatedViewExist) {
600 this.relatedViewExist = relatedViewExist;
601 }
602 }