001/*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.kuali.ole.select.document;
018
019import org.kuali.ole.module.purap.document.PurchaseOrderReopenDocument;
020import org.kuali.ole.module.purap.document.RequisitionDocument;
021import org.kuali.ole.module.purap.document.service.OlePurapService;
022import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
023import org.kuali.ole.select.document.service.OlePurchaseOrderDocumentHelperService;
024import org.kuali.ole.sys.OLEConstants;
025import org.kuali.ole.sys.context.SpringContext;
026import org.kuali.ole.vnd.businessobject.VendorAlias;
027import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
028
029import java.util.HashMap;
030import java.util.Iterator;
031import java.util.List;
032import java.util.Map;
033
034/**
035 * Purchase Order Reopen Document
036 */
037public class OlePurchaseOrderReopenDocument extends PurchaseOrderReopenDocument {
038    protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePurchaseOrderReopenDocument.class);
039
040    private String vendorPoNumber;
041    private static transient OlePurapService olePurapService;
042    /**
043     * Default constructor.
044     */
045    public OlePurchaseOrderReopenDocument() {
046        super();
047    }
048
049    /**
050     * This method is overridden to populate newly added ole fields from requisition into Ole Purchase Order Reopen Document.
051     *
052     * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#populatePurchaseOrderFromRequisition(org.kuali.ole.module.purap.document.RequisitionDocument)
053     */
054    @Override
055    public void populatePurchaseOrderFromRequisition(RequisitionDocument requisitionDocument) {
056
057        if (LOG.isDebugEnabled()) {
058            LOG.debug("Inside populatePurchaseOrderFromRequisition of OlePurchaseOrderReopenDocument");
059        }
060        SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).populatePurchaseOrderFromRequisition(this, requisitionDocument);
061
062
063    }
064
065    /**
066     * This method is overriden to populate bib info in Ole Purchase Order Reopen Document
067     *
068     * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#prepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
069     */
070    @Override
071    public void prepareForSave(KualiDocumentEvent event) {
072
073        if (LOG.isDebugEnabled()) {
074            LOG.debug("Inside prepareForSave of OlePurchaseOrderReopenDocument");
075        }
076        SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).prepareForSave(this, event);
077        super.prepareForSave(event);
078    }
079
080
081    /**
082     * This method is overriden to populate bib info in Ole Purchase Order Reopen Document
083     *
084     * @see org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocumentBase#processAfterRetrieve()
085     */
086    @Override
087    public void processAfterRetrieve() {
088        if (LOG.isDebugEnabled()) {
089            LOG.debug("Inside processAfterRetrieve of OlePurchaseOrderReopenDocument");
090        }
091        if (this.getVendorAliasName() == null) {
092            populateVendorAliasName();
093        }
094        try {
095            List<OlePurchaseOrderItem> items = this.getItems();
096            Iterator iterator = items.iterator();
097            while (iterator.hasNext()) {
098                Object object = iterator.next();
099                if (object instanceof OlePurchaseOrderItem) {
100                    OlePurchaseOrderItem singleItem = (OlePurchaseOrderItem) object;
101                    if(singleItem.getCopyList().size() > 0) {
102                        //getOlePurapService().setInvoiceDocumentsForPO(olePurchaseOrderItem);
103                        getOlePurapService().setInvoiceDocumentsForPO(this,singleItem);
104                    }
105                }
106            }
107        } catch (Exception e) {
108            LOG.error("Exception in OlePurchaseOrderCloseDocument:processAfterRetrieve" + e.getMessage());
109            throw new RuntimeException(e);
110        }
111        SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).processAfterRetrieve(this);
112
113    }
114
115    @Override
116    public List getItemsActiveOnly() {
117        if (LOG.isDebugEnabled()) {
118            LOG.debug("Inside getItemsActiveOnly of OlePurchaseOrderReopenDocument");
119        }
120        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnly(this);
121    }
122
123    /**
124     * Gets the active items in this Purchase Order, and sets up the alternate amount for GL entry creation.
125     *
126     * @return the list of all active items in this Purchase Order.
127     */
128    @Override
129    public List getItemsActiveOnlySetupAlternateAmount() {
130        if (LOG.isDebugEnabled()) {
131            LOG.debug("Inside getItemsActiveOnlySetupAlternateAmount of OlePurchaseOrderReopenDocument");
132        }
133        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnlySetupAlternateAmount(this);
134    }
135
136    @Override
137    public boolean getAdditionalChargesExist() {
138        if (LOG.isDebugEnabled()) {
139            LOG.debug("Inside getAdditionalChargesExist of OlePurchaseOrderReopenDocument");
140        }
141        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getAdditionalChargesExist(this);
142    }
143
144    /**
145     * This method returns if Purchase Order Document created is in Final Status
146     *
147     * @return
148     */
149    public boolean getIsFinalReqs() {
150        if (LOG.isDebugEnabled()) {
151            LOG.debug("Inside getIsFinalReqs of OlePurchaseOrderReopenDocument");
152        }
153
154        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsFinalReqs(this);
155    }
156
157    public boolean getIsSplitPO() {
158        if (LOG.isDebugEnabled()) {
159            LOG.debug("Inside getIsSplitPO of OlePurchaseOrderReopenDocument");
160        }
161        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsSplitPO(this);
162    }
163
164    public boolean getIsReOpenPO() {
165        if (LOG.isDebugEnabled()) {
166            LOG.debug("Inside getIsReOpenPO of OlePurchaseOrderReopenDocument");
167        }
168        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsReOpenPO(this);
169    }
170
171    /**
172     * This method is used to get the bibedtior creat url from propertie file
173     *
174     * @return Bibeditor creat url string
175     */
176    public String getBibeditorCreateURL() {
177        if (LOG.isDebugEnabled()) {
178            LOG.debug("Inside getBibeditorCreateURL of OlePurchaseOrderReopenDocument");
179        }
180        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorCreateURL();
181    }
182
183    public String getBibSearchURL() {
184        LOG.debug("Inside getBibSearchURL of OlePurchaseOrderReopenDocument");
185        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibSearchURL();
186    }
187
188
189    /**
190     * This method is used to get the Instanceeditor url from propertie file
191     *
192     * @return Instanceeditor url string
193     */
194    public String getInstanceEditorURL() {
195        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getInstanceEditorURL();
196    }
197
198    /**
199     * This method is used to get the bibedtior edit url from propertie file
200     *
201     * @return Bibeditor edit url string
202     */
203    public String getBibeditorEditURL() {
204        if (LOG.isDebugEnabled()) {
205            LOG.debug("Inside getBibeditorEditURL of OlePurchaseOrderReopenDocument");
206        }
207        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorEditURL();
208    }
209
210    /**
211     * This method is used to get the bibedtior view url from propertie file
212     *
213     * @return Bibeditor view url string
214     */
215    public String getBibeditorViewURL() {
216        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorViewURL();
217    }
218
219    /**
220     * This method is used to get the directory path where the marc xml files need to be created
221     *
222     * @return Directory path string
223     */
224    public String getMarcXMLFileDirLocation() throws Exception {
225        if (LOG.isDebugEnabled()) {
226            LOG.debug("Inside getMarcXMLFileDirLocation of OlePurchaseOrderReopenDocument");
227        }
228        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getMarcXMLFileDirLocation();
229    }
230
231
232    public String getVendorPoNumber() {
233        return vendorPoNumber;
234    }
235
236    public void setVendorPoNumber(String vendorPoNumber) {
237        this.vendorPoNumber = vendorPoNumber;
238    }
239
240    /**
241     * This method is used to check the status of the document for displaying view and edit buttons in line item
242     *
243     * @return boolean
244     */
245    public boolean getIsSaved() {
246        if (this.getDocumentHeader().getWorkflowDocument().isSaved() || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
247            return true;
248        }
249        return false;
250    }
251
252    public boolean getIsATypeOfRCVGDoc() {
253        return false;
254    }
255
256    public boolean getIsATypeOfCORRDoc() {
257        return false;
258    }
259
260    private void populateVendorAliasName() {
261        Map vendorDetailMap = new HashMap();
262        vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, this.getVendorHeaderGeneratedIdentifier());
263        vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, this.getVendorDetailAssignedIdentifier());
264        List<VendorAlias> vendorDetailList = (List) getBusinessObjectService().findMatching(VendorAlias.class, vendorDetailMap);
265        if (vendorDetailList != null && vendorDetailList.size() > 0) {
266            this.setVendorAliasName(vendorDetailList.get(0).getVendorAliasName());
267        }
268    }
269
270    /**
271     * This method is used to get the dublin editor edit url from property file
272     *
273     * @return Dublineditor edit url string
274     */
275    public String getDublinEditorEditURL() {
276        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorEditURL();
277    }
278
279    /**
280     * This method is used to get the dublin editor view url from property file
281     *
282     * @return dublineditor view url string
283     */
284    public String getDublinEditorViewURL() {
285        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getDublinEditorViewURL();
286    }
287
288    public static OlePurapService getOlePurapService() {
289        if (olePurapService == null) {
290            olePurapService = SpringContext.getBean(OlePurapService.class);
291        }
292        return olePurapService;
293    }
294}