View Javadoc
1   /*
2    * Copyright 2011 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.select.document.validation.impl;
17  
18  
19  import org.kuali.ole.module.purap.PurapConstants;
20  import org.kuali.ole.select.OleSelectConstant;
21  import org.kuali.ole.select.businessobject.OleRequisitionItem;
22  import org.kuali.ole.select.constants.OleSelectPropertyConstants;
23  import org.kuali.ole.sys.document.validation.impl.AccountingRuleEngineRuleBase;
24  import org.kuali.rice.krad.document.Document;
25  import org.kuali.rice.krad.util.GlobalVariables;
26  
27  public class OleRequisitionRuleBase extends AccountingRuleEngineRuleBase implements OleRequisitionRule {
28      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleRequisitionRuleBase.class);
29  
30      /**
31       * Constructs a OleRequisitionRule.java
32       */
33      public OleRequisitionRuleBase() {
34          super();
35      }
36  
37  
38      public boolean processCustomAddDiscountBusinessRules(Document document, OleRequisitionItem reqItem) {
39          boolean result = true;
40          LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules OleRequisitionItem---------->");
41          if (reqItem.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
42              LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules '%' for  OleRequisitionItem---------->");
43              int inDecimalPoint = String.valueOf(reqItem.getItemDiscount()).indexOf(".");
44              if (inDecimalPoint != -1) {
45                  if (String.valueOf(reqItem.getItemDiscount()).substring(0, inDecimalPoint).length() > 2) {
46  
47                      GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
48                      LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for  OleRequisitionItem ---------->");
49                      result = false;
50                  } else if (reqItem.getItemDiscount().bigDecimalValue().scale() > 2) {
51                      GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT);
52                      LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DECIMAL_LIMIT for OleRequisitionItem ---------->");
53                      result = false;
54                  }
55  
56              } else {
57                  if (String.valueOf(reqItem.getItemDiscount()).length() > 2) {
58                      GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
59                      LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for  OleRequisitionItem----2------>");
60                      result = false;
61                  }
62              }
63          } else {
64              LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules '#' for  OleRequisitionItem---------->");
65              int i = reqItem.getItemListPrice().compareTo(reqItem.getItemDiscount());
66              if (reqItem.getItemListPrice().compareTo(reqItem.getItemDiscount()) < 0) {
67  
68                  GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
69                  LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for  OleRequisitionItem---------->");
70                  result = false;
71              }
72          }
73          return result;
74      }
75  
76      public boolean processCustomForeignCurrencyRequisitionBusinessRules(Document document, OleRequisitionItem item) {
77          boolean result = true;
78          if (item.getItemForeignListPrice() == null) {
79              GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
80              LOG.debug("***Inside ForeignCurrencyRequisitionBusinessRules ItemForeignListPrice is null***");
81              result = false;
82          }
83          if (item.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
84              LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For requisition---------->");
85              int inDecimalPoint = String.valueOf(item.getItemForeignDiscount()).indexOf(".");
86              if (inDecimalPoint != -1) {
87                  if (String.valueOf(item.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
88  
89                      GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
90                      LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For requisition ---------->");
91                      result = false;
92                  } else if (item.getItemForeignDiscount().bigDecimalValue().scale() > 2) {
93                      GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT);
94                      LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For requisition ---------->");
95                      result = false;
96                  }
97  
98              } else {
99                  if (String.valueOf(item.getItemForeignDiscount()).length() > 2) {
100                     GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
101                     LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For requisition ----2------>");
102                     result = false;
103                 }
104             }
105         } else {
106             LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '#' For requisition ---------->");
107             int inDecimalPoint = String.valueOf(item.getItemForeignDiscount()).indexOf(".");
108             if (inDecimalPoint != -1) {
109                 if (String.valueOf(item.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
110 
111                     GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
112                     LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For requisition ---------->");
113                     result = false;
114                 } else if (item.getItemForeignDiscount().bigDecimalValue().scale() > 2) {
115                     GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT);
116                     LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For requisition ---------->");
117                     result = false;
118                 }
119 
120             } else if (String.valueOf(item.getItemForeignDiscount()).length() > 2) {
121                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
122                 LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For requisition ----2------>");
123                 result = false;
124             }
125             if (item.getItemForeignListPrice().compareTo(item.getItemForeignDiscount()) < 0) {
126 
127                 GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
128                 LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for  OleRequisitionItem---------->");
129                 result = false;
130             }
131         }
132 
133         return result;
134     }
135 
136 
137 }