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.ar.document.validation.impl; 017 018 import org.apache.commons.lang.StringUtils; 019 import org.kuali.kfs.coa.businessobject.Account; 020 import org.kuali.kfs.module.ar.ArConstants; 021 import org.kuali.kfs.module.ar.ArKeyConstants; 022 import org.kuali.kfs.module.ar.ArPropertyConstants; 023 import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceDetail; 024 import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument; 025 import org.kuali.kfs.sys.KFSConstants; 026 import org.kuali.kfs.sys.KFSPropertyConstants; 027 import org.kuali.kfs.sys.document.validation.GenericValidation; 028 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 029 import org.kuali.rice.kns.service.ParameterService; 030 import org.kuali.rice.kns.util.GlobalVariables; 031 import org.kuali.rice.kns.util.ObjectUtils; 032 033 public class CustomerInvoiceDetailSubFundGroupReceivableValidation extends GenericValidation { 034 035 private CustomerInvoiceDetail customerInvoiceDetail; 036 private ParameterService parameterService; 037 038 public ParameterService getParameterService() { 039 return parameterService; 040 } 041 042 public void setParameterService(ParameterService parameterService) { 043 this.parameterService = parameterService; 044 } 045 046 public boolean validate(AttributedDocumentEvent event) { 047 customerInvoiceDetail.refreshReferenceObject(KFSPropertyConstants.ACCOUNT); 048 Account account = customerInvoiceDetail.getAccount(); 049 if (StringUtils.isNotEmpty(account.getSubFundGroupCode())) { 050 String receivableObjectCode = parameterService.getParameterValue(CustomerInvoiceDocument.class, ArConstants.GLPE_RECEIVABLE_OFFSET_OBJECT_CODE_BY_SUB_FUND, account.getSubFundGroupCode()); 051 052 if (StringUtils.isEmpty(receivableObjectCode)) { 053 GlobalVariables.getMessageMap().putError(KFSConstants.SUB_FUND_GROUP_CODE_PROPERTY_NAME, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DOCUMENT_INVALID_SUBFUND_WITH_NO_AR_OBJ_CD, account.getSubFundGroupCode(), account.getAccountNumber()); 054 return false; 055 } 056 else { 057 customerInvoiceDetail.setAccountsReceivableObjectCode(receivableObjectCode); 058 customerInvoiceDetail.refreshReferenceObject("accountsReceivableObject"); 059 060 if (ObjectUtils.isNull(customerInvoiceDetail.getAccountsReceivableObject())) { 061 GlobalVariables.getMessageMap().putError(KFSConstants.SUB_FUND_GROUP_CODE_PROPERTY_NAME, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DOCUMENT_INVALID_SUBFUND_AR_OBJ_CD_IN_PARM, receivableObjectCode, account.getSubFundGroupCode(), account.getAccountNumber()); 062 return false; 063 } 064 } 065 } 066 067 return true; 068 } 069 070 public CustomerInvoiceDetail getCustomerInvoiceDetail() { 071 return customerInvoiceDetail; 072 } 073 074 public void setCustomerInvoiceDetail(CustomerInvoiceDetail customerInvoiceDetail) { 075 this.customerInvoiceDetail = customerInvoiceDetail; 076 } 077 078 }