1 package org.kuali.ole.module.purap.service.impl;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.coa.businessobject.*;
5 import org.kuali.ole.module.purap.businessobject.InvoiceAccount;
6 import org.kuali.ole.select.OleSelectConstant;
7 import org.kuali.ole.select.businessobject.OlePurchaseOrderAccount;
8 import org.kuali.ole.sys.OLEConstants;
9 import org.kuali.ole.sys.OLEKeyConstants;
10 import org.kuali.ole.sys.businessobject.AccountingLine;
11 import org.kuali.ole.sys.businessobject.OriginationCode;
12 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
13 import org.kuali.ole.sys.context.SpringContext;
14 import org.kuali.rice.core.api.config.property.ConfigurationService;
15 import org.kuali.rice.kew.doctype.bo.DocumentTypeEBO;
16 import org.kuali.rice.krad.datadictionary.DataDictionary;
17 import org.kuali.rice.krad.util.GlobalVariables;
18 import org.kuali.rice.krad.util.ObjectUtils;
19
20
21
22
23
24
25
26
27 public class OLEPaymentRequestAccountingLineRuleHelperServiceImpl extends PaymentRequestAccountingLineRuleHelperServiceImpl {
28 @Override
29 public boolean validateAccountingLine(AccountingLine accountingLine) {
30 boolean isInvoice = false;
31 if (accountingLine instanceof InvoiceAccount || accountingLine instanceof OlePurchaseOrderAccount) {
32 isInvoice = true;
33 }
34 if (accountingLine == null) {
35 throw new IllegalStateException(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.ERROR_DOCUMENT_NULL_ACCOUNTING_LINE));
36 }
37 DataDictionary dd = getDataDictionaryService().getDataDictionary();
38 org.kuali.rice.krad.datadictionary.BusinessObjectEntry accountingLineEntry = dd.getBusinessObjectEntry(SourceAccountingLine.class.getName());
39 String accountIdentifyingPropertyName = getAccountIdentifyingPropertyName(accountingLine);
40 accountingLine.refreshReferenceObject(OLEConstants.CHART_PROPERTY_NAME);
41 Chart chart = accountingLine.getChart();
42 accountingLine.refreshReferenceObject(OLEConstants.ACCOUNT_PROPERTY_NAME);
43 String accountNumber = accountingLine.getAccountNumber();
44 Account account = accountingLine.getAccount();
45 accountingLine.refreshReferenceObject(OLEConstants.OrderQueue.ORDQ_OBJ_CODE);
46 ObjectCode objectCode = accountingLine.getObjectCode();
47 boolean valid = true;
48 valid &= isValidChart(accountIdentifyingPropertyName, chart, dd, isInvoice);
49 valid &= isValidAccount(accountIdentifyingPropertyName, account, accountNumber, dd, isInvoice);
50 if (StringUtils.isNotBlank(accountingLine.getSubAccountNumber())) {
51 accountingLine.refreshReferenceObject(OLEConstants.SUB_ACCOUNT_PROPERTY_NAME);
52 SubAccount subAccount = accountingLine.getSubAccount();
53 valid &= isValidSubAccount(accountIdentifyingPropertyName, subAccount, dd);
54 }
55 valid &= isValidObjectCode(accountIdentifyingPropertyName, objectCode, dd);
56 if (StringUtils.isNotBlank(accountingLine.getFinancialSubObjectCode())) {
57 accountingLine.refreshReferenceObject(OLEConstants.SUB_OBJECT_CODE_PROPERTY_NAME);
58 SubObjectCode subObjectCode = accountingLine.getSubObjectCode();
59 valid &= isValidSubObjectCode(accountIdentifyingPropertyName, subObjectCode, dd);
60 }
61 if (StringUtils.isNotBlank(accountingLine.getProjectCode())) {
62 accountingLine.refreshReferenceObject(OLEConstants.PROJECT_PROPERTY_NAME);
63 ProjectCode projectCode = accountingLine.getProject();
64 valid &= isValidProjectCode(accountIdentifyingPropertyName, projectCode, dd);
65 }
66 if (StringUtils.isNotBlank(accountingLine.getReferenceOriginCode())) {
67 accountingLine.refreshReferenceObject(OLEConstants.REF_ORIGIN_PROPERTY_NAME);
68 OriginationCode referenceOrigin = accountingLine.getReferenceOrigin();
69 valid &= isValidReferenceOriginCode(accountIdentifyingPropertyName, referenceOrigin, accountingLineEntry);
70 }
71 if (StringUtils.isNotBlank(accountingLine.getReferenceTypeCode())) {
72 DocumentTypeEBO referenceType = accountingLine.getReferenceFinancialSystemDocumentTypeCode();
73 valid &= isValidReferenceTypeCode(accountingLine.getReferenceTypeCode(), referenceType, accountingLineEntry, accountIdentifyingPropertyName);
74 }
75 valid &= hasRequiredOverrides(accountingLine, accountingLine.getOverrideCode());
76 return valid;
77 }
78
79 private boolean isValidAccount(String accountIdentifyingPropertyName, Account account, String accountNumber, DataDictionary dataDictionary, boolean isInvoice) {
80 return isValidAccount(account, accountNumber, dataDictionary, OLEConstants.ACCOUNT_NUMBER_PROPERTY_NAME, accountIdentifyingPropertyName, isInvoice);
81 }
82
83 private boolean isValidAccount(Account account, String accountNumber, DataDictionary dataDictionary, String errorPropertyName, String accountIdentifyingPropertyName, boolean isInvoice) {
84 String label = getAccountLabel();
85 if (ObjectUtils.isNull(account)) {
86 if (isInvoice) {
87 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLEInvoiceView_ProcessItems_AccountingLines, OLEKeyConstants.ERROR_EXISTING_WITH_IDENTIFYING_ACCOUNTING_LINE, label, accountNumber);
88 } else {
89 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_EXISTING_WITH_IDENTIFYING_ACCOUNTING_LINE, label, accountNumber);
90 }
91 return false;
92 }
93 if (!account.isActive()) {
94 if (isInvoice) {
95 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLEInvoiceView_ProcessItems_AccountingLines, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNT_CLOSED_WITH_IDENTIFYING_ACCOUNTING_LINE, label);
96 } else {
97 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNT_CLOSED_WITH_IDENTIFYING_ACCOUNTING_LINE, label);
98 }
99 return false;
100 }
101 if (ObjectUtils.isNotNull(account.getAccountRestrictedStatusCode())) {
102 if (account.getAccountRestrictedStatusCode().equalsIgnoreCase(OleSelectConstant.ACCOUNT_TEMPORARY_RESTRICTED_CODE)) {
103 if (isInvoice) {
104 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLEInvoiceView_ProcessItems_AccountingLines, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNT_IS_TEMPORARY_RESTRICTED, label);
105 } else {
106 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNT_IS_TEMPORARY_RESTRICTED, label);
107 }
108 return false;
109 } else if (account.getAccountRestrictedStatusCode().equalsIgnoreCase(OleSelectConstant.ACCOUNT_RESTRICTED_CODE)) {
110 if (isInvoice) {
111 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLEInvoiceView_ProcessItems_AccountingLines, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNT_IS_RESTRICTED, accountNumber);
112 } else {
113 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_DOCUMENT_ACCOUNT_IS_RESTRICTED, accountNumber);
114 }
115 return false;
116 }
117 }
118 return true;
119 }
120
121 public boolean isValidChart(String accountIdentifyingPropertyName, Chart chart, DataDictionary dataDictionary, boolean isInvoice) {
122 return isValidChart(chart, dataDictionary, OLEConstants.CHART_OF_ACCOUNTS_CODE_PROPERTY_NAME, accountIdentifyingPropertyName, isInvoice);
123 }
124
125 public boolean isValidChart(Chart chart, DataDictionary dataDictionary, String errorPropertyName, String accountIdentifyingPropertyName, boolean isInvoice) {
126 String label = getChartLabel();
127 if (ObjectUtils.isNull(chart)) {
128 if (isInvoice) {
129 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLEInvoiceView_ProcessItems_AccountingLines, OLEKeyConstants.ERROR_EXISTING_WITH_IDENTIFYING_ACCOUNTING_LINE, label);
130 } else {
131 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_EXISTING_WITH_IDENTIFYING_ACCOUNTING_LINE, label);
132 }
133 return false;
134 }
135 if (!chart.isActive()) {
136 if (isInvoice) {
137 GlobalVariables.getMessageMap().putErrorForSectionId(OLEConstants.OLEInvoiceView_ProcessItems_AccountingLines, OLEKeyConstants.ERROR_INACTIVE_WITH_IDENTIFYING_ACCOUNTING_LINE, label);
138 } else {
139 GlobalVariables.getMessageMap().putError(errorPropertyName, OLEKeyConstants.ERROR_INACTIVE_WITH_IDENTIFYING_ACCOUNTING_LINE, label);
140 }
141 return false;
142 }
143 return true;
144 }
145
146 }