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.ld.document.validation.impl; 017 018 import static org.kuali.kfs.sys.businessobject.AccountingLineOverride.CODE.EXPIRED_ACCOUNT; 019 import static org.kuali.kfs.sys.businessobject.AccountingLineOverride.CODE.EXPIRED_ACCOUNT_AND_NON_FRINGE_ACCOUNT_USED; 020 021 import java.util.ArrayList; 022 import java.util.List; 023 024 import org.apache.commons.lang.StringUtils; 025 import org.kuali.kfs.coa.businessobject.Account; 026 import org.kuali.kfs.module.ld.LaborConstants ; 027 import org.kuali.kfs.module.ld.LaborKeyConstants; 028 import org.kuali.kfs.module.ld.LaborPropertyConstants; 029 import org.kuali.kfs.module.ld.businessobject.ExpenseTransferAccountingLine; 030 import org.kuali.kfs.module.ld.businessobject.ExpenseTransferSourceAccountingLine; 031 import org.kuali.kfs.module.ld.businessobject.LaborObject; 032 import org.kuali.kfs.module.ld.document.LaborExpenseTransferDocumentBase; 033 import org.kuali.kfs.module.ld.document.SalaryExpenseTransferDocument; 034 import org.kuali.kfs.sys.KFSKeyConstants; 035 import org.kuali.kfs.sys.KFSPropertyConstants; 036 import org.kuali.kfs.sys.businessobject.AccountingLine; 037 import org.kuali.kfs.sys.document.AccountingDocument; 038 import org.kuali.kfs.sys.document.validation.GenericValidation; 039 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent; 040 import org.kuali.rice.kns.util.GlobalVariables; 041 import org.kuali.rice.kns.util.KualiDecimal; 042 043 /** 044 * determine whether the amount in the account is not zero 045 * 046 * @param accountingDocument the given document 047 * @param accountingLine the given accounting line 048 * @return true determine whether the amount in the account is not zero; otherwise, false 049 */ 050 public class LaborExpenseTransfeAmountValidValidation extends GenericValidation { 051 private AccountingLine accountingLineForValidation; 052 private AccountingDocument accountingDocumentForValidation; 053 054 /** 055 * Validates that an accounting line whether the expired account in the target accounting line 056 * can be used. 057 * <strong>Expects an accounting line as the first a parameter</strong> 058 * @see org.kuali.kfs.validation.Validation#validate(java.lang.Object[]) 059 */ 060 public boolean validate(AttributedDocumentEvent event) { 061 boolean result = true; 062 063 AccountingLine accountingLine = getAccountingLineForValidation(); 064 AccountingDocument accountingDocumentForValidation = getAccountingDocumentForValidation(); 065 066 // not allow the zero amount on the account lines. 067 if (!isAmountValid(accountingDocumentForValidation,accountingLine)) { 068 GlobalVariables.getMessageMap().putError(KFSPropertyConstants.AMOUNT, KFSKeyConstants.ERROR_ZERO_AMOUNT, "an accounting line"); 069 return false; 070 } 071 072 return result; 073 } 074 075 /** 076 * determine whether the amount in the account is not zero. 077 * 078 * @param accountingDocument the given accounting line 079 * @return true if the amount is not zero; otherwise, false 080 */ 081 082 public boolean isAmountValid(AccountingDocument document, AccountingLine accountingLine) { 083 KualiDecimal amount = accountingLine.getAmount(); 084 085 // Check for zero amount 086 if (amount.isZero()) { 087 GlobalVariables.getMessageMap().putError(KFSPropertyConstants.AMOUNT, KFSKeyConstants.ERROR_ZERO_AMOUNT, "an accounting line"); 088 return false; 089 } 090 return true; 091 } 092 093 /** 094 * Gets the accountingLineForValidation attribute. 095 * @return Returns the accountingLineForValidation. 096 */ 097 public AccountingDocument getAccountingDocumentForValidation() { 098 return accountingDocumentForValidation; 099 } 100 101 /** 102 * Sets the accountingLineForValidation attribute value. 103 * @param accountingLineForValidation The accountingLineForValidation to set. 104 */ 105 public void setAccountingLineForValidation(AccountingDocument accountingDocumentForValidation) { 106 this.accountingDocumentForValidation = accountingDocumentForValidation; 107 } 108 109 /** 110 * Gets the accountingLineForValidation attribute. 111 * @return Returns the accountingLineForValidation. 112 */ 113 public AccountingLine getAccountingLineForValidation() { 114 return accountingLineForValidation; 115 } 116 117 /** 118 * Sets the accountingLineForValidation attribute value. 119 * @param accountingLineForValidation The accountingLineForValidation to set. 120 */ 121 public void setAccountingLineForValidation(AccountingLine accountingLineForValidation) { 122 this.accountingLineForValidation = accountingLineForValidation; 123 } 124 }