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