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.apache.commons.lang.StringUtils;
19  import org.kuali.ole.module.purap.PurapConstants;
20  import org.kuali.ole.module.purap.PurapKeyConstants;
21  import org.kuali.ole.module.purap.PurapPropertyConstants;
22  import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
23  import org.kuali.ole.module.purap.document.PaymentRequestDocument;
24  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
25  import org.kuali.ole.sys.OLEPropertyConstants;
26  import org.kuali.ole.sys.document.validation.GenericValidation;
27  import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
28  import org.kuali.rice.core.api.util.type.KualiDecimal;
29  import org.kuali.rice.krad.util.GlobalVariables;
30  import org.kuali.rice.krad.util.ObjectUtils;
31  
32  import java.util.List;
33  
34  public class PaymentRequestPurchaseOrderIdValidation extends GenericValidation {
35  
36      public boolean validate(AttributedDocumentEvent event) {
37          boolean valid = true;
38          PaymentRequestDocument document = (PaymentRequestDocument) event.getDocument();
39          GlobalVariables.getMessageMap().clearErrorPath();
40          GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
41  
42          Integer POID = document.getPurchaseOrderIdentifier();
43  
44          PurchaseOrderDocument purchaseOrderDocument = document.getPurchaseOrderDocument();
45          if (ObjectUtils.isNull(purchaseOrderDocument)) {
46              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_PURCHASE_ORDER_NOT_EXIST);
47              valid &= false;
48          } else if (purchaseOrderDocument.isPendingActionIndicator()) {
49              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_PURCHASE_PENDING_ACTION);
50              valid &= false;
51          } else if (!StringUtils.equals(purchaseOrderDocument.getApplicationDocumentStatus(), PurapConstants.PurchaseOrderStatuses.APPDOC_OPEN)) {
52              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_PURCHASE_ORDER_NOT_OPEN);
53              valid &= false;
54              
55          } else {
56              
57              
58          }
59          GlobalVariables.getMessageMap().clearErrorPath();
60          return valid;
61      }
62  
63      
64  
65  
66  
67  
68  
69  
70      protected boolean encumberedItemExistsForInvoicing(PurchaseOrderDocument document) {
71          boolean zeroDollar = true;
72          GlobalVariables.getMessageMap().clearErrorPath();
73          GlobalVariables.getMessageMap().addToErrorPath(OLEPropertyConstants.DOCUMENT);
74          for (PurchaseOrderItem poi : (List<PurchaseOrderItem>) document.getItems()) {
75              
76              if (poi.getItemType().isLineItemIndicator() && poi.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
77                  KualiDecimal encumberedQuantity = poi.getItemOutstandingEncumberedQuantity() == null ? KualiDecimal.ZERO : poi.getItemOutstandingEncumberedQuantity();
78                  if (encumberedQuantity.compareTo(KualiDecimal.ZERO) == 1) {
79                      zeroDollar = false;
80                      break;
81                  }
82              }
83              
84              else if (poi.getItemType().isAmountBasedGeneralLedgerIndicator() || poi.getItemType().isAdditionalChargeIndicator()) {
85                  KualiDecimal encumberedAmount = poi.getItemOutstandingEncumberedAmount() == null ? KualiDecimal.ZERO : poi.getItemOutstandingEncumberedAmount();
86                  if (encumberedAmount.compareTo(KualiDecimal.ZERO) == 1) {
87                      zeroDollar = false;
88                      break;
89                  }
90              }
91          }
92          if (zeroDollar) {
93              GlobalVariables.getMessageMap().putError(PurapPropertyConstants.PURCHASE_ORDER_IDENTIFIER, PurapKeyConstants.ERROR_NO_ITEMS_TO_INVOICE);
94          }
95          GlobalVariables.getMessageMap().clearErrorPath();
96          return !zeroDollar;
97      }
98  
99  }