View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.select.businessobject;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.ole.DocumentUniqueIDPrefix;
20  import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.BibInfoRecord;
21  import org.kuali.ole.module.purap.PurapConstants;
22  import org.kuali.ole.module.purap.PurapPropertyConstants;
23  import org.kuali.ole.module.purap.businessobject.InvoiceItem;
24  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
25  import org.kuali.ole.module.purap.businessobject.PurApItemUseTax;
26  import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
27  import org.kuali.ole.module.purap.document.InvoiceDocument;
28  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
29  import org.kuali.ole.module.purap.document.service.OlePurapService;
30  import org.kuali.ole.module.purap.document.service.PurapService;
31  import org.kuali.ole.module.purap.exception.PurError;
32  import org.kuali.ole.module.purap.util.ExpiredOrClosedAccountEntry;
33  import org.kuali.ole.module.purap.util.PurApRelatedViews;
34  import org.kuali.ole.pojo.OleOrderRecord;
35  import org.kuali.ole.select.OleSelectConstant;
36  import org.kuali.ole.select.bo.OLELinkPurapDonor;
37  import org.kuali.ole.select.document.OleInvoiceDocument;
38  import org.kuali.ole.select.lookup.DocData;
39  import org.kuali.ole.sys.OLEConstants;
40  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
41  import org.kuali.ole.sys.businessobject.UnitOfMeasure;
42  import org.kuali.ole.sys.context.SpringContext;
43  import org.kuali.rice.core.api.util.type.AbstractKualiDecimal;
44  import org.kuali.rice.core.api.util.type.KualiDecimal;
45  import org.kuali.rice.core.api.util.type.KualiInteger;
46  import org.kuali.rice.kew.api.KewApiConstants;
47  import org.kuali.rice.kew.api.KewApiServiceLocator;
48  import org.kuali.rice.kew.api.doctype.DocumentType;
49  import org.kuali.rice.krad.util.KRADConstants;
50  import org.kuali.rice.krad.util.ObjectUtils;
51  
52  import java.math.BigDecimal;
53  import java.util.ArrayList;
54  import java.util.Date;
55  import java.util.HashMap;
56  import java.util.List;
57  
58  public class OleInvoiceItem extends InvoiceItem {
59  
60      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleInvoiceItem.class);
61      // Foreign Currency Conversion
62      private BigDecimal itemExtendedPrice;
63      protected String itemCurrencyType;
64      protected KualiDecimal itemForeignListPrice;
65      protected KualiDecimal itemForeignDiscount;
66      protected String itemForeignDiscountType;
67      protected KualiDecimal itemForeignDiscountAmt;
68      protected KualiDecimal itemForeignUnitCost;
69      protected KualiDecimal itemExchangeRate;
70      protected KualiDecimal itemUnitCostUSD;
71      protected KualiDecimal foreignCurrencyExtendedPrice;
72  
73      protected boolean itemRouteToRequestorIndicator;
74      protected boolean itemPublicViewIndicator;
75  
76      protected boolean debitItem = true;
77      protected String invoiceListPrice;
78      protected String invoiceForeignListPrice;
79      protected String additionalUnitPrice;
80      protected String localTitleId;
81  
82  
83      protected Integer formatTypeId;
84      protected KualiInteger itemNoOfParts;
85      protected KualiDecimal itemListPrice;
86      protected KualiDecimal itemDiscount;
87      private String discountItem;
88      protected String itemDiscountType;
89      protected BigDecimal itemSurcharge;
90      protected String note;
91      protected List<OleInvoiceNote> notes;
92      protected Integer poItemIdentifier;
93  
94      private Boolean relatedViewExist;
95      private transient PurApRelatedViews relatedViews;
96      private UnitOfMeasure itemUnitOfMeasure;
97  
98      private String vendorItemIdentifier;
99  
100     //BibInfo Details
101     private BibInfoBean bibInfoBean;
102     protected String itemTitleId;
103     protected String bibUUID;
104     private DocData docData;
105     private InvoiceDocument invoiceDocument;
106     private OleOrderRecord oleOrderRecord;
107     protected Integer receiptStatusId;
108     private OleReceiptStatus oleReceiptStatus;
109     private boolean useTaxIndicator;
110     /**
111      * For Quantity As Integer
112      */
113     private KualiInteger oleItemQuantity;
114     private String oleCopiesOrdered;
115     private KualiInteger olePoOutstandingQuantity;
116     private String oleOpenQuantity;
117     private OleFormatType formatType = new OleFormatType();
118     private String poItemLink;
119     private Date purchaseOrderEndDate;
120     private String docFormat;
121     //Subscription Date
122     private Date subscriptionFromDate;
123     private Date subscriptionToDate;
124     private boolean subscriptionOverlap;
125     private List<SourceAccountingLine> sourceAccountingLineList = new ArrayList<SourceAccountingLine>();
126     private OLEInvoiceOffsetAccountingLine oleInvoiceOffsetAccountingLine;
127 
128     private String donorCode;
129     private String donorId;
130     private List<OLELinkPurapDonor> oleDonors = new ArrayList<>();
131     private List<OLEPaidCopy> paidCopies = new ArrayList<>();
132     private Integer tempPurchaseOrderIdentifier;
133     private String listPrice;
134     private String foreignListPrice;
135     private String foreignUnitCost;
136     private String foreignDiscount;
137     private String exchangeRate;
138     private String invoicedCurrency;
139     protected String additionalForeignUnitCost;
140 
141     private Integer reLinkPO;
142     private Integer requisitionItemIdentifier;
143     private Integer tempItemIdentifier;
144     public String itemTitle;
145     private boolean enableDetailsSection=false;
146 
147     private BibInfoRecord bibInfoRecord;
148 
149     public BibInfoRecord getBibInfoRecord() {
150         return bibInfoRecord;
151     }
152 
153     public void setBibInfoRecord(BibInfoRecord bibInfoRecord) {
154         this.bibInfoRecord = bibInfoRecord;
155     }
156 
157     public Integer getTempItemIdentifier() {
158         return tempItemIdentifier;
159     }
160 
161     public void setTempItemIdentifier(Integer tempItemIdentifier) {
162         this.tempItemIdentifier = tempItemIdentifier;
163     }
164 
165     public String getDocFormat() {
166         return docFormat;
167     }
168 
169     public Integer getTempPurchaseOrderIdentifier() {
170         if (poItemIdentifier != null) {
171             tempPurchaseOrderIdentifier = getPurchaseOrderIdentifier();
172         } else {
173             tempPurchaseOrderIdentifier = null;
174         }
175         return tempPurchaseOrderIdentifier;
176     }
177 
178     public void setTempPurchaseOrderIdentifier(Integer tempPurchaseOrderIdentifier) {
179         this.tempPurchaseOrderIdentifier = tempPurchaseOrderIdentifier;
180     }
181 
182     public void setDocFormat(String docFormat) {
183         this.docFormat = docFormat;
184     }
185 
186     public String getOleOpenQuantity() {
187      /*   if (getPoOutstandingQuantity() != null) {
188             return String.valueOf(super.getPoOutstandingQuantity().intValue());
189         }*/
190         return oleOpenQuantity;
191     }
192 
193     public void setOleOpenQuantity(String oleOpenQuantity) {
194         this.oleOpenQuantity = oleOpenQuantity;
195     }
196 
197     public String getVendorItemIdentifier() {
198         return vendorItemIdentifier;
199     }
200 
201     public void setVendorItemIdentifier(String vendorItemIdentifier) {
202         this.vendorItemIdentifier = vendorItemIdentifier;
203     }
204 
205     public String getLocalTitleId() {
206         return localTitleId;
207     }
208 
209     public String getDonorCode() {
210         return donorCode;
211     }
212 
213     public void setDonorCode(String donorCode) {
214         this.donorCode = donorCode;
215     }
216 
217     public String getDonorId() {
218         return donorId;
219     }
220 
221     public void setDonorId(String donorId) {
222         this.donorId = donorId;
223     }
224 
225     public List<OLELinkPurapDonor> getOleDonors() {
226         return oleDonors;
227     }
228 
229     public void setOleDonors(List<OLELinkPurapDonor> oleDonors) {
230         this.oleDonors = oleDonors;
231     }
232 
233     public void setLocalTitleId(String localTitleId) {
234         this.localTitleId = localTitleId;
235     }
236 
237     /**
238      * Gets the value of the receiptStatusId property
239      *
240      * @return receiptStatusId
241      */
242     public Integer getReceiptStatusId() {
243         return receiptStatusId;
244     }
245 
246     /**
247      * Sets the receiptStatusId value
248      *
249      * @param receiptStatusId
250      */
251     public void setReceiptStatusId(Integer receiptStatusId) {
252         this.receiptStatusId = receiptStatusId;
253     }
254 
255     /**
256      * Gets the instance of OleReceiptStatus
257      *
258      * @return oleReceiptStatus
259      */
260     public OleReceiptStatus getOleReceiptStatus() {
261         return oleReceiptStatus;
262     }
263 
264     /**
265      * Sets the instance value for OleReceiptStatus
266      *
267      * @param oleReceiptStatus
268      */
269     public void setOleReceiptStatus(OleReceiptStatus oleReceiptStatus) {
270         this.oleReceiptStatus = oleReceiptStatus;
271     }
272 
273     public OleOrderRecord getOleOrderRecord() {
274         return oleOrderRecord;
275     }
276 
277     public void setOleOrderRecord(OleOrderRecord oleOrderRecord) {
278         this.oleOrderRecord = oleOrderRecord;
279     }
280 
281     // added for jira - OLE-2203
282     protected boolean additionalChargeUsd;
283 
284     /**
285      * Constructs a OleInvoiceItem.java.
286      */
287     public OleInvoiceItem() {
288         this.setItemNoOfParts(new KualiInteger(1));
289         this.setItemUnitOfMeasureCode(PurapConstants.InvoiceDocumentStrings.CUSTOMER_INVOICE_DETAIL_UOM_DEFAULT);
290         this.setOleItemQuantity(new KualiInteger(1));
291         this.setItemListPrice(new KualiDecimal(0.00));
292         notes = new ArrayList<OleInvoiceNote>();
293     }
294 
295     /**
296      * Constructs a OleInvoiceItem.java.
297      *
298      * @param poi
299      * @param prqs
300      * @param expiredOrClosedAccountList
301      */
302     public OleInvoiceItem(PurchaseOrderItem poi, InvoiceDocument prqs, HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList) {
303         super(poi, prqs, expiredOrClosedAccountList);
304         this.setInvoiceDocument(prqs);
305         LOG.debug("Inside OleInvoiceItem Constructor");
306         LOG.debug("Setting the Format,Discount and Price Details");
307         notes = new ArrayList<OleInvoiceNote>();
308 
309         OlePurchaseOrderItem olePoi = (OlePurchaseOrderItem) poi;
310         olePoi.getItemTypeCode();
311         notes.addAll(olePoi.getInvoiceNotes());
312         this.setItemForeignDiscount(olePoi.getInvoiceForeignDiscount() != null ? new KualiDecimal(olePoi.getInvoiceForeignDiscount()) : new KualiDecimal(0.00));
313         this.setForeignDiscount(olePoi.getInvoiceForeignDiscount());
314         this.setItemForeignDiscountType(olePoi.getInvoiceForeignDiscountType());
315         this.setItemForeignDiscountAmt(olePoi.getItemForeignDiscountAmt());
316         this.setItemCurrencyType(olePoi.getInvoiceForeignCurrency() != null ? olePoi.getInvoiceForeignCurrency() : olePoi.getItemCurrencyType());
317         this.setInvoicedCurrency(olePoi.getInvoiceForeignCurrency() != null ? olePoi.getInvoiceForeignCurrency() : olePoi.getItemCurrencyType());
318         this.setItemExchangeRate(olePoi.getInvoiceExchangeRate() != null ? new KualiDecimal(olePoi.getInvoiceExchangeRate()) : new KualiDecimal(0.00));
319         this.setExchangeRate(olePoi.getInvoiceExchangeRate() != null ? olePoi.getInvoiceExchangeRate() : null);
320         this.setItemUnitCostUSD(olePoi.getItemUnitCostUSD());
321         this.setFormatTypeId(olePoi.getFormatTypeId());
322         this.setItemNoOfParts(olePoi.getNoOfPartsInvoiced());
323         this.setOleDonors(olePoi.getOleDonors());
324         this.setItemListPrice(olePoi.getItemListPrice());
325         this.setItemDiscount(olePoi.getItemDiscount() != null ? olePoi.getItemDiscount() : new KualiDecimal(0.00));
326         this.setItemDiscountType(olePoi.getItemDiscountType());
327         this.setItemCatalogNumber(olePoi.getItemCatalogNumber());
328         this.setPoItemIdentifier(olePoi.getItemIdentifier());
329         this.setExtendedPrice(olePoi.getExtendedPrice());
330         this.setItemQuantity(olePoi.getItemQuantity());
331         this.setBibInfoBean(olePoi.getBibInfoBean());
332         if (olePoi.getItemTitleId() != null) {
333             this.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(olePoi.getItemTitleId()));
334         }
335         this.setItemTitleId(olePoi.getItemTitleId());
336         if (olePoi.getNoOfCopiesInvoiced() != null) {
337             this.setItemQuantity(olePoi.getNoOfCopiesInvoiced().kualiDecimalValue());
338         }
339         if (new KualiDecimal(olePoi.getInvoiceItemListPrice()).isLessThan(AbstractKualiDecimal.ZERO)) {
340             this.setInvoiceListPrice(olePoi.getInvoiceItemListPrice());
341             this.setListPrice(olePoi.getInvoiceItemListPrice());
342 
343         } else {
344             this.setItemListPrice(new KualiDecimal(olePoi.getInvoiceItemListPrice()));
345         }
346         if (new KualiDecimal(olePoi.getInvoiceForeignItemListPrice()).isLessThan(AbstractKualiDecimal.ZERO)) {
347             this.setInvoiceForeignListPrice(olePoi.getInvoiceForeignItemListPrice());
348             this.setForeignListPrice(olePoi.getInvoiceForeignItemListPrice());
349         }   else {
350             this.setItemForeignListPrice(new KualiDecimal(olePoi.getInvoiceForeignItemListPrice()));
351         }
352         //this.setInvoiceListPrice(olePoi.getInvoiceItemListPrice());
353         this.setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(this).setScale(4, BigDecimal.ROUND_HALF_UP));
354         this.setItemForeignUnitCost(SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(this).itemForeignUnitCost);
355         this.setForeignUnitCost(this.getItemForeignUnitCost().toString());
356         this.setExtendedPrice(this.calculateExtendedPrice());
357         this.setReceiptStatusId(olePoi.getReceiptStatusId());
358         this.setItemSurcharge(olePoi.getItemSurcharge());
359         this.setPurapDocumentIdentifier(prqs.getPurapDocumentIdentifier());
360 
361         this.setSubscriptionOverlap(olePoi.isSubscriptionOverlap());
362         this.setSubscriptionFromDate(olePoi.getSubscriptionFromDate());
363         this.setSubscriptionToDate(olePoi.getSubscriptionToDate());
364         this.setItemRouteToRequestorIndicator(olePoi.isItemRouteToRequestorIndicator());
365         this.setItemPublicViewIndicator(olePoi.isItemPublicViewIndicator());
366     }
367 
368     /**
369      * Constructs a OleInvoiceItem.java.
370      *
371      * @param poi
372      * @param prqs
373      */
374     public OleInvoiceItem(PurchaseOrderItem poi, InvoiceDocument prqs) {
375         super(poi, prqs);
376         this.setInvoiceDocument(prqs);
377         LOG.debug("Inside OleInvoiceItem Constructor");
378         LOG.debug("Setting the Format,Discount and Price Details");
379         notes = new ArrayList<OleInvoiceNote>();
380         OlePurchaseOrderItem olePoi = (OlePurchaseOrderItem) poi;
381         notes.addAll(olePoi.getInvoiceNotes());
382         this.setItemForeignDiscount(olePoi.getInvoiceForeignDiscount() != null? new KualiDecimal(olePoi.getInvoiceForeignDiscount()) : new KualiDecimal(0.00));
383         this.setForeignDiscount(olePoi.getInvoiceForeignDiscount());
384         this.setItemForeignDiscountType(olePoi.getItemForeignDiscountType());
385         this.setItemForeignDiscountAmt(olePoi.getItemForeignDiscountAmt());
386         this.setItemForeignUnitCost(olePoi.getItemForeignUnitCost());
387         this.setItemTitleId(olePoi.getItemTitleId());
388         this.setItemCurrencyType(olePoi.getInvoiceForeignCurrency()!=null ? olePoi.getInvoiceForeignCurrency() : olePoi.getItemCurrencyType());
389         this.setInvoicedCurrency(olePoi.getInvoiceForeignCurrency()!=null? olePoi.getInvoiceForeignCurrency() : olePoi.getItemCurrencyType());
390         this.setItemExchangeRate(olePoi.getInvoiceExchangeRate()!= null ? new KualiDecimal(olePoi.getInvoiceExchangeRate()) : new KualiDecimal(0.00));
391         this.setExchangeRate(olePoi.getInvoiceExchangeRate()!= null? olePoi.getInvoiceExchangeRate() : null);
392         this.setItemUnitCostUSD(olePoi.getItemUnitCostUSD());
393         this.setOleDonors(olePoi.getOleDonors());
394         this.setFormatTypeId(olePoi.getFormatTypeId());
395         this.setItemNoOfParts(olePoi.getItemNoOfParts());
396         this.setItemListPrice(olePoi.getItemListPrice());
397         this.setItemDiscount(olePoi.getItemDiscount() != null ? olePoi.getItemDiscount() : new KualiDecimal(0.00));
398         this.setItemDiscountType(olePoi.getItemDiscountType());
399         this.setItemCatalogNumber(olePoi.getItemCatalogNumber());
400         if (olePoi.getItemTitleId() != null) {
401             this.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(olePoi.getItemTitleId()));
402         }
403         this.setPoItemIdentifier(olePoi.getItemIdentifier());
404         if (olePoi.getNoOfCopiesInvoiced() != null) {
405             this.setItemQuantity(olePoi.getNoOfCopiesInvoiced().kualiDecimalValue());
406         }
407         if (new KualiDecimal(olePoi.getInvoiceItemListPrice()).isLessThan(AbstractKualiDecimal.ZERO)) {
408             this.setInvoiceListPrice(olePoi.getInvoiceItemListPrice());
409             this.setListPrice(olePoi.getInvoiceItemListPrice());
410 
411         } else {
412             this.setItemListPrice(new KualiDecimal(olePoi.getInvoiceItemListPrice()));
413         }
414         if (new KualiDecimal(olePoi.getInvoiceForeignItemListPrice()).isLessThan(AbstractKualiDecimal.ZERO)) {
415             this.setInvoiceForeignListPrice(olePoi.getInvoiceForeignItemListPrice());
416             this.setForeignListPrice(olePoi.getInvoiceForeignItemListPrice());
417         }   else {
418             this.setItemForeignListPrice(new KualiDecimal(olePoi.getInvoiceForeignItemListPrice()));
419         }
420         //this.setInvoiceListPrice(olePoi.getInvoiceItemListPrice());
421         this.setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(this).setScale(4, BigDecimal.ROUND_HALF_UP));
422         this.setItemForeignUnitCost(SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(this).itemForeignUnitCost);
423         this.setForeignUnitCost(this.getItemForeignUnitCost().toString());
424         this.setExtendedPrice(this.calculateExtendedPrice());
425         this.setPurapDocumentIdentifier(prqs.getPurapDocumentIdentifier());
426         this.setItemRouteToRequestorIndicator(olePoi.isItemRouteToRequestorIndicator());
427         this.setItemPublicViewIndicator(olePoi.isItemPublicViewIndicator());
428     }
429 
430     @Override
431     public boolean isConsideredEnteredWithZero() {
432         return isConsideredEntered(true);
433     }
434 
435     @Override
436     public boolean isConsideredEnteredWithoutZero() {
437         return isConsideredEntered(false);
438     }
439 
440     private boolean isConsideredEntered(boolean allowsZero) {
441         if (getItemType().isLineItemIndicator()) {
442             if ((getItemType().isQuantityBasedGeneralLedgerIndicator())) {
443                 if ((ObjectUtils.isNull(getItemQuantity()) || getItemQuantity().isZero()) && (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero()))) {
444                     return false;
445                 }
446             } else {
447                 if (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero())) {
448                     return false;
449                 }
450             }
451         } else {
452             if ((ObjectUtils.isNull(getItemUnitPrice()) || (allowsZero && this.getItemUnitPrice().compareTo(new BigDecimal(0)) == 0)) && (StringUtils.isBlank(getItemDescription()))) {
453                 return false;
454             }
455         }
456 
457         return true;
458     }
459 
460     public String getItemCurrencyType() {
461         return itemCurrencyType;
462     }
463 
464     public void setItemCurrencyType(String itemCurrencyType) {
465         this.itemCurrencyType = itemCurrencyType;
466     }
467 
468     public KualiDecimal getItemForeignListPrice() {
469         return itemForeignListPrice;
470     }
471 
472     public void setItemForeignListPrice(KualiDecimal itemForeignListPrice) {
473         this.itemForeignListPrice = itemForeignListPrice;
474     }
475 
476     public KualiDecimal getItemForeignDiscount() {
477         return itemForeignDiscount;
478     }
479 
480     public void setItemForeignDiscount(KualiDecimal itemForeignDiscount) {
481         this.itemForeignDiscount = itemForeignDiscount;
482     }
483 
484     public String getItemForeignDiscountType() {
485         return itemForeignDiscountType;
486     }
487 
488     public void setItemForeignDiscountType(String itemForeignDiscountType) {
489         this.itemForeignDiscountType = itemForeignDiscountType;
490     }
491 
492     public KualiDecimal getItemForeignDiscountAmt() {
493         return itemForeignDiscountAmt;
494     }
495 
496     public void setItemForeignDiscountAmt(KualiDecimal itemForeignDiscountAmt) {
497         this.itemForeignDiscountAmt = itemForeignDiscountAmt;
498     }
499 
500     public KualiDecimal getItemForeignUnitCost() {
501         return itemForeignUnitCost;
502     }
503 
504     public void setItemForeignUnitCost(KualiDecimal itemForeignUnitCost) {
505         this.itemForeignUnitCost = itemForeignUnitCost;
506     }
507 
508     public String getInvoicedCurrency() {
509         return invoicedCurrency;
510     }
511 
512     public void setInvoicedCurrency(String invoicedCurrency) {
513         this.invoicedCurrency = invoicedCurrency;
514     }
515 
516     public String getExchangeRate() {
517         if (exchangeRate != null && !exchangeRate.isEmpty()) {
518             return exchangeRate;
519         } else {
520             return itemExchangeRate!= null? itemExchangeRate.toString() :null;
521         }
522     }
523 
524     public void setExchangeRate(String exchangeRate) {
525         this.exchangeRate = exchangeRate;
526     }
527 
528     public String getForeignDiscount() {
529         if (foreignDiscount != null && !foreignDiscount.isEmpty()) {
530             return foreignDiscount;
531         } else {
532             return itemForeignDiscount!= null? itemForeignDiscount.toString() :null;
533         }
534     }
535 
536     public void setForeignDiscount(String foreignDiscount) {
537         this.foreignDiscount = foreignDiscount;
538     }
539 
540     public String getForeignUnitCost() {
541         if (foreignUnitCost != null && !foreignUnitCost.isEmpty()) {
542             return foreignUnitCost;
543         } else {
544             if (!debitItem) {
545                 return itemForeignUnitCost != null ?  "(" + itemForeignUnitCost.toString().replace("-", "") + ")" : null;
546             } else {
547                 return itemForeignUnitCost.toString();
548             }
549         }
550     }
551 
552     public void setForeignUnitCost(String foreignUnitCost) {
553         this.foreignUnitCost = foreignUnitCost;
554         if (foreignUnitCost != null) {
555             if (foreignUnitCost.contains("(") || foreignUnitCost.contains(")")) {
556                 foreignUnitCost = foreignUnitCost.replace("(", "");
557                 foreignUnitCost = foreignUnitCost.replace(")", "");
558                 foreignUnitCost = "-" + foreignUnitCost;
559                 this.foreignUnitCost = foreignUnitCost;
560             }
561             if (new KualiDecimal(foreignUnitCost).isLessThan(KualiDecimal.ZERO)) {
562                 foreignUnitCost = foreignUnitCost.replace("-", "");
563                 foreignUnitCost = "(" + foreignUnitCost + ")";
564                 this.foreignUnitCost = foreignUnitCost;
565             } else {
566                 this.foreignUnitCost = foreignUnitCost;
567             }
568         }
569 
570     }
571 
572     public String getAdditionalForeignUnitCost() {
573         if (!isDebitItem()) {
574             additionalForeignUnitCost =  this.getItemForeignUnitCost() != null ? this.getItemForeignUnitCost().negated().toString() : null;
575         } else{
576             additionalForeignUnitCost =  this.getItemForeignUnitCost() != null ? this.getItemForeignUnitCost().toString() : null;
577         }
578         return this.additionalForeignUnitCost;
579     }
580 
581     public void setAdditionalForeignUnitCost(String additionalForeignUnitCost) {
582         if (additionalForeignUnitCost != null && !additionalForeignUnitCost.isEmpty() &&
583                 (new KualiDecimal(additionalForeignUnitCost)).isLessThan(AbstractKualiDecimal.ZERO)) {
584           //  this.setDebitItem(false);
585             this.setItemForeignUnitCost(new KualiDecimal(additionalForeignUnitCost).abs());
586             this.additionalForeignUnitCost = additionalForeignUnitCost;
587         } else if (additionalForeignUnitCost != null && !additionalForeignUnitCost.isEmpty() &&
588                 (new KualiDecimal(additionalForeignUnitCost)).isGreaterEqual(AbstractKualiDecimal.ZERO)) {
589           //  this.setDebitItem(true);
590             this.setItemForeignUnitCost((new KualiDecimal(additionalForeignUnitCost)));
591             this.additionalForeignUnitCost = additionalForeignUnitCost;
592         }
593         else {
594             this.setItemForeignUnitCost(null);
595             this.additionalForeignUnitCost = additionalForeignUnitCost;
596         }
597     }
598 
599     public KualiDecimal getItemExchangeRate() {
600         return itemExchangeRate;
601     }
602 
603     public void setItemExchangeRate(KualiDecimal itemExchangeRate) {
604         this.itemExchangeRate = itemExchangeRate;
605     }
606 
607     public KualiDecimal getItemUnitCostUSD() {
608         return itemUnitCostUSD;
609     }
610 
611     public void setItemUnitCostUSD(KualiDecimal itemUnitCostUSD) {
612         this.itemUnitCostUSD = itemUnitCostUSD;
613     }
614 
615     public Integer getFormatTypeId() {
616         return formatTypeId;
617     }
618 
619     public void setFormatTypeId(Integer formatTypeId) {
620         this.formatTypeId = formatTypeId;
621     }
622 
623     public KualiInteger getItemNoOfParts() {
624         if (this.itemNoOfParts != null) {
625             return itemNoOfParts;
626         } else {
627             return itemNoOfParts;
628         }
629     }
630 
631     public void setItemNoOfParts(KualiInteger itemNoOfParts) {
632         this.itemNoOfParts = itemNoOfParts;
633     }
634 
635     public KualiDecimal getItemListPrice() {
636         return itemListPrice;
637     }
638 
639     public void setItemListPrice(KualiDecimal itemListPrice) {
640         this.itemListPrice = itemListPrice;
641     }
642 
643     public String getDiscountItem() {
644         return String.valueOf(itemDiscount) != null ? String.valueOf(itemDiscount) : "0";
645     }
646 
647     public void setDiscountItem(String discountItem) {
648         this.itemDiscount = new KualiDecimal(discountItem);
649     }
650 
651     public KualiDecimal getItemDiscount() {
652         return itemDiscount;
653     }
654 
655     public void setItemDiscount(KualiDecimal itemDiscount) {
656         this.itemDiscount = itemDiscount;
657     }
658 
659     public String getItemDiscountType() {
660         return itemDiscountType;
661     }
662 
663     public void setItemDiscountType(String itemDiscountType) {
664         this.itemDiscountType = itemDiscountType;
665     }
666 
667     public BigDecimal getItemSurcharge() {
668         return itemSurcharge;
669     }
670 
671     public void setItemSurcharge(BigDecimal itemSurcharge) {
672         this.itemSurcharge = itemSurcharge;
673     }
674 
675     public Integer getPoItemIdentifier() {
676         return poItemIdentifier;
677     }
678 
679     public void setPoItemIdentifier(Integer poItemIdentifier) {
680         this.poItemIdentifier = poItemIdentifier;
681     }
682 
683     public String getNote() {
684         return note;
685     }
686 
687     public void setNote(String note) {
688         this.note = note;
689     }
690 
691     public List<OleInvoiceNote> getNotes() {
692         return notes;
693     }
694 
695     public void setNotes(List<OleInvoiceNote> notes) {
696         this.notes = notes;
697     }
698 
699     public UnitOfMeasure getItemUnitOfMeasure() {
700         if (ObjectUtils.isNull(itemUnitOfMeasure) || !StringUtils.equalsIgnoreCase(itemUnitOfMeasure.getItemUnitOfMeasureCode(), getItemUnitOfMeasureCode())) {
701             refreshReferenceObject(PurapPropertyConstants.ITEM_UNIT_OF_MEASURE);
702         }
703         return itemUnitOfMeasure;
704     }
705 
706     public void setItemUnitOfMeasure(UnitOfMeasure itemUnitOfMeasure) {
707         this.itemUnitOfMeasure = itemUnitOfMeasure;
708     }
709 
710     public boolean getIsUnorderedItem() {
711         if (this.getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
712             return false;
713         }
714         return true;
715     }
716 
717     public KualiDecimal getForeignCurrencyExtendedPrice() {
718         return foreignCurrencyExtendedPrice;
719     }
720 
721     public void setForeignCurrencyExtendedPrice(KualiDecimal foreignCurrencyExtendedPrice) {
722         this.foreignCurrencyExtendedPrice = foreignCurrencyExtendedPrice;
723     }
724 
725     public String getItemTitleId() {
726         return itemTitleId;
727     }
728 
729     public void setItemTitleId(String itemTitleId) {
730         this.itemTitleId = itemTitleId;
731     }
732 
733     public BibInfoBean getBibInfoBean() {
734         return bibInfoBean;
735     }
736 
737     public void setBibInfoBean(BibInfoBean bibInfoBean) {
738         this.bibInfoBean = bibInfoBean;
739     }
740 
741     public String getBibUUID() {
742         return bibUUID;
743     }
744 
745     public void setBibUUID(String bibUUID) {
746         this.bibUUID = bibUUID;
747     }
748 
749     public DocData getDocData() {
750         return docData;
751     }
752 
753     public void setDocData(DocData docData) {
754         this.docData = docData;
755     }
756 
757     public InvoiceDocument getInvoiceDocument() {
758         return invoiceDocument;
759     }
760 
761     public void setInvoiceDocument(InvoiceDocument invoiceDocument) {
762         setPurapDocument(invoiceDocument);
763         this.invoiceDocument = invoiceDocument;
764     }
765 
766     public boolean isAdditionalChargeUsd() {
767         return additionalChargeUsd;
768     }
769 
770     public void setAdditionalChargeUsd(boolean additionalChargeUsd) {
771         this.additionalChargeUsd = additionalChargeUsd;
772     }
773 
774     public String getOleCopiesOrdered() {
775         return String.valueOf(super.getItemQuantity().intValue());
776     }
777 
778     public void setOleCopiesOrdered(String oleCopiesOrdered) {
779         super.setItemQuantity(new KualiDecimal(oleCopiesOrdered));
780     }
781 
782     /**
783      * Gets the oleItemQuantity attribute.
784      *
785      * @return Returns the oleItemQuantity.
786      */
787     public KualiInteger getOleItemQuantity() {
788         return new KualiInteger(super.getItemQuantity().intValue());
789     }
790 
791     /**
792      * Sets the oleItemQuantity attribute value.
793      *
794      * @param oleItemQuantity The oleItemQuantity to set.
795      */
796     public void setOleItemQuantity(KualiInteger oleItemQuantity) {
797         super.setItemQuantity(new KualiDecimal(oleItemQuantity.intValue()));
798     }
799 
800     /**
801      * Gets the olePoOutstandingQuantity attribute.
802      *
803      * @return Returns the olePoOutstandingQuantity.
804      */
805     public KualiInteger getOlePoOutstandingQuantity() {
806         if (getPoOutstandingQuantity() != null) {
807             return new KualiInteger(super.getPoOutstandingQuantity().intValue());
808         }
809         return new KualiInteger(0);
810     }
811 
812     /**
813      * Sets the olePoOutstandingQuantity attribute value.
814      *
815      * @param olePoOutstandingQuantity The olePoOutstandingQuantity to set.
816      */
817     public void setOlePoOutstandingQuantity(KualiInteger olePoOutstandingQuantity) {
818         if (olePoOutstandingQuantity != null) {
819             super.setPoOutstandingQuantity(new KualiDecimal(olePoOutstandingQuantity.intValue()));
820         }
821     }
822 
823     public boolean isUseTaxIndicator() {
824         return useTaxIndicator;
825     }
826 
827     public void setUseTaxIndicator(boolean useTaxIndicator) {
828         this.useTaxIndicator = useTaxIndicator;
829     }
830 
831     @Override
832     public KualiDecimal getItemTaxAmount() {
833         KualiDecimal taxAmount = KualiDecimal.ZERO;
834 
835         /*if (ObjectUtils.isNull(purapDocument)) {
836             this.refreshReferenceObject("purapDocument");
837         }*/
838 
839         if (this.isUseTaxIndicator() == false) {
840             taxAmount = this.getItemSalesTaxAmount();
841         } else {
842             // sum use tax item tax amounts
843             for (PurApItemUseTax useTaxItem : this.getUseTaxItems()) {
844                 taxAmount = taxAmount.add(useTaxItem.getTaxAmount());
845             }
846         }
847 
848         return taxAmount;
849     }
850 
851     public OleFormatType getFormatType() {
852         return formatType;
853     }
854 
855     public void setFormatType(OleFormatType formatType) {
856         this.formatType = formatType;
857     }
858 
859     public PurApRelatedViews getRelatedViews() {
860         /*if (!getRelatedViewExist()) {
861             relatedViews = new PurApRelatedViews(this.getInvoiceDocument() != null ? this.getInvoiceDocument().getDocumentNumber() : null,
862                     this.getAccountsPayablePurchasingDocumentLinkIdentifier() != null ? this.getAccountsPayablePurchasingDocumentLinkIdentifier() : null);
863             ;
864         }*/
865         return relatedViews;
866     }
867 
868     public void setRelatedViews(PurApRelatedViews relatedViews) {
869         this.relatedViews = relatedViews;
870     }
871 
872     public Boolean getRelatedViewExist() {
873         if (this.relatedViews != null) {
874             this.relatedViewExist = Boolean.TRUE;
875         } else {
876             this.relatedViewExist = Boolean.FALSE;
877         }
878         return relatedViewExist;
879     }
880 
881     public void setRelatedViewExist(Boolean relatedViewExist) {
882         this.relatedViewExist = relatedViewExist;
883     }
884 
885     public boolean isDebitItem() {
886         return debitItem;
887     }
888 
889     public void setDebitItem(boolean debitItem) {
890         this.debitItem = debitItem;
891     }
892 
893     public String getInvoiceListPrice() {
894         if (!isDebitItem()) {
895             return this.getItemListPrice() != null ? this.getItemListPrice().negated().toString() : null;
896         }
897         return itemListPrice.toString();
898     }
899 
900     public void setInvoiceListPrice(String invoiceListPrice) {
901         if (invoiceListPrice != null && !invoiceListPrice.isEmpty() &&
902                 (new KualiDecimal(invoiceListPrice)).isLessThan(AbstractKualiDecimal.ZERO)) {
903             this.setDebitItem(false);
904         } else {
905             this.setDebitItem(true);
906         }
907         this.setItemListPrice((new KualiDecimal(invoiceListPrice)).abs());
908         this.invoiceListPrice = invoiceListPrice;
909     }
910 
911     public String getInvoiceForeignListPrice() {
912         if (!isDebitItem()) {
913             return this.getItemForeignListPrice() != null ? this.getItemForeignListPrice().negated().toString() : null;
914         }
915         return invoiceForeignListPrice;
916     }
917 
918     public void setInvoiceForeignListPrice(String invoiceForeignListPrice) {
919         if (invoiceForeignListPrice != null && !invoiceForeignListPrice.isEmpty() &&
920                 (new KualiDecimal(invoiceForeignListPrice)).isLessThan(AbstractKualiDecimal.ZERO)) {
921             this.setDebitItem(false);
922         } else {
923             this.setDebitItem(true);
924         }
925         this.setItemForeignListPrice((new KualiDecimal(invoiceForeignListPrice)).abs());
926         this.invoiceForeignListPrice = invoiceForeignListPrice;
927     }
928 
929     public String getAdditionalUnitPrice() {
930         if (!isDebitItem()) {
931             additionalUnitPrice =  this.getItemUnitPrice() != null ? this.getItemUnitPrice().negate().toString() : null;
932         } else{
933             additionalUnitPrice =  this.getItemUnitPrice() != null ? this.getItemUnitPrice().toString() : null;
934         }
935         return this.additionalUnitPrice;
936     }
937 
938     public String getListPrice() {
939         if (listPrice != null && !listPrice.isEmpty()) {
940             return listPrice;
941         } else if (invoiceListPrice != null && new KualiDecimal(invoiceListPrice).isLessThan(KualiDecimal.ZERO)) {
942             return "(" + invoiceListPrice.replace("-", "") + ")";
943         } else {
944             if (!debitItem) {
945                 return "(" + itemListPrice.toString().replace("-", "") + ")";
946             } else {
947                 return itemListPrice.toString();
948             }
949         }
950     }
951 
952     public void setListPrice(String listPrice) {
953         this.listPrice = listPrice;
954         if (listPrice.contains("(") || listPrice.contains(")")) {
955             listPrice = listPrice.replace("(", "");
956             listPrice = listPrice.replace(")", "");
957             listPrice = "-" + listPrice;
958             this.listPrice = listPrice;
959         }
960         if (new KualiDecimal(listPrice).isLessThan(KualiDecimal.ZERO)) {
961             this.setInvoiceListPrice(listPrice);
962             listPrice = listPrice.replace("-", "");
963             listPrice = "(" + listPrice + ")";
964             this.listPrice = listPrice;
965         } else {
966             this.setInvoiceListPrice(listPrice);
967             this.listPrice = listPrice;
968         }
969 
970     }
971 
972     public String getForeignListPrice() {
973         if (foreignListPrice != null && !foreignListPrice.isEmpty()) {
974             return foreignListPrice;
975         } else if (invoiceForeignListPrice != null && new KualiDecimal(invoiceForeignListPrice).isLessThan(KualiDecimal.ZERO)) {
976             return "(" + invoiceForeignListPrice.replace("-", "") + ")";
977         } else {
978             if (!debitItem) {
979                 return "(" + itemForeignListPrice.toString().replace("-", "") + ")";
980             } else {
981                 return itemForeignListPrice.toString();
982             }
983         }
984     }
985 
986     public void setForeignListPrice(String foreignListPrice) {
987         this.foreignListPrice = foreignListPrice;
988         if(foreignListPrice != null) {
989         if (foreignListPrice.contains("(") || foreignListPrice.contains(")")) {
990             foreignListPrice = foreignListPrice.replace("(", "");
991             foreignListPrice = foreignListPrice.replace(")", "");
992             foreignListPrice = "-" + foreignListPrice;
993             this.foreignListPrice = foreignListPrice;
994         }
995         if (new KualiDecimal(foreignListPrice).isLessThan(KualiDecimal.ZERO)) {
996             this.setInvoiceForeignListPrice(foreignListPrice);
997             foreignListPrice = foreignListPrice.replace("-", "");
998             foreignListPrice = "(" + foreignListPrice + ")";
999             this.foreignListPrice = foreignListPrice;
1000         } else {
1001             this.setInvoiceForeignListPrice(foreignListPrice);
1002             this.foreignListPrice = foreignListPrice;
1003         }
1004         }
1005     }
1006 
1007     public void setAdditionalUnitPrice(String additionalUnitPrice) {
1008         if (additionalUnitPrice != null && !additionalUnitPrice.isEmpty() &&
1009                 (new KualiDecimal(additionalUnitPrice)).isLessThan(AbstractKualiDecimal.ZERO)) {
1010             this.setDebitItem(false);
1011             this.setItemUnitPrice((new BigDecimal(additionalUnitPrice)).abs());
1012             this.additionalUnitPrice = additionalUnitPrice;
1013         } else if (additionalUnitPrice != null && !additionalUnitPrice.isEmpty() &&
1014                 (new KualiDecimal(additionalUnitPrice)).isGreaterEqual(AbstractKualiDecimal.ZERO)) {
1015             this.setDebitItem(true);
1016             this.setItemUnitPrice((new BigDecimal(additionalUnitPrice)));
1017             this.additionalUnitPrice = additionalUnitPrice;
1018         }
1019         else {
1020             this.setItemUnitPrice(null);
1021             this.additionalUnitPrice = additionalUnitPrice;
1022         }
1023 
1024     }
1025 
1026     public String getPoItemLink() {
1027         if (poItemIdentifier != null) {
1028             String documentTypeName = PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_DOCUMENT;
1029             DocumentType docType = KewApiServiceLocator.getDocumentTypeService().getDocumentTypeByName(documentTypeName);
1030             String docHandlerUrl = docType.getResolvedDocumentHandlerUrl();
1031             int endSubString = docHandlerUrl.lastIndexOf("/");
1032             String serverName = docHandlerUrl.substring(0, endSubString);
1033             String handler = docHandlerUrl.substring(endSubString + 1, docHandlerUrl.lastIndexOf("?"));
1034             poItemLink = serverName + "/" + KRADConstants.PORTAL_ACTION + "?channelTitle=" + docType.getName() + "&channelUrl=" +
1035                     handler + "?" + KRADConstants.DISPATCH_REQUEST_PARAMETER + "=" + KRADConstants.DOC_HANDLER_METHOD + "&" +
1036                     KRADConstants.PARAMETER_DOC_ID + "=" + this.getPurchaseOrderDocument().getDocumentNumber() + "&" + KRADConstants.PARAMETER_COMMAND + "=" +
1037                     KewApiConstants.DOCSEARCH_COMMAND;
1038 
1039         } else {
1040             poItemLink = "";
1041         }
1042         return poItemLink;
1043     }
1044 
1045     public void setPoItemLink(String poItemLink) {
1046         this.poItemLink = poItemLink;
1047     }
1048 
1049     public Date getSubscriptionFromDate() {
1050         return subscriptionFromDate;
1051     }
1052 
1053     public void setSubscriptionFromDate(Date subscriptionFromDate) {
1054         this.subscriptionFromDate = subscriptionFromDate;
1055     }
1056 
1057     public Date getSubscriptionToDate() {
1058         return subscriptionToDate;
1059     }
1060 
1061     public void setSubscriptionToDate(Date subscriptionToDate) {
1062         this.subscriptionToDate = subscriptionToDate;
1063     }
1064 
1065     public boolean isSubscriptionOverlap() {
1066         return subscriptionOverlap;
1067     }
1068 
1069     public void setSubscriptionOverlap(boolean subscriptionOverlap) {
1070         this.subscriptionOverlap = subscriptionOverlap;
1071     }
1072 
1073     public Date getPurchaseOrderEndDate() {
1074         return purchaseOrderEndDate;
1075     }
1076 
1077     public void setPurchaseOrderEndDate(Date purchaseOrderEndDate) {
1078         this.purchaseOrderEndDate = purchaseOrderEndDate;
1079     }
1080 
1081 
1082     public void setPaidCopies(List<OLEPaidCopy> paidCopies) {
1083         this.paidCopies = paidCopies;
1084     }
1085 
1086     public List<OLEPaidCopy> getPaidCopies() {
1087         return paidCopies;
1088     }
1089 
1090     public void setOleInvoiceOffsetAccountingLine(OLEInvoiceOffsetAccountingLine oleInvoiceOffsetAccountingLine) {
1091         this.oleInvoiceOffsetAccountingLine = oleInvoiceOffsetAccountingLine;
1092     }
1093 
1094     public List<SourceAccountingLine> getSourceAccountingLineList() {
1095         return sourceAccountingLineList;
1096     }
1097 
1098     public void setSourceAccountingLineList(List<SourceAccountingLine> sourceAccountingLineList) {
1099         this.sourceAccountingLineList = sourceAccountingLineList;
1100     }
1101 
1102     public OLEInvoiceOffsetAccountingLine getOleInvoiceOffsetAccountingLine() {
1103         return oleInvoiceOffsetAccountingLine;
1104     }
1105 
1106     public Integer getReLinkPO() {
1107         return reLinkPO;
1108     }
1109 
1110     public void setReLinkPO(Integer reLinkPO) {
1111         this.reLinkPO = reLinkPO;
1112     }
1113 
1114     @Override
1115     public PurchaseOrderItem getPurchaseOrderItem() {
1116         InvoiceDocument invDoc = getInvoice();
1117        /* if (ObjectUtils.isNotNull(this.getPurapDocumentIdentifier())) {
1118             if (ObjectUtils.isNull(this.getInvoice())) {
1119                 this.refreshReferenceObject(PurapPropertyConstants.PURAP_DOC);
1120             }
1121         }*/
1122         PurchaseOrderItem poi = null;
1123         // ideally we should do this a different way - maybe move it all into the service or save this info somehow (make sure and
1124         // update though)
1125         if (invDoc!= null) {
1126             PurchaseOrderDocument po = invDoc.getPurchaseOrderDocument(this.getPurchaseOrderIdentifier());
1127             if (po != null) {
1128                 this.setPostingYear(po.getPostingYear());
1129                 if (po.getRecurringPaymentType() != null) {
1130                     this.setRecurringPaymentType(po.getRecurringPaymentType());
1131                     this.setRecurringPaymentTypeCode(po.getRecurringPaymentTypeCode());
1132 
1133                 }
1134 
1135                 if (this.getItemType().isLineItemIndicator() && this.getItemLineNumber() != null && this.getItemLineNumber()< 0) {
1136                     List<PurchaseOrderItem> items = po.getItems();
1137                     poi = items.get(this.getItemLineNumber().intValue() - 1);
1138                     // throw error if line numbers don't match
1139                     // MSU Contribution DTT-3014 OLEMI-8483 OLECNTRB-974
1140                     /*
1141                     * List items = po.getItems(); if (items != null) { for (Object object : items) { PurchaseOrderItem item =
1142                     * (PurchaseOrderItem) object; if (item != null && item.getItemLineNumber().equals(this.getItemLineNumber())) { poi
1143                     * = item; break; } } }
1144                     */
1145                 } else if (this.getItemType().isLineItemIndicator()) {
1146                     List<PurchaseOrderItem> items = po.getItems();
1147                     for (int count = 0; count < items.size(); count++) {
1148                         if (this.getPoItemIdentifier() != null) {
1149                             if (this.getPoItemIdentifier().compareTo((items.get(count)).getItemIdentifier()) == 0) {
1150                                 this.setItemLineNumber(items.get(count).getItemLineNumber());
1151                                 poi = items.get(this.getItemLineNumber().intValue() - 1);
1152                                 break;
1153                             }
1154                         }
1155                         //items.get(count).getItemLineNumber();
1156                     }
1157                 } else {
1158                     poi = (PurchaseOrderItem) SpringContext.getBean(PurapService.class).getBelowTheLineByType(po, this.getItemType());
1159                     if (poi != null) {
1160                         this.setItemLineNumber(poi.getItemLineNumber());
1161                     }
1162                 }
1163             }
1164 
1165             if (poi != null) {
1166                 this.setPoItem(poi);
1167                 return poi;
1168             } else {
1169                 if (LOG.isDebugEnabled()) {
1170                     LOG.debug("getPurchaseOrderItem() Returning null because PurchaseOrderItem object for line number" + getItemLineNumber() + "or itemType " + getItemTypeCode() + " is null");
1171                 }
1172                 return null;
1173             }
1174         } else {
1175 
1176             LOG.error("getPurchaseOrderItem() Returning null because invoice object is null");
1177             throw new PurError("Payment Request Object in Purchase Order item line number " + getItemLineNumber() + "or itemType " + getItemTypeCode() + " is null");
1178         }
1179     }
1180 
1181     public Integer getRequisitionItemIdentifier() {
1182         return requisitionItemIdentifier;
1183     }
1184 
1185     public void setRequisitionItemIdentifier(Integer requisitionItemIdentifier) {
1186         this.requisitionItemIdentifier = requisitionItemIdentifier;
1187     }
1188 
1189     //Added for Jira OLE-5370
1190     public String getItemTitle() {
1191         itemTitle = getItemDescription();
1192         if(itemTitle.contains(OLEConstants.ANGLE_BRACKET_LESS_THAN)){
1193             itemTitle = itemTitle.replace(OLEConstants.ANGLE_BRACKET_LESS_THAN,"&#60;");
1194         }
1195         if(itemTitle.contains(OLEConstants.ANGLE_BRACKET_GREATER_THAN)){
1196             itemTitle = itemTitle.replace(OLEConstants.ANGLE_BRACKET_GREATER_THAN,"&#62;");
1197         }
1198         return itemTitle;
1199     }
1200 
1201     public void setItemTitle(String itemTitle) {
1202         this.itemTitle = itemTitle;
1203     }
1204 
1205     public boolean isItemPublicViewIndicator() {
1206         return itemPublicViewIndicator;
1207     }
1208 
1209     public void setItemPublicViewIndicator(boolean itemPublicViewIndicator) {
1210         this.itemPublicViewIndicator = itemPublicViewIndicator;
1211     }
1212 
1213     public boolean isItemRouteToRequestorIndicator() {
1214         return itemRouteToRequestorIndicator;
1215     }
1216 
1217     public void setItemRouteToRequestorIndicator(boolean itemRouteToRequestorIndicator) {
1218         this.itemRouteToRequestorIndicator = itemRouteToRequestorIndicator;
1219     }
1220 
1221     public boolean isEnableDetailsSection() {
1222         return enableDetailsSection;
1223     }
1224 
1225     public void setEnableDetailsSection(boolean enableDetailsSection) {
1226         this.enableDetailsSection = enableDetailsSection;
1227     }
1228     
1229     public BigDecimal getItemExtendedPrice() {
1230         return calculateItemExtendedPrice();
1231     }
1232 
1233 
1234     public BigDecimal calculateItemExtendedPrice() {
1235         BigDecimal extendedPrice = BigDecimal.ZERO;
1236         BigDecimal itemUnitPrice = getItemUnitPrice();
1237         if (ObjectUtils.isNotNull(itemUnitPrice)) {
1238             if (this.getItemType().isAmountBasedGeneralLedgerIndicator()) {
1239                 // SERVICE ITEM: return unit price as extended price
1240                 extendedPrice = itemUnitPrice;
1241             } else if (ObjectUtils.isNotNull(this.getItemQuantity())) {
1242                 BigDecimal calcExtendedPrice = itemUnitPrice.multiply(this.getItemQuantity().bigDecimalValue());
1243                 // ITEM TYPE (qty driven): return (unitPrice x qty)
1244                 extendedPrice = calcExtendedPrice.setScale(4, KualiDecimal.ROUND_BEHAVIOR);
1245             }
1246         }
1247         return extendedPrice;
1248     }
1249 
1250     @Override
1251     public KualiDecimal getTotalAmount() {
1252         KualiDecimal totalAmount = getExtendedPrice();
1253         if (ObjectUtils.isNull(totalAmount)) {
1254             totalAmount = KualiDecimal.ZERO;
1255         }
1256 
1257         KualiDecimal taxAmount = getItemTaxAmount();
1258         if (ObjectUtils.isNull(taxAmount)) {
1259             taxAmount = KualiDecimal.ZERO;
1260         }
1261 
1262         totalAmount = totalAmount.add(taxAmount);
1263 
1264         return totalAmount;
1265     }
1266 
1267     public BigDecimal getInvoiceTotalAmount() {
1268         BigDecimal totalAmount = getItemExtendedPrice();
1269         if (ObjectUtils.isNull(totalAmount)) {
1270             totalAmount = BigDecimal.ZERO;
1271         }
1272 
1273         KualiDecimal taxAmount = getItemTaxAmount();
1274         if (ObjectUtils.isNull(taxAmount)) {
1275             taxAmount = KualiDecimal.ZERO;
1276         }
1277 
1278         totalAmount = totalAmount.add(taxAmount.bigDecimalValue());
1279 
1280         return totalAmount;
1281     }
1282 
1283 
1284     public KualiDecimal getForeignTotalAmount() {
1285         KualiDecimal totalAmount = calculateForeignExtendedPrice();
1286         if (ObjectUtils.isNull(totalAmount)) {
1287             totalAmount = KualiDecimal.ZERO;
1288         }
1289 
1290         KualiDecimal taxAmount = getItemTaxAmount();
1291         if (ObjectUtils.isNull(taxAmount)) {
1292             taxAmount = KualiDecimal.ZERO;
1293         }
1294 
1295         totalAmount = totalAmount.add(taxAmount);
1296 
1297         return totalAmount;
1298     }
1299 
1300     public KualiDecimal calculateForeignExtendedPrice() {
1301         KualiDecimal extendedPrice = KualiDecimal.ZERO;
1302         if (this.getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)) {
1303             if (ObjectUtils.isNotNull(itemForeignUnitCost)) {
1304                 if (this.getItemType().isAmountBasedGeneralLedgerIndicator()) {
1305                     extendedPrice = new KualiDecimal(this.itemForeignUnitCost.toString());
1306                 } else if (ObjectUtils.isNotNull(this.getItemQuantity())) {
1307                     BigDecimal calcExtendedPrice = this.itemForeignUnitCost.bigDecimalValue().multiply(this.getItemQuantity().bigDecimalValue());
1308                     extendedPrice = new KualiDecimal(calcExtendedPrice.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR));
1309                 }
1310             }
1311         }
1312         return extendedPrice;
1313     }
1314 
1315 
1316 }