001/*
002 * Copyright 2011 The Kuali Foundation.
003 * 
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.opensource.org/licenses/ecl2.php
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.ole.select.document.validation.impl;
017
018
019import org.kuali.ole.module.purap.PurapConstants;
020import org.kuali.ole.select.OleSelectConstant;
021import org.kuali.ole.select.businessobject.OleRequisitionItem;
022import org.kuali.ole.select.constants.OleSelectPropertyConstants;
023import org.kuali.ole.sys.document.validation.impl.AccountingRuleEngineRuleBase;
024import org.kuali.rice.krad.document.Document;
025import org.kuali.rice.krad.util.GlobalVariables;
026
027public class OleRequisitionRuleBase extends AccountingRuleEngineRuleBase implements OleRequisitionRule {
028    protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleRequisitionRuleBase.class);
029
030    /**
031     * Constructs a OleRequisitionRule.java
032     */
033    public OleRequisitionRuleBase() {
034        super();
035    }
036
037
038    public boolean processCustomAddDiscountBusinessRules(Document document, OleRequisitionItem reqItem) {
039        boolean result = true;
040        LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules OleRequisitionItem---------->");
041        if (reqItem.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
042            LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules '%' for  OleRequisitionItem---------->");
043            int inDecimalPoint = String.valueOf(reqItem.getItemDiscount()).indexOf(".");
044            if (inDecimalPoint != -1) {
045                if (String.valueOf(reqItem.getItemDiscount()).substring(0, inDecimalPoint).length() > 2) {
046
047                    GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
048                    LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for  OleRequisitionItem ---------->");
049                    result = false;
050                } else if (reqItem.getItemDiscount().bigDecimalValue().scale() > 2) {
051                    GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT);
052                    LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DECIMAL_LIMIT for OleRequisitionItem ---------->");
053                    result = false;
054                }
055
056            } else {
057                if (String.valueOf(reqItem.getItemDiscount()).length() > 2) {
058                    GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
059                    LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules PERCENTAGE_MAX_LIMIT for  OleRequisitionItem----2------>");
060                    result = false;
061                }
062            }
063        } else {
064            LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules '#' for  OleRequisitionItem---------->");
065            int i = reqItem.getItemListPrice().compareTo(reqItem.getItemDiscount());
066            if (reqItem.getItemListPrice().compareTo(reqItem.getItemDiscount()) < 0) {
067
068                GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DISCOUNT_LIMIT, new String[]{"Discount"});
069                LOG.debug("<------------------Inside processCustomAddDiscountBusinessRules MAX_DISCOUNT_LIMIT for  OleRequisitionItem---------->");
070                result = false;
071            }
072        }
073        return result;
074    }
075
076    public boolean processCustomForeignCurrencyRequisitionBusinessRules(Document document, OleRequisitionItem item) {
077        boolean result = true;
078        if (item.getItemForeignListPrice() == null) {
079            GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_ITEM_FOREIGN_LIST_PRICE, new String[]{"Foreign List Price"});
080            LOG.debug("***Inside ForeignCurrencyRequisitionBusinessRules ItemForeignListPrice is null***");
081            result = false;
082        }
083        if (item.getItemForeignDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
084            LOG.debug("<------------------Inside ForeignCurrencyBusinessRules '%' For requisition---------->");
085            int inDecimalPoint = String.valueOf(item.getItemForeignDiscount()).indexOf(".");
086            if (inDecimalPoint != -1) {
087                if (String.valueOf(item.getItemForeignDiscount()).substring(0, inDecimalPoint).length() > 2) {
088
089                    GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.PERCENTAGE_MAX_LIMIT, new String[]{"Discount"});
090                    LOG.debug("<------------------Inside ForeignCurrencyBusinessRules PERCENTAGE_MAX_LIMIT For requisition ---------->");
091                    result = false;
092                } else if (item.getItemForeignDiscount().bigDecimalValue().scale() > 2) {
093                    GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.MAX_DECIMAL_LIMIT);
094                    LOG.debug("<------------------Inside ForeignCurrencyBusinessRules MAX_DECIMAL_LIMIT For requisition ---------->");
095                    result = false;
096                }
097
098            } else {
099                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}