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.web.struts;
17  
18  import org.kuali.ole.module.purap.businessobject.PurApItem;
19  import org.kuali.ole.module.purap.document.web.struts.RequisitionForm;
20  import org.kuali.ole.select.OleSelectConstant;
21  import org.kuali.ole.select.businessobject.OleRequisitionCopies;
22  import org.kuali.ole.select.businessobject.OleRequisitionItem;
23  import org.kuali.ole.select.businessobject.OleRequisitionPaymentHistory;
24  import org.kuali.ole.select.document.OleRequisitionDocument;
25  import org.kuali.ole.vnd.businessobject.VendorCustomerNumber;
26  import org.kuali.rice.core.api.util.type.KualiDecimal;
27  
28  import java.math.BigDecimal;
29  import java.util.List;
30  
31  public class OleRequisitionForm extends RequisitionForm {
32  
33      private OleRequisitionCopies newOleCopies = new OleRequisitionCopies();
34      private OleRequisitionPaymentHistory newOleRequisitionPaymentHistory = new OleRequisitionPaymentHistory();
35      private boolean currencyTypeIndicator = true;
36      /**
37       * @see org.kuali.ole.module.purap.document.web.struts.PurchasingFormBase#setupNewPurchasingItemLine()
38       */
39      @Override
40      public PurApItem setupNewPurchasingItemLine() {
41          return new OleRequisitionItem();
42      }
43  
44      @Override
45      public PurApItem getAndResetNewPurchasingItemLine() {
46  
47          PurApItem aPurchasingItemLine = getNewPurchasingItemLine();
48          OleRequisitionItem reqItem = (OleRequisitionItem) aPurchasingItemLine;
49          setNewPurchasingItemLine(setupNewPurchasingItemLine());
50          OleRequisitionItem reqItems = (OleRequisitionItem) this.getNewPurchasingItemLine();
51  
52          OleRequisitionDocument document = (OleRequisitionDocument) this.getDocument();
53          if (document.getVendorDetail() != null) {
54  
55              if (document.getVendorDetail().getCurrencyType()!=null){
56                  if(document.getVendorDetail().getCurrencyType().getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME )){
57                      currencyTypeIndicator=true;
58                  }
59                  else{
60                      currencyTypeIndicator=false;
61                  }
62              }
63              String customerNumber = document.getVendorCustomerNumber();
64              List<VendorCustomerNumber> vendorCustomerNumbers = document.getVendorDetail().getVendorCustomerNumbers();
65              if (customerNumber != null && vendorCustomerNumbers != null) {
66                  for (VendorCustomerNumber vendorCustomerNumber : vendorCustomerNumbers) {
67                      if (vendorCustomerNumber.getVendorCustomerNumber().equalsIgnoreCase(customerNumber)) {
68                          if (!currencyTypeIndicator) {
69                              if (customerNumber != null) {
70                                  reqItems.setItemForeignDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0)));
71                                  reqItems.setItemForeignDiscountType(vendorCustomerNumber.getVendorDiscountType());
72                              }
73  
74                              reqItems.setItemExchangeRate(reqItem.getItemExchangeRate());
75                              setNewPurchasingItemLine(reqItems);
76                          } else {
77                              if (customerNumber != null) {
78                                  reqItems.setItemDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0)));
79                                  reqItems.setItemDiscountType(vendorCustomerNumber.getVendorDiscountType());
80                              }
81                              setNewPurchasingItemLine(reqItems);
82                          }
83                      }
84                  }
85              } else {
86                  reqItems.setItemForeignDiscount(new KualiDecimal(0.0));
87                  reqItems.setItemDiscount(new KualiDecimal(0));
88  
89              }
90          }
91          return aPurchasingItemLine;
92  
93      }
94  
95      /**
96       * Gets the newOleCopies attribute.
97       *
98       * @return Returns the newOleCopies.
99       */
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 }