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.authorization;
017    
018    import java.util.Set;
019    
020    import org.kuali.kfs.module.purap.PurapAuthorizationConstants.PurchaseOrderEditMode;
021    import org.kuali.kfs.module.purap.PurapConstants.PurchaseOrderStatuses;
022    import org.kuali.kfs.module.purap.document.PurchaseOrderDocument;
023    import org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument;
024    import org.kuali.kfs.module.purap.document.service.PurapService;
025    import org.kuali.kfs.sys.context.SpringContext;
026    import org.kuali.rice.kns.document.Document;
027    import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument;
028    
029    
030    public class PurchaseOrderAmendmentDocumentPresentationController extends PurchaseOrderDocumentPresentationController {
031        
032        @Override
033        protected boolean canEdit(Document document) {
034            PurchaseOrderDocument poDocument = (PurchaseOrderDocument)document;
035            // po amend docs in CGIP status are only editable when in Initiated or Saved status
036            if (PurchaseOrderStatuses.CHANGE_IN_PROCESS.equals(poDocument.getStatusCode())) {
037                KualiWorkflowDocument workflowDoc = document.getDocumentHeader().getWorkflowDocument();
038                if (!workflowDoc.stateIsInitiated() && !workflowDoc.stateIsSaved()) {
039                    return false;
040                }
041            }    
042            return super.canEdit(document);
043        }
044        
045        @Override
046        public Set<String> getEditModes(Document document) {
047            Set<String> editModes = super.getEditModes(document);
048            PurchaseOrderDocument poDocument = (PurchaseOrderDocument)document;
049    
050            if (PurchaseOrderStatuses.CHANGE_IN_PROCESS.equals(poDocument.getStatusCode())) {
051                KualiWorkflowDocument workflowDoc = document.getDocumentHeader().getWorkflowDocument();
052                //  amendment doc needs to lock its field for initiator while enroute
053                if (workflowDoc.stateIsInitiated() || workflowDoc.stateIsSaved()) {
054                    editModes.add(PurchaseOrderEditMode.AMENDMENT_ENTRY);
055                }
056            }
057            if (PurchaseOrderStatuses.AWAIT_NEW_UNORDERED_ITEM_REVIEW.equals(poDocument.getStatusCode())) {
058                editModes.add(PurchaseOrderEditMode.AMENDMENT_ENTRY);
059            }
060            
061            if (SpringContext.getBean(PurapService.class).isDocumentStoppedInRouteNode((PurchasingAccountsPayableDocument) document, "New Unordered Items")) {
062                editModes.add(PurchaseOrderEditMode.UNORDERED_ITEM_ACCOUNT_ENTRY);
063            }
064            
065            return editModes;
066        }
067    
068        @Override
069        protected boolean canReload(Document document) {
070            //  show the reload button if the doc is anything but processed or final
071            KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument();
072            return (workflowDocument.stateIsSaved() || workflowDocument.stateIsEnroute()) ;
073        }
074    
075    }