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.HashMap;
019    import java.util.List;
020    import java.util.Map;
021    
022    import javax.servlet.http.HttpServletRequest;
023    
024    import org.apache.log4j.Logger;
025    import org.kuali.kfs.module.purap.PurapAuthorizationConstants;
026    import org.kuali.kfs.module.purap.PurapKeyConstants;
027    import org.kuali.kfs.module.purap.document.BulkReceivingDocument;
028    import org.kuali.kfs.sys.KFSConstants;
029    import org.kuali.kfs.sys.document.web.struts.FinancialSystemTransactionalDocumentFormBase;
030    import org.kuali.rice.kew.util.KEWConstants;
031    import org.kuali.rice.kns.util.KNSConstants;
032    import org.kuali.rice.kns.util.ObjectUtils;
033    import org.kuali.rice.kns.web.ui.ExtraButton;
034    
035    public class BulkReceivingForm extends FinancialSystemTransactionalDocumentFormBase {
036        
037        protected static final Logger LOG = Logger.getLogger(BulkReceivingForm.class); 
038        protected Integer purchaseOrderId;
039    
040        public BulkReceivingForm() {
041            super();
042        }
043    
044        @Override
045        protected String getDefaultDocumentTypeName() {
046            return "RCVB";
047        }
048        
049        public BulkReceivingDocument getBulkReceivingDocument() {
050            return (BulkReceivingDocument) getDocument();
051        }
052    
053        public void setBulkReceivingDocument(BulkReceivingDocument bulkReceivingDocument) {
054            setDocument(bulkReceivingDocument);
055        }
056    
057        public Integer getPurchaseOrderId() {
058            return purchaseOrderId;
059        }
060    
061        public void setPurchaseOrderId(Integer purchaseOrderId) {
062            this.purchaseOrderId = purchaseOrderId;
063        }
064    
065        /**
066         * Override the superclass method to add appropriate buttons for
067         * BulkReceivingDocument.
068         * 
069         * @see org.kuali.rice.kns.web.struts.form.KualiForm#getExtraButtons()
070         */
071        @Override
072        public List<ExtraButton> getExtraButtons() {
073            extraButtons.clear();
074            
075            String displayInitTab = (String)getEditingMode().get(PurapAuthorizationConstants.BulkReceivingEditMode.DISPLAY_INIT_TAB);
076            if (ObjectUtils.isNotNull(displayInitTab) && displayInitTab.equalsIgnoreCase("true")) {
077                extraButtons.add(createBulkReceivingContinueButton());
078                extraButtons.add(createClearInitFieldsButton());
079            }
080            else if (getBulkReceivingDocument().getDocumentHeader().getWorkflowDocument().stateIsEnroute() || 
081                    getBulkReceivingDocument().getDocumentHeader().getWorkflowDocument().stateIsProcessed() || 
082                    getBulkReceivingDocument().getDocumentHeader().getWorkflowDocument().stateIsFinal()) {
083                extraButtons.add(createPrintReceivingTicketButton());
084            }
085                
086            return extraButtons;
087        }        
088    
089        protected ExtraButton createBulkReceivingContinueButton(){
090            ExtraButton continueButton = new ExtraButton();
091            continueButton.setExtraButtonProperty("methodToCall.continueBulkReceiving");
092            continueButton.setExtraButtonSource("${" + KFSConstants.RICE_EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_continue.gif");
093            continueButton.setExtraButtonAltText("Continue");
094            return continueButton;
095        }
096        
097        protected ExtraButton createClearInitFieldsButton(){
098            ExtraButton clearButton = new ExtraButton();
099            clearButton.setExtraButtonProperty("methodToCall.clearInitFields");
100            clearButton.setExtraButtonSource("${" + KFSConstants.RICE_EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_clear.gif");
101            clearButton.setExtraButtonAltText("Clear");
102            return clearButton;
103        }
104        
105        protected ExtraButton createPrintReceivingTicketButton(){
106            ExtraButton printButton = new ExtraButton();
107            printButton.setExtraButtonProperty("methodToCall.printReceivingTicketPDF");
108            printButton.setExtraButtonSource("${" + KFSConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_print.gif");
109            printButton.setExtraButtonAltText("Print");
110            return printButton;
111        }
112    
113        public String getGoodsDeliveredByLabel(){
114            return PurapKeyConstants.MESSAGE_BULK_RECEIVING_GOODSDELIVEREDBY_LABEL;
115        }
116    
117        
118        @Override
119        public boolean shouldMethodToCallParameterBeUsed(String methodToCallParameterName, String methodToCallParameterValue, HttpServletRequest request) {
120            if (KNSConstants.DISPATCH_REQUEST_PARAMETER.equals(methodToCallParameterName) && "printReceivingTicket".equals(methodToCallParameterValue)) {
121                return true;
122            }
123            return super.shouldMethodToCallParameterBeUsed(methodToCallParameterName, methodToCallParameterValue, request);
124        }
125    }