View Javadoc
1   /*
2    * Copyright 2009 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.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       * @see org.kuali.ole.module.purap.service.impl.AccountsPayableAccountingLineRuleHelperServiceImpl#hasRequiredOverrides(org.kuali.ole.sys.businessobject.AccountingLine, java.lang.String)
43       *      For payment request we must throw an error after AP approval for C&G accounts that are expired more than 90 days.
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          //if account exists
53          if (ObjectUtils.isNotNull(account)) {
54              //after AP approval
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; // default to 90 days (approximately 3 months)
66  
67                  if (ObjectUtils.isNotNull(expirationExtensionDays) && expirationExtensionDays.trim().length() > 0) {
68  
69                      expirationExtensionDaysInt = new Integer(expirationExtensionDays).intValue();
70                  }
71  
72                  //if account is expired, c&g and past 90 days, add error
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              //account not valid, shouldn't happen but just in case
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          // make sure it exists
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          // check active status
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         // make sure it exists
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         // MSU Contribution OLEMI-8345 DTT-4169 OLECNTRB-960
122         // check active flag
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      * @see org.kuali.ole.sys.document.service.impl.AccountingLineRuleHelperServiceImpl#isValidSubAccount(org.kuali.ole.coa.businessobject.SubAccount, org.kuali.rice.krad.datadictionary.DataDictionary, java.lang.String)
137      */
138     @Override
139     public boolean isValidSubAccount(SubAccount subAccount, DataDictionary dataDictionary, String errorPropertyName,
140                                      String errorPropertyIdentifyingName) {
141         String label = getSubAccountLabel();
142 
143         // make sure it exists
144         if (ObjectUtils.isNull(subAccount)) {
145             GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_EXISTENCE, label);
146             return false;
147         }
148         // MSU Contribution OLEMI-8345 DTT-4023 OLECNTRB-960
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 }