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.fp.document.authorization; 017 018 import org.kuali.kfs.fp.businessobject.CashDrawer; 019 import org.kuali.kfs.fp.document.CashReceiptDocument; 020 import org.kuali.kfs.fp.service.CashDrawerService; 021 import org.kuali.kfs.sys.context.SpringContext; 022 import org.kuali.kfs.sys.document.authorization.LedgerPostingDocumentPresentationControllerBase; 023 import org.kuali.rice.kns.document.Document; 024 import org.kuali.rice.kns.workflow.service.KualiWorkflowDocument; 025 026 public class CashReceiptDocumentPresentationController extends LedgerPostingDocumentPresentationControllerBase { 027 private static final String CASH_MANAGEMENT_NODE_NAME = "CashManagement"; 028 029 /** 030 * @see org.kuali.rice.kns.document.authorization.DocumentPresentationControllerBase#canApprove(org.kuali.rice.kns.document.Document) 031 */ 032 @Override 033 protected boolean canApprove(Document document) { 034 return this.canApproveOrBlanketApprove(document) ? super.canApprove(document) : false; 035 } 036 037 /** 038 * @see org.kuali.rice.kns.document.authorization.DocumentPresentationControllerBase#canBlanketApprove(org.kuali.rice.kns.document.Document) 039 */ 040 @Override 041 protected boolean canBlanketApprove(Document document) { 042 return this.canApproveOrBlanketApprove(document) ? super.canBlanketApprove(document) : false; 043 } 044 045 protected boolean canApproveOrBlanketApprove(Document document) { 046 KualiWorkflowDocument workflowDocument = document.getDocumentHeader().getWorkflowDocument(); 047 if (workflowDocument.isApprovalRequested() && !workflowDocument.isAdHocRequested()) { 048 CashReceiptDocument cashReceiptDocument = (CashReceiptDocument) document; 049 050 String campusCode = cashReceiptDocument.getCampusLocationCode(); 051 CashDrawer cashDrawer = SpringContext.getBean(CashDrawerService.class).getByCampusCode(campusCode); 052 if (cashDrawer == null) { 053 throw new RuntimeException("No cash drawer exists for campus code "+campusCode+"; please create on via the Cash Drawer Maintenance Document before attemping to create a CashReceiptDocument for campus "+campusCode); 054 } 055 if (cashDrawer == null) { 056 throw new IllegalStateException("There is no cash drawer associated with cash receipt: " + cashReceiptDocument.getDocumentNumber()); 057 } 058 059 if (cashDrawer.isClosed()) { 060 return false; 061 } 062 } 063 064 return true; 065 } 066 067 /** 068 * Prevents editing of the document at the CashManagement node 069 * @see org.kuali.rice.kns.document.authorization.DocumentPresentationControllerBase#canEdit(org.kuali.rice.kns.document.Document) 070 */ 071 @Override 072 protected boolean canEdit(Document document) { 073 if (document.getDocumentHeader().getWorkflowDocument().getCurrentRouteNodeNames().contains(CashReceiptDocumentPresentationController.CASH_MANAGEMENT_NODE_NAME)) return false; 074 return super.canEdit(document); 075 } 076 077 }