001/*
002 * Copyright 2013 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 1.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/ecl1.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
018import org.kuali.ole.module.purap.PurapKeyConstants;
019import org.kuali.ole.module.purap.PurapPropertyConstants;
020import org.kuali.ole.select.businessobject.OleCreditMemoItem;
021import org.kuali.ole.sys.OLEPropertyConstants;
022import org.kuali.ole.sys.document.validation.GenericValidation;
023import org.kuali.ole.sys.document.validation.event.AttributedDocumentEvent;
024import org.kuali.rice.krad.util.GlobalVariables;
025
026public class OleVendorCreditMemoFlagLineItemTotalsValidation extends GenericValidation {
027
028    private OleCreditMemoItem itemForValidation;
029
030    @Override
031    public boolean validate(AttributedDocumentEvent event) {
032        if (itemForValidation.getItemSurcharge() == null) {
033            if (itemForValidation.getItemQuantity() != null && itemForValidation.getExtendedPrice() != null && itemForValidation.calculateExtendedPrice().compareTo(itemForValidation.getExtendedPrice()) != 0) {
034                String errorKey = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "[" + (itemForValidation.getItemLineNumber() - 1) + "]." + PurapPropertyConstants.EXTENDED_PRICE;
035                GlobalVariables.getMessageMap().putError(errorKey, PurapKeyConstants.ERROR_PAYMENT_REQUEST_ITEM_TOTAL_NOT_EQUAL);
036            }
037        }
038
039        return true;
040    }
041
042    public OleCreditMemoItem getItemForValidation() {
043        return itemForValidation;
044    }
045
046    public void setItemForValidation(OleCreditMemoItem itemForValidation) {
047        this.itemForValidation = itemForValidation;
048    }
049
050}