1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.validation.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.PurapConstants.PaymentRequestStatuses;
21 import org.kuali.ole.module.purap.PurapKeyConstants;
22 import org.kuali.ole.module.purap.PurapParameterConstants;
23 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
24 import org.kuali.ole.module.purap.businessobject.PurApItem;
25 import org.kuali.ole.module.purap.document.PaymentRequestDocument;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.ole.sys.document.AccountingDocument;
28 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
29 import org.kuali.ole.sys.service.impl.OleParameterConstants;
30 import org.kuali.rice.coreservice.framework.parameter.ParameterService;
31 import org.kuali.rice.krad.service.DataDictionaryService;
32 import org.kuali.rice.krad.util.GlobalVariables;
33 import org.kuali.rice.krad.util.ObjectUtils;
34
35 public class PaymentRequestNonZeroAccountingLineAmountValidation extends PurchasingAccountsPayableAccountingLineAccessibleValidation {
36
37 private PurApItem itemForValidation;
38 private ParameterService parameterService;
39
40 public boolean validate(AttributedDocumentEvent event) {
41 boolean valid = true;
42 String status = ((PaymentRequestDocument) event.getDocument()).getApplicationDocumentStatus();
43
44 AccountingDocument accountingDocument = (AccountingDocument) event.getDocument();
45 this.setAccountingDocumentForValidation(accountingDocument);
46 this.setDataDictionaryService(SpringContext.getBean(DataDictionaryService.class));
47
48
49 if (StringUtils.equals(PaymentRequestStatuses.APPDOC_AWAITING_FISCAL_REVIEW, status)) {
50 for (PurApAccountingLine acct : itemForValidation.getSourceAccountingLines()) {
51 this.setAccountingLineForValidation(acct);
52 final boolean lineIsAccessible = lookupAccountingLineAuthorizer().hasEditPermissionOnAccountingLine(accountingDocument, acct, getAccountingLineCollectionProperty(), GlobalVariables.getUserSession().getPerson(), true);
53
54 if (lineIsAccessible) {
55
56
57 if (ObjectUtils.isNull(acct.getAmount())) {
58 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_ACCOUNTING_AMOUNT_INVALID, itemForValidation.getItemIdentifierString());
59 valid &= false;
60 } else {
61 if (acct.getAmount().isZero()) {
62 if (!canApproveAccountingLinesWithZeroAmount()) {
63 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_ACCOUNTING_AMOUNT_INVALID, itemForValidation.getItemIdentifierString());
64 valid &= false;
65 }
66 }
67 }
68 }
69 }
70 }
71
72 return valid;
73 }
74
75
76
77
78
79
80
81
82 public boolean canApproveAccountingLinesWithZeroAmount() {
83 boolean canApproveLine = false;
84
85
86 String approveZeroAmountLine = SpringContext.getBean(ParameterService.class).getParameterValueAsString(OleParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.APPROVE_ACCOUNTING_LINES_WITH_ZERO_DOLLAR_AMOUNT_IND);
87
88 if ("Y".equalsIgnoreCase(approveZeroAmountLine)) {
89 return true;
90 }
91
92 return canApproveLine;
93 }
94
95 public PurApItem getItemForValidation() {
96 return itemForValidation;
97 }
98
99 public void setItemForValidation(PurApItem itemForValidation) {
100 this.itemForValidation = itemForValidation;
101 }
102
103
104
105
106
107
108
109 public ParameterService getParameterService() {
110 return parameterService;
111 }
112
113
114
115
116
117
118 public void setParameterService(ParameterService parameterService) {
119 this.parameterService = parameterService;
120 }
121 }