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.kuali.ole.module.purap.PurapConstants;
19 import org.kuali.ole.module.purap.PurapKeyConstants;
20 import org.kuali.ole.module.purap.businessobject.PaymentRequestItem;
21 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
22 import org.kuali.ole.select.businessobject.OlePaymentRequestItem;
23 import org.kuali.ole.sys.document.validation.GenericValidation;
24 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
25 import org.kuali.rice.core.api.util.type.KualiDecimal;
26 import org.kuali.rice.krad.util.GlobalVariables;
27
28 public class PaymentRequestAccountTotalValidation extends GenericValidation {
29
30 private PaymentRequestItem itemForValidation;
31
32
33
34
35 @Override
36 public boolean validate(AttributedDocumentEvent event) {
37 boolean valid = true;
38
39
40 KualiDecimal totalAmount = KualiDecimal.ZERO;
41 KualiDecimal desiredAmount =
42 (itemForValidation.getTotalAmount() == null) ? new KualiDecimal(0) : itemForValidation.getTotalAmount();
43
44 KualiDecimal prorateSurcharge = KualiDecimal.ZERO;
45 OlePaymentRequestItem preqItem = (OlePaymentRequestItem) itemForValidation;
46 if (preqItem.getItemType().isQuantityBasedGeneralLedgerIndicator() && preqItem.getExtendedPrice() != null && preqItem.getExtendedPrice().compareTo(KualiDecimal.ZERO) != 0) {
47 if (preqItem.getItemSurcharge() != null && preqItem.getItemTypeCode().equals("ITEM")) {
48 prorateSurcharge = new KualiDecimal(preqItem.getItemSurcharge()).multiply(preqItem.getItemQuantity());
49 }
50 desiredAmount = desiredAmount.subtract(prorateSurcharge);
51 }
52
53 for (PurApAccountingLine account : itemForValidation.getSourceAccountingLines()) {
54 if (account.getAmount() != null) {
55 totalAmount = totalAmount.add(account.getAmount());
56 } else {
57 totalAmount = totalAmount.add(KualiDecimal.ZERO);
58 }
59 }
60
61 if (desiredAmount.compareTo(totalAmount) != 0) {
62 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, PurapKeyConstants.ERROR_ITEM_ACCOUNTING_TOTAL_AMOUNT, itemForValidation.getItemIdentifierString(), desiredAmount.toString());
63 valid = false;
64 }
65
66
67 return valid;
68 }
69
70 public PaymentRequestItem getItemForValidation() {
71 return itemForValidation;
72 }
73
74 public void setItemForValidation(PaymentRequestItem itemForValidation) {
75 this.itemForValidation = itemForValidation;
76 }
77
78 }