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.PurapConstants;
19  import org.kuali.ole.module.purap.businessobject.PurApItem;
20  import org.kuali.ole.module.purap.document.web.struts.InvoiceForm;
21  import org.kuali.ole.select.businessobject.OleInvoiceItem;
22  import org.kuali.ole.select.document.OleInvoiceDocument;
23  import org.kuali.ole.vnd.businessobject.VendorCustomerNumber;
24  import org.kuali.rice.core.api.util.type.KualiDecimal;
25  
26  import java.math.BigDecimal;
27  import java.util.List;
28  
29  /**
30   * This class is the KualiForm class for Ole Invoice
31   */
32  public class OleInvoiceForm extends InvoiceForm {
33  
34  
35      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleInvoiceForm.class);
36  
37      private PurApItem newPaymentItemLine;
38  
39      /**
40       * setting Item Type to Unordered Item
41       *
42       * @see org.kuali.ole.module.purap.document.web.struts.InvoiceForm#setupNewPurchasingItemLine()
43       */
44      @Override
45      public PurApItem setupNewPurchasingItemLine() {
46          OleInvoiceItem newItem = new OleInvoiceItem();
47          newItem.setItemTypeCode(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE);
48          return newItem;
49      }
50  
51      @Override
52      public PurApItem getAndResetNewPurchasingItemLine() {
53  
54          PurApItem aPurchasingItemLine = getNewPurchasingItemLine();
55          OleInvoiceItem reqItem = (OleInvoiceItem) aPurchasingItemLine;
56          setNewPurchasingItemLine(setupNewPurchasingItemLine());
57          OleInvoiceItem reqItems = (OleInvoiceItem) this.getNewPurchasingItemLine();
58  
59          OleInvoiceDocument document = (OleInvoiceDocument) this.getDocument();
60          if (document.getVendorDetail() != null) {
61              String customerNumber = document.getVendorCustomerNumber();
62  
63              List<VendorCustomerNumber> vendorCustomerNumbers = document.getVendorDetail().getVendorCustomerNumbers();
64              if (customerNumber != null && vendorCustomerNumbers != null) {
65                  for (VendorCustomerNumber vendorCustomerNumber : vendorCustomerNumbers) {
66                      if (vendorCustomerNumber.getVendorCustomerNumber().equalsIgnoreCase(customerNumber)) {
67                          if (document.getVendorDetail().getVendorHeader().getVendorForeignIndicator()) {
68                              if (customerNumber != null) {
69                                  reqItems.setItemForeignDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0)));
70                                  reqItems.setItemForeignDiscountType(vendorCustomerNumber.getVendorDiscountType());
71                              }
72  
73                              reqItems.setItemExchangeRate(reqItem.getItemExchangeRate());
74                              setNewPurchasingItemLine(reqItems);
75                          } else {
76                              if (customerNumber != null) {
77                                  reqItems.setItemDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0)));
78                                  reqItems.setItemDiscountType(vendorCustomerNumber.getVendorDiscountType());
79                              }
80                              setNewPurchasingItemLine(reqItems);
81                          }
82                      }
83                  }
84              } else {
85                  reqItems.setItemForeignDiscount(new KualiDecimal(0.0));
86                  reqItems.setItemDiscount(new KualiDecimal(0));
87              }
88          }
89          return aPurchasingItemLine;
90  
91      }
92  
93      public PurApItem getNewPaymentItemLine() {
94          return newPaymentItemLine;
95      }
96  
97      public void setNewPaymentItemLine(PurApItem newPaymentItemLine) {
98          this.newPaymentItemLine = newPaymentItemLine;
99      }
100 
101     public OleInvoiceForm() {
102         super();
103         this.setNewPaymentItemLine(null);
104         this.setNewPurchasingItemLine(setupNewPurchasingItemLine());
105     }
106 
107 }