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