1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
35
36 public class YearEndAccountingPeriodValuesFinder extends KeyValuesBase {
37
38
39
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
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 }