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.web.struts; 017 018import org.kuali.ole.module.purap.businessobject.PurApItem; 019import org.kuali.ole.module.purap.document.web.struts.RequisitionForm; 020import org.kuali.ole.select.OleSelectConstant; 021import org.kuali.ole.select.businessobject.OleRequisitionCopies; 022import org.kuali.ole.select.businessobject.OleRequisitionItem; 023import org.kuali.ole.select.businessobject.OleRequisitionPaymentHistory; 024import org.kuali.ole.select.document.OleRequisitionDocument; 025import org.kuali.ole.vnd.businessobject.VendorCustomerNumber; 026import org.kuali.rice.core.api.util.type.KualiDecimal; 027 028import java.math.BigDecimal; 029import java.util.List; 030 031public class OleRequisitionForm extends RequisitionForm { 032 033 private OleRequisitionCopies newOleCopies = new OleRequisitionCopies(); 034 private OleRequisitionPaymentHistory newOleRequisitionPaymentHistory = new OleRequisitionPaymentHistory(); 035 private boolean currencyTypeIndicator = true; 036 /** 037 * @see org.kuali.ole.module.purap.document.web.struts.PurchasingFormBase#setupNewPurchasingItemLine() 038 */ 039 @Override 040 public PurApItem setupNewPurchasingItemLine() { 041 return new OleRequisitionItem(); 042 } 043 044 @Override 045 public PurApItem getAndResetNewPurchasingItemLine() { 046 047 PurApItem aPurchasingItemLine = getNewPurchasingItemLine(); 048 OleRequisitionItem reqItem = (OleRequisitionItem) aPurchasingItemLine; 049 setNewPurchasingItemLine(setupNewPurchasingItemLine()); 050 OleRequisitionItem reqItems = (OleRequisitionItem) this.getNewPurchasingItemLine(); 051 052 OleRequisitionDocument document = (OleRequisitionDocument) this.getDocument(); 053 if (document.getVendorDetail() != null) { 054 055 if (document.getVendorDetail().getCurrencyType()!=null){ 056 if(document.getVendorDetail().getCurrencyType().getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME )){ 057 currencyTypeIndicator=true; 058 } 059 else{ 060 currencyTypeIndicator=false; 061 } 062 } 063 String customerNumber = document.getVendorCustomerNumber(); 064 List<VendorCustomerNumber> vendorCustomerNumbers = document.getVendorDetail().getVendorCustomerNumbers(); 065 if (customerNumber != null && vendorCustomerNumbers != null) { 066 for (VendorCustomerNumber vendorCustomerNumber : vendorCustomerNumbers) { 067 if (vendorCustomerNumber.getVendorCustomerNumber().equalsIgnoreCase(customerNumber)) { 068 if (!currencyTypeIndicator) { 069 if (customerNumber != null) { 070 reqItems.setItemForeignDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0))); 071 reqItems.setItemForeignDiscountType(vendorCustomerNumber.getVendorDiscountType()); 072 } 073 074 reqItems.setItemExchangeRate(reqItem.getItemExchangeRate()); 075 setNewPurchasingItemLine(reqItems); 076 } else { 077 if (customerNumber != null) { 078 reqItems.setItemDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0))); 079 reqItems.setItemDiscountType(vendorCustomerNumber.getVendorDiscountType()); 080 } 081 setNewPurchasingItemLine(reqItems); 082 } 083 } 084 } 085 } else { 086 reqItems.setItemForeignDiscount(new KualiDecimal(0.0)); 087 reqItems.setItemDiscount(new KualiDecimal(0)); 088 089 } 090 } 091 return aPurchasingItemLine; 092 093 } 094 095 /** 096 * Gets the newOleCopies attribute. 097 * 098 * @return Returns the newOleCopies. 099 */ 100 public OleRequisitionCopies getNewOleCopies() { 101 return newOleCopies; 102 } 103 104 /** 105 * Sets the newOleCopies attribute value. 106 * 107 * @param newOleCopies The newOleCopies to set. 108 */ 109 public void setNewOleCopies(OleRequisitionCopies newOleCopies) { 110 this.newOleCopies = newOleCopies; 111 } 112 113 /** 114 * Gets the newOleRequisitionPaymentHistory attribute. 115 * 116 * @return Returns the newOleRequisitionPaymentHistory. 117 */ 118 public OleRequisitionPaymentHistory getNewOleRequisitionPaymentHistory() { 119 return newOleRequisitionPaymentHistory; 120 } 121 122 /** 123 * Sets the newOleRequisitionPaymentHistory attribute value. 124 * 125 * @param newOleRequisitionPaymentHistory 126 * The newOleRequisitionPaymentHistory to set. 127 */ 128 public void setNewOleRequisitionPaymentHistory(OleRequisitionPaymentHistory newOleRequisitionPaymentHistory) { 129 this.newOleRequisitionPaymentHistory = newOleRequisitionPaymentHistory; 130 } 131 132}