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