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 (relatedViews == null) {
861             relatedViews = new PurApRelatedViews(
862             		this.getInvoiceDocument() != null ? this.getInvoiceDocument().getDocumentNumber()
863             				: null,
864                     this.getAccountsPayablePurchasingDocumentLinkIdentifier() != null ?
865                     		this.getAccountsPayablePurchasingDocumentLinkIdentifier() : null);
866         }
867         return relatedViews;
868     }
869 
870     public void setRelatedViews(PurApRelatedViews relatedViews) {
871         this.relatedViews = relatedViews;
872     }
873 
874     public Boolean getRelatedViewExist() {
875         if (this.relatedViews != null) {
876             this.relatedViewExist = Boolean.TRUE;
877         } else {
878             this.relatedViewExist = Boolean.FALSE;
879         }
880         return relatedViewExist;
881     }
882 
883     public void setRelatedViewExist(Boolean relatedViewExist) {
884         this.relatedViewExist = relatedViewExist;
885     }
886 
887     public boolean isDebitItem() {
888         return debitItem;
889     }
890 
891     public void setDebitItem(boolean debitItem) {
892         this.debitItem = debitItem;
893     }
894 
895     public String getInvoiceListPrice() {
896         if (!isDebitItem()) {
897             return this.getItemListPrice() != null ? this.getItemListPrice().negated().toString() : null;
898         }
899         return itemListPrice.toString();
900     }
901 
902     public void setInvoiceListPrice(String invoiceListPrice) {
903         if (invoiceListPrice != null && !invoiceListPrice.isEmpty() &&
904                 (new KualiDecimal(invoiceListPrice)).isLessThan(AbstractKualiDecimal.ZERO)) {
905             this.setDebitItem(false);
906         } else {
907             this.setDebitItem(true);
908         }
909         this.setItemListPrice((new KualiDecimal(invoiceListPrice)).abs());
910         this.invoiceListPrice = invoiceListPrice;
911     }
912 
913     public String getInvoiceForeignListPrice() {
914         if (!isDebitItem()) {
915             return this.getItemForeignListPrice() != null ? this.getItemForeignListPrice().negated().toString() : null;
916         }
917         return invoiceForeignListPrice;
918     }
919 
920     public void setInvoiceForeignListPrice(String invoiceForeignListPrice) {
921         if (invoiceForeignListPrice != null && !invoiceForeignListPrice.isEmpty() &&
922                 (new KualiDecimal(invoiceForeignListPrice)).isLessThan(AbstractKualiDecimal.ZERO)) {
923             this.setDebitItem(false);
924         } else {
925             this.setDebitItem(true);
926         }
927         this.setItemForeignListPrice((new KualiDecimal(invoiceForeignListPrice)).abs());
928         this.invoiceForeignListPrice = invoiceForeignListPrice;
929     }
930 
931     public String getAdditionalUnitPrice() {
932         if (!isDebitItem()) {
933             additionalUnitPrice =  this.getItemUnitPrice() != null ? this.getItemUnitPrice().negate().toString() : null;
934         } else{
935             additionalUnitPrice =  this.getItemUnitPrice() != null ? this.getItemUnitPrice().toString() : null;
936         }
937         return this.additionalUnitPrice;
938     }
939 
940     public String getListPrice() {
941         if (listPrice != null && !listPrice.isEmpty()) {
942             return listPrice;
943         } else if (invoiceListPrice != null && new KualiDecimal(invoiceListPrice).isLessThan(KualiDecimal.ZERO)) {
944             return "(" + invoiceListPrice.replace("-", "") + ")";
945         } else {
946             if (!debitItem) {
947                 return "(" + itemListPrice.toString().replace("-", "") + ")";
948             } else {
949                 return itemListPrice.toString();
950             }
951         }
952     }
953 
954     public void setListPrice(String listPrice) {
955         this.listPrice = listPrice;
956         if (listPrice.contains("(") || listPrice.contains(")")) {
957             listPrice = listPrice.replace("(", "");
958             listPrice = listPrice.replace(")", "");
959             listPrice = "-" + listPrice;
960             this.listPrice = listPrice;
961         }
962         if (new KualiDecimal(listPrice).isLessThan(KualiDecimal.ZERO)) {
963             this.setInvoiceListPrice(listPrice);
964             listPrice = listPrice.replace("-", "");
965             listPrice = "(" + listPrice + ")";
966             this.listPrice = listPrice;
967         } else {
968             this.setInvoiceListPrice(listPrice);
969             this.listPrice = listPrice;
970         }
971 
972     }
973 
974     public String getForeignListPrice() {
975         if (foreignListPrice != null && !foreignListPrice.isEmpty()) {
976             return foreignListPrice;
977         } else if (invoiceForeignListPrice != null && new KualiDecimal(invoiceForeignListPrice).isLessThan(KualiDecimal.ZERO)) {
978             return "(" + invoiceForeignListPrice.replace("-", "") + ")";
979         } else {
980             if (!debitItem) {
981                 return "(" + itemForeignListPrice.toString().replace("-", "") + ")";
982             } else {
983                 return itemForeignListPrice.toString();
984             }
985         }
986     }
987 
988     public void setForeignListPrice(String foreignListPrice) {
989         this.foreignListPrice = foreignListPrice;
990         if(foreignListPrice != null) {
991         if (foreignListPrice.contains("(") || foreignListPrice.contains(")")) {
992             foreignListPrice = foreignListPrice.replace("(", "");
993             foreignListPrice = foreignListPrice.replace(")", "");
994             foreignListPrice = "-" + foreignListPrice;
995             this.foreignListPrice = foreignListPrice;
996         }
997         if (new KualiDecimal(foreignListPrice).isLessThan(KualiDecimal.ZERO)) {
998             this.setInvoiceForeignListPrice(foreignListPrice);
999             foreignListPrice = foreignListPrice.replace("-", "");
1000             foreignListPrice = "(" + foreignListPrice + ")";
1001             this.foreignListPrice = foreignListPrice;
1002         } else {
1003             this.setInvoiceForeignListPrice(foreignListPrice);
1004             this.foreignListPrice = foreignListPrice;
1005         }
1006         }
1007     }
1008 
1009     public void setAdditionalUnitPrice(String additionalUnitPrice) {
1010         if (additionalUnitPrice != null && !additionalUnitPrice.isEmpty() &&
1011                 (new KualiDecimal(additionalUnitPrice)).isLessThan(AbstractKualiDecimal.ZERO)) {
1012             this.setDebitItem(false);
1013             this.setItemUnitPrice((new BigDecimal(additionalUnitPrice)).abs());
1014             this.additionalUnitPrice = additionalUnitPrice;
1015         } else if (additionalUnitPrice != null && !additionalUnitPrice.isEmpty() &&
1016                 (new KualiDecimal(additionalUnitPrice)).isGreaterEqual(AbstractKualiDecimal.ZERO)) {
1017             this.setDebitItem(true);
1018             this.setItemUnitPrice((new BigDecimal(additionalUnitPrice)));
1019             this.additionalUnitPrice = additionalUnitPrice;
1020         }
1021         else {
1022             this.setItemUnitPrice(null);
1023             this.additionalUnitPrice = additionalUnitPrice;
1024         }
1025 
1026     }
1027 
1028     public String getPoItemLink() {
1029         if (poItemIdentifier != null) {
1030             String documentTypeName = PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_DOCUMENT;
1031             DocumentType docType = KewApiServiceLocator.getDocumentTypeService().getDocumentTypeByName(documentTypeName);
1032             String docHandlerUrl = docType.getResolvedDocumentHandlerUrl();
1033             int endSubString = docHandlerUrl.lastIndexOf("/");
1034             String serverName = docHandlerUrl.substring(0, endSubString);
1035             String handler = docHandlerUrl.substring(endSubString + 1, docHandlerUrl.lastIndexOf("?"));
1036             poItemLink = serverName + "/" + KRADConstants.PORTAL_ACTION + "?channelTitle=" + docType.getName() + "&channelUrl=" +
1037                     handler + "?" + KRADConstants.DISPATCH_REQUEST_PARAMETER + "=" + KRADConstants.DOC_HANDLER_METHOD + "&" +
1038                     KRADConstants.PARAMETER_DOC_ID + "=" + this.getPurchaseOrderDocument().getDocumentNumber() + "&" + KRADConstants.PARAMETER_COMMAND + "=" +
1039                     KewApiConstants.DOCSEARCH_COMMAND;
1040 
1041         } else {
1042             poItemLink = "";
1043         }
1044         return poItemLink;
1045     }
1046 
1047     public void setPoItemLink(String poItemLink) {
1048         this.poItemLink = poItemLink;
1049     }
1050 
1051     public Date getSubscriptionFromDate() {
1052         return subscriptionFromDate;
1053     }
1054 
1055     public void setSubscriptionFromDate(Date subscriptionFromDate) {
1056         this.subscriptionFromDate = subscriptionFromDate;
1057     }
1058 
1059     public Date getSubscriptionToDate() {
1060         return subscriptionToDate;
1061     }
1062 
1063     public void setSubscriptionToDate(Date subscriptionToDate) {
1064         this.subscriptionToDate = subscriptionToDate;
1065     }
1066 
1067     public boolean isSubscriptionOverlap() {
1068         return subscriptionOverlap;
1069     }
1070 
1071     public void setSubscriptionOverlap(boolean subscriptionOverlap) {
1072         this.subscriptionOverlap = subscriptionOverlap;
1073     }
1074 
1075     public Date getPurchaseOrderEndDate() {
1076         return purchaseOrderEndDate;
1077     }
1078 
1079     public void setPurchaseOrderEndDate(Date purchaseOrderEndDate) {
1080         this.purchaseOrderEndDate = purchaseOrderEndDate;
1081     }
1082 
1083 
1084     public void setPaidCopies(List<OLEPaidCopy> paidCopies) {
1085         this.paidCopies = paidCopies;
1086     }
1087 
1088     public List<OLEPaidCopy> getPaidCopies() {
1089         return paidCopies;
1090     }
1091 
1092     public void setOleInvoiceOffsetAccountingLine(OLEInvoiceOffsetAccountingLine oleInvoiceOffsetAccountingLine) {
1093         this.oleInvoiceOffsetAccountingLine = oleInvoiceOffsetAccountingLine;
1094     }
1095 
1096     public List<SourceAccountingLine> getSourceAccountingLineList() {
1097         return sourceAccountingLineList;
1098     }
1099 
1100     public void setSourceAccountingLineList(List<SourceAccountingLine> sourceAccountingLineList) {
1101         this.sourceAccountingLineList = sourceAccountingLineList;
1102     }
1103 
1104     public OLEInvoiceOffsetAccountingLine getOleInvoiceOffsetAccountingLine() {
1105         return oleInvoiceOffsetAccountingLine;
1106     }
1107 
1108     public Integer getReLinkPO() {
1109         return reLinkPO;
1110     }
1111 
1112     public void setReLinkPO(Integer reLinkPO) {
1113         this.reLinkPO = reLinkPO;
1114     }
1115 
1116     @Override
1117     public PurchaseOrderItem getPurchaseOrderItem() {
1118         InvoiceDocument invDoc = getInvoice();
1119        /* if (ObjectUtils.isNotNull(this.getPurapDocumentIdentifier())) {
1120             if (ObjectUtils.isNull(this.getInvoice())) {
1121                 this.refreshReferenceObject(PurapPropertyConstants.PURAP_DOC);
1122             }
1123         }*/
1124         PurchaseOrderItem poi = null;
1125         // ideally we should do this a different way - maybe move it all into the service or save this info somehow (make sure and
1126         // update though)
1127         if (invDoc!= null) {
1128             PurchaseOrderDocument po = invDoc.getPurchaseOrderDocument(this.getPurchaseOrderIdentifier());
1129             if (po != null) {
1130                 this.setPostingYear(po.getPostingYear());
1131                 if (po.getRecurringPaymentType() != null) {
1132                     this.setRecurringPaymentType(po.getRecurringPaymentType());
1133                     this.setRecurringPaymentTypeCode(po.getRecurringPaymentTypeCode());
1134 
1135                 }
1136 
1137                 if (this.getItemType().isLineItemIndicator() && this.getItemLineNumber() != null && this.getItemLineNumber()< 0) {
1138                     List<PurchaseOrderItem> items = po.getItems();
1139                     poi = items.get(this.getItemLineNumber().intValue() - 1);
1140                     // throw error if line numbers don't match
1141                     // MSU Contribution DTT-3014 OLEMI-8483 OLECNTRB-974
1142                     /*
1143                     * List items = po.getItems(); if (items != null) { for (Object object : items) { PurchaseOrderItem item =
1144                     * (PurchaseOrderItem) object; if (item != null && item.getItemLineNumber().equals(this.getItemLineNumber())) { poi
1145                     * = item; break; } } }
1146                     */
1147                 } else if (this.getItemType().isLineItemIndicator()) {
1148                     List<PurchaseOrderItem> items = po.getItems();
1149                     for (int count = 0; count < items.size(); count++) {
1150                         if (this.getPoItemIdentifier() != null) {
1151                             if (this.getPoItemIdentifier().compareTo((items.get(count)).getItemIdentifier()) == 0) {
1152                                 this.setItemLineNumber(items.get(count).getItemLineNumber());
1153                                 poi = items.get(this.getItemLineNumber().intValue() - 1);
1154                                 break;
1155                             }
1156                         }
1157                         //items.get(count).getItemLineNumber();
1158                     }
1159                 } else {
1160                     poi = (PurchaseOrderItem) SpringContext.getBean(PurapService.class).getBelowTheLineByType(po, this.getItemType());
1161                     if (poi != null) {
1162                         this.setItemLineNumber(poi.getItemLineNumber());
1163                     }
1164                 }
1165             }
1166 
1167             if (poi != null) {
1168                 this.setPoItem(poi);
1169                 return poi;
1170             } else {
1171                 if (LOG.isDebugEnabled()) {
1172                     LOG.debug("getPurchaseOrderItem() Returning null because PurchaseOrderItem object for line number" + getItemLineNumber() + "or itemType " + getItemTypeCode() + " is null");
1173                 }
1174                 return null;
1175             }
1176         } else {
1177 
1178             LOG.error("getPurchaseOrderItem() Returning null because invoice object is null");
1179             throw new PurError("Payment Request Object in Purchase Order item line number " + getItemLineNumber() + "or itemType " + getItemTypeCode() + " is null");
1180         }
1181     }
1182 
1183     public Integer getRequisitionItemIdentifier() {
1184         return requisitionItemIdentifier;
1185     }
1186 
1187     public void setRequisitionItemIdentifier(Integer requisitionItemIdentifier) {
1188         this.requisitionItemIdentifier = requisitionItemIdentifier;
1189     }
1190 
1191     //Added for Jira OLE-5370
1192     public String getItemTitle() {
1193         itemTitle = getItemDescription();
1194         if(itemTitle.contains(OLEConstants.ANGLE_BRACKET_LESS_THAN)){
1195             itemTitle = itemTitle.replace(OLEConstants.ANGLE_BRACKET_LESS_THAN,"&#60;");
1196         }
1197         if(itemTitle.contains(OLEConstants.ANGLE_BRACKET_GREATER_THAN)){
1198             itemTitle = itemTitle.replace(OLEConstants.ANGLE_BRACKET_GREATER_THAN,"&#62;");
1199         }
1200         return itemTitle;
1201     }
1202 
1203     public void setItemTitle(String itemTitle) {
1204         this.itemTitle = itemTitle;
1205     }
1206 
1207     public boolean isItemPublicViewIndicator() {
1208         return itemPublicViewIndicator;
1209     }
1210 
1211     public void setItemPublicViewIndicator(boolean itemPublicViewIndicator) {
1212         this.itemPublicViewIndicator = itemPublicViewIndicator;
1213     }
1214 
1215     public boolean isItemRouteToRequestorIndicator() {
1216         return itemRouteToRequestorIndicator;
1217     }
1218 
1219     public void setItemRouteToRequestorIndicator(boolean itemRouteToRequestorIndicator) {
1220         this.itemRouteToRequestorIndicator = itemRouteToRequestorIndicator;
1221     }
1222 
1223     public boolean isEnableDetailsSection() {
1224         return enableDetailsSection;
1225     }
1226 
1227     public void setEnableDetailsSection(boolean enableDetailsSection) {
1228         this.enableDetailsSection = enableDetailsSection;
1229     }
1230     
1231     public BigDecimal getItemExtendedPrice() {
1232         return calculateItemExtendedPrice();
1233     }
1234 
1235 
1236     public BigDecimal calculateItemExtendedPrice() {
1237         BigDecimal extendedPrice = BigDecimal.ZERO;
1238         BigDecimal itemUnitPrice = getItemUnitPrice();
1239         if (ObjectUtils.isNotNull(itemUnitPrice)) {
1240             if (this.getItemType().isAmountBasedGeneralLedgerIndicator()) {
1241                 // SERVICE ITEM: return unit price as extended price
1242                 extendedPrice = itemUnitPrice;
1243             } else if (ObjectUtils.isNotNull(this.getItemQuantity())) {
1244                 BigDecimal calcExtendedPrice = itemUnitPrice.multiply(this.getItemQuantity().bigDecimalValue());
1245                 // ITEM TYPE (qty driven): return (unitPrice x qty)
1246                 extendedPrice = calcExtendedPrice.setScale(4, KualiDecimal.ROUND_BEHAVIOR);
1247             }
1248         }
1249         return extendedPrice;
1250     }
1251 
1252     @Override
1253     public KualiDecimal getTotalAmount() {
1254         KualiDecimal totalAmount = getExtendedPrice();
1255         if (ObjectUtils.isNull(totalAmount)) {
1256             totalAmount = KualiDecimal.ZERO;
1257         }
1258 
1259         KualiDecimal taxAmount = getItemTaxAmount();
1260         if (ObjectUtils.isNull(taxAmount)) {
1261             taxAmount = KualiDecimal.ZERO;
1262         }
1263 
1264         totalAmount = totalAmount.add(taxAmount);
1265 
1266         return totalAmount;
1267     }
1268 
1269     public BigDecimal getInvoiceTotalAmount() {
1270         BigDecimal totalAmount = getItemExtendedPrice();
1271         if (ObjectUtils.isNull(totalAmount)) {
1272             totalAmount = BigDecimal.ZERO;
1273         }
1274 
1275         KualiDecimal taxAmount = getItemTaxAmount();
1276         if (ObjectUtils.isNull(taxAmount)) {
1277             taxAmount = KualiDecimal.ZERO;
1278         }
1279 
1280         totalAmount = totalAmount.add(taxAmount.bigDecimalValue());
1281 
1282         return totalAmount;
1283     }
1284 
1285 
1286     public KualiDecimal getForeignTotalAmount() {
1287         KualiDecimal totalAmount = calculateForeignExtendedPrice();
1288         if (ObjectUtils.isNull(totalAmount)) {
1289             totalAmount = KualiDecimal.ZERO;
1290         }
1291 
1292         KualiDecimal taxAmount = getItemTaxAmount();
1293         if (ObjectUtils.isNull(taxAmount)) {
1294             taxAmount = KualiDecimal.ZERO;
1295         }
1296 
1297         totalAmount = totalAmount.add(taxAmount);
1298 
1299         return totalAmount;
1300     }
1301 
1302     public KualiDecimal calculateForeignExtendedPrice() {
1303         KualiDecimal extendedPrice = KualiDecimal.ZERO;
1304         if (this.getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)) {
1305             if (ObjectUtils.isNotNull(itemForeignUnitCost)) {
1306                 if (this.getItemType().isAmountBasedGeneralLedgerIndicator()) {
1307                     extendedPrice = new KualiDecimal(this.itemForeignUnitCost.toString());
1308                 } else if (ObjectUtils.isNotNull(this.getItemQuantity())) {
1309                     BigDecimal calcExtendedPrice = this.itemForeignUnitCost.bigDecimalValue().multiply(this.getItemQuantity().bigDecimalValue());
1310                     extendedPrice = new KualiDecimal(calcExtendedPrice.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR));
1311                 }
1312             }
1313         }
1314         return extendedPrice;
1315     }
1316 
1317 
1318 }