View Javadoc
1   /*
2    * Copyright 2013 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.PurapConstants;
19  import org.kuali.ole.module.purap.businessobject.PurApItem;
20  import org.kuali.ole.module.purap.document.web.struts.VendorCreditMemoForm;
21  import org.kuali.ole.select.OleSelectConstant;
22  import org.kuali.ole.select.businessobject.OleCreditMemoItem;
23  import org.kuali.ole.select.document.OleVendorCreditMemoDocument;
24  import org.kuali.ole.vnd.businessobject.VendorCustomerNumber;
25  import org.kuali.rice.core.api.util.type.KualiDecimal;
26  
27  import java.math.BigDecimal;
28  import java.util.List;
29  
30  
31  /**
32   * Struts Action Form for Credit Memo document.
33   */
34  
35  public class OleVendorCreditMemoForm extends VendorCreditMemoForm {
36  
37      private PurApItem newCreditItemLine;
38      private boolean currencyTypeIndicator;
39  
40      public OleVendorCreditMemoForm() {
41          super();
42          this.setNewCreditItemLine(null);
43          this.setNewPurchasingItemLine(setupNewPurchasingItemLine());
44      }
45  
46  
47      public PurApItem getNewCreditItemLine() {
48          return newCreditItemLine;
49      }
50  
51  
52      public void setNewCreditItemLine(PurApItem newCreditItemLine) {
53          this.newCreditItemLine = newCreditItemLine;
54      }
55  
56  
57      @Override
58      public PurApItem setupNewPurchasingItemLine() {
59          OleCreditMemoItem newItem = new OleCreditMemoItem();
60          newItem.setItemTypeCode(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE);
61          return newItem;
62      }
63  
64      @Override
65      public PurApItem getAndResetNewPurchasingItemLine() {
66  
67          PurApItem aPurchasingItemLine = getNewPurchasingItemLine();
68          OleCreditMemoItem crdtItem = (OleCreditMemoItem) aPurchasingItemLine;
69          setNewPurchasingItemLine(setupNewPurchasingItemLine());
70          OleCreditMemoItem crdtItems = (OleCreditMemoItem) this.getNewPurchasingItemLine();
71  
72          OleVendorCreditMemoDocument document = (OleVendorCreditMemoDocument) this.getDocument();
73          if (document.getVendorDetail().getCurrencyType()!=null){
74              if(document.getVendorDetail().getCurrencyType().getCurrencyType().equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)){
75                  currencyTypeIndicator=true;
76              }
77              else{
78                  currencyTypeIndicator=false;
79              }
80          }
81          if (document.getVendorDetail() != null) {
82              String customerNumber = document.getVendorCustomerNumber();
83  
84              List<VendorCustomerNumber> vendorCustomerNumbers = document.getVendorDetail().getVendorCustomerNumbers();
85              if (customerNumber != null && vendorCustomerNumbers != null) {
86                  for (VendorCustomerNumber vendorCustomerNumber : vendorCustomerNumbers) {
87                      if (vendorCustomerNumber.getVendorCustomerNumber().equalsIgnoreCase(customerNumber)) {
88                          if (!currencyTypeIndicator) {
89                              if (customerNumber != null) {
90                                  crdtItems.setItemForeignDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0)));
91                                  crdtItems.setItemForeignDiscountType(vendorCustomerNumber.getVendorDiscountType());
92                              }
93  
94                              crdtItems.setItemExchangeRate(crdtItem.getItemExchangeRate());
95                              setNewPurchasingItemLine(crdtItems);
96                          }
97                      }
98                  }
99              } else {
100                 crdtItems.setItemForeignDiscount(new KualiDecimal(0.0));
101                 crdtItems.setItemForeignDiscount(new KualiDecimal(0.0));
102             }
103         }
104         return aPurchasingItemLine;
105     }
106 
107 }