View Javadoc

1   /*
2    * Copyright 2007 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.businessobject.options;
17  
18  import java.sql.Date;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.ole.coa.businessobject.AccountingPeriod;
24  import org.kuali.ole.coa.service.AccountingPeriodService;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.ole.sys.service.impl.OleParameterConstants;
28  import org.kuali.rice.core.api.datetime.DateTimeService;
29  import org.kuali.rice.core.api.util.ConcreteKeyValue;
30  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
31  import org.kuali.rice.krad.keyvalues.KeyValuesBase;
32  
33  /**
34   * returns list of accounting period value pairs valid for year end posting
35   */
36  public class YearEndAccountingPeriodValuesFinder extends KeyValuesBase {
37  
38      /**
39       * @see org.kuali.rice.kns.lookup.keyvalues.KeyValuesFinder#getKeyValues()
40       */
41      @Override
42      public List getKeyValues() {
43          List<ConcreteKeyValue> accountingPeriodCodes = new ArrayList<ConcreteKeyValue>();
44  
45          Date date = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
46          AccountingPeriod currentAccountingPeriod = SpringContext.getBean(AccountingPeriodService.class).getByDate(date);
47  
48          if (currentAccountingPeriod.isOpen()) {
49              // add the current period with blank value, so scrubber will set entries when posting
50              accountingPeriodCodes.add(new ConcreteKeyValue("", currentAccountingPeriod.getUniversityFiscalPeriodName()));
51          }
52  
53          String numberOfPostbackPeriodsParmVal = SpringContext.getBean(ParameterService.class).getParameterValueAsString(OLEConstants.CoreModuleNamespaces.OLE, OleParameterConstants.YEAR_END_ACCOUNTING_PERIOD_PARAMETER_NAMES.DETAIL_PARAMETER_TYPE, OleParameterConstants.YEAR_END_ACCOUNTING_PERIOD_PARAMETER_NAMES.NUMBER_OF_POSTBACK_PERIODS);
54          if (StringUtils.isNotBlank(numberOfPostbackPeriodsParmVal) && Integer.valueOf(numberOfPostbackPeriodsParmVal) > 0) {
55              for (int i = 1; i <= Integer.valueOf(numberOfPostbackPeriodsParmVal); i++) {
56                  int currentFiscalYear = currentAccountingPeriod.getUniversityFiscalYear();
57                  int currentFiscalPeriod = Integer.valueOf(currentAccountingPeriod.getUniversityFiscalPeriodCode());
58  
59                  if (currentFiscalPeriod == 1) {
60                      currentFiscalYear = currentFiscalYear - 1;
61                      currentFiscalPeriod = 13;
62                  } else {
63                      currentFiscalPeriod = currentFiscalPeriod - 1;
64                  }
65  
66                  currentAccountingPeriod = SpringContext.getBean(AccountingPeriodService.class).getByPeriod(StringUtils.leftPad(Integer.toString(currentFiscalPeriod), 2, "0"), currentFiscalYear);
67                  if (currentAccountingPeriod.isOpen()) {
68                      accountingPeriodCodes.add(new ConcreteKeyValue(currentAccountingPeriod.getUniversityFiscalPeriodCode() + currentAccountingPeriod.getUniversityFiscalYear(), currentAccountingPeriod.getUniversityFiscalPeriodName()));
69                  }
70              }
71          }
72  
73          return accountingPeriodCodes;
74      }
75  }