001/*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.ole.select.businessobject;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.ole.module.purap.PurapConstants;
020import org.kuali.ole.module.purap.PurapPropertyConstants;
021import org.kuali.ole.module.purap.businessobject.InvoiceItem;
022import org.kuali.ole.module.purap.businessobject.PurApItemUseTax;
023import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
024import org.kuali.ole.module.purap.document.InvoiceDocument;
025import org.kuali.ole.module.purap.util.ExpiredOrClosedAccountEntry;
026import org.kuali.ole.module.purap.util.PurApRelatedViews;
027import org.kuali.ole.pojo.OleOrderRecord;
028import org.kuali.ole.select.OleSelectConstant;
029import org.kuali.ole.select.lookup.DocData;
030import org.kuali.ole.sys.businessobject.UnitOfMeasure;
031import org.kuali.rice.core.api.util.type.AbstractKualiDecimal;
032import org.kuali.rice.core.api.util.type.KualiDecimal;
033import org.kuali.rice.core.api.util.type.KualiInteger;
034import org.kuali.rice.kew.api.KewApiConstants;
035import org.kuali.rice.kew.api.KewApiServiceLocator;
036import org.kuali.rice.kew.api.doctype.DocumentType;
037import org.kuali.rice.krad.util.KRADConstants;
038import org.kuali.rice.krad.util.ObjectUtils;
039
040import java.math.BigDecimal;
041import java.util.ArrayList;
042import java.util.HashMap;
043import java.util.List;
044
045public class OleInvoiceItem extends InvoiceItem {
046
047    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleInvoiceItem.class);
048    // Foreign Currency Conversion
049    protected String itemCurrencyType;
050    protected KualiDecimal itemForeignListPrice;
051    protected KualiDecimal itemForeignDiscount;
052    protected String itemForeignDiscountType;
053    protected KualiDecimal itemForeignDiscountAmt;
054    protected KualiDecimal itemForeignUnitCost;
055    protected KualiDecimal itemExchangeRate;
056    protected KualiDecimal itemUnitCostUSD;
057    protected KualiDecimal foreignCurrencyExtendedPrice;
058
059    protected boolean debitItem = true;
060    protected String invoiceListPrice;
061    protected String additionalUnitPrice;
062
063
064    protected Integer formatTypeId;
065    protected KualiInteger itemNoOfParts;
066    protected KualiDecimal itemListPrice;
067    protected KualiDecimal itemDiscount;
068    private String discountItem;
069    protected String itemDiscountType;
070    protected BigDecimal itemSurcharge;
071    protected String note;
072    protected List<OleInvoiceNote> notes;
073    protected Integer poItemIdentifier;
074
075    private Boolean relatedViewExist;
076    private transient PurApRelatedViews relatedViews;
077    private UnitOfMeasure itemUnitOfMeasure;
078
079    private String vendorItemIdentifier;
080
081    //BibInfo Details
082    private BibInfoBean bibInfoBean;
083    protected String itemTitleId;
084    protected String bibUUID;
085    private DocData docData;
086    private InvoiceDocument invoiceDocument;
087    private OleOrderRecord oleOrderRecord;
088    protected Integer receiptStatusId;
089    private OleReceiptStatus oleReceiptStatus;
090    private boolean useTaxIndicator;
091    /**
092     * For Quantity As Integer
093     */
094    private KualiInteger oleItemQuantity;
095    private String oleCopiesOrdered;
096    private KualiInteger olePoOutstandingQuantity;
097    private String oleOpenQuantity;
098    private OleFormatType formatType = new OleFormatType();
099    private String poItemLink;
100
101
102
103    public String getOleOpenQuantity() {
104        if (getPoOutstandingQuantity() != null) {
105            return String.valueOf(super.getPoOutstandingQuantity().intValue());
106        }
107        return "0";
108    }
109
110    public void setOleOpenQuantity(String oleOpenQuantity) {
111        if (oleOpenQuantity != null) {
112            super.setPoOutstandingQuantity(new KualiDecimal(oleOpenQuantity));
113        }
114    }
115
116    public String getVendorItemIdentifier() {
117        return vendorItemIdentifier;
118    }
119
120    public void setVendorItemIdentifier(String vendorItemIdentifier) {
121        this.vendorItemIdentifier = vendorItemIdentifier;
122    }
123
124    /**
125     * Gets the value of the receiptStatusId property
126     *
127     * @return receiptStatusId
128     */
129    public Integer getReceiptStatusId() {
130        return receiptStatusId;
131    }
132
133    /**
134     * Sets the receiptStatusId value
135     *
136     * @param receiptStatusId
137     */
138    public void setReceiptStatusId(Integer receiptStatusId) {
139        this.receiptStatusId = receiptStatusId;
140    }
141
142    /**
143     * Gets the instance of OleReceiptStatus
144     *
145     * @return oleReceiptStatus
146     */
147    public OleReceiptStatus getOleReceiptStatus() {
148        return oleReceiptStatus;
149    }
150
151    /**
152     * Sets the instance value for OleReceiptStatus
153     *
154     * @param oleReceiptStatus
155     */
156    public void setOleReceiptStatus(OleReceiptStatus oleReceiptStatus) {
157        this.oleReceiptStatus = oleReceiptStatus;
158    }
159
160    public OleOrderRecord getOleOrderRecord() {
161        return oleOrderRecord;
162    }
163
164    public void setOleOrderRecord(OleOrderRecord oleOrderRecord) {
165        this.oleOrderRecord = oleOrderRecord;
166    }
167
168    // added for jira - OLE-2203
169    protected boolean additionalChargeUsd;
170
171    /**
172     * Constructs a OleInvoiceItem.java.
173     */
174    public OleInvoiceItem() {
175        this.setItemNoOfParts(new KualiInteger(1));
176        this.setItemUnitOfMeasureCode(PurapConstants.InvoiceDocumentStrings.CUSTOMER_INVOICE_DETAIL_UOM_DEFAULT);
177        this.setOleItemQuantity(new KualiInteger(1));
178        this.setItemListPrice(new KualiDecimal(0.00));
179        notes = new ArrayList<OleInvoiceNote>();
180        // added for jira - OLE-2203
181        this.setItemCurrencyType(OleSelectConstant.USD);
182    }
183
184    /**
185     * Constructs a OleInvoiceItem.java.
186     *
187     * @param poi
188     * @param prqs
189     * @param expiredOrClosedAccountList
190     */
191    public OleInvoiceItem(PurchaseOrderItem poi, InvoiceDocument prqs, HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList) {
192        super(poi, prqs, expiredOrClosedAccountList);
193        this.setInvoiceDocument(prqs);
194        LOG.debug("Inside OleInvoiceItem Constructor");
195        LOG.debug("Setting the Format,Discount and Price Details");
196        notes = new ArrayList<OleInvoiceNote>();
197
198        OlePurchaseOrderItem olePoi = (OlePurchaseOrderItem) poi;
199        olePoi.getItemTypeCode();
200        notes.addAll(olePoi.getInvoiceNotes());
201        this.setItemForeignListPrice(olePoi.getItemForeignListPrice());
202        this.setItemForeignDiscount(olePoi.getItemForeignDiscount());
203        this.setItemForeignDiscountType(olePoi.getItemForeignDiscountType());
204        this.setItemForeignDiscountAmt(olePoi.getItemForeignDiscountAmt());
205        this.setItemForeignUnitCost(olePoi.getItemForeignUnitCost());
206        this.setItemExchangeRate(olePoi.getItemExchangeRate());
207        this.setItemUnitCostUSD(olePoi.getItemUnitCostUSD());
208        this.setFormatTypeId(olePoi.getFormatTypeId());
209        this.setItemNoOfParts(olePoi.getNoOfPartsInvoiced());
210        this.setItemListPrice(olePoi.getItemListPrice());
211        this.setItemDiscount(olePoi.getItemDiscount() != null ? olePoi.getItemDiscount() : new KualiDecimal(0.00));
212        this.setItemDiscountType(olePoi.getItemDiscountType());
213        this.setItemCatalogNumber(olePoi.getItemCatalogNumber());
214        this.setPoItemIdentifier(olePoi.getItemIdentifier());
215        this.setExtendedPrice(olePoi.getExtendedPrice());
216        this.setItemQuantity(olePoi.getItemQuantity());
217        this.setBibInfoBean(olePoi.getBibInfoBean());
218        this.setItemTitleId(olePoi.getItemTitleId());
219        if (olePoi.getNoOfCopiesInvoiced() != null) {
220            this.setItemQuantity(olePoi.getNoOfCopiesInvoiced().kualiDecimalValue());
221        }
222        if (new KualiDecimal(olePoi.getInvoiceItemListPrice()).isLessThan(AbstractKualiDecimal.ZERO)) {
223            this.setInvoiceListPrice(olePoi.getInvoiceItemListPrice());
224        }
225        else {
226            this.setItemListPrice(new KualiDecimal(olePoi.getInvoiceItemListPrice()));
227        }
228        //this.setInvoiceListPrice(olePoi.getInvoiceItemListPrice());
229        this.setItemUnitPrice(this.getItemListPrice().bigDecimalValue());
230        this.setExtendedPrice(this.calculateExtendedPrice()) ;
231        // added for OLE-2203
232        this.setItemCurrencyType(OleSelectConstant.USD);
233        this.setReceiptStatusId(olePoi.getReceiptStatusId());
234        this.setItemSurcharge(olePoi.getItemSurcharge());
235        this.setPurapDocumentIdentifier(prqs.getPurapDocumentIdentifier());
236    }
237
238    /**
239     * Constructs a OleInvoiceItem.java.
240     *
241     * @param poi
242     * @param prqs
243     */
244    public OleInvoiceItem(PurchaseOrderItem poi, InvoiceDocument prqs) {
245        super(poi, prqs);
246        this.setInvoiceDocument(prqs);
247        LOG.debug("Inside OleInvoiceItem Constructor");
248        LOG.debug("Setting the Format,Discount and Price Details");
249        notes = new ArrayList<OleInvoiceNote>();
250        OlePurchaseOrderItem olePoi = (OlePurchaseOrderItem) poi;
251        notes.addAll(olePoi.getInvoiceNotes());
252        this.setItemForeignListPrice(olePoi.getItemForeignListPrice());
253        this.setItemForeignDiscount(olePoi.getItemForeignDiscount());
254        this.setItemForeignDiscountType(olePoi.getItemForeignDiscountType());
255        this.setItemForeignDiscountAmt(olePoi.getItemForeignDiscountAmt());
256        this.setItemForeignUnitCost(olePoi.getItemForeignUnitCost());
257        this.setItemExchangeRate(olePoi.getItemExchangeRate());
258        this.setItemUnitCostUSD(olePoi.getItemUnitCostUSD());
259        this.setFormatTypeId(olePoi.getFormatTypeId());
260        this.setItemNoOfParts(olePoi.getItemNoOfParts());
261        this.setItemListPrice(olePoi.getItemListPrice());
262        this.setItemDiscount(olePoi.getItemDiscount() != null ? olePoi.getItemDiscount() : new KualiDecimal(0.00));
263        this.setItemDiscountType(olePoi.getItemDiscountType());
264        this.setItemCatalogNumber(olePoi.getItemCatalogNumber());
265        this.setPoItemIdentifier(olePoi.getItemIdentifier());
266        if (olePoi.getNoOfCopiesInvoiced() != null) {
267            this.setItemQuantity(olePoi.getNoOfCopiesInvoiced().kualiDecimalValue());
268        }
269        if (new KualiDecimal(olePoi.getInvoiceItemListPrice()).isLessThan(AbstractKualiDecimal.ZERO)) {
270            this.setInvoiceListPrice(olePoi.getInvoiceItemListPrice());
271        }
272        else {
273            this.setItemListPrice(new KualiDecimal(olePoi.getInvoiceItemListPrice()));
274        }
275        //this.setInvoiceListPrice(olePoi.getInvoiceItemListPrice());
276        this.setItemUnitPrice(this.getItemListPrice().bigDecimalValue());
277        this.setExtendedPrice(this.calculateExtendedPrice()) ;
278        // added for OLE-2203
279        this.setItemCurrencyType(OleSelectConstant.USD);
280        this.setPurapDocumentIdentifier(prqs.getPurapDocumentIdentifier());
281    }
282
283    @Override
284    public boolean isConsideredEnteredWithZero() {
285        return isConsideredEntered(true);
286    }
287
288    @Override
289    public boolean isConsideredEnteredWithoutZero() {
290        return isConsideredEntered(false);
291    }
292
293    private boolean isConsideredEntered(boolean allowsZero) {
294        if (getItemType().isLineItemIndicator()) {
295            if ((getItemType().isQuantityBasedGeneralLedgerIndicator())) {
296                if ((ObjectUtils.isNull(getItemQuantity()) || getItemQuantity().isZero()) && (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero()))) {
297                    return false;
298                }
299            } else {
300                if (ObjectUtils.isNull(getExtendedPrice()) || (allowsZero && getExtendedPrice().isZero())) {
301                    return false;
302                }
303            }
304        } else {
305            if ((ObjectUtils.isNull(getItemUnitPrice()) || (allowsZero && this.getItemUnitPrice().compareTo(new BigDecimal(0)) == 0)) && (StringUtils.isBlank(getItemDescription()))) {
306                return false;
307            }
308        }
309
310        return true;
311    }
312
313    public String getItemCurrencyType() {
314        return itemCurrencyType;
315    }
316
317    public void setItemCurrencyType(String itemCurrencyType) {
318        this.itemCurrencyType = itemCurrencyType;
319    }
320
321    public KualiDecimal getItemForeignListPrice() {
322        return itemForeignListPrice;
323    }
324
325    public void setItemForeignListPrice(KualiDecimal itemForeignListPrice) {
326        this.itemForeignListPrice = itemForeignListPrice;
327    }
328
329    public KualiDecimal getItemForeignDiscount() {
330        return itemForeignDiscount;
331    }
332
333    public void setItemForeignDiscount(KualiDecimal itemForeignDiscount) {
334        this.itemForeignDiscount = itemForeignDiscount;
335    }
336
337    public String getItemForeignDiscountType() {
338        return itemForeignDiscountType;
339    }
340
341    public void setItemForeignDiscountType(String itemForeignDiscountType) {
342        this.itemForeignDiscountType = itemForeignDiscountType;
343    }
344
345    public KualiDecimal getItemForeignDiscountAmt() {
346        return itemForeignDiscountAmt;
347    }
348
349    public void setItemForeignDiscountAmt(KualiDecimal itemForeignDiscountAmt) {
350        this.itemForeignDiscountAmt = itemForeignDiscountAmt;
351    }
352
353    public KualiDecimal getItemForeignUnitCost() {
354        return itemForeignUnitCost;
355    }
356
357    public void setItemForeignUnitCost(KualiDecimal itemForeignUnitCost) {
358        this.itemForeignUnitCost = itemForeignUnitCost;
359    }
360
361    public KualiDecimal getItemExchangeRate() {
362        return itemExchangeRate;
363    }
364
365    public void setItemExchangeRate(KualiDecimal itemExchangeRate) {
366        this.itemExchangeRate = itemExchangeRate;
367    }
368
369    public KualiDecimal getItemUnitCostUSD() {
370        return itemUnitCostUSD;
371    }
372
373    public void setItemUnitCostUSD(KualiDecimal itemUnitCostUSD) {
374        this.itemUnitCostUSD = itemUnitCostUSD;
375    }
376
377    public Integer getFormatTypeId() {
378        return formatTypeId;
379    }
380
381    public void setFormatTypeId(Integer formatTypeId) {
382        this.formatTypeId = formatTypeId;
383    }
384
385    public KualiInteger getItemNoOfParts() {
386        if (this.itemNoOfParts != null) {
387            return itemNoOfParts;
388        } else {
389            return itemNoOfParts;
390        }
391    }
392
393    public void setItemNoOfParts(KualiInteger itemNoOfParts) {
394        this.itemNoOfParts = itemNoOfParts;
395    }
396
397    public KualiDecimal getItemListPrice() {
398        return itemListPrice;
399    }
400
401    public void setItemListPrice(KualiDecimal itemListPrice) {
402        this.itemListPrice = itemListPrice;
403    }
404
405    public String getDiscountItem() {
406        return String.valueOf(itemDiscount) != null ? String.valueOf(itemDiscount) : "0" ;
407    }
408
409    public void setDiscountItem(String discountItem) {
410        this.itemDiscount = new KualiDecimal(discountItem);
411    }
412
413    public KualiDecimal getItemDiscount() {
414        return itemDiscount;
415    }
416
417    public void setItemDiscount(KualiDecimal itemDiscount) {
418        this.itemDiscount = itemDiscount;
419    }
420
421    public String getItemDiscountType() {
422        return itemDiscountType;
423    }
424
425    public void setItemDiscountType(String itemDiscountType) {
426        this.itemDiscountType = itemDiscountType;
427    }
428
429    public BigDecimal getItemSurcharge() {
430        return itemSurcharge;
431    }
432
433    public void setItemSurcharge(BigDecimal itemSurcharge) {
434        this.itemSurcharge = itemSurcharge;
435    }
436
437    public Integer getPoItemIdentifier() {
438        return poItemIdentifier;
439    }
440
441    public void setPoItemIdentifier(Integer poItemIdentifier) {
442        this.poItemIdentifier = poItemIdentifier;
443    }
444
445    public String getNote() {
446        return note;
447    }
448
449    public void setNote(String note) {
450        this.note = note;
451    }
452
453    public List<OleInvoiceNote> getNotes() {
454        return notes;
455    }
456
457    public void setNotes(List<OleInvoiceNote> notes) {
458        this.notes = notes;
459    }
460
461    public UnitOfMeasure getItemUnitOfMeasure() {
462        if (ObjectUtils.isNull(itemUnitOfMeasure) || !StringUtils.equalsIgnoreCase(itemUnitOfMeasure.getItemUnitOfMeasureCode(), getItemUnitOfMeasureCode())) {
463            refreshReferenceObject(PurapPropertyConstants.ITEM_UNIT_OF_MEASURE);
464        }
465        return itemUnitOfMeasure;
466    }
467
468    public void setItemUnitOfMeasure(UnitOfMeasure itemUnitOfMeasure) {
469        this.itemUnitOfMeasure = itemUnitOfMeasure;
470    }
471
472    public boolean getIsUnorderedItem() {
473        if (this.getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
474            return false;
475        }
476        return true;
477    }
478
479    public KualiDecimal getForeignCurrencyExtendedPrice() {
480        return foreignCurrencyExtendedPrice;
481    }
482
483    public void setForeignCurrencyExtendedPrice(KualiDecimal foreignCurrencyExtendedPrice) {
484        this.foreignCurrencyExtendedPrice = foreignCurrencyExtendedPrice;
485    }
486
487    public String getItemTitleId() {
488        return itemTitleId;
489    }
490
491    public void setItemTitleId(String itemTitleId) {
492        this.itemTitleId = itemTitleId;
493    }
494
495    public BibInfoBean getBibInfoBean() {
496        return bibInfoBean;
497    }
498
499    public void setBibInfoBean(BibInfoBean bibInfoBean) {
500        this.bibInfoBean = bibInfoBean;
501    }
502
503    public String getBibUUID() {
504        return bibUUID;
505    }
506
507    public void setBibUUID(String bibUUID) {
508        this.bibUUID = bibUUID;
509    }
510
511    public DocData getDocData() {
512        return docData;
513    }
514
515    public void setDocData(DocData docData) {
516        this.docData = docData;
517    }
518
519    public InvoiceDocument getInvoiceDocument() {
520        return invoiceDocument;
521    }
522
523    public void setInvoiceDocument(InvoiceDocument invoiceDocument) {
524        setPurapDocument(invoiceDocument);
525        this.invoiceDocument = invoiceDocument;
526    }
527
528    public boolean isAdditionalChargeUsd() {
529        return additionalChargeUsd;
530    }
531
532    public void setAdditionalChargeUsd(boolean additionalChargeUsd) {
533        this.additionalChargeUsd = additionalChargeUsd;
534    }
535
536    public String getOleCopiesOrdered() {
537        return String.valueOf(super.getItemQuantity().intValue());
538    }
539
540    public void setOleCopiesOrdered(String oleCopiesOrdered) {
541        super.setItemQuantity(new KualiDecimal(oleCopiesOrdered));
542    }
543
544    /**
545     * Gets the oleItemQuantity attribute.
546     *
547     * @return Returns the oleItemQuantity.
548     */
549    public KualiInteger getOleItemQuantity() {
550        return new KualiInteger(super.getItemQuantity().intValue());
551    }
552
553    /**
554     * Sets the oleItemQuantity attribute value.
555     *
556     * @param oleItemQuantity The oleItemQuantity to set.
557     */
558    public void setOleItemQuantity(KualiInteger oleItemQuantity) {
559        super.setItemQuantity(new KualiDecimal(oleItemQuantity.intValue()));
560    }
561
562    /**
563     * Gets the olePoOutstandingQuantity attribute.
564     *
565     * @return Returns the olePoOutstandingQuantity.
566     */
567    public KualiInteger getOlePoOutstandingQuantity() {
568        if (getPoOutstandingQuantity() != null) {
569            return new KualiInteger(super.getPoOutstandingQuantity().intValue());
570        }
571        return new KualiInteger(0);
572    }
573
574    /**
575     * Sets the olePoOutstandingQuantity attribute value.
576     *
577     * @param olePoOutstandingQuantity The olePoOutstandingQuantity to set.
578     */
579    public void setOlePoOutstandingQuantity(KualiInteger olePoOutstandingQuantity) {
580        if (olePoOutstandingQuantity != null) {
581            super.setPoOutstandingQuantity(new KualiDecimal(olePoOutstandingQuantity.intValue()));
582        }
583    }
584
585    public boolean isUseTaxIndicator() {
586        return useTaxIndicator;
587    }
588
589    public void setUseTaxIndicator(boolean useTaxIndicator) {
590        this.useTaxIndicator = useTaxIndicator;
591    }
592
593    @Override
594    public KualiDecimal getItemTaxAmount() {
595        KualiDecimal taxAmount = KualiDecimal.ZERO;
596
597        /*if (ObjectUtils.isNull(purapDocument)) {
598            this.refreshReferenceObject("purapDocument");
599        }*/
600
601        if (this.isUseTaxIndicator() == false) {
602            taxAmount = this.getItemSalesTaxAmount();
603        } else {
604            // sum use tax item tax amounts
605            for (PurApItemUseTax useTaxItem : this.getUseTaxItems()) {
606                taxAmount = taxAmount.add(useTaxItem.getTaxAmount());
607            }
608        }
609
610        return taxAmount;
611    }
612
613    public OleFormatType getFormatType() {
614        return formatType;
615    }
616
617    public void setFormatType(OleFormatType formatType) {
618        this.formatType = formatType;
619    }
620
621    public PurApRelatedViews getRelatedViews() {
622        if (!getRelatedViewExist()) {
623            relatedViews = new PurApRelatedViews(this.getInvoiceDocument()!=null?this.getInvoiceDocument().getDocumentNumber():null,
624                    this.getAccountsPayablePurchasingDocumentLinkIdentifier()!=null?this.getAccountsPayablePurchasingDocumentLinkIdentifier():null);
625            ;
626        }
627        return relatedViews;
628    }
629
630    public void setRelatedViews(PurApRelatedViews relatedViews) {
631        this.relatedViews = relatedViews;
632    }
633
634    public Boolean getRelatedViewExist() {
635        if (this.relatedViews != null) {
636            this.relatedViewExist = Boolean.TRUE;
637        } else {
638            this.relatedViewExist =  Boolean.FALSE;
639        }
640        return relatedViewExist;
641    }
642
643    public void setRelatedViewExist(Boolean relatedViewExist) {
644        this.relatedViewExist = relatedViewExist;
645    }
646
647    public boolean isDebitItem() {
648        return debitItem;
649    }
650
651    public void setDebitItem(boolean debitItem) {
652        this.debitItem = debitItem;
653    }
654
655    public String getInvoiceListPrice() {
656        if (!isDebitItem()) {
657            return this.getItemListPrice() != null ? this.getItemListPrice().negated().toString() : null;
658        }
659        return itemListPrice.toString();
660    }
661
662    public void setInvoiceListPrice(String invoiceListPrice) {
663        if (invoiceListPrice != null && !invoiceListPrice.isEmpty() &&
664                (new KualiDecimal(invoiceListPrice)).isLessThan(AbstractKualiDecimal.ZERO)) {
665            this.setDebitItem(false);
666        }
667        this.setItemListPrice((new KualiDecimal(invoiceListPrice)).abs());
668        this.invoiceListPrice = invoiceListPrice;
669    }
670
671    public String getAdditionalUnitPrice() {
672        if (!isDebitItem()) {
673            return this.getItemUnitPrice() != null ? this.getItemUnitPrice().negate().toString() : null;
674        }
675        return this.getItemUnitPrice() != null ? this.getItemUnitPrice().toString() : null;
676    }
677
678    public void setAdditionalUnitPrice(String additionalUnitPrice) {
679        if (additionalUnitPrice != null && !additionalUnitPrice.isEmpty() &&
680                (new KualiDecimal(additionalUnitPrice)).isLessThan(AbstractKualiDecimal.ZERO)) {
681            this.setDebitItem(false);
682        }
683        this.setItemUnitPrice((new BigDecimal(additionalUnitPrice)).abs());
684        this.additionalUnitPrice = additionalUnitPrice;
685    }
686
687    public String getPoItemLink() {
688        String documentTypeName = PurapConstants.PurchaseOrderDocTypes.PURCHASE_ORDER_DOCUMENT;
689        DocumentType docType = KewApiServiceLocator.getDocumentTypeService().getDocumentTypeByName(documentTypeName);
690        String docHandlerUrl = docType.getResolvedDocumentHandlerUrl();
691        int endSubString = docHandlerUrl.lastIndexOf("/");
692        String serverName = docHandlerUrl.substring(0, endSubString);
693        String handler = docHandlerUrl.substring(endSubString + 1, docHandlerUrl.lastIndexOf("?"));
694        return serverName + "/" + KRADConstants.PORTAL_ACTION + "?channelTitle=" + docType.getName() + "&channelUrl=" +
695                handler + "?" + KRADConstants.DISPATCH_REQUEST_PARAMETER + "=" + KRADConstants.DOC_HANDLER_METHOD + "&" +
696                KRADConstants.PARAMETER_DOC_ID + "=" + this.getPurchaseOrderDocument().getDocumentNumber() + "&" + KRADConstants.PARAMETER_COMMAND + "=" +
697                KewApiConstants.DOCSEARCH_COMMAND;
698    }
699
700    public void setPoItemLink(String poItemLink) {
701        this.poItemLink = poItemLink;
702    }
703}