1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.document.validation.impl;
17
18 import java.sql.Date;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.joda.time.DateTime;
22 import org.kuali.ole.coa.businessobject.Account;
23 import org.kuali.ole.coa.businessobject.IndirectCostRecoveryAccount;
24 import org.kuali.ole.coa.businessobject.SubFundGroup;
25 import org.kuali.ole.coa.service.AccountService;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.rice.core.api.config.property.ConfigurationService;
28 import org.kuali.rice.kns.document.MaintenanceDocument;
29 import org.kuali.rice.krad.util.ObjectUtils;
30 import org.kuali.rice.location.api.postalcode.PostalCode;
31 import org.kuali.rice.location.api.postalcode.PostalCodeService;
32
33
34
35
36
37 public class AccountPreRules extends MaintenancePreRulesBase {
38
39 protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AccountPreRules.class);
40
41 protected static final String DEFAULT_STATE_CODE = "Account.Defaults.StateCode";
42 protected static final String DEFAULT_ACCOUNT_TYPE_CODE = "Account.Defaults.AccountType";
43
44 protected ConfigurationService configService;
45 protected AccountService accountService;
46 protected PostalCodeService postalZipCodeService;
47 protected Account newAccount;
48
49 protected static final String GENERAL_FUND_CD = "GF";
50 protected static final String RESTRICTED_FUND_CD = "RF";
51 protected static final String ENDOWMENT_FUND_CD = "EN";
52 protected static final String PLANT_FUND_CD = "PF";
53
54 protected static final String RESTRICTED_CD_RESTRICTED = "R";
55 protected static final String RESTRICTED_CD_UNRESTRICTED = "U";
56 protected static final String RESTRICTED_CD_TEMPORARILY_RESTRICTED = "T";
57 protected static final String RESTRICTED_CD_NOT_APPLICABLE = "N";
58
59
60 public AccountPreRules() {
61 accountService = SpringContext.getBean(AccountService.class);
62 configService = SpringContext.getBean(ConfigurationService.class);
63 postalZipCodeService = SpringContext.getBean(PostalCodeService.class);
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77 @Override
78 protected boolean doCustomPreRules(MaintenanceDocument document) {
79 setupConvenienceObjects(document);
80 checkForContinuationAccounts();
81 checkForDefaultSubFundGroupStatus();
82
83 LOG.debug("done with continuation account, proceeeding with remaining pre rules");
84
85 newAccountDefaults(document);
86 setStateFromZip(document);
87
88 return true;
89 }
90
91
92
93
94
95 protected void checkForDefaultSubFundGroupStatus() {
96 String restrictedStatusCode = "";
97
98
99
100 if (ObjectUtils.isNull(newAccount.getSubFundGroup()) || StringUtils.isBlank(newAccount.getSubFundGroupCode())) {
101 return;
102 }
103 SubFundGroup subFundGroup = newAccount.getSubFundGroup();
104
105
106 if (StringUtils.isNotBlank(subFundGroup.getAccountRestrictedStatusCode())) {
107 restrictedStatusCode = subFundGroup.getAccountRestrictedStatusCode().trim();
108 String subFundGroupCd = subFundGroup.getSubFundGroupCode();
109 newAccount.setAccountRestrictedStatusCode(restrictedStatusCode);
110 }
111
112 }
113
114
115
116
117 protected void checkForContinuationAccounts() {
118 LOG.debug("entering checkForContinuationAccounts()");
119
120 if (StringUtils.isNotBlank(newAccount.getReportsToAccountNumber())) {
121 Account account = checkForContinuationAccount("Fringe Benefit Account", newAccount.getReportsToChartOfAccountsCode(), newAccount.getReportsToAccountNumber(), "");
122 if (ObjectUtils.isNotNull(account)) {
123 newAccount.setReportsToAccountNumber(account.getAccountNumber());
124 newAccount.setReportsToChartOfAccountsCode(account.getChartOfAccountsCode());
125 }
126 }
127
128 if (StringUtils.isNotBlank(newAccount.getEndowmentIncomeAccountNumber())) {
129 Account account = checkForContinuationAccount("Endowment Account", newAccount.getEndowmentIncomeAcctFinCoaCd(), newAccount.getEndowmentIncomeAccountNumber(), "");
130 if (ObjectUtils.isNotNull(account)) {
131 newAccount.setEndowmentIncomeAccountNumber(account.getAccountNumber());
132 newAccount.setEndowmentIncomeAcctFinCoaCd(account.getChartOfAccountsCode());
133 }
134 }
135
136 if (StringUtils.isNotBlank(newAccount.getIncomeStreamAccountNumber())) {
137 Account account = checkForContinuationAccount("Income Stream Account", newAccount.getIncomeStreamFinancialCoaCode(), newAccount.getIncomeStreamAccountNumber(), "");
138 if (ObjectUtils.isNotNull(account)) {
139 newAccount.setIncomeStreamAccountNumber(account.getAccountNumber());
140 newAccount.setIncomeStreamFinancialCoaCode(account.getChartOfAccountsCode());
141 }
142 }
143
144 if (StringUtils.isNotBlank(newAccount.getContractControlAccountNumber())) {
145 Account account = checkForContinuationAccount("Contract Control Account", newAccount.getContractControlFinCoaCode(), newAccount.getContractControlAccountNumber(), "");
146 if (ObjectUtils.isNotNull(account)) {
147 newAccount.setContractControlAccountNumber(account.getAccountNumber());
148 newAccount.setContractControlFinCoaCode(account.getChartOfAccountsCode());
149 }
150 }
151
152 for (IndirectCostRecoveryAccount icra : newAccount.getActiveIndirectCostRecoveryAccounts()){
153 if (StringUtils.isNotBlank(icra.getIndirectCostRecoveryAccountNumber())) {
154 Account account = checkForContinuationAccount("Indirect Cost Recovery Account", icra.getIndirectCostRecoveryAccountNumber(), icra.getIndirectCostRecoveryFinCoaCode(), "");
155 if (ObjectUtils.isNotNull(account)) {
156 icra.setIndirectCostRecoveryAccountNumber(account.getAccountNumber());
157 icra.setIndirectCostRecoveryFinCoaCode(account.getChartOfAccountsCode());
158 }
159 }
160 }
161
162
163 }
164
165
166
167
168
169
170
171
172 protected void setupConvenienceObjects(MaintenanceDocument document) {
173
174
175 newAccount = (Account) document.getNewMaintainableObject().getBusinessObject();
176 newAccount.refreshNonUpdateableReferences();
177 }
178
179
180
181
182
183
184 protected void newAccountDefaults(MaintenanceDocument maintenanceDocument) {
185
186
187
188
189
190
191
192
193 DateTime ts = new DateTime(maintenanceDocument.getDocumentHeader().getWorkflowDocument().getDateCreated());
194 Date newts = new Date(ts.getMillis());
195
196 if (ts != null) {
197
198 if (newAccount.getAccountCreateDate() == null) {
199 newAccount.setAccountCreateDate(newts);
200 }
201
202 if (newAccount.getAccountEffectiveDate() == null) {
203 newAccount.setAccountEffectiveDate(newts);
204 }
205 }
206 }
207
208
209
210
211
212
213 protected void setStateFromZip(MaintenanceDocument maintenanceDocument) {
214
215
216
217 if (StringUtils.isNotBlank(newAccount.getAccountZipCode()) && StringUtils.isNotBlank(newAccount.getAccountCountryCode()) ) {
218 PostalCode zip = postalZipCodeService.getPostalCode( newAccount.getAccountCountryCode(), newAccount.getAccountZipCode() );
219
220
221 if (ObjectUtils.isNotNull(zip)) {
222 newAccount.setAccountCityName(zip.getCityName());
223 newAccount.setAccountStateCode(zip.getStateCode());
224 }
225 }
226 }
227
228
229 }