View Javadoc
1   /*
2    * Copyright 2011 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.purap.document.service.impl;
17  
18  import org.apache.commons.lang.StringEscapeUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.apache.commons.lang.time.DateUtils;
21  import org.kuali.ole.DocumentUniqueIDPrefix;
22  import org.kuali.ole.docstore.common.document.Bib;
23  import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
24  import org.kuali.ole.docstore.common.document.content.bib.marc.DataField;
25  import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.BibInfoRecord;
26  import org.kuali.ole.module.purap.businessobject.PurApItem;
27  import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
28  import org.kuali.ole.module.purap.document.*;
29  import org.kuali.ole.module.purap.document.service.OlePurapService;
30  import org.kuali.ole.select.OleSelectConstant;
31  import org.kuali.ole.select.businessobject.*;
32  import org.kuali.ole.select.document.OleInvoiceDocument;
33  import org.kuali.ole.select.document.OlePaymentRequestDocument;
34  import org.kuali.ole.select.document.OlePurchaseOrderDocument;
35  import org.kuali.ole.select.document.OleRequisitionDocument;
36  import org.kuali.ole.select.document.OleVendorCreditMemoDocument;
37  import org.kuali.ole.sys.OLEConstants;
38  import org.kuali.ole.sys.context.SpringContext;
39  import org.kuali.ole.vnd.businessobject.VendorDetail;
40  import org.kuali.rice.core.api.datetime.DateTimeService;
41  import org.kuali.rice.core.api.util.type.KualiDecimal;
42  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
43  import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
44  import org.kuali.rice.kim.api.identity.Person;
45  import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
46  import org.kuali.rice.krad.service.BusinessObjectService;
47  import org.kuali.rice.krad.service.DocumentHeaderService;
48  import org.kuali.rice.krad.service.KRADServiceLocator;
49  import org.kuali.rice.krad.util.GlobalVariables;
50  
51  import java.math.BigDecimal;
52  import java.util.*;
53  
54  public class OlePurapServiceImpl implements OlePurapService {
55  
56      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePurapServiceImpl.class);
57      protected ParameterService parameterService;
58      private static transient BusinessObjectService businessObjectService;
59      private DateTimeService dateTimeService;
60      private static final String timeStampFormat = "MMddyyHHmm";
61  
62      public BusinessObjectService getBusinessObjectService() {
63          if (businessObjectService == null) {
64              businessObjectService = SpringContext.getBean(BusinessObjectService.class);
65          }
66          return businessObjectService;
67      }
68  
69      public DateTimeService getDateTimeService() {
70          if (dateTimeService == null) {
71              dateTimeService = SpringContext.getBean(DateTimeService.class);
72          }
73          return dateTimeService;
74      }
75  
76      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
77          this.businessObjectService = businessObjectService;
78      }
79  
80      public void setParameterService(ParameterService parameterService) {
81          this.parameterService = parameterService;
82      }
83      @Override
84      public BigDecimal calculateDiscount(OleRequisitionItem oleRequisition) {
85  
86          if (oleRequisition.getItemListPrice() != null && oleRequisition.getItemDiscountType() != null) {
87  
88              if (oleRequisition.getItemDiscount() == null) {
89                  oleRequisition.setItemDiscount(new KualiDecimal(0));
90              }
91              if (oleRequisition.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
92                  LOG.debug("###### Percentage ##### ");
93                  return oleRequisition.getItemListPrice().bigDecimalValue().subtract((oleRequisition.getItemDiscount().bigDecimalValue().multiply(new BigDecimal(0.01))).multiply(oleRequisition.getItemListPrice().bigDecimalValue()));
94              } else {
95                  LOG.debug("###### Dollor ##### ");
96                  if (LOG.isDebugEnabled()) {
97                      LOG.debug("oleRequisition.getItemDiscountType()**********" + oleRequisition.getItemDiscountType());
98                  }
99                  return oleRequisition.getItemListPrice().bigDecimalValue().subtract(oleRequisition.getItemDiscount().bigDecimalValue());
100             }
101         } else {
102             oleRequisition.setItemListPrice(new KualiDecimal(0.0));
103             return new BigDecimal(0.0);
104         }
105 
106     }
107 
108     @Override
109     public BigDecimal calculateDiscount(OlePurchaseOrderItem olePurchaseOrder) {
110 
111         if (olePurchaseOrder.getItemListPrice() != null && olePurchaseOrder.getItemDiscountType() != null) {
112             if (olePurchaseOrder.getItemDiscount() == null) {
113                 olePurchaseOrder.setItemDiscount(new KualiDecimal(0));
114             }
115             if (olePurchaseOrder.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
116                 return olePurchaseOrder.getItemListPrice().bigDecimalValue().subtract((olePurchaseOrder.getItemDiscount().bigDecimalValue().multiply(new BigDecimal(0.01))).multiply(olePurchaseOrder.getItemListPrice().bigDecimalValue()));
117             } else {
118                 return olePurchaseOrder.getItemListPrice().bigDecimalValue().subtract(olePurchaseOrder.getItemDiscount().bigDecimalValue());
119             }
120         } else {
121             olePurchaseOrder.setItemListPrice(new KualiDecimal(0.0));
122             return new BigDecimal(0.0);
123         }
124 
125     }
126 
127 
128 // Foreign Currency Conversion
129 
130     @Override
131     public OleRequisitionItem calculateForeignCurrency(OleRequisitionItem oleRequisition) {
132         if (oleRequisition.getItemForeignListPrice() != null && oleRequisition.getItemForeignDiscountType() != null) {
133             if (oleRequisition.getItemForeignDiscount() == null) {
134                 oleRequisition.setItemForeignDiscount(new KualiDecimal(0));
135             }
136             if (oleRequisition.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
137                 BigDecimal calculatedForeignDiscountAmt = oleRequisition.getItemForeignDiscount().bigDecimalValue().multiply(new BigDecimal(0.01)).multiply(oleRequisition.getItemForeignListPrice().bigDecimalValue());
138                 oleRequisition.setItemForeignDiscountAmt(new KualiDecimal(calculatedForeignDiscountAmt.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
139                 oleRequisition.setItemForeignUnitCost(oleRequisition.getItemForeignListPrice().subtract(oleRequisition.getItemForeignDiscountAmt()));
140                 return oleRequisition;
141             } else {
142                 oleRequisition.setItemForeignDiscountAmt((oleRequisition.getItemForeignDiscount()));
143                 oleRequisition.setItemForeignUnitCost(new KualiDecimal(oleRequisition.getItemForeignListPrice().bigDecimalValue().subtract(oleRequisition.getItemForeignDiscount().bigDecimalValue())));
144                 return oleRequisition;
145             }
146         } else {
147             return oleRequisition;
148         }
149     }
150 
151     @Override
152     public OlePurchaseOrderItem calculateForeignCurrency(OlePurchaseOrderItem olePurchaseOrder) {
153         if (olePurchaseOrder.getItemForeignListPrice() != null && olePurchaseOrder.getItemForeignDiscountType() != null) {
154             if (olePurchaseOrder.getItemForeignDiscount() == null) {
155                 olePurchaseOrder.setItemForeignDiscount(new KualiDecimal(0));
156             }
157             if (olePurchaseOrder.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
158                 BigDecimal calculatedForeignDiscountAmt = olePurchaseOrder.getItemForeignDiscount().bigDecimalValue().multiply(new BigDecimal(0.01)).multiply(olePurchaseOrder.getItemForeignListPrice().bigDecimalValue());
159                 olePurchaseOrder.setItemForeignDiscountAmt(new KualiDecimal(calculatedForeignDiscountAmt.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
160                 olePurchaseOrder.setItemForeignUnitCost(olePurchaseOrder.getItemForeignListPrice().subtract(olePurchaseOrder.getItemForeignDiscountAmt()));
161                 return olePurchaseOrder;
162             } else {
163                 olePurchaseOrder.setItemForeignDiscountAmt(olePurchaseOrder.getItemForeignDiscount());
164                 olePurchaseOrder.setItemForeignUnitCost(olePurchaseOrder.getItemForeignListPrice().subtract(olePurchaseOrder.getItemForeignDiscount()));
165                 return olePurchaseOrder;
166             }
167         } else {
168             return olePurchaseOrder;
169         }
170     }
171 
172     @Override
173     public BigDecimal calculateDiscount(OlePaymentRequestItem olePaymentRequestOrder) {
174 
175         if (olePaymentRequestOrder.getItemListPrice() != null) {
176             if (olePaymentRequestOrder.getItemDiscount() == null) {
177                 olePaymentRequestOrder.setItemDiscount(new KualiDecimal(0));
178             }
179             if (olePaymentRequestOrder.getItemDiscountType() != null && olePaymentRequestOrder.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
180                 return olePaymentRequestOrder.getItemListPrice().bigDecimalValue().subtract((olePaymentRequestOrder.getItemDiscount().bigDecimalValue().multiply(new BigDecimal(0.01))).multiply(olePaymentRequestOrder.getItemListPrice().bigDecimalValue()));
181             } else {
182                 return olePaymentRequestOrder.getItemListPrice().bigDecimalValue().subtract(olePaymentRequestOrder.getItemDiscount().bigDecimalValue());
183             }
184         } else {
185             olePaymentRequestOrder.setItemListPrice(new KualiDecimal(0.0));
186             return new BigDecimal(0.0);
187         }
188 
189     }
190 
191     @Override
192     public BigDecimal calculateDiscount(OleInvoiceItem oleInvoiceOrder) {
193 
194         if (oleInvoiceOrder.getItemListPrice() != null) {
195             if (oleInvoiceOrder.getItemDiscount() == null) {
196                 oleInvoiceOrder.setItemDiscount(new KualiDecimal(0));
197             }
198             if (oleInvoiceOrder.getItemDiscountType() != null && oleInvoiceOrder.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
199                 return oleInvoiceOrder.getItemListPrice().bigDecimalValue().subtract((oleInvoiceOrder.getItemDiscount().bigDecimalValue().multiply(new BigDecimal(0.01))).multiply(oleInvoiceOrder.getItemListPrice().bigDecimalValue()));
200             } else {
201                 return oleInvoiceOrder.getItemListPrice().bigDecimalValue().subtract(oleInvoiceOrder.getItemDiscount().bigDecimalValue());
202             }
203         } else {
204             oleInvoiceOrder.setItemListPrice(new KualiDecimal(0.0));
205             return new BigDecimal(0.0);
206         }
207 
208     }
209 
210     @Override
211     public OlePaymentRequestItem calculateForeignCurrency(OlePaymentRequestItem item) {
212         if (item.getItemForeignListPrice() != null) {
213             if (item.getItemForeignDiscount() == null) {
214                 item.setItemForeignDiscount(new KualiDecimal(0));
215             }
216             if (item.getItemForeignDiscountType() != null && item.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
217                 BigDecimal calculatedForeignDiscountAmt = item.getItemForeignDiscount().bigDecimalValue().multiply(new BigDecimal(0.01)).multiply(item.getItemForeignListPrice().bigDecimalValue());
218                 item.setItemForeignDiscountAmt(new KualiDecimal(calculatedForeignDiscountAmt.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
219                 item.setItemForeignUnitCost(item.getItemForeignListPrice().subtract(item.getItemForeignDiscountAmt()));
220                 return item;
221             } else {
222                 item.setItemForeignDiscountAmt(item.getItemForeignDiscount());
223                 item.setItemForeignUnitCost(item.getItemForeignListPrice().subtract(item.getItemForeignDiscount()));
224                 return item;
225             }
226         } else {
227             return item;
228         }
229     }
230 
231 
232     @Override
233     public OleInvoiceItem calculateForeignCurrency(OleInvoiceItem item) {
234         if (item.getItemForeignListPrice() != null) {
235             if (item.getItemForeignDiscount() == null) {
236                 item.setItemForeignDiscount(new KualiDecimal(0));
237             }
238             if (item.getItemForeignDiscountType() != null && item.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
239                 BigDecimal calculatedForeignDiscountAmt = item.getItemForeignDiscount().bigDecimalValue().multiply(new BigDecimal(0.01)).multiply(item.getItemForeignListPrice().bigDecimalValue());
240                 item.setItemForeignDiscountAmt(new KualiDecimal(calculatedForeignDiscountAmt.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
241                 item.setItemForeignUnitCost(item.getItemForeignListPrice().subtract(item.getItemForeignDiscountAmt()));
242                 return item;
243             } else {
244                 item.setItemForeignDiscountAmt(item.getItemForeignDiscount());
245                 item.setItemForeignUnitCost(item.getItemForeignListPrice().subtract(item.getItemForeignDiscount()));
246                 return item;
247             }
248         } else {
249             return item;
250         }
251     }
252 
253 
254     /**
255      * Returns first, middle and last initials of logged in user
256      * to be appended in the document description
257      *
258      * @return initials of logged in user
259      */
260     public String getOperatorInitials() {
261         LOG.debug("Inside getOperatorInitials()");
262         StringBuffer operatorInitials = new StringBuffer();
263         Person person = GlobalVariables.getUserSession().getPerson();
264         operatorInitials.append(StringUtils.isEmpty(person.getFirstName()) ? "" : person.getFirstName().toLowerCase().charAt(0));
265         operatorInitials.append(StringUtils.isEmpty(person.getMiddleName()) ? "" : person.getMiddleName().toLowerCase().charAt(0));
266         operatorInitials.append(StringUtils.isEmpty(person.getLastName()) ? "" : person.getLastName().toLowerCase().charAt(0));
267         LOG.debug("End of getOperatorInitials()");
268         return operatorInitials.toString();
269     }
270 
271     public OleCreditMemoItem calculateForeignCurrency(OleCreditMemoItem oleCreditMemoItem) {
272         if (oleCreditMemoItem.getItemForeignListPrice() != null && oleCreditMemoItem.getItemForeignDiscountType() != null) {
273             if (oleCreditMemoItem.getItemForeignDiscount() == null) {
274                 oleCreditMemoItem.setItemForeignDiscount(new KualiDecimal(0));
275             }
276             if (oleCreditMemoItem.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
277                 BigDecimal calculatedForeignDiscountAmt = oleCreditMemoItem.getItemForeignDiscount().bigDecimalValue().multiply(new BigDecimal(0.01)).multiply(oleCreditMemoItem.getItemForeignListPrice().bigDecimalValue());
278                 oleCreditMemoItem.setItemForeignDiscountAmt(new KualiDecimal(calculatedForeignDiscountAmt.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
279                 oleCreditMemoItem.setItemForeignUnitCost(oleCreditMemoItem.getItemForeignListPrice().subtract(oleCreditMemoItem.getItemForeignDiscountAmt()));
280                 return oleCreditMemoItem;
281             } else {
282                 oleCreditMemoItem.setItemForeignDiscountAmt(oleCreditMemoItem.getItemForeignDiscount());
283                 oleCreditMemoItem.setItemForeignUnitCost(oleCreditMemoItem.getItemForeignListPrice().subtract(oleCreditMemoItem.getItemForeignDiscount()));
284                 return oleCreditMemoItem;
285             }
286         } else {
287             return oleCreditMemoItem;
288         }
289     }
290 
291     /**
292      * This method returns the section Name that are to be collapsed while opening the document
293      * @param document
294      * @return collapseSections
295      */
296     public void getInitialCollapseSections(PurchasingAccountsPayableDocument document) {
297         LOG.debug("Inside getInitialCollapseSections()");
298         String[] collapseSections = new String[]{};
299         try {
300             if (document instanceof RequisitionDocument) {
301                 OleRequisitionDocument requisitionDocument = (OleRequisitionDocument)document;
302                 collapseSections = parameterService.getParameterValuesAsString(RequisitionDocument.class,
303                         OLEConstants.INITIAL_COLLAPSE_SECTIONS).toArray(new String[]{});
304                 requisitionDocument.setOverviewFlag(canCollapse(OLEConstants.OVERVIEW_SECTION, collapseSections));
305                 requisitionDocument.setDeliveryFlag(canCollapse(OLEConstants.DELIVERY_SECTION, collapseSections));
306                 requisitionDocument.setVendorFlag(canCollapse(OLEConstants.VENDOR_SECTION, collapseSections));
307                 requisitionDocument.setTitlesFlag(canCollapse(OLEConstants.TITLES_SECTION, collapseSections));
308                 requisitionDocument.setPaymentInfoFlag(canCollapse(OLEConstants.PAYMENT_INFO_SECTION, collapseSections));
309                 requisitionDocument.setAdditionalInstitutionalInfoFlag(canCollapse(OLEConstants.ADDITIONAL_INSTUT_SECTION, collapseSections));
310                 requisitionDocument.setAccountSummaryFlag(canCollapse(OLEConstants.ACCOUNT_SUMMARY_SECTION, collapseSections));
311                 requisitionDocument.setRelatedDocumentsFlag(canCollapse(OLEConstants.RELATED_DOCUMENT_SECTION, collapseSections));
312                 requisitionDocument.setPaymentHistoryFlag(canCollapse(OLEConstants.PAYMENT_HISTORY_SECTION, collapseSections));
313                 requisitionDocument.setNotesAndAttachmentFlag(canCollapse(OLEConstants.NOTES_AND_ATTACH_SECTION, collapseSections));
314                 requisitionDocument.setAdHocRecipientsFlag(canCollapse(OLEConstants.ADHOC_RECIPIENT_SECTION, collapseSections));
315                 requisitionDocument.setRouteLogFlag(canCollapse(OLEConstants.ROUTE_LOG_SECTION, collapseSections));
316             }
317             else if (document instanceof PurchaseOrderDocument) {
318                 PurchaseOrderDocument poDocument = (PurchaseOrderDocument)document;
319                 collapseSections = parameterService.getParameterValuesAsString(PurchaseOrderDocument.class,
320                         OLEConstants.INITIAL_COLLAPSE_SECTIONS).toArray(new String[]{});
321                 poDocument.setOverviewFlag(canCollapse(OLEConstants.OVERVIEW_SECTION,collapseSections));
322                 poDocument.setDeliveryFlag(canCollapse(OLEConstants.DELIVERY_SECTION,collapseSections));
323                 poDocument.setVendorFlag(canCollapse(OLEConstants.VENDOR_SECTION,collapseSections));
324                 poDocument.setTitlesFlag(canCollapse(OLEConstants.TITLES_SECTION,collapseSections));
325                 poDocument.setPaymentInfoFlag(canCollapse(OLEConstants.PAYMENT_INFO_SECTION,collapseSections));
326                 poDocument.setAdditionalInstitutionalInfoFlag(canCollapse(OLEConstants.ADDITIONAL_INSTUT_SECTION,collapseSections));
327                 poDocument.setAccountSummaryFlag(canCollapse(OLEConstants.ACCOUNT_SUMMARY_SECTION,collapseSections));
328                 poDocument.setRelatedDocumentsFlag(canCollapse(OLEConstants.RELATED_DOCUMENT_SECTION,collapseSections));
329                 poDocument.setPaymentHistoryFlag(canCollapse(OLEConstants.PAYMENT_HISTORY_SECTION,collapseSections));
330                 poDocument.setNotesAndAttachmentFlag(canCollapse(OLEConstants.NOTES_AND_ATTACH_SECTION,collapseSections));
331                 poDocument.setAdHocRecipientsFlag(canCollapse(OLEConstants.ADHOC_RECIPIENT_SECTION,collapseSections));
332                 poDocument.setRouteLogFlag(canCollapse(OLEConstants.ROUTE_LOG_SECTION,collapseSections));
333             }
334             else if (document instanceof PaymentRequestDocument) {
335                 PaymentRequestDocument paymentRequestDoc = (PaymentRequestDocument)document;
336                 collapseSections = parameterService.getParameterValuesAsString(PaymentRequestDocument.class,
337                         OLEConstants.INITIAL_COLLAPSE_SECTIONS).toArray(new String[]{});
338                 paymentRequestDoc.setOverviewFlag(canCollapse(OLEConstants.OVERVIEW_SECTION,collapseSections));
339                 paymentRequestDoc.setDeliveryFlag(canCollapse(OLEConstants.DELIVERY_SECTION,collapseSections));
340                 paymentRequestDoc.setInvoiceInfoFlag(canCollapse(OLEConstants.INVOICE_SECTION,collapseSections));
341                 paymentRequestDoc.setProcessItemsFlag(canCollapse(OLEConstants.PROCESS_ITEM_SECTION,collapseSections));
342                 paymentRequestDoc.setAccountSummaryFlag(canCollapse(OLEConstants.ACCOUNT_SUMMARY_SECTION,collapseSections));
343                 paymentRequestDoc.setRelatedDocumentsFlag(canCollapse(OLEConstants.RELATED_DOCUMENT_SECTION,collapseSections));
344                 paymentRequestDoc.setPaymentHistoryFlag(canCollapse(OLEConstants.PAYMENT_HISTORY_SECTION,collapseSections));
345                 paymentRequestDoc.setGeneralEntriesFlag(canCollapse(OLEConstants.GENERAL_ENTRY_SECTION,collapseSections));
346                 paymentRequestDoc.setNotesAndAttachmentFlag(canCollapse(OLEConstants.NOTES_AND_ATTACH_SECTION,collapseSections));
347                 paymentRequestDoc.setAdHocRecipientsFlag(canCollapse(OLEConstants.ADHOC_RECIPIENT_SECTION,collapseSections));
348                 paymentRequestDoc.setRouteLogFlag(canCollapse(OLEConstants.ROUTE_LOG_SECTION,collapseSections));
349             }
350             else if (document instanceof VendorCreditMemoDocument) {
351                 VendorCreditMemoDocument vmDocument = (VendorCreditMemoDocument)document;
352                 collapseSections = parameterService.getParameterValuesAsString(VendorCreditMemoDocument.class,
353                         OLEConstants.INITIAL_COLLAPSE_SECTIONS).toArray(new String[]{});
354                 vmDocument.setOverviewFlag(canCollapse(OLEConstants.OVERVIEW_SECTION,collapseSections));
355                 vmDocument.setVendorFlag(canCollapse(OLEConstants.VENDOR_SECTION,collapseSections));
356                 vmDocument.setCreditMemoInfoFlag(canCollapse(OLEConstants.VENDOR_SECTION,collapseSections));
357                 vmDocument.setProcessItemsFlag(canCollapse(OLEConstants.PROCESS_ITEM_SECTION,collapseSections));
358                 vmDocument.setAccountSummaryFlag(canCollapse(OLEConstants.ACCOUNT_SUMMARY_SECTION,collapseSections));
359                 vmDocument.setRelatedDocumentsFlag(canCollapse(OLEConstants.RELATED_DOCUMENT_SECTION,collapseSections));
360                 vmDocument.setPaymentHistoryFlag(canCollapse(OLEConstants.PAYMENT_HISTORY_SECTION,collapseSections));
361                 vmDocument.setGeneralEntriesFlag(canCollapse(OLEConstants.GENERAL_ENTRY_SECTION,collapseSections));
362                 vmDocument.setNotesAndAttachmentFlag(canCollapse(OLEConstants.NOTES_AND_ATTACH_SECTION,collapseSections));
363                 vmDocument.setAdHocRecipientsFlag(canCollapse(OLEConstants.ADHOC_RECIPIENT_SECTION,collapseSections));
364                 vmDocument.setRouteLogFlag(canCollapse(OLEConstants.ROUTE_LOG_SECTION,collapseSections));
365             }
366 
367         }
368         catch (Exception e) {
369             LOG.error("Error while getting the default Collapse section on PurchasingAccountsPayable Document");
370             throw new RuntimeException(e);
371         }
372         LOG.debug("Leaving getInitialCollapseSections()");
373 
374     }
375 
376     private boolean canCollapse(String sectionName, String[] collapseSections) {
377         LOG.debug("Inside method canCollapse()");
378         List<String> sectionLists = Arrays.asList(collapseSections);
379         if (sectionLists.contains(sectionName)) {
380             return false;
381         }
382         return true;
383     }
384 
385 
386     /*
387     Method to return the First and Last name of a patron given the patronid
388     This method is used only for the purpose of displaying the Patron name information on the Requisition Document..
389      */
390     public String getPatronName(String patronId){
391         StringBuffer patronName = new StringBuffer();
392         try{
393             if(LOG.isDebugEnabled()){
394                 LOG.debug("Getting name for patron -" + patronId);
395             }
396             Map<String,String> map=new HashMap<String,String>();
397             map.put("entityId",patronId);
398             EntityNameBo entityNameBo=(EntityNameBo) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(EntityNameBo.class,map);
399             patronName.append(entityNameBo.getLastName()).append(", ").append(entityNameBo.getFirstName());
400             if(LOG.isDebugEnabled()){
401                 LOG.debug("Returning Name:" + patronName + ": for patronId :" + patronId + ":");
402             }
403         } catch(Exception e){
404             LOG.error("Exception while trying to get name for patron ",e);
405         }
406         return patronName.toString();
407     }//end getPatronName method...
408 
409     /**
410      * This method is used to set the BibMarcRecord which in turn used for creation of Bib record into docstore.
411      * @param bibMarcRecord
412      * @param bibInfoBean
413      */
414     public void setBibMarcRecord(BibMarcRecord bibMarcRecord,BibInfoBean bibInfoBean) {
415         LOG.debug("Inside setBibMarcRecord method.....");
416         List<org.kuali.ole.docstore.common.document.content.bib.marc.DataField> dataFieldList = new ArrayList<DataField>()
417                 ;
418         if (StringUtils.isNotEmpty(bibInfoBean.getTitle())) {
419             dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_TITLE_245, bibInfoBean.getTitle(), org.kuali.ole.OLEConstants.A, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1,dataFieldList));
420         }
421         if (StringUtils.isNotEmpty(bibInfoBean.getAuthor())) {
422             dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_AUTHOR_100, bibInfoBean.getAuthor(), org.kuali.ole.OLEConstants.A, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1,dataFieldList));
423         }
424 
425         if (StringUtils.isNotEmpty(bibInfoBean.getEdition())) {
426             dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_EDITION_250, bibInfoBean.getEdition(), org.kuali.ole.OLEConstants.A, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1,dataFieldList));
427         }
428 
429         if (StringUtils.isNotEmpty(bibInfoBean.getSeries())) {
430             dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_SERIES_490, bibInfoBean.getSeries(), org.kuali.ole.OLEConstants.A, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1,dataFieldList));
431         }
432 
433         if (StringUtils.isNotEmpty(bibInfoBean.getPlaceOfPublication())) {
434             dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_POP_260, bibInfoBean.getPlaceOfPublication(), org.kuali.ole.OLEConstants.A, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1,dataFieldList));
435         }
436 
437         if (StringUtils.isNotEmpty(bibInfoBean.getPublisher())) {
438             dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_PUBLISHER_260, bibInfoBean.getPublisher(), org.kuali.ole.OLEConstants.B, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1,dataFieldList));
439         }
440 
441         if (StringUtils.isNotEmpty(bibInfoBean.getYearOfPublication())) {
442             dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_YOP_260, bibInfoBean.getYearOfPublication(), org.kuali.ole.OLEConstants.C, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1,dataFieldList));
443         }
444 
445         if (StringUtils.isNotEmpty(bibInfoBean.getTypeOfStandardNumber())) {
446             String standardType = bibInfoBean.getTypeOfStandardNumber();
447             boolean isIssn = false;
448             boolean isIsbn = false;
449             if (standardType.equalsIgnoreCase(org.kuali.ole.OLEConstants.OLEBatchProcess.ISSN)) {
450                 isIssn = true;
451             } else if (standardType.equalsIgnoreCase(org.kuali.ole.OLEConstants.ISBN)) {
452                 isIsbn = true;
453             }
454             if (StringUtils.isNotEmpty(bibInfoBean.getStandardNumber())) {
455                 if (isIssn) {
456                     dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_022, bibInfoBean.getStandardNumber(), org.kuali.ole.OLEConstants.A, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1,dataFieldList));
457                 } else if (isIsbn) {
458                     dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_020, bibInfoBean.getStandardNumber(), org.kuali.ole.OLEConstants.A, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1,dataFieldList));
459                 } else {
460                     dataFieldList.add(setDataField(org.kuali.ole.OLEConstants.MARC_EDITOR_024, bibInfoBean.getStandardNumber(), org.kuali.ole.OLEConstants.A, org.kuali.ole.OLEConstants.MARC_EDITOR_IND1_8,dataFieldList));
461                 }
462             }
463         }
464         bibMarcRecord.setDataFields(dataFieldList);
465         LOG.debug("setBibMarcRecord method successfull.....");
466     }
467 
468 
469 
470     /**
471      * This method is used the set the Datafield for the given tag and value
472      * @param tag
473      * @param value
474      * @param dataFieldList
475      * @return
476      */
477     private DataField setDataField(String tag, String value, String subFieldCode, String ind1, List<DataField> dataFieldList){
478         if(LOG.isDebugEnabled()){
479             LOG.debug("inside setDataField method.....");
480             LOG.debug("tag---->"+tag+" "+"value---->"+value);
481         }
482         DataField dataField = new DataField();
483         for(DataField dataFields:dataFieldList){
484             if(dataFields.getTag().equalsIgnoreCase(tag)){
485                 dataField=dataFields;
486             }
487         }
488         dataFieldList.remove(dataField);
489         dataField.setTag(tag);
490         dataField.setInd1(ind1);
491         List<org.kuali.ole.docstore.common.document.content.bib.marc.SubField> subFields = new ArrayList<>();
492         org.kuali.ole.docstore.common.document.content.bib.marc.SubField subField = new org.kuali.ole.docstore.common.document.content.bib.marc.SubField();
493         subField.setCode(subFieldCode);
494         subField.setValue(value);
495         subFields.add(subField);
496         dataField.getSubFields().add(subField);
497         return dataField;
498     }
499 
500     /**
501      * This method is to retrieve the Invoice Documents related to Requisition
502      * @param purApItem
503      */
504     public void setInvoiceDocumentsForRequisition(PurApItem purApItem) {
505         OleRequisitionItem singleItem = (OleRequisitionItem) purApItem;
506         Map<String, OleInvoiceDocument> paidDocuments = new HashMap<String, OleInvoiceDocument>();
507         Map<String, OlePaymentRequestDocument> paymentRequests = new HashMap<String, OlePaymentRequestDocument>();
508         for (OleCopy oleCopy : singleItem.getCopyList()) {
509             if (oleCopy.getOlePaidCopies().size() > 0) {
510                 for (OLEPaidCopy olePaidCopy : oleCopy.getOlePaidCopies()) {
511                     OleInvoiceDocument invoiceDocument = null;
512                     if (olePaidCopy.getInvoiceItemId() != null &&
513                             paidDocuments.containsKey(olePaidCopy.getInvoiceItemId().toString())) {
514                         OleInvoiceItem invoiceItem = olePaidCopy.getInvoiceItem();
515                         invoiceDocument = paidDocuments.get(olePaidCopy.getInvoiceItemId());
516                         if (invoiceItem.getPoItemIdentifier().compareTo(oleCopy.getPoItemId()) == 0 && invoiceDocument != null) {
517                             ((OleInvoiceItem)invoiceDocument.getItem(invoiceItem.getItemLineNumber())).setRequisitionItemIdentifier(oleCopy.getReqItemId());
518                         }
519                     }
520                     else if (olePaidCopy.getInvoiceItem().getInvoiceDocument() != null && olePaidCopy.getInvoiceItem().getInvoiceDocument().getPurapDocumentIdentifier() != null
521                             && (paidDocuments.containsKey(olePaidCopy.getInvoiceItem().getInvoiceDocument().getPurapDocumentIdentifier().toString()))) {
522                         OleInvoiceItem invoiceItem = olePaidCopy.getInvoiceItem();
523                         invoiceDocument = paidDocuments.get(olePaidCopy.getInvoiceItem().getInvoiceDocument().getPurapDocumentIdentifier());
524                         if (invoiceItem.getPoItemIdentifier().compareTo(oleCopy.getPoItemId()) == 0 && invoiceDocument != null) {
525                             ((OleInvoiceItem)invoiceDocument.getItem(invoiceItem.getItemLineNumber())).setRequisitionItemIdentifier(oleCopy.getReqItemId());
526                         }
527                     }
528                     else {
529                         if (olePaidCopy.getInvoiceItem() != null && olePaidCopy.getInvoiceItem().isDebitItem()) {
530                             OleInvoiceItem invoiceItem = olePaidCopy.getInvoiceItem();
531                             invoiceDocument = (OleInvoiceDocument)olePaidCopy.getInvoiceItem().getInvoiceDocument();
532                             if (invoiceDocument != null && SpringContext.getBean(DocumentHeaderService.class) != null) {
533                                 invoiceDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(invoiceDocument.getDocumentNumber()));
534                                 if (invoiceItem.getPoItemIdentifier().compareTo(oleCopy.getPoItemId()) == 0) {
535                                     invoiceItem.setRequisitionItemIdentifier(oleCopy.getReqItemId());
536                                 }
537                                 paidDocuments.put(invoiceDocument.getPurapDocumentIdentifier().toString(),
538                                         invoiceDocument);
539                                 invoiceDocument.setPaymentRequestDocuments(new ArrayList<OlePaymentRequestDocument>());
540                                 invoiceDocument.setCreditMemoDocuments(new ArrayList<OleVendorCreditMemoDocument>());
541                             }
542                         }
543                     }
544                     if (invoiceDocument != null && olePaidCopy.getPreqItem() != null) {
545                         OlePaymentRequestDocument preq = (OlePaymentRequestDocument) olePaidCopy.getPreqItem().getPaymentRequestDocument();
546                         if (preq != null && !paymentRequests.containsKey(preq.getDocumentNumber())) {
547                             paymentRequests.put(preq.getDocumentNumber(), preq);
548                             invoiceDocument.getPaymentRequestDocuments().add(preq);
549                         }
550                     }
551                     if (invoiceDocument != null && SpringContext.getBean(DocumentHeaderService.class) != null) {
552                         invoiceDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(invoiceDocument.getDocumentNumber()));
553                         paidDocuments.put(invoiceDocument.getPurapDocumentIdentifier().toString(),
554                                 invoiceDocument);
555                     }
556                 }
557             }
558         }
559         Collection collection = (Collection) (paidDocuments.values());
560         List list = new ArrayList(collection);
561         singleItem.setInvoiceDocuments(list);
562     }
563 
564     /**
565      * This method is to retrieve the Invoice Documents related to PO
566      * @param purApItem
567      */
568     public void setInvoiceDocumentsForPO(PurApItem purApItem) {
569         OlePurchaseOrderItem singleItem = (OlePurchaseOrderItem) purApItem;
570         Map<String, OleInvoiceDocument> paidDocuments = new HashMap<String, OleInvoiceDocument>();
571         Map<String, OlePaymentRequestDocument> paymentRequests = new HashMap<String, OlePaymentRequestDocument>();
572         for (OleCopy oleCopy : singleItem.getCopyList()) {
573             if (oleCopy.getOlePaidCopies().size() > 0) {
574                 for (OLEPaidCopy olePaidCopy : oleCopy.getOlePaidCopies()) {
575                     OleInvoiceDocument invoiceDocument = null;
576                     if (olePaidCopy.getInvoiceItemId() != null &&
577                             paidDocuments.containsKey(olePaidCopy.getInvoiceItemId().toString())) {
578                         invoiceDocument = paidDocuments.get(olePaidCopy.getInvoiceItemId());
579                     }
580                     else if (olePaidCopy.getInvoiceItem().getInvoiceDocument() != null && olePaidCopy.getInvoiceItem().getInvoiceDocument().getPurapDocumentIdentifier() != null
581                             && (paidDocuments.containsKey(olePaidCopy.getInvoiceItem().getInvoiceDocument().getPurapDocumentIdentifier().toString()))) {
582                         invoiceDocument = paidDocuments.get(olePaidCopy.getInvoiceItem().getInvoiceDocument().getPurapDocumentIdentifier());
583                     }
584                     else {
585                         if (olePaidCopy.getInvoiceItem() != null) {
586                             invoiceDocument = (OleInvoiceDocument)olePaidCopy.getInvoiceItem().getInvoiceDocument();
587                             if (invoiceDocument != null && SpringContext.getBean(DocumentHeaderService.class) != null) {
588                                 invoiceDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(invoiceDocument.getDocumentNumber()));
589                                 paidDocuments.put(invoiceDocument.getPurapDocumentIdentifier().toString(),
590                                         invoiceDocument);
591                                 invoiceDocument.setPaymentRequestDocuments(new ArrayList<OlePaymentRequestDocument>());
592                                 invoiceDocument.setCreditMemoDocuments(new ArrayList<OleVendorCreditMemoDocument>());
593                             }
594                         }
595                     }
596                     if (invoiceDocument != null && olePaidCopy.getPreqItem() != null) {
597                         OlePaymentRequestDocument preq = (OlePaymentRequestDocument)olePaidCopy.getPreqItem().getPaymentRequestDocument();
598                         if (preq != null && !paymentRequests.containsKey(preq.getDocumentNumber())) {
599                             paymentRequests.put(preq.getDocumentNumber(),preq);
600                             invoiceDocument.getPaymentRequestDocuments().add(preq);
601                         }
602                     }
603                     if (invoiceDocument != null && SpringContext.getBean(DocumentHeaderService.class) != null) {
604                         invoiceDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(invoiceDocument.getDocumentNumber()));
605                         paidDocuments.put(invoiceDocument.getPurapDocumentIdentifier().toString(),
606                                 invoiceDocument);
607                     }
608                 }
609             }
610         }
611         Collection collection = (Collection)(paidDocuments.values());
612         List list = new ArrayList(collection);
613         singleItem.setInvoiceDocuments(list);
614     }
615 
616     public void setInvoiceDocumentsForPO(PurchaseOrderDocument purchaseOrderDocument,PurApItem purApItem) {
617         OlePurchaseOrderItem singleItem = (OlePurchaseOrderItem) purApItem;
618         Map<String, OleInvoiceDocument> invoiceDocMap = new HashMap<>();
619         List<OlePurchaseOrderDocument> olePurchaseOrderDocumentList = getRelatedPurchaseOrderList(purchaseOrderDocument);
620         for(OlePurchaseOrderDocument linkedOlePurchaseOrderDocument:olePurchaseOrderDocumentList){
621             for(OlePurchaseOrderItem olePurchaseOrderItem:(List<OlePurchaseOrderItem>)linkedOlePurchaseOrderDocument.getItems()){
622                 if (olePurchaseOrderItem.getItemTypeCode().equals(org.kuali.ole.OLEConstants.ITM_TYP_CODE)&&olePurchaseOrderItem.getItemTitleId().equals(singleItem.getItemTitleId())) {
623                     List<OleInvoiceItem> oleInvoiceItemList = getOleInvoiceItemList(purchaseOrderDocument,olePurchaseOrderItem);
624                     if(oleInvoiceItemList!=null){
625                         for(OleInvoiceItem oleInvoiceItem:oleInvoiceItemList){
626                             if(!invoiceDocMap.containsKey(oleInvoiceItem.getInvoiceDocument().getPurapDocumentIdentifier().toString())){
627                                 OleInvoiceDocument oleInvoiceDocument = (OleInvoiceDocument)oleInvoiceItem.getInvoiceDocument();
628                                 oleInvoiceDocument.setDocumentHeader(SpringContext.getBean(DocumentHeaderService.class).getDocumentHeaderById(oleInvoiceDocument.getDocumentNumber()));
629                                 if(oleInvoiceDocument.getPaymentRequestDocuments()!=null){
630                                     List<OlePaymentRequestDocument> olePaymentRequestDocumentList = getOlePaymentRequestDocumentList(oleInvoiceDocument);
631                                     oleInvoiceDocument.setPaymentRequestDocuments(olePaymentRequestDocumentList);
632                                 }
633                                 if(oleInvoiceDocument.getCreditMemoDocuments()!=null){
634                                     List<OleVendorCreditMemoDocument> oleVendorCreditMemoDocumentList = getOleVendorCreditMemoDocumentList(oleInvoiceDocument);
635                                     oleInvoiceDocument.setCreditMemoDocuments(oleVendorCreditMemoDocumentList);
636                                 }
637                                 invoiceDocMap.put(oleInvoiceItem.getInvoiceDocument().getPurapDocumentIdentifier().toString(), oleInvoiceDocument);
638                             }
639                         }
640                     }
641                 }
642             }
643         }
644         Collection collection = (Collection)(invoiceDocMap.values());
645         List list = new ArrayList(collection);
646         singleItem.setInvoiceDocuments(list);
647     }
648 
649     private List<OlePurchaseOrderDocument> getRelatedPurchaseOrderList(PurchaseOrderDocument purchaseOrderDocument){
650         Map<String,String> poCriteriaMap = new HashMap<>();
651         poCriteriaMap.put(org.kuali.ole.OLEConstants.PurapInvoiceHistory.PURAP_DOC_LINK,Integer.toString(purchaseOrderDocument.getAccountsPayablePurchasingDocumentLinkIdentifier()));
652         List<OlePurchaseOrderDocument> olePurchaseOrderDocumentList = (List<OlePurchaseOrderDocument>)getBusinessObjectService().findMatching(OlePurchaseOrderDocument.class,poCriteriaMap);
653         return olePurchaseOrderDocumentList;
654     }
655 
656     private List<OleInvoiceItem> getOleInvoiceItemList(PurchaseOrderDocument purchaseOrderDocument,OlePurchaseOrderItem olePurchaseOrderItem){
657         Map<String,String> invoiceCriteriaMap = new HashMap<>();
658         invoiceCriteriaMap.put(org.kuali.ole.OLEConstants.PurapInvoiceHistory.POID,Integer.toString(purchaseOrderDocument.getPurapDocumentIdentifier()));
659         invoiceCriteriaMap.put(org.kuali.ole.OLEConstants.PurapInvoiceHistory.PO_ITM_ID,Integer.toString(olePurchaseOrderItem.getItemIdentifier()));
660         List<OleInvoiceItem> oleInvoiceItemList = (List<OleInvoiceItem>)getBusinessObjectService().findMatching(OleInvoiceItem.class,invoiceCriteriaMap);
661         return oleInvoiceItemList;
662     }
663 
664     private List<OlePaymentRequestDocument> getOlePaymentRequestDocumentList(OleInvoiceDocument oleInvoiceDocument){
665         Map<String,String> paymentRequestMap = new HashMap<>();
666         paymentRequestMap.put(org.kuali.ole.OLEConstants.PurapInvoiceHistory.INVOICE_ID,Integer.toString(oleInvoiceDocument.getPurapDocumentIdentifier()));
667         List<OlePaymentRequestDocument> olePaymentRequestDocumentList = (List<OlePaymentRequestDocument>)getBusinessObjectService().findMatching(OlePaymentRequestDocument.class,paymentRequestMap);
668         return olePaymentRequestDocumentList;
669     }
670 
671     private List<OleVendorCreditMemoDocument> getOleVendorCreditMemoDocumentList(OleInvoiceDocument oleInvoiceDocument){
672         Map<String,String> creditMemoMap = new HashMap<>();
673         creditMemoMap.put(org.kuali.ole.OLEConstants.PurapInvoiceHistory.INVOICE_ID,Integer.toString(oleInvoiceDocument.getPurapDocumentIdentifier()));
674         List<OleVendorCreditMemoDocument> oleVendorCreditMemoDocumentList = (List<OleVendorCreditMemoDocument>)getBusinessObjectService().findMatching(OleVendorCreditMemoDocument.class,creditMemoMap);
675         return oleVendorCreditMemoDocumentList;
676     }
677 
678     /**
679      * This method is used to get the requestor type id for the given requestor type
680      * @param requestorType
681      * @return
682      */
683     public Integer getRequestorTypeId(String requestorType) {
684         Map<String, Object> criteria = new HashMap<String, Object>();
685         criteria.put(OleSelectConstant.REQUESTOR_TYPE, requestorType);
686         Collection<OleRequestorType> requestorTypeList = getBusinessObjectService().findMatching(OleRequestorType.class, criteria);
687         return requestorTypeList.iterator().next().getRequestorTypeId();
688     }
689 
690     /**
691      * This method is used to set the claimdate for Requisition
692      * @param oleRequisitionItem
693      */
694     public void setClaimDateForReq(OleRequisitionItem oleRequisitionItem,VendorDetail vendorDetail){
695         if (vendorDetail != null) {
696             String claimInterval = vendorDetail.getClaimInterval();
697             if (StringUtils.isNotBlank(claimInterval)) {
698                 Integer actIntvl = Integer.parseInt(claimInterval);
699                 oleRequisitionItem.setClaimDate(new java.sql.Date(DateUtils.addDays(new java.util.Date(), actIntvl).getTime()));
700             }
701         }
702     }
703 
704     /**
705      * This method is used to set the claimdate for Purchase Order
706      * @param olePurchaseOrderItem
707      */
708     public void setClaimDateForPO(OlePurchaseOrderItem olePurchaseOrderItem,VendorDetail vendorDetail){
709         if (vendorDetail != null) {
710             String claimInterval = vendorDetail.getClaimInterval();
711             if (StringUtils.isNotBlank(claimInterval)) {
712                 Integer actIntvl = Integer.parseInt(claimInterval);
713                 olePurchaseOrderItem.setClaimDate(new java.sql.Date(DateUtils.addDays(new java.util.Date(), actIntvl).getTime()));
714             }
715         }
716     }
717 
718     /**
719      * This method is used to get the item description for the given Bib
720      * @param bib
721      */
722     public String getItemDescription(Bib bib){
723         LOG.debug("### Inside setItemDescription() of OleRequisitionDocument ###");
724         String itemDescription = ((bib.getTitle() != null && !bib.getTitle().isEmpty()) ? bib.getTitle() + "," : "") + ((bib.getAuthor() != null && !bib.getAuthor().isEmpty()) ? bib.getAuthor() + "," : "") + ((bib.getPublisher() != null && !bib.getPublisher().isEmpty()) ? bib.getPublisher() + "," : "") + ((bib.getIsbn() != null && !bib.getIsbn().isEmpty()) ? bib.getIsbn() + "," : "");
725         itemDescription = itemDescription.lastIndexOf(",") < 0 ? itemDescription :
726                 itemDescription.substring(0, itemDescription.lastIndexOf(","));
727         if(LOG.isDebugEnabled()){
728             LOG.debug("Item Description---------->"+itemDescription);
729         }
730         StringEscapeUtils stringEscapeUtils = new StringEscapeUtils();
731         itemDescription = stringEscapeUtils.unescapeHtml(itemDescription);
732         return itemDescription;
733     }
734 
735 
736     public String getItemDescription(OlePurchaseOrderItem olePurchaseOrderItem) {
737         BibInfoRecord bibInfoRecord = olePurchaseOrderItem.getBibInfoRecord();
738         String itemDescription = null;
739         if (bibInfoRecord != null) {
740             olePurchaseOrderItem.setBibUUID(bibInfoRecord.getBibIdStr());
741             olePurchaseOrderItem.setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(olePurchaseOrderItem.getItemTitleId()));
742 
743             itemDescription = ((bibInfoRecord.getTitle() != null && !bibInfoRecord.getTitle().isEmpty()) ? bibInfoRecord.getTitle().trim() + ", " : "")
744                     + ((bibInfoRecord.getAuthor() != null && !bibInfoRecord
745                     .getAuthor().isEmpty()) ? bibInfoRecord.getAuthor().trim() + ", "
746                     : "")
747                     + ((bibInfoRecord.getPublisher() != null && !bibInfoRecord
748                     .getPublisher().isEmpty()) ? bibInfoRecord.getPublisher().trim()
749                     + ", " : "")
750                     + ((bibInfoRecord.getIsxn() != null && !bibInfoRecord.getIsxn()
751                     .isEmpty()) ? bibInfoRecord.getIsxn().trim() + ", " : "");
752         }
753         if (itemDescription != null && !(itemDescription.equals(""))) {
754             itemDescription = itemDescription.lastIndexOf(",") < 0 ? itemDescription :
755                     itemDescription.substring(0, itemDescription.lastIndexOf(","));
756             StringEscapeUtils stringEscapeUtils = new StringEscapeUtils();
757             itemDescription = stringEscapeUtils.unescapeXml(itemDescription);
758         }
759         return itemDescription;
760     }
761 
762     /**
763      *  This method is used to get the Purchase Order Type object based on the given purchase order type id
764      * @param purchaseOrderTypeId
765      * @return
766      */
767     public PurchaseOrderType getPurchaseOrderType(BigDecimal purchaseOrderTypeId){
768         Map purchaseOrderTypeIdMap = new HashMap();
769         purchaseOrderTypeIdMap.put(org.kuali.ole.OLEConstants.PURCHASE_ORDER_TYPE_ID, purchaseOrderTypeId);
770         List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) getBusinessObjectService().findMatching(PurchaseOrderType.class, purchaseOrderTypeIdMap);
771         if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) {
772             return purchaseOrderTypeDocumentList.get(0);
773         }else{
774             return null;
775         }
776     }
777 
778     /**
779      * This method returns the system parameter value for the given input.
780      * @param name
781      * @return
782      */
783     public String getParameter(String name) {
784         LOG.debug("Inside getParameter()");
785         String parameter = "";
786         try {
787             Map<String, String> criteriaMap = new HashMap<String, String>();
788             criteriaMap.put(org.kuali.ole.OLEConstants.NAMESPACE_CODE, org.kuali.ole.OLEConstants.SELECT_NMSPC);
789             criteriaMap.put(org.kuali.ole.OLEConstants.COMPONENT_CODE, org.kuali.ole.OLEConstants.SELECT_CMPNT);
790             criteriaMap.put(org.kuali.ole.OLEConstants.NAME_SELECTOR, name);
791             List<ParameterBo> parametersList = (List<ParameterBo>) getBusinessObjectService().findMatching(ParameterBo.class, criteriaMap);
792             for (ParameterBo parameterBo : parametersList) {
793                 parameter = parameterBo.getValue();
794             }
795         } catch (Exception e) {
796             LOG.error("Exception while getting parameter value", e);
797         }
798         LOG.debug("End of getParameter()");
799         return parameter;
800     }
801 
802     /**
803      * This method gives the current date time value.
804      * @return
805      */
806     public String getCurrentDateTime() {
807         LOG.debug("Inside getCurrentDateTime()");
808         Date date = getDateTimeService().getCurrentDate();
809         String currentDate = SpringContext.getBean(DateTimeService.class).toString(date, timeStampFormat);
810         LOG.debug("End of getCurrentDateTime()");
811         return currentDate;
812     }
813 
814     /**
815      * This method is used to set the Document Description from system parameters.
816      * @param description
817      * @param descMap
818      * @return
819      */
820     public String setDocumentDescription(String description,Map descMap){
821         LOG.debug("Inside setDocumentDescription()");
822         if(description.contains(OLEConstants.OPERATOR_INITIALS)){
823             description = description.replace(OLEConstants.OPERATOR_INITIALS,getOperatorInitials());
824         }
825         if(description.contains(OLEConstants.CURRENT_DATE_TIME)){
826             description = description.replace(OLEConstants.CURRENT_DATE_TIME,getCurrentDateTime());
827         }
828         if(descMap != null){
829             if(description.contains(OLEConstants.PO_DOC_ID)){
830                 description = description.replace(OLEConstants.PO_DOC_ID,descMap.get(OLEConstants.PO_DOC_ID) != null ?descMap.get(OLEConstants.PO_DOC_ID).toString():"");
831             }
832             if(description.contains(OLEConstants.VENDOR_NAME)){
833                 description = description.replace(OLEConstants.VENDOR_NAME,descMap.get(OLEConstants.VENDOR_NAME) != null ?descMap.get(OLEConstants.VENDOR_NAME).toString():"");
834             }
835             if(description.contains(OLEConstants.ORDER_TYP)){
836                 description = description.replace(OLEConstants.ORDER_TYP,descMap.get(OLEConstants.ORDER_TYP) != null ? descMap.get(OLEConstants.ORDER_TYP).toString():"");
837             }
838             if(description.contains(OLEConstants.VND_ITM_ID)){
839                 description = description.replace(OLEConstants.VND_ITM_ID,descMap.get(OLEConstants.VND_ITM_ID) != null ? descMap.get(OLEConstants.VND_ITM_ID).toString():"");
840             }
841         }
842         if(LOG.isDebugEnabled()) {
843             LOG.debug("Document Description ----------------->" +  description);
844         }
845         LOG.debug("End of setDocumentDescription()");
846         return description;
847 
848     }
849 }