View Javadoc

1   /*
2    * Copyright 2008 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.module.purap.service.impl;
17  
18  import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceItem;
19  import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceItemMapping;
20  import org.kuali.ole.module.purap.businessobject.ElectronicInvoiceRejectItem;
21  import org.kuali.ole.module.purap.businessobject.PurchaseOrderItem;
22  import org.kuali.ole.module.purap.util.ElectronicInvoiceUtils;
23  import org.kuali.rice.core.api.util.type.KualiDecimal;
24  
25  import java.math.BigDecimal;
26  import java.util.Map;
27  
28  public class ElectronicInvoiceItemHolder {
29  
30      private ElectronicInvoiceOrderHolder orderHolder;
31      private ElectronicInvoiceRejectItem rejectItem;
32      private ElectronicInvoiceItem invoiceItem;
33      private PurchaseOrderItem poItem;
34      private Map<String, ElectronicInvoiceItemMapping> itemTypeMappings;
35  
36      private boolean isRejectItemHolder;
37      private boolean validateHeader;
38  
39      public ElectronicInvoiceItemHolder(ElectronicInvoiceRejectItem rejectItem,
40                                         Map itemTypeMappings,
41                                         PurchaseOrderItem poItem,
42                                         ElectronicInvoiceOrderHolder orderHolder) {
43  
44          if (rejectItem == null) {
45              throw new NullPointerException("ElectronicInvoiceRejectItem should not be null");
46          }
47  
48          this.rejectItem = rejectItem;
49          this.poItem = poItem;
50          this.orderHolder = orderHolder;
51  
52          isRejectItemHolder = true;
53      }
54  
55      public ElectronicInvoiceItemHolder(ElectronicInvoiceItem invoiceItem,
56                                         Map itemTypeMappings,
57                                         PurchaseOrderItem poItem,
58                                         ElectronicInvoiceOrderHolder orderHolder) {
59  
60          if (invoiceItem == null) {
61              throw new NullPointerException("ElectronicInvoiceItem should not be null");
62          }
63  
64          this.invoiceItem = invoiceItem;
65          this.poItem = poItem;
66          this.orderHolder = orderHolder;
67  
68          isRejectItemHolder = false;
69      }
70  
71      public Integer getInvoiceItemLineNumber() {
72          if (isRejectItemHolder()) {
73              return rejectItem.getInvoiceReferenceItemLineNumber();
74          } else {
75              return invoiceItem.getReferenceLineNumberInteger();
76          }
77      }
78  
79      public String getInvoiceItemDescription() {
80          if (isRejectItemHolder()) {
81              return rejectItem.getInvoiceReferenceItemDescription();
82          } else {
83              return invoiceItem.getReferenceDescription();
84          }
85      }
86  
87      public PurchaseOrderItem getPurchaseOrderItem() {
88          return poItem;
89      }
90  
91      public String getCatalogNumberStripped() {
92          if (isRejectItemHolder()) {
93              return ElectronicInvoiceUtils.stripSplChars(rejectItem.getInvoiceItemCatalogNumber());
94          } else {
95              return ElectronicInvoiceUtils.stripSplChars(invoiceItem.getCatalogNumber());
96          }
97      }
98  
99      public BigDecimal getUnitPrice() {
100         if (isRejectItemHolder()) {
101             return rejectItem.getInvoiceItemUnitPrice();
102         } else {
103             return invoiceItem.getInvoiceLineUnitCostBigDecimal();
104         }
105     }
106 
107     public String getUnitPriceCurrency() {
108         if (isRejectItemHolder()) {
109             return rejectItem.getInvoiceItemUnitPriceCurrencyCode();
110         } else {
111             return invoiceItem.getUnitPriceCurrency();
112         }
113     }
114 
115     public BigDecimal getQuantity() {
116         if (isRejectItemHolder()) {
117             return rejectItem.getInvoiceItemQuantity();
118         } else {
119             return invoiceItem.getInvoiceLineQuantityBigDecimal();
120         }
121     }
122 
123     public KualiDecimal getSubTotalAmount() {
124         if (isRejectItemHolder()) {
125             return new KualiDecimal(rejectItem.getInvoiceItemSubTotalAmount().setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR));
126         } else {
127             return new KualiDecimal(invoiceItem.getInvoiceLineSubTotalAmountBigDecimal());
128         }
129     }
130 
131     public boolean isRejectItemHolder() {
132         return isRejectItemHolder;
133     }
134 
135     public ElectronicInvoiceItemMapping getItemMapping(String invoiceItemTypeCode) {
136         if (itemTypeMappings == null) {
137             return null;
138         } else {
139             return itemTypeMappings.get(invoiceItemTypeCode);
140         }
141     }
142 
143     public String getItemTypeCode(String invoiceItemTypeCode) {
144 
145         ElectronicInvoiceItemMapping itemMapping = getItemMapping(invoiceItemTypeCode);
146 
147         if (itemMapping != null) {
148             return itemMapping.getItemTypeCode();
149         } else {
150             return null;
151         }
152     }
153 
154     public String getInvoiceItemCatalogNumber() {
155         if (isRejectItemHolder()) {
156             return rejectItem.getInvoiceItemCatalogNumber();
157         } else {
158             return invoiceItem.getReferenceItemIDSupplierPartID();
159         }
160     }
161 
162     public String getInvoiceItemUnitOfMeasureCode() {
163         if (isRejectItemHolder()) {
164             return rejectItem.getInvoiceItemUnitOfMeasureCode();
165         } else {
166             return invoiceItem.getUnitOfMeasure();
167         }
168     }
169 
170     public boolean isUnitOfMeasureAcceptIndicatorEnabled() {
171         if (isRejectItemHolder()) {
172             return rejectItem.isUnitOfMeasureAcceptIndicator();
173         } else {
174             return false;
175         }
176     }
177 
178     public boolean isCatalogNumberAcceptIndicatorEnabled() {
179         if (isRejectItemHolder()) {
180             return rejectItem.isCatalogNumberAcceptIndicator();
181         } else {
182             return false;
183         }
184     }
185 
186     public BigDecimal getInvoiceItemUnitPrice() {
187         if (isRejectItemHolder()) {
188             return rejectItem.getInvoiceItemUnitPrice();
189         } else {
190             return invoiceItem.getInvoiceLineUnitCostBigDecimal();
191         }
192     }
193 
194     public BigDecimal getInvoiceItemQuantity() {
195         if (isRejectItemHolder()) {
196             return rejectItem.getInvoiceItemQuantity();
197         } else {
198             return invoiceItem.getInvoiceLineQuantityBigDecimal();
199         }
200     }
201 
202     public BigDecimal getInvoiceItemSubTotalAmount() {
203         if (isRejectItemHolder()) {
204             return rejectItem.getInvoiceItemSubTotalAmount();
205         } else {
206             return invoiceItem.getInvoiceLineSubTotalAmountBigDecimal();
207         }
208     }
209 
210     public BigDecimal getTaxAmount() {
211         if (isRejectItemHolder()) {
212             return rejectItem.getInvoiceItemTaxAmount();
213         } else {
214             return invoiceItem.getInvoiceLineTaxAmountBigDecimal();
215         }
216     }
217 
218     public ElectronicInvoiceOrderHolder getInvoiceOrderHolder() {
219         return orderHolder;
220     }
221 }