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.coa.businessobject.Account;
19 import org.kuali.ole.module.purap.PurapConstants;
20 import org.kuali.ole.module.purap.PurapConstants.PRQSDocumentsStrings;
21 import org.kuali.ole.module.purap.PurapPropertyConstants;
22 import org.kuali.ole.select.OleSelectConstant;
23 import org.kuali.ole.select.businessobject.OleInvoiceItem;
24 import org.kuali.ole.select.document.OleInvoiceDocument;
25 import org.kuali.ole.select.document.service.OleInvoiceService;
26 import org.kuali.ole.sys.OLEConstants;
27 import org.kuali.ole.sys.OLEKeyConstants;
28 import org.kuali.ole.sys.OLEPropertyConstants;
29 import org.kuali.ole.sys.businessobject.SourceAccountingLine;
30 import org.kuali.ole.sys.context.SpringContext;
31 import org.kuali.ole.sys.document.validation.GenericValidation;
32 import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
33 import org.kuali.rice.krad.service.KRADServiceLocator;
34 import org.kuali.rice.krad.util.GlobalVariables;
35 import org.kuali.rice.krad.util.ObjectUtils;
36
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40
41 public class InvoiceValidation extends GenericValidation {
42
43 public boolean validate(AttributedDocumentEvent event) {
44 boolean valid = true;
45 OleInvoiceDocument document = (OleInvoiceDocument) event.getDocument();
46 GlobalVariables.getMessageMap().clearErrorPath();
47 GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
48
49
50
51
52
53 if (ObjectUtils.isNull(document.getInvoiceDate())) {
54 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.INVOICE_DATE, OLEKeyConstants.ERROR_REQUIRED, PRQSDocumentsStrings.INVOICE_DATE);
55 valid &= false;
56 }
57
58
59
60
61 if (ObjectUtils.isNull(document.getVendorInvoiceAmount())) {
62 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.VENDOR_INVOICE_AMOUNT, OLEKeyConstants.ERROR_REQUIRED, PRQSDocumentsStrings.VENDOR_INVOICE_AMOUNT);
63 valid &= false;
64 }
65
66 if(document.getPaymentMethodIdentifier() != null) {
67 String paymentType = SpringContext.getBean(OleInvoiceService.class).getPaymentMethodType(document.getPaymentMethodIdentifier());
68 if (paymentType.equals(OLEConstants.DEPOSIT)) {
69 for (OleInvoiceItem item : (List<OleInvoiceItem>) document.getItems()) {
70 if (item.getItemTypeCode().equals("ITEM")) {
71 if (item.getSourceAccountingLineList().size() <= 0) {
72 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.OFFSET_ACCT_LINE, OLEKeyConstants.ERROR_REQUIRED, PurapConstants.PRQSDocumentsStrings.OFFSET_ACCT_LINE);
73 valid &= false;
74 }
75 if (item.getSourceAccountingLineList().size() > 0) {
76 for (SourceAccountingLine accountingLine : item.getSourceAccountingLineList()) {
77 String accNo = accountingLine.getAccountNumber();
78 Integer vendorIdentifier = document.getVendorHeaderGeneratedIdentifier();
79 if ((accNo != null && accNo != "") && (vendorIdentifier != null)) {
80 Map accMap = new HashMap();
81 accMap.put("accountNumber", accNo);
82 accMap.put("subFundGroupCode", "CLRREV");
83 accMap.put("vendorHeaderGeneratedIdentifier", vendorIdentifier);
84 List<Account> account = (List<Account>) KRADServiceLocator.getBusinessObjectService().findMatching(Account.class, accMap);
85 if (account.size() <= 0) {
86 GlobalVariables.getMessageMap().putError(PurapPropertyConstants.OFFSET_ACCT_LINE, OleSelectConstant.ERROR_INVALID_ACC_NO, accNo);
87 valid &= false;
88 }
89
90 }
91
92 }
93
94
95 }
96
97 }
98 }
99 }
100 }
101
102 GlobalVariables.getMessageMap().clearErrorPath();
103 return valid;
104 }
105
106 }