1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.fp.document.validation.impl;
17
18 import static org.kuali.ole.fp.document.validation.impl.CreditCardReceiptDocumentRuleConstants.CREDIT_CARD_RECEIPT_PREFIX;
19 import static org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.ERROR_PATH.DOCUMENT_ERROR_PREFIX;
20
21 import org.kuali.ole.fp.businessobject.CreditCardDetail;
22 import org.kuali.ole.fp.document.CreditCardReceiptDocument;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.ole.sys.OLEKeyConstants.CashReceipt;
25 import org.kuali.ole.sys.OLEPropertyConstants;
26 import org.kuali.ole.sys.context.SpringContext;
27 import org.kuali.rice.core.api.util.type.KualiDecimal;
28 import org.kuali.rice.kns.service.DataDictionaryService;
29 import org.kuali.rice.kns.service.DictionaryValidationService;
30 import org.kuali.rice.krad.util.GlobalVariables;
31 import org.kuali.rice.krad.util.MessageMap;
32
33
34
35
36 public class CreditCardReceiptDocumentRuleUtil {
37
38
39
40
41
42
43
44
45 public static boolean validateCreditCardReceipt(CreditCardDetail creditCardReceipt) {
46 MessageMap errorMap = GlobalVariables.getMessageMap();
47 int originalErrorCount = errorMap.getErrorCount();
48
49
50 SpringContext.getBean(DictionaryValidationService.class).validateBusinessObject(creditCardReceipt);
51 boolean isValid = (errorMap.getErrorCount() == originalErrorCount);
52
53
54 if (isValid) {
55 isValid = !creditCardReceipt.getCreditCardAdvanceDepositAmount().isZero();
56 if (!isValid) {
57 String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(CreditCardDetail.class, OLEPropertyConstants.CREDIT_CARD_ADVANCE_DEPOSIT_AMOUNT);
58 errorMap.putError(OLEPropertyConstants.CREDIT_CARD_ADVANCE_DEPOSIT_AMOUNT, OLEKeyConstants.ERROR_ZERO_AMOUNT, label);
59 }
60 }
61
62 if (isValid) {
63 isValid = SpringContext.getBean(DictionaryValidationService.class).validateReferenceExists(creditCardReceipt, OLEPropertyConstants.CREDIT_CARD_TYPE);
64 if (!isValid) {
65 String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(CreditCardDetail.class, OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_TYPE_CODE);
66 errorMap.putError(OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_TYPE_CODE, OLEKeyConstants.ERROR_EXISTENCE, label);
67 }
68 }
69 if (isValid) {
70 isValid = SpringContext.getBean(DictionaryValidationService.class).validateReferenceExists(creditCardReceipt, OLEPropertyConstants.CREDIT_CARD_VENDOR);
71 if (!isValid) {
72 String label = SpringContext.getBean(DataDictionaryService.class).getAttributeLabel(CreditCardDetail.class, OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_VENDOR_NUMBER);
73 errorMap.putError(OLEPropertyConstants.FINANCIAL_DOCUMENT_CREDIT_CARD_VENDOR_NUMBER, OLEKeyConstants.ERROR_EXISTENCE, label);
74 }
75 }
76
77 return isValid;
78 }
79
80
81
82
83
84
85
86
87 public static boolean areCashTotalsInvalid(CreditCardReceiptDocument ccrDocument) {
88 String documentEntryName = ccrDocument.getDocumentHeader().getWorkflowDocument().getDocumentTypeName();
89
90 boolean isInvalid = isTotalInvalid(ccrDocument, ccrDocument.getTotalDollarAmount(), documentEntryName, OLEPropertyConstants.CREDIT_CARD_RECEIPTS_TOTAL);
91
92 return isInvalid;
93 }
94
95
96
97
98
99
100
101
102
103
104 private static boolean isTotalInvalid(CreditCardReceiptDocument ccrDocument, KualiDecimal totalAmount, String documentEntryName, String propertyName) {
105 boolean isInvalid = false;
106 String errorProperty = CREDIT_CARD_RECEIPT_PREFIX + propertyName;
107
108
109 DataDictionaryService dds = SpringContext.getBean(DataDictionaryService.class);
110 String errorLabel = dds.getAttributeLabel(documentEntryName, propertyName);
111 if ((totalAmount == null) || totalAmount.isZero()) {
112 GlobalVariables.getMessageMap().putError(errorProperty, CashReceipt.ERROR_ZERO_TOTAL, errorLabel);
113
114 isInvalid = true;
115 }
116 else {
117 int precount = GlobalVariables.getMessageMap().getNumberOfPropertiesWithErrors();
118
119 DictionaryValidationService dvs = SpringContext.getBean(DictionaryValidationService.class);
120 dvs.validateDocumentAttribute(ccrDocument, propertyName, DOCUMENT_ERROR_PREFIX);
121
122
123 GlobalVariables.getMessageMap().replaceError(errorProperty, OLEKeyConstants.ERROR_MAX_LENGTH, CashReceipt.ERROR_EXCESSIVE_TOTAL, errorLabel);
124
125 int postcount = GlobalVariables.getMessageMap().getNumberOfPropertiesWithErrors();
126 isInvalid = (postcount > precount);
127 }
128
129 return isInvalid;
130 }
131 }