1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document.validation.impl;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.select.OleSelectConstant;
21 import org.kuali.ole.select.businessobject.OlePaymentRequestItem;
22 import org.kuali.ole.select.businessobject.OleSufficientFundCheck;
23 import org.kuali.ole.select.constants.OleSelectPropertyConstants;
24 import org.kuali.ole.select.document.OlePaymentRequestDocument;
25 import org.kuali.ole.select.document.service.OlePaymentRequestFundCheckService;
26 import org.kuali.ole.sys.OLEConstants;
27 import org.kuali.ole.sys.OLEPropertyConstants;
28 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
29 import org.kuali.ole.sys.context.SpringContext;
30 import org.kuali.ole.sys.document.validation.GenericValidation;
31 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
32 import org.kuali.rice.core.api.util.RiceKeyConstants;
33 import org.kuali.rice.core.api.util.type.KualiDecimal;
34 import org.kuali.rice.core.api.util.type.KualiInteger;
35 import org.kuali.rice.krad.service.BusinessObjectService;
36 import org.kuali.rice.krad.util.GlobalVariables;
37
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 public class OlePaymentRequestItemValidation extends GenericValidation {
43
44 private BusinessObjectService businessObjectService;
45
46 @Override
47 public boolean validate(AttributedDocumentEvent event) {
48 boolean valid = true;
49 boolean isUnordered = false;
50 boolean orderedWithQty = true;
51 int count = 0;
52 OlePaymentRequestDocument document = (OlePaymentRequestDocument) event.getDocument();
53 if ((document.getPaymentMethod() != null) && (document.getPaymentMethod().getPaymentMethodId() != null)) {
54 document.setPaymentMethodId(document.getPaymentMethod().getPaymentMethodId());
55 }
56 List<OlePaymentRequestItem> items = document.getItems();
57 for (OlePaymentRequestItem item : items) {
58 count += 1;
59 if (item.getItemTypeCode().equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
60 isUnordered = true;
61 if (StringUtils.equalsIgnoreCase(item.getItemTypeCode(), PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) {
62 if (item.getItemQuantity() == null || item.getItemQuantity().isLessEqual(KualiDecimal.ZERO)) {
63 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_ITEM_QUANTITY_REQUIRED, "Item " + count);
64 valid = false;
65 }
66 }
67 }
68 if (item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
69 if (StringUtils.equalsIgnoreCase(item.getItemTypeCode(), PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE) || StringUtils.equalsIgnoreCase(item.getItemTypeCode(), PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE)) {
70 if (item.getItemDescription() == null || item.getItemDescription().trim().length() <= 0) {
71 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, "Item " + count);
72 valid = false;
73 }
74 }
75 if (item.getItemQuantity() != null && item.getItemQuantity().isGreaterThan(KualiDecimal.ZERO)) {
76 if (item.getItemNoOfParts() == null || (item.getItemNoOfParts()).isLessEqual(KualiInteger.ZERO)) {
77 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_NO_OF_PARTS_REQUIRED, "Item " + count);
78 valid = false;
79 }
80 }
81 }
82 }
83 if (!isUnordered) {
84 for (OlePaymentRequestItem item : items) {
85 if (item.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
86 if (item.getItemQuantity() == null || item.getItemQuantity().isLessEqual(KualiDecimal.ZERO)) {
87 orderedWithQty = false;
88 } else {
89 orderedWithQty = true;
90 }
91 }
92 if (orderedWithQty) {
93 break;
94 }
95 }
96 }
97 if (!orderedWithQty) {
98 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_ATLEAST_ONE_ITEM_QTY_REQUIRED);
99 valid = false;
100 }
101
102
103 List<SourceAccountingLine> sourceAccountingLineList = document.getSourceAccountingLines();
104 for (SourceAccountingLine accLine : sourceAccountingLineList) {
105 Map searchMap = new HashMap();
106 Map<String, Object> key = new HashMap<String, Object>();
107 String chartCode = accLine.getChartOfAccountsCode();
108 String accNo = accLine.getAccountNumber();
109 String objectCd = accLine.getFinancialObjectCode();
110 key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode);
111 key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo);
112 String option = null;
113 OleSufficientFundCheck account = getBusinessObjectService().findByPrimaryKey(OleSufficientFundCheck.class,
114 key);
115 if (account != null) {
116 option = account.getNotificationOption();
117 if (option != null) {
118 if (option.equals(OLEPropertyConstants.BLOCK_USE)) {
119 boolean fundCheck = SpringContext.getBean(OlePaymentRequestFundCheckService.class)
120 .hasSufficientFundCheckRequired(accLine);
121 if (fundCheck) {
122 GlobalVariables.getMessageMap().putError(OLEConstants.ERROR_MSG_FOR_INSUFF_FUND,
123 RiceKeyConstants.ERROR_CUSTOM,
124 OLEConstants.INSUFF_FUND + accLine.getAccountNumber());
125 valid = false;
126 }
127 } else if (option.equals(OLEPropertyConstants.WARNING_MSG)) {
128 boolean fundcheckRequired = SpringContext.getBean(OlePaymentRequestFundCheckService.class)
129 .hasSufficientFundCheckRequired(accLine);
130 if (fundcheckRequired) {
131 GlobalVariables.getMessageMap().putWarning(PurapConstants.DETAIL_TAB_ERRORS,
132 OleSelectPropertyConstants.INSUFF_FUND,
133 new String[]{accLine.getAccountNumber()});
134 }
135 }
136 }
137 }
138 }
139 return valid;
140
141 }
142
143
144 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
145 this.businessObjectService = businessObjectService;
146 }
147
148 public BusinessObjectService getBusinessObjectService() {
149 if (businessObjectService == null) {
150 businessObjectService = SpringContext.getBean(BusinessObjectService.class);
151 }
152 return businessObjectService;
153 }
154
155 }