1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.service.impl;
17
18 import org.kuali.ole.coa.businessobject.Account;
19 import org.kuali.ole.coa.businessobject.ObjectCode;
20 import org.kuali.ole.coa.businessobject.SubAccount;
21 import org.kuali.ole.coa.businessobject.SubObjectCode;
22 import org.kuali.ole.coa.service.AccountService;
23 import org.kuali.ole.coa.service.ObjectCodeService;
24 import org.kuali.ole.coa.service.SubObjectCodeService;
25 import org.kuali.ole.gl.batch.ScrubberStep;
26 import org.kuali.ole.module.purap.PurapConstants.PaymentRequestStatuses;
27 import org.kuali.ole.module.purap.PurapKeyConstants;
28 import org.kuali.ole.module.purap.document.PaymentRequestDocument;
29 import org.kuali.ole.sys.OLEConstants;
30 import org.kuali.ole.sys.OLEKeyConstants;
31 import org.kuali.ole.sys.businessobject.AccountingLine;
32 import org.kuali.ole.sys.context.SpringContext;
33 import org.kuali.rice.core.api.datetime.DateTimeService;
34 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
35 import org.kuali.rice.krad.datadictionary.DataDictionary;
36 import org.kuali.rice.krad.util.GlobalVariables;
37 import org.kuali.rice.krad.util.ObjectUtils;
38
39 public class PaymentRequestAccountingLineRuleHelperServiceImpl extends PurapAccountingLineRuleHelperServiceImpl {
40
41
42
43
44
45 @Override
46 public boolean hasRequiredOverrides(AccountingLine line, String overrideCode) {
47 boolean hasOverrides = true;
48
49 Account account = SpringContext.getBean(AccountService.class).getByPrimaryId(line.getChartOfAccountsCode(), line.getAccountNumber());
50 String docStatus = getDocument().getApplicationDocumentStatus();
51
52
53 if (ObjectUtils.isNotNull(account)) {
54
55 if (PaymentRequestStatuses.APPDOC_AWAITING_SUB_ACCT_MGR_REVIEW.equals(docStatus) ||
56 PaymentRequestStatuses.APPDOC_AWAITING_FISCAL_REVIEW.equals(docStatus) ||
57 PaymentRequestStatuses.APPDOC_AWAITING_ORG_REVIEW.equals(docStatus) ||
58 PaymentRequestStatuses.APPDOC_AWAITING_TAX_REVIEW.equals(docStatus) ||
59 PaymentRequestStatuses.APPDOC_DEPARTMENT_APPROVED.equals(docStatus) ||
60 PaymentRequestStatuses.APPDOC_AWAITING_PAYMENT_REVIEW.equals(docStatus)
61 ||
62 PaymentRequestStatuses.APPDOC_AUTO_APPROVED.equals(docStatus)) {
63
64 String expirationExtensionDays = SpringContext.getBean(ParameterService.class).getParameterValueAsString(ScrubberStep.class, OLEConstants.SystemGroupParameterNames.GL_SCRUBBER_VALIDATION_DAYS_OFFSET);
65 int expirationExtensionDaysInt = 3 * 30;
66
67 if (ObjectUtils.isNotNull(expirationExtensionDays) && expirationExtensionDays.trim().length() > 0) {
68
69 expirationExtensionDaysInt = new Integer(expirationExtensionDays).intValue();
70 }
71
72
73 if (account.isExpired() && account.isForContractsAndGrants() && (SpringContext.getBean(DateTimeService.class).dateDiff(account.getAccountExpirationDate(), SpringContext.getBean(DateTimeService.class).getCurrentDate(), true) > expirationExtensionDaysInt)) {
74 GlobalVariables.getMessageMap().putError(OLEConstants.ACCOUNT_NUMBER_PROPERTY_NAME, PurapKeyConstants.ERROR_ITEM_ACCOUNT_EXPIRED_REPLACE, account.getAccountNumber());
75 hasOverrides = false;
76 }
77 }
78 } else {
79
80 hasOverrides = false;
81 }
82 return hasOverrides;
83 }
84
85
86 public boolean isValidObjectCode(ObjectCode objectCode, DataDictionary dataDictionary, String errorPropertyName) {
87 String label = getObjectCodeLabel();
88
89
90 if (ObjectUtils.isNull(objectCode)) {
91 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_EXISTENCE, label);
92 return false;
93 }
94
95 Integer universityFiscalYear = ((PaymentRequestDocument) getDocument()).getPostingYearPriorOrCurrent();
96 ObjectCode objectCodeForValidation = (SpringContext.getBean(ObjectCodeService.class).getByPrimaryId(universityFiscalYear, objectCode.getChartOfAccountsCode(), objectCode.getFinancialObjectCode()));
97
98
99 if (!objectCodeForValidation.isFinancialObjectActiveCode()) {
100 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_INACTIVE, label);
101 return false;
102 }
103
104 return true;
105 }
106
107
108 public boolean isValidSubObjectCode(SubObjectCode subObjectCode, DataDictionary dataDictionary, String errorPropertyName) {
109 String label = getSubObjectCodeLabel();
110
111
112 if (ObjectUtils.isNull(subObjectCode)) {
113 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_EXISTENCE, label);
114 return false;
115 }
116
117 Integer universityFiscalYear = ((PaymentRequestDocument) getDocument()).getPostingYearPriorOrCurrent();
118 SubObjectCode subObjectCodeForValidation = (SpringContext.getBean(SubObjectCodeService.class).getByPrimaryId(universityFiscalYear, subObjectCode.getChartOfAccountsCode(), subObjectCode.getAccountNumber(), subObjectCode.getFinancialObjectCode(), subObjectCode.getFinancialSubObjectCode()));
119
120
121
122
123 if (!subObjectCodeForValidation.isActive()) {
124 if (((PaymentRequestDocument) getDocument()).getApplicationDocumentStatus().equals(
125 PaymentRequestStatuses.APPDOC_AWAITING_FISCAL_REVIEW)) {
126 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_INACTIVE, label);
127 return false;
128 }
129 }
130
131 return true;
132 }
133
134
135
136
137
138 @Override
139 public boolean isValidSubAccount(SubAccount subAccount, DataDictionary dataDictionary, String errorPropertyName,
140 String errorPropertyIdentifyingName) {
141 String label = getSubAccountLabel();
142
143
144 if (ObjectUtils.isNull(subAccount)) {
145 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_EXISTENCE, label);
146 return false;
147 }
148
149 if (!subAccount.isActive()) {
150 if (((PaymentRequestDocument) getDocument()).getApplicationDocumentStatus().equals(
151 PaymentRequestStatuses.APPDOC_AWAITING_FISCAL_REVIEW)) {
152 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_INACTIVE, label);
153 return false;
154 }
155
156 }
157 return true;
158 }
159
160 }