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 static org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
019
020 import java.util.HashMap;
021 import java.util.Map;
022
023 import org.kuali.kfs.module.ar.ArConstants;
024 import org.kuali.kfs.module.ar.ArKeyConstants;
025 import org.kuali.kfs.module.ar.ArPropertyConstants;
026 import org.kuali.kfs.module.ar.businessobject.CustomerInvoiceItemCode;
027 import org.kuali.kfs.module.ar.businessobject.OrganizationOptions;
028 import org.kuali.kfs.module.ar.document.CustomerInvoiceDocument;
029 import org.kuali.kfs.sys.KFSPropertyConstants;
030 import org.kuali.kfs.sys.document.validation.GenericValidation;
031 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
032 import org.kuali.rice.kns.service.BusinessObjectService;
033 import org.kuali.rice.kns.util.GlobalVariables;
034 import org.kuali.rice.kns.util.ObjectUtils;
035
036 public class CustomerInvoiceBillingOrgOptionValidation extends GenericValidation {
037
038 private CustomerInvoiceDocument customerInvoiceDocument;
039 private BusinessObjectService businessObjectService;
040
041 public boolean validate(AttributedDocumentEvent event) {
042
043 Map<String, String> criteria = new HashMap<String, String>();
044 criteria.put("chartOfAccountsCode", customerInvoiceDocument.getBillByChartOfAccountCode());
045 criteria.put("organizationCode", customerInvoiceDocument.getBilledByOrganizationCode());
046 OrganizationOptions organizationOptions = (OrganizationOptions) businessObjectService.findByPrimaryKey(OrganizationOptions.class, criteria);
047
048 if (ObjectUtils.isNull(organizationOptions)) {
049 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerInvoiceDocumentFields.BILLED_BY_ORGANIZATION_CODE, ArKeyConstants.InvoiceItemCode.ORG_OPTIONS_DOES_NOT_EXIST_FOR_CHART_AND_ORG, new String[]{customerInvoiceDocument.getBillByChartOfAccountCode(), customerInvoiceDocument.getBilledByOrganizationCode()});
050 return false;
051 }
052 else {
053 if (!(customerInvoiceDocument.getAccountsReceivableDocumentHeader().getProcessingChartOfAccountCode().equalsIgnoreCase(organizationOptions.getProcessingChartOfAccountCode()) &&
054 customerInvoiceDocument.getAccountsReceivableDocumentHeader().getProcessingOrganizationCode().equalsIgnoreCase(organizationOptions.getProcessingOrganizationCode()))) {
055 GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + ArPropertyConstants.CustomerInvoiceDocumentFields.BILLED_BY_ORGANIZATION_CODE,
056 ArKeyConstants.ERROR_CUSTOMER_INVOICE_DOCUMENT_INVALID_BILLING_PROCESSING_ORGANIZATION_IN_ORG_OPTIONS,
057 new String[]{customerInvoiceDocument.getAccountsReceivableDocumentHeader().getProcessingChartOfAccCodeAndOrgCode(),
058 customerInvoiceDocument.getBilledByChartOfAccCodeAndOrgCode()});
059 return false;
060 }
061 }
062 return true;
063 }
064
065 public CustomerInvoiceDocument getCustomerInvoiceDocument() {
066 return customerInvoiceDocument;
067 }
068
069 public void setCustomerInvoiceDocument(CustomerInvoiceDocument customerInvoiceDocument) {
070 this.customerInvoiceDocument = customerInvoiceDocument;
071 }
072
073 public BusinessObjectService getBusinessObjectService() {
074 return businessObjectService;
075 }
076
077 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
078 this.businessObjectService = businessObjectService;
079 }
080 }