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.bc.document.validation.impl; 017 018 import java.sql.Date; 019 import java.util.ArrayList; 020 import java.util.Calendar; 021 import java.util.GregorianCalendar; 022 import java.util.List; 023 024 import org.kuali.kfs.coa.businessobject.AccountingPeriod; 025 import org.kuali.kfs.coa.service.AccountingPeriodService; 026 import org.kuali.kfs.module.bc.BCConstants; 027 import org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionGeneralLedger; 028 import org.kuali.kfs.sys.KFSConstants; 029 import org.kuali.kfs.sys.KFSPropertyConstants; 030 import org.kuali.kfs.sys.ObjectUtil; 031 import org.kuali.kfs.sys.context.SpringContext; 032 033 /** 034 * Common Budget Construction rule utilities 035 */ 036 public class BudgetConstructionRuleUtil { 037 038 /** 039 * Checks if newLine already exists in existingLines using the comparable fields as the uniqueness test 040 * 041 * @param existingLines 042 * @param newLine 043 * @param comparableFields 044 * @return 045 */ 046 public static boolean hasExistingPBGLLine(List<PendingBudgetConstructionGeneralLedger> existingLines, PendingBudgetConstructionGeneralLedger newLine) { 047 048 boolean isFound = false; 049 050 // fields used to check for unique line below 051 List<String> comparableFields = new ArrayList<String>(); 052 comparableFields.add(KFSPropertyConstants.FINANCIAL_OBJECT_CODE); 053 comparableFields.add(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE); 054 055 if (newLine.getFinancialSubObjectCode() == null) { 056 newLine.setFinancialSubObjectCode(KFSConstants.getDashFinancialSubObjectCode()); 057 } 058 for (PendingBudgetConstructionGeneralLedger line : existingLines) { 059 if (ObjectUtil.equals(line, newLine, comparableFields)) { 060 isFound = true; 061 break; 062 } 063 } 064 if (newLine.getFinancialSubObjectCode().equalsIgnoreCase(KFSConstants.getDashFinancialSubObjectCode())) { 065 newLine.setFinancialSubObjectCode(null); 066 } 067 068 return isFound; 069 } 070 public static Calendar getNoBudgetAllowedExpireDate(Integer activeBCFiscalYear){ 071 072 AccountingPeriod accountingPeriod = (AccountingPeriod) SpringContext.getBean(AccountingPeriodService.class).getByPeriod(BCConstants.NO_BUDGET_ALLOWED_EXPIRE_ACCOUNTING_PERIOD, activeBCFiscalYear-BCConstants.NO_BUDGET_ALLOWED_FY_OFFSET); 073 074 Date date = accountingPeriod.getUniversityFiscalPeriodEndDate(); 075 GregorianCalendar gcal = new GregorianCalendar(); 076 gcal.setTime(date); 077 gcal.add(Calendar.DAY_OF_MONTH, 1); 078 079 return gcal; 080 081 } 082 public static Calendar getAccountExpiredWarningExpireDate(Integer activeBCFiscalYear){ 083 084 AccountingPeriod accountingPeriod = (AccountingPeriod) SpringContext.getBean(AccountingPeriodService.class).getByPeriod(BCConstants.ACCOUNT_EXPIRE_WARNING_ACCOUNTING_PERIOD, activeBCFiscalYear-BCConstants.ACCOUNT_EXPIRE_WARNING_FY_OFFSET); 085 086 Date date = accountingPeriod.getUniversityFiscalPeriodEndDate(); 087 GregorianCalendar gcal = new GregorianCalendar(); 088 gcal.setTime(date); 089 gcal.add(Calendar.DAY_OF_MONTH, 1); 090 091 return gcal; 092 093 } 094 }