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