View Javadoc
1   /*
2    * Copyright 2008-2009 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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         /* if (ObjectUtils.isNull(document.getPurchaseOrderDocuments()) || document.getPurchaseOrderDocuments().size() < 1) {
50              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, OLEKeyConstants.ERROR_REQUIRED, PRQSDocumentsStrings.PURCHASE_ORDER_ID);
51              valid &= false;
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          /* if (StringUtils.isBlank(document.getInvoiceNumber())) {
58              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.INVOICE_NUMBER, OLEKeyConstants.ERROR_REQUIRED, PRQSDocumentsStrings.INVOICE_NUMBER);
59              valid &= false;
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 }