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  
17  package org.kuali.ole.select.document;
18  
19  import org.kuali.ole.module.purap.document.PurchaseOrderVoidDocument;
20  import org.kuali.ole.module.purap.document.RequisitionDocument;
21  import org.kuali.ole.module.purap.document.service.OlePurapService;
22  import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
23  import org.kuali.ole.select.document.service.OlePurchaseOrderDocumentHelperService;
24  import org.kuali.ole.sys.OLEConstants;
25  import org.kuali.ole.sys.context.SpringContext;
26  import org.kuali.ole.vnd.businessobject.VendorAlias;
27  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
28  
29  import java.util.HashMap;
30  import java.util.Iterator;
31  import java.util.List;
32  import java.util.Map;
33  
34  /**
35   * Purchase Order Void Document
36   */
37  public class OlePurchaseOrderVoidDocument extends PurchaseOrderVoidDocument {
38      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePurchaseOrderVoidDocument.class);
39      private String vendorPoNumber;
40      private static transient OlePurapService olePurapService;
41  
42      /**
43       * Default constructor.
44       */
45      public OlePurchaseOrderVoidDocument() {
46          super();
47      }
48  
49      /**
50       * This method is overridden to populate newly added ole fields from requisition into Ole Purchase Order Void Document.
51       *
52       * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#populatePurchaseOrderFromRequisition(org.kuali.ole.module.purap.document.RequisitionDocument)
53       */
54      @Override
55      public void populatePurchaseOrderFromRequisition(RequisitionDocument requisitionDocument) {
56          SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).populatePurchaseOrderFromRequisition(this, requisitionDocument);
57      }
58  
59      /**
60       * This method is overriden to populate bib info in Ole Purchase Order Void Document.
61       *
62       * @see org.kuali.ole.module.purap.document.PurchaseOrderCloseDocument#prepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
63       */
64      @Override
65      public void prepareForSave(KualiDocumentEvent event) {
66          SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).prepareForSave(this, event);
67          super.prepareForSave(event);
68      }
69  
70      /**
71       * This method is overriden to populate bib info in Ole Purchase Order Void Document.
72       *
73       * @see org.kuali.ole.module.purap.document.PurchaseOrderCloseDocument#prepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
74       */
75      @Override
76      public void processAfterRetrieve() {
77          if (this.getVendorAliasName() == null) {
78              populateVendorAliasName();
79          }
80          try {
81              List<OlePurchaseOrderItem> items = this.getItems();
82              Iterator iterator = items.iterator();
83              while (iterator.hasNext()) {
84                  Object object = iterator.next();
85                  if (object instanceof OlePurchaseOrderItem) {
86                      OlePurchaseOrderItem singleItem = (OlePurchaseOrderItem) object;
87                      if(singleItem.getCopyList().size() > 0) {
88                          //getOlePurapService().setInvoiceDocumentsForPO(olePurchaseOrderItem);
89                          getOlePurapService().setInvoiceDocumentsForPO(this,singleItem);
90                      }
91                  }
92              }
93          } catch (Exception e) {
94              LOG.error("Exception in OlePurchaseOrderCloseDocument:processAfterRetrieve" + e.getMessage());
95              throw new RuntimeException(e);
96          }
97          SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).processAfterRetrieve(this);
98      }
99  
100     @Override
101     public List getItemsActiveOnly() {
102         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnly(this);
103     }
104 
105     /**
106      * Gets the active items in this Purchase Order, and sets up the alternate amount for GL entry creation.
107      *
108      * @return the list of all active items in this Purchase Order.
109      */
110     @Override
111     public List getItemsActiveOnlySetupAlternateAmount() {
112         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnlySetupAlternateAmount(this);
113     }
114 
115     @Override
116     public boolean getAdditionalChargesExist() {
117         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getAdditionalChargesExist(this);
118     }
119 
120     /**
121      * This method returns if Purchase Order Document created is in Final Status
122      *
123      * @return
124      */
125     public boolean getIsFinalReqs() {
126         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsFinalReqs(this);
127     }
128 
129     public boolean getIsSplitPO() {
130         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsSplitPO(this);
131     }
132 
133     public boolean getIsReOpenPO() {
134         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsReOpenPO(this);
135     }
136 
137     /**
138      * This method is used to get the bibedtior creat url from propertie file
139      *
140      * @return Bibeditor creat url string
141      */
142     public String getBibeditorCreateURL() {
143         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorCreateURL();
144     }
145 
146     public String getBibSearchURL() {
147         LOG.debug("Inside getBibSearchURL of OlePurchaseOrderVoidDocument");
148         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibSearchURL();
149     }
150 
151     /**
152      * This method is used to get the bibedtior edit url from propertie file
153      *
154      * @return Bibeditor edit url string
155      */
156     public String getBibeditorEditURL() {
157         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorEditURL();
158     }
159 
160     /**
161      * This method is used to get the dublinedtior edit url from propertie file
162      *
163      * @return Dublineditor edit url string
164      */
165     public String getDublinEditorEditURL() {
166         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorEditURL();
167     }
168     /**
169      * This method is used to get the Instanceeditor url from propertie file
170      *
171      * @return Instanceeditor url string
172      */
173     public String getInstanceEditorURL() {
174         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getInstanceEditorURL();
175     }
176 
177     /**
178      * This method is used to get the bibedtior view url from propertie file
179      *
180      * @return Bibeditor view url string
181      */
182     public String getBibeditorViewURL() {
183         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorViewURL();
184     }
185 
186     /**
187      * This method is used to get the dublinedtior view url from propertie file
188      *
189      * @return dublineditor view url string
190      */
191     public String getDublinEditorViewURL() {
192         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorViewURL();
193     }
194     /**
195      * This method is used to get the directory path where the marc xml files need to be created
196      *
197      * @return Directory path string
198      */
199     public String getMarcXMLFileDirLocation() throws Exception {
200         return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getMarcXMLFileDirLocation();
201     }
202 
203     public String getVendorPoNumber() {
204         return vendorPoNumber;
205     }
206 
207     public void setVendorPoNumber(String vendorPoNumber) {
208         this.vendorPoNumber = vendorPoNumber;
209     }
210 
211 
212     /**
213      * This method is used to check the status of the document for displaying view and edit buttons in line item
214      *
215      * @return boolean
216      */
217     public boolean getIsSaved() {
218         if (this.getDocumentHeader().getWorkflowDocument().isSaved() || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
219             return true;
220         }
221         return false;
222     }
223 
224     public boolean getIsATypeOfRCVGDoc() {
225         return false;
226     }
227 
228     public boolean getIsATypeOfCORRDoc() {
229         return false;
230     }
231 
232     private void populateVendorAliasName() {
233         Map vendorDetailMap = new HashMap();
234         vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, this.getVendorHeaderGeneratedIdentifier());
235         vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, this.getVendorDetailAssignedIdentifier());
236         List<VendorAlias> vendorDetailList = (List) getBusinessObjectService().findMatching(VendorAlias.class, vendorDetailMap);
237         if (vendorDetailList != null && vendorDetailList.size() > 0) {
238             this.setVendorAliasName(vendorDetailList.get(0).getVendorAliasName());
239         }
240     }
241 
242     public static OlePurapService getOlePurapService() {
243         if (olePurapService == null) {
244             olePurapService = SpringContext.getBean(OlePurapService.class);
245         }
246         return olePurapService;
247     }
248 }