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.document;
17  
18  import org.apache.commons.lang.ArrayUtils;
19  import org.apache.commons.lang.StringEscapeUtils;
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
22  import org.kuali.ole.docstore.common.document.Bib;
23  import org.kuali.ole.docstore.common.document.BibMarc;
24  import org.kuali.ole.DocumentUniqueIDPrefix;
25  import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.BibInfoRecord;
26  import org.kuali.ole.gl.service.SufficientFundsService;
27  import org.kuali.ole.module.purap.PurapConstants;
28  import org.kuali.ole.module.purap.PurapConstants.InvoiceStatuses;
29  import org.kuali.ole.module.purap.PurapParameterConstants;
30  import org.kuali.ole.module.purap.PurapPropertyConstants;
31  import org.kuali.ole.module.purap.PurapWorkflowConstants;
32  import org.kuali.ole.module.purap.businessobject.*;
33  import org.kuali.ole.module.purap.document.InvoiceDocument;
34  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
35  import org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocument;
36  import org.kuali.ole.module.purap.document.service.AccountsPayableService;
37  import org.kuali.ole.module.purap.document.service.InvoiceService;
38  import org.kuali.ole.module.purap.document.service.PurapService;
39  import org.kuali.ole.module.purap.document.validation.event.AttributedContinuePurapEvent;
40  import org.kuali.ole.module.purap.service.PurapAccountingService;
41  import org.kuali.ole.module.purap.util.ExpiredOrClosedAccountEntry;
42  import org.kuali.ole.module.purap.util.SummaryAccount;
43  import org.kuali.ole.select.OleSelectConstant;
44  import org.kuali.ole.select.bo.OLELinkPurapDonor;
45  import org.kuali.ole.select.businessobject.*;
46  import org.kuali.ole.select.document.service.OleInvoiceService;
47  import org.kuali.ole.select.document.service.impl.OleInvoiceFundCheckServiceImpl;
48  import org.kuali.ole.select.form.OLEInvoiceForm;
49  import org.kuali.ole.select.service.BibInfoService;
50  import org.kuali.ole.select.service.BibInfoWrapperService;
51  import org.kuali.ole.select.service.FileProcessingService;
52  import org.kuali.ole.select.service.impl.BibInfoServiceImpl;
53  import org.kuali.ole.sys.OLEConstants;
54  import org.kuali.ole.sys.OLEPropertyConstants;
55  import org.kuali.ole.sys.businessobject.Bank;
56  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
57  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
58  import org.kuali.ole.sys.businessobject.SufficientFundsItem;
59  import org.kuali.ole.sys.context.SpringContext;
60  import org.kuali.ole.sys.service.BankService;
61  import org.kuali.ole.sys.service.GeneralLedgerPendingEntryService;
62  import org.kuali.ole.sys.service.UniversityDateService;
63  import org.kuali.ole.vnd.VendorConstants;
64  import org.kuali.ole.vnd.businessobject.OleCurrencyType;
65  import org.kuali.ole.vnd.businessobject.OleExchangeRate;
66  import org.kuali.ole.vnd.businessobject.VendorAddress;
67  import org.kuali.ole.vnd.document.service.VendorService;
68  import org.kuali.rice.core.api.config.property.ConfigContext;
69  import org.kuali.rice.core.api.config.property.ConfigurationService;
70  import org.kuali.rice.core.api.datetime.DateTimeService;
71  import org.kuali.rice.core.api.util.type.KualiDecimal;
72  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
73  import org.kuali.rice.kew.api.KewApiConstants;
74  import org.kuali.rice.kew.api.KewApiServiceLocator;
75  import org.kuali.rice.kew.api.WorkflowDocument;
76  import org.kuali.rice.kew.api.action.ActionRequestType;
77  import org.kuali.rice.kew.api.action.ActionTaken;
78  import org.kuali.rice.kew.api.action.RoutingReportCriteria;
79  import org.kuali.rice.kew.api.exception.WorkflowException;
80  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange;
81  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
82  import org.kuali.rice.kim.api.identity.Person;
83  import org.kuali.rice.kim.api.identity.PersonService;
84  import org.kuali.rice.kim.api.identity.principal.Principal;
85  import org.kuali.rice.kim.api.services.IdentityManagementService;
86  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
87  import org.kuali.rice.krad.bo.Note;
88  import org.kuali.rice.krad.document.Copyable;
89  import org.kuali.rice.krad.exception.ValidationException;
90  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
91  import org.kuali.rice.krad.service.BusinessObjectService;
92  import org.kuali.rice.krad.service.DocumentService;
93  import org.kuali.rice.krad.util.GlobalVariables;
94  import org.kuali.rice.krad.util.ObjectUtils;
95  import org.kuali.rice.krad.workflow.service.WorkflowDocumentService;
96  
97  import java.math.BigDecimal;
98  import java.math.RoundingMode;
99  import java.util.*;
100 
101 /**
102  * This class is the document class for Ole Payment Request
103  */
104 
105 public class OleInvoiceDocument extends InvoiceDocument implements Copyable {
106 
107     private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleInvoiceDocument.class);
108 
109     private Integer invoiceTypeId;
110     private Integer invoiceSubTypeId;
111     private String vendorId;
112     private String vendorAlias;
113     private String invoiceTypeHdnId;
114     private String invoiceSubTypeHdnId;
115     private String acquisitionUnit;
116     private String empty;
117     protected transient List<SummaryAccount> summaryAccounts;
118     private boolean sfcFlag;
119     private String invoiceItemTotal;
120     private String invoiceForeignItemTotal;
121     private String invoiceAmount;
122     private boolean baSfcFlag;
123     private boolean validationFlag;
124     private boolean blanketApproveValidationFlag;
125     private boolean blanketApproveSubscriptionDateValidationFlag;
126     private boolean subscriptionDateValidationFlag;
127     private String purchaseOrderDocumentNums;
128     private boolean duplicateApproveFlag = false;
129     private boolean blanketApproveFlag=true;
130     private boolean overviewFlag = true;
131     private boolean vendorInfoFlag = true;
132     private boolean invoiceInfoFlag = true;
133     private boolean processItemFlag = false;
134     private boolean processTitlesFlag = false;
135     private boolean currentItemsFlag = false;
136 
137 
138     private boolean additionalChargesFlag = false;
139     private boolean accountSummaryFlag = false;
140     private boolean notesAndAttachmentFlag = false;
141     private boolean adHocRecipientsFlag = false;
142     private boolean routeLogFlag = false;
143     private boolean routeLogDisplayFlag = false;
144     private boolean unsaved = false;
145     private boolean canClose = false;
146 
147     private String cloneDebitInvoice;
148     private boolean cloneFlag = false;
149     private boolean amountExceeds = false;
150     private String exceedsEncumbranceTitle;
151     private String exceedsEncumbranceExtendedCost;
152     private String exceedsEncumbranceListPrice;
153     private boolean amountExceedsForBlanketApprove;
154     private boolean itemSign;
155 
156     private String vendorLink;
157     private boolean foreignCurrencyFlag=false;
158     private Long invoiceCurrencyTypeId;
159     private String invoiceCurrencyType;
160     private OleCurrencyType oleCurrencyType;
161     private boolean currencyOverrideFlag = false;
162     private String currencyOverrideMessage;
163     private String invoiceCurrencyExchangeRate;
164     private boolean dbRetrieval= false;
165     private boolean enableCurrentItems = false;
166     private String foreignVendorAmount;
167     private String foreignInvoiceAmount;
168     private List<OleInvoiceItem> deletedInvoiceItems =  new ArrayList<>();
169     private boolean duplicateRouteFlag;
170     private boolean duplicateSaveFlag;
171     private boolean duplicateValidationFlag;
172     private String invoiceInfo;
173 
174     public boolean isBlanketApproveFlag() {
175         return blanketApproveFlag;
176     }
177     private boolean currencyTypeIndicator = true;
178 
179     public void setBlanketApproveFlag(boolean blanketApproveFlag) {
180         this.blanketApproveFlag = blanketApproveFlag;
181     }
182 
183     private List<OlePaymentRequestDocument> paymentRequestDocuments = new ArrayList<OlePaymentRequestDocument>();
184 
185     public boolean isCanClose() {
186         return canClose;
187     }
188 
189     public void setCanClose(boolean canClose) {
190         this.canClose = canClose;
191     }
192 
193     public boolean isUnsaved() {
194         return unsaved;
195     }
196 
197     public void setUnsaved(boolean unsaved) {
198         this.unsaved = unsaved;
199     }
200 
201     private boolean duplicateFlag = false;
202 
203 
204     private BigDecimal priorTotal = new BigDecimal(0);
205 
206     public String getAcquisitionUnit() {
207         return acquisitionUnit;
208     }
209 
210     public void setAcquisitionUnit(String acquisitionUnit) {
211         this.acquisitionUnit = acquisitionUnit;
212     }
213 
214     public BigDecimal getPriorTotal() {
215         return priorTotal;
216     }
217 
218     public void setPriorTotal(BigDecimal priorTotal) {
219         this.priorTotal = priorTotal;
220     }
221 
222     public String getEmpty() {
223         return empty;
224     }
225 
226     public void setEmpty(String empty) {
227         this.empty = empty;
228     }
229 
230     // NOT PERSISTED IN DB
231     //private String invoiceType;
232     // private String invoiceSubType;
233 
234     // REFERENCE OBJECTS
235     private OleInvoiceSubType oleInvoiceSubType;
236     private OleInvoiceType oleInvoiceType;
237 
238     // Prorating Additional charges
239     private boolean prorateQty;
240     private boolean prorateDollar;
241     private boolean prorateManual;
242     private boolean noProrate;
243 
244     private String prorateBy;
245 
246     private BigDecimal foreignVendorInvoiceAmount;
247 
248     private BigDecimal purchaseOrderTypeId;
249     private PurchaseOrderType orderType;
250     private static transient BibInfoService bibInfoService;
251     private String paymentMethodIdentifier;
252     private Integer paymentMethodId;
253     private OlePaymentMethod paymentMethod;
254     private String vendorFaxNumber;
255 
256     protected Integer accountsPayablePurchasingDocumentLinkIdentifier;
257     protected List<PurchasingAccountsPayableDocument> purchaseOrders;
258 
259 
260     private String invoicedGrandTotal;
261     private String invoicedItemTotal;
262     //private boolean invoiceModified;
263     private String searchResultInvoiceDate;
264     private String searchResultInvoicePayDate;
265     private boolean offsetAccountIndicator;
266 
267     public boolean isNoProrate() {
268         return noProrate;
269     }
270 
271     public void setNoProrate(boolean noProrate) {
272         this.noProrate = noProrate;
273     }
274 
275     @SuppressWarnings("rawtypes")
276     public List getPurchaseOrders() {
277         return purchaseOrders;
278     }
279 
280     @SuppressWarnings("rawtypes")
281     public void setPurchaseOrders(List purchaseOrders) {
282         this.purchaseOrders = purchaseOrders;
283     }
284 
285     public String getVendorFaxNumber() {
286         return vendorFaxNumber;
287     }
288 
289     public void setVendorFaxNumber(String vendorFaxNumber) {
290         this.vendorFaxNumber = vendorFaxNumber;
291     }
292 
293     public String getPaymentMethodIdentifier() {
294         return paymentMethodIdentifier;
295     }
296 
297     public void setPaymentMethodIdentifier(String paymentMethodIdentifier) {
298         this.paymentMethodIdentifier = paymentMethodIdentifier;
299     }
300 
301     public String getVendorId() {
302         return vendorId;
303     }
304 
305     public void setVendorId(String vendorId) {
306         this.vendorId = vendorId;
307     }
308 
309     public String getInvoiceSubTypeHdnId() {
310         return invoiceSubTypeHdnId;
311     }
312 
313     public void setInvoiceSubTypeHdnId(String invoiceSubTypeHdnId) {
314         this.invoiceSubTypeHdnId = invoiceSubTypeHdnId;
315     }
316 
317     //Overview
318     private String documentYear;
319     private String documentTotalAmount;
320 
321     //Additional Items
322     /*List<OLEInvoiceAdditionalItem> additionalItems = new ArrayList<OLEInvoiceAdditionalItem>();*/
323 
324     public String getDocumentYear() {
325         return documentYear;
326     }
327 
328     public void setDocumentYear(String documentYear) {
329         this.documentYear = documentYear;
330     }
331 
332     public String getDocumentTotalAmount() {
333         if (!isDbRetrieval()) {
334             this.documentTotalAmount = this.getTotalDollarAmount().toString();
335         }
336         return documentTotalAmount;
337         //return this.getTotalDollarAmount().toString();
338     }
339 
340     public void setDocumentTotalAmount(String documentTotalAmount) {
341         this.documentTotalAmount = documentTotalAmount;
342     }
343 
344     /*public List<OLEInvoiceAdditionalItem> getAdditionalItems() {
345         return additionalItems;
346     }
347 
348     public void setAdditionalItems(List<OLEInvoiceAdditionalItem> additionalItems) {
349         this.additionalItems = additionalItems;
350     }*/
351 
352     private List<OlePurchaseOrderItem> purchaseOrderItems = new ArrayList<OlePurchaseOrderItem>();
353 
354 
355     public List<OlePurchaseOrderItem> getPurchaseOrderItems() {
356         return purchaseOrderItems;
357     }
358 
359     public void setPurchaseOrderItems(List<OlePurchaseOrderItem> purchaseOrderItems) {
360         this.purchaseOrderItems = purchaseOrderItems;
361     }
362 
363     public Integer getPaymentMethodId() {
364         return paymentMethodId;
365     }
366 
367     public void setPaymentMethodId(Integer paymentMethodId) {
368         this.paymentMethodId = paymentMethodId;
369     }
370 
371     public OlePaymentMethod getPaymentMethod() {
372         return paymentMethod;
373     }
374 
375     public void setPaymentMethod(OlePaymentMethod paymentMethod) {
376         this.paymentMethod = paymentMethod;
377     }
378 
379     public static BibInfoService getBibInfoService() {
380         if (bibInfoService == null) {
381             bibInfoService = SpringContext.getBean(BibInfoServiceImpl.class);
382         }
383         return bibInfoService;
384     }
385 
386     @Override
387     public BigDecimal getPurchaseOrderTypeId() {
388         return purchaseOrderTypeId;
389     }
390 
391     @Override
392     public void setPurchaseOrderTypeId(BigDecimal purchaseOrderTypeId) {
393         this.purchaseOrderTypeId = purchaseOrderTypeId;
394     }
395 
396     @Override
397     public PurchaseOrderType getOrderType() {
398         return orderType;
399     }
400 
401     @Override
402     public Integer getAccountsPayablePurchasingDocumentLinkIdentifier() {
403         return accountsPayablePurchasingDocumentLinkIdentifier;
404     }
405 
406     @Override
407     public void setAccountsPayablePurchasingDocumentLinkIdentifier(Integer accountsPayablePurchasingDocumentLinkIdentifier) {
408         this.accountsPayablePurchasingDocumentLinkIdentifier = accountsPayablePurchasingDocumentLinkIdentifier;
409     }
410 
411     @Override
412     public void setOrderType(PurchaseOrderType orderType) {
413         this.orderType = orderType;
414     }
415 
416     public Integer getInvoiceTypeId() {
417         return invoiceTypeId;
418     }
419 
420     public void setInvoiceTypeId(Integer invoiceTypeId) {
421         this.invoiceTypeId = invoiceTypeId;
422     }
423 
424     public String getInvoiceTypeHdnId() {
425         return invoiceTypeHdnId;
426     }
427 
428     public void setInvoiceTypeHdnId(String invoiceTypeHdnId) {
429         this.invoiceTypeHdnId = invoiceTypeHdnId;
430     }
431 
432     public Integer getInvoiceSubTypeId() {
433         return invoiceSubTypeId;
434     }
435 
436     public void setInvoiceSubTypeId(Integer invoiceSubTypeId) {
437         this.invoiceSubTypeId = invoiceSubTypeId;
438     }
439 
440     public String getInvoiceType() {
441         return invoiceType;
442     }
443 
444     public void setInvoiceType(String invoiceType) {
445         this.invoiceType = invoiceType;
446     }
447 
448 
449     public String getInvoiceSubType() {
450         return invoiceSubType;
451     }
452 
453     public void setInvoiceSubType(String invoiceSubType) {
454         this.invoiceSubType = invoiceSubType;
455     }
456 
457     public OleInvoiceSubType getOleInvoiceSubType() {
458         return oleInvoiceSubType;
459     }
460 
461     public void setOleInvoiceSubType(OleInvoiceSubType oleInvoiceSubType) {
462         this.oleInvoiceSubType = oleInvoiceSubType;
463     }
464 
465     public OleInvoiceType getOleInvoiceType() {
466         return oleInvoiceType;
467     }
468 
469     public void setOleInvoiceType(OleInvoiceType oleInvoiceType) {
470         this.oleInvoiceType = oleInvoiceType;
471     }
472 
473     public boolean isProrateQty() {
474         return prorateQty;
475     }
476 
477     public void setProrateQty(boolean prorateQty) {
478         this.prorateQty = prorateQty;
479     }
480 
481     public boolean isProrateDollar() {
482         return prorateDollar;
483     }
484 
485     public void setProrateDollar(boolean prorateDollar) {
486         this.prorateDollar = prorateDollar;
487     }
488 
489     public boolean isProrateManual() {
490         return prorateManual;
491     }
492 
493     public void setProrateManual(boolean prorateManual) {
494         this.prorateManual = prorateManual;
495     }
496 
497     public boolean isAmountExceeds() {
498         return amountExceeds;
499     }
500 
501     public void setAmountExceeds(boolean amountExceeds) {
502         this.amountExceeds = amountExceeds;
503     }
504 
505     public String getExceedsEncumbranceTitle() {
506         return exceedsEncumbranceTitle;
507     }
508 
509     public void setExceedsEncumbranceTitle(String exceedsEncumbranceTitle) {
510         this.exceedsEncumbranceTitle = exceedsEncumbranceTitle;
511     }
512 
513     public String getExceedsEncumbranceExtendedCost() {
514         return exceedsEncumbranceExtendedCost;
515     }
516 
517     public void setExceedsEncumbranceExtendedCost(String exceedsEncumbranceExtendedCost) {
518         this.exceedsEncumbranceExtendedCost = exceedsEncumbranceExtendedCost;
519     }
520 
521     public String getExceedsEncumbranceListPrice() {
522         return exceedsEncumbranceListPrice;
523     }
524 
525     public void setExceedsEncumbranceListPrice(String exceedsEncumbranceListPrice) {
526         this.exceedsEncumbranceListPrice = exceedsEncumbranceListPrice;
527     }
528 
529     public boolean isAmountExceedsForBlanketApprove() {
530         return amountExceedsForBlanketApprove;
531     }
532 
533     public void setAmountExceedsForBlanketApprove(boolean amountExceedsForBlanketApprove) {
534         this.amountExceedsForBlanketApprove = amountExceedsForBlanketApprove;
535     }
536 
537     private static transient ConfigurationService kualiConfigurationService;
538     private static transient BibInfoWrapperService bibInfoWrapperService;
539     private static transient FileProcessingService fileProcessingService;
540     private static transient BusinessObjectService businessObjectService;
541     private static transient VendorService vendorService;
542     private static transient InvoiceService invoiceService;
543     private static transient OleInvoiceService oleInvoiceService;
544     private static transient PurapService purapService;
545     private static transient AccountsPayableService accountsPayableService;
546     private static transient IdentityManagementService identityManagementService;
547     private static transient WorkflowDocumentService workflowDocumentService;
548 
549     //Proforma
550     private boolean proformaIndicator;
551 
552     public static WorkflowDocumentService getWorkflowDocumentService() {
553         if (workflowDocumentService == null) {
554             workflowDocumentService = SpringContext.getBean(WorkflowDocumentService.class);
555         }
556         return workflowDocumentService;
557     }
558 
559     public static void setWorkflowDocumentService(WorkflowDocumentService workflowDocumentService) {
560         OleInvoiceDocument.workflowDocumentService = workflowDocumentService;
561     }
562 
563     public static InvoiceService getInvoiceService() {
564         if (invoiceService == null) {
565             invoiceService = SpringContext.getBean(InvoiceService.class);
566         }
567         return invoiceService;
568     }
569 
570     public static void setInvoiceService(InvoiceService invoiceService) {
571         OleInvoiceDocument.invoiceService = invoiceService;
572     }
573 
574     public static VendorService getVendorService() {
575         if (vendorService == null) {
576             vendorService = SpringContext.getBean(VendorService.class);
577         }
578         return vendorService;
579     }
580 
581     public static void setVendorService(VendorService vendorService) {
582         OleInvoiceDocument.vendorService = vendorService;
583     }
584 
585     public static PurapService getPurapService() {
586         if (purapService == null) {
587             purapService = SpringContext.getBean(PurapService.class);
588         }
589         return purapService;
590     }
591 
592     public static void setPurapService(PurapService purapService) {
593         OleInvoiceDocument.purapService = purapService;
594     }
595 
596     public static OleInvoiceService getOleInvoiceService() {
597         if (oleInvoiceService == null) {
598             oleInvoiceService = SpringContext.getBean(OleInvoiceService.class);
599         }
600         return oleInvoiceService;
601     }
602 
603     public static void setOleInvoiceService(OleInvoiceService oleInvoiceService) {
604         OleInvoiceDocument.oleInvoiceService = oleInvoiceService;
605     }
606 
607     public static IdentityManagementService getIdentityManagementService() {
608         if (identityManagementService == null) {
609             identityManagementService = SpringContext.getBean(IdentityManagementService.class);
610         }
611         return identityManagementService;
612     }
613 
614     public static void setIdentityManagementService(IdentityManagementService identityManagementService) {
615         OleInvoiceDocument.identityManagementService = identityManagementService;
616     }
617 
618     public static AccountsPayableService getAccountsPayableService() {
619         if (accountsPayableService == null) {
620             accountsPayableService = SpringContext.getBean(AccountsPayableService.class);
621         }
622         return accountsPayableService;
623     }
624 
625     public static void setAccountsPayableService(AccountsPayableService accountsPayableService) {
626         OleInvoiceDocument.accountsPayableService = accountsPayableService;
627     }
628 
629     public static ConfigurationService getConfigurationService() {
630         if (kualiConfigurationService == null) {
631             kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
632         }
633         return kualiConfigurationService;
634     }
635 
636     public static void setConfigurationService(ConfigurationService kualiConfigurationService) {
637         OleInvoiceDocument.kualiConfigurationService = kualiConfigurationService;
638     }
639 
640     public static BibInfoWrapperService getBibInfoWrapperService() {
641         if (bibInfoWrapperService == null) {
642             bibInfoWrapperService = SpringContext.getBean(BibInfoWrapperService.class);
643         }
644         return bibInfoWrapperService;
645     }
646 
647     public static void setBibInfoWrapperService(BibInfoWrapperService bibInfoWrapperService) {
648         OleInvoiceDocument.bibInfoWrapperService = bibInfoWrapperService;
649     }
650 
651 
652     public static FileProcessingService getFileProcessingService() {
653         if (fileProcessingService == null) {
654             fileProcessingService = SpringContext.getBean(FileProcessingService.class);
655         }
656         return fileProcessingService;
657     }
658 
659     public static void setFileProcessingService(FileProcessingService fileProcessingService) {
660         OleInvoiceDocument.fileProcessingService = fileProcessingService;
661     }
662 
663     public static DateTimeService getDateTimeService() {
664         if (dateTimeService == null) {
665             dateTimeService = SpringContext.getBean(DateTimeService.class);
666         }
667         return dateTimeService;
668     }
669 
670     public static void setDateTimeService(DateTimeService dateTimeService) {
671         OleInvoiceDocument.dateTimeService = dateTimeService;
672     }
673 
674     @Override
675     public BusinessObjectService getBusinessObjectService() {
676         if (businessObjectService == null) {
677             businessObjectService = SpringContext.getBean(BusinessObjectService.class);
678         }
679         return businessObjectService;
680     }
681 
682     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
683         this.businessObjectService = businessObjectService;
684     }
685 
686     /**
687      * Default constructor.
688      */
689     public OleInvoiceDocument() {
690         super();
691         /*this.setProrateBy(OLEConstants.PRORATE_BY_DOLLAR);
692         this.setProrateDollar(true);*/
693     }
694 
695     public void initiateDocument() throws WorkflowException {
696         super.initiateDocument();
697         OleInvoiceItem item;
698         this.setUseTaxIndicator(false);
699         String[] collapseSections = getOleInvoiceService().getDefaultCollapseSections();
700         this.setOverviewFlag(getOleInvoiceService().canCollapse(OLEConstants.OVERVIEW_SECTION, collapseSections));
701         this.setVendorInfoFlag(getOleInvoiceService().canCollapse(OLEConstants.VENDOR_INFO_SECTION, collapseSections));
702         this.setInvoiceInfoFlag(getOleInvoiceService().canCollapse(OLEConstants.INVOICE_INFO_SECTION, collapseSections));
703         this.setProcessItemFlag(getOleInvoiceService().canCollapse(OLEConstants.PROCESS_ITEMS_SECTION, collapseSections));
704         this.setProcessTitlesFlag(getOleInvoiceService().canCollapse(OLEConstants.PROCESS_TITLES_SECTION, collapseSections));
705         this.setCurrentItemsFlag(getOleInvoiceService().canCollapse(OLEConstants.CURRENT_ITEM_SECTION, collapseSections));
706         this.setAdditionalChargesFlag(getOleInvoiceService().canCollapse(OLEConstants.ADDITIONAL_CHARGES_SECTION, collapseSections));
707         this.setAccountSummaryFlag(getOleInvoiceService().canCollapse(OLEConstants.ACCOUNT_SUMMARY_SECTION, collapseSections));
708         this.setAdHocRecipientsFlag(getOleInvoiceService().canCollapse(OLEConstants.ADHOC_RECIPIENT_SECTION, collapseSections));
709         this.setRouteLogFlag(getOleInvoiceService().canCollapse(OLEConstants.ROUTE_LOG_SECTION, collapseSections));
710         this.setNotesAndAttachmentFlag(getOleInvoiceService().canCollapse(OLEConstants.NOTES_AND_ATTACH_SECTION, collapseSections));
711 
712         if (this.getItems() == null || this.getItems().size() == 0) {
713             this.items = new ArrayList<>();
714             SpringContext.getBean(PurapService.class).addBelowLineItems(this);
715             List<OleInvoiceItem> oleInvItems = this.getItems();
716             for (OleInvoiceItem oleInvoiceItem : oleInvItems) {
717                 oleInvoiceItem.setPostingYear(SpringContext.getBean(UniversityDateService.class).getCurrentUniversityDate().getUniversityFiscalYear());
718             }
719         }
720     }
721 
722     /**
723      * This method is overridden to populate Ole InvoiceDocument from PurchaseOrder Document
724      *
725      * @see org.kuali.ole.module.purap.document.InvoiceDocument#populateInvoiceFromPurchaseOrder(org.kuali.ole.module.purap.document.PurchaseOrderDocument, java.util.HashMap)
726      */
727     @Override
728     public void populateInvoiceFromPurchaseOrder(PurchaseOrderDocument po, HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList) {
729         LOG.debug("Inside populateInvoiceFromPurchaseOrder method of OleInvoice Document");
730         this.setPaymentMethodId(po.getVendorDetail().getPaymentMethodId());
731         this.setPurchaseOrderIdentifier(po.getPurapDocumentIdentifier());
732         this.getDocumentHeader().setOrganizationDocumentNumber(po.getDocumentHeader().getOrganizationDocumentNumber());
733         this.setPostingYear(po.getPostingYear());
734         this.setReceivingDocumentRequiredIndicator(po.isReceivingDocumentRequiredIndicator());
735         this.setUseTaxIndicator(po.isUseTaxIndicator());
736         this.setInvoicePositiveApprovalIndicator(po.isPaymentRequestPositiveApprovalIndicator());
737         this.setVendorCustomerNumber(po.getVendorCustomerNumber());
738 
739         if (po.getPurchaseOrderCostSource() != null) {
740             this.setInvoiceCostSource(po.getPurchaseOrderCostSource());
741             this.setInvoiceCostSourceCode(po.getPurchaseOrderCostSourceCode());
742         }
743 
744         if (po.getVendorShippingPaymentTerms() != null) {
745             this.setVendorShippingPaymentTerms(po.getVendorShippingPaymentTerms());
746             this.setVendorShippingPaymentTermsCode(po.getVendorShippingPaymentTermsCode());
747         }
748 
749         if (po.getVendorPaymentTerms() != null) {
750             this.setVendorPaymentTermsCode(po.getVendorPaymentTermsCode());
751             this.setVendorPaymentTerms(po.getVendorPaymentTerms());
752         }
753 
754         if (po.getRecurringPaymentType() != null) {
755             this.setRecurringPaymentType(po.getRecurringPaymentType());
756             this.setRecurringPaymentTypeCode(po.getRecurringPaymentTypeCode());
757         }
758 
759         Bank defaultBank = SpringContext.getBean(BankService.class).getDefaultBankByDocType(this.getClass());
760         if (defaultBank != null) {
761             this.setBankCode(defaultBank.getBankCode());
762             this.setBank(defaultBank);
763         }
764         this.setVendorHeaderGeneratedIdentifier(po.getVendorHeaderGeneratedIdentifier());
765         this.setVendorDetailAssignedIdentifier(po.getVendorDetailAssignedIdentifier());
766         this.setVendorCustomerNumber(po.getVendorCustomerNumber());
767         this.setVendorName(po.getVendorName());
768 
769         // set original vendor
770         this.setOriginalVendorHeaderGeneratedIdentifier(po.getVendorHeaderGeneratedIdentifier());
771         this.setOriginalVendorDetailAssignedIdentifier(po.getVendorDetailAssignedIdentifier());
772 
773         // set alternate vendor info as well
774         this.setAlternateVendorHeaderGeneratedIdentifier(po.getAlternateVendorHeaderGeneratedIdentifier());
775         this.setAlternateVendorDetailAssignedIdentifier(po.getAlternateVendorDetailAssignedIdentifier());
776 
777         // populate preq vendor address with the default remit address type for the vendor if found
778         String userCampus = GlobalVariables.getUserSession().getPerson().getCampusCode();
779         VendorAddress vendorAddress = getVendorService().getVendorDefaultAddress(po.getVendorHeaderGeneratedIdentifier(), po.getVendorDetailAssignedIdentifier(), VendorConstants.AddressTypes.REMIT, userCampus);
780         if (vendorAddress != null) {
781             this.templateVendorAddress(vendorAddress);
782             this.setVendorAddressGeneratedIdentifier(vendorAddress.getVendorAddressGeneratedIdentifier());
783             setVendorAttentionName(StringUtils.defaultString(vendorAddress.getVendorAttentionName()));
784         } else {
785             // set address from PO
786             this.setVendorAddressGeneratedIdentifier(po.getVendorAddressGeneratedIdentifier());
787             this.setVendorLine1Address(po.getVendorLine1Address());
788             this.setVendorLine2Address(po.getVendorLine2Address());
789             this.setVendorCityName(po.getVendorCityName());
790             this.setVendorAddressInternationalProvinceName(po.getVendorAddressInternationalProvinceName());
791             this.setVendorStateCode(po.getVendorStateCode());
792             this.setVendorPostalCode(po.getVendorPostalCode());
793             this.setVendorCountryCode(po.getVendorCountryCode());
794 
795             boolean blankAttentionLine = StringUtils.equalsIgnoreCase(
796                     "Y",
797                     SpringContext.getBean(ParameterService.class).getParameterValueAsString(
798                             PurapConstants.PURAP_NAMESPACE, "Document",
799                             PurapParameterConstants.BLANK_ATTENTION_LINE_FOR_PO_TYPE_ADDRESS));
800 
801             if (blankAttentionLine) {
802                 setVendorAttentionName(StringUtils.EMPTY);
803             } else {
804                 setVendorAttentionName(StringUtils.defaultString(po.getVendorAttentionName()));
805             }
806         }
807 
808         this.setInvoicePayDate(getInvoiceService().calculatePayDate(this.getInvoiceDate(), this.getVendorPaymentTerms()));
809 
810         if (getInvoiceService().encumberedItemExistsForInvoicing(po)) {
811             for (OlePurchaseOrderItem poi : (List<OlePurchaseOrderItem>) po.getItems()) {
812                 // check to make sure it's eligible for payment (i.e. active and has encumbrance available
813                 if (getDocumentSpecificService().poItemEligibleForAp(this, poi)) {
814                     OleInvoiceItem invoiceItem = new OleInvoiceItem(poi, this, expiredOrClosedAccountList);
815                     invoiceItem.setReceivingDocumentRequiredIndicator(po.isReceivingDocumentRequiredIndicator());
816                     this.getItems().add(invoiceItem);
817                     PurchasingCapitalAssetItem purchasingCAMSItem = po.getPurchasingCapitalAssetItemByItemIdentifier(poi.getItemIdentifier());
818                     if (purchasingCAMSItem != null) {
819                         invoiceItem.setCapitalAssetTransactionTypeCode(purchasingCAMSItem.getCapitalAssetTransactionTypeCode());
820                     }
821 
822                     /*
823                     // copy usetaxitems over
824                     invoiceItem.getUseTaxItems().clear();
825                     for (PurApItemUseTax useTax : poi.getUseTaxItems()) {
826                         invoiceItem.getUseTaxItems().add(useTax);
827                     }
828                     */
829                 }
830             }
831         }
832 
833         // add missing below the line
834         getPurapService().addBelowLineItems(this);
835         this.setAccountsPayablePurchasingDocumentLinkIdentifier(po.getAccountsPayablePurchasingDocumentLinkIdentifier());
836 
837         //fix up below the line items
838         getInvoiceService().removeIneligibleAdditionalCharges(this);
839 
840         this.fixItemReferences();
841         this.refreshNonUpdateableReferences();
842     }
843 
844     @Override
845     public Class getItemClass() {
846         return OleInvoiceItem.class;
847     }
848 
849     @Override
850     public PurApAccountingLine getFirstAccount() {
851         // loop through items, and pick the first item
852         if ((getItems() != null) && (!getItems().isEmpty())) {
853             OleInvoiceItem itemToUse = null;
854             for (Iterator iter = getItems().iterator(); iter.hasNext(); ) {
855                 OleInvoiceItem item = (OleInvoiceItem) iter.next();
856                 if ((item.isConsideredEntered()) && ((item.getSourceAccountingLines() != null) && (!item.getSourceAccountingLines().isEmpty()))) {
857                     // accounting lines are not empty so pick the first account
858                     PurApAccountingLine accountLine = item.getSourceAccountingLine(0);
859                     accountLine.refreshNonUpdateableReferences();
860                     return accountLine;
861                 }
862                 /*
863                 if (((item.getExtendedPrice() != null) && item.getExtendedPrice().compareTo(BigDecimal.ZERO) > 0) && ((item.getAccounts() != null) && (!item.getAccounts().isEmpty()))) {
864                     // accounting lines are not empty so pick the first account
865                List accts = (List)item.getAccounts();
866                InvoiceAccount accountLine = (InvoiceAccount)accts.get(0);
867                     return accountLine.getFinancialChartOfAccountsCode() + "-" + accountLine.getAccountNumber();
868                 }
869                 */
870             }
871         }
872         return null;
873 
874     }
875 
876     @Override
877     public PurApItem getItem(int pos) {
878         OleInvoiceItem item = (OleInvoiceItem) super.getItem(pos);
879         if (item.getInvoice() == null) {
880             item.setInvoice(this);
881         }
882         return item;
883     }
884 
885    /* @Override
886     public void processAfterRetrieve() {
887         super.processAfterRetrieve();
888     }*/
889 
890     public void loadInvoiceDocument() {
891     try {
892         long b1 = System.currentTimeMillis();
893      //   super.processAfterRetrieve();
894         LOG.debug("###########inside OleInvoiceDocument processAfterRetrieve###########");
895 
896         if (this.getPaymentMethodId() != null) {
897             OlePaymentMethod olePaymentMethod = SpringContext.getBean(BusinessObjectService.class)
898                     .findBySinglePrimaryKey(OlePaymentMethod.class, this.getPaymentMethodId());
899             this.setPaymentMethod(olePaymentMethod);
900             this.setPaymentMethodIdentifier(this.getPaymentMethodId().toString());
901         }
902         if (this.getInvoiceTypeId() != null) {
903             this.setInvoiceTypeHdnId(this.getInvoiceTypeId().toString());
904         }
905         if (this.getInvoiceSubTypeId() != null) {
906             this.setInvoiceSubTypeHdnId(this.getInvoiceSubTypeId().toString());
907         }
908         if (this.getVendorInvoiceAmount() != null) {
909             this.setInvoiceAmount(this.getVendorInvoiceAmount().toString());
910         }
911         if (this.getForeignVendorInvoiceAmount() != null) {
912             this.setForeignInvoiceAmount(this.getForeignVendorInvoiceAmount().toString());
913         }
914         List<BigDecimal> newUnitPriceList = new ArrayList<BigDecimal>();
915         BigDecimal newUnitPrice = new BigDecimal(0);
916         BigDecimal hundred = new BigDecimal(100);
917         List<OleInvoiceItem> item = this.getItems();
918         String titleId = null;
919         //int itemCount = 0;
920          /*   List<String> itemIds = new ArrayList<>();
921             for(OleInvoiceItem invoiceItem : (List<OleInvoiceItem>)this.getItems()){
922                 if(invoiceItem.getItemTitleId()!=null){
923                     itemIds.add(invoiceItem.getItemTitleId());
924                 }
925             }
926             DocstoreClientLocator docstoreClientLocator = new DocstoreClientLocator();
927             List<Bib> bibs = new ArrayList<>();
928             if(itemIds.size()>0){
929                 bibs = docstoreClientLocator.getDocstoreClient().retrieveBibs(itemIds);
930             }*/
931         String itemDescription = "";
932         BigDecimal exchangeRate = new BigDecimal("0");
933         if (this.getInvoiceCurrencyTypeId() != null) {
934             OleCurrencyType oleCurrencyType = SpringContext.getBean(BusinessObjectService.class)
935                     .findBySinglePrimaryKey(OleCurrencyType.class, this.getInvoiceCurrencyTypeId());
936             this.setOleCurrencyType(oleCurrencyType);
937             this.setInvoiceCurrencyType(this.getInvoiceCurrencyTypeId().toString());
938             if ( oleCurrencyType.getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME) ){
939                 currencyTypeIndicator=true;
940                 this.setForeignCurrencyFlag(false);
941             } else {
942                 currencyTypeIndicator=false;
943                 this.setForeignCurrencyFlag(true);
944             }
945         } else {
946             if ( this.getVendorDetail() !=null && this.getVendorDetail().getCurrencyType() != null ){
947                 if(this.getVendorDetail().getCurrencyType().getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){
948                     currencyTypeIndicator=true;
949                     this.setForeignCurrencyFlag(false);
950                     this.setInvoiceCurrencyType(this.getVendorDetail().getCurrencyType().getCurrencyTypeId().toString());
951                 }
952                 else{
953                     currencyTypeIndicator=false;
954                     this.setForeignCurrencyFlag(true);
955                     this.setInvoiceCurrencyType(this.getVendorDetail().getCurrencyType().getCurrencyTypeId().toString());
956                 }
957             }
958         }
959 
960         if (this.getInvoiceCurrencyTypeId() != null && (!currencyTypeIndicator) ){
961             if (StringUtils.isBlank(this.getInvoiceCurrencyExchangeRate())) {
962                 exchangeRate = SpringContext.getBean(OleInvoiceService.class).getExchangeRate(this.getInvoiceCurrencyType()).getExchangeRate();
963                 this.setInvoiceCurrencyExchangeRate(exchangeRate.toString());
964                 //    items.setItemExchangeRate(new KualiDecimal(exchangeRate));
965                 //    items.setExchangeRate(exchangeRate.toString());
966             }
967         }
968 
969         for (int i = 0; item.size() > i; i++) {
970             OleInvoiceItem items = (OleInvoiceItem) this.getItem(i);
971             if (this.getInvoiceCurrencyTypeId() != null) {
972                 items.setItemCurrencyType(oleCurrencyType.getCurrencyType());
973                 items.setInvoicedCurrency(oleCurrencyType.getCurrencyType());
974             } else {
975                 if (this.getVendorDetail() !=null && this.getVendorDetail().getCurrencyType() != null ){
976                     items.setItemCurrencyType(this.getVendorDetail().getCurrencyType().getCurrencyType());
977                     items.setInvoicedCurrency(this.getVendorDetail().getCurrencyType().getCurrencyType());
978                 }
979             }
980 
981             if (this.getInvoiceCurrencyTypeId() != null && (!currencyTypeIndicator) ){
982                 if (StringUtils.isNotBlank(this.getInvoiceCurrencyExchangeRate())) {
983                     try {
984                         //          Double.parseDouble(this.getInvoiceCurrencyExchangeRate());
985                         items.setItemExchangeRate(new KualiDecimal(this.getInvoiceCurrencyExchangeRate()));
986                         items.setExchangeRate(this.getInvoiceCurrencyExchangeRate());
987                     }
988                     catch (NumberFormatException nfe) {
989                         throw new RuntimeException("Invalid Exchange Rate", nfe);
990                     }
991                 }   else {
992                     items.setItemExchangeRate(new KualiDecimal(exchangeRate));
993                     items.setExchangeRate(exchangeRate.toString());
994                 }
995                 if (items.getItemExchangeRate() != null && items.getItemForeignUnitCost() != null   && !this.getApplicationDocumentStatus().equals("Department-Approved")) {
996                     items.setItemUnitCostUSD(new KualiDecimal(items.getItemForeignUnitCost().bigDecimalValue().divide(new BigDecimal(items.getExchangeRate()), 4, BigDecimal.ROUND_HALF_UP)));
997                     items.setItemUnitPrice(items.getItemForeignUnitCost().bigDecimalValue().divide(new BigDecimal(items.getExchangeRate()), 4, BigDecimal.ROUND_HALF_UP));
998                     items.setItemListPrice(items.getItemUnitCostUSD());
999                     items.setExtendedPrice(items.calculateExtendedPrice());
1000                 }
1001                 //this.setForeignVendorInvoiceAmount(this.getVendorInvoiceAmount().bigDecimalValue().multiply(tempOleExchangeRate.getExchangeRate()));
1002             }
1003 
1004             if (LOG.isDebugEnabled()) {
1005                 LOG.debug("Title id while retriving ------>" + items.getItemTitleId());
1006             }
1007             if (items.getItemTitleId() != null) {
1008                 BibInfoRecord  bibInfoRecord = items.getBibInfoRecord();
1009 
1010                 if(bibInfoRecord !=null){
1011                     items.setBibUUID(bibInfoRecord.getBibIdStr());
1012                     items.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(items.getItemTitleId()));
1013 
1014                     itemDescription = ((bibInfoRecord.getTitle() != null && !bibInfoRecord.getTitle().isEmpty()) ? bibInfoRecord.getTitle().trim() + ", " : "")
1015                             + ((bibInfoRecord.getAuthor() != null && !bibInfoRecord
1016                             .getAuthor().isEmpty()) ? bibInfoRecord.getAuthor().trim() + ", "
1017                             : "")
1018                             + ((bibInfoRecord.getPublisher() != null && !bibInfoRecord
1019                             .getPublisher().isEmpty()) ? bibInfoRecord.getPublisher().trim()
1020                             + ", " : "")
1021                             + ((bibInfoRecord.getIsxn() != null && !bibInfoRecord.getIsxn()
1022                             .isEmpty()) ? bibInfoRecord.getIsxn().trim() + ", " : "");
1023                 }
1024                 if (itemDescription != null && !(itemDescription.equals(""))) {
1025                     itemDescription = itemDescription.lastIndexOf(",") < 0 ? itemDescription :
1026                             itemDescription.substring(0, itemDescription.lastIndexOf(","));
1027                     StringEscapeUtils stringEscapeUtils = new StringEscapeUtils();
1028                     itemDescription = stringEscapeUtils.unescapeXml(itemDescription);
1029                     items.setItemDescription(itemDescription);
1030                 }
1031                 HashMap<String, String> queryMap = new HashMap<String, String>();
1032                 if (items.getPoItemIdentifier() != null) {
1033                     queryMap.put(OLEConstants.OleCopy.PO_ITM_ID, items.getPoItemIdentifier().toString());
1034                     List<OLELinkPurapDonor> oleLinkPurapDonorList = (List<OLELinkPurapDonor>) getBusinessObjectService().findMatching(OLELinkPurapDonor.class, queryMap);
1035                     if (oleLinkPurapDonorList != null) {
1036                         items.setOleDonors(oleLinkPurapDonorList);
1037                         oleLinkPurapDonorList.clear();
1038                     }
1039                 }
1040             }
1041             if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())) {
1042                 if (items.getItemDiscount() == null) {
1043                     items.setItemDiscount(KualiDecimal.ZERO);
1044                 }
1045 
1046                 if (items.getItemListPrice() == null) {
1047                     items.setItemListPrice(KualiDecimal.ZERO);
1048                 }
1049 
1050                     /*   if (items.getItemDiscountType() != null && items.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
1051                        newUnitPrice = (hundred.subtract(items.getItemDiscount().bigDecimalValue())).divide(hundred).multiply(items.getItemListPrice().bigDecimalValue());
1052                    } else {
1053                        newUnitPrice = items.getItemListPrice().bigDecimalValue().subtract(items.getItemDiscount().bigDecimalValue());
1054                    }
1055                    items.setItemSurcharge(items.getItemUnitPrice().subtract(newUnitPrice).setScale(4, RoundingMode.HALF_UP));*/
1056             }
1057                 /*else if (items.getItemType().isAdditionalChargeIndicator() && (!currencyTypeIndicator)) {
1058                     if (items.getItemForeignUnitCost() != null) {
1059                         items.setAdditionalForeignUnitCost(items.getItemForeignUnitCost().toString());
1060                     }
1061                 }*/
1062             items.setOleOpenQuantity(String.valueOf(items.getPoOutstandingQuantity()));
1063         }
1064         if (this.getVendorHeaderGeneratedIdentifier() != null && this.getVendorDetailAssignedIdentifier() != null) {
1065             this.setVendorId(this.getVendorHeaderGeneratedIdentifier().toString() + "-" + this.getVendorDetailAssignedIdentifier().toString());
1066         }
1067 
1068         if (this.getProrateBy() != null) {
1069             this.setProrateQty(this.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY));
1070             this.setProrateManual(this.getProrateBy().equals(OLEConstants.MANUAL_PRORATE));
1071             this.setProrateDollar(this.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR));
1072             this.setNoProrate(this.getProrateBy().equals(OLEConstants.NO_PRORATE));
1073         }
1074         long b2 = System.currentTimeMillis();
1075         long tot = b2-b1;
1076         LOG.info("loadInvoiceDocument"+tot);
1077     } catch (Exception e) {
1078         LOG.error("Exception during processAfterRetrieve in OleInvoiceDocument "+e);
1079         throw new RuntimeException(e);
1080     }
1081 
1082     }
1083     /**
1084      * This method is overrided to create POA from new Line Item of Invoice
1085      *
1086      * @see org.kuali.ole.module.purap.document.InvoiceDocument#doRouteStatusChange(org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange)
1087      */
1088     @Override
1089     public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
1090         LOG.debug("doRouteStatusChange() started");
1091 
1092         super.doRouteStatusChange(statusChangeEvent);
1093         try {
1094             // DOCUMENT PROCESSED
1095             if (this.getDocumentHeader().getWorkflowDocument().isProcessed()) {
1096                 if (!InvoiceStatuses.APPDOC_AUTO_APPROVED.equals(getApplicationDocumentStatus())) {
1097                     //delete unentered items and update po totals and save po
1098                     getOleInvoiceService().completePaymentDocument(this);
1099                     this.setApplicationDocumentStatus(PurapConstants.InvoiceStatuses.APPDOC_DEPARTMENT_APPROVED);
1100                     if (this.getImmediatePaymentIndicator()) {
1101                         this.setInvoicePayDate(new java.sql.Date(this.getAccountsPayableApprovalTimestamp().getTime()));
1102                     }
1103                     /*if(this.getImmediatePaymentIndicator()) {
1104                         this.setInvoicePayDate(new java.sql.Date(this.getAccountsPayableApprovalTimestamp().getTime()));
1105                     }*/
1106                     populateDocumentForRouting();
1107                     getPurapService().saveDocumentNoValidation(this);
1108                     SpringContext.getBean(OleInvoiceService.class).createPaymentRequestOrCreditMemoDocument(this);
1109                     //SpringContext.getBean(OleInvoiceService.class).createPaymentRequest(this);
1110                     return;
1111                 }
1112             }
1113             /* else if (this.getFinancialSystemDocumentHeader().getWorkflowDocument().isFinal())  {
1114                 if(this.getImmediatePaymentIndicator()) {
1115                     this.setInvoicePayDate(new java.sql.Date(this.getAccountsPayableApprovalTimestamp().getTime()));
1116                 }
1117                 SpringContext.getBean(OleInvoiceService.class).createPaymentRequestOrCreditMemoDocument(this);
1118             }*/
1119 
1120             // DOCUMENT DISAPPROVED
1121             else if (this.getDocumentHeader().getWorkflowDocument().isDisapproved()) {
1122                 // String nodeName =
1123                 // getWorkflowDocumentService().getCurrentRouteLevelName(getDocumentHeader().getWorkflowDocument());
1124                 String nodeName = getDocumentHeader().getWorkflowDocument().getCurrentNodeNames().iterator().next();
1125                 HashMap<String, String> disApprovedStatusMap = PurapConstants.InvoiceStatuses
1126                         .getInvoiceAppDocDisapproveStatuses();
1127                 // NodeDetails currentNode = NodeDetailEnum.getNodeDetailEnumByName(nodeName);
1128                 // STATUS_ORDER currentNode = STATUS_ORDER.getByStatusCode(nodeName);
1129                 if (ObjectUtils.isNotNull(nodeName)) {
1130                     String newStatusCode = disApprovedStatusMap.get(nodeName);
1131                     // currentNode.getDisapprovedStatusCode();
1132                     if ((StringUtils.isBlank(newStatusCode))
1133                             && ((InvoiceStatuses.APPDOC_INITIATE.equals(getApplicationDocumentStatus())) || (InvoiceStatuses.APPDOC_IN_PROCESS
1134                             .equals(getApplicationDocumentStatus())))) {
1135                         newStatusCode = InvoiceStatuses.APPDOC_CANCELLED_POST_AP_APPROVE;
1136                     }
1137                     if (StringUtils.isNotBlank(newStatusCode)) {
1138                         getAccountsPayableService().cancelAccountsPayableDocument(this, nodeName);
1139                         return;
1140                     }
1141                 }
1142                 logAndThrowRuntimeException("No status found to set for document being disapproved in node '" + nodeName + "'");
1143             }
1144             // DOCUMENT CANCELED
1145             else if (this.getDocumentHeader().getWorkflowDocument().isCanceled()) {
1146                 // String currentNodeName =
1147                 // getWorkflowDocumentService().getCurrentRouteLevelName(this.getDocumentHeader().getWorkflowDocument());
1148                 // NodeDetails currentNode = NodeDetailEnum.getNodeDetailEnumByName(currentNodeName);
1149                 String nodeName = getDocumentHeader().getWorkflowDocument().getCurrentNodeNames().iterator().next();
1150                 HashMap<String, String> disApprovedStatusMap = PurapConstants.InvoiceStatuses
1151                         .getInvoiceAppDocDisapproveStatuses();
1152                 if (ObjectUtils.isNotNull(nodeName)) {
1153                     // String cancelledStatusCode = currentNode.getDisapprovedStatusCode();
1154                     String cancelledStatusCode = disApprovedStatusMap.get(nodeName);
1155                     if (StringUtils.isNotBlank(cancelledStatusCode)) {
1156                         this.setApplicationDocumentStatus(cancelledStatusCode);
1157                         getPurapService().saveDocumentNoValidation(this);
1158                         return;
1159                     }
1160                 }
1161                 logAndThrowRuntimeException("No status found to set for document being canceled in node '" + nodeName
1162                         + "'");
1163             }
1164         } catch (Exception e) {
1165             logAndThrowRuntimeException("Error saving routing data while saving document with id " + getDocumentNumber(), e);
1166         }
1167     }
1168 
1169     /**
1170      * Sends FYI workflow request to the given user on this document.
1171      *
1172      * @param workflowDocument the associated workflow document.
1173      * @param userNetworkId    the network ID of the user to be sent to.
1174      * @param annotation       the annotation notes contained in this document.
1175      * @param responsibility   the responsibility specified in the request.
1176      * @throws org.kuali.rice.kew.api.exception.WorkflowException
1177      *
1178      */
1179     public void appSpecificRouteDocumentToUser(WorkflowDocument workflowDocument, String userNetworkId,
1180                                                String annotation, String responsibility) throws WorkflowException {
1181         if (ObjectUtils.isNotNull(workflowDocument)) {
1182             String annotationNote = (ObjectUtils.isNull(annotation)) ? "" : annotation;
1183             String responsibilityNote = (ObjectUtils.isNull(responsibility)) ? "" : responsibility;
1184             String currentNodeName = getCurrentRouteNodeName(workflowDocument);
1185             Principal principal = getIdentityManagementService().getPrincipalByPrincipalName(userNetworkId);
1186             workflowDocument.adHocToPrincipal(ActionRequestType.FYI, currentNodeName, annotationNote,
1187                     principal.getPrincipalId(), responsibilityNote, true);
1188         }
1189     }
1190 
1191     /**
1192      * Returns the name of the current route node.
1193      *
1194      * @param wd the current workflow document.
1195      * @return the name of the current route node.
1196      * @throws org.kuali.rice.kew.api.exception.WorkflowException
1197      *
1198      */
1199     protected String getCurrentRouteNodeName(WorkflowDocument wd) throws WorkflowException {
1200         // String[] nodeNames = wd.getNodeNames();
1201         Set<String> nodeNameSet = wd.getNodeNames();
1202         String[] nodeNames = (String[]) nodeNameSet.toArray(); // Here it fails.
1203 
1204         if ((nodeNames == null) || (nodeNames.length == 0)) {
1205             return null;
1206         } else {
1207             return nodeNames[0];
1208         }
1209     }
1210 
1211     public BigDecimal getForeignVendorInvoiceAmount() {
1212         return foreignVendorInvoiceAmount;
1213     }
1214 
1215     public void setForeignVendorInvoiceAmount(BigDecimal foreignVendorInvoiceAmount) {
1216         this.foreignVendorInvoiceAmount = foreignVendorInvoiceAmount;
1217     }
1218 
1219     /**
1220      * This method is used to get the bibedtior creat url from propertie file
1221      *
1222      * @return Bibeditor creat url string
1223      */
1224     public String getBibeditorCreateURL() {
1225         String bibeditorCreateURL = getConfigurationService().getPropertyValueAsString(
1226                 OLEConstants.BIBEDITOR_CREATE_URL_KEY);
1227         return bibeditorCreateURL;
1228     }
1229 
1230     /**
1231      * This method is used to get the bibedtior edit url from propertie file
1232      *
1233      * @return Bibeditor edit url string
1234      */
1235     public String getBibeditorEditURL() {
1236         String bibeditorEditURL = getConfigurationService().getPropertyValueAsString(OLEConstants.BIBEDITOR_URL_KEY);
1237         return bibeditorEditURL;
1238     }
1239 
1240     /**
1241      * This method is used to get the bibedtior view url from propertie file
1242      *
1243      * @return Bibeditor view url string
1244      */
1245     public String getBibeditorViewURL() {
1246         String bibeditorViewURL = getConfigurationService().getPropertyValueAsString(OLEConstants.DOCSTORE_APP_URL_KEY);
1247         return bibeditorViewURL;
1248     }
1249 
1250     /**
1251      * This method is used to get the directory path where the marc xml files need to be created
1252      *
1253      * @return Directory path string
1254      */
1255     public String getMarcXMLFileDirLocation() throws Exception {
1256         String externaleDirectory = getFileProcessingService().getMarcXMLFileDirLocation();
1257         return externaleDirectory;
1258     }
1259 
1260     @Override
1261     public void prepareForSave(KualiDocumentEvent event) {
1262         // TODO Auto-generated method stub
1263         // first populate, then call super
1264         if (event instanceof AttributedContinuePurapEvent) {
1265             SpringContext.getBean(OleInvoiceService.class).populateInvoice(this);
1266         }
1267         if(this.getVendorPaymentTermsCode() != null && this.getVendorPaymentTermsCode().isEmpty()) {
1268             this.setVendorPaymentTermsCode(null);
1269         }
1270         super.prepareForSave(event);
1271         try {
1272             if (this.proformaIndicator && !this.immediatePaymentIndicator) {
1273                 this.setImmediatePaymentIndicator(true);
1274             }
1275             LOG.debug("###########Inside OleInvoiceDocument " + "repareForSave###########");
1276             List<OleInvoiceItem> items = new ArrayList<OleInvoiceItem>();
1277             items = this.getItems();
1278             Iterator iterator = items.iterator();
1279             HashMap dataMap = new HashMap();
1280             String titleId;
1281             while (iterator.hasNext()) {
1282                 LOG.debug("###########inside prepareForSave item loop###########");
1283                 Object object = iterator.next();
1284                 if (object instanceof OleInvoiceItem) {
1285                     LOG.debug("###########inside prepareForSave ole payment request item###########");
1286                     OleInvoiceItem singleItem = (OleInvoiceItem) object;
1287                     if (StringUtils.isNotBlank(this.invoiceCurrencyType)) {
1288                         this.setInvoiceCurrencyTypeId(new Long(this.getInvoiceCurrencyType()));
1289                         String currencyType = SpringContext.getBean(OleInvoiceService.class).getCurrencyType(this.getInvoiceCurrencyType());
1290                         if (StringUtils.isNotBlank(currencyType)) {
1291                             if(!currencyType.equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) {
1292                                 if (StringUtils.isNotBlank(this.getInvoiceCurrencyExchangeRate())) {
1293                                     try {
1294                                         Double.parseDouble(this.getInvoiceCurrencyExchangeRate());
1295                                         singleItem.setItemExchangeRate(new KualiDecimal(this.getInvoiceCurrencyExchangeRate()));
1296                                         singleItem.setExchangeRate(this.getInvoiceCurrencyExchangeRate());
1297                                     }
1298                                     catch (NumberFormatException nfe) {
1299                                         throw new RuntimeException("Invalid Exchange Rate", nfe);
1300                                     }
1301                                 }   else {
1302                                     BigDecimal exchangeRate = SpringContext.getBean(OleInvoiceService.class).getExchangeRate(this.getInvoiceCurrencyType()).getExchangeRate();
1303                                     this.setInvoiceCurrencyExchangeRate(exchangeRate.toString());
1304                                     singleItem.setItemExchangeRate(new KualiDecimal(exchangeRate));
1305                                     singleItem.setExchangeRate(exchangeRate.toString());
1306                                 }
1307                                 this.setVendorInvoiceAmount(this.getForeignVendorInvoiceAmount() != null ?
1308                                         new KualiDecimal(this.getForeignVendorInvoiceAmount().divide(new BigDecimal(singleItem.getExchangeRate()), 4, RoundingMode.HALF_UP)) : null);
1309                             }
1310                         }
1311                     }
1312                     setItemDescription(singleItem);
1313                     Map<String, String> copyCriteria = new HashMap<String, String>();
1314                     if (singleItem.getPaidCopies().size() <= 0 && singleItem.getPoItemIdentifier() != null && (this.getPurapDocumentIdentifier() != null && singleItem.getItemIdentifier() != null)) {
1315                         copyCriteria.put("poItemId", singleItem.getPoItemIdentifier().toString());
1316                         List<OleCopy> copies = (List<OleCopy>) getBusinessObjectService().findMatching(OleCopy.class, copyCriteria);
1317                         if (copies.size() > 0) {
1318                             List<OLEPaidCopy> paidCopies = new ArrayList<OLEPaidCopy>();
1319                             for (OleCopy copy : copies) {
1320                                 OLEPaidCopy paidCopy = new OLEPaidCopy();
1321                                 paidCopy.setCopyId(copy.getCopyId());
1322                                 paidCopy.setInvoiceItemId(this.getPurapDocumentIdentifier());
1323                                 paidCopy.setInvoiceIdentifier(singleItem.getItemIdentifier());
1324                                 //copy.getOlePaidCopies().add(paidCopy);
1325                                 paidCopies.add(paidCopy);
1326                             }
1327                             getBusinessObjectService().save(paidCopies);
1328                             singleItem.setPaidCopies(paidCopies);
1329                         }
1330                     }
1331                 }
1332             }
1333         } catch (Exception e) {
1334             LOG.error("Exception during prepareForSave() in OleInvoiceDocument", e);
1335             throw new RuntimeException(e);
1336         }
1337     }
1338 
1339     /* @Override
1340         public KualiDecimal getGrandTotal() {
1341             if ((this.prorateBy != null) && (this.prorateBy.equals(OLEConstants.PRORATE_BY_QTY) || this.prorateBy.equals(OLEConstants.PRORATE_BY_DOLLAR) || this.prorateBy.equals(OLEConstants.MANUAL_PRORATE))) {
1342                 return this.getGrandPreTaxTotal().add(this.getGrandTaxAmount());
1343             } else {
1344                 return super.getGrandTotal();
1345             }
1346         }
1347 
1348         @Override
1349         public KualiDecimal getGrandTotalExcludingDiscount() {
1350             String[] discountCode = new String[]{PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE};
1351             if ((this.prorateBy != null)
1352                     && (this.prorateBy.equals(OLEConstants.PRORATE_BY_QTY)
1353                     || this.prorateBy.equals(OLEConstants.PRORATE_BY_DOLLAR) || this.prorateBy
1354                     .equals(OLEConstants.MANUAL_PRORATE))) {
1355                 return this.getTotalDollarAmountWithExclusions(discountCode, false);
1356             } else {
1357                 return this.getTotalDollarAmountWithExclusions(discountCode, true);
1358             }
1359         }
1360 
1361         @Override
1362         public KualiDecimal getTotalDollarAmountAllItems(String[] excludedTypes) {
1363             if ((this.prorateBy != null)
1364                     && (this.prorateBy.equals(OLEConstants.PRORATE_BY_QTY)
1365                     || this.prorateBy.equals(OLEConstants.PRORATE_BY_DOLLAR) || this.prorateBy
1366                     .equals(OLEConstants.MANUAL_PRORATE))) {
1367                 return getTotalDollarAmountWithExclusions(excludedTypes, false);
1368             } else {
1369                 return getTotalDollarAmountWithExclusions(excludedTypes, true);
1370             }
1371         }
1372 
1373         @Override
1374         public KualiDecimal getGrandPreTaxTotalExcludingDiscount() {
1375             String[] discountCode = new String[]{PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE};
1376             if ((this.prorateBy != null)
1377                     && (this.prorateBy.equals(OLEConstants.PRORATE_BY_QTY)
1378                     || this.prorateBy.equals(OLEConstants.PRORATE_BY_DOLLAR) || this.prorateBy
1379                     .equals(OLEConstants.MANUAL_PRORATE))) {
1380                 return this.getTotalPreTaxDollarAmountWithExclusions(discountCode, false);
1381             } else {
1382                 return this.getTotalPreTaxDollarAmountWithExclusions(discountCode, true);
1383             }
1384         }
1385 
1386         @Override
1387         public KualiDecimal getGrandTaxAmountExcludingDiscount() {
1388             String[] discountCode = new String[]{PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE};
1389             if ((this.prorateBy != null)
1390                     && (this.prorateBy.equals(OLEConstants.PRORATE_BY_QTY)
1391                     || this.prorateBy.equals(OLEConstants.PRORATE_BY_DOLLAR) || this.prorateBy
1392                     .equals(OLEConstants.MANUAL_PRORATE))) {
1393                 return this.getTotalTaxAmountWithExclusions(discountCode, false);
1394             } else {
1395                 return this.getTotalTaxAmountWithExclusions(discountCode, true);
1396             }
1397         }
1398 
1399         @Override
1400         public KualiDecimal getTotalPreTaxDollarAmountAllItems(String[] excludedTypes) {
1401             if ((this.prorateBy != null)
1402                     && (this.prorateBy.equals(OLEConstants.PRORATE_BY_QTY)
1403                     || this.prorateBy.equals(OLEConstants.PRORATE_BY_DOLLAR) || this.prorateBy
1404                     .equals(OLEConstants.MANUAL_PRORATE))) {
1405                 return getTotalPreTaxDollarAmountWithExclusions(excludedTypes, false);
1406             } else {
1407                 return getTotalPreTaxDollarAmountWithExclusions(excludedTypes, true);
1408             }
1409         }
1410 
1411         @Override
1412         public KualiDecimal getTotalPreTaxDollarAmountAboveLineItems() {
1413             if ((this.prorateBy != null) && (this.prorateBy.equals(OLEConstants.PRORATE_BY_QTY) || this.prorateBy.equals(OLEConstants.PRORATE_BY_DOLLAR) || this.prorateBy.equals(OLEConstants.MANUAL_PRORATE))) {
1414                 KualiDecimal addChargeItem = KualiDecimal.ZERO;
1415                 KualiDecimal lineItemPreTaxTotal = KualiDecimal.ZERO;
1416                 KualiDecimal prorateSurcharge = KualiDecimal.ZERO;
1417                 List<OleInvoiceItem> item = this.getItems();
1418                 for (OleInvoiceItem items : item) {
1419                     if (items.getItemType().isQuantityBasedGeneralLedgerIndicator() && items.getExtendedPrice() != null && items.getExtendedPrice().compareTo(KualiDecimal.ZERO) != 0) {
1420                         if (items.getItemSurcharge() != null) {
1421                             prorateSurcharge = new KualiDecimal(items.getItemSurcharge());
1422                         }
1423                         addChargeItem = addChargeItem.add(items.getExtendedPrice().subtract(prorateSurcharge.multiply(items.getItemQuantity())));
1424                     }
1425                 }
1426                 lineItemPreTaxTotal = addChargeItem;
1427                 return lineItemPreTaxTotal;
1428             } else {
1429                 return super.getTotalPreTaxDollarAmountAboveLineItems();
1430             }
1431         }
1432     */
1433 
1434     /**
1435      * This method is used to check the status of the document for displaying view and edit buttons in line item
1436      *
1437      * @return boolean
1438      */
1439     public boolean getIsSaved() {
1440         if (this.getDocumentHeader().getWorkflowDocument().isSaved()
1441                 || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
1442             return true;
1443         }
1444         return false;
1445     }
1446 
1447     private void setItemDescription(OleInvoiceItem singleItem) throws Exception {
1448         if (singleItem.getOleOrderRecord() != null) {
1449             Map<String, ?> bibAssociatedFieldValuesMap = singleItem.getOleOrderRecord().getOleBibRecord().getBibAssociatedFieldsValueMap();
1450             List titleList = (List) bibAssociatedFieldValuesMap.get("Title_search");
1451             String title = titleList != null && !titleList.isEmpty() ? (String) (titleList).get(0) : null;
1452             List authorList = (List) bibAssociatedFieldValuesMap.get("Author_search");
1453             String author = authorList != null && !authorList.isEmpty() ? (String) (authorList).get(0) : null;
1454             List publisherList = (List) bibAssociatedFieldValuesMap.get("Publisher_search");
1455             String publisher = publisherList != null && !publisherList.isEmpty() ? (String) (publisherList).get(0) : null;
1456             List isbnList = (List) bibAssociatedFieldValuesMap.get("020a");
1457             String isbn = isbnList != null && !isbnList.isEmpty() ? (String) (isbnList).get(0) : null;
1458 
1459             singleItem.setBibUUID(singleItem.getOleOrderRecord().getOleBibRecord().getBibUUID());
1460             singleItem.setItemDescription(title + "," + author + "," + publisher + "," + isbn);
1461         }
1462     }
1463 
1464     public String getProrateBy() {
1465         return prorateBy;
1466     }
1467 
1468     public void setProrateBy(String prorateBy) {
1469         this.prorateBy = prorateBy;
1470     }
1471 
1472     /**
1473      * This method returns the boolean if the proforma indicator is selected
1474      *
1475      * @return proformaIndicator
1476      */
1477     public boolean isProformaIndicator() {
1478         return proformaIndicator;
1479     }
1480 
1481     /**
1482      * This method sets the proforma Indicator
1483      *
1484      * @param proformaIndicator
1485      */
1486 
1487     public void setProformaIndicator(boolean proformaIndicator) {
1488         this.proformaIndicator = proformaIndicator;
1489     }
1490 
1491     /**
1492      * Payment Request needs to wait for receiving if the receiving requirements have NOT been met.
1493      *
1494      * @return
1495      */
1496     @Override
1497     protected boolean shouldWaitForReceiving() {
1498         // only require if PO was marked to require receiving
1499         Boolean invReceiveInd = false;
1500         //List<OleInvoiceItem> invItem = (List<OleInvoiceItem>) this.getItems();
1501         for (OleInvoiceItem invoiceItem : (List<OleInvoiceItem>) this.getItems()) {
1502             if (invoiceItem.isReceivingDocumentRequiredIndicator()) {
1503                 invReceiveInd = true;
1504                 break;
1505             }
1506         }
1507 
1508 
1509         if (invReceiveInd && !this.proformaIndicator) {
1510             return !isReceivingRequirementMet();
1511         }
1512 
1513         //receiving is not required or has already been fulfilled, no need to stop for routing
1514         return false;
1515     }
1516 
1517     /**
1518      * Provides answers to the following splits: PurchaseWasReceived VendorIsEmployeeOrNonResidentAlien
1519      *
1520      * @see org.kuali.ole.sys.document.FinancialSystemTransactionalDocumentBase#answerSplitNodeQuestion(String)
1521      */
1522     @Override
1523     public boolean answerSplitNodeQuestion(String nodeName) throws UnsupportedOperationException {
1524         if (nodeName.equals(OLEConstants.HAS_VENDOR_DEPOSIT_ACCOUNT)) {
1525             return hasVendorDepositAccount();
1526         }
1527         if (nodeName.equals(OLEConstants.OleInvoice.HAS_INVOICE_TYPE)) {
1528             return hasInvoiceType();
1529         }
1530         if (nodeName.equals(OLEConstants.OleInvoice.HAS_PREPAID_INVOICE_TYPE)) {
1531             return hasPrepaidInvoiceType();
1532         }
1533         if (nodeName.equals(OLEConstants.OleInvoice.HAS_PAYMENT_METHOD)) {
1534             return hasPaymentMethod();
1535         }
1536         if (nodeName.equals(PurapWorkflowConstants.BUDGET_REVIEW_REQUIRED)) {
1537             return isBudgetReviewRequired();
1538         }
1539         if (nodeName.equals(PurapWorkflowConstants.REQUIRES_IMAGE_ATTACHMENT)) {
1540             return requiresAccountsPayableReviewRouting();
1541         }
1542         if (nodeName.equals(PurapWorkflowConstants.PURCHASE_WAS_RECEIVED)) {
1543             return shouldWaitForReceiving();
1544         }
1545         if (nodeName.equals(PurapWorkflowConstants.VENDOR_IS_EMPLOYEE_OR_NON_RESIDENT_ALIEN)) {
1546             return isVendorEmployeeOrNonResidentAlien();
1547         }
1548         if (nodeName.equals(OLEConstants.REQUIRES_SEPARATION_OF_DUTIES)) {
1549             return isSeparationOfDutiesReviewRequired();
1550         }
1551 
1552         if (nodeName.equals(PurapWorkflowConstants.NOTIFY_BUDGET_REVIEW)) {
1553             return isNotificationRequired();
1554         }
1555         throw new UnsupportedOperationException("Cannot answer split question for this node you call \"" + nodeName + "\"");
1556     }
1557 
1558     private boolean hasInvoiceType() {
1559         if (this.getInvoiceTypeId() != null) {
1560             return true;
1561         }
1562         return false;
1563     }
1564 
1565     private boolean hasVendorDepositAccount() {
1566         if (this.getPaymentMethodIdentifier() != null) {
1567             String paymentType = SpringContext.getBean(OleInvoiceService.class).getPaymentMethodType(this.getPaymentMethodIdentifier());
1568             if (paymentType.equals("Deposit")) {
1569                 return true;
1570             }
1571         }
1572         return false;
1573     }
1574 
1575     private boolean hasPrepaidInvoiceType() {
1576         if (this.getInvoiceTypeId() != null) {
1577             Map<String, String> invoiceMap = new HashMap<String, String>();
1578             invoiceMap.put("invoiceTypeId", this.getInvoiceTypeId().toString());
1579             OleInvoiceType invoiceType = this.getBusinessObjectService().findByPrimaryKey(OleInvoiceType.class,
1580                     invoiceMap);
1581             if (invoiceType != null &&
1582                     invoiceType.getInvoiceType().equals("Prepay") ||
1583                     invoiceType.getInvoiceType().equals("Deposit")) {
1584                 return true;
1585             }
1586         }
1587         return false;
1588     }
1589 
1590     private boolean hasPaymentMethod() {
1591         if (this.getPaymentMethodId() != null) {
1592             return true;
1593         }
1594         return false;
1595     }
1596 
1597     public Set<Person> getAllPriorApprovers() throws WorkflowException {
1598         PersonService personService = KimApiServiceLocator.getPersonService();
1599         List<ActionTaken> actionsTaken = getDocumentHeader().getWorkflowDocument().getActionsTaken();
1600         Set<String> principalIds = new HashSet<String>();
1601         Set<Person> persons = new HashSet<Person>();
1602 
1603         for (ActionTaken actionTaken : actionsTaken) {
1604             if (KewApiConstants.ACTION_TAKEN_APPROVED_CD.equals(actionTaken.getActionTaken())) {
1605                 String principalId = actionTaken.getPrincipalId();
1606                 if (!principalIds.contains(principalId)) {
1607                     principalIds.add(principalId);
1608                     persons.add(personService.getPerson(principalId));
1609                 }
1610             }
1611         }
1612         return persons;
1613     }
1614 
1615     protected boolean isSeparationOfDutiesReviewRequired() {
1616         try {
1617             Set<Person> priorApprovers = getAllPriorApprovers();
1618 
1619             // The initiator cannot be the approver
1620             String initiatorPrincipalId = getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
1621             Person initiator = SpringContext.getBean(PersonService.class).getPerson(initiatorPrincipalId);
1622             // If there is only one approver, and that approver is also the initiator, then Separation of Duties is required.
1623             boolean priorApproverIsInitiator = priorApprovers.contains(initiator);
1624             boolean onlyOneApprover = (priorApprovers.size() == 1);
1625             if (priorApproverIsInitiator && onlyOneApprover) {
1626                 return true;
1627             }
1628 
1629             // if there are more than 0 prior approvers which means there had been at least another approver than the current approver
1630             // then no need for separation of duties
1631             if (priorApprovers.size() > 0) {
1632                 return false;
1633             }
1634         } catch (WorkflowException we) {
1635             LOG.error("Exception while attempting to retrieve all prior approvers from workflow: " + we);
1636         }
1637         return false;
1638     }
1639 
1640     public boolean isBudgetReviewRequired() {
1641 
1642         OleInvoiceFundCheckServiceImpl oleInvoiceFundCheckServiceImpl = new OleInvoiceFundCheckServiceImpl();
1643         boolean required = false;
1644         if ((SpringContext.getBean(OleInvoiceService.class).getPaymentMethodType(this.getPaymentMethodIdentifier())).equals(OLEConstants.DEPOSIT)) {
1645             return false;
1646         }
1647         // if document's fiscal year is less than or equal to the current fiscal year
1648         if (SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear().compareTo(getPostingYear()) >= 0) {
1649             List<SourceAccountingLine> sourceAccountingLineList = this.getSourceAccountingLines();
1650             for (SourceAccountingLine accLine : sourceAccountingLineList) {
1651                 String chart = accLine.getAccount().getChartOfAccountsCode();
1652                 String account = accLine.getAccount().getAccountNumber();
1653                 String sfCode = accLine.getAccount().getAccountSufficientFundsCode();
1654                 Map<String, Object> key = new HashMap<String, Object>();
1655                 key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chart);
1656                 key.put(OLEPropertyConstants.ACCOUNT_NUMBER, account);
1657                 OleSufficientFundCheck oleSufficientFundCheck = businessObjectService.findByPrimaryKey(
1658                         OleSufficientFundCheck.class, key);
1659                /* List<GeneralLedgerPendingEntry> pendingEntries = getPendingLedgerEntriesForSufficientFundsChecking();
1660                 for (GeneralLedgerPendingEntry glpe : pendingEntries) {
1661                     glpe.getChartOfAccountsCode();
1662                 }*/
1663                 SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(this);
1664                 SpringContext.getBean(BusinessObjectService.class).save(getGeneralLedgerPendingEntries());
1665 
1666                 if (oleSufficientFundCheck != null) {
1667                     String option = oleSufficientFundCheck.getNotificationOption() != null ? oleSufficientFundCheck
1668                             .getNotificationOption() : "";
1669                     if (option.equals(OLEPropertyConstants.BUD_REVIEW)) {
1670                         /*List<GeneralLedgerPendingEntry> pendingEntries = getPendingLedgerEntriesForSufficientFundsChecking();
1671                         for (GeneralLedgerPendingEntry glpe : pendingEntries) {
1672                             glpe.getChartOfAccountsCode();
1673                         }
1674                         SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(this);
1675                         SpringContext.getBean(BusinessObjectService.class).save(getGeneralLedgerPendingEntries());*/
1676 
1677                         required = oleInvoiceFundCheckServiceImpl.hasSufficientFundCheckRequired(accLine);
1678                         SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());
1679 /*                        SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());*/
1680                         return required;
1681                     }
1682                 }
1683             }
1684         }
1685         SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());
1686         /*SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());*/
1687         return required;
1688         // get list of sufficientfundItems
1689 
1690         // delete and recreate the GL entries for this document so they do not get included in the SF check
1691         // This is *NOT* ideal. The SF service needs to be updated to allow it to provide the current
1692         // document number so that it can be exlcuded from pending entry checks.
1693         //   List<GeneralLedgerPendingEntry> pendingEntries = getPendingLedgerEntriesForSufficientFundsChecking();
1694         // dumb loop to just force OJB to load the objects. Otherwise, the proxy object above
1695         // only gets resolved *after* the delete below and no SF check happens.
1696         // for (GeneralLedgerPendingEntry glpe : pendingEntries) {
1697         // glpe.getChartOfAccountsCode();
1698         // }
1699         // SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());
1700         // List<SufficientFundsItem> fundsItems = SpringContext.getBean(SufficientFundsService.class)
1701         //.checkSufficientFundsForPREQ(pendingEntries);
1702 
1703         //if (fundsItems.size() > 0) {
1704         //return true;
1705         //}
1706 
1707 
1708         //return false;
1709     }
1710 
1711     private boolean isNotificationRequired() {
1712         OleInvoiceFundCheckServiceImpl oleInvoiceFundCheckServiceImpl = new OleInvoiceFundCheckServiceImpl();
1713         if ((SpringContext.getBean(OleInvoiceService.class).getPaymentMethodType(this.getPaymentMethodIdentifier())).equals(OLEConstants.DEPOSIT)) {
1714             return false;
1715         }
1716         List<SourceAccountingLine> sourceAccountingLineList = this.getSourceAccountingLines();
1717         boolean sufficientFundCheck = false;
1718         for (SourceAccountingLine accLine : sourceAccountingLineList) {
1719             Map searchMap = new HashMap();
1720             String notificationOption = null;
1721             Map<String, Object> key = new HashMap<String, Object>();
1722             String chartCode = accLine.getChartOfAccountsCode();
1723             String accNo = accLine.getAccountNumber();
1724             String objectCd = accLine.getFinancialObjectCode();
1725             key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
1726             key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
1727             OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(
1728                     OleSufficientFundCheck.class, key);
1729             if (account != null) {
1730                 notificationOption = account.getNotificationOption();
1731             }
1732             if (notificationOption != null && notificationOption.equals(OLEPropertyConstants.NOTIFICATION)) {
1733                 sufficientFundCheck = oleInvoiceFundCheckServiceImpl.hasSufficientFundCheckRequired(accLine);
1734                 return sufficientFundCheck;
1735             }
1736         }
1737         return sufficientFundCheck;
1738     }
1739 
1740     @Override
1741     protected void populateAccountsForRouting() {
1742 
1743         // if(this.getDocumentHeader().ge)
1744         List<SufficientFundsItem> fundsItems = new ArrayList<SufficientFundsItem>();
1745         try {
1746             // String nodeName =
1747             // SpringContext.getBean(WorkflowDocumentService.class).getCurrentRouteLevelName(getFinancialSystemDocumentHeader().getWorkflowDocument());
1748             String nodeName = getFinancialSystemDocumentHeader().getWorkflowDocument().getCurrentNodeNames().iterator()
1749                     .next();
1750             if (nodeName != null
1751                     && (nodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE) || nodeName
1752                     .equalsIgnoreCase(PurapWorkflowConstants.BUDGET_REVIEW_REQUIRED))) {
1753                 if (SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear()
1754                         .compareTo(getPostingYear()) >= 0) {
1755 
1756                     SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(
1757                             this);
1758                     SpringContext.getBean(BusinessObjectService.class).save(getGeneralLedgerPendingEntries());
1759 
1760                     List<GeneralLedgerPendingEntry> pendingEntries = getPendingLedgerEntriesForSufficientFundsChecking();
1761                     for (GeneralLedgerPendingEntry glpe : pendingEntries) {
1762                         glpe.getChartOfAccountsCode();
1763                     }
1764 
1765                     fundsItems = SpringContext.getBean(SufficientFundsService.class).checkSufficientFundsForInvoice(pendingEntries);
1766 
1767 /*
1768                     SpringContext.getBean(GeneralLedgerPendingEntryService.class).generateGeneralLedgerPendingEntries(
1769                             this);
1770                     SpringContext.getBean(BusinessObjectService.class).save(getGeneralLedgerPendingEntries());
1771 
1772                     fundsItems = SpringContext.getBean(SufficientFundsService.class).checkSufficientFundsForInvoice(
1773                             pendingEntries);
1774 */
1775 
1776                 }
1777                 SpringContext.getBean(PurapAccountingService.class).updateAccountAmounts(this);
1778                 if (accountsForRouting == null) {
1779                     accountsForRouting = (SpringContext.getBean(PurapAccountingService.class).generateSummary(getItems()));
1780                 }
1781                 String documentFiscalYearString = this.getPostingYear().toString();
1782                 List<String> fundsItemList = new ArrayList<String>();
1783                 for (SufficientFundsItem fundsItem : fundsItems) {
1784                     fundsItemList.add(fundsItem.getAccount().getChartOfAccountsCode());
1785                 }
1786                 if (accountsForRouting != null) {
1787                     for (Iterator accountsForRoutingIter = accountsForRouting.iterator(); accountsForRoutingIter.hasNext(); ) {
1788                         if (!(fundsItemList.contains(((SourceAccountingLine) accountsForRoutingIter.next())
1789                                 .getChartOfAccountsCode()))) {
1790                             accountsForRoutingIter.remove();
1791                         }
1792                     }
1793 
1794 /*                SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());*/
1795                     setAccountsForRouting(accountsForRouting);
1796                 }
1797                 // need to refresh to get the references for the searchable attributes (ie status) and for invoking route levels (ie
1798                 // account
1799                 // objects) -hjs
1800                 refreshNonUpdateableReferences();
1801                 for (SourceAccountingLine sourceLine : getAccountsForRouting()) {
1802                     sourceLine.refreshNonUpdateableReferences();
1803                 }
1804             } else {
1805                 super.populateAccountsForRouting();
1806             }
1807             SpringContext.getBean(GeneralLedgerPendingEntryService.class).delete(getDocumentNumber());
1808         } catch (Exception e) {
1809             logAndThrowRuntimeException("Error in populateAccountsForRouting while submitting document with id "
1810                     + getDocumentNumber(), e);
1811         }
1812 
1813     }
1814 
1815     /**
1816      * @see org.kuali.rice.krad.document.DocumentBase#doRouteLevelChange(org.kuali.rice.kew.framework.postprocessor.DocumentRouteLevelChange)
1817      */
1818     @Override
1819     public void doRouteLevelChange(DocumentRouteLevelChange levelChangeEvent) {
1820 
1821         super.doRouteLevelChange(levelChangeEvent);
1822         try {
1823             String newNodeName = levelChangeEvent.getNewNodeName();
1824             List<String> desiredActions = new ArrayList<String>(2);
1825             RoutingReportCriteria.Builder reportCriteria = RoutingReportCriteria.Builder
1826                     .createByDocumentIdAndTargetNodeName(getDocumentNumber(), newNodeName);
1827             desiredActions.add(ActionRequestType.APPROVE.getCode());
1828             desiredActions.add(ActionRequestType.FYI.getCode());
1829             desiredActions.add(ActionRequestType.COMPLETE.getCode());
1830             if (KewApiServiceLocator.getWorkflowDocumentActionsService().documentWillHaveAtLeastOneActionRequest(
1831                     reportCriteria.build(), desiredActions, false)) {
1832                 if (StringUtils.isNotBlank(newNodeName)) {
1833                     if (StringUtils.isNotBlank(newNodeName)) {
1834                         if (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE)
1835                                 || newNodeName.equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET)) {
1836                             String note = "";
1837                             if (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.BUDGET_NODE)) {
1838                                 note = OLEConstants.SufficientFundCheck.INV_NOTE;
1839                             }
1840                             if (newNodeName.equalsIgnoreCase(PurapWorkflowConstants.FYI_BUDGET)) {
1841                                 note = OLEConstants.SufficientFundCheck.FYI_NOTE;
1842                             }
1843                             DocumentService documentService = SpringContext.getBean(DocumentService.class);
1844                             Note apoNote = documentService.createNoteFromDocument(this, note);
1845                             this.addNote(apoNote);
1846                             documentService.saveDocumentNotes(this);
1847                         }
1848                     }
1849                 }
1850             }
1851         } catch (Exception e) {
1852             String errorMsg = "Workflow Error found checking actions requests on document with id "
1853                     + getDocumentNumber() + ". *** WILL NOT UPDATE PURAP STATUS ***";
1854             LOG.error(errorMsg, e);
1855         }
1856     }
1857 
1858     private OleInvoiceDocument invoiceDocumentObject;
1859 
1860     public OleInvoiceDocument getInvoiceDocumentObject() {
1861         return invoiceDocumentObject;
1862     }
1863 
1864     public void setInvoiceDocumentObject(OleInvoiceDocument invoiceDocumentObject) {
1865         this.invoiceDocumentObject = invoiceDocumentObject;
1866     }
1867 
1868 
1869     private String invoiceNumber;
1870     //private String paymentAttachmentIndicator;
1871     private String invoicePaymentClassification;
1872     private String invoiceVendorAmount;
1873     private String invoiceExtractDate;
1874     private String invoiceProcessedDate;
1875     private String invoiceType;
1876     private String invoiceSubType;
1877     private String invoiceBankCode;
1878     //private Date invoicePayDate;
1879     private String invoicePayDateCheck;
1880     private String vendorAmount;
1881     private String itemTotal;
1882     private String foreignItemTotal;
1883     private String grantTotal;
1884     private String foreignGrandTotal;
1885 
1886     private String invoicedForeignItemTotal;
1887     private String invoicedForeignGrandTotal;
1888 
1889     public String getInvoicePayDateCheck() {
1890         return invoicePayDateCheck;
1891     }
1892 
1893     public void setInvoicePayDateCheck(String invoicePayDateCheck) {
1894         this.invoicePayDateCheck = invoicePayDateCheck;
1895     }
1896 
1897 
1898     public String getInvoiceNumber() {
1899         return invoiceNumber;
1900     }
1901 
1902     public void setInvoiceNumber(String invoiceNumber) {
1903         this.invoiceNumber = invoiceNumber;
1904     }
1905 
1906 
1907     public String getInvoicePaymentClassification() {
1908         return invoicePaymentClassification;
1909     }
1910 
1911     public void setInvoicePaymentClassification(String invoicePaymentClassification) {
1912         this.invoicePaymentClassification = invoicePaymentClassification;
1913     }
1914 
1915     public String getInvoiceVendorAmount() {
1916         return invoiceVendorAmount;
1917     }
1918 
1919     public void setInvoiceVendorAmount(String invoiceVendorAmount) {
1920         this.invoiceVendorAmount = invoiceVendorAmount;
1921     }
1922 
1923     public String getInvoiceExtractDate() {
1924         return invoiceExtractDate;
1925     }
1926 
1927     public void setInvoiceExtractDate(String invoiceExtractDate) {
1928         this.invoiceExtractDate = invoiceExtractDate;
1929     }
1930 
1931     public String getInvoiceProcessedDate() {
1932         return invoiceProcessedDate;
1933     }
1934 
1935     public void setInvoiceProcessedDate(String invoiceProcessedDate) {
1936         this.invoiceProcessedDate = invoiceProcessedDate;
1937     }
1938 
1939     public String getInvoiceBankCode() {
1940         return invoiceBankCode;
1941     }
1942 
1943     public void setInvoiceBankCode(String invoiceBankCode) {
1944         this.invoiceBankCode = invoiceBankCode;
1945     }
1946 
1947 
1948     private String poId;
1949 
1950     public String getPoId() {
1951         return poId;
1952     }
1953 
1954     public void setPoId(String poId) {
1955         this.poId = poId;
1956     }
1957 
1958 
1959     public String getInvoiceCostSourceCode() {
1960         return invoiceCostSourceCode;
1961     }
1962 
1963     public void setInvoiceCostSourceCode(String invoiceCostSourceCode) {
1964         this.invoiceCostSourceCode = invoiceCostSourceCode;
1965     }
1966 
1967     public Integer getVendorHeaderGeneratedIdentifier() {
1968         return vendorHeaderGeneratedIdentifier;
1969     }
1970 
1971     public void setVendorHeaderGeneratedIdentifier(Integer vendorHeaderGeneratedIdentifier) {
1972         this.vendorHeaderGeneratedIdentifier = vendorHeaderGeneratedIdentifier;
1973     }
1974 
1975     public List<SummaryAccount> getSummaryAccounts() {
1976         if (summaryAccounts == null) {
1977             refreshAccountSummmary();
1978         }
1979         return summaryAccounts;
1980     }
1981 
1982     public void setSummaryAccounts(List<SummaryAccount> summaryAccounts) {
1983         this.summaryAccounts = summaryAccounts;
1984     }
1985 
1986     public void clearSummaryAccounts() {
1987         summaryAccounts = new ArrayList<SummaryAccount>();
1988     }
1989 
1990     /**
1991      * Updates the summaryAccounts that are contained in the form. Currently we are only calling this on load and when
1992      * refreshAccountSummary is called.
1993      */
1994     public void refreshAccountSummmary() {
1995         clearSummaryAccounts();
1996         summaryAccounts.addAll(SpringContext.getBean(PurapAccountingService.class).generateSummaryAccounts(this));
1997     }
1998 
1999     public boolean isSfcFlag() {
2000         return sfcFlag;
2001     }
2002 
2003     public void setSfcFlag(boolean sfcFlag) {
2004         this.sfcFlag = sfcFlag;
2005     }
2006 
2007     public String getInvoiceItemTotal() {
2008         // if (this.invoiceItemTotal == null || this.invoiceItemTotal.isEmpty() || this.invoiceItemTotal.equalsIgnoreCase("0.00")) {
2009         BigDecimal addChargeItem = BigDecimal.ZERO;
2010         List<OleInvoiceItem> item = this.getItems();
2011         for (OleInvoiceItem invoiceditem : item) {
2012             if (invoiceditem.getItemType().isAdditionalChargeIndicator() && invoiceditem.getExtendedPrice() != null) {
2013                 addChargeItem = addChargeItem.add(invoiceditem.getExtendedPrice().bigDecimalValue());
2014             }
2015         }
2016         return (this.getTotalDollarAmount().subtract(new KualiDecimal(addChargeItem)).toString());
2017 
2018         /* }
2019        return invoiceItemTotal;*/
2020     }
2021 
2022     public void setInvoiceItemTotal(String invoiceItemTotal) {
2023         this.invoiceItemTotal = invoiceItemTotal;
2024     }
2025 
2026     public String getInvoiceForeignItemTotal() {
2027         BigDecimal addChargeItem = BigDecimal.ZERO;
2028         List<OleInvoiceItem> item = this.getItems();
2029         for (OleInvoiceItem invoicedItem : item) {
2030             if (invoicedItem.getItemType().isAdditionalChargeIndicator() && invoicedItem.getItemUnitPrice() != null) {
2031                 addChargeItem = addChargeItem.add(invoicedItem.getItemUnitPrice());
2032             }
2033         }
2034         return (this.getTotalDollarAmount().subtract(new KualiDecimal(addChargeItem)).toString());
2035     }
2036 
2037     public void setInvoiceForeignItemTotal(String invoiceForeignItemTotal) {
2038         this.invoiceForeignItemTotal = invoiceForeignItemTotal;
2039     }
2040 
2041     public String getVendorAmount() {
2042         if (vendorAmount != null && !vendorAmount.isEmpty()) {
2043             return vendorAmount;
2044         } else {
2045             vendorAmount = this.getInvoiceAmount();
2046             if (vendorAmount != null && vendorAmount.contains("-")) {
2047                 vendorAmount = vendorAmount.replace("-", "");
2048                 vendorAmount = "(" + vendorAmount + ")";
2049             }
2050             return vendorAmount;
2051         }
2052     }
2053 
2054     public void setVendorAmount(String vendorAmount) {
2055         this.vendorAmount = vendorAmount;
2056         if (vendorAmount.contains("(") || vendorAmount.contains(")")) {
2057             vendorAmount = vendorAmount.replace("(", "");
2058             vendorAmount = vendorAmount.replace(")", "");
2059             vendorAmount = "-" + vendorAmount;
2060             this.vendorAmount = vendorAmount;
2061         }
2062         if (vendorAmount != null && new KualiDecimal(vendorAmount).isLessThan(KualiDecimal.ZERO)) {
2063             this.setInvoiceAmount(vendorAmount);
2064             vendorAmount = vendorAmount.replace("-", "");
2065             vendorAmount = "(" + vendorAmount + ")";
2066             this.vendorAmount = vendorAmount;
2067         } else {
2068             this.setInvoiceAmount(vendorAmount);
2069             this.vendorAmount = vendorAmount;
2070         }
2071     }
2072 
2073     public String getForeignVendorAmount() {
2074         if (foreignVendorAmount != null && !foreignVendorAmount.isEmpty()) {
2075             return foreignVendorAmount;
2076         } else {
2077             foreignVendorAmount = this.getForeignVendorInvoiceAmount() != null ? this.getForeignVendorInvoiceAmount().toString() : null;
2078             if (foreignVendorAmount != null && foreignVendorAmount.contains("-")) {
2079                 foreignVendorAmount = foreignVendorAmount.replace("-", "");
2080                 foreignVendorAmount = "(" + foreignVendorAmount + ")";
2081             }
2082             return foreignVendorAmount;
2083         }
2084     }
2085 
2086     public void setForeignVendorAmount(String foreignVendorAmount) {
2087         this.foreignVendorAmount = foreignVendorAmount;
2088         if (foreignVendorAmount.contains("(") || foreignVendorAmount.contains(")")) {
2089             foreignVendorAmount = foreignVendorAmount.replace("(", "");
2090             foreignVendorAmount = foreignVendorAmount.replace(")", "");
2091             foreignVendorAmount = "-" + foreignVendorAmount;
2092             this.foreignVendorAmount = foreignVendorAmount;
2093         }
2094         if (foreignVendorAmount != null && new KualiDecimal(foreignVendorAmount).isLessThan(KualiDecimal.ZERO)) {
2095             this.setForeignInvoiceAmount(foreignVendorAmount);
2096             foreignVendorAmount = foreignVendorAmount.replace("-", "");
2097             foreignVendorAmount = "(" + foreignVendorAmount + ")";
2098             this.foreignVendorAmount = foreignVendorAmount;
2099         } else {
2100             this.setForeignInvoiceAmount(foreignVendorAmount);
2101             this.foreignVendorAmount = foreignVendorAmount;
2102         }
2103     }
2104 
2105     public String getForeignInvoiceAmount() {
2106         return foreignInvoiceAmount;
2107     }
2108 
2109     public void setForeignInvoiceAmount(String foreignInvoiceAmount) {
2110         this.foreignInvoiceAmount = foreignInvoiceAmount;
2111     }
2112 
2113     public String getInvoiceAmount() {
2114         return invoiceAmount;
2115     }
2116 
2117     public void setInvoiceAmount(String invoiceAmount) {
2118         this.invoiceAmount = invoiceAmount;
2119     }
2120 
2121     public boolean isBaSfcFlag() {
2122         return baSfcFlag;
2123     }
2124 
2125     public void setBaSfcFlag(boolean baSfcFlag) {
2126         this.baSfcFlag = baSfcFlag;
2127     }
2128 
2129     /**
2130      * This method calculates the grand Total
2131      *
2132      * @param includeBelowTheLine
2133      * @param itemsForTotal
2134      * @return
2135      */
2136     protected KualiDecimal getInvoicedTotalWithAllItems(boolean includeBelowTheLine, List<OleInvoiceItem> itemsForTotal) {
2137 
2138         BigDecimal total = BigDecimal.ZERO;
2139         for (OleInvoiceItem item : itemsForTotal) {
2140             item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
2141             ItemType it = item.getItemType();
2142             if (includeBelowTheLine || it.isLineItemIndicator()) {
2143                 BigDecimal totalAmount = item.getTotalAmount().bigDecimalValue();
2144                 BigDecimal itemTotal = (totalAmount != null) ? totalAmount : BigDecimal.ZERO;
2145                 if (item.isDebitItem()) {
2146                     total = total.add(itemTotal);
2147                 } else {
2148                     total = total.subtract(itemTotal);
2149                 }
2150                 /*if (item.getItemDiscount() != null) {
2151                     total = total.subtract(item.getItemDiscount());
2152                 }*/
2153             }
2154         }
2155         return new KualiDecimal(total);
2156     }
2157 
2158     protected KualiDecimal getInvoicedForeignTotalWithAllItems(boolean includeBelowTheLine, List<OleInvoiceItem> itemsForTotal) {
2159 
2160         KualiDecimal total = new KualiDecimal(BigDecimal.ZERO);
2161         for (OleInvoiceItem item : itemsForTotal) {
2162             item.refreshReferenceObject(PurapPropertyConstants.ITEM_TYPE);
2163             ItemType it = item.getItemType();
2164             if (includeBelowTheLine || it.isLineItemIndicator()) {
2165                 KualiDecimal totalAmount = item.getForeignTotalAmount();
2166                 KualiDecimal itemTotal = (totalAmount != null) ? totalAmount : KualiDecimal.ZERO;
2167                 if (item.isDebitItem()) {
2168                     total = total.add(itemTotal);
2169                 } else {
2170                     total = total.subtract(itemTotal);
2171                 }
2172             }
2173         }
2174         return total;
2175     }
2176 
2177     public String getInvoicedItemTotal() {
2178         KualiDecimal total = getInvoicedTotalWithAllItems(false, this.getItems());
2179         if (this.isItemSign()) {
2180             if (total.isLessThan(KualiDecimal.ZERO)) {
2181                 total = total;
2182             }
2183         }
2184         return total != null ? total.toString() : "0";
2185     }
2186 
2187     public void setInvoicedItemTotal(String invoicedItemTotal) {
2188         this.invoicedItemTotal = invoicedItemTotal;
2189     }
2190 
2191     public String getInvoicedForeignItemTotal() {
2192         KualiDecimal foreignItemTotal = getInvoicedForeignTotalWithAllItems(false, this.getItems());
2193        /* if (this.isItemSign()) {
2194             if (foreignItemTotal.isLessThan(KualiDecimal.ZERO)) {
2195                 foreignItemTotal = foreignItemTotal;
2196             }
2197         } */
2198         return foreignItemTotal != null ? foreignItemTotal.toString() : "0";
2199     }
2200 
2201     public void setInvoicedForeignItemTotal(String invoicedForeignItemTotal) {
2202         this.invoicedForeignItemTotal = invoicedForeignItemTotal;
2203     }
2204 
2205     public String getItemTotal() {
2206         if(!this.isDbRetrieval()){
2207             itemTotal = this.getInvoicedItemTotal();
2208         }
2209         if (itemTotal != null && !itemTotal.contains("(")
2210                 && new KualiDecimal(itemTotal).isLessThan(KualiDecimal.ZERO)) {
2211             itemTotal = itemTotal.replace("-", "");
2212             itemTotal = "(" + itemTotal + ")";
2213         }
2214         return itemTotal;
2215     }
2216 
2217     public void setItemTotal(String itemTotal) {
2218         this.itemTotal = itemTotal;
2219     }
2220 
2221     public String getForeignItemTotal() {
2222         if(!this.isDbRetrieval()){
2223             foreignItemTotal = this.getInvoicedForeignItemTotal();
2224         }
2225         if (foreignItemTotal != null && !foreignItemTotal.contains("(")
2226                 && new KualiDecimal(foreignItemTotal).isLessThan(KualiDecimal.ZERO)) {
2227             foreignItemTotal = foreignItemTotal.replace("-", "");
2228             foreignItemTotal = "(" + foreignItemTotal + ")";
2229         }
2230         return foreignItemTotal;
2231     }
2232 
2233     public void setForeignItemTotal(String foreignItemTotal) {
2234         this.foreignItemTotal = foreignItemTotal;
2235     }
2236 
2237     public String getGrantTotal() {
2238         if(!this.isDbRetrieval()){
2239             grantTotal = this.getInvoicedGrandTotal();
2240         }
2241         if (grantTotal != null &&  !grantTotal.contains("(")
2242                 && new KualiDecimal(grantTotal).isLessThan(KualiDecimal.ZERO)) {
2243             grantTotal = grantTotal.replace("-", "");
2244             grantTotal = "(" + grantTotal + ")";
2245         }
2246         return grantTotal;
2247     }
2248 
2249     public void setGrantTotal(String grantTotal) {
2250         this.grantTotal = grantTotal;
2251     }
2252 
2253     public String getForeignGrandTotal() {
2254         if(!this.isDbRetrieval()){
2255             foreignGrandTotal = this.getInvoicedForeignGrandTotal();
2256         }
2257         if (foreignGrandTotal != null &&  !foreignGrandTotal.contains("(")
2258                 && new KualiDecimal(foreignGrandTotal).isLessThan(KualiDecimal.ZERO)) {
2259             foreignGrandTotal = foreignGrandTotal.replace("-", "");
2260             foreignGrandTotal = "(" + foreignGrandTotal + ")";
2261         }
2262         return foreignGrandTotal;
2263     }
2264 
2265     public void setForeignGrandTotal(String foreignGrandTotal) {
2266         this.foreignGrandTotal = foreignGrandTotal;
2267     }
2268 
2269     public String getInvoicedGrandTotal() {
2270         KualiDecimal total = getInvoicedTotalWithAllItems(true, this.getItems());
2271       /*  if (this.isItemSign()) {
2272             if (total.isLessThan(KualiDecimal.ZERO)) {
2273                 total = total;
2274             }
2275         } */
2276         return total != null ? total.toString() : "0";
2277     }
2278 
2279     public void setInvoicedGrandTotal(String invoicedGrandTotal) {
2280         this.invoicedGrandTotal = invoicedGrandTotal;
2281     }
2282 
2283     public String getInvoicedForeignGrandTotal() {
2284         KualiDecimal total = getInvoicedForeignTotalWithAllItems(true, this.getItems());
2285        /* if (this.isItemSign()) {
2286             if (total.isLessThan(KualiDecimal.ZERO)) {
2287                 total = total;
2288             }
2289         } */
2290         for (OleInvoiceItem item : (List<OleInvoiceItem>)this.getItems()) {
2291             if (!item.getItemType().getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)
2292                     && item.getAdditionalForeignUnitCost() != null) {
2293                 total = total.add(new KualiDecimal(item.getAdditionalForeignUnitCost()));
2294             }
2295             else if (!item.getItemType().getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)
2296                     && item.getItemForeignUnitCost() != null) {
2297                 total = total.add(item.getItemForeignUnitCost());
2298             }
2299         }
2300 
2301         return total != null ? total.toString() : "0";
2302     }
2303     public void setInvoicedForeignGrandTotal(String invoicedForeignGrandTotal) {
2304         this.invoicedForeignGrandTotal = invoicedForeignGrandTotal;
2305     }
2306 
2307     public boolean isValidationFlag() {
2308         return validationFlag;
2309     }
2310 
2311     public void setValidationFlag(boolean validationFlag) {
2312         this.validationFlag = validationFlag;
2313     }
2314 
2315     public boolean isBlanketApproveValidationFlag() {
2316         return blanketApproveValidationFlag;
2317     }
2318 
2319     public void setBlanketApproveValidationFlag(boolean blanketApproveValidationFlag) {
2320         this.blanketApproveValidationFlag = blanketApproveValidationFlag;
2321     }
2322 
2323     public String getPurchaseOrderDocumentNums() {
2324         return purchaseOrderDocumentNums;
2325     }
2326 
2327     public void setPurchaseOrderDocumentNums(String purchaseOrderDocumentNums) {
2328         this.purchaseOrderDocumentNums = purchaseOrderDocumentNums;
2329     }
2330 
2331     /*public boolean isInvoiceModified() {
2332         return invoiceModified;
2333     }
2334 
2335     public void setInvoiceModified(boolean invoiceModified) {
2336         this.invoiceModified = invoiceModified;
2337     }*/
2338 
2339     public boolean isOverviewFlag() {
2340         return overviewFlag;
2341     }
2342 
2343     public void setOverviewFlag(boolean overviewFlag) {
2344         this.overviewFlag = overviewFlag;
2345     }
2346 
2347     public boolean isVendorInfoFlag() {
2348         return vendorInfoFlag;
2349     }
2350 
2351     public void setVendorInfoFlag(boolean vendorInfoFlag) {
2352         this.vendorInfoFlag = vendorInfoFlag;
2353     }
2354 
2355     public boolean isInvoiceInfoFlag() {
2356         return invoiceInfoFlag;
2357     }
2358 
2359     public void setInvoiceInfoFlag(boolean invoiceInfoFlag) {
2360         this.invoiceInfoFlag = invoiceInfoFlag;
2361     }
2362 
2363     public boolean isProcessItemFlag() {
2364         return processItemFlag;
2365     }
2366 
2367     public void setProcessItemFlag(boolean processItemFlag) {
2368         this.processItemFlag = processItemFlag;
2369     }
2370 
2371     public boolean isProcessTitlesFlag() {
2372         return processTitlesFlag;
2373     }
2374 
2375     public void setProcessTitlesFlag(boolean processTitlesFlag) {
2376         this.processTitlesFlag = processTitlesFlag;
2377     }
2378 
2379     public boolean isCurrentItemsFlag() {
2380         return currentItemsFlag;
2381     }
2382 
2383     public void setCurrentItemsFlag(boolean currentItemsFlag) {
2384         this.currentItemsFlag = currentItemsFlag;
2385     }
2386 
2387     public boolean isAdditionalChargesFlag() {
2388         return additionalChargesFlag;
2389     }
2390 
2391     public void setAdditionalChargesFlag(boolean additionalChargesFlag) {
2392         this.additionalChargesFlag = additionalChargesFlag;
2393     }
2394 
2395     public boolean isAccountSummaryFlag() {
2396         return accountSummaryFlag;
2397     }
2398 
2399     public void setAccountSummaryFlag(boolean accountSummaryFlag) {
2400         this.accountSummaryFlag = accountSummaryFlag;
2401     }
2402 
2403     public boolean isNotesAndAttachmentFlag() {
2404         return notesAndAttachmentFlag;
2405     }
2406 
2407     public void setNotesAndAttachmentFlag(boolean notesAndAttachmentFlag) {
2408         this.notesAndAttachmentFlag = notesAndAttachmentFlag;
2409     }
2410 
2411     public boolean isAdHocRecipientsFlag() {
2412         return adHocRecipientsFlag;
2413     }
2414 
2415     public void setAdHocRecipientsFlag(boolean adHocRecipientsFlag) {
2416         this.adHocRecipientsFlag = adHocRecipientsFlag;
2417     }
2418 
2419     public boolean isRouteLogFlag() {
2420         return routeLogFlag;
2421     }
2422 
2423     public void setRouteLogFlag(boolean routeLogFlag) {
2424         this.routeLogFlag = routeLogFlag;
2425     }
2426 
2427     public boolean isRouteLogDisplayFlag() {
2428         return routeLogDisplayFlag;
2429     }
2430 
2431     public void setRouteLogDisplayFlag(boolean routeLogDisplayFlag) {
2432         this.routeLogDisplayFlag = routeLogDisplayFlag;
2433     }
2434 
2435 
2436     /**
2437      * Performs logic needed to copy Invoice Document.
2438      */
2439     @Override
2440     public void toCopy() throws WorkflowException, ValidationException {
2441         super.toCopy();
2442         String[] collapseSections = getOleInvoiceService().getDefaultCollapseSections();
2443         this.setOverviewFlag(getOleInvoiceService().canCollapse(OLEConstants.OVERVIEW_SECTION, collapseSections));
2444         this.setVendorInfoFlag(getOleInvoiceService().canCollapse(OLEConstants.VENDOR_INFO_SECTION, collapseSections));
2445         this.setInvoiceInfoFlag(getOleInvoiceService().canCollapse(OLEConstants.INVOICE_INFO_SECTION, collapseSections));
2446         this.setProcessTitlesFlag(getOleInvoiceService().canCollapse(OLEConstants.PROCESS_TITLES_SECTION, collapseSections));
2447         this.setCurrentItemsFlag(getOleInvoiceService().canCollapse(OLEConstants.CURRENT_ITEM_SECTION, collapseSections));
2448         this.setAdditionalChargesFlag(getOleInvoiceService().canCollapse(OLEConstants.ADDITIONAL_CHARGES_SECTION, collapseSections));
2449         this.setAccountSummaryFlag(getOleInvoiceService().canCollapse(OLEConstants.ACCOUNT_SUMMARY_SECTION, collapseSections));
2450         this.setAdHocRecipientsFlag(getOleInvoiceService().canCollapse(OLEConstants.ADHOC_RECIPIENT_SECTION, collapseSections));
2451         this.setRouteLogFlag(getOleInvoiceService().canCollapse(OLEConstants.ROUTE_LOG_SECTION, collapseSections));
2452         this.setNotesAndAttachmentFlag(getOleInvoiceService().canCollapse(OLEConstants.NOTES_AND_ATTACH_SECTION, collapseSections));
2453         // Clear related views
2454         this.setAccountsPayablePurchasingDocumentLinkIdentifier(null);
2455         this.setRelatedViews(null);
2456         this.setInvoiceNumber("");
2457         this.setNoteLine1Text("");
2458 
2459         Person currentUser = GlobalVariables.getUserSession().getPerson();
2460         this.setPurapDocumentIdentifier(null);
2461 
2462         // Set req status to INPR.
2463         //for app doc status
2464         updateAndSaveAppDocStatus(InvoiceStatuses.APPDOC_INITIATE);
2465         this.setPostingYear(SpringContext.getBean(UniversityDateService.class).getCurrentFiscalYear());
2466 
2467         for (Iterator iter = this.getItems().iterator(); iter.hasNext(); ) {
2468             OleInvoiceItem item = (OleInvoiceItem) iter.next();
2469             item.setPurapDocumentIdentifier(null);
2470             item.setItemIdentifier(null);
2471             if (this.getCloneDebitInvoice().equalsIgnoreCase("true")) {
2472                 item.setDebitItem(true);
2473                 item.setInvoiceListPrice(item.getItemListPrice().abs().toString());
2474             } else {
2475                 item.setDebitItem(false);
2476                 item.setInvoiceListPrice(item.getItemListPrice().negated().toString());
2477             }
2478             for (Iterator acctIter = item.getSourceAccountingLines().iterator(); acctIter.hasNext(); ) {
2479                 InvoiceAccount account = (InvoiceAccount) acctIter.next();
2480                 account.setAccountIdentifier(null);
2481                 account.setItemIdentifier(null);
2482                 account.setObjectId(null);
2483                 account.setVersionNumber(null);
2484             }
2485             item.setPaidCopies(new ArrayList<OLEPaidCopy>());
2486         }
2487         SpringContext.getBean(PurapService.class).addBelowLineItems(this);
2488         this.refreshNonUpdateableReferences();
2489     }
2490 
2491     /**
2492      * Checks whether copying of this document should be allowed. Copying is not allowed if this is a B2B requistion, and more than
2493      * a set number of days have passed since the document's creation.
2494      *
2495      * @return True if copying of this requisition is allowed.
2496      */
2497     @Override
2498     public boolean getAllowsCopy() {
2499         //boolean allowsCopy = super.getAllowsCopy();
2500         boolean allowsCopy = true;
2501         return allowsCopy;
2502     }
2503 
2504     /**
2505      * This method returns the duplicateFlag indicator
2506      *
2507      * @return duplicateFlag
2508      */
2509     public boolean isDuplicateFlag() {
2510         return duplicateFlag;
2511     }
2512 
2513     /**
2514      * This method sets the duplicateFlag
2515      *
2516      * @param duplicateFlag
2517      */
2518     public void setDuplicateFlag(boolean duplicateFlag) {
2519         this.duplicateFlag = duplicateFlag;
2520     }
2521 
2522     public String getSearchResultInvoiceDate() {
2523         return searchResultInvoiceDate;
2524     }
2525 
2526     public void setSearchResultInvoiceDate(String searchResultInvoiceDate) {
2527         this.searchResultInvoiceDate = searchResultInvoiceDate;
2528     }
2529 
2530     public String getSearchResultInvoicePayDate() {
2531         return searchResultInvoicePayDate;
2532     }
2533 
2534     public void setSearchResultInvoicePayDate(String searchResultInvoicePayDate) {
2535         this.searchResultInvoicePayDate = searchResultInvoicePayDate;
2536     }
2537 
2538     public boolean isDuplicateApproveFlag() {
2539         return duplicateApproveFlag;
2540     }
2541 
2542     public void setDuplicateApproveFlag(boolean duplicateApproveFlag) {
2543         this.duplicateApproveFlag = duplicateApproveFlag;
2544     }
2545 
2546     public String getCloneDebitInvoice() {
2547         return cloneDebitInvoice;
2548     }
2549 
2550     public void setCloneDebitInvoice(String cloneDebitInvoice) {
2551         this.cloneDebitInvoice = cloneDebitInvoice;
2552     }
2553 
2554     public boolean isCloneFlag() {
2555         return cloneFlag;
2556     }
2557 
2558     public void setCloneFlag(boolean cloneFlag) {
2559         this.cloneFlag = cloneFlag;
2560     }
2561 
2562     public List<OlePaymentRequestDocument> getPaymentRequestDocuments() {
2563         return paymentRequestDocuments;
2564     }
2565 
2566     public void setPaymentRequestDocuments(List<OlePaymentRequestDocument> paymentRequestDocuments) {
2567         this.paymentRequestDocuments = paymentRequestDocuments;
2568     }
2569 
2570     public boolean isOffsetAccountIndicator() {
2571         return offsetAccountIndicator;
2572     }
2573 
2574     public void setOffsetAccountIndicator(boolean offsetAccountIndicator) {
2575         this.offsetAccountIndicator = offsetAccountIndicator;
2576     }
2577 
2578     public boolean isItemSign() {
2579         return itemSign;
2580     }
2581 
2582     public void setItemSign(boolean itemSign) {
2583         this.itemSign = itemSign;
2584     }
2585 
2586     public boolean isBlanketApproveSubscriptionDateValidationFlag() {
2587         return blanketApproveSubscriptionDateValidationFlag;
2588     }
2589 
2590     public void setBlanketApproveSubscriptionDateValidationFlag(boolean blanketApproveSubscriptionDateValidationFlag) {
2591         this.blanketApproveSubscriptionDateValidationFlag = blanketApproveSubscriptionDateValidationFlag;
2592     }
2593 
2594     public boolean isSubscriptionDateValidationFlag() {
2595         return subscriptionDateValidationFlag;
2596     }
2597 
2598     public void setSubscriptionDateValidationFlag(boolean subscriptionDateValidationFlag) {
2599         this.subscriptionDateValidationFlag = subscriptionDateValidationFlag;
2600     }
2601 
2602     public String getVendorLink() {
2603         String oleurl = ConfigContext.getCurrentContextConfig().getProperty("ole.url");
2604         String url = oleurl+ OLEConstants.VENDOR_LINK +vendorHeaderGeneratedIdentifier + "&amp;vendorDetailAssignedIdentifier="
2605                 +vendorDetailAssignedIdentifier;
2606         return url;
2607     }
2608 
2609     public void setVendorLink(String vendorLink) {
2610         this.vendorLink = vendorLink;
2611     }
2612 
2613     public boolean isForeignCurrencyFlag() {
2614         return foreignCurrencyFlag;
2615     }
2616 
2617     public void setForeignCurrencyFlag(boolean foreignCurrencyFlag) {
2618         this.foreignCurrencyFlag = foreignCurrencyFlag;
2619     }
2620 
2621     public Long getInvoiceCurrencyTypeId() {
2622         return invoiceCurrencyTypeId;
2623     }
2624 
2625     public void setInvoiceCurrencyTypeId(Long invoiceCurrencyTypeId) {
2626         this.invoiceCurrencyTypeId = invoiceCurrencyTypeId;
2627     }
2628 
2629     public String getInvoiceCurrencyType() {
2630         return invoiceCurrencyType;
2631     }
2632 
2633     public void setInvoiceCurrencyType(String invoiceCurrencyType) {
2634         this.invoiceCurrencyType = invoiceCurrencyType;
2635     }
2636 
2637     public OleCurrencyType getOleCurrencyType() {
2638         return oleCurrencyType;
2639     }
2640 
2641     public void setOleCurrencyType(OleCurrencyType oleCurrencyType) {
2642         this.oleCurrencyType = oleCurrencyType;
2643     }
2644 
2645     public boolean isCurrencyOverrideFlag() {
2646         return currencyOverrideFlag;
2647     }
2648 
2649     public void setCurrencyOverrideFlag(boolean currencyOverrideFlag) {
2650         this.currencyOverrideFlag = currencyOverrideFlag;
2651     }
2652 
2653     public String getCurrencyOverrideMessage() {
2654         return currencyOverrideMessage;
2655     }
2656 
2657     public void setCurrencyOverrideMessage(String currencyOverrideMessage) {
2658         this.currencyOverrideMessage = currencyOverrideMessage;
2659     }
2660 
2661     public String getInvoiceCurrencyExchangeRate() {
2662         if (invoiceCurrencyExchangeRate != null && !invoiceCurrencyExchangeRate.isEmpty()) {
2663             if (invoiceCurrencyExchangeRate != null && invoiceCurrencyExchangeRate.contains("-")) {
2664                 invoiceCurrencyExchangeRate = invoiceCurrencyExchangeRate.replace("-", "");
2665                 invoiceCurrencyExchangeRate = "(" + invoiceCurrencyExchangeRate + ")";
2666             }
2667             return invoiceCurrencyExchangeRate;
2668         }
2669         return invoiceCurrencyExchangeRate;
2670     }
2671 
2672     public void setInvoiceCurrencyExchangeRate(String invoiceCurrencyExchangeRate) {
2673         this.invoiceCurrencyExchangeRate = invoiceCurrencyExchangeRate;
2674         if (invoiceCurrencyExchangeRate != null) {
2675             if (invoiceCurrencyExchangeRate.contains("(") || invoiceCurrencyExchangeRate.contains(")")) {
2676                 invoiceCurrencyExchangeRate = invoiceCurrencyExchangeRate.replace("(", "");
2677                 invoiceCurrencyExchangeRate = invoiceCurrencyExchangeRate.replace(")", "");
2678                 invoiceCurrencyExchangeRate = "-" + invoiceCurrencyExchangeRate;
2679                 this.invoiceCurrencyExchangeRate = invoiceCurrencyExchangeRate;
2680             }
2681             if (new KualiDecimal(invoiceCurrencyExchangeRate).isLessThan(KualiDecimal.ZERO)) {
2682                 invoiceCurrencyExchangeRate = invoiceCurrencyExchangeRate.replace("-", "");
2683                 invoiceCurrencyExchangeRate = "(" + invoiceCurrencyExchangeRate + ")";
2684                 this.invoiceCurrencyExchangeRate = invoiceCurrencyExchangeRate;
2685             }
2686         }
2687     }
2688 
2689     public boolean isDbRetrieval() {
2690         return dbRetrieval;
2691     }
2692 
2693     public void setDbRetrieval(boolean dbRetrieval) {
2694         this.dbRetrieval = dbRetrieval;
2695     }
2696 
2697     public boolean isEnableCurrentItems() {
2698         return enableCurrentItems;
2699     }
2700 
2701     public void setEnableCurrentItems(boolean enableCurrentItems) {
2702         this.enableCurrentItems = enableCurrentItems;
2703     }
2704 
2705     public List<OleInvoiceItem> getDeletedInvoiceItems() {
2706         return deletedInvoiceItems;
2707     }
2708 
2709     public void setDeletedInvoiceItems(List<OleInvoiceItem> deletedInvoiceItems) {
2710         this.deletedInvoiceItems = deletedInvoiceItems;
2711     }
2712 
2713     public boolean isDuplicateRouteFlag() {
2714         return duplicateRouteFlag;
2715     }
2716 
2717     public void setDuplicateRouteFlag(boolean duplicateRouteFlag) {
2718         this.duplicateRouteFlag = duplicateRouteFlag;
2719     }
2720 
2721     public boolean isDuplicateSaveFlag() {
2722         return duplicateSaveFlag;
2723     }
2724 
2725     public void setDuplicateSaveFlag(boolean duplicateSaveFlag) {
2726         this.duplicateSaveFlag = duplicateSaveFlag;
2727     }
2728 
2729     public String getVendorAlias() {
2730         return vendorAlias;
2731     }
2732 
2733     public void setVendorAlias(String vendorAlias) {
2734         this.vendorAlias = vendorAlias;
2735     }
2736 
2737     public boolean isDuplicateValidationFlag() {
2738         return duplicateValidationFlag;
2739     }
2740 
2741     public void setDuplicateValidationFlag(boolean duplicateValidationFlag) {
2742         this.duplicateValidationFlag = duplicateValidationFlag;
2743     }
2744 
2745     public String getInvoiceInfo() {
2746         if(StringUtils.isNotEmpty(invoiceNumber)){
2747             invoiceInfo = "";
2748             invoiceInfo = "Invoice (" + invoiceNumber + ")";
2749         }else{
2750             invoiceInfo = "Invoice";
2751         }
2752         return invoiceInfo;
2753     }
2754 
2755     public void setInvoiceInfo(String invoiceInfo) {
2756         this.invoiceInfo = invoiceInfo;
2757     }
2758 }
2759