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    package org.kuali.kfs.module.purap.document.web.struts;
017    
018    import java.util.List;
019    import java.util.Properties;
020    
021    import org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument;
022    import org.kuali.kfs.pdp.PdpPropertyConstants;
023    import org.kuali.kfs.pdp.businessobject.PurchasingPaymentDetail;
024    import org.kuali.kfs.sys.KFSConstants;
025    import org.kuali.kfs.sys.KFSParameterKeyConstants;
026    import org.kuali.kfs.sys.context.SpringContext;
027    import org.kuali.kfs.sys.document.web.struts.FinancialSystemTransactionalDocumentFormBase;
028    import org.kuali.kfs.sys.service.impl.KfsParameterConstants;
029    import org.kuali.rice.kns.service.KualiConfigurationService;
030    import org.kuali.rice.kns.service.ParameterService;
031    import org.kuali.rice.kns.util.KNSConstants;
032    import org.kuali.rice.kns.util.UrlFactory;
033    import org.kuali.rice.kns.web.ui.ExtraButton;
034    
035    /**
036     * Struts Action Form for Electronic Invoice Reject document.
037     */
038    public class ElectronicInvoiceRejectForm extends FinancialSystemTransactionalDocumentFormBase {
039    
040        /**
041         * Constructs a PaymentRequestForm instance and sets up the appropriately casted document.
042         */
043        public ElectronicInvoiceRejectForm() {
044            super();
045        }
046    
047        @Override
048        protected String getDefaultDocumentTypeName() {
049            return "EIRT";
050        }
051        
052        public ElectronicInvoiceRejectDocument getElectronicInvoiceRejectDocument() {
053            return (ElectronicInvoiceRejectDocument) getDocument();
054        }
055    
056        public void setElectronicInvoiceRejectDocument(ElectronicInvoiceRejectDocument eirDocument) {
057            setDocument(eirDocument);
058        }
059    
060        /**
061         * Build additional electronic invoice specific buttons and set extraButtons list.
062         * 
063         * @return - list of extra buttons to be displayed to the user
064         */
065        @Override
066        public List<ExtraButton> getExtraButtons() {
067            // clear out the extra buttons array
068            extraButtons.clear();
069    
070            ElectronicInvoiceRejectDocument eirDoc = this.getElectronicInvoiceRejectDocument();
071    
072            String externalImageURL = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSConstants.RICE_EXTERNALIZABLE_IMAGES_URL_KEY);
073            String appExternalImageURL = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSConstants.EXTERNALIZABLE_IMAGES_URL_KEY);
074    
075            if (eirDoc.getDocumentHeader().getWorkflowDocument().stateIsEnroute()){
076              if (eirDoc.isInvoiceResearchIndicator()) {
077                  addExtraButton("methodToCall.completeResearch", appExternalImageURL + "buttonsmall_complresearch.gif", "Complete Research");
078              } else {
079                  addExtraButton("methodToCall.startResearch", appExternalImageURL + "buttonsmall_research.gif", "Research");
080              }
081            }
082    
083            return extraButtons;
084        }
085    
086        /**
087         * Adds a new button to the extra buttons collection.
088         * 
089         * @param property - property for button
090         * @param source - location of image
091         * @param altText - alternate text for button if images don't appear
092         */
093        protected void addExtraButton(String property, String source, String altText) {
094    
095            ExtraButton newButton = new ExtraButton();
096    
097            newButton.setExtraButtonProperty(property);
098            newButton.setExtraButtonSource(source);
099            newButton.setExtraButtonAltText(altText);
100    
101            extraButtons.add(newButton);
102        }
103        
104        /**
105         * This method builds the url for the disbursement info on the purap documents.
106         * @return the disbursement info url
107         */
108        public String getDisbursementInfoUrl() {
109            String basePath = SpringContext.getBean(KualiConfigurationService.class).getPropertyString(KFSConstants.APPLICATION_URL_KEY);
110            ParameterService parameterService = SpringContext.getBean(ParameterService.class);
111    
112            String orgCode = parameterService.getParameterValue(KfsParameterConstants.PURCHASING_BATCH.class, KFSParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_ORG_CODE);
113            String subUnitCode = parameterService.getParameterValue(KfsParameterConstants.PURCHASING_BATCH.class, KFSParameterKeyConstants.PurapPdpParameterConstants.PURAP_PDP_SUB_UNIT_CODE);
114    
115            Properties parameters = new Properties();
116            parameters.put(KFSConstants.DISPATCH_REQUEST_PARAMETER, KFSConstants.SEARCH_METHOD);
117            parameters.put(KFSConstants.BACK_LOCATION, basePath + "/" + KFSConstants.MAPPING_PORTAL + ".do");
118            parameters.put(KNSConstants.DOC_FORM_KEY, "88888888");
119            parameters.put(KFSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, PurchasingPaymentDetail.class.getName());
120            parameters.put(KFSConstants.HIDE_LOOKUP_RETURN_LINK, "true");
121            parameters.put(KFSConstants.SUPPRESS_ACTIONS, "false");
122            parameters.put(PdpPropertyConstants.PaymentDetail.PAYMENT_UNIT_CODE, orgCode);
123            parameters.put(PdpPropertyConstants.PaymentDetail.PAYMENT_SUBUNIT_CODE, subUnitCode);
124    
125            String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/" + KFSConstants.LOOKUP_ACTION, parameters);
126    
127            return lookupUrl;
128        }
129    
130    }