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.validation.impl; 017 018 import org.kuali.kfs.fp.businessobject.CashDrawer; 019 import org.kuali.kfs.fp.document.CashReceiptFamilyBase; 020 import org.kuali.kfs.fp.document.service.CashReceiptService; 021 import org.kuali.kfs.fp.service.CashDrawerService; 022 import org.kuali.kfs.sys.KFSConstants; 023 import org.kuali.kfs.sys.KFSKeyConstants; 024 import org.kuali.kfs.sys.document.validation.GenericValidation; 025 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 026 import org.kuali.rice.kns.util.GlobalVariables; 027 028 /** 029 * Validation for the cash receipt document that verifies that the cash drawer is open at approval. 030 */ 031 public class CashReceiptCashDrawerOpenValidation extends GenericValidation { 032 private CashReceiptFamilyBase cashReceiptDocumentForValidation; 033 private CashReceiptService cashReceiptService; 034 private CashDrawerService cashDrawerService; 035 036 /** 037 * Makes sure that the cash drawer for the verification unit associated with this CR doc is 038 * open. If it's not, the the rule fails. 039 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent) 040 */ 041 public boolean validate(AttributedDocumentEvent event) { 042 CashDrawer cd = getCashDrawerService().getByCampusCode(getCashReceiptDocumentForValidation().getCampusLocationCode()); 043 if (cd == null) { 044 throw new IllegalStateException("There is no cash drawer associated with unitName '" + getCashReceiptDocumentForValidation().getCampusLocationCode() + "' from cash receipt " + getCashReceiptDocumentForValidation().getDocumentNumber()); 045 } 046 else if (cd.isClosed() && !getCashReceiptDocumentForValidation().getDocumentHeader().getWorkflowDocument().isAdHocRequested()) { 047 GlobalVariables.getMessageMap().putError(KFSConstants.GLOBAL_ERRORS, KFSKeyConstants.CashReceipt.MSG_CASH_DRAWER_CLOSED_VERIFICATION_NOT_ALLOWED, cd.getCampusCode()); 048 return false; 049 } 050 return true; 051 } 052 053 /** 054 * Gets the cashReceiptDocumentForValidation attribute. 055 * @return Returns the cashReceiptDocumentForValidation. 056 */ 057 public CashReceiptFamilyBase getCashReceiptDocumentForValidation() { 058 return cashReceiptDocumentForValidation; 059 } 060 061 /** 062 * Sets the cashReceiptDocumentForValidation attribute value. 063 * @param cashReceiptDocumentForValidation The cashReceiptDocumentForValidation to set. 064 */ 065 public void setCashReceiptDocumentForValidation(CashReceiptFamilyBase cashReceiptFamilyDocumentForValidation) { 066 this.cashReceiptDocumentForValidation = cashReceiptFamilyDocumentForValidation; 067 } 068 069 /** 070 * Gets the cashDrawerService attribute. 071 * @return Returns the cashDrawerService. 072 */ 073 public CashDrawerService getCashDrawerService() { 074 return cashDrawerService; 075 } 076 077 /** 078 * Sets the cashDrawerService attribute value. 079 * @param cashDrawerService The cashDrawerService to set. 080 */ 081 public void setCashDrawerService(CashDrawerService cashDrawerService) { 082 this.cashDrawerService = cashDrawerService; 083 } 084 085 /** 086 * Gets the cashReceiptService attribute. 087 * @return Returns the cashReceiptService. 088 */ 089 public CashReceiptService getCashReceiptService() { 090 return cashReceiptService; 091 } 092 093 /** 094 * Sets the cashReceiptService attribute value. 095 * @param cashReceiptService The cashReceiptService to set. 096 */ 097 public void setCashReceiptService(CashReceiptService cashReceiptService) { 098 this.cashReceiptService = cashReceiptService; 099 } 100 }