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      private boolean filterProcessItems = true;
40  
41      /**
42       * setting Item Type to Unordered Item
43       *
44       * @see org.kuali.ole.module.purap.document.web.struts.InvoiceForm#setupNewPurchasingItemLine()
45       */
46      @Override
47      public PurApItem setupNewPurchasingItemLine() {
48          OleInvoiceItem newItem = new OleInvoiceItem();
49          newItem.setItemTypeCode(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE);
50          return newItem;
51      }
52  
53      @Override
54      public PurApItem getAndResetNewPurchasingItemLine() {
55  
56          PurApItem aPurchasingItemLine = getNewPurchasingItemLine();
57          OleInvoiceItem reqItem = (OleInvoiceItem) aPurchasingItemLine;
58          setNewPurchasingItemLine(setupNewPurchasingItemLine());
59          OleInvoiceItem reqItems = (OleInvoiceItem) this.getNewPurchasingItemLine();
60  
61          OleInvoiceDocument document = (OleInvoiceDocument) this.getDocument();
62          if (document.getVendorDetail() != null) {
63              String customerNumber = document.getVendorCustomerNumber();
64  
65              List<VendorCustomerNumber> vendorCustomerNumbers = document.getVendorDetail().getVendorCustomerNumbers();
66              if (customerNumber != null && vendorCustomerNumbers != null) {
67                  for (VendorCustomerNumber vendorCustomerNumber : vendorCustomerNumbers) {
68                      if (vendorCustomerNumber.getVendorCustomerNumber().equalsIgnoreCase(customerNumber)) {
69                          if (document.getVendorDetail().getVendorHeader().getVendorForeignIndicator()) {
70                              if (customerNumber != null) {
71                                  reqItems.setItemForeignDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0)));
72                                  reqItems.setItemForeignDiscountType(vendorCustomerNumber.getVendorDiscountType());
73                              }
74  
75                              reqItems.setItemExchangeRate(reqItem.getItemExchangeRate());
76                              setNewPurchasingItemLine(reqItems);
77                          } else {
78                              if (customerNumber != null) {
79                                  reqItems.setItemDiscount(new KualiDecimal(vendorCustomerNumber.getVendorDiscountPercentage() != null ? vendorCustomerNumber.getVendorDiscountPercentage().bigDecimalValue() : new BigDecimal(0.0)));
80                                  reqItems.setItemDiscountType(vendorCustomerNumber.getVendorDiscountType());
81                              }
82                              setNewPurchasingItemLine(reqItems);
83                          }
84                      }
85                  }
86              } else {
87                  reqItems.setItemForeignDiscount(new KualiDecimal(0.0));
88                  reqItems.setItemDiscount(new KualiDecimal(0));
89              }
90          }
91          return aPurchasingItemLine;
92  
93      }
94  
95      public PurApItem getNewPaymentItemLine() {
96          return newPaymentItemLine;
97      }
98  
99      public void setNewPaymentItemLine(PurApItem newPaymentItemLine) {
100         this.newPaymentItemLine = newPaymentItemLine;
101     }
102 
103     public boolean isFilterProcessItems() {
104 		return filterProcessItems;
105 	}
106 
107 	public void setFilterProcessItems(boolean filterProcessItems) {
108 		this.filterProcessItems = filterProcessItems;
109 	}
110 
111 	public OleInvoiceForm() {
112         super();
113         this.setNewPaymentItemLine(null);
114         this.setNewPurchasingItemLine(setupNewPurchasingItemLine());
115     }
116 
117 }