1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.service.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.coa.businessobject.ObjectCode;
20 import org.kuali.ole.coa.businessobject.OffsetDefinition;
21 import org.kuali.ole.coa.service.OffsetDefinitionService;
22 import org.kuali.ole.fp.document.YearEndDocument;
23 import org.kuali.ole.fp.document.service.YearEndPendingEntryService;
24 import org.kuali.ole.gl.service.SufficientFundsService;
25 import org.kuali.ole.sys.OLEConstants;
26 import org.kuali.ole.sys.OLEPropertyConstants;
27 import org.kuali.ole.sys.businessobject.AccountingLine;
28 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
29 import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
30 import org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants;
31 import org.kuali.ole.sys.service.UniversityDateService;
32 import org.kuali.rice.krad.document.TransactionalDocument;
33 import org.kuali.rice.krad.util.ObjectUtils;
34
35
36
37
38 public class YearEndPendingEntryServiceImpl implements YearEndPendingEntryService {
39 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(YearEndPendingEntryServiceImpl.class);
40
41 protected static final String FINAL_ACCOUNTING_PERIOD = OLEConstants.MONTH13;
42
43 protected UniversityDateService universityDateService;
44 protected SufficientFundsService sufficientFundsService;
45 protected OffsetDefinitionService offsetDefinitionService;
46
47
48
49
50 @Override
51 public void customizeExplicitGeneralLedgerPendingEntry(TransactionalDocument transactionalDocument, AccountingLine accountingLine, GeneralLedgerPendingEntry explicitEntry) {
52 if (!(transactionalDocument instanceof YearEndDocument)) {
53 throw new IllegalArgumentException("invalid (not a year end document) for class:" + transactionalDocument.getClass());
54 }
55 YearEndDocument yearEndDocument = (YearEndDocument) transactionalDocument;
56 explicitEntry.setUniversityFiscalPeriodCode(getAccountingPeriodForYearEndEntry());
57 explicitEntry.setUniversityFiscalYear(getPreviousFiscalYear());
58 }
59
60
61
62
63 @Override
64 public boolean customizeOffsetGeneralLedgerPendingEntry(TransactionalDocument transactionalDocument, GeneralLedgerPendingEntrySourceDetail accountingLine, GeneralLedgerPendingEntry explicitEntry, GeneralLedgerPendingEntry offsetEntry) {
65 if (!(transactionalDocument instanceof YearEndDocument)) {
66 throw new IllegalArgumentException("invalid (not a year end document) for class:" + transactionalDocument.getClass());
67 }
68 OffsetDefinition offsetDefinition = offsetDefinitionService.getByPrimaryId(getPreviousFiscalYear(), explicitEntry.getChartOfAccountsCode(), explicitEntry.getFinancialDocumentTypeCode(), explicitEntry.getFinancialBalanceTypeCode());
69 if (!ObjectUtils.isNull(offsetDefinition)) {
70 String offsetObjectCode = getOffsetFinancialObjectCode(offsetDefinition);
71 offsetEntry.setFinancialObjectCode(offsetObjectCode);
72 if (offsetObjectCode.equals(AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialObjectCode())) {
73
74 offsetEntry.setAcctSufficientFundsFinObjCd(AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialObjectCode());
75 }
76 else {
77 offsetDefinition.refreshReferenceObject(OLEPropertyConstants.FINANCIAL_OBJECT);
78 ObjectCode financialObject = offsetDefinition.getFinancialObject();
79
80 if (ObjectUtils.isNull(financialObject)) {
81 throw new RuntimeException("offset object code " + offsetEntry.getUniversityFiscalYear() + "-" + offsetEntry.getChartOfAccountsCode() + "-" + offsetEntry.getFinancialObjectCode());
82 }
83 offsetEntry.refreshReferenceObject(OLEPropertyConstants.ACCOUNT);
84 offsetEntry.setAcctSufficientFundsFinObjCd(sufficientFundsService.getSufficientFundsObjectCode(financialObject, offsetEntry.getAccount().getAccountSufficientFundsCode()));
85 }
86
87 offsetEntry.setFinancialObjectTypeCode(getOffsetFinancialObjectTypeCode(offsetDefinition));
88
89 return true;
90 }
91 return false;
92 }
93
94
95
96
97 @Override
98 public String getFinalAccountingPeriod() {
99 return FINAL_ACCOUNTING_PERIOD;
100 }
101
102
103
104
105 protected String getAccountingPeriodForYearEndEntry() {
106 return getFinalAccountingPeriod();
107 }
108
109
110
111
112 @Override
113 public Integer getPreviousFiscalYear() {
114 return universityDateService.getCurrentFiscalYear() - 1;
115 }
116
117
118
119
120
121
122
123 protected String getOffsetFinancialObjectCode(OffsetDefinition offsetDefinition) {
124 if (null != offsetDefinition) {
125 String returnString = (!StringUtils.isBlank(offsetDefinition.getFinancialObjectCode())) ? offsetDefinition.getFinancialObjectCode() : AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialObjectCode();
126 return returnString;
127 } else {
128 return AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialObjectCode();
129 }
130 }
131
132
133
134
135
136
137
138 protected String getOffsetFinancialObjectTypeCode(OffsetDefinition offsetDefinition) {
139 if (null != offsetDefinition && null != offsetDefinition.getFinancialObject()) {
140 String returnString = (!StringUtils.isBlank(offsetDefinition.getFinancialObject().getFinancialObjectTypeCode())) ? offsetDefinition.getFinancialObject().getFinancialObjectTypeCode() : AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialObjectType();
141 return returnString;
142 } else {
143 return AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialObjectType();
144 }
145
146 }
147
148 public void setUniversityDateService(UniversityDateService universityDateService) {
149 this.universityDateService = universityDateService;
150 }
151
152 public void setSufficientFundsService(SufficientFundsService sufficientFundsService) {
153 this.sufficientFundsService = sufficientFundsService;
154 }
155
156 public void setOffsetDefinitionService(OffsetDefinitionService offsetDefinitionService) {
157 this.offsetDefinitionService = offsetDefinitionService;
158 }
159
160 }