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.select.document.service.OlePurchaseOrderDocumentHelperService;
022import org.kuali.ole.sys.OLEConstants;
023import org.kuali.ole.sys.context.SpringContext;
024import org.kuali.ole.vnd.businessobject.VendorAlias;
025import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
026
027import java.util.HashMap;
028import java.util.List;
029import java.util.Map;
030
031/**
032 * Purchase Order Reopen Document
033 */
034public class OlePurchaseOrderReopenDocument extends PurchaseOrderReopenDocument {
035    protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OlePurchaseOrderReopenDocument.class);
036
037    private String vendorPoNumber;
038
039    /**
040     * Default constructor.
041     */
042    public OlePurchaseOrderReopenDocument() {
043        super();
044    }
045
046    /**
047     * This method is overridden to populate newly added ole fields from requisition into Ole Purchase Order Reopen Document.
048     *
049     * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#populatePurchaseOrderFromRequisition(org.kuali.ole.module.purap.document.RequisitionDocument)
050     */
051    @Override
052    public void populatePurchaseOrderFromRequisition(RequisitionDocument requisitionDocument) {
053
054        if (LOG.isDebugEnabled()) {
055            LOG.debug("Inside populatePurchaseOrderFromRequisition of OlePurchaseOrderReopenDocument");
056        }
057        SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).populatePurchaseOrderFromRequisition(this, requisitionDocument);
058
059
060    }
061
062    /**
063     * This method is overriden to populate bib info in Ole Purchase Order Reopen Document
064     *
065     * @see org.kuali.ole.module.purap.document.PurchaseOrderDocument#prepareForSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
066     */
067    @Override
068    public void prepareForSave(KualiDocumentEvent event) {
069
070        if (LOG.isDebugEnabled()) {
071            LOG.debug("Inside prepareForSave of OlePurchaseOrderReopenDocument");
072        }
073        SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).prepareForSave(this, event);
074        super.prepareForSave(event);
075    }
076
077
078    /**
079     * This method is overriden to populate bib info in Ole Purchase Order Reopen Document
080     *
081     * @see org.kuali.ole.module.purap.document.PurchasingAccountsPayableDocumentBase#processAfterRetrieve()
082     */
083    @Override
084    public void processAfterRetrieve() {
085        if (LOG.isDebugEnabled()) {
086            LOG.debug("Inside processAfterRetrieve of OlePurchaseOrderReopenDocument");
087        }
088        if (this.getVendorAliasName() == null) {
089            populateVendorAliasName();
090        }
091        SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).processAfterRetrieve(this);
092
093    }
094
095    @Override
096    public List getItemsActiveOnly() {
097        if (LOG.isDebugEnabled()) {
098            LOG.debug("Inside getItemsActiveOnly of OlePurchaseOrderReopenDocument");
099        }
100        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnly(this);
101    }
102
103    /**
104     * Gets the active items in this Purchase Order, and sets up the alternate amount for GL entry creation.
105     *
106     * @return the list of all active items in this Purchase Order.
107     */
108    @Override
109    public List getItemsActiveOnlySetupAlternateAmount() {
110        if (LOG.isDebugEnabled()) {
111            LOG.debug("Inside getItemsActiveOnlySetupAlternateAmount of OlePurchaseOrderReopenDocument");
112        }
113        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getItemsActiveOnlySetupAlternateAmount(this);
114    }
115
116    @Override
117    public boolean getAdditionalChargesExist() {
118        if (LOG.isDebugEnabled()) {
119            LOG.debug("Inside getAdditionalChargesExist of OlePurchaseOrderReopenDocument");
120        }
121        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getAdditionalChargesExist(this);
122    }
123
124    /**
125     * This method returns if Purchase Order Document created is in Final Status
126     *
127     * @return
128     */
129    public boolean getIsFinalReqs() {
130        if (LOG.isDebugEnabled()) {
131            LOG.debug("Inside getIsFinalReqs of OlePurchaseOrderReopenDocument");
132        }
133
134        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsFinalReqs(this);
135    }
136
137    public boolean getIsSplitPO() {
138        if (LOG.isDebugEnabled()) {
139            LOG.debug("Inside getIsSplitPO of OlePurchaseOrderReopenDocument");
140        }
141        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsSplitPO(this);
142    }
143
144    public boolean getIsReOpenPO() {
145        if (LOG.isDebugEnabled()) {
146            LOG.debug("Inside getIsReOpenPO of OlePurchaseOrderReopenDocument");
147        }
148        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getIsReOpenPO(this);
149    }
150
151    /**
152     * This method is used to get the bibedtior creat url from propertie file
153     *
154     * @return Bibeditor creat url string
155     */
156    public String getBibeditorCreateURL() {
157        if (LOG.isDebugEnabled()) {
158            LOG.debug("Inside getBibeditorCreateURL of OlePurchaseOrderReopenDocument");
159        }
160        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorCreateURL();
161    }
162
163    public String getBibSearchURL() {
164        LOG.debug("Inside getBibSearchURL of OlePurchaseOrderReopenDocument");
165        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibSearchURL();
166    }
167
168
169    /**
170     * This method is used to get the Instanceeditor url from propertie file
171     *
172     * @return Instanceeditor url string
173     */
174    public String getInstanceEditorURL() {
175        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getInstanceEditorURL();
176    }
177
178    /**
179     * This method is used to get the bibedtior edit url from propertie file
180     *
181     * @return Bibeditor edit url string
182     */
183    public String getBibeditorEditURL() {
184        if (LOG.isDebugEnabled()) {
185            LOG.debug("Inside getBibeditorEditURL of OlePurchaseOrderReopenDocument");
186        }
187        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorEditURL();
188    }
189
190    /**
191     * This method is used to get the bibedtior view url from propertie file
192     *
193     * @return Bibeditor view url string
194     */
195    public String getBibeditorViewURL() {
196        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getBibeditorViewURL();
197    }
198
199    /**
200     * This method is used to get the directory path where the marc xml files need to be created
201     *
202     * @return Directory path string
203     */
204    public String getMarcXMLFileDirLocation() throws Exception {
205        if (LOG.isDebugEnabled()) {
206            LOG.debug("Inside getMarcXMLFileDirLocation of OlePurchaseOrderReopenDocument");
207        }
208        return SpringContext.getBean(OlePurchaseOrderDocumentHelperService.class).getMarcXMLFileDirLocation();
209    }
210
211
212    public String getVendorPoNumber() {
213        return vendorPoNumber;
214    }
215
216    public void setVendorPoNumber(String vendorPoNumber) {
217        this.vendorPoNumber = vendorPoNumber;
218    }
219
220    /**
221     * This method is used to check the status of the document for displaying view and edit buttons in line item
222     *
223     * @return boolean
224     */
225    public boolean getIsSaved() {
226        if (this.getDocumentHeader().getWorkflowDocument().isSaved() || this.getDocumentHeader().getWorkflowDocument().isInitiated()) {
227            return true;
228        }
229        return false;
230    }
231
232    public boolean getIsATypeOfRCVGDoc() {
233        return false;
234    }
235
236    public boolean getIsATypeOfCORRDoc() {
237        return false;
238    }
239
240    private void populateVendorAliasName() {
241        Map vendorDetailMap = new HashMap();
242        vendorDetailMap.put(OLEConstants.VENDOR_HEADER_IDENTIFIER, this.getVendorHeaderGeneratedIdentifier());
243        vendorDetailMap.put(OLEConstants.VENDOR_DETAIL_IDENTIFIER, this.getVendorDetailAssignedIdentifier());
244        List<VendorAlias> vendorDetailList = (List) getBusinessObjectService().findMatching(VendorAlias.class, vendorDetailMap);
245        if (vendorDetailList != null && vendorDetailList.size() > 0) {
246            this.setVendorAliasName(vendorDetailList.get(0).getVendorAliasName());
247        }
248    }
249}